2019-01-24 20:41:30 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2018 Vulcanize
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-22 17:44:35 +00:00
|
|
|
|
|
|
|
package bite_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2018-08-30 20:06:14 +00:00
|
|
|
|
2018-11-08 15:14:35 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2018-08-30 20:06:14 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2018-11-08 15:14:35 +00:00
|
|
|
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/bite"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
2018-08-22 17:44:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Bite Converter", func() {
|
|
|
|
var converter = bite.BiteConverter{}
|
|
|
|
|
|
|
|
Describe("ToEntity", func() {
|
|
|
|
It("converts an eth log to a bite entity", func() {
|
2019-01-23 18:44:09 +00:00
|
|
|
entities, err := converter.ToEntities(test_data.KovanCatABI, []types.Log{test_data.EthBiteLog})
|
2018-08-22 17:44:35 +00:00
|
|
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-10-02 22:25:38 +00:00
|
|
|
Expect(len(entities)).To(Equal(1))
|
|
|
|
entity := entities[0]
|
2018-10-26 18:26:10 +00:00
|
|
|
Expect(entity).To(Equal(test_data.BiteEntity))
|
2018-08-22 17:44:35 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("returns an error if converting log to entity fails", func() {
|
2018-10-02 22:25:38 +00:00
|
|
|
_, err := converter.ToEntities("error abi", []types.Log{test_data.EthBiteLog})
|
2018-08-22 17:44:35 +00:00
|
|
|
|
|
|
|
Expect(err).To(HaveOccurred())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("ToModel", func() {
|
|
|
|
var emptyEntity = bite.BiteEntity{}
|
|
|
|
|
|
|
|
It("converts an Entity to a Model", func() {
|
2018-10-26 18:26:10 +00:00
|
|
|
models, err := converter.ToModels([]interface{}{test_data.BiteEntity})
|
2018-08-22 17:44:35 +00:00
|
|
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-10-02 22:25:38 +00:00
|
|
|
Expect(len(models)).To(Equal(1))
|
|
|
|
model := models[0]
|
2018-08-22 17:44:35 +00:00
|
|
|
Expect(model).To(Equal(test_data.BiteModel))
|
|
|
|
})
|
|
|
|
|
2018-10-29 20:08:00 +00:00
|
|
|
It("returns an error if the entity type is wrong", func() {
|
|
|
|
_, err := converter.ToModels([]interface{}{test_data.WrongEntity{}})
|
|
|
|
|
|
|
|
Expect(err).To(HaveOccurred())
|
|
|
|
Expect(err.Error()).To(ContainSubstring("entity of type test_data.WrongEntity, not bite.BiteEntity"))
|
|
|
|
})
|
|
|
|
|
2018-08-22 17:44:35 +00:00
|
|
|
It("handles nil values", func() {
|
|
|
|
emptyLog, err := json.Marshal(types.Log{})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
expectedModel := bite.BiteModel{
|
2018-10-18 16:35:27 +00:00
|
|
|
Ilk: "",
|
2018-10-08 02:51:37 +00:00
|
|
|
Urn: "0x0000000000000000000000000000000000000000",
|
2018-08-22 17:44:35 +00:00
|
|
|
Ink: "",
|
|
|
|
Art: "",
|
|
|
|
IArt: "",
|
|
|
|
Tab: "",
|
2018-10-16 19:51:26 +00:00
|
|
|
NFlip: "",
|
2018-08-22 17:44:35 +00:00
|
|
|
TransactionIndex: 0,
|
2018-11-12 20:59:16 +00:00
|
|
|
Raw: emptyLog,
|
2018-08-22 17:44:35 +00:00
|
|
|
}
|
2018-10-26 18:26:10 +00:00
|
|
|
models, err := converter.ToModels([]interface{}{emptyEntity})
|
2018-08-22 17:44:35 +00:00
|
|
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-10-02 22:25:38 +00:00
|
|
|
Expect(len(models)).To(Equal(1))
|
|
|
|
model := models[0]
|
2018-08-22 17:44:35 +00:00
|
|
|
Expect(model).To(Equal(expectedModel))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|