2018-08-22 17:44:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Vulcanize
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package bite_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/bite"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
2018-08-30 20:06:14 +00:00
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2018-09-04 21:01:23 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
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() {
|
2018-10-02 22:25:38 +00:00
|
|
|
entities, err := converter.ToEntities(shared.CatABI, []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-08-22 17:44:35 +00:00
|
|
|
Expect(entity.Ilk).To(Equal(test_data.BiteEntity.Ilk))
|
2018-09-12 14:10:34 +00:00
|
|
|
Expect(entity.Urn).To(Equal(test_data.BiteEntity.Urn))
|
2018-08-22 17:44:35 +00:00
|
|
|
Expect(entity.Ink).To(Equal(test_data.BiteEntity.Ink))
|
|
|
|
Expect(entity.Art).To(Equal(test_data.BiteEntity.Art))
|
|
|
|
Expect(entity.Tab).To(Equal(test_data.BiteEntity.Tab))
|
|
|
|
Expect(entity.Flip).To(Equal(test_data.BiteEntity.Flip))
|
|
|
|
Expect(entity.IArt).To(Equal(test_data.BiteEntity.IArt))
|
2018-08-30 20:06:14 +00:00
|
|
|
Expect(entity.TransactionIndex).To(Equal(test_data.BiteEntity.TransactionIndex))
|
|
|
|
Expect(entity.Raw).To(Equal(test_data.BiteEntity.Raw))
|
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-02 22:25:38 +00:00
|
|
|
models, err := converter.ToModels([]bite.BiteEntity{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))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("handles nil values", func() {
|
|
|
|
emptyLog, err := json.Marshal(types.Log{})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
expectedModel := bite.BiteModel{
|
2018-10-08 02:51:37 +00:00
|
|
|
Ilk: "0x0000000000000000000000000000000000000000",
|
|
|
|
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,
|
|
|
|
Raw: string(emptyLog),
|
|
|
|
}
|
2018-10-02 22:25:38 +00:00
|
|
|
models, err := converter.ToModels([]bite.BiteEntity{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))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|