forked from cerc-io/ipld-eth-server
Update flip kick and tend transformers due to contract changes
* Update FlipperAddress to new local ganache address * Update flip_kick table * Update flipkick transformer to handle new signature and abi * Update tend table * Update tend converter
This commit is contained in:
@@ -17,7 +17,7 @@ package flip_kick
|
||||
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
|
||||
var FlipKickConfig = shared.TransformerConfig{
|
||||
ContractAddresses: "0x08cb6176addcca2e1d1ffe21bee464b72ee4cd8d", //this is a temporary address deployed locally
|
||||
ContractAddresses: shared.FlipperContractAddress,
|
||||
ContractAbi: shared.FlipperABI,
|
||||
Topics: []string{shared.FlipKickSignature},
|
||||
StartingBlockNumber: 0,
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -17,7 +17,6 @@ package flip_kick
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
@@ -45,7 +44,7 @@ func (FlipKickConverter) ToEntity(contractAddress string, contractAbi string, et
|
||||
|
||||
contract := bind.NewBoundContract(address, abi, nil, nil, nil)
|
||||
|
||||
err = contract.UnpackLog(entity, "FlipKick", ethLog)
|
||||
err = contract.UnpackLog(entity, "Kick", ethLog)
|
||||
if err != nil {
|
||||
return entity, err
|
||||
}
|
||||
@@ -54,24 +53,17 @@ func (FlipKickConverter) ToEntity(contractAddress string, contractAbi string, et
|
||||
}
|
||||
|
||||
func (FlipKickConverter) ToModel(flipKick FlipKickEntity) (FlipKickModel, error) {
|
||||
//TODO: Confirm if the following values can be/ever will be nil
|
||||
|
||||
if flipKick.Id == nil {
|
||||
return FlipKickModel{}, errors.New("FlipKick log ID cannot be nil.")
|
||||
}
|
||||
|
||||
id := flipKick.Id.String()
|
||||
vat := strings.ToLower(flipKick.Vat.String())
|
||||
ilk := strings.ToLower(common.ToHex(flipKick.Ilk[:]))
|
||||
lot := utilities.ConvertNilToEmptyString(flipKick.Lot.String())
|
||||
bid := utilities.ConvertNilToEmptyString(flipKick.Bid.String())
|
||||
guy := strings.ToLower(flipKick.Guy.String())
|
||||
gal := strings.ToLower(flipKick.Gal.String())
|
||||
gal := flipKick.Gal.String()
|
||||
endValue := utilities.ConvertNilToZeroTimeValue(flipKick.End)
|
||||
end := time.Unix(endValue, 0)
|
||||
eraValue := utilities.ConvertNilToZeroTimeValue(flipKick.Era)
|
||||
era := time.Unix(eraValue, 0)
|
||||
lad := strings.ToLower(flipKick.Lad.String())
|
||||
urn := common.BytesToAddress(flipKick.Urn[:common.AddressLength]).String()
|
||||
tab := utilities.ConvertNilToEmptyString(flipKick.Tab.String())
|
||||
rawLogJson, err := json.Marshal(flipKick.Raw)
|
||||
if err != nil {
|
||||
@@ -81,15 +73,11 @@ func (FlipKickConverter) ToModel(flipKick FlipKickEntity) (FlipKickModel, error)
|
||||
|
||||
return FlipKickModel{
|
||||
Id: id,
|
||||
Vat: vat,
|
||||
Ilk: ilk,
|
||||
Lot: lot,
|
||||
Bid: bid,
|
||||
Guy: guy,
|
||||
Gal: gal,
|
||||
End: end,
|
||||
Era: era,
|
||||
Lad: lad,
|
||||
Urn: urn,
|
||||
Tab: tab,
|
||||
Raw: rawLogString,
|
||||
}, nil
|
||||
|
||||
@@ -33,25 +33,21 @@ var _ = Describe("FlipKick Converter", func() {
|
||||
|
||||
Describe("ToEntity", func() {
|
||||
It("converts an Eth Log to a FlipKickEntity", func() {
|
||||
entity, err := converter.ToEntity(test_data.FlipAddress, shared.FlipperABI, test_data.EthFlipKickLog)
|
||||
entity, err := converter.ToEntity(shared.FlipperContractAddress, shared.FlipperABI, test_data.EthFlipKickLog)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(entity.Id).To(Equal(test_data.FlipKickEntity.Id))
|
||||
Expect(entity.Vat).To(Equal(test_data.FlipKickEntity.Vat))
|
||||
Expect(entity.Ilk).To(Equal(test_data.FlipKickEntity.Ilk))
|
||||
Expect(entity.Lot).To(Equal(test_data.FlipKickEntity.Lot))
|
||||
Expect(entity.Bid).To(Equal(test_data.FlipKickEntity.Bid))
|
||||
Expect(entity.Guy).To(Equal(test_data.FlipKickEntity.Guy))
|
||||
Expect(entity.Gal).To(Equal(test_data.FlipKickEntity.Gal))
|
||||
Expect(entity.End).To(Equal(test_data.FlipKickEntity.End))
|
||||
Expect(entity.Era).To(Equal(test_data.FlipKickEntity.Era))
|
||||
Expect(entity.Lad).To(Equal(test_data.FlipKickEntity.Lad))
|
||||
Expect(entity.Urn).To(Equal(test_data.FlipKickEntity.Urn))
|
||||
Expect(entity.Tab).To(Equal(test_data.FlipKickEntity.Tab))
|
||||
Expect(entity.Raw).To(Equal(test_data.FlipKickEntity.Raw))
|
||||
})
|
||||
|
||||
It("returns an error if converting log to entity fails", func() {
|
||||
_, err := converter.ToEntity(test_data.FlipAddress, "error abi", test_data.EthFlipKickLog)
|
||||
_, err := converter.ToEntity(shared.FlipperContractAddress, "error abi", test_data.EthFlipKickLog)
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
@@ -59,7 +55,6 @@ var _ = Describe("FlipKick Converter", func() {
|
||||
|
||||
Describe("ToModel", func() {
|
||||
var emptyAddressHex = "0x0000000000000000000000000000000000000000"
|
||||
var emptyByteArrayHex = "0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
var emptyString = ""
|
||||
var emptyTime = time.Unix(0, 0)
|
||||
var emptyEntity = flip_kick.FlipKickEntity{}
|
||||
@@ -87,15 +82,11 @@ var _ = Describe("FlipKick Converter", func() {
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(model.Id).To(Equal("1"))
|
||||
Expect(model.Vat).To(Equal(emptyAddressHex))
|
||||
Expect(model.Ilk).To(Equal(emptyByteArrayHex))
|
||||
Expect(model.Lot).To(Equal(emptyString))
|
||||
Expect(model.Bid).To(Equal(emptyString))
|
||||
Expect(model.Guy).To(Equal(emptyAddressHex))
|
||||
Expect(model.Gal).To(Equal(emptyAddressHex))
|
||||
Expect(model.End).To(Equal(emptyTime))
|
||||
Expect(model.Era).To(Equal(emptyTime))
|
||||
Expect(model.Lad).To(Equal(emptyAddressHex))
|
||||
Expect(model.Urn).To(Equal(emptyAddressHex))
|
||||
Expect(model.Tab).To(Equal(emptyString))
|
||||
Expect(model.Raw).To(Equal(emptyRawLog))
|
||||
})
|
||||
|
||||
@@ -23,15 +23,11 @@ import (
|
||||
|
||||
type FlipKickEntity struct {
|
||||
Id *big.Int
|
||||
Vat common.Address
|
||||
Ilk [32]byte
|
||||
Lot *big.Int
|
||||
Bid *big.Int
|
||||
Guy common.Address
|
||||
Gal common.Address
|
||||
End *big.Int
|
||||
Era *big.Int
|
||||
Lad common.Address
|
||||
Urn [32]byte
|
||||
Tab *big.Int
|
||||
Raw types.Log
|
||||
}
|
||||
|
||||
@@ -17,51 +17,18 @@ package flip_kick_test
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth/client"
|
||||
rpc2 "github.com/vulcanize/vulcanizedb/pkg/geth/converters/rpc"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth/node"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
"github.com/vulcanize/vulcanizedb/test_config"
|
||||
)
|
||||
|
||||
var _ = Describe("Integration tests", func() {
|
||||
XIt("Fetches FlipKickEntity event logs from a local test chain", func() {
|
||||
ipcPath := test_config.TestClient.IPCPath
|
||||
|
||||
rawRpcClient, err := rpc.Dial(ipcPath)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
rpcClient := client.NewRpcClient(rawRpcClient, ipcPath)
|
||||
ethClient := ethclient.NewClient(rawRpcClient)
|
||||
blockChainClient := client.NewEthClient(ethClient)
|
||||
realNode := node.MakeNode(rpcClient)
|
||||
transactionConverter := rpc2.NewRpcTransactionConverter(ethClient)
|
||||
realBlockChain := geth.NewBlockChain(blockChainClient, realNode, transactionConverter)
|
||||
realFetcher := shared.NewFetcher(realBlockChain)
|
||||
topic0 := common.HexToHash(shared.FlipKickSignature)
|
||||
topics := [][]common.Hash{{topic0}}
|
||||
|
||||
result, err := realFetcher.FetchLogs(test_data.FlipAddress, topics, test_data.FlipKickBlockNumber)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(len(result) > 0).To(BeTrue())
|
||||
Expect(result[0].Address).To(Equal(test_data.EthFlipKickLog.Address))
|
||||
Expect(result[0].TxHash).To(Equal(test_data.EthFlipKickLog.TxHash))
|
||||
Expect(result[0].BlockNumber).To(Equal(test_data.EthFlipKickLog.BlockNumber))
|
||||
Expect(result[0].Topics).To(Equal(test_data.EthFlipKickLog.Topics))
|
||||
Expect(result[0].Index).To(Equal(test_data.EthFlipKickLog.Index))
|
||||
})
|
||||
|
||||
It("unpacks an event log", func() {
|
||||
address := common.HexToAddress(test_data.FlipAddress)
|
||||
address := common.HexToAddress(shared.FlipperContractAddress)
|
||||
abi, err := geth.ParseAbi(shared.FlipperABI)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
@@ -70,20 +37,16 @@ var _ = Describe("Integration tests", func() {
|
||||
|
||||
var eventLog = test_data.EthFlipKickLog
|
||||
|
||||
err = contract.UnpackLog(entity, "FlipKick", eventLog)
|
||||
err = contract.UnpackLog(entity, "Kick", eventLog)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
expectedEntity := test_data.FlipKickEntity
|
||||
Expect(entity.Id).To(Equal(expectedEntity.Id))
|
||||
Expect(entity.Vat).To(Equal(expectedEntity.Vat))
|
||||
Expect(entity.Ilk).To(Equal(expectedEntity.Ilk))
|
||||
Expect(entity.Lot).To(Equal(expectedEntity.Lot))
|
||||
Expect(entity.Bid).To(Equal(expectedEntity.Bid))
|
||||
Expect(entity.Guy).To(Equal(expectedEntity.Guy))
|
||||
Expect(entity.Gal).To(Equal(expectedEntity.Gal))
|
||||
Expect(entity.End).To(Equal(expectedEntity.End))
|
||||
Expect(entity.Era).To(Equal(expectedEntity.Era))
|
||||
Expect(entity.Lad).To(Equal(expectedEntity.Lad))
|
||||
Expect(entity.Urn).To(Equal(expectedEntity.Urn))
|
||||
Expect(entity.Tab).To(Equal(expectedEntity.Tab))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -18,15 +18,11 @@ import "time"
|
||||
|
||||
type FlipKickModel struct {
|
||||
Id string
|
||||
Vat string
|
||||
Ilk string
|
||||
Lot string
|
||||
Bid string
|
||||
Guy string
|
||||
Gal string
|
||||
End time.Time
|
||||
Era time.Time
|
||||
Lad string
|
||||
Urn string
|
||||
Tab string
|
||||
Raw string `db:"raw_log"`
|
||||
}
|
||||
|
||||
@@ -35,9 +35,9 @@ func NewFlipKickRepository(db *postgres.DB) FlipKickRepository {
|
||||
}
|
||||
func (fkr FlipKickRepository) Create(headerId int64, flipKick FlipKickModel) error {
|
||||
_, err := fkr.DB.Exec(
|
||||
`INSERT into maker.flip_kick (header_id, id, vat, ilk, lot, bid, guy, gal, "end", era, lad, tab, raw_log)
|
||||
VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)`,
|
||||
headerId, flipKick.Id, flipKick.Vat, flipKick.Ilk, flipKick.Lot, flipKick.Bid, flipKick.Guy, flipKick.Gal, flipKick.End, flipKick.Era, flipKick.Lad, flipKick.Tab, flipKick.Raw,
|
||||
`INSERT into maker.flip_kick (header_id, id, lot, bid, gal, "end", urn, tab, raw_log)
|
||||
VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
|
||||
headerId, flipKick.Id, flipKick.Lot, flipKick.Bid, flipKick.Gal, flipKick.End, flipKick.Urn, flipKick.Tab, flipKick.Raw,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -65,17 +65,13 @@ var _ = Describe("FlipKick Repository", func() {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(dbResult.HeaderId).To(Equal(headerId))
|
||||
Expect(dbResult.Id).To(Equal(flipKick.Id))
|
||||
Expect(dbResult.Vat).To(Equal(flipKick.Vat))
|
||||
Expect(dbResult.Ilk).To(Equal(flipKick.Ilk))
|
||||
Expect(dbResult.Lot).To(Equal(flipKick.Lot))
|
||||
Expect(dbResult.Bid).To(Equal(flipKick.Bid))
|
||||
Expect(dbResult.Guy).To(Equal(flipKick.Guy))
|
||||
Expect(dbResult.Gal).To(Equal(flipKick.Gal))
|
||||
Expect(dbResult.End.Equal(flipKick.End)).To(BeTrue())
|
||||
Expect(dbResult.Era.Equal(flipKick.Era)).To(BeTrue())
|
||||
Expect(dbResult.Lad).To(Equal(flipKick.Lad))
|
||||
Expect(dbResult.Urn).To(Equal(flipKick.Urn))
|
||||
Expect(dbResult.Tab).To(Equal(flipKick.Tab))
|
||||
Expect(dbResult.Raw).To(Equal(flipKick.Raw))
|
||||
Expect(dbResult.Raw).To(MatchJSON(flipKick.Raw))
|
||||
})
|
||||
|
||||
It("returns an error if inserting the flip_kick record fails", func() {
|
||||
|
||||
Reference in New Issue
Block a user