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-07 15:51:34 +00:00
|
|
|
|
2018-08-07 20:17:29 +00:00
|
|
|
package flip_kick_test
|
2018-08-07 15:51:34 +00:00
|
|
|
|
|
|
|
import (
|
2018-08-16 21:36:35 +00:00
|
|
|
"encoding/json"
|
2018-08-07 20:17:29 +00:00
|
|
|
"math/big"
|
2018-08-07 15:51:34 +00:00
|
|
|
"time"
|
2018-08-07 20:17:29 +00:00
|
|
|
|
2018-08-07 15:51:34 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2018-08-07 20:17:29 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
2018-08-07 15:51:34 +00:00
|
|
|
)
|
|
|
|
|
2018-08-16 21:36:35 +00:00
|
|
|
var _ = Describe("FlipKick Converter", func() {
|
|
|
|
var converter = flip_kick.FlipKickConverter{}
|
2018-08-07 15:51:34 +00:00
|
|
|
|
2018-08-16 21:36:35 +00:00
|
|
|
Describe("ToEntity", func() {
|
|
|
|
It("converts an Eth Log to a FlipKickEntity", func() {
|
2019-01-23 18:44:09 +00:00
|
|
|
entities, err := converter.ToEntities(test_data.KovanFlipperABI, []types.Log{test_data.EthFlipKickLog})
|
2018-08-07 15:51:34 +00:00
|
|
|
|
2018-08-16 21:36:35 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-09-20 20:13:37 +00:00
|
|
|
Expect(len(entities)).To(Equal(1))
|
|
|
|
entity := entities[0]
|
2018-10-23 21:33:04 +00:00
|
|
|
Expect(entity).To(Equal(test_data.FlipKickEntity))
|
2018-08-16 21:36:35 +00:00
|
|
|
})
|
2018-08-07 15:51:34 +00:00
|
|
|
|
2018-08-16 21:36:35 +00:00
|
|
|
It("returns an error if converting log to entity fails", func() {
|
2018-09-27 15:12:29 +00:00
|
|
|
_, err := converter.ToEntities("error abi", []types.Log{test_data.EthFlipKickLog})
|
2018-08-07 15:51:34 +00:00
|
|
|
|
2018-08-16 21:36:35 +00:00
|
|
|
Expect(err).To(HaveOccurred())
|
|
|
|
})
|
2018-08-07 15:51:34 +00:00
|
|
|
})
|
|
|
|
|
2018-08-16 21:36:35 +00:00
|
|
|
Describe("ToModel", func() {
|
|
|
|
var emptyAddressHex = "0x0000000000000000000000000000000000000000"
|
|
|
|
var emptyString = ""
|
|
|
|
var emptyTime = time.Unix(0, 0)
|
|
|
|
var emptyEntity = flip_kick.FlipKickEntity{}
|
2018-11-12 20:59:16 +00:00
|
|
|
var emptyRawLog []byte
|
|
|
|
var err error
|
2018-08-07 15:51:34 +00:00
|
|
|
|
2018-08-16 21:36:35 +00:00
|
|
|
BeforeEach(func() {
|
|
|
|
emptyEntity.Id = big.NewInt(1)
|
2018-11-12 20:59:16 +00:00
|
|
|
emptyRawLog, err = json.Marshal(types.Log{})
|
2018-08-16 21:36:35 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
})
|
|
|
|
|
|
|
|
It("converts an Entity to a Model", func() {
|
2018-11-02 14:12:51 +00:00
|
|
|
models, err := converter.ToModels([]interface{}{test_data.FlipKickEntity})
|
2018-08-07 15:51:34 +00:00
|
|
|
|
2018-08-16 21:36:35 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-09-20 20:13:37 +00:00
|
|
|
Expect(len(models)).To(Equal(1))
|
|
|
|
Expect(models[0]).To(Equal(test_data.FlipKickModel))
|
2018-08-16 21:36:35 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("handles nil values", func() {
|
2018-11-02 14:12:51 +00:00
|
|
|
models, err := converter.ToModels([]interface{}{emptyEntity})
|
2018-08-16 21:36:35 +00:00
|
|
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-09-20 20:13:37 +00:00
|
|
|
Expect(len(models)).To(Equal(1))
|
2018-11-02 14:12:51 +00:00
|
|
|
model := models[0].(flip_kick.FlipKickModel)
|
2018-09-18 14:27:14 +00:00
|
|
|
Expect(model.BidId).To(Equal("1"))
|
2018-08-16 21:36:35 +00:00
|
|
|
Expect(model.Lot).To(Equal(emptyString))
|
|
|
|
Expect(model.Bid).To(Equal(emptyString))
|
|
|
|
Expect(model.Gal).To(Equal(emptyAddressHex))
|
|
|
|
Expect(model.End).To(Equal(emptyTime))
|
2018-09-04 20:50:29 +00:00
|
|
|
Expect(model.Urn).To(Equal(emptyAddressHex))
|
2018-08-16 21:36:35 +00:00
|
|
|
Expect(model.Tab).To(Equal(emptyString))
|
|
|
|
Expect(model.Raw).To(Equal(emptyRawLog))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("returns an error if the flip kick event id is nil", func() {
|
|
|
|
emptyEntity.Id = nil
|
2018-11-02 14:12:51 +00:00
|
|
|
_, err := converter.ToModels([]interface{}{emptyEntity})
|
2018-08-16 21:36:35 +00:00
|
|
|
|
|
|
|
Expect(err).To(HaveOccurred())
|
|
|
|
})
|
2018-11-02 14:12:51 +00:00
|
|
|
|
|
|
|
It("returns an error if the wrong entity type is passed in", func() {
|
|
|
|
_, err := converter.ToModels([]interface{}{test_data.WrongEntity{}})
|
|
|
|
|
|
|
|
Expect(err).To(HaveOccurred())
|
|
|
|
Expect(err.Error()).To(ContainSubstring("entity of type"))
|
|
|
|
})
|
2018-08-16 21:36:35 +00:00
|
|
|
})
|
2018-08-07 15:51:34 +00:00
|
|
|
})
|