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:
Elizabeth 2018-09-04 15:50:29 -05:00 committed by GitHub
parent 807b7accd6
commit 53635ec362
33 changed files with 147 additions and 448 deletions

View File

@ -2,15 +2,11 @@ CREATE TABLE maker.flip_kick (
db_id SERIAL PRIMARY KEY, db_id SERIAL PRIMARY KEY,
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
id NUMERIC NOT NULL UNIQUE, id NUMERIC NOT NULL UNIQUE,
mom VARCHAR,
vat VARCHAR,
ilk VARCHAR,
lot NUMERIC, lot NUMERIC,
bid NUMERIC, bid NUMERIC,
guy VARCHAR,
gal VARCHAR, gal VARCHAR,
"end" TIMESTAMP WITH TIME ZONE, "end" TIMESTAMP WITH TIME ZONE,
era TIMESTAMP WITH TIME ZONE, urn VARCHAR,
lad VARCHAR, tab NUMERIC,
tab NUMERIC raw_log JSONB
); );

View File

@ -1,2 +0,0 @@
ALTER TABLE maker.flip_kick
DROP COLUMN raw_log;

View File

@ -1,2 +0,0 @@
ALTER TABLE maker.flip_kick
ADD COLUMN raw_log json;

View File

@ -1,12 +1,11 @@
CREATE TABLE maker.tend ( CREATE TABLE maker.tend (
db_id SERIAL PRIMARY KEY, db_id SERIAL PRIMARY KEY,
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
id NUMERIC NOT NULL UNIQUE, bid_id NUMERIC NOT NULL UNIQUE,
lot NUMERIC, lot NUMERIC,
bid NUMERIC, bid NUMERIC,
guy BYTEA, guy VARCHAR,
tic NUMERIC, tic NUMERIC,
era TIMESTAMP WITH TIME ZONE,
tx_idx INTEGER NOT NUll, tx_idx INTEGER NOT NUll,
raw_log JSONB raw_log JSONB
); );

View File

@ -1,2 +0,0 @@
ALTER TABLE maker.flip_kick
ADD COLUMN mom VARCHAR;

View File

@ -1,2 +0,0 @@
ALTER TABLE maker.flip_kick
DROP COLUMN mom;

View File

@ -87,17 +87,13 @@ CREATE TABLE maker.flip_kick (
db_id integer NOT NULL, db_id integer NOT NULL,
header_id integer NOT NULL, header_id integer NOT NULL,
id numeric NOT NULL, id numeric NOT NULL,
vat character varying,
ilk character varying,
lot numeric, lot numeric,
bid numeric, bid numeric,
guy character varying,
gal character varying, gal character varying,
"end" timestamp with time zone, "end" timestamp with time zone,
era timestamp with time zone, urn character varying,
lad character varying,
tab numeric, tab numeric,
raw_log json raw_log jsonb
); );
@ -200,12 +196,11 @@ ALTER SEQUENCE maker.price_feeds_id_seq OWNED BY maker.price_feeds.id;
CREATE TABLE maker.tend ( CREATE TABLE maker.tend (
db_id integer NOT NULL, db_id integer NOT NULL,
header_id integer NOT NULL, header_id integer NOT NULL,
id numeric NOT NULL, bid_id numeric NOT NULL,
lot numeric, lot numeric,
bid numeric, bid numeric,
guy bytea, guy character varying,
tic numeric, tic numeric,
era timestamp with time zone,
tx_idx integer NOT NULL, tx_idx integer NOT NULL,
raw_log jsonb raw_log jsonb
); );
@ -766,11 +761,11 @@ ALTER TABLE ONLY maker.price_feeds
-- --
-- Name: tend tend_id_key; Type: CONSTRAINT; Schema: maker; Owner: - -- Name: tend tend_bid_id_key; Type: CONSTRAINT; Schema: maker; Owner: -
-- --
ALTER TABLE ONLY maker.tend ALTER TABLE ONLY maker.tend
ADD CONSTRAINT tend_id_key UNIQUE (id); ADD CONSTRAINT tend_bid_id_key UNIQUE (bid_id);
-- --

View File

@ -17,7 +17,7 @@ package flip_kick
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
var FlipKickConfig = shared.TransformerConfig{ var FlipKickConfig = shared.TransformerConfig{
ContractAddresses: "0x08cb6176addcca2e1d1ffe21bee464b72ee4cd8d", //this is a temporary address deployed locally ContractAddresses: shared.FlipperContractAddress,
ContractAbi: shared.FlipperABI, ContractAbi: shared.FlipperABI,
Topics: []string{shared.FlipKickSignature}, Topics: []string{shared.FlipKickSignature},
StartingBlockNumber: 0, StartingBlockNumber: 0,

File diff suppressed because one or more lines are too long

View File

@ -17,7 +17,6 @@ package flip_kick
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"strings"
"time" "time"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "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) contract := bind.NewBoundContract(address, abi, nil, nil, nil)
err = contract.UnpackLog(entity, "FlipKick", ethLog) err = contract.UnpackLog(entity, "Kick", ethLog)
if err != nil { if err != nil {
return entity, err return entity, err
} }
@ -54,24 +53,17 @@ func (FlipKickConverter) ToEntity(contractAddress string, contractAbi string, et
} }
func (FlipKickConverter) ToModel(flipKick FlipKickEntity) (FlipKickModel, error) { func (FlipKickConverter) ToModel(flipKick FlipKickEntity) (FlipKickModel, error) {
//TODO: Confirm if the following values can be/ever will be nil
if flipKick.Id == nil { if flipKick.Id == nil {
return FlipKickModel{}, errors.New("FlipKick log ID cannot be nil.") return FlipKickModel{}, errors.New("FlipKick log ID cannot be nil.")
} }
id := flipKick.Id.String() id := flipKick.Id.String()
vat := strings.ToLower(flipKick.Vat.String())
ilk := strings.ToLower(common.ToHex(flipKick.Ilk[:]))
lot := utilities.ConvertNilToEmptyString(flipKick.Lot.String()) lot := utilities.ConvertNilToEmptyString(flipKick.Lot.String())
bid := utilities.ConvertNilToEmptyString(flipKick.Bid.String()) bid := utilities.ConvertNilToEmptyString(flipKick.Bid.String())
guy := strings.ToLower(flipKick.Guy.String()) gal := flipKick.Gal.String()
gal := strings.ToLower(flipKick.Gal.String())
endValue := utilities.ConvertNilToZeroTimeValue(flipKick.End) endValue := utilities.ConvertNilToZeroTimeValue(flipKick.End)
end := time.Unix(endValue, 0) end := time.Unix(endValue, 0)
eraValue := utilities.ConvertNilToZeroTimeValue(flipKick.Era) urn := common.BytesToAddress(flipKick.Urn[:common.AddressLength]).String()
era := time.Unix(eraValue, 0)
lad := strings.ToLower(flipKick.Lad.String())
tab := utilities.ConvertNilToEmptyString(flipKick.Tab.String()) tab := utilities.ConvertNilToEmptyString(flipKick.Tab.String())
rawLogJson, err := json.Marshal(flipKick.Raw) rawLogJson, err := json.Marshal(flipKick.Raw)
if err != nil { if err != nil {
@ -81,15 +73,11 @@ func (FlipKickConverter) ToModel(flipKick FlipKickEntity) (FlipKickModel, error)
return FlipKickModel{ return FlipKickModel{
Id: id, Id: id,
Vat: vat,
Ilk: ilk,
Lot: lot, Lot: lot,
Bid: bid, Bid: bid,
Guy: guy,
Gal: gal, Gal: gal,
End: end, End: end,
Era: era, Urn: urn,
Lad: lad,
Tab: tab, Tab: tab,
Raw: rawLogString, Raw: rawLogString,
}, nil }, nil

View File

@ -33,25 +33,21 @@ var _ = Describe("FlipKick Converter", func() {
Describe("ToEntity", func() { Describe("ToEntity", func() {
It("converts an Eth Log to a FlipKickEntity", 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(err).NotTo(HaveOccurred())
Expect(entity.Id).To(Equal(test_data.FlipKickEntity.Id)) 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.Lot).To(Equal(test_data.FlipKickEntity.Lot))
Expect(entity.Bid).To(Equal(test_data.FlipKickEntity.Bid)) 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.Gal).To(Equal(test_data.FlipKickEntity.Gal))
Expect(entity.End).To(Equal(test_data.FlipKickEntity.End)) Expect(entity.End).To(Equal(test_data.FlipKickEntity.End))
Expect(entity.Era).To(Equal(test_data.FlipKickEntity.Era)) Expect(entity.Urn).To(Equal(test_data.FlipKickEntity.Urn))
Expect(entity.Lad).To(Equal(test_data.FlipKickEntity.Lad))
Expect(entity.Tab).To(Equal(test_data.FlipKickEntity.Tab)) Expect(entity.Tab).To(Equal(test_data.FlipKickEntity.Tab))
Expect(entity.Raw).To(Equal(test_data.FlipKickEntity.Raw)) Expect(entity.Raw).To(Equal(test_data.FlipKickEntity.Raw))
}) })
It("returns an error if converting log to entity fails", func() { 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()) Expect(err).To(HaveOccurred())
}) })
@ -59,7 +55,6 @@ var _ = Describe("FlipKick Converter", func() {
Describe("ToModel", func() { Describe("ToModel", func() {
var emptyAddressHex = "0x0000000000000000000000000000000000000000" var emptyAddressHex = "0x0000000000000000000000000000000000000000"
var emptyByteArrayHex = "0x0000000000000000000000000000000000000000000000000000000000000000"
var emptyString = "" var emptyString = ""
var emptyTime = time.Unix(0, 0) var emptyTime = time.Unix(0, 0)
var emptyEntity = flip_kick.FlipKickEntity{} var emptyEntity = flip_kick.FlipKickEntity{}
@ -87,15 +82,11 @@ var _ = Describe("FlipKick Converter", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(model.Id).To(Equal("1")) 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.Lot).To(Equal(emptyString))
Expect(model.Bid).To(Equal(emptyString)) Expect(model.Bid).To(Equal(emptyString))
Expect(model.Guy).To(Equal(emptyAddressHex))
Expect(model.Gal).To(Equal(emptyAddressHex)) Expect(model.Gal).To(Equal(emptyAddressHex))
Expect(model.End).To(Equal(emptyTime)) Expect(model.End).To(Equal(emptyTime))
Expect(model.Era).To(Equal(emptyTime)) Expect(model.Urn).To(Equal(emptyAddressHex))
Expect(model.Lad).To(Equal(emptyAddressHex))
Expect(model.Tab).To(Equal(emptyString)) Expect(model.Tab).To(Equal(emptyString))
Expect(model.Raw).To(Equal(emptyRawLog)) Expect(model.Raw).To(Equal(emptyRawLog))
}) })

View File

@ -23,15 +23,11 @@ import (
type FlipKickEntity struct { type FlipKickEntity struct {
Id *big.Int Id *big.Int
Vat common.Address
Ilk [32]byte
Lot *big.Int Lot *big.Int
Bid *big.Int Bid *big.Int
Guy common.Address
Gal common.Address Gal common.Address
End *big.Int End *big.Int
Era *big.Int Urn [32]byte
Lad common.Address
Tab *big.Int Tab *big.Int
Raw types.Log Raw types.Log
} }

View File

@ -17,51 +17,18 @@ package flip_kick_test
import ( import (
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common" "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/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/geth" "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/flip_kick"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/test_config"
) )
var _ = Describe("Integration tests", func() { 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() { It("unpacks an event log", func() {
address := common.HexToAddress(test_data.FlipAddress) address := common.HexToAddress(shared.FlipperContractAddress)
abi, err := geth.ParseAbi(shared.FlipperABI) abi, err := geth.ParseAbi(shared.FlipperABI)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
@ -70,20 +37,16 @@ var _ = Describe("Integration tests", func() {
var eventLog = test_data.EthFlipKickLog var eventLog = test_data.EthFlipKickLog
err = contract.UnpackLog(entity, "FlipKick", eventLog) err = contract.UnpackLog(entity, "Kick", eventLog)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
expectedEntity := test_data.FlipKickEntity expectedEntity := test_data.FlipKickEntity
Expect(entity.Id).To(Equal(expectedEntity.Id)) 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.Lot).To(Equal(expectedEntity.Lot))
Expect(entity.Bid).To(Equal(expectedEntity.Bid)) Expect(entity.Bid).To(Equal(expectedEntity.Bid))
Expect(entity.Guy).To(Equal(expectedEntity.Guy))
Expect(entity.Gal).To(Equal(expectedEntity.Gal)) Expect(entity.Gal).To(Equal(expectedEntity.Gal))
Expect(entity.End).To(Equal(expectedEntity.End)) Expect(entity.End).To(Equal(expectedEntity.End))
Expect(entity.Era).To(Equal(expectedEntity.Era)) Expect(entity.Urn).To(Equal(expectedEntity.Urn))
Expect(entity.Lad).To(Equal(expectedEntity.Lad))
Expect(entity.Tab).To(Equal(expectedEntity.Tab)) Expect(entity.Tab).To(Equal(expectedEntity.Tab))
}) })
}) })

View File

@ -18,15 +18,11 @@ import "time"
type FlipKickModel struct { type FlipKickModel struct {
Id string Id string
Vat string
Ilk string
Lot string Lot string
Bid string Bid string
Guy string
Gal string Gal string
End time.Time End time.Time
Era time.Time Urn string
Lad string
Tab string Tab string
Raw string `db:"raw_log"` Raw string `db:"raw_log"`
} }

View File

@ -35,9 +35,9 @@ func NewFlipKickRepository(db *postgres.DB) FlipKickRepository {
} }
func (fkr FlipKickRepository) Create(headerId int64, flipKick FlipKickModel) error { func (fkr FlipKickRepository) Create(headerId int64, flipKick FlipKickModel) error {
_, err := fkr.DB.Exec( _, err := fkr.DB.Exec(
`INSERT into maker.flip_kick (header_id, id, vat, ilk, lot, bid, guy, gal, "end", era, lad, tab, raw_log) `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, $10, $11, $12, $13)`, VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
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, headerId, flipKick.Id, flipKick.Lot, flipKick.Bid, flipKick.Gal, flipKick.End, flipKick.Urn, flipKick.Tab, flipKick.Raw,
) )
if err != nil { if err != nil {

View File

@ -65,17 +65,13 @@ var _ = Describe("FlipKick Repository", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(dbResult.HeaderId).To(Equal(headerId)) Expect(dbResult.HeaderId).To(Equal(headerId))
Expect(dbResult.Id).To(Equal(flipKick.Id)) 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.Lot).To(Equal(flipKick.Lot))
Expect(dbResult.Bid).To(Equal(flipKick.Bid)) Expect(dbResult.Bid).To(Equal(flipKick.Bid))
Expect(dbResult.Guy).To(Equal(flipKick.Guy))
Expect(dbResult.Gal).To(Equal(flipKick.Gal)) Expect(dbResult.Gal).To(Equal(flipKick.Gal))
Expect(dbResult.End.Equal(flipKick.End)).To(BeTrue()) Expect(dbResult.End.Equal(flipKick.End)).To(BeTrue())
Expect(dbResult.Era.Equal(flipKick.Era)).To(BeTrue()) Expect(dbResult.Urn).To(Equal(flipKick.Urn))
Expect(dbResult.Lad).To(Equal(flipKick.Lad))
Expect(dbResult.Tab).To(Equal(flipKick.Tab)) 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() { It("returns an error if inserting the flip_kick record fails", func() {

File diff suppressed because one or more lines are too long

View File

@ -17,9 +17,9 @@ package tend
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
var TendConfig = shared.TransformerConfig{ var TendConfig = shared.TransformerConfig{
ContractAddresses: "0x08cb6176addcca2e1d1ffe21bee464b72ee4cd8d", //this is a temporary address deployed locally ContractAddresses: shared.FlipperContractAddress,
ContractAbi: shared.FlipperABI, ContractAbi: shared.FlipperABI,
Topics: []string{shared.TendSignature}, Topics: []string{shared.TendFunctionSignature},
StartingBlockNumber: 0, StartingBlockNumber: 0,
EndingBlockNumber: 100, EndingBlockNumber: 100,
} }

View File

@ -16,61 +16,37 @@ package tend
import ( import (
"encoding/json" "encoding/json"
"errors" "math/big"
"time"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/vulcanize/vulcanizedb/pkg/geth"
"github.com/vulcanize/vulcanizedb/pkg/transformers/utilities"
) )
type Converter interface { type Converter interface {
ToEntity(contractAddress string, contractAbi string, ethLog types.Log) (TendEntity, error) Convert(contractAddress string, contractAbi string, ethLog types.Log) (TendModel, error)
ToModel(entity TendEntity) (TendModel, error)
} }
type TendConverter struct{} type TendConverter struct{}
func (c TendConverter) ToEntity(contractAddress string, contractAbi string, ethLog types.Log) (TendEntity, error) { func (c TendConverter) Convert(contractAddress string, contractAbi string, ethLog types.Log) (TendModel, error) {
entity := TendEntity{} entity := TendModel{}
address := common.HexToAddress(contractAddress) entity.Guy = common.HexToAddress(ethLog.Topics[1].Hex()).String()
abi, err := geth.ParseAbi(contractAbi) entity.BidId = ethLog.Topics[2].Big().String()
entity.Lot = ethLog.Topics[3].Big().String()
if err != nil { itemByteLength := 32
return entity, err lastDataItemStartIndex := len(ethLog.Data) - itemByteLength
} lastItem := ethLog.Data[lastDataItemStartIndex:]
last := big.NewInt(0).SetBytes(lastItem)
entity.Bid = last.String()
contract := bind.NewBoundContract(address, abi, nil, nil, nil) entity.Tic = "0" //TODO: how do we get the bid tic?
err = contract.UnpackLog(&entity, "Tend", ethLog)
if err != nil {
return entity, err
}
entity.TransactionIndex = ethLog.TxIndex entity.TransactionIndex = ethLog.TxIndex
entity.Raw = ethLog rawJson, err := json.Marshal(ethLog)
return entity, nil
}
func (c TendConverter) ToModel(entity TendEntity) (TendModel, error) {
if entity.Id == nil {
return TendModel{}, errors.New("Tend log ID cannot be nil.")
}
rawJson, err := json.Marshal(entity.Raw)
if err != nil { if err != nil {
return TendModel{}, err return TendModel{}, err
} }
era := utilities.ConvertNilToZeroTimeValue(entity.Era)
return TendModel{ entity.Raw = string(rawJson)
Id: utilities.ConvertNilToEmptyString(entity.Id.String()), return entity, err
Lot: utilities.ConvertNilToEmptyString(entity.Lot.String()),
Bid: utilities.ConvertNilToEmptyString(entity.Bid.String()),
Guy: entity.Guy[:],
Tic: utilities.ConvertNilToEmptyString(entity.Tic.String()),
Era: time.Unix(era, 0),
TransactionIndex: entity.TransactionIndex,
Raw: string(rawJson),
}, nil
} }

View File

@ -15,11 +15,6 @@
package tend_test package tend_test
import ( import (
"encoding/json"
"math/big"
"time"
"github.com/ethereum/go-ethereum/core/types"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
@ -30,74 +25,16 @@ import (
var _ = Describe("Tend TendConverter", func() { var _ = Describe("Tend TendConverter", func() {
var converter tend.TendConverter var converter tend.TendConverter
var emptyEntity tend.TendEntity
var testEntity tend.TendEntity
BeforeEach(func() { BeforeEach(func() {
converter = tend.TendConverter{} converter = tend.TendConverter{}
emptyEntity = tend.TendEntity{}
testEntity = test_data.TendEntity
}) })
Describe("ToEntity", func() { Describe("Convert", func() {
It("converts a log to an entity", func() { It("converts an eth log to a db model", func() {
entity, err := converter.ToEntity(test_data.FlipAddress, shared.FlipperABI, test_data.TendLog) model, err := converter.Convert(shared.FlipperContractAddress, shared.FlipperABI, test_data.TendLogNote)
Expect(err).NotTo(HaveOccurred())
Expect(entity).To(Equal(testEntity))
})
It("returns an error if there is a failure in parsing the abi", func() {
malformedAbi := "bad"
entity, err := converter.ToEntity(test_data.FlipAddress, malformedAbi, test_data.TendLog)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("invalid abi"))
Expect(entity).To(Equal(emptyEntity))
})
It("returns an error if there is a failure unpacking the log", func() {
incompleteAbi := "[{}]"
entity, err := converter.ToEntity(test_data.FlipAddress, incompleteAbi, test_data.TendLog)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("abi: could not locate"))
Expect(entity).To(Equal(emptyEntity))
})
})
Describe("ToModel", func() {
It("converts an entity to a model", func() {
model, err := converter.ToModel(testEntity)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(model).To(Equal(test_data.TendModel)) Expect(model).To(Equal(test_data.TendModel))
}) })
It("handles nil values", func() {
emptyEntity.Id = big.NewInt(1)
emptyLog, err := json.Marshal(types.Log{})
Expect(err).NotTo(HaveOccurred())
expectedModel := tend.TendModel{
Id: "1",
Lot: "",
Bid: "",
Guy: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Tic: "",
Era: time.Unix(0, 0),
Raw: string(emptyLog),
}
model, err := converter.ToModel(emptyEntity)
Expect(err).NotTo(HaveOccurred())
Expect(model).To(Equal(expectedModel))
})
It("returns an error if the log Id is nil", func() {
model, err := converter.ToModel(emptyEntity)
Expect(err).To(HaveOccurred())
Expect(model).To(Equal(tend.TendModel{}))
})
}) })
}) })

View File

@ -1,33 +0,0 @@
// 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 tend
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
type TendEntity struct {
Id *big.Int
Lot *big.Int
Bid *big.Int
Guy common.Address
Tic *big.Int
Era *big.Int
TransactionIndex uint
Raw types.Log
}

View File

@ -15,7 +15,6 @@
package tend_test package tend_test
import ( import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
@ -27,14 +26,13 @@ import (
rpc2 "github.com/vulcanize/vulcanizedb/pkg/geth/converters/rpc" rpc2 "github.com/vulcanize/vulcanizedb/pkg/geth/converters/rpc"
"github.com/vulcanize/vulcanizedb/pkg/geth/node" "github.com/vulcanize/vulcanizedb/pkg/geth/node"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/tend"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
) )
// These test are pending either being able to emit a Tend event on a Ganache test chain or until the contracts are deployed to Kovan. // These test are marked as pending until the Flip contract is deployed to Kovan.
var _ = XDescribe("Integration tests", func() { var _ = Describe("Integration tests", func() {
It("Fetches Tend event logs from a local test chain", func() { XIt("Fetches Tend event logs from a local test chain", func() {
ipcPath := test_config.TestClient.IPCPath ipcPath := test_config.TestClient.IPCPath
rawRpcClient, err := rpc.Dial(ipcPath) rawRpcClient, err := rpc.Dial(ipcPath)
@ -47,10 +45,10 @@ var _ = XDescribe("Integration tests", func() {
transactionConverter := rpc2.NewRpcTransactionConverter(ethClient) transactionConverter := rpc2.NewRpcTransactionConverter(ethClient)
realBlockChain := geth.NewBlockChain(blockChainClient, realNode, transactionConverter) realBlockChain := geth.NewBlockChain(blockChainClient, realNode, transactionConverter)
realFetcher := shared.NewFetcher(realBlockChain) realFetcher := shared.NewFetcher(realBlockChain)
topic0 := common.HexToHash(shared.TendSignature) topic0 := common.HexToHash(shared.TendFunctionSignature)
topics := [][]common.Hash{{topic0}} topics := [][]common.Hash{{topic0}}
result, err := realFetcher.FetchLogs(test_data.FlipAddress, topics, test_data.FlipKickBlockNumber) result, err := realFetcher.FetchLogs(shared.FlipperContractAddress, topics, test_data.FlipKickBlockNumber)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(len(result) > 0).To(BeTrue()) Expect(len(result) > 0).To(BeTrue())
@ -60,27 +58,4 @@ var _ = XDescribe("Integration tests", func() {
Expect(result[0].Topics).To(Equal(test_data.EthFlipKickLog.Topics)) Expect(result[0].Topics).To(Equal(test_data.EthFlipKickLog.Topics))
Expect(result[0].Index).To(Equal(test_data.EthFlipKickLog.Index)) Expect(result[0].Index).To(Equal(test_data.EthFlipKickLog.Index))
}) })
It("unpacks an event log", func() {
address := common.HexToAddress(test_data.FlipAddress)
abi, err := geth.ParseAbi(shared.FlipperABI)
Expect(err).NotTo(HaveOccurred())
contract := bind.NewBoundContract(address, abi, nil, nil, nil)
entity := tend.TendEntity{}
var eventLog = test_data.TendLog
err = contract.UnpackLog(&entity, "Tend", eventLog)
Expect(err).NotTo(HaveOccurred())
expectedEntity := test_data.TendEntity
Expect(entity.Id).To(Equal(expectedEntity.Id))
Expect(entity.Lot).To(Equal(expectedEntity.Lot))
Expect(entity.Bid).To(Equal(expectedEntity.Bid))
Expect(entity.Guy).To(Equal(expectedEntity.Guy))
Expect(entity.Tic).To(Equal(expectedEntity.Tic))
Expect(entity.Era).To(Equal(expectedEntity.Era))
Expect(entity.Raw).To(Equal(expectedEntity.Raw))
})
}) })

View File

@ -14,17 +14,12 @@
package tend package tend
import (
"time"
)
type TendModel struct { type TendModel struct {
Id string BidId string `db:"bid_id"`
Lot string Lot string
Bid string Bid string
Guy []byte Guy string
Tic string Tic string
Era time.Time
TransactionIndex uint `db:"tx_idx"` TransactionIndex uint `db:"tx_idx"`
Raw string `db:"raw_log"` Raw string `db:"raw_log"`
} }

View File

@ -34,9 +34,9 @@ func NewTendRepository(db *postgres.DB) TendRepository {
func (r TendRepository) Create(headerId int64, tend TendModel) error { func (r TendRepository) Create(headerId int64, tend TendModel) error {
_, err := r.DB.Exec( _, err := r.DB.Exec(
`INSERT into maker.tend (header_id, id, lot, bid, guy, tic, era, tx_idx, raw_log) `INSERT into maker.tend (header_id, bid_id, lot, bid, guy, tic, tx_idx, raw_log)
VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9)`, VALUES($1, $2, $3, $4, $5, $6, $7, $8)`,
headerId, tend.Id, tend.Lot, tend.Bid, tend.Guy, tend.Tic, tend.Era, tend.TransactionIndex, tend.Raw, headerId, tend.BidId, tend.Lot, tend.Bid, tend.Guy, tend.Tic, tend.TransactionIndex, tend.Raw,
) )
return err return err

View File

@ -58,17 +58,16 @@ var _ = Describe("TendRepository", func() {
Expect(count).To(Equal(1)) Expect(count).To(Equal(1))
dbResult := tend.TendModel{} dbResult := tend.TendModel{}
err = db.Get(&dbResult, `SELECT id, lot, bid, guy, tic, era, tx_idx, raw_log FROM maker.tend WHERE header_id = $1`, headerId) err = db.Get(&dbResult, `SELECT bid_id, lot, bid, guy, tic, tx_idx, raw_log FROM maker.tend WHERE header_id = $1`, headerId)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(dbResult.Id).To(Equal(test_data.TendModel.Id)) Expect(dbResult.BidId).To(Equal(test_data.TendModel.BidId))
Expect(dbResult.Lot).To(Equal(test_data.TendModel.Lot)) Expect(dbResult.Lot).To(Equal(test_data.TendModel.Lot))
Expect(dbResult.Bid).To(Equal(test_data.TendModel.Bid)) Expect(dbResult.Bid).To(Equal(test_data.TendModel.Bid))
Expect(dbResult.Guy).To(Equal(test_data.TendModel.Guy)) Expect(dbResult.Guy).To(Equal(test_data.TendModel.Guy))
Expect(dbResult.Tic).To(Equal(test_data.TendModel.Tic)) Expect(dbResult.Tic).To(Equal(test_data.TendModel.Tic))
Expect(dbResult.Era.Equal(test_data.TendModel.Era)).To(BeTrue())
Expect(dbResult.TransactionIndex).To(Equal(test_data.TendModel.TransactionIndex)) Expect(dbResult.TransactionIndex).To(Equal(test_data.TendModel.TransactionIndex))
Expect(dbResult.Raw).To(MatchJSON(test_data.RawJson)) Expect(dbResult.Raw).To(MatchJSON(test_data.RawLogNoteJson))
}) })
It("returns an error if inserting a tend record fails", func() { It("returns an error if inserting a tend record fails", func() {
@ -111,7 +110,7 @@ var _ = Describe("TendRepository", func() {
outOfRangeBlockNumber = tendBlockNumber + 2 outOfRangeBlockNumber = tendBlockNumber + 2
}) })
It("returns headers for which there isn't an associated flip_kick record", func() { It("returns headers for which there isn't an associated tend record", func() {
var headerIds []int64 var headerIds []int64
for _, number := range []int64{startingBlockNumber, tendBlockNumber, endingBlockNumber, outOfRangeBlockNumber} { for _, number := range []int64{startingBlockNumber, tendBlockNumber, endingBlockNumber, outOfRangeBlockNumber} {

View File

@ -50,7 +50,7 @@ func (i TendTransformerInitializer) NewTendTransformer(db *postgres.DB, blockCha
func (t TendTransformer) Execute() error { func (t TendTransformer) Execute() error {
config := t.Config config := t.Config
topics := [][]common.Hash{{common.HexToHash(shared.TendSignature)}} topics := [][]common.Hash{{common.HexToHash(shared.TendFunctionSignature)}}
missingHeaders, err := t.Repository.MissingHeaders(config.StartingBlockNumber, config.EndingBlockNumber) missingHeaders, err := t.Repository.MissingHeaders(config.StartingBlockNumber, config.EndingBlockNumber)
if err != nil { if err != nil {
@ -66,8 +66,7 @@ func (t TendTransformer) Execute() error {
} }
for _, ethLog := range ethLogs { for _, ethLog := range ethLogs {
entity, err := t.Converter.ToEntity(config.ContractAddresses, config.ContractAbi, ethLog) model, err := t.Converter.Convert(config.ContractAddresses, config.ContractAbi, ethLog)
model, err := t.Converter.ToModel(entity)
if err != nil { if err != nil {
log.Println("Error converting logs:", err) log.Println("Error converting logs:", err)
return err return err

View File

@ -69,13 +69,13 @@ var _ = Describe("Tend Transformer", func() {
It("fetches eth logs for each missing header", func() { It("fetches eth logs for each missing header", func() {
repository.SetMissingHeaders([]core.Header{{BlockNumber: blockNumber1}, {BlockNumber: blockNumber2}}) repository.SetMissingHeaders([]core.Header{{BlockNumber: blockNumber1}, {BlockNumber: blockNumber2}})
expectedTopics := [][]common.Hash{{common.HexToHash(shared.TendSignature)}} expectedTopics := [][]common.Hash{{common.HexToHash(shared.TendFunctionSignature)}}
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(fetcher.FetchedBlocks).To(Equal([]int64{blockNumber1, blockNumber2})) Expect(fetcher.FetchedBlocks).To(Equal([]int64{blockNumber1, blockNumber2}))
Expect(fetcher.FetchedTopics).To(Equal(expectedTopics)) Expect(fetcher.FetchedTopics).To(Equal(expectedTopics))
Expect(fetcher.FetchedContractAddress).To(Equal(test_data.FlipAddress)) Expect(fetcher.FetchedContractAddress).To(Equal(shared.FlipperContractAddress))
}) })
It("returns an error if fetching logs fails", func() { It("returns an error if fetching logs fails", func() {
@ -87,40 +87,30 @@ var _ = Describe("Tend Transformer", func() {
Expect(err).To(MatchError(fakes.FakeError)) Expect(err).To(MatchError(fakes.FakeError))
}) })
It("converts an eth log to an Entity", func() { It("converts an eth log to an Model", func() {
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
fetcher.SetFetchedLogs([]types.Log{test_data.TendLog}) fetcher.SetFetchedLogs([]types.Log{test_data.TendLogNote})
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(converter.ConverterContract).To(Equal(tend.TendConfig.ContractAddresses)) Expect(converter.ConverterContract).To(Equal(tend.TendConfig.ContractAddresses))
Expect(converter.ConverterAbi).To(Equal(tend.TendConfig.ContractAbi)) Expect(converter.ConverterAbi).To(Equal(tend.TendConfig.ContractAbi))
Expect(converter.LogsToConvert).To(Equal([]types.Log{test_data.TendLog})) Expect(converter.LogsToConvert).To(Equal([]types.Log{test_data.TendLogNote}))
}) })
It("returns an error if converter fails", func() { It("returns an error if converter fails", func() {
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
fetcher.SetFetchedLogs([]types.Log{test_data.TendLog}) fetcher.SetFetchedLogs([]types.Log{test_data.TendLogNote})
converter.SetConverterError(fakes.FakeError) converter.SetConverterError(fakes.FakeError)
err := transformer.Execute() err := transformer.Execute()
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(fakes.FakeError)) Expect(err).To(MatchError(fakes.FakeError))
}) })
It("returns an error if converter fails", func() {
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
fetcher.SetFetchedLogs([]types.Log{test_data.TendLog})
err := transformer.Execute()
Expect(err).NotTo(HaveOccurred())
Expect(converter.EntitiesToConvert).To(ContainElement(test_data.TendEntity))
})
It("persists the tend record", func() { It("persists the tend record", func() {
headerId := int64(1) headerId := int64(1)
repository.SetMissingHeaders([]core.Header{{BlockNumber: blockNumber1, Id: headerId}}) repository.SetMissingHeaders([]core.Header{{BlockNumber: blockNumber1, Id: headerId}})
fetcher.SetFetchedLogs([]types.Log{test_data.TendLog}) fetcher.SetFetchedLogs([]types.Log{test_data.TendLogNote})
err := transformer.Execute() err := transformer.Execute()
@ -131,7 +121,7 @@ var _ = Describe("Tend Transformer", func() {
It("returns error if persisting tend record fails", func() { It("returns error if persisting tend record fails", func() {
repository.SetMissingHeaders([]core.Header{{BlockNumber: blockNumber1}}) repository.SetMissingHeaders([]core.Header{{BlockNumber: blockNumber1}})
fetcher.SetFetchedLogs([]types.Log{test_data.TendLog}) fetcher.SetFetchedLogs([]types.Log{test_data.TendLogNote})
repository.SetCreateError(fakes.FakeError) repository.SetCreateError(fakes.FakeError)
err := transformer.Execute() err := transformer.Execute()

View File

@ -1,27 +0,0 @@
// 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 test_data
var (
FlipAddress = "0x08cb6176addcca2e1d1ffe21bee464b72ee4cd8d"
FlipKickTransactionHash = "0x6b155a55fd77b751195deeebf7abfd8691ca01ee588817a920f19d5b27f65191"
FlipKickData = "0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000038219779a699d67d7e7740b8c8f43d3e2dae218266616b6520696c6b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064d922894153be9eef7b7218dc565d1d0ce2a09200000000000000000000000007fa9ef6609ca7921112231f8f195138ebba2977000000000000000000000000000000000000000000000000000000005b8063b7000000000000000000000000000000000000000000000000000000005b7729370000000000000000000000007340e006f4135ba6970d43bf43d88dcad4e7a8ca0000000000000000000000000000000000000000000000000000000000000032"
FlipKickBlockHash = "0x32f8b12023b3a1b4c73f9a46da976931b0355714ada8b8044ebcb2cd295751a9"
FlipKickBlockNumber = int64(10)
TendData = "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000003200000000000000000000000064d922894153be9eef7b7218dc565d1d0ce2a0920000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005b6db414"
TendTransactionHash = "0xadeddf804e0fef88b6145807df063c538c9942df2725a0458a084900c0fbf5e9"
TendBlockHash = "0xdd6238b841c8cf4d91b05da7540b7f0851176fcc8477cdc4b75c93e28dfe0a88"
TendBlockNumber = int64(11)
)

View File

@ -27,62 +27,64 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
) )
var idString = "1" var (
var id, _ = new(big.Int).SetString(idString, 10) idString = "1"
var vat = "0x38219779a699d67d7e7740b8c8f43d3e2dae2182" id, _ = new(big.Int).SetString(idString, 10)
var ilk = [32]byte{102, 97, 107, 101, 32, 105, 108, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} lotString = "100"
var lotString = "100" lot, _ = new(big.Int).SetString(lotString, 10)
var lot, _ = new(big.Int).SetString(lotString, 10) bidString = "0"
var bidString = "0" bid = new(big.Int).SetBytes([]byte{0})
var bid = new(big.Int).SetBytes([]byte{0}) gal = "0x07Fa9eF6609cA7921112231F8f195138ebbA2977"
var guy = "0x64d922894153be9eef7b7218dc565d1d0ce2a092" end = int64(1535991025)
var gal = "0x07fa9ef6609ca7921112231f8f195138ebba2977" urn = [32]byte{115, 64, 224, 6, 244, 19, 91, 166, 151, 13, 67, 191, 67, 216, 141, 202, 212, 231, 168, 202, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
var end = int64(1535140791) urnString = "0x7340e006f4135BA6970D43bf43d88DCAD4e7a8CA"
var era = int64(1534535991) tabString = "50"
var lad = "0x7340e006f4135ba6970d43bf43d88dcad4e7a8ca" tab, _ = new(big.Int).SetString(tabString, 10)
var tabString = "50" rawLogJson, _ = json.Marshal(EthFlipKickLog)
var tab, _ = new(big.Int).SetString(tabString, 10) rawLogString = string(rawLogJson)
var rawLogJson, _ = json.Marshal(EthFlipKickLog) )
var rawLogString = string(rawLogJson)
var (
flipKickTransactionHash = "0xd11ab35cfb1ad71f790d3dd488cc1a2046080e765b150e8997aa0200947d4a9b"
flipKickData = "0x0000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007fa9ef6609ca7921112231f8f195138ebba2977000000000000000000000000000000000000000000000000000000005b8d5cf10000000000000000000000000000000000000000000000000000000000000032"
flipKickBlockHash = "0x40fcad7863ab4bef421d638b7ad6116e81577f14a62ef847b07f8527944466fd"
FlipKickBlockNumber = int64(10)
)
var EthFlipKickLog = types.Log{ var EthFlipKickLog = types.Log{
Address: common.HexToAddress(FlipAddress), Address: common.HexToAddress(shared.FlipperContractAddress),
Topics: []common.Hash{common.HexToHash(shared.FlipKickSignature)}, Topics: []common.Hash{
Data: hexutil.MustDecode(FlipKickData), common.HexToHash(shared.FlipKickSignature),
common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000001"),
common.HexToHash("0x7340e006f4135ba6970d43bf43d88dcad4e7a8ca000000000000000000000000"),
},
Data: hexutil.MustDecode(flipKickData),
BlockNumber: uint64(FlipKickBlockNumber), BlockNumber: uint64(FlipKickBlockNumber),
TxHash: common.HexToHash(FlipKickTransactionHash), TxHash: common.HexToHash(flipKickTransactionHash),
TxIndex: 0, TxIndex: 0,
BlockHash: common.HexToHash(FlipKickBlockHash), BlockHash: common.HexToHash(flipKickBlockHash),
Index: 0, Index: 0,
Removed: false, Removed: false,
} }
var FlipKickEntity = flip_kick.FlipKickEntity{ var FlipKickEntity = flip_kick.FlipKickEntity{
Id: id, Id: id,
Vat: common.HexToAddress(vat),
Ilk: ilk,
Lot: lot, Lot: lot,
Bid: bid, Bid: bid,
Guy: common.HexToAddress(guy),
Gal: common.HexToAddress(gal), Gal: common.HexToAddress(gal),
End: big.NewInt(end), End: big.NewInt(end),
Era: big.NewInt(era), Urn: urn,
Lad: common.HexToAddress(lad),
Tab: tab, Tab: tab,
Raw: EthFlipKickLog, Raw: EthFlipKickLog,
} }
var FlipKickModel = flip_kick.FlipKickModel{ var FlipKickModel = flip_kick.FlipKickModel{
Id: idString, Id: idString,
Vat: vat,
Ilk: "0x" + common.Bytes2Hex(ilk[:]),
Lot: lotString, Lot: lotString,
Bid: bidString, Bid: bidString,
Guy: guy,
Gal: gal, Gal: gal,
End: time.Unix(end, 0), End: time.Unix(end, 0),
Era: time.Unix(era, 0), Urn: urnString,
Lad: lad,
Tab: tabString, Tab: tabString,
Raw: rawLogString, Raw: rawLogString,
} }

View File

@ -39,6 +39,7 @@ var (
frobLad = [32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 217, 34, 137, 65, 83, 190, 158, 239, 123, 114, 24, 220, 86, 93, 29, 12, 226, 160, 146} frobLad = [32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 217, 34, 137, 65, 83, 190, 158, 239, 123, 114, 24, 220, 86, 93, 29, 12, 226, 160, 146}
gem, _ = big.NewInt(0).SetString("115792089237316195423570985008687907853269984665640564039457584007913129639926", 10) gem, _ = big.NewInt(0).SetString("115792089237316195423570985008687907853269984665640564039457584007913129639926", 10)
ink = big.NewInt(15) ink = big.NewInt(15)
ilk = [32]byte{102, 97, 107, 101, 32, 105, 108, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
) )
var EthFrobLog = types.Log{ var EthFrobLog = types.Log{

View File

@ -16,6 +16,7 @@ package flip_kick
import ( import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick" "github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
) )

View File

@ -25,19 +25,13 @@ type MockTendConverter struct {
ConverterContract string ConverterContract string
ConverterAbi string ConverterAbi string
LogsToConvert []types.Log LogsToConvert []types.Log
EntitiesToConvert []tend.TendEntity
ConverterError error ConverterError error
} }
func (c *MockTendConverter) ToEntity(contractAddress string, contractAbi string, ethLog types.Log) (tend.TendEntity, error) { func (c *MockTendConverter) Convert(contractAddress string, contractAbi string, ethLog types.Log) (tend.TendModel, error) {
c.ConverterContract = contractAddress c.ConverterContract = contractAddress
c.ConverterAbi = contractAbi c.ConverterAbi = contractAbi
c.LogsToConvert = append(c.LogsToConvert, ethLog) c.LogsToConvert = append(c.LogsToConvert, ethLog)
return test_data.TendEntity, c.ConverterError
}
func (c *MockTendConverter) ToModel(entity tend.TendEntity) (tend.TendModel, error) {
c.EntitiesToConvert = append(c.EntitiesToConvert, entity)
return test_data.TendModel, c.ConverterError return test_data.TendModel, c.ConverterError
} }

View File

@ -18,7 +18,6 @@ import (
"encoding/json" "encoding/json"
"math/big" "math/big"
"strconv" "strconv"
"time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
@ -28,45 +27,41 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/tend" "github.com/vulcanize/vulcanizedb/pkg/transformers/tend"
) )
var tendLot = big.NewInt(100) var (
var tendBid = big.NewInt(50) tendId = int64(10)
var tendGuy = common.HexToAddress("0x64d922894153be9eef7b7218dc565d1d0ce2a092") tendLot = "85000000000000000000"
var tic = new(big.Int).SetBytes([]byte{0}) tendBid = "1000000000000000000"
var tendEra = big.NewInt(1533916180) tendGuy = "0x7d7bEe5fCfD8028cf7b00876C5b1421c800561A6"
var RawJson, _ = json.Marshal(TendLog) tic = new(big.Int).SetBytes([]byte{0})
var rawString = string(RawJson) tendData = "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000644b43ed12000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000049b9ca9a6943400000000000000000000000000000000000000000000000000000de0b6b3a7640000"
tendTransactionHash = "0x7909c8793ded2b8348f5db623044fbc26bb7ab78ad5792897abdf68ddc1df63d"
tendBlockHash = "0xa8ea87147c0a68daeb6b1d9f8c0937ba975a650809cab80d19c969e8d0df452c"
)
var TendLog = types.Log{ var TendLogNote = types.Log{
Address: common.HexToAddress(FlipAddress), Address: common.StringToAddress(shared.FlipperContractAddress),
Topics: []common.Hash{common.HexToHash(shared.TendSignature)}, Topics: []common.Hash{
Data: hexutil.MustDecode(TendData), common.HexToHash("0x4b43ed1200000000000000000000000000000000000000000000000000000000"), //abbreviated tend function signature
BlockNumber: uint64(TendBlockNumber), common.HexToHash("0x0000000000000000000000007d7bee5fcfd8028cf7b00876c5b1421c800561a6"), //msg caller address
TxHash: common.HexToHash(TendTransactionHash), common.HexToHash("0x000000000000000000000000000000000000000000000000000000000000000a"), //first param of the function called (i.e. flip kick id)
TxIndex: 1, common.HexToHash("0x0000000000000000000000000000000000000000000000049b9ca9a694340000"), //second param of the function called (i.e. lot)
BlockHash: common.HexToHash(TendBlockHash), },
Index: 0, Data: hexutil.MustDecode(tendData),
BlockNumber: 11,
TxHash: common.HexToHash(tendTransactionHash),
TxIndex: 10,
BlockHash: common.HexToHash(tendBlockHash),
Index: 1,
Removed: false, Removed: false,
} }
var RawLogNoteJson, _ = json.Marshal(TendLogNote)
var tendId = int64(1) var TendModel = tend.TendModel{
var TendEntity = tend.TendEntity{ BidId: strconv.FormatInt(tendId, 10),
Id: big.NewInt(tendId),
Lot: tendLot, Lot: tendLot,
Bid: tendBid, Bid: tendBid,
Guy: tendGuy, Guy: tendGuy,
Tic: tic,
Era: tendEra,
TransactionIndex: TendLog.TxIndex,
Raw: TendLog,
}
var TendModel = tend.TendModel{
Id: strconv.FormatInt(tendId, 10),
Lot: tendLot.String(),
Bid: tendBid.String(),
Guy: tendGuy[:],
Tic: tic.String(), Tic: tic.String(),
Era: time.Unix(tendEra.Int64(), 0), TransactionIndex: TendLogNote.TxIndex,
TransactionIndex: TendLog.TxIndex, Raw: string(RawLogNoteJson),
Raw: rawString,
} }