From db4b8913988eebfbc9dc18c1102559c1861f1bc6 Mon Sep 17 00:00:00 2001 From: Rob Mulholand Date: Wed, 29 Aug 2018 09:12:29 -0500 Subject: [PATCH 1/5] Backfill Pit.file log events --- .../1535667935_create_pit_file_table.down.sql | 1 + .../1535667935_create_pit_file_table.up.sql | 10 ++ db/schema.sql | 66 +++++++ pkg/transformers/bite/bite_suite_test.go | 6 + pkg/transformers/bite/config.go | 2 +- pkg/transformers/bite/transformer.go | 4 +- pkg/transformers/bite/transfromer_test.go | 6 +- pkg/transformers/flip_kick/config.go | 2 +- pkg/transformers/flip_kick/transformer.go | 4 +- .../flip_kick/transformer_test.go | 6 +- pkg/transformers/frob/config.go | 2 +- pkg/transformers/frob/transformer.go | 4 +- pkg/transformers/frob/transformer_test.go | 4 +- pkg/transformers/pit_file/config.go | 13 ++ pkg/transformers/pit_file/converter.go | 32 ++++ pkg/transformers/pit_file/converter_test.go | 20 +++ pkg/transformers/pit_file/model.go | 9 + .../pit_file/pit_file_suite_test.go | 13 ++ pkg/transformers/pit_file/repository.go | 48 ++++++ pkg/transformers/pit_file/repository_test.go | 130 ++++++++++++++ pkg/transformers/pit_file/transformer.go | 56 ++++++ pkg/transformers/pit_file/transformer_test.go | 162 ++++++++++++++++++ pkg/transformers/shared/constants.go | 8 +- pkg/transformers/shared/transformer.go | 2 +- pkg/transformers/tend/config.go | 2 +- pkg/transformers/tend/transformer.go | 4 +- pkg/transformers/tend/transformer_test.go | 2 +- .../test_data/mocks/pit_file/converter.go | 26 +++ .../test_data/mocks/pit_file/repository.go | 42 +++++ pkg/transformers/test_data/pit_file.go | 41 +++++ pkg/transformers/transformers.go | 4 + test_config/test_config.go | 1 + 32 files changed, 707 insertions(+), 25 deletions(-) create mode 100644 db/migrations/1535667935_create_pit_file_table.down.sql create mode 100644 db/migrations/1535667935_create_pit_file_table.up.sql create mode 100644 pkg/transformers/pit_file/config.go create mode 100644 pkg/transformers/pit_file/converter.go create mode 100644 pkg/transformers/pit_file/converter_test.go create mode 100644 pkg/transformers/pit_file/model.go create mode 100644 pkg/transformers/pit_file/pit_file_suite_test.go create mode 100644 pkg/transformers/pit_file/repository.go create mode 100644 pkg/transformers/pit_file/repository_test.go create mode 100644 pkg/transformers/pit_file/transformer.go create mode 100644 pkg/transformers/pit_file/transformer_test.go create mode 100644 pkg/transformers/test_data/mocks/pit_file/converter.go create mode 100644 pkg/transformers/test_data/mocks/pit_file/repository.go create mode 100644 pkg/transformers/test_data/pit_file.go diff --git a/db/migrations/1535667935_create_pit_file_table.down.sql b/db/migrations/1535667935_create_pit_file_table.down.sql new file mode 100644 index 00000000..4f92d89f --- /dev/null +++ b/db/migrations/1535667935_create_pit_file_table.down.sql @@ -0,0 +1 @@ +DROP TABLE maker.pit_file; \ No newline at end of file diff --git a/db/migrations/1535667935_create_pit_file_table.up.sql b/db/migrations/1535667935_create_pit_file_table.up.sql new file mode 100644 index 00000000..ff0312b4 --- /dev/null +++ b/db/migrations/1535667935_create_pit_file_table.up.sql @@ -0,0 +1,10 @@ +CREATE TABLE maker.pit_file ( + id SERIAL PRIMARY KEY, + header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, + ilk TEXT, + what TEXT, + risk NUMERIC, + tx_idx INTEGER NOT NUll, + raw_log JSONB, + UNIQUE (header_id, tx_idx) +); \ No newline at end of file diff --git a/db/schema.sql b/db/schema.sql index 761378b1..8cc66b1d 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -155,6 +155,41 @@ CREATE SEQUENCE maker.frob_id_seq ALTER SEQUENCE maker.frob_id_seq OWNED BY maker.frob.id; +-- +-- Name: pit_file; Type: TABLE; Schema: maker; Owner: - +-- + +CREATE TABLE maker.pit_file ( + id integer NOT NULL, + header_id integer NOT NULL, + ilk text, + what text, + risk numeric, + tx_idx integer NOT NULL, + raw_log jsonb +); + + +-- +-- Name: pit_file_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- + +CREATE SEQUENCE maker.pit_file_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: pit_file_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- + +ALTER SEQUENCE maker.pit_file_id_seq OWNED BY maker.pit_file.id; + + -- -- Name: price_feeds; Type: TABLE; Schema: maker; Owner: - -- @@ -619,6 +654,13 @@ ALTER TABLE ONLY maker.flip_kick ALTER COLUMN db_id SET DEFAULT nextval('maker.f ALTER TABLE ONLY maker.frob ALTER COLUMN id SET DEFAULT nextval('maker.frob_id_seq'::regclass); +-- +-- Name: pit_file id; Type: DEFAULT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.pit_file ALTER COLUMN id SET DEFAULT nextval('maker.pit_file_id_seq'::regclass); + + -- -- Name: price_feeds id; Type: DEFAULT; Schema: maker; Owner: - -- @@ -744,6 +786,22 @@ ALTER TABLE ONLY maker.frob ADD CONSTRAINT frob_pkey PRIMARY KEY (id); +-- +-- Name: pit_file pit_file_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.pit_file + ADD CONSTRAINT pit_file_header_id_tx_idx_key UNIQUE (header_id, tx_idx); + + +-- +-- Name: pit_file pit_file_pkey; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.pit_file + ADD CONSTRAINT pit_file_pkey PRIMARY KEY (id); + + -- -- Name: price_feeds price_feeds_header_id_medianizer_address_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: - -- @@ -939,6 +997,14 @@ ALTER TABLE ONLY maker.price_feeds ADD CONSTRAINT headers_fk FOREIGN KEY (header_id) REFERENCES public.headers(id) ON DELETE CASCADE; +-- +-- Name: pit_file pit_file_header_id_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.pit_file + ADD CONSTRAINT pit_file_header_id_fkey FOREIGN KEY (header_id) REFERENCES public.headers(id) ON DELETE CASCADE; + + -- -- Name: tend tend_header_id_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: - -- diff --git a/pkg/transformers/bite/bite_suite_test.go b/pkg/transformers/bite/bite_suite_test.go index ab9920d3..e5a93b26 100644 --- a/pkg/transformers/bite/bite_suite_test.go +++ b/pkg/transformers/bite/bite_suite_test.go @@ -19,9 +19,15 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "io/ioutil" + "log" ) func TestBite(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Bite Suite") } + +var _ = BeforeSuite(func() { + log.SetOutput(ioutil.Discard) +}) diff --git a/pkg/transformers/bite/config.go b/pkg/transformers/bite/config.go index 6c743cf5..f05a5c29 100644 --- a/pkg/transformers/bite/config.go +++ b/pkg/transformers/bite/config.go @@ -21,7 +21,7 @@ import ( ) var BiteConfig = shared.TransformerConfig{ - ContractAddresses: "0xe0f0fa6982c59d8aa4ae0134bfe048327bd788cacf758b643ca41f055ffce76c", //this is a temporary address deployed locally + ContractAddress: "0xe0f0fa6982c59d8aa4ae0134bfe048327bd788cacf758b643ca41f055ffce76c", //this is a temporary address deployed locally ContractAbi: BiteABI, Topics: []string{BiteSignature}, StartingBlockNumber: 0, diff --git a/pkg/transformers/bite/transformer.go b/pkg/transformers/bite/transformer.go index 3f90157d..7a68311a 100644 --- a/pkg/transformers/bite/transformer.go +++ b/pkg/transformers/bite/transformer.go @@ -59,14 +59,14 @@ func (b BiteTransformer) Execute() error { } for _, header := range missingHeaders { - ethLogs, err := b.Fetcher.FetchLogs(config.ContractAddresses, topics, header.BlockNumber) + ethLogs, err := b.Fetcher.FetchLogs(config.ContractAddress, topics, header.BlockNumber) if err != nil { log.Println("Error fetching matching logs:", err) return err } for _, ethLog := range ethLogs { - entity, err := b.Converter.ToEntity(config.ContractAddresses, config.ContractAbi, ethLog) + entity, err := b.Converter.ToEntity(config.ContractAddress, config.ContractAbi, ethLog) model, err := b.Converter.ToModel(entity) if err != nil { log.Println("Error converting logs:", err) diff --git a/pkg/transformers/bite/transfromer_test.go b/pkg/transformers/bite/transfromer_test.go index cdc6c8d9..21e43fbb 100644 --- a/pkg/transformers/bite/transfromer_test.go +++ b/pkg/transformers/bite/transfromer_test.go @@ -53,7 +53,7 @@ var _ = Describe("Bite Transformer", func() { } testConfig = shared.TransformerConfig{ - ContractAddresses: "0x12345", + ContractAddress: "0x12345", ContractAbi: "test abi", Topics: []string{shared.BiteSignature}, StartingBlockNumber: blockNumber1, @@ -85,7 +85,7 @@ var _ = Describe("Bite Transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{blockNumber1, blockNumber2})) Expect(fetcher.FetchedTopics).To(Equal(expectedTopics)) - Expect(fetcher.FetchedContractAddress).To(Equal(bite.BiteConfig.ContractAddresses)) + Expect(fetcher.FetchedContractAddress).To(Equal(bite.BiteConfig.ContractAddress)) }) It("returns an error if fetching logs fails", func() { @@ -103,7 +103,7 @@ var _ = Describe("Bite Transformer", func() { err := transformer.Execute() Expect(err).NotTo(HaveOccurred()) - Expect(converter.ConverterContract).To(Equal(bite.BiteConfig.ContractAddresses)) + Expect(converter.ConverterContract).To(Equal(bite.BiteConfig.ContractAddress)) Expect(converter.ConverterAbi).To(Equal(bite.BiteConfig.ContractAbi)) Expect(converter.LogsToConvert).To(Equal([]types.Log{test_data.EthBiteLog})) }) diff --git a/pkg/transformers/flip_kick/config.go b/pkg/transformers/flip_kick/config.go index 5a34fa93..c5e1448f 100644 --- a/pkg/transformers/flip_kick/config.go +++ b/pkg/transformers/flip_kick/config.go @@ -17,7 +17,7 @@ package flip_kick import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" var FlipKickConfig = shared.TransformerConfig{ - ContractAddresses: shared.FlipperContractAddress, + ContractAddress: shared.FlipperContractAddress, ContractAbi: shared.FlipperABI, Topics: []string{shared.FlipKickSignature}, StartingBlockNumber: 0, diff --git a/pkg/transformers/flip_kick/transformer.go b/pkg/transformers/flip_kick/transformer.go index 0f700b57..a7331073 100644 --- a/pkg/transformers/flip_kick/transformer.go +++ b/pkg/transformers/flip_kick/transformer.go @@ -91,13 +91,13 @@ func (fkt FlipKickTransformer) Execute() error { log.Printf("Fetching event logs for %d headers \n", len(headers)) var resultingErrors []error for _, header := range headers { - ethLogs, err := fkt.Fetcher.FetchLogs(config.ContractAddresses, topics, header.BlockNumber) + ethLogs, err := fkt.Fetcher.FetchLogs(config.ContractAddress, topics, header.BlockNumber) if err != nil { resultingErrors = append(resultingErrors, newTransformerError(err, header.BlockNumber, FetcherError)) } for _, ethLog := range ethLogs { - entity, err := fkt.Converter.ToEntity(config.ContractAddresses, config.ContractAbi, ethLog) + entity, err := fkt.Converter.ToEntity(config.ContractAddress, config.ContractAbi, ethLog) if err != nil { resultingErrors = append(resultingErrors, newTransformerError(err, header.BlockNumber, LogToEntityError)) } diff --git a/pkg/transformers/flip_kick/transformer_test.go b/pkg/transformers/flip_kick/transformer_test.go index 0f14665a..7e4350df 100644 --- a/pkg/transformers/flip_kick/transformer_test.go +++ b/pkg/transformers/flip_kick/transformer_test.go @@ -54,7 +54,7 @@ var _ = Describe("FlipKick Transformer", func() { startingBlockNumber := rand.Int63() testConfig = shared.TransformerConfig{ - ContractAddresses: "0x12345", + ContractAddress: "0x12345", ContractAbi: "test abi", Topics: []string{shared.FlipKickSignature}, StartingBlockNumber: startingBlockNumber, @@ -83,7 +83,7 @@ var _ = Describe("FlipKick Transformer", func() { err := transformer.Execute() Expect(err).NotTo(HaveOccurred()) - Expect(fetcher.FetchedContractAddress).To(Equal(testConfig.ContractAddresses)) + Expect(fetcher.FetchedContractAddress).To(Equal(testConfig.ContractAddress)) Expect(fetcher.FetchedTopics).To(Equal(expectedTopics)) Expect(fetcher.FetchedBlocks).To(Equal([]int64{blockNumber})) }) @@ -100,7 +100,7 @@ var _ = Describe("FlipKick Transformer", func() { err := transformer.Execute() Expect(err).NotTo(HaveOccurred()) - Expect(converter.ConverterContract).To(Equal(testConfig.ContractAddresses)) + Expect(converter.ConverterContract).To(Equal(testConfig.ContractAddress)) Expect(converter.ConverterAbi).To(Equal(testConfig.ContractAbi)) Expect(converter.LogsToConvert).To(Equal(logs)) Expect(converter.EntitiesToConvert).To(Equal([]flip_kick.FlipKickEntity{test_data.FlipKickEntity})) diff --git a/pkg/transformers/frob/config.go b/pkg/transformers/frob/config.go index cd824f06..55d209fe 100644 --- a/pkg/transformers/frob/config.go +++ b/pkg/transformers/frob/config.go @@ -17,7 +17,7 @@ package frob import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" var FrobConfig = shared.TransformerConfig{ - ContractAddresses: "0xff3f2400f1600f3f493a9a92704a29b96795af1a", //this is a temporary address deployed locally + ContractAddress: "0xff3f2400f1600f3f493a9a92704a29b96795af1a", //this is a temporary address deployed locally ContractAbi: FrobABI, Topics: []string{FrobEventSignature}, StartingBlockNumber: 0, diff --git a/pkg/transformers/frob/transformer.go b/pkg/transformers/frob/transformer.go index f72d2b08..324e345e 100644 --- a/pkg/transformers/frob/transformer.go +++ b/pkg/transformers/frob/transformer.go @@ -52,12 +52,12 @@ func (transformer FrobTransformer) Execute() error { } for _, header := range missingHeaders { topics := [][]common.Hash{{common.HexToHash(FrobEventSignature)}} - matchingLogs, err := transformer.Fetcher.FetchLogs(FrobConfig.ContractAddresses, topics, header.BlockNumber) + matchingLogs, err := transformer.Fetcher.FetchLogs(FrobConfig.ContractAddress, topics, header.BlockNumber) if err != nil { return err } for _, log := range matchingLogs { - entity, err := transformer.Converter.ToEntity(FrobConfig.ContractAddresses, FrobConfig.ContractAbi, log) + entity, err := transformer.Converter.ToEntity(FrobConfig.ContractAddress, FrobConfig.ContractAbi, log) if err != nil { return err } diff --git a/pkg/transformers/frob/transformer_test.go b/pkg/transformers/frob/transformer_test.go index ca7dfe31..36e7fa4c 100644 --- a/pkg/transformers/frob/transformer_test.go +++ b/pkg/transformers/frob/transformer_test.go @@ -74,7 +74,7 @@ var _ = Describe("Frob transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) - Expect(fetcher.FetchedContractAddress).To(Equal(frob.FrobConfig.ContractAddresses)) + Expect(fetcher.FetchedContractAddress).To(Equal(frob.FrobConfig.ContractAddress)) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(frob.FrobEventSignature)}})) }) @@ -110,7 +110,7 @@ var _ = Describe("Frob transformer", func() { err := transformer.Execute() Expect(err).NotTo(HaveOccurred()) - Expect(converter.PassedContractAddress).To(Equal(frob.FrobConfig.ContractAddresses)) + Expect(converter.PassedContractAddress).To(Equal(frob.FrobConfig.ContractAddress)) Expect(converter.PassedContractABI).To(Equal(frob.FrobConfig.ContractAbi)) Expect(converter.PassedLog).To(Equal(test_data.EthFrobLog)) Expect(converter.PassedEntity).To(Equal(test_data.FrobEntity)) diff --git a/pkg/transformers/pit_file/config.go b/pkg/transformers/pit_file/config.go new file mode 100644 index 00000000..d7b9516c --- /dev/null +++ b/pkg/transformers/pit_file/config.go @@ -0,0 +1,13 @@ +package pit_file + +import ( + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" +) + +var PitFileConfig = shared.TransformerConfig{ + ContractAddress: "0xff3f2400f1600f3f493a9a92704a29b96795af1a", // temporary address from Ganache deploy + ContractAbi: shared.PitABI, + Topics: []string{shared.PitFileSignature}, + StartingBlockNumber: 0, + EndingBlockNumber: 100, +} diff --git a/pkg/transformers/pit_file/converter.go b/pkg/transformers/pit_file/converter.go new file mode 100644 index 00000000..0bcc4116 --- /dev/null +++ b/pkg/transformers/pit_file/converter.go @@ -0,0 +1,32 @@ +package pit_file + +import ( + "bytes" + "encoding/json" + "github.com/ethereum/go-ethereum/core/types" + "math/big" +) + +type Converter interface { + ToModel(contractAddress string, contractAbi string, ethLog types.Log) (PitFileModel, error) +} + +type PitFileConverter struct { +} + +func (PitFileConverter) ToModel(contractAddress string, contractAbi string, ethLog types.Log) (entity PitFileModel, err error) { + ilk := string(bytes.Trim(ethLog.Topics[2].Bytes(), "\x00")) + what := string(bytes.Trim(ethLog.Topics[3].Bytes(), "\x00")) + itemByteLength := 32 + riskBytes := ethLog.Data[len(ethLog.Data)-itemByteLength:] + risk := big.NewInt(0).SetBytes(riskBytes).String() + + raw, err := json.Marshal(ethLog) + return PitFileModel{ + Ilk: ilk, + What: what, + Risk: risk, + TransactionIndex: ethLog.TxIndex, + Raw: raw, + }, err +} diff --git a/pkg/transformers/pit_file/converter_test.go b/pkg/transformers/pit_file/converter_test.go new file mode 100644 index 00000000..30e97fd6 --- /dev/null +++ b/pkg/transformers/pit_file/converter_test.go @@ -0,0 +1,20 @@ +package pit_file_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" +) + +var _ = Describe("Pit file converter", func() { + It("converts a log to an entity", func() { + converter := pit_file.PitFileConverter{} + + model, err := converter.ToModel(test_data.PitAddress, shared.PitABI, test_data.EthPitFileLog) + + Expect(err).NotTo(HaveOccurred()) + Expect(model).To(Equal(test_data.PitFileModel)) + }) +}) diff --git a/pkg/transformers/pit_file/model.go b/pkg/transformers/pit_file/model.go new file mode 100644 index 00000000..d42ba67d --- /dev/null +++ b/pkg/transformers/pit_file/model.go @@ -0,0 +1,9 @@ +package pit_file + +type PitFileModel struct { + Ilk string + What string + Risk string + TransactionIndex uint `db:"tx_idx"` + Raw []byte `db:"raw_log"` +} diff --git a/pkg/transformers/pit_file/pit_file_suite_test.go b/pkg/transformers/pit_file/pit_file_suite_test.go new file mode 100644 index 00000000..c992d4c9 --- /dev/null +++ b/pkg/transformers/pit_file/pit_file_suite_test.go @@ -0,0 +1,13 @@ +package pit_file_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestPitFile(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "PitFile Suite") +} diff --git a/pkg/transformers/pit_file/repository.go b/pkg/transformers/pit_file/repository.go new file mode 100644 index 00000000..4184269a --- /dev/null +++ b/pkg/transformers/pit_file/repository.go @@ -0,0 +1,48 @@ +package pit_file + +import ( + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" +) + +type Repository interface { + Create(headerID int64, transactionIndex uint, model PitFileModel) error + MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) +} + +type PitFileRepository struct { + db *postgres.DB +} + +func NewPitFileRepository(db *postgres.DB) PitFileRepository { + return PitFileRepository{ + db: db, + } +} + +func (repository PitFileRepository) Create(headerID int64, transactionIndex uint, model PitFileModel) error { + _, err := repository.db.Exec( + `INSERT into maker.pit_file (header_id, ilk, what, risk, tx_idx, raw_log) + VALUES($1, $2, $3, $4::NUMERIC, $5, $6)`, + headerID, model.Ilk, model.What, model.Risk, model.TransactionIndex, model.Raw, + ) + return err +} + +func (repository PitFileRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { + var result []core.Header + err := repository.db.Select( + &result, + `SELECT headers.id, headers.block_number FROM headers + LEFT JOIN maker.pit_file on headers.id = header_id + WHERE header_id ISNULL + AND headers.block_number >= $1 + AND headers.block_number <= $2 + AND headers.eth_node_fingerprint = $3`, + startingBlockNumber, + endingBlockNumber, + repository.db.Node.ID, + ) + + return result, err +} diff --git a/pkg/transformers/pit_file/repository_test.go b/pkg/transformers/pit_file/repository_test.go new file mode 100644 index 00000000..d86a46e9 --- /dev/null +++ b/pkg/transformers/pit_file/repository_test.go @@ -0,0 +1,130 @@ +package pit_file_test + +import ( + "database/sql" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" + "github.com/vulcanize/vulcanizedb/test_config" +) + +var _ = Describe("Pit file repository", func() { + Describe("Create", func() { + It("adds a pit file event", func() { + db := test_config.NewTestDB(core.Node{}) + test_config.CleanTestDB(db) + headerRepository := repositories.NewHeaderRepository(db) + headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{}) + Expect(err).NotTo(HaveOccurred()) + pitFileRepository := pit_file.NewPitFileRepository(db) + + err = pitFileRepository.Create(headerID, 123, test_data.PitFileModel) + + Expect(err).NotTo(HaveOccurred()) + var dbPitFile pit_file.PitFileModel + err = db.Get(&dbPitFile, `SELECT ilk, what, risk, tx_idx, raw_log FROM maker.pit_file WHERE header_id = $1`, headerID) + Expect(err).NotTo(HaveOccurred()) + Expect(dbPitFile.Ilk).To(Equal(test_data.PitFileModel.Ilk)) + Expect(dbPitFile.What).To(Equal(test_data.PitFileModel.What)) + Expect(dbPitFile.Risk).To(Equal(test_data.PitFileModel.Risk)) + Expect(dbPitFile.TransactionIndex).To(Equal(test_data.PitFileModel.TransactionIndex)) + // The raw bytes scanned out of the DB are compressed (missing whitespace), such that they don't strictly equal the input bytes + Expect(dbPitFile.Raw).To(MatchJSON(test_data.PitFileModel.Raw)) + }) + + It("does not duplicate pit file events", func() { + db := test_config.NewTestDB(core.Node{}) + test_config.CleanTestDB(db) + headerRepository := repositories.NewHeaderRepository(db) + headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{}) + Expect(err).NotTo(HaveOccurred()) + pitFileRepository := pit_file.NewPitFileRepository(db) + err = pitFileRepository.Create(headerID, 123, test_data.PitFileModel) + Expect(err).NotTo(HaveOccurred()) + + err = pitFileRepository.Create(headerID, 123, test_data.PitFileModel) + + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint")) + }) + + It("removes pit file if corresponding header is deleted", func() { + db := test_config.NewTestDB(core.Node{}) + test_config.CleanTestDB(db) + headerRepository := repositories.NewHeaderRepository(db) + headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{}) + Expect(err).NotTo(HaveOccurred()) + pitFileRepository := pit_file.NewPitFileRepository(db) + err = pitFileRepository.Create(headerID, 123, test_data.PitFileModel) + Expect(err).NotTo(HaveOccurred()) + + _, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID) + + Expect(err).NotTo(HaveOccurred()) + var dbPitFile pit_file.PitFileModel + err = db.Get(&dbPitFile, `SELECT ilk, what, risk, tx_idx, raw_log FROM maker.pit_file WHERE header_id = $1`, headerID) + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(sql.ErrNoRows)) + }) + }) + + Describe("MissingHeaders", func() { + It("returns headers with no associated pit file event", func() { + db := test_config.NewTestDB(core.Node{}) + test_config.CleanTestDB(db) + headerRepository := repositories.NewHeaderRepository(db) + startingBlockNumber := int64(1) + pitFileBlockNumber := int64(2) + endingBlockNumber := int64(3) + blockNumbers := []int64{startingBlockNumber, pitFileBlockNumber, endingBlockNumber, endingBlockNumber + 1} + var headerIDs []int64 + for _, n := range blockNumbers { + headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{BlockNumber: n}) + headerIDs = append(headerIDs, headerID) + Expect(err).NotTo(HaveOccurred()) + } + pitFileRepository := pit_file.NewPitFileRepository(db) + err := pitFileRepository.Create(headerIDs[1], 123, test_data.PitFileModel) + Expect(err).NotTo(HaveOccurred()) + + headers, err := pitFileRepository.MissingHeaders(startingBlockNumber, endingBlockNumber) + + Expect(err).NotTo(HaveOccurred()) + Expect(len(headers)).To(Equal(2)) + Expect(headers[0].BlockNumber).To(Or(Equal(startingBlockNumber), Equal(endingBlockNumber))) + Expect(headers[1].BlockNumber).To(Or(Equal(startingBlockNumber), Equal(endingBlockNumber))) + }) + + It("only returns headers associated with the current node", func() { + db := test_config.NewTestDB(core.Node{}) + test_config.CleanTestDB(db) + blockNumbers := []int64{1, 2, 3} + headerRepository := repositories.NewHeaderRepository(db) + dbTwo := test_config.NewTestDB(core.Node{ID: "second"}) + headerRepositoryTwo := repositories.NewHeaderRepository(dbTwo) + var headerIDs []int64 + for _, n := range blockNumbers { + headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{BlockNumber: n}) + Expect(err).NotTo(HaveOccurred()) + headerIDs = append(headerIDs, headerID) + _, err = headerRepositoryTwo.CreateOrUpdateHeader(core.Header{BlockNumber: n}) + Expect(err).NotTo(HaveOccurred()) + } + pitFileRepository := pit_file.NewPitFileRepository(db) + pitFileRepositoryTwo := pit_file.NewPitFileRepository(dbTwo) + err := pitFileRepository.Create(headerIDs[0], 0, test_data.PitFileModel) + Expect(err).NotTo(HaveOccurred()) + + nodeOneMissingHeaders, err := pitFileRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) + Expect(err).NotTo(HaveOccurred()) + Expect(len(nodeOneMissingHeaders)).To(Equal(len(blockNumbers) - 1)) + + nodeTwoMissingHeaders, err := pitFileRepositoryTwo.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) + Expect(err).NotTo(HaveOccurred()) + Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers))) + }) + }) +}) diff --git a/pkg/transformers/pit_file/transformer.go b/pkg/transformers/pit_file/transformer.go new file mode 100644 index 00000000..c6c38ad3 --- /dev/null +++ b/pkg/transformers/pit_file/transformer.go @@ -0,0 +1,56 @@ +package pit_file + +import ( + "github.com/ethereum/go-ethereum/common" + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" +) + +type PitFileTransformer struct { + Config shared.TransformerConfig + Converter Converter + Fetcher shared.LogFetcher + Repository Repository +} + +type PitFileTransformerInitializer struct { + Config shared.TransformerConfig +} + +func (initializer PitFileTransformerInitializer) NewPitFileTransformer(db *postgres.DB, blockChain core.BlockChain) shared.Transformer { + converter := PitFileConverter{} + fetcher := shared.NewFetcher(blockChain) + repository := NewPitFileRepository(db) + return PitFileTransformer{ + Config: initializer.Config, + Converter: converter, + Fetcher: fetcher, + Repository: repository, + } +} + +func (transformer PitFileTransformer) Execute() error { + missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber) + if err != nil { + return err + } + for _, header := range missingHeaders { + topics := [][]common.Hash{{common.HexToHash(shared.PitFileSignature)}} + matchingLogs, err := transformer.Fetcher.FetchLogs(PitFileConfig.ContractAddress, topics, header.BlockNumber) + if err != nil { + return err + } + for _, log := range matchingLogs { + model, err := transformer.Converter.ToModel(PitFileConfig.ContractAddress, shared.PitABI, log) + if err != nil { + return err + } + err = transformer.Repository.Create(header.Id, log.TxIndex, model) + if err != nil { + return err + } + } + } + return nil +} diff --git a/pkg/transformers/pit_file/transformer_test.go b/pkg/transformers/pit_file/transformer_test.go new file mode 100644 index 00000000..e9351b3c --- /dev/null +++ b/pkg/transformers/pit_file/transformer_test.go @@ -0,0 +1,162 @@ +package pit_file_test + +import ( + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/fakes" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks" + pit_file_mocks "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks/pit_file" +) + +var _ = Describe("Pit file transformer", func() { + It("gets missing headers for block numbers specified in config", func() { + repository := &pit_file_mocks.MockPitFileRepository{} + transformer := pit_file.PitFileTransformer{ + Config: pit_file.PitFileConfig, + Fetcher: &mocks.MockLogFetcher{}, + Converter: &pit_file_mocks.MockPitFileConverter{}, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).NotTo(HaveOccurred()) + Expect(repository.PassedStartingBlockNumber).To(Equal(pit_file.PitFileConfig.StartingBlockNumber)) + Expect(repository.PassedEndingBlockNumber).To(Equal(pit_file.PitFileConfig.EndingBlockNumber)) + }) + + It("returns error if repository returns error for missing headers", func() { + repository := &pit_file_mocks.MockPitFileRepository{} + repository.SetMissingHeadersErr(fakes.FakeError) + transformer := pit_file.PitFileTransformer{ + Fetcher: &mocks.MockLogFetcher{}, + Converter: &pit_file_mocks.MockPitFileConverter{}, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("fetches logs for missing headers", func() { + fetcher := &mocks.MockLogFetcher{} + repository := &pit_file_mocks.MockPitFileRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}, {BlockNumber: 2}}) + transformer := pit_file.PitFileTransformer{ + Fetcher: fetcher, + Converter: &pit_file_mocks.MockPitFileConverter{}, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).NotTo(HaveOccurred()) + Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) + Expect(fetcher.FetchedContractAddress).To(Equal(pit_file.PitFileConfig.ContractAddress)) + Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.PitFileSignature)}})) + }) + + It("returns error if fetcher returns error", func() { + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetcherError(fakes.FakeError) + repository := &pit_file_mocks.MockPitFileRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) + transformer := pit_file.PitFileTransformer{ + Fetcher: fetcher, + Converter: &pit_file_mocks.MockPitFileConverter{}, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("converts matching logs", func() { + converter := &pit_file_mocks.MockPitFileConverter{} + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileLog}) + repository := &pit_file_mocks.MockPitFileRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) + transformer := pit_file.PitFileTransformer{ + Fetcher: fetcher, + Converter: converter, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).NotTo(HaveOccurred()) + Expect(converter.PassedContractAddress).To(Equal(pit_file.PitFileConfig.ContractAddress)) + Expect(converter.PassedContractABI).To(Equal(pit_file.PitFileConfig.ContractAbi)) + Expect(converter.PassedLog).To(Equal(test_data.EthPitFileLog)) + }) + + It("returns error if converter returns error", func() { + converter := &pit_file_mocks.MockPitFileConverter{} + converter.SetConverterError(fakes.FakeError) + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileLog}) + repository := &pit_file_mocks.MockPitFileRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) + transformer := pit_file.PitFileTransformer{ + Fetcher: fetcher, + Converter: converter, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("persists pit file model", func() { + converter := &pit_file_mocks.MockPitFileConverter{} + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileLog}) + repository := &pit_file_mocks.MockPitFileRepository{} + fakeHeader := core.Header{BlockNumber: 1, Id: 2} + repository.SetMissingHeaders([]core.Header{fakeHeader}) + transformer := pit_file.PitFileTransformer{ + Fetcher: fetcher, + Converter: converter, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).NotTo(HaveOccurred()) + Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id)) + Expect(repository.PassedTransactionIndex).To(Equal(test_data.EthPitFileLog.TxIndex)) + Expect(repository.PassedModel).To(Equal(test_data.PitFileModel)) + }) + + It("returns error if repository returns error for create", func() { + converter := &pit_file_mocks.MockPitFileConverter{} + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileLog}) + repository := &pit_file_mocks.MockPitFileRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}}) + repository.SetCreateError(fakes.FakeError) + transformer := pit_file.PitFileTransformer{ + Fetcher: fetcher, + Converter: converter, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) +}) diff --git a/pkg/transformers/shared/constants.go b/pkg/transformers/shared/constants.go index 938a79f4..e1fda760 100644 --- a/pkg/transformers/shared/constants.go +++ b/pkg/transformers/shared/constants.go @@ -15,9 +15,11 @@ package shared var ( + FlipperABI = `[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"bids","outputs":[{"name":"bid","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"guy","type":"address"},{"name":"tic","type":"uint48"},{"name":"end","type":"uint48"},{"name":"urn","type":"bytes32"},{"name":"gal","type":"address"},{"name":"tab","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x4423c5f1"},{"constant":true,"inputs":[],"name":"ttl","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x4e8b1dd5"},{"constant":true,"inputs":[],"name":"gem","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x7bd2bea7"},{"constant":true,"inputs":[],"name":"beg","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x7d780d82"},{"constant":true,"inputs":[],"name":"tau","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xcfc4af55"},{"constant":true,"inputs":[],"name":"kicks","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xcfdd3302"},{"constant":true,"inputs":[],"name":"dai","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xf4b9fa75"},{"inputs":[{"name":"dai_","type":"address"},{"name":"gem_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor","signature":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"id","type":"uint256"},{"indexed":false,"name":"lot","type":"uint256"},{"indexed":false,"name":"bid","type":"uint256"},{"indexed":false,"name":"gal","type":"address"},{"indexed":false,"name":"end","type":"uint48"},{"indexed":true,"name":"urn","type":"bytes32"},{"indexed":false,"name":"tab","type":"uint256"}],"name":"Kick","type":"event","signature":"0xbac86238bdba81d21995024470425ecb370078fa62b7271b90cf28cbd1e3e87e"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event","signature":"0x644843f351d3fba4abcd60109eaff9f54bac8fb8ccf0bab941009c21df21cf31"},{"constant":true,"inputs":[],"name":"era","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x143e55e0"},{"constant":false,"inputs":[{"name":"urn","type":"bytes32"},{"name":"gal","type":"address"},{"name":"tab","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"kick","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xeae19d9e"},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"tick","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xfc7b6aee"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"tend","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x4b43ed12"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"dent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x5ff3a382"},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"deal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xc959c42b"}]` FlipperContractAddress = "0x6b59c42097e2fff7cad96cb08ceefd601081ad9c" //this is a temporary address deployed locally - FlipperABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"era\",\"outputs\":[{\"name\":\"\",\"type\":\"uint48\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"bids\",\"outputs\":[{\"name\":\"bid\",\"type\":\"uint256\"},{\"name\":\"lot\",\"type\":\"uint256\"},{\"name\":\"guy\",\"type\":\"address\"},{\"name\":\"tic\",\"type\":\"uint48\"},{\"name\":\"end\",\"type\":\"uint48\"},{\"name\":\"urn\",\"type\":\"bytes32\"},{\"name\":\"gal\",\"type\":\"address\"},{\"name\":\"tab\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"id\",\"type\":\"uint256\"},{\"name\":\"lot\",\"type\":\"uint256\"},{\"name\":\"bid\",\"type\":\"uint256\"}],\"name\":\"tend\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"ttl\",\"outputs\":[{\"name\":\"\",\"type\":\"uint48\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"id\",\"type\":\"uint256\"},{\"name\":\"lot\",\"type\":\"uint256\"},{\"name\":\"bid\",\"type\":\"uint256\"}],\"name\":\"dent\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"gem\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"beg\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"id\",\"type\":\"uint256\"}],\"name\":\"deal\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"tau\",\"outputs\":[{\"name\":\"\",\"type\":\"uint48\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"kicks\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"urn\",\"type\":\"bytes32\"},{\"name\":\"gal\",\"type\":\"address\"},{\"name\":\"tab\",\"type\":\"uint256\"},{\"name\":\"lot\",\"type\":\"uint256\"},{\"name\":\"bid\",\"type\":\"uint256\"}],\"name\":\"kick\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"dai\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"id\",\"type\":\"uint256\"}],\"name\":\"tick\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"dai_\",\"type\":\"address\"},{\"name\":\"gem_\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"id\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"lot\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"bid\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"gal\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"end\",\"type\":\"uint48\"},{\"indexed\":true,\"name\":\"urn\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"tab\",\"type\":\"uint256\"}],\"name\":\"Kick\",\"type\":\"event\"},{\"anonymous\":true,\"inputs\":[{\"indexed\":true,\"name\":\"sig\",\"type\":\"bytes4\"},{\"indexed\":true,\"name\":\"guy\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"foo\",\"type\":\"bytes32\"},{\"indexed\":true,\"name\":\"bar\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"wad\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"fax\",\"type\":\"bytes\"}],\"name\":\"LogNote\",\"type\":\"event\"}]" - FlipKickSignature = "0xbac86238bdba81d21995024470425ecb370078fa62b7271b90cf28cbd1e3e87e" - BiteSignature = "0x44a8f29dfcf27e5dd7a4db50b390f851bf3ecf2bf221243be3e853f586134455" + FlipKickSignature = "0x8828a22eb6a18623309ad55592866c4b077989e9e8a25e1b85f9bf6f7282520f" + PitABI = `[{"constant":true,"inputs":[],"name":"vat","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"live","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"drip","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"Line","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"wards","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"ilks","outputs":[{"name":"spot","type":"uint256"},{"name":"line","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"vat_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"ilk","type":"bytes32"},{"indexed":true,"name":"lad","type":"bytes32"},{"indexed":false,"name":"ink","type":"uint256"},{"indexed":false,"name":"art","type":"uint256"},{"indexed":false,"name":"dink","type":"int256"},{"indexed":false,"name":"dart","type":"int256"},{"indexed":false,"name":"iArt","type":"uint256"}],"name":"Frob","type":"event"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"address"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"dink","type":"int256"},{"name":"dart","type":"int256"}],"name":"frob","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]` + PitFileSignature = "0x1a0b287e00000000000000000000000000000000000000000000000000000000" TendFunctionSignature = "0x4b43ed1200000000000000000000000000000000000000000000000000000000" + BiteSignature = "0x44a8f29dfcf27e5dd7a4db50b390f851bf3ecf2bf221243be3e853f586134455" ) diff --git a/pkg/transformers/shared/transformer.go b/pkg/transformers/shared/transformer.go index 56f8fc40..9632e6cd 100644 --- a/pkg/transformers/shared/transformer.go +++ b/pkg/transformers/shared/transformer.go @@ -28,7 +28,7 @@ type Transformer interface { type TransformerInitializer func(db *postgres.DB, blockChain core.BlockChain) Transformer type TransformerConfig struct { - ContractAddresses string + ContractAddress string ContractAbi string Topics []string StartingBlockNumber int64 diff --git a/pkg/transformers/tend/config.go b/pkg/transformers/tend/config.go index 3859186d..f8fcc847 100644 --- a/pkg/transformers/tend/config.go +++ b/pkg/transformers/tend/config.go @@ -17,7 +17,7 @@ package tend import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" var TendConfig = shared.TransformerConfig{ - ContractAddresses: shared.FlipperContractAddress, + ContractAddress: shared.FlipperContractAddress, ContractAbi: shared.FlipperABI, Topics: []string{shared.TendFunctionSignature}, StartingBlockNumber: 0, diff --git a/pkg/transformers/tend/transformer.go b/pkg/transformers/tend/transformer.go index e1b9864e..89b285c8 100644 --- a/pkg/transformers/tend/transformer.go +++ b/pkg/transformers/tend/transformer.go @@ -59,14 +59,14 @@ func (t TendTransformer) Execute() error { } for _, header := range missingHeaders { - ethLogs, err := t.Fetcher.FetchLogs(config.ContractAddresses, topics, header.BlockNumber) + ethLogs, err := t.Fetcher.FetchLogs(config.ContractAddress, topics, header.BlockNumber) if err != nil { log.Println("Error fetching matching logs:", err) return err } for _, ethLog := range ethLogs { - model, err := t.Converter.Convert(config.ContractAddresses, config.ContractAbi, ethLog) + model, err := t.Converter.Convert(config.ContractAddress, config.ContractAbi, ethLog) if err != nil { log.Println("Error converting logs:", err) return err diff --git a/pkg/transformers/tend/transformer_test.go b/pkg/transformers/tend/transformer_test.go index 3fa3ae58..d3fd3570 100644 --- a/pkg/transformers/tend/transformer_test.go +++ b/pkg/transformers/tend/transformer_test.go @@ -93,7 +93,7 @@ var _ = Describe("Tend Transformer", func() { err := transformer.Execute() Expect(err).NotTo(HaveOccurred()) - Expect(converter.ConverterContract).To(Equal(tend.TendConfig.ContractAddresses)) + Expect(converter.ConverterContract).To(Equal(tend.TendConfig.ContractAddress)) Expect(converter.ConverterAbi).To(Equal(tend.TendConfig.ContractAbi)) Expect(converter.LogsToConvert).To(Equal([]types.Log{test_data.TendLogNote})) }) diff --git a/pkg/transformers/test_data/mocks/pit_file/converter.go b/pkg/transformers/test_data/mocks/pit_file/converter.go new file mode 100644 index 00000000..45693ea4 --- /dev/null +++ b/pkg/transformers/test_data/mocks/pit_file/converter.go @@ -0,0 +1,26 @@ +package pit_file + +import ( + "github.com/ethereum/go-ethereum/core/types" + + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" +) + +type MockPitFileConverter struct { + PassedContractAddress string + PassedContractABI string + PassedLog types.Log + converterError error +} + +func (converter *MockPitFileConverter) SetConverterError(err error) { + converter.converterError = err +} + +func (converter *MockPitFileConverter) ToModel(contractAddress string, contractAbi string, ethLog types.Log) (pit_file.PitFileModel, error) { + converter.PassedContractAddress = contractAddress + converter.PassedContractABI = contractAbi + converter.PassedLog = ethLog + return test_data.PitFileModel, converter.converterError +} diff --git a/pkg/transformers/test_data/mocks/pit_file/repository.go b/pkg/transformers/test_data/mocks/pit_file/repository.go new file mode 100644 index 00000000..9475adaa --- /dev/null +++ b/pkg/transformers/test_data/mocks/pit_file/repository.go @@ -0,0 +1,42 @@ +package pit_file + +import ( + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" +) + +type MockPitFileRepository struct { + createError error + PassedEndingBlockNumber int64 + PassedModel pit_file.PitFileModel + PassedHeaderID int64 + PassedStartingBlockNumber int64 + PassedTransactionIndex uint + missingHeaders []core.Header + missingHeadersErr error +} + +func (repository *MockPitFileRepository) SetCreateError(err error) { + repository.createError = err +} + +func (repository *MockPitFileRepository) SetMissingHeadersErr(err error) { + repository.missingHeadersErr = err +} + +func (repository *MockPitFileRepository) SetMissingHeaders(headers []core.Header) { + repository.missingHeaders = headers +} + +func (repository *MockPitFileRepository) Create(headerID int64, transactionIndex uint, model pit_file.PitFileModel) error { + repository.PassedHeaderID = headerID + repository.PassedTransactionIndex = transactionIndex + repository.PassedModel = model + return repository.createError +} + +func (repository *MockPitFileRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { + repository.PassedStartingBlockNumber = startingBlockNumber + repository.PassedEndingBlockNumber = endingBlockNumber + return repository.missingHeaders, repository.missingHeadersErr +} diff --git a/pkg/transformers/test_data/pit_file.go b/pkg/transformers/test_data/pit_file.go new file mode 100644 index 00000000..db1a0c0a --- /dev/null +++ b/pkg/transformers/test_data/pit_file.go @@ -0,0 +1,41 @@ +package test_data + +import ( + "encoding/json" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/core/types" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" + "math/big" +) + +var ( + PitAddress = "0xff3f2400f1600f3f493a9a92704a29b96795af1a" +) + +var EthPitFileLog = types.Log{ + Address: common.HexToAddress(PitAddress), + Topics: []common.Hash{ + common.HexToHash("0x1a0b287e00000000000000000000000000000000000000000000000000000000"), + common.HexToHash("0x0000000000000000000000000f243e26db94b5426032e6dfa6007802dea2a614"), + common.HexToHash("0x66616b6520696c6b000000000000000000000000000000000000000000000000"), + common.HexToHash("0x73706f7400000000000000000000000000000000000000000000000000000000"), + }, + Data: hexutil.MustDecode("0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000641a0b287e66616b6520696c6b00000000000000000000000000000000000000000000000073706f7400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007b"), + BlockNumber: 11, + TxHash: common.HexToHash("0x1ba8125f60fa045c85b35df3983bee37db8627fbc32e3442a5cf17c85bb83f09"), + TxIndex: 111, + BlockHash: common.HexToHash("0x6dc284247c524b22b10a75ef1c9d1709a509208d04c15fa2b675a293db637d21"), + Index: 0, + Removed: false, +} + +var raw, _ = json.Marshal(EthPitFileLog) + +var PitFileModel = pit_file.PitFileModel{ + Ilk: "fake ilk", + What: "spot", + Risk: big.NewInt(123).String(), + TransactionIndex: EthPitFileLog.TxIndex, + Raw: raw, +} diff --git a/pkg/transformers/transformers.go b/pkg/transformers/transformers.go index 7278e643..a8af1a44 100644 --- a/pkg/transformers/transformers.go +++ b/pkg/transformers/transformers.go @@ -18,6 +18,7 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/transformers/bite" "github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick" "github.com/vulcanize/vulcanizedb/pkg/transformers/frob" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" "github.com/vulcanize/vulcanizedb/pkg/transformers/price_feeds" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/tend" @@ -28,6 +29,8 @@ func TransformerInitializers() []shared.TransformerInitializer { flipKickTransformerInitializer := flip_kick.FlipKickTransformerInitializer{Config: flipKickConfig} frobConfig := frob.FrobConfig frobTransformerInitializer := frob.FrobTransformerInitializer{Config: frobConfig} + pitFileConfig := pit_file.PitFileConfig + pitFileTransformerInitializer := pit_file.PitFileTransformerInitializer{Config: pitFileConfig} priceFeedConfig := price_feeds.PriceFeedConfig priceFeedTransformerInitializer := price_feeds.PriceFeedTransformerInitializer{Config: priceFeedConfig} tendConfig := tend.TendConfig @@ -38,6 +41,7 @@ func TransformerInitializers() []shared.TransformerInitializer { biteTransformerInitializer.NewBiteTransformer, flipKickTransformerInitializer.NewFlipKickTransformer, frobTransformerInitializer.NewFrobTransformer, + pitFileTransformerInitializer.NewPitFileTransformer, priceFeedTransformerInitializer.NewPriceFeedTransformer, tendTransformerInitializer.NewTendTransformer, } diff --git a/test_config/test_config.go b/test_config/test_config.go index e6926a82..29bf6ca1 100644 --- a/test_config/test_config.go +++ b/test_config/test_config.go @@ -77,6 +77,7 @@ func CleanTestDB(db *postgres.DB) { db.MustExec("DELETE FROM headers") db.MustExec("DELETE FROM log_filters") db.MustExec("DELETE FROM logs") + db.MustExec("DELETE FROM maker.pit_file") db.MustExec("DELETE FROM receipts") db.MustExec("DELETE FROM transactions") db.MustExec("DELETE FROM watched_contracts") From 8f5bc0a9566d445632bcb762045f346f1bce12ff Mon Sep 17 00:00:00 2001 From: Rob Mulholand Date: Thu, 30 Aug 2018 18:51:56 -0500 Subject: [PATCH 2/5] Add raw log to Frob record in DB - Enables parsing additional values off the log if necessary - Also update Frob to reflect DSS changes (lad => urn) - Move Frob constants to shared directory --- .../1533844125_create_frob_table.up.sql | 7 +-- db/schema.sql | 7 +-- pkg/transformers/frob/config.go | 4 +- pkg/transformers/frob/constants.go | 20 -------- pkg/transformers/frob/converter.go | 29 ++++++++---- pkg/transformers/frob/converter_test.go | 6 ++- pkg/transformers/frob/entity.go | 18 +++++--- pkg/transformers/frob/integration_test.go | 6 +-- pkg/transformers/frob/model.go | 16 ++++--- pkg/transformers/frob/repository.go | 10 ++-- pkg/transformers/frob/repository_test.go | 44 +++++++++--------- pkg/transformers/frob/transformer.go | 9 ++-- pkg/transformers/frob/transformer_test.go | 46 +++++++++++++++++-- pkg/transformers/pit_file/repository_test.go | 1 - pkg/transformers/shared/constants.go | 3 +- pkg/transformers/test_data/frob.go | 34 ++++++++------ .../test_data/mocks/frob/converter.go | 17 ++++--- .../test_data/mocks/frob/repository.go | 4 +- pkg/transformers/test_data/pit_file.go | 5 +- 19 files changed, 167 insertions(+), 119 deletions(-) delete mode 100644 pkg/transformers/frob/constants.go diff --git a/db/migrations/1533844125_create_frob_table.up.sql b/db/migrations/1533844125_create_frob_table.up.sql index 9c17a51a..78a0fdb0 100644 --- a/db/migrations/1533844125_create_frob_table.up.sql +++ b/db/migrations/1533844125_create_frob_table.up.sql @@ -1,13 +1,14 @@ CREATE TABLE maker.frob ( id SERIAL PRIMARY KEY, header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - tx_idx INTEGER, ilk bytea, - lad bytea, + urn bytea, dink NUMERIC, dart NUMERIC, ink NUMERIC, art NUMERIC, - iart NUMERIC, + iart NUMERIC, + tx_idx INTEGER NOT NUll, + raw_log JSONB, UNIQUE (header_id, tx_idx) ); \ No newline at end of file diff --git a/db/schema.sql b/db/schema.sql index 8cc66b1d..cfa0ed9a 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -124,14 +124,15 @@ ALTER SEQUENCE maker.flip_kick_db_id_seq OWNED BY maker.flip_kick.db_id; CREATE TABLE maker.frob ( id integer NOT NULL, header_id integer NOT NULL, - tx_idx integer, ilk bytea, - lad bytea, + urn bytea, dink numeric, dart numeric, ink numeric, art numeric, - iart numeric + iart numeric, + tx_idx integer NOT NULL, + raw_log jsonb ); diff --git a/pkg/transformers/frob/config.go b/pkg/transformers/frob/config.go index 55d209fe..d01cf3ec 100644 --- a/pkg/transformers/frob/config.go +++ b/pkg/transformers/frob/config.go @@ -18,8 +18,8 @@ import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" var FrobConfig = shared.TransformerConfig{ ContractAddress: "0xff3f2400f1600f3f493a9a92704a29b96795af1a", //this is a temporary address deployed locally - ContractAbi: FrobABI, - Topics: []string{FrobEventSignature}, + ContractAbi: shared.PitABI, + Topics: []string{shared.FrobSignature}, StartingBlockNumber: 0, EndingBlockNumber: 100, } diff --git a/pkg/transformers/frob/constants.go b/pkg/transformers/frob/constants.go deleted file mode 100644 index 7b8e2e8a..00000000 --- a/pkg/transformers/frob/constants.go +++ /dev/null @@ -1,20 +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 frob - -var ( - FrobABI = `[{"constant":true,"inputs":[],"name":"vat","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"live","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"drip","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"Line","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"wards","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"ilks","outputs":[{"name":"spot","type":"uint256"},{"name":"line","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"vat_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"ilk","type":"bytes32"},{"indexed":true,"name":"lad","type":"bytes32"},{"indexed":false,"name":"ink","type":"uint256"},{"indexed":false,"name":"art","type":"uint256"},{"indexed":false,"name":"dink","type":"int256"},{"indexed":false,"name":"dart","type":"int256"},{"indexed":false,"name":"iArt","type":"uint256"}],"name":"Frob","type":"event"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"address"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"dink","type":"int256"},{"name":"dart","type":"int256"}],"name":"frob","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]` - FrobEventSignature = "0x6cedf1d3a466a3d6bab04887b1642177bf6dbf1daa737c2e8f639cd0b020d9d0" -) diff --git a/pkg/transformers/frob/converter.go b/pkg/transformers/frob/converter.go index 42af3e25..82e711eb 100644 --- a/pkg/transformers/frob/converter.go +++ b/pkg/transformers/frob/converter.go @@ -19,12 +19,13 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" + "encoding/json" "github.com/vulcanize/vulcanizedb/pkg/geth" ) type Converter interface { ToEntity(contractAddress string, contractAbi string, ethLog types.Log) (FrobEntity, error) - ToModel(flipKick FrobEntity) FrobModel + ToModel(flipKick FrobEntity) (FrobModel, error) } type FrobConverter struct { @@ -39,17 +40,25 @@ func (FrobConverter) ToEntity(contractAddress string, contractAbi string, ethLog } contract := bind.NewBoundContract(address, abi, nil, nil, nil) err = contract.UnpackLog(&entity, "Frob", ethLog) + entity.TransactionIndex = ethLog.TxIndex + entity.Raw = ethLog return entity, err } -func (FrobConverter) ToModel(frob FrobEntity) FrobModel { - return FrobModel{ - Ilk: frob.Ilk[:], - Lad: frob.Lad[:], - Dink: frob.Dink.String(), - Dart: frob.Dart.String(), - Ink: frob.Ink.String(), - Art: frob.Art.String(), - IArt: frob.IArt.String(), +func (FrobConverter) ToModel(frob FrobEntity) (FrobModel, error) { + rawLog, err := json.Marshal(frob.Raw) + if err != nil { + return FrobModel{}, err } + return FrobModel{ + Ilk: frob.Ilk[:], + Urn: frob.Urn[:], + Ink: frob.Ink.String(), + Art: frob.Art.String(), + Dink: frob.Dink.String(), + Dart: frob.Dart.String(), + IArt: frob.IArt.String(), + TransactionIndex: frob.TransactionIndex, + Raw: rawLog, + }, nil } diff --git a/pkg/transformers/frob/converter_test.go b/pkg/transformers/frob/converter_test.go index 29279946..ab404dc1 100644 --- a/pkg/transformers/frob/converter_test.go +++ b/pkg/transformers/frob/converter_test.go @@ -19,6 +19,7 @@ import ( . "github.com/onsi/gomega" "github.com/vulcanize/vulcanizedb/pkg/transformers/frob" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" ) @@ -26,7 +27,7 @@ var _ = Describe("Frob converter", func() { It("converts a log to an entity", func() { converter := frob.FrobConverter{} - entity, err := converter.ToEntity(test_data.TemporaryFrobAddress, frob.FrobABI, test_data.EthFrobLog) + entity, err := converter.ToEntity(test_data.TemporaryFrobAddress, shared.PitABI, test_data.EthFrobLog) Expect(err).NotTo(HaveOccurred()) Expect(entity).To(Equal(test_data.FrobEntity)) @@ -35,8 +36,9 @@ var _ = Describe("Frob converter", func() { It("converts an entity to a model", func() { converter := frob.FrobConverter{} - model := converter.ToModel(test_data.FrobEntity) + model, err := converter.ToModel(test_data.FrobEntity) + Expect(err).NotTo(HaveOccurred()) Expect(model).To(Equal(test_data.FrobModel)) }) }) diff --git a/pkg/transformers/frob/entity.go b/pkg/transformers/frob/entity.go index 0010d558..c150219e 100644 --- a/pkg/transformers/frob/entity.go +++ b/pkg/transformers/frob/entity.go @@ -16,14 +16,18 @@ package frob import ( "math/big" + + "github.com/ethereum/go-ethereum/core/types" ) type FrobEntity struct { - Ilk [32]byte - Lad [32]byte - Ink *big.Int - Art *big.Int - Dink *big.Int - Dart *big.Int - IArt *big.Int + Ilk [32]byte + Urn [32]byte + Ink *big.Int + Art *big.Int + Dink *big.Int + Dart *big.Int + IArt *big.Int + TransactionIndex uint + Raw types.Log } diff --git a/pkg/transformers/frob/integration_test.go b/pkg/transformers/frob/integration_test.go index 0f4c6988..907ca75e 100644 --- a/pkg/transformers/frob/integration_test.go +++ b/pkg/transformers/frob/integration_test.go @@ -46,7 +46,7 @@ var _ = Describe("Integration tests", func() { transactionConverter := vRpc.NewRpcTransactionConverter(ethClient) realBlockChain := geth.NewBlockChain(blockChainClient, realNode, transactionConverter) realFetcher := shared.NewFetcher(realBlockChain) - topic0 := common.HexToHash(frob.FrobEventSignature) + topic0 := common.HexToHash(shared.FrobSignature) topics := [][]common.Hash{{topic0}} result, err := realFetcher.FetchLogs(test_data.TemporaryFrobAddress, topics, int64(12)) @@ -62,7 +62,7 @@ var _ = Describe("Integration tests", func() { It("unpacks an event log", func() { address := common.HexToAddress(test_data.TemporaryFrobAddress) - abi, err := geth.ParseAbi(frob.FrobABI) + abi, err := geth.ParseAbi(shared.PitABI) Expect(err).NotTo(HaveOccurred()) contract := bind.NewBoundContract(address, abi, nil, nil, nil) @@ -78,6 +78,6 @@ var _ = Describe("Integration tests", func() { Expect(entity.IArt).To(Equal(expectedEntity.IArt)) Expect(entity.Ilk).To(Equal(expectedEntity.Ilk)) Expect(entity.Ink).To(Equal(expectedEntity.Ink)) - Expect(entity.Lad).To(Equal(expectedEntity.Lad)) + Expect(entity.Urn).To(Equal(expectedEntity.Urn)) }) }) diff --git a/pkg/transformers/frob/model.go b/pkg/transformers/frob/model.go index 90a1b3eb..566fe8e3 100644 --- a/pkg/transformers/frob/model.go +++ b/pkg/transformers/frob/model.go @@ -15,11 +15,13 @@ package frob type FrobModel struct { - Ilk []byte - Lad []byte - Ink string - Art string - Dink string - Dart string - IArt string + Ilk []byte + Urn []byte + Ink string + Art string + Dink string + Dart string + IArt string + TransactionIndex uint `db:"tx_idx"` + Raw []byte `db:"raw_log"` } diff --git a/pkg/transformers/frob/repository.go b/pkg/transformers/frob/repository.go index 0d9bb922..f2d60b31 100644 --- a/pkg/transformers/frob/repository.go +++ b/pkg/transformers/frob/repository.go @@ -20,7 +20,7 @@ import ( ) type Repository interface { - Create(headerID int64, transactionIndex uint, model FrobModel) error + Create(headerID int64, model FrobModel) error MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) } @@ -32,10 +32,10 @@ func NewFrobRepository(db *postgres.DB) FrobRepository { return FrobRepository{db: db} } -func (repository FrobRepository) Create(headerID int64, transactionIndex uint, model FrobModel) error { - _, err := repository.db.Exec(`INSERT INTO maker.frob (header_id, tx_idx, art, dart, dink, iart, ilk, ink, lad) - VALUES($1, $2, $3::NUMERIC, $4::NUMERIC, $5::NUMERIC, $6::NUMERIC, $7, $8::NUMERIC, $9)`, - headerID, transactionIndex, model.Art, model.Dart, model.Dink, model.IArt, model.Ilk, model.Ink, model.Lad) +func (repository FrobRepository) Create(headerID int64, model FrobModel) error { + _, err := repository.db.Exec(`INSERT INTO maker.frob (header_id, art, dart, dink, iart, ilk, ink, urn, raw_log, tx_idx) + VALUES($1, $2::NUMERIC, $3::NUMERIC, $4::NUMERIC, $5::NUMERIC, $6, $7::NUMERIC, $8, $9, $10)`, + headerID, model.Art, model.Dart, model.Dink, model.IArt, model.Ilk, model.Ink, model.Urn, model.Raw, model.TransactionIndex) return err } diff --git a/pkg/transformers/frob/repository_test.go b/pkg/transformers/frob/repository_test.go index cd7378f2..bfba9eed 100644 --- a/pkg/transformers/frob/repository_test.go +++ b/pkg/transformers/frob/repository_test.go @@ -30,56 +30,61 @@ import ( var _ = Describe("Frob repository", func() { Describe("Create", func() { It("adds a frob", func() { - node := core.Node{} - db := test_config.NewTestDB(node) + db := test_config.NewTestDB(core.Node{}) test_config.CleanTestDB(db) headerRepository := repositories.NewHeaderRepository(db) headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{}) Expect(err).NotTo(HaveOccurred()) frobRepository := frob.NewFrobRepository(db) - err = frobRepository.Create(headerID, 123, test_data.FrobModel) + err = frobRepository.Create(headerID, test_data.FrobModel) Expect(err).NotTo(HaveOccurred()) var dbFrob frob.FrobModel - err = db.Get(&dbFrob, `SELECT art, dart, dink, iart, ilk, ink, lad FROM maker.frob WHERE header_id = $1`, headerID) + err = db.Get(&dbFrob, `SELECT art, dart, dink, iart, ilk, ink, urn, tx_idx, raw_log FROM maker.frob WHERE header_id = $1`, headerID) Expect(err).NotTo(HaveOccurred()) - Expect(dbFrob).To(Equal(test_data.FrobModel)) + Expect(dbFrob.Ilk).To(Equal(test_data.FrobModel.Ilk)) + Expect(dbFrob.Urn).To(Equal(test_data.FrobModel.Urn)) + Expect(dbFrob.Ink).To(Equal(test_data.FrobModel.Ink)) + Expect(dbFrob.Art).To(Equal(test_data.FrobModel.Art)) + Expect(dbFrob.Dink).To(Equal(test_data.FrobModel.Dink)) + Expect(dbFrob.Dart).To(Equal(test_data.FrobModel.Dart)) + Expect(dbFrob.IArt).To(Equal(test_data.FrobModel.IArt)) + Expect(dbFrob.TransactionIndex).To(Equal(test_data.FrobModel.TransactionIndex)) + Expect(dbFrob.Raw).To(MatchJSON(test_data.FrobModel.Raw)) }) It("does not duplicate frob events", func() { - node := core.Node{} - db := test_config.NewTestDB(node) + db := test_config.NewTestDB(core.Node{}) test_config.CleanTestDB(db) headerRepository := repositories.NewHeaderRepository(db) headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{}) Expect(err).NotTo(HaveOccurred()) frobRepository := frob.NewFrobRepository(db) - err = frobRepository.Create(headerID, 123, test_data.FrobModel) + err = frobRepository.Create(headerID, test_data.FrobModel) Expect(err).NotTo(HaveOccurred()) - err = frobRepository.Create(headerID, 123, test_data.FrobModel) + err = frobRepository.Create(headerID, test_data.FrobModel) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint")) }) It("removes frob if corresponding header is deleted", func() { - node := core.Node{} - db := test_config.NewTestDB(node) + db := test_config.NewTestDB(core.Node{}) test_config.CleanTestDB(db) headerRepository := repositories.NewHeaderRepository(db) headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{}) Expect(err).NotTo(HaveOccurred()) frobRepository := frob.NewFrobRepository(db) - err = frobRepository.Create(headerID, 123, test_data.FrobModel) + err = frobRepository.Create(headerID, test_data.FrobModel) Expect(err).NotTo(HaveOccurred()) _, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID) Expect(err).NotTo(HaveOccurred()) var dbFrob frob.FrobModel - err = db.Get(&dbFrob, `SELECT art, iart, ilk, ink, lad FROM maker.frob WHERE header_id = $1`, headerID) + err = db.Get(&dbFrob, `SELECT art, iart, ilk, ink, urn, tx_idx, raw_log FROM maker.frob WHERE header_id = $1`, headerID) Expect(err).To(HaveOccurred()) Expect(err).To(MatchError(sql.ErrNoRows)) }) @@ -87,8 +92,7 @@ var _ = Describe("Frob repository", func() { Describe("MissingHeaders", func() { It("returns headers with no associated frob event", func() { - node := core.Node{} - db := test_config.NewTestDB(node) + db := test_config.NewTestDB(core.Node{}) test_config.CleanTestDB(db) headerRepository := repositories.NewHeaderRepository(db) startingBlockNumber := int64(1) @@ -102,7 +106,7 @@ var _ = Describe("Frob repository", func() { Expect(err).NotTo(HaveOccurred()) } frobRepository := frob.NewFrobRepository(db) - err := frobRepository.Create(headerIDs[1], 123, test_data.FrobModel) + err := frobRepository.Create(headerIDs[1], test_data.FrobModel) Expect(err).NotTo(HaveOccurred()) headers, err := frobRepository.MissingHeaders(startingBlockNumber, endingBlockNumber) @@ -114,13 +118,11 @@ var _ = Describe("Frob repository", func() { }) It("only returns headers associated with the current node", func() { - nodeOne := core.Node{} - db := test_config.NewTestDB(nodeOne) + db := test_config.NewTestDB(core.Node{}) test_config.CleanTestDB(db) blockNumbers := []int64{1, 2, 3} headerRepository := repositories.NewHeaderRepository(db) - nodeTwo := core.Node{ID: "second"} - dbTwo := test_config.NewTestDB(nodeTwo) + dbTwo := test_config.NewTestDB(core.Node{ID: "second"}) headerRepositoryTwo := repositories.NewHeaderRepository(dbTwo) var headerIDs []int64 for _, n := range blockNumbers { @@ -132,7 +134,7 @@ var _ = Describe("Frob repository", func() { } frobRepository := frob.NewFrobRepository(db) frobRepositoryTwo := frob.NewFrobRepository(dbTwo) - err := frobRepository.Create(headerIDs[0], 0, test_data.FrobModel) + err := frobRepository.Create(headerIDs[0], test_data.FrobModel) Expect(err).NotTo(HaveOccurred()) nodeOneMissingHeaders, err := frobRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) diff --git a/pkg/transformers/frob/transformer.go b/pkg/transformers/frob/transformer.go index 324e345e..3460bac2 100644 --- a/pkg/transformers/frob/transformer.go +++ b/pkg/transformers/frob/transformer.go @@ -51,7 +51,7 @@ func (transformer FrobTransformer) Execute() error { return err } for _, header := range missingHeaders { - topics := [][]common.Hash{{common.HexToHash(FrobEventSignature)}} + topics := [][]common.Hash{{common.HexToHash(shared.FrobSignature)}} matchingLogs, err := transformer.Fetcher.FetchLogs(FrobConfig.ContractAddress, topics, header.BlockNumber) if err != nil { return err @@ -61,8 +61,11 @@ func (transformer FrobTransformer) Execute() error { if err != nil { return err } - model := transformer.Converter.ToModel(entity) - err = transformer.Repository.Create(header.Id, log.TxIndex, model) + model, err := transformer.Converter.ToModel(entity) + if err != nil { + return err + } + err = transformer.Repository.Create(header.Id, model) if err != nil { return err } diff --git a/pkg/transformers/frob/transformer_test.go b/pkg/transformers/frob/transformer_test.go index 36e7fa4c..58d4348c 100644 --- a/pkg/transformers/frob/transformer_test.go +++ b/pkg/transformers/frob/transformer_test.go @@ -23,6 +23,7 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/transformers/frob" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks" frob_mocks "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks/frob" @@ -75,7 +76,7 @@ var _ = Describe("Frob transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) Expect(fetcher.FetchedContractAddress).To(Equal(frob.FrobConfig.ContractAddress)) - Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(frob.FrobEventSignature)}})) + Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.FrobSignature)}})) }) It("returns error if fetcher returns error", func() { @@ -95,7 +96,7 @@ var _ = Describe("Frob transformer", func() { Expect(err).To(MatchError(fakes.FakeError)) }) - It("converts matching logs", func() { + It("converts matching logs to entity", func() { converter := &frob_mocks.MockFrobConverter{} fetcher := &mocks.MockLogFetcher{} fetcher.SetFetchedLogs([]types.Log{test_data.EthFrobLog}) @@ -113,12 +114,48 @@ var _ = Describe("Frob transformer", func() { Expect(converter.PassedContractAddress).To(Equal(frob.FrobConfig.ContractAddress)) Expect(converter.PassedContractABI).To(Equal(frob.FrobConfig.ContractAbi)) Expect(converter.PassedLog).To(Equal(test_data.EthFrobLog)) + }) + + It("returns error if converting to entity returns error", func() { + converter := &frob_mocks.MockFrobConverter{} + converter.SetToEntityError(fakes.FakeError) + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthFrobLog}) + repository := &frob_mocks.MockFrobRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) + transformer := frob.FrobTransformer{ + Fetcher: fetcher, + Converter: converter, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("converts frob entity to model", func() { + converter := &frob_mocks.MockFrobConverter{} + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthFrobLog}) + repository := &frob_mocks.MockFrobRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) + transformer := frob.FrobTransformer{ + Fetcher: fetcher, + Converter: converter, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).NotTo(HaveOccurred()) Expect(converter.PassedEntity).To(Equal(test_data.FrobEntity)) }) - It("returns error if converter returns error", func() { + It("returns error if converting to model returns error", func() { converter := &frob_mocks.MockFrobConverter{} - converter.SetConverterError(fakes.FakeError) + converter.SetToModelError(fakes.FakeError) fetcher := &mocks.MockLogFetcher{} fetcher.SetFetchedLogs([]types.Log{test_data.EthFrobLog}) repository := &frob_mocks.MockFrobRepository{} @@ -152,7 +189,6 @@ var _ = Describe("Frob transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id)) - Expect(repository.PassedTransactionIndex).To(Equal(test_data.EthFrobLog.TxIndex)) Expect(repository.PassedFrobModel).To(Equal(test_data.FrobModel)) }) diff --git a/pkg/transformers/pit_file/repository_test.go b/pkg/transformers/pit_file/repository_test.go index d86a46e9..bb7624ee 100644 --- a/pkg/transformers/pit_file/repository_test.go +++ b/pkg/transformers/pit_file/repository_test.go @@ -31,7 +31,6 @@ var _ = Describe("Pit file repository", func() { Expect(dbPitFile.What).To(Equal(test_data.PitFileModel.What)) Expect(dbPitFile.Risk).To(Equal(test_data.PitFileModel.Risk)) Expect(dbPitFile.TransactionIndex).To(Equal(test_data.PitFileModel.TransactionIndex)) - // The raw bytes scanned out of the DB are compressed (missing whitespace), such that they don't strictly equal the input bytes Expect(dbPitFile.Raw).To(MatchJSON(test_data.PitFileModel.Raw)) }) diff --git a/pkg/transformers/shared/constants.go b/pkg/transformers/shared/constants.go index e1fda760..68475d5d 100644 --- a/pkg/transformers/shared/constants.go +++ b/pkg/transformers/shared/constants.go @@ -18,7 +18,8 @@ var ( FlipperABI = `[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"bids","outputs":[{"name":"bid","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"guy","type":"address"},{"name":"tic","type":"uint48"},{"name":"end","type":"uint48"},{"name":"urn","type":"bytes32"},{"name":"gal","type":"address"},{"name":"tab","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x4423c5f1"},{"constant":true,"inputs":[],"name":"ttl","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x4e8b1dd5"},{"constant":true,"inputs":[],"name":"gem","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x7bd2bea7"},{"constant":true,"inputs":[],"name":"beg","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x7d780d82"},{"constant":true,"inputs":[],"name":"tau","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xcfc4af55"},{"constant":true,"inputs":[],"name":"kicks","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xcfdd3302"},{"constant":true,"inputs":[],"name":"dai","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xf4b9fa75"},{"inputs":[{"name":"dai_","type":"address"},{"name":"gem_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor","signature":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"id","type":"uint256"},{"indexed":false,"name":"lot","type":"uint256"},{"indexed":false,"name":"bid","type":"uint256"},{"indexed":false,"name":"gal","type":"address"},{"indexed":false,"name":"end","type":"uint48"},{"indexed":true,"name":"urn","type":"bytes32"},{"indexed":false,"name":"tab","type":"uint256"}],"name":"Kick","type":"event","signature":"0xbac86238bdba81d21995024470425ecb370078fa62b7271b90cf28cbd1e3e87e"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event","signature":"0x644843f351d3fba4abcd60109eaff9f54bac8fb8ccf0bab941009c21df21cf31"},{"constant":true,"inputs":[],"name":"era","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x143e55e0"},{"constant":false,"inputs":[{"name":"urn","type":"bytes32"},{"name":"gal","type":"address"},{"name":"tab","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"kick","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xeae19d9e"},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"tick","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xfc7b6aee"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"tend","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x4b43ed12"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"dent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x5ff3a382"},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"deal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xc959c42b"}]` FlipperContractAddress = "0x6b59c42097e2fff7cad96cb08ceefd601081ad9c" //this is a temporary address deployed locally FlipKickSignature = "0x8828a22eb6a18623309ad55592866c4b077989e9e8a25e1b85f9bf6f7282520f" - PitABI = `[{"constant":true,"inputs":[],"name":"vat","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"live","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"drip","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"Line","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"wards","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"ilks","outputs":[{"name":"spot","type":"uint256"},{"name":"line","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"vat_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"ilk","type":"bytes32"},{"indexed":true,"name":"lad","type":"bytes32"},{"indexed":false,"name":"ink","type":"uint256"},{"indexed":false,"name":"art","type":"uint256"},{"indexed":false,"name":"dink","type":"int256"},{"indexed":false,"name":"dart","type":"int256"},{"indexed":false,"name":"iArt","type":"uint256"}],"name":"Frob","type":"event"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"address"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"dink","type":"int256"},{"name":"dart","type":"int256"}],"name":"frob","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]` + FrobSignature = "0x6cedf1d3a466a3d6bab04887b1642177bf6dbf1daa737c2e8f639cd0b020d9d0" + PitABI = `[{"constant":true,"inputs":[],"name":"vat","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x36569e77"},{"constant":true,"inputs":[],"name":"live","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x957aa58c"},{"constant":true,"inputs":[],"name":"drip","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x9f678cca"},{"constant":true,"inputs":[],"name":"Line","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xbabe8a3f"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"wards","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xbf353dbb"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"ilks","outputs":[{"name":"spot","type":"uint256"},{"name":"line","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xd9638d36"},{"inputs":[{"name":"vat_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor","signature":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"ilk","type":"bytes32"},{"indexed":true,"name":"urn","type":"bytes32"},{"indexed":false,"name":"ink","type":"uint256"},{"indexed":false,"name":"art","type":"uint256"},{"indexed":false,"name":"dink","type":"int256"},{"indexed":false,"name":"dart","type":"int256"},{"indexed":false,"name":"iArt","type":"uint256"}],"name":"Frob","type":"event","signature":"0xb2afa28318bcc689926b52835d844de174ef8de97e982a85c0199d584920791b"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event","signature":"0x644843f351d3fba4abcd60109eaff9f54bac8fb8ccf0bab941009c21df21cf31"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x65fae35e"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x9c52a7f1"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x1a0b287e"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x29ae8114"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"address"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xd4e8be83"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"dink","type":"int256"},{"name":"dart","type":"int256"}],"name":"frob","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x5a984ded"}]` PitFileSignature = "0x1a0b287e00000000000000000000000000000000000000000000000000000000" TendFunctionSignature = "0x4b43ed1200000000000000000000000000000000000000000000000000000000" BiteSignature = "0x44a8f29dfcf27e5dd7a4db50b390f851bf3ecf2bf221243be3e853f586134455" diff --git a/pkg/transformers/test_data/frob.go b/pkg/transformers/test_data/frob.go index 673194e4..f494756f 100644 --- a/pkg/transformers/test_data/frob.go +++ b/pkg/transformers/test_data/frob.go @@ -15,6 +15,7 @@ package test_data import ( + "encoding/json" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" @@ -59,21 +60,26 @@ var EthFrobLog = types.Log{ } var FrobEntity = frob.FrobEntity{ - Ilk: ilk, - Lad: frobLad, - Dink: dink, - Dart: dart, - Ink: ink, - Art: art, - IArt: iArt, + Ilk: ilk, + Urn: frobLad, + Ink: ink, + Art: art, + Dink: dink, + Dart: dart, + IArt: iArt, + TransactionIndex: EthFrobLog.TxIndex, + Raw: EthFrobLog, } +var rawFrobLog, _ = json.Marshal(EthFrobLog) var FrobModel = frob.FrobModel{ - Ilk: ilk[:], - Lad: frobLad[:], - Dink: dink.String(), - Dart: dart.String(), - Ink: ink.String(), - Art: art.String(), - IArt: iArt.String(), + Ilk: ilk[:], + Urn: frobLad[:], + Ink: ink.String(), + Art: art.String(), + Dink: dink.String(), + Dart: dart.String(), + IArt: iArt.String(), + TransactionIndex: EthFrobLog.TxIndex, + Raw: rawFrobLog, } diff --git a/pkg/transformers/test_data/mocks/frob/converter.go b/pkg/transformers/test_data/mocks/frob/converter.go index a290840e..0624141a 100644 --- a/pkg/transformers/test_data/mocks/frob/converter.go +++ b/pkg/transformers/test_data/mocks/frob/converter.go @@ -25,21 +25,26 @@ type MockFrobConverter struct { PassedContractABI string PassedLog types.Log PassedEntity frob.FrobEntity - converterError error + toEntityError error + toModelError error } -func (converter *MockFrobConverter) SetConverterError(err error) { - converter.converterError = err +func (converter *MockFrobConverter) SetToEntityError(err error) { + converter.toEntityError = err +} + +func (converter *MockFrobConverter) SetToModelError(err error) { + converter.toModelError = err } func (converter *MockFrobConverter) ToEntity(contractAddress string, contractAbi string, ethLog types.Log) (frob.FrobEntity, error) { converter.PassedContractAddress = contractAddress converter.PassedContractABI = contractAbi converter.PassedLog = ethLog - return test_data.FrobEntity, converter.converterError + return test_data.FrobEntity, converter.toEntityError } -func (converter *MockFrobConverter) ToModel(frobEntity frob.FrobEntity) frob.FrobModel { +func (converter *MockFrobConverter) ToModel(frobEntity frob.FrobEntity) (frob.FrobModel, error) { converter.PassedEntity = frobEntity - return test_data.FrobModel + return test_data.FrobModel, converter.toModelError } diff --git a/pkg/transformers/test_data/mocks/frob/repository.go b/pkg/transformers/test_data/mocks/frob/repository.go index 79c37ab5..5358fda6 100644 --- a/pkg/transformers/test_data/mocks/frob/repository.go +++ b/pkg/transformers/test_data/mocks/frob/repository.go @@ -25,7 +25,6 @@ type MockFrobRepository struct { PassedFrobModel frob.FrobModel PassedHeaderID int64 PassedStartingBlockNumber int64 - PassedTransactionIndex uint missingHeaders []core.Header missingHeadersErr error } @@ -42,9 +41,8 @@ func (repository *MockFrobRepository) SetMissingHeaders(headers []core.Header) { repository.missingHeaders = headers } -func (repository *MockFrobRepository) Create(headerID int64, transactionIndex uint, model frob.FrobModel) error { +func (repository *MockFrobRepository) Create(headerID int64, model frob.FrobModel) error { repository.PassedHeaderID = headerID - repository.PassedTransactionIndex = transactionIndex repository.PassedFrobModel = model return repository.createError } diff --git a/pkg/transformers/test_data/pit_file.go b/pkg/transformers/test_data/pit_file.go index db1a0c0a..49232706 100644 --- a/pkg/transformers/test_data/pit_file.go +++ b/pkg/transformers/test_data/pit_file.go @@ -30,12 +30,11 @@ var EthPitFileLog = types.Log{ Removed: false, } -var raw, _ = json.Marshal(EthPitFileLog) - +var rawPitFileLog, _ = json.Marshal(EthPitFileLog) var PitFileModel = pit_file.PitFileModel{ Ilk: "fake ilk", What: "spot", Risk: big.NewInt(123).String(), TransactionIndex: EthPitFileLog.TxIndex, - Raw: raw, + Raw: rawPitFileLog, } From a30e5036fdc43eb262b9528946c87818c8518366 Mon Sep 17 00:00:00 2001 From: Rob Mulholand Date: Tue, 4 Sep 2018 16:01:23 -0500 Subject: [PATCH 3/5] generate log event signatures from functions --- pkg/transformers/bite/config.go | 4 +- pkg/transformers/bite/constants.go | 22 ------ pkg/transformers/bite/converter_test.go | 3 +- pkg/transformers/bite/integration_test.go | 4 +- pkg/transformers/pit_file/config.go | 2 +- pkg/transformers/pit_file/transformer.go | 2 +- pkg/transformers/pit_file/transformer_test.go | 2 +- pkg/transformers/price_feeds/constants.go | 2 - .../price_feeds/converter_test.go | 3 +- pkg/transformers/price_feeds/fetcher.go | 3 +- pkg/transformers/price_feeds/fetcher_test.go | 3 +- pkg/transformers/shared/constants.go | 29 ++++++-- .../shared/event_signature_generator.go | 14 ++++ .../shared/event_signature_generator_test.go | 69 +++++++++++++++++++ 14 files changed, 120 insertions(+), 42 deletions(-) delete mode 100644 pkg/transformers/bite/constants.go create mode 100644 pkg/transformers/shared/event_signature_generator.go create mode 100644 pkg/transformers/shared/event_signature_generator_test.go diff --git a/pkg/transformers/bite/config.go b/pkg/transformers/bite/config.go index f05a5c29..4d22a611 100644 --- a/pkg/transformers/bite/config.go +++ b/pkg/transformers/bite/config.go @@ -22,8 +22,8 @@ import ( var BiteConfig = shared.TransformerConfig{ ContractAddress: "0xe0f0fa6982c59d8aa4ae0134bfe048327bd788cacf758b643ca41f055ffce76c", //this is a temporary address deployed locally - ContractAbi: BiteABI, - Topics: []string{BiteSignature}, + ContractAbi: shared.CatABI, + Topics: []string{shared.BiteSignature}, StartingBlockNumber: 0, EndingBlockNumber: 100, } diff --git a/pkg/transformers/bite/constants.go b/pkg/transformers/bite/constants.go deleted file mode 100644 index 66f3ee3f..00000000 --- a/pkg/transformers/bite/constants.go +++ /dev/null @@ -1,22 +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 bite - -var ( - BiteABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"vat\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"vow\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"flips\",\"outputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"lad\",\"type\":\"bytes32\"},{\"name\":\"ink\",\"type\":\"uint256\"},{\"name\":\"tab\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"nflip\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"live\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"wards\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"ilks\",\"outputs\":[{\"name\":\"flip\",\"type\":\"address\"},{\"name\":\"chop\",\"type\":\"uint256\"},{\"name\":\"lump\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"pit\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"vat_\",\"type\":\"address\"},{\"name\":\"pit_\",\"type\":\"address\"},{\"name\":\"vow_\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"ilk\",\"type\":\"bytes32\"},{\"indexed\":true,\"name\":\"lad\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"ink\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"art\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"tab\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"flip\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"iArt\",\"type\":\"uint256\"}],\"name\":\"Bite\",\"type\":\"event\"},{\"anonymous\":true,\"inputs\":[{\"indexed\":true,\"name\":\"sig\",\"type\":\"bytes4\"},{\"indexed\":true,\"name\":\"guy\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"foo\",\"type\":\"bytes32\"},{\"indexed\":true,\"name\":\"bar\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"wad\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"fax\",\"type\":\"bytes\"}],\"name\":\"LogNote\",\"type\":\"event\"},{\"constant\":false,\"inputs\":[{\"name\":\"guy\",\"type\":\"address\"}],\"name\":\"rely\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"guy\",\"type\":\"address\"}],\"name\":\"deny\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"what\",\"type\":\"bytes32\"},{\"name\":\"data\",\"type\":\"uint256\"}],\"name\":\"file\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"what\",\"type\":\"bytes32\"},{\"name\":\"flip\",\"type\":\"address\"}],\"name\":\"file\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"lad\",\"type\":\"bytes32\"}],\"name\":\"bite\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"n\",\"type\":\"uint256\"},{\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"flip\",\"outputs\":[{\"name\":\"id\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" - BiteSignature = "0x99b5620489b6ef926d4518936cfec15d305452712b88bd59da2d9c10fb0953e8" -) diff --git a/pkg/transformers/bite/converter_test.go b/pkg/transformers/bite/converter_test.go index f7f48137..e3120c5d 100644 --- a/pkg/transformers/bite/converter_test.go +++ b/pkg/transformers/bite/converter_test.go @@ -26,6 +26,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" ) var _ = Describe("Bite Converter", func() { @@ -33,7 +34,7 @@ var _ = Describe("Bite Converter", func() { Describe("ToEntity", func() { It("converts an eth log to a bite entity", func() { - entity, err := converter.ToEntity(test_data.TemporaryBiteAddress, bite.BiteABI, test_data.EthBiteLog) + entity, err := converter.ToEntity(test_data.TemporaryBiteAddress, shared.CatABI, test_data.EthBiteLog) Expect(err).NotTo(HaveOccurred()) Expect(entity.Ilk).To(Equal(test_data.BiteEntity.Ilk)) diff --git a/pkg/transformers/bite/integration_test.go b/pkg/transformers/bite/integration_test.go index aa803143..881a45d0 100644 --- a/pkg/transformers/bite/integration_test.go +++ b/pkg/transformers/bite/integration_test.go @@ -48,7 +48,7 @@ var _ = Describe("Integration tests", func() { transactionConverter := rpc2.NewRpcTransactionConverter(ethClient) realBlockChain := geth.NewBlockChain(blockChainClient, realNode, transactionConverter) realFetcher := shared.NewFetcher(realBlockChain) - topic0 := common.HexToHash(bite.BiteSignature) + topic0 := common.HexToHash(shared.BiteSignature) topics := [][]common.Hash{{topic0}} result, err := realFetcher.FetchLogs(test_data.TemporaryBiteAddress, topics, int64(26)) @@ -64,7 +64,7 @@ var _ = Describe("Integration tests", func() { It("unpacks an event log", func() { address := common.HexToAddress(test_data.TemporaryBiteAddress) - abi, err := geth.ParseAbi(bite.BiteABI) + abi, err := geth.ParseAbi(shared.CatABI) Expect(err).NotTo(HaveOccurred()) contract := bind.NewBoundContract(address, abi, nil, nil, nil) diff --git a/pkg/transformers/pit_file/config.go b/pkg/transformers/pit_file/config.go index d7b9516c..4298910c 100644 --- a/pkg/transformers/pit_file/config.go +++ b/pkg/transformers/pit_file/config.go @@ -7,7 +7,7 @@ import ( var PitFileConfig = shared.TransformerConfig{ ContractAddress: "0xff3f2400f1600f3f493a9a92704a29b96795af1a", // temporary address from Ganache deploy ContractAbi: shared.PitABI, - Topics: []string{shared.PitFileSignature}, + Topics: []string{shared.PitFileSignatureOne}, StartingBlockNumber: 0, EndingBlockNumber: 100, } diff --git a/pkg/transformers/pit_file/transformer.go b/pkg/transformers/pit_file/transformer.go index c6c38ad3..3c91c04d 100644 --- a/pkg/transformers/pit_file/transformer.go +++ b/pkg/transformers/pit_file/transformer.go @@ -36,7 +36,7 @@ func (transformer PitFileTransformer) Execute() error { return err } for _, header := range missingHeaders { - topics := [][]common.Hash{{common.HexToHash(shared.PitFileSignature)}} + topics := [][]common.Hash{{common.HexToHash(shared.PitFileSignatureOne)}} matchingLogs, err := transformer.Fetcher.FetchLogs(PitFileConfig.ContractAddress, topics, header.BlockNumber) if err != nil { return err diff --git a/pkg/transformers/pit_file/transformer_test.go b/pkg/transformers/pit_file/transformer_test.go index e9351b3c..ea39787d 100644 --- a/pkg/transformers/pit_file/transformer_test.go +++ b/pkg/transformers/pit_file/transformer_test.go @@ -61,7 +61,7 @@ var _ = Describe("Pit file transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) Expect(fetcher.FetchedContractAddress).To(Equal(pit_file.PitFileConfig.ContractAddress)) - Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.PitFileSignature)}})) + Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.PitFileSignatureOne)}})) }) It("returns error if fetcher returns error", func() { diff --git a/pkg/transformers/price_feeds/constants.go b/pkg/transformers/price_feeds/constants.go index 846adf74..9a407c42 100644 --- a/pkg/transformers/price_feeds/constants.go +++ b/pkg/transformers/price_feeds/constants.go @@ -22,7 +22,5 @@ import ( var ( ErrNoMatchingLog = errors.New("no matching log") Ether = big.NewFloat(1e18) - LogValueTopic0 = "0x296ba4ca62c6c21c95e828080cb8aec7481b71390585605300a8a76f9e95b527" - MedianizerABI = `[{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"","type":"bytes32"}],"name":"poke","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"poke","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"compute","outputs":[{"name":"","type":"bytes32"},{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"wat","type":"address"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"wat","type":"address"}],"name":"unset","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"indexes","outputs":[{"name":"","type":"bytes12"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"next","outputs":[{"name":"","type":"bytes12"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"read","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"peek","outputs":[{"name":"","type":"bytes32"},{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes12"}],"name":"values","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"min_","type":"uint96"}],"name":"setMin","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"void","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"pos","type":"bytes12"},{"name":"wat","type":"address"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"pos","type":"bytes12"}],"name":"unset","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"next_","type":"bytes12"}],"name":"setNext","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"min","outputs":[{"name":"","type":"uint96"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"val","type":"bytes32"}],"name":"LogValue","type":"event"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}]]` Ray = big.NewFloat(1e27) ) diff --git a/pkg/transformers/price_feeds/converter_test.go b/pkg/transformers/price_feeds/converter_test.go index 0c309477..89111265 100644 --- a/pkg/transformers/price_feeds/converter_test.go +++ b/pkg/transformers/price_feeds/converter_test.go @@ -21,6 +21,7 @@ import ( . "github.com/onsi/gomega" "github.com/vulcanize/vulcanizedb/pkg/transformers/price_feeds" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" ) var _ = Describe("Price feed converter", func() { @@ -31,7 +32,7 @@ var _ = Describe("Price feed converter", func() { // https://etherscan.io/tx/0xa51a50a2adbfba4e2ab3d72dfd67a21c769f1bc8d2b180663a15500a56cde58f log := types.Log{ Address: medianizerAddress, - Topics: []common.Hash{common.HexToHash(price_feeds.LogValueTopic0)}, + Topics: []common.Hash{common.HexToHash(shared.LogValueSignature)}, Data: common.FromHex("00000000000000000000000000000000000000000000001486f658319fb0c100"), BlockNumber: blockNumber, TxHash: common.HexToHash("0xa51a50a2adbfba4e2ab3d72dfd67a21c769f1bc8d2b180663a15500a56cde58f"), diff --git a/pkg/transformers/price_feeds/fetcher.go b/pkg/transformers/price_feeds/fetcher.go index ecc79d4d..5918bc42 100644 --- a/pkg/transformers/price_feeds/fetcher.go +++ b/pkg/transformers/price_feeds/fetcher.go @@ -19,6 +19,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "math/big" ) @@ -48,7 +49,7 @@ func (fetcher PriceFeedFetcher) FetchLogValues(blockNumber int64) ([]types.Log, FromBlock: n, ToBlock: n, Addresses: addresses, - Topics: [][]common.Hash{{common.HexToHash(LogValueTopic0)}}, + Topics: [][]common.Hash{{common.HexToHash(shared.LogValueSignature)}}, } return fetcher.blockChain.GetEthLogsWithCustomQuery(query) } diff --git a/pkg/transformers/price_feeds/fetcher_test.go b/pkg/transformers/price_feeds/fetcher_test.go index acb0acfb..e6bb942a 100644 --- a/pkg/transformers/price_feeds/fetcher_test.go +++ b/pkg/transformers/price_feeds/fetcher_test.go @@ -25,6 +25,7 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/transformers/price_feeds" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" ) var _ = Describe("Price fetcher", func() { @@ -46,7 +47,7 @@ var _ = Describe("Price fetcher", func() { FromBlock: big.NewInt(blockNumber), ToBlock: big.NewInt(blockNumber), Addresses: expectedAddresses, - Topics: [][]common.Hash{{common.HexToHash(price_feeds.LogValueTopic0)}}, + Topics: [][]common.Hash{{common.HexToHash(shared.LogValueSignature)}}, } mockBlockChain.AssertGetEthLogsWithCustomQueryCalledWith(expectedQuery) }) diff --git a/pkg/transformers/shared/constants.go b/pkg/transformers/shared/constants.go index 68475d5d..c417e088 100644 --- a/pkg/transformers/shared/constants.go +++ b/pkg/transformers/shared/constants.go @@ -15,12 +15,27 @@ package shared var ( - FlipperABI = `[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"bids","outputs":[{"name":"bid","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"guy","type":"address"},{"name":"tic","type":"uint48"},{"name":"end","type":"uint48"},{"name":"urn","type":"bytes32"},{"name":"gal","type":"address"},{"name":"tab","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x4423c5f1"},{"constant":true,"inputs":[],"name":"ttl","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x4e8b1dd5"},{"constant":true,"inputs":[],"name":"gem","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x7bd2bea7"},{"constant":true,"inputs":[],"name":"beg","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x7d780d82"},{"constant":true,"inputs":[],"name":"tau","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xcfc4af55"},{"constant":true,"inputs":[],"name":"kicks","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xcfdd3302"},{"constant":true,"inputs":[],"name":"dai","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xf4b9fa75"},{"inputs":[{"name":"dai_","type":"address"},{"name":"gem_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor","signature":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"id","type":"uint256"},{"indexed":false,"name":"lot","type":"uint256"},{"indexed":false,"name":"bid","type":"uint256"},{"indexed":false,"name":"gal","type":"address"},{"indexed":false,"name":"end","type":"uint48"},{"indexed":true,"name":"urn","type":"bytes32"},{"indexed":false,"name":"tab","type":"uint256"}],"name":"Kick","type":"event","signature":"0xbac86238bdba81d21995024470425ecb370078fa62b7271b90cf28cbd1e3e87e"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event","signature":"0x644843f351d3fba4abcd60109eaff9f54bac8fb8ccf0bab941009c21df21cf31"},{"constant":true,"inputs":[],"name":"era","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x143e55e0"},{"constant":false,"inputs":[{"name":"urn","type":"bytes32"},{"name":"gal","type":"address"},{"name":"tab","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"kick","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xeae19d9e"},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"tick","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xfc7b6aee"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"tend","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x4b43ed12"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"dent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x5ff3a382"},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"deal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xc959c42b"}]` + biteMethod = "Bite(bytes32,bytes32,uint256,uint256,uint256,uint256,uint256)" + flipKickMethod = "Kick(uint256,uint256,uint256,address,uint48,bytes32,uint256)" + frobMethod = "Frob(bytes32,bytes32,uint256,uint256,int256,int256,uint256)" + pitFileMethodOne = "file(bytes32,bytes32,uint256)" + pitFileMethodThree = "file(bytes32,address)" + pitFileMethodTwo = "file(bytes32,uint256)" + tendMethod = "tend(uint256,uint256,uint256)" + + CatABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"vat\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"vow\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"flips\",\"outputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"lad\",\"type\":\"bytes32\"},{\"name\":\"ink\",\"type\":\"uint256\"},{\"name\":\"tab\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"nflip\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"live\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"wards\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"ilks\",\"outputs\":[{\"name\":\"flip\",\"type\":\"address\"},{\"name\":\"chop\",\"type\":\"uint256\"},{\"name\":\"lump\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"pit\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"vat_\",\"type\":\"address\"},{\"name\":\"pit_\",\"type\":\"address\"},{\"name\":\"vow_\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"ilk\",\"type\":\"bytes32\"},{\"indexed\":true,\"name\":\"lad\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"ink\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"art\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"tab\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"flip\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"iArt\",\"type\":\"uint256\"}],\"name\":\"Bite\",\"type\":\"event\"},{\"anonymous\":true,\"inputs\":[{\"indexed\":true,\"name\":\"sig\",\"type\":\"bytes4\"},{\"indexed\":true,\"name\":\"guy\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"foo\",\"type\":\"bytes32\"},{\"indexed\":true,\"name\":\"bar\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"wad\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"fax\",\"type\":\"bytes\"}],\"name\":\"LogNote\",\"type\":\"event\"},{\"constant\":false,\"inputs\":[{\"name\":\"guy\",\"type\":\"address\"}],\"name\":\"rely\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"guy\",\"type\":\"address\"}],\"name\":\"deny\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"what\",\"type\":\"bytes32\"},{\"name\":\"data\",\"type\":\"uint256\"}],\"name\":\"file\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"what\",\"type\":\"bytes32\"},{\"name\":\"flip\",\"type\":\"address\"}],\"name\":\"file\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"lad\",\"type\":\"bytes32\"}],\"name\":\"bite\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"n\",\"type\":\"uint256\"},{\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"flip\",\"outputs\":[{\"name\":\"id\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" + FlipperABI = `[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"bids","outputs":[{"name":"bid","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"guy","type":"address"},{"name":"tic","type":"uint48"},{"name":"end","type":"uint48"},{"name":"urn","type":"bytes32"},{"name":"gal","type":"address"},{"name":"tab","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x4423c5f1"},{"constant":true,"inputs":[],"name":"ttl","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x4e8b1dd5"},{"constant":true,"inputs":[],"name":"gem","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x7bd2bea7"},{"constant":true,"inputs":[],"name":"beg","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x7d780d82"},{"constant":true,"inputs":[],"name":"tau","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xcfc4af55"},{"constant":true,"inputs":[],"name":"kicks","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xcfdd3302"},{"constant":true,"inputs":[],"name":"dai","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xf4b9fa75"},{"inputs":[{"name":"dai_","type":"address"},{"name":"gem_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor","signature":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"id","type":"uint256"},{"indexed":false,"name":"lot","type":"uint256"},{"indexed":false,"name":"bid","type":"uint256"},{"indexed":false,"name":"gal","type":"address"},{"indexed":false,"name":"end","type":"uint48"},{"indexed":true,"name":"urn","type":"bytes32"},{"indexed":false,"name":"tab","type":"uint256"}],"name":"Kick","type":"event","signature":"0xbac86238bdba81d21995024470425ecb370078fa62b7271b90cf28cbd1e3e87e"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event","signature":"0x644843f351d3fba4abcd60109eaff9f54bac8fb8ccf0bab941009c21df21cf31"},{"constant":true,"inputs":[],"name":"era","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x143e55e0"},{"constant":false,"inputs":[{"name":"urn","type":"bytes32"},{"name":"gal","type":"address"},{"name":"tab","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"kick","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xeae19d9e"},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"tick","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xfc7b6aee"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"tend","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x4b43ed12"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"dent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x5ff3a382"},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"deal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xc959c42b"}]` + MedianizerABI = `[{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"","type":"bytes32"}],"name":"poke","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"poke","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"compute","outputs":[{"name":"","type":"bytes32"},{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"wat","type":"address"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"wat","type":"address"}],"name":"unset","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"indexes","outputs":[{"name":"","type":"bytes12"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"next","outputs":[{"name":"","type":"bytes12"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"read","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"peek","outputs":[{"name":"","type":"bytes32"},{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes12"}],"name":"values","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"min_","type":"uint96"}],"name":"setMin","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"void","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"pos","type":"bytes12"},{"name":"wat","type":"address"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"pos","type":"bytes12"}],"name":"unset","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"next_","type":"bytes12"}],"name":"setNext","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"min","outputs":[{"name":"","type":"uint96"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"val","type":"bytes32"}],"name":"LogValue","type":"event"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}]]` + PitABI = `[{"constant":true,"inputs":[],"name":"vat","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x36569e77"},{"constant":true,"inputs":[],"name":"live","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x957aa58c"},{"constant":true,"inputs":[],"name":"drip","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x9f678cca"},{"constant":true,"inputs":[],"name":"Line","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xbabe8a3f"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"wards","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xbf353dbb"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"ilks","outputs":[{"name":"spot","type":"uint256"},{"name":"line","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xd9638d36"},{"inputs":[{"name":"vat_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor","signature":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"ilk","type":"bytes32"},{"indexed":true,"name":"urn","type":"bytes32"},{"indexed":false,"name":"ink","type":"uint256"},{"indexed":false,"name":"art","type":"uint256"},{"indexed":false,"name":"dink","type":"int256"},{"indexed":false,"name":"dart","type":"int256"},{"indexed":false,"name":"iArt","type":"uint256"}],"name":"Frob","type":"event","signature":"0xb2afa28318bcc689926b52835d844de174ef8de97e982a85c0199d584920791b"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event","signature":"0x644843f351d3fba4abcd60109eaff9f54bac8fb8ccf0bab941009c21df21cf31"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x65fae35e"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x9c52a7f1"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x1a0b287e"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x29ae8114"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"address"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xd4e8be83"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"dink","type":"int256"},{"name":"dart","type":"int256"}],"name":"frob","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x5a984ded"}]` + FlipperContractAddress = "0x6b59c42097e2fff7cad96cb08ceefd601081ad9c" //this is a temporary address deployed locally - FlipKickSignature = "0x8828a22eb6a18623309ad55592866c4b077989e9e8a25e1b85f9bf6f7282520f" - FrobSignature = "0x6cedf1d3a466a3d6bab04887b1642177bf6dbf1daa737c2e8f639cd0b020d9d0" - PitABI = `[{"constant":true,"inputs":[],"name":"vat","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x36569e77"},{"constant":true,"inputs":[],"name":"live","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x957aa58c"},{"constant":true,"inputs":[],"name":"drip","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x9f678cca"},{"constant":true,"inputs":[],"name":"Line","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xbabe8a3f"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"wards","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xbf353dbb"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"ilks","outputs":[{"name":"spot","type":"uint256"},{"name":"line","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xd9638d36"},{"inputs":[{"name":"vat_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor","signature":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"ilk","type":"bytes32"},{"indexed":true,"name":"urn","type":"bytes32"},{"indexed":false,"name":"ink","type":"uint256"},{"indexed":false,"name":"art","type":"uint256"},{"indexed":false,"name":"dink","type":"int256"},{"indexed":false,"name":"dart","type":"int256"},{"indexed":false,"name":"iArt","type":"uint256"}],"name":"Frob","type":"event","signature":"0xb2afa28318bcc689926b52835d844de174ef8de97e982a85c0199d584920791b"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event","signature":"0x644843f351d3fba4abcd60109eaff9f54bac8fb8ccf0bab941009c21df21cf31"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x65fae35e"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x9c52a7f1"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x1a0b287e"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x29ae8114"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"address"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xd4e8be83"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"dink","type":"int256"},{"name":"dart","type":"int256"}],"name":"frob","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x5a984ded"}]` - PitFileSignature = "0x1a0b287e00000000000000000000000000000000000000000000000000000000" - TendFunctionSignature = "0x4b43ed1200000000000000000000000000000000000000000000000000000000" - BiteSignature = "0x44a8f29dfcf27e5dd7a4db50b390f851bf3ecf2bf221243be3e853f586134455" + + BiteSignature = GetEventSignature(biteMethod) + FlipKickSignature = GetEventSignature(flipKickMethod) + FrobSignature = GetEventSignature(frobMethod) + LogValueSignature = GetEventSignature("") + PitFileSignatureOne = GetLogNoteSignature(pitFileMethodOne) + PitFileSignatureThree = GetLogNoteSignature(pitFileMethodThree) + PitFileSignatureTwo = GetLogNoteSignature(pitFileMethodTwo) + TendFunctionSignature = GetLogNoteSignature(tendMethod) ) diff --git a/pkg/transformers/shared/event_signature_generator.go b/pkg/transformers/shared/event_signature_generator.go new file mode 100644 index 00000000..4c44dac5 --- /dev/null +++ b/pkg/transformers/shared/event_signature_generator.go @@ -0,0 +1,14 @@ +package shared + +import "github.com/ethereum/go-ethereum/crypto" + +func GetEventSignature(solidityMethodSignature string) string { + eventSignature := []byte(solidityMethodSignature) + hash := crypto.Keccak256Hash(eventSignature) + return hash.Hex() +} + +func GetLogNoteSignature(solidityMethodSignature string) string { + rawSignature := GetEventSignature(solidityMethodSignature) + return rawSignature[:10] + "00000000000000000000000000000000000000000000000000000000" +} diff --git a/pkg/transformers/shared/event_signature_generator_test.go b/pkg/transformers/shared/event_signature_generator_test.go new file mode 100644 index 00000000..abd7f896 --- /dev/null +++ b/pkg/transformers/shared/event_signature_generator_test.go @@ -0,0 +1,69 @@ +package shared_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" +) + +var _ = Describe("Event signature generator", func() { + Describe("generating non-anonymous event signatures", func() { + It("generates bite event signature", func() { + expected := "0x99b5620489b6ef926d4518936cfec15d305452712b88bd59da2d9c10fb0953e8" + actual := shared.GetEventSignature("Bite(bytes32,bytes32,uint256,uint256,uint256,uint256,uint256)") + + Expect(expected).To(Equal(actual)) + }) + + It("generates frob event signature", func() { + expected := "0xb2afa28318bcc689926b52835d844de174ef8de97e982a85c0199d584920791b" + actual := shared.GetEventSignature("Frob(bytes32,bytes32,uint256,uint256,int256,int256,uint256)") + + Expect(expected).To(Equal(actual)) + }) + + It("generates flip kick event signature", func() { + expected := "0xbac86238bdba81d21995024470425ecb370078fa62b7271b90cf28cbd1e3e87e" + actual := shared.GetEventSignature("Kick(uint256,uint256,uint256,address,uint48,bytes32,uint256)") + + Expect(expected).To(Equal(actual)) + }) + + It("generates log value event signature", func() { + expected := "0x296ba4ca62c6c21c95e828080cb8aec7481b71390585605300a8a76f9e95b527" + actual := shared.GetEventSignature("LogValue(bytes32)") + + Expect(expected).To(Equal(actual)) + }) + }) + + Describe("generating LogNote event signatures", func() { + It("generates flip tend event signature", func() { + expected := "0x4b43ed1200000000000000000000000000000000000000000000000000000000" + actual := shared.GetLogNoteSignature("tend(uint256,uint256,uint256)") + + Expect(expected).To(Equal(actual)) + }) + + It("generates pit file event signature for overloaded function with three arguments", func() { + expected := "0x1a0b287e00000000000000000000000000000000000000000000000000000000" + actual := shared.GetLogNoteSignature("file(bytes32,bytes32,uint256)") + + Expect(expected).To(Equal(actual)) + }) + + It("generates pit file event signature for overloaded function with two arguments", func() { + expected := "0x29ae811400000000000000000000000000000000000000000000000000000000" + actual := shared.GetLogNoteSignature("file(bytes32,uint256)") + + Expect(expected).To(Equal(actual)) + }) + + It("generates pit file event signature for overloaded function with two different arguments", func() { + expected := "0xd4e8be8300000000000000000000000000000000000000000000000000000000" + actual := shared.GetLogNoteSignature("file(bytes32,address)") + + Expect(expected).To(Equal(actual)) + }) + }) +}) From e1f609528d0ecc2b6bb798e4511b52089ef9384d Mon Sep 17 00:00:00 2001 From: Rob Mulholand Date: Wed, 5 Sep 2018 09:24:28 -0500 Subject: [PATCH 4/5] Add Pit file stability fee event - file event on the pit contract is overloaded and each implementation logs a note - existing Pit file transformer now specified as dealing with ilks --- .../1535667935_create_pit_file_table.down.sql | 3 +- .../1535667935_create_pit_file_table.up.sql | 16 +- db/schema.sql | 101 +++++++++-- pkg/transformers/pit_file/config.go | 2 +- pkg/transformers/pit_file/converter_test.go | 20 --- .../debt_ceiling/debt_ceiling_suite_test.go | 13 ++ .../pit_file/{ => ilk}/converter.go | 13 +- .../pit_file/ilk/converter_test.go | 20 +++ .../ilk_suite_test.go} | 6 +- pkg/transformers/pit_file/{ => ilk}/model.go | 6 +- .../pit_file/{ => ilk}/repository.go | 20 +-- .../pit_file/ilk/repository_test.go | 129 ++++++++++++++ .../pit_file/{ => ilk}/transformer.go | 25 +-- .../pit_file/{ => ilk}/transformer_test.go | 70 ++++---- .../pit_file/stability_fee/converter.go | 27 +++ .../pit_file/stability_fee/converter_test.go | 20 +++ .../pit_file/stability_fee/model.go | 8 + .../pit_file/stability_fee/repository.go | 48 ++++++ .../{ => stability_fee}/repository_test.go | 51 +++--- .../stability_fee/stability_fee_suite_test.go | 13 ++ .../pit_file/stability_fee/transformer.go | 57 ++++++ .../stability_fee/transformer_test.go | 163 ++++++++++++++++++ pkg/transformers/shared/constants.go | 30 ++-- .../mocks/pit_file/{ => ilk}/converter.go | 12 +- .../mocks/pit_file/ilk/repository.go | 40 +++++ .../test_data/mocks/pit_file/repository.go | 42 ----- .../mocks/pit_file/stability_fee/converter.go | 25 +++ .../pit_file/stability_fee/repository.go | 38 ++++ pkg/transformers/test_data/pit_file.go | 40 ++++- pkg/transformers/transformers.go | 8 +- test_config/test_config.go | 3 +- 31 files changed, 858 insertions(+), 211 deletions(-) delete mode 100644 pkg/transformers/pit_file/converter_test.go create mode 100644 pkg/transformers/pit_file/debt_ceiling/debt_ceiling_suite_test.go rename pkg/transformers/pit_file/{ => ilk}/converter.go (69%) create mode 100644 pkg/transformers/pit_file/ilk/converter_test.go rename pkg/transformers/pit_file/{pit_file_suite_test.go => ilk/ilk_suite_test.go} (56%) rename pkg/transformers/pit_file/{ => ilk}/model.go (65%) rename pkg/transformers/pit_file/{ => ilk}/repository.go (54%) create mode 100644 pkg/transformers/pit_file/ilk/repository_test.go rename pkg/transformers/pit_file/{ => ilk}/transformer.go (52%) rename pkg/transformers/pit_file/{ => ilk}/transformer_test.go (65%) create mode 100644 pkg/transformers/pit_file/stability_fee/converter.go create mode 100644 pkg/transformers/pit_file/stability_fee/converter_test.go create mode 100644 pkg/transformers/pit_file/stability_fee/model.go create mode 100644 pkg/transformers/pit_file/stability_fee/repository.go rename pkg/transformers/pit_file/{ => stability_fee}/repository_test.go (69%) create mode 100644 pkg/transformers/pit_file/stability_fee/stability_fee_suite_test.go create mode 100644 pkg/transformers/pit_file/stability_fee/transformer.go create mode 100644 pkg/transformers/pit_file/stability_fee/transformer_test.go rename pkg/transformers/test_data/mocks/pit_file/{ => ilk}/converter.go (51%) create mode 100644 pkg/transformers/test_data/mocks/pit_file/ilk/repository.go delete mode 100644 pkg/transformers/test_data/mocks/pit_file/repository.go create mode 100644 pkg/transformers/test_data/mocks/pit_file/stability_fee/converter.go create mode 100644 pkg/transformers/test_data/mocks/pit_file/stability_fee/repository.go diff --git a/db/migrations/1535667935_create_pit_file_table.down.sql b/db/migrations/1535667935_create_pit_file_table.down.sql index 4f92d89f..0b8b947d 100644 --- a/db/migrations/1535667935_create_pit_file_table.down.sql +++ b/db/migrations/1535667935_create_pit_file_table.down.sql @@ -1 +1,2 @@ -DROP TABLE maker.pit_file; \ No newline at end of file +DROP TABLE maker.pit_file_ilk; +DROP TABLE maker.pit_file_stability_fee; \ No newline at end of file diff --git a/db/migrations/1535667935_create_pit_file_table.up.sql b/db/migrations/1535667935_create_pit_file_table.up.sql index ff0312b4..8c0dd5ae 100644 --- a/db/migrations/1535667935_create_pit_file_table.up.sql +++ b/db/migrations/1535667935_create_pit_file_table.up.sql @@ -1,10 +1,20 @@ -CREATE TABLE maker.pit_file ( +CREATE TABLE maker.pit_file_ilk ( id SERIAL PRIMARY KEY, header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, ilk TEXT, what TEXT, - risk NUMERIC, + data NUMERIC, tx_idx INTEGER NOT NUll, raw_log JSONB, UNIQUE (header_id, tx_idx) -); \ No newline at end of file +); + +CREATE TABLE maker.pit_file_stability_fee ( + id SERIAL PRIMARY KEY, + header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, + what TEXT, + data TEXT, + tx_idx INTEGER NOT NULL, + raw_log JSONB, + UNIQUE (header_id, tx_idx) +) \ No newline at end of file diff --git a/db/schema.sql b/db/schema.sql index cfa0ed9a..a84f76af 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -157,25 +157,25 @@ ALTER SEQUENCE maker.frob_id_seq OWNED BY maker.frob.id; -- --- Name: pit_file; Type: TABLE; Schema: maker; Owner: - +-- Name: pit_file_ilk; Type: TABLE; Schema: maker; Owner: - -- -CREATE TABLE maker.pit_file ( +CREATE TABLE maker.pit_file_ilk ( id integer NOT NULL, header_id integer NOT NULL, ilk text, what text, - risk numeric, + data numeric, tx_idx integer NOT NULL, raw_log jsonb ); -- --- Name: pit_file_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- Name: pit_file_ilk_id_seq; Type: SEQUENCE; Schema: maker; Owner: - -- -CREATE SEQUENCE maker.pit_file_id_seq +CREATE SEQUENCE maker.pit_file_ilk_id_seq AS integer START WITH 1 INCREMENT BY 1 @@ -185,10 +185,44 @@ CREATE SEQUENCE maker.pit_file_id_seq -- --- Name: pit_file_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- Name: pit_file_ilk_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - -- -ALTER SEQUENCE maker.pit_file_id_seq OWNED BY maker.pit_file.id; +ALTER SEQUENCE maker.pit_file_ilk_id_seq OWNED BY maker.pit_file_ilk.id; + + +-- +-- Name: pit_file_stability_fee; Type: TABLE; Schema: maker; Owner: - +-- + +CREATE TABLE maker.pit_file_stability_fee ( + id integer NOT NULL, + header_id integer NOT NULL, + what text, + data text, + tx_idx integer NOT NULL, + raw_log jsonb +); + + +-- +-- Name: pit_file_stability_fee_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- + +CREATE SEQUENCE maker.pit_file_stability_fee_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: pit_file_stability_fee_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- + +ALTER SEQUENCE maker.pit_file_stability_fee_id_seq OWNED BY maker.pit_file_stability_fee.id; -- @@ -656,10 +690,17 @@ ALTER TABLE ONLY maker.frob ALTER COLUMN id SET DEFAULT nextval('maker.frob_id_s -- --- Name: pit_file id; Type: DEFAULT; Schema: maker; Owner: - +-- Name: pit_file_ilk id; Type: DEFAULT; Schema: maker; Owner: - -- -ALTER TABLE ONLY maker.pit_file ALTER COLUMN id SET DEFAULT nextval('maker.pit_file_id_seq'::regclass); +ALTER TABLE ONLY maker.pit_file_ilk ALTER COLUMN id SET DEFAULT nextval('maker.pit_file_ilk_id_seq'::regclass); + + +-- +-- Name: pit_file_stability_fee id; Type: DEFAULT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.pit_file_stability_fee ALTER COLUMN id SET DEFAULT nextval('maker.pit_file_stability_fee_id_seq'::regclass); -- @@ -788,19 +829,35 @@ ALTER TABLE ONLY maker.frob -- --- Name: pit_file pit_file_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: - +-- Name: pit_file_ilk pit_file_ilk_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: - -- -ALTER TABLE ONLY maker.pit_file - ADD CONSTRAINT pit_file_header_id_tx_idx_key UNIQUE (header_id, tx_idx); +ALTER TABLE ONLY maker.pit_file_ilk + ADD CONSTRAINT pit_file_ilk_header_id_tx_idx_key UNIQUE (header_id, tx_idx); -- --- Name: pit_file pit_file_pkey; Type: CONSTRAINT; Schema: maker; Owner: - +-- Name: pit_file_ilk pit_file_ilk_pkey; Type: CONSTRAINT; Schema: maker; Owner: - -- -ALTER TABLE ONLY maker.pit_file - ADD CONSTRAINT pit_file_pkey PRIMARY KEY (id); +ALTER TABLE ONLY maker.pit_file_ilk + ADD CONSTRAINT pit_file_ilk_pkey PRIMARY KEY (id); + + +-- +-- Name: pit_file_stability_fee pit_file_stability_fee_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.pit_file_stability_fee + ADD CONSTRAINT pit_file_stability_fee_header_id_tx_idx_key UNIQUE (header_id, tx_idx); + + +-- +-- Name: pit_file_stability_fee pit_file_stability_fee_pkey; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.pit_file_stability_fee + ADD CONSTRAINT pit_file_stability_fee_pkey PRIMARY KEY (id); -- @@ -999,11 +1056,19 @@ ALTER TABLE ONLY maker.price_feeds -- --- Name: pit_file pit_file_header_id_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: - +-- Name: pit_file_ilk pit_file_ilk_header_id_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: - -- -ALTER TABLE ONLY maker.pit_file - ADD CONSTRAINT pit_file_header_id_fkey FOREIGN KEY (header_id) REFERENCES public.headers(id) ON DELETE CASCADE; +ALTER TABLE ONLY maker.pit_file_ilk + ADD CONSTRAINT pit_file_ilk_header_id_fkey FOREIGN KEY (header_id) REFERENCES public.headers(id) ON DELETE CASCADE; + + +-- +-- Name: pit_file_stability_fee pit_file_stability_fee_header_id_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.pit_file_stability_fee + ADD CONSTRAINT pit_file_stability_fee_header_id_fkey FOREIGN KEY (header_id) REFERENCES public.headers(id) ON DELETE CASCADE; -- diff --git a/pkg/transformers/pit_file/config.go b/pkg/transformers/pit_file/config.go index 4298910c..bbec9911 100644 --- a/pkg/transformers/pit_file/config.go +++ b/pkg/transformers/pit_file/config.go @@ -7,7 +7,7 @@ import ( var PitFileConfig = shared.TransformerConfig{ ContractAddress: "0xff3f2400f1600f3f493a9a92704a29b96795af1a", // temporary address from Ganache deploy ContractAbi: shared.PitABI, - Topics: []string{shared.PitFileSignatureOne}, + Topics: []string{shared.PitFileIlkSignature, shared.PitFileDebtCeilingSignature, shared.PitFileStabilityFeeSignature}, StartingBlockNumber: 0, EndingBlockNumber: 100, } diff --git a/pkg/transformers/pit_file/converter_test.go b/pkg/transformers/pit_file/converter_test.go deleted file mode 100644 index 30e97fd6..00000000 --- a/pkg/transformers/pit_file/converter_test.go +++ /dev/null @@ -1,20 +0,0 @@ -package pit_file_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" -) - -var _ = Describe("Pit file converter", func() { - It("converts a log to an entity", func() { - converter := pit_file.PitFileConverter{} - - model, err := converter.ToModel(test_data.PitAddress, shared.PitABI, test_data.EthPitFileLog) - - Expect(err).NotTo(HaveOccurred()) - Expect(model).To(Equal(test_data.PitFileModel)) - }) -}) diff --git a/pkg/transformers/pit_file/debt_ceiling/debt_ceiling_suite_test.go b/pkg/transformers/pit_file/debt_ceiling/debt_ceiling_suite_test.go new file mode 100644 index 00000000..97af51bc --- /dev/null +++ b/pkg/transformers/pit_file/debt_ceiling/debt_ceiling_suite_test.go @@ -0,0 +1,13 @@ +package debt_ceiling_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestDebtCeiling(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "DebtCeiling Suite") +} diff --git a/pkg/transformers/pit_file/converter.go b/pkg/transformers/pit_file/ilk/converter.go similarity index 69% rename from pkg/transformers/pit_file/converter.go rename to pkg/transformers/pit_file/ilk/converter.go index 0bcc4116..37409cd5 100644 --- a/pkg/transformers/pit_file/converter.go +++ b/pkg/transformers/pit_file/ilk/converter.go @@ -1,4 +1,4 @@ -package pit_file +package ilk import ( "bytes" @@ -8,13 +8,12 @@ import ( ) type Converter interface { - ToModel(contractAddress string, contractAbi string, ethLog types.Log) (PitFileModel, error) + ToModel(contractAddress string, contractAbi string, ethLog types.Log) (PitFileIlkModel, error) } -type PitFileConverter struct { -} +type PitFileIlkConverter struct{} -func (PitFileConverter) ToModel(contractAddress string, contractAbi string, ethLog types.Log) (entity PitFileModel, err error) { +func (PitFileIlkConverter) ToModel(contractAddress string, contractAbi string, ethLog types.Log) (entity PitFileIlkModel, err error) { ilk := string(bytes.Trim(ethLog.Topics[2].Bytes(), "\x00")) what := string(bytes.Trim(ethLog.Topics[3].Bytes(), "\x00")) itemByteLength := 32 @@ -22,10 +21,10 @@ func (PitFileConverter) ToModel(contractAddress string, contractAbi string, ethL risk := big.NewInt(0).SetBytes(riskBytes).String() raw, err := json.Marshal(ethLog) - return PitFileModel{ + return PitFileIlkModel{ Ilk: ilk, What: what, - Risk: risk, + Data: risk, TransactionIndex: ethLog.TxIndex, Raw: raw, }, err diff --git a/pkg/transformers/pit_file/ilk/converter_test.go b/pkg/transformers/pit_file/ilk/converter_test.go new file mode 100644 index 00000000..0e2ac687 --- /dev/null +++ b/pkg/transformers/pit_file/ilk/converter_test.go @@ -0,0 +1,20 @@ +package ilk_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/ilk" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" +) + +var _ = Describe("Pit file ilk converter", func() { + It("converts a log to an model", func() { + converter := ilk.PitFileIlkConverter{} + + model, err := converter.ToModel(test_data.PitAddress, shared.PitABI, test_data.EthPitFileIlkLog) + + Expect(err).NotTo(HaveOccurred()) + Expect(model).To(Equal(test_data.PitFileIlkModel)) + }) +}) diff --git a/pkg/transformers/pit_file/pit_file_suite_test.go b/pkg/transformers/pit_file/ilk/ilk_suite_test.go similarity index 56% rename from pkg/transformers/pit_file/pit_file_suite_test.go rename to pkg/transformers/pit_file/ilk/ilk_suite_test.go index c992d4c9..18f7f9dc 100644 --- a/pkg/transformers/pit_file/pit_file_suite_test.go +++ b/pkg/transformers/pit_file/ilk/ilk_suite_test.go @@ -1,4 +1,4 @@ -package pit_file_test +package ilk_test import ( "testing" @@ -7,7 +7,7 @@ import ( . "github.com/onsi/gomega" ) -func TestPitFile(t *testing.T) { +func TestIlk(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "PitFile Suite") + RunSpecs(t, "Ilk Suite") } diff --git a/pkg/transformers/pit_file/model.go b/pkg/transformers/pit_file/ilk/model.go similarity index 65% rename from pkg/transformers/pit_file/model.go rename to pkg/transformers/pit_file/ilk/model.go index d42ba67d..cbf1a470 100644 --- a/pkg/transformers/pit_file/model.go +++ b/pkg/transformers/pit_file/ilk/model.go @@ -1,9 +1,9 @@ -package pit_file +package ilk -type PitFileModel struct { +type PitFileIlkModel struct { Ilk string What string - Risk string + Data string TransactionIndex uint `db:"tx_idx"` Raw []byte `db:"raw_log"` } diff --git a/pkg/transformers/pit_file/repository.go b/pkg/transformers/pit_file/ilk/repository.go similarity index 54% rename from pkg/transformers/pit_file/repository.go rename to pkg/transformers/pit_file/ilk/repository.go index 4184269a..9f65bbe8 100644 --- a/pkg/transformers/pit_file/repository.go +++ b/pkg/transformers/pit_file/ilk/repository.go @@ -1,4 +1,4 @@ -package pit_file +package ilk import ( "github.com/vulcanize/vulcanizedb/pkg/core" @@ -6,35 +6,35 @@ import ( ) type Repository interface { - Create(headerID int64, transactionIndex uint, model PitFileModel) error + Create(headerID int64, model PitFileIlkModel) error MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) } -type PitFileRepository struct { +type PitFileIlkRepository struct { db *postgres.DB } -func NewPitFileRepository(db *postgres.DB) PitFileRepository { - return PitFileRepository{ +func NewPitFileIlkRepository(db *postgres.DB) PitFileIlkRepository { + return PitFileIlkRepository{ db: db, } } -func (repository PitFileRepository) Create(headerID int64, transactionIndex uint, model PitFileModel) error { +func (repository PitFileIlkRepository) Create(headerID int64, model PitFileIlkModel) error { _, err := repository.db.Exec( - `INSERT into maker.pit_file (header_id, ilk, what, risk, tx_idx, raw_log) + `INSERT into maker.pit_file_ilk (header_id, ilk, what, data, tx_idx, raw_log) VALUES($1, $2, $3, $4::NUMERIC, $5, $6)`, - headerID, model.Ilk, model.What, model.Risk, model.TransactionIndex, model.Raw, + headerID, model.Ilk, model.What, model.Data, model.TransactionIndex, model.Raw, ) return err } -func (repository PitFileRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { +func (repository PitFileIlkRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { var result []core.Header err := repository.db.Select( &result, `SELECT headers.id, headers.block_number FROM headers - LEFT JOIN maker.pit_file on headers.id = header_id + LEFT JOIN maker.pit_file_ilk on headers.id = header_id WHERE header_id ISNULL AND headers.block_number >= $1 AND headers.block_number <= $2 diff --git a/pkg/transformers/pit_file/ilk/repository_test.go b/pkg/transformers/pit_file/ilk/repository_test.go new file mode 100644 index 00000000..63307c5c --- /dev/null +++ b/pkg/transformers/pit_file/ilk/repository_test.go @@ -0,0 +1,129 @@ +package ilk_test + +import ( + "database/sql" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/ilk" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" + "github.com/vulcanize/vulcanizedb/test_config" +) + +var _ = Describe("Pit file ilk repository", func() { + Describe("Create", func() { + It("adds a pit file ilk event", func() { + db := test_config.NewTestDB(core.Node{}) + test_config.CleanTestDB(db) + headerRepository := repositories.NewHeaderRepository(db) + headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{}) + Expect(err).NotTo(HaveOccurred()) + pitFileRepository := ilk.NewPitFileIlkRepository(db) + + err = pitFileRepository.Create(headerID, test_data.PitFileIlkModel) + + Expect(err).NotTo(HaveOccurred()) + var dbPitFile ilk.PitFileIlkModel + err = db.Get(&dbPitFile, `SELECT ilk, what, data, tx_idx, raw_log FROM maker.pit_file_ilk WHERE header_id = $1`, headerID) + Expect(err).NotTo(HaveOccurred()) + Expect(dbPitFile.Ilk).To(Equal(test_data.PitFileIlkModel.Ilk)) + Expect(dbPitFile.What).To(Equal(test_data.PitFileIlkModel.What)) + Expect(dbPitFile.Data).To(Equal(test_data.PitFileIlkModel.Data)) + Expect(dbPitFile.TransactionIndex).To(Equal(test_data.PitFileIlkModel.TransactionIndex)) + Expect(dbPitFile.Raw).To(MatchJSON(test_data.PitFileIlkModel.Raw)) + }) + + It("does not duplicate pit file ilk events", func() { + db := test_config.NewTestDB(core.Node{}) + test_config.CleanTestDB(db) + headerRepository := repositories.NewHeaderRepository(db) + headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{}) + Expect(err).NotTo(HaveOccurred()) + pitFileRepository := ilk.NewPitFileIlkRepository(db) + err = pitFileRepository.Create(headerID, test_data.PitFileIlkModel) + Expect(err).NotTo(HaveOccurred()) + + err = pitFileRepository.Create(headerID, test_data.PitFileIlkModel) + + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint")) + }) + + It("removes pit file ilk if corresponding header is deleted", func() { + db := test_config.NewTestDB(core.Node{}) + test_config.CleanTestDB(db) + headerRepository := repositories.NewHeaderRepository(db) + headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{}) + Expect(err).NotTo(HaveOccurred()) + pitFileRepository := ilk.NewPitFileIlkRepository(db) + err = pitFileRepository.Create(headerID, test_data.PitFileIlkModel) + Expect(err).NotTo(HaveOccurred()) + + _, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID) + + Expect(err).NotTo(HaveOccurred()) + var dbPitFile ilk.PitFileIlkModel + err = db.Get(&dbPitFile, `SELECT ilk, what, data, tx_idx, raw_log FROM maker.pit_file_ilk WHERE header_id = $1`, headerID) + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(sql.ErrNoRows)) + }) + }) + + Describe("MissingHeaders", func() { + It("returns headers with no associated pit file ilk event", func() { + db := test_config.NewTestDB(core.Node{}) + test_config.CleanTestDB(db) + headerRepository := repositories.NewHeaderRepository(db) + startingBlockNumber := int64(1) + pitFileBlockNumber := int64(2) + endingBlockNumber := int64(3) + blockNumbers := []int64{startingBlockNumber, pitFileBlockNumber, endingBlockNumber, endingBlockNumber + 1} + var headerIDs []int64 + for _, n := range blockNumbers { + headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{BlockNumber: n}) + headerIDs = append(headerIDs, headerID) + Expect(err).NotTo(HaveOccurred()) + } + pitFileRepository := ilk.NewPitFileIlkRepository(db) + err := pitFileRepository.Create(headerIDs[1], test_data.PitFileIlkModel) + Expect(err).NotTo(HaveOccurred()) + + headers, err := pitFileRepository.MissingHeaders(startingBlockNumber, endingBlockNumber) + + Expect(err).NotTo(HaveOccurred()) + Expect(len(headers)).To(Equal(2)) + Expect(headers[0].BlockNumber).To(Or(Equal(startingBlockNumber), Equal(endingBlockNumber))) + Expect(headers[1].BlockNumber).To(Or(Equal(startingBlockNumber), Equal(endingBlockNumber))) + }) + + It("only returns headers associated with the current node", func() { + db := test_config.NewTestDB(core.Node{}) + test_config.CleanTestDB(db) + blockNumbers := []int64{1, 2, 3} + headerRepository := repositories.NewHeaderRepository(db) + dbTwo := test_config.NewTestDB(core.Node{ID: "second"}) + headerRepositoryTwo := repositories.NewHeaderRepository(dbTwo) + var headerIDs []int64 + for _, n := range blockNumbers { + headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{BlockNumber: n}) + Expect(err).NotTo(HaveOccurred()) + headerIDs = append(headerIDs, headerID) + _, err = headerRepositoryTwo.CreateOrUpdateHeader(core.Header{BlockNumber: n}) + Expect(err).NotTo(HaveOccurred()) + } + pitFileRepository := ilk.NewPitFileIlkRepository(db) + pitFileRepositoryTwo := ilk.NewPitFileIlkRepository(dbTwo) + err := pitFileRepository.Create(headerIDs[0], test_data.PitFileIlkModel) + Expect(err).NotTo(HaveOccurred()) + + nodeOneMissingHeaders, err := pitFileRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) + Expect(err).NotTo(HaveOccurred()) + Expect(len(nodeOneMissingHeaders)).To(Equal(len(blockNumbers) - 1)) + + nodeTwoMissingHeaders, err := pitFileRepositoryTwo.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) + Expect(err).NotTo(HaveOccurred()) + Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers))) + }) + }) +}) diff --git a/pkg/transformers/pit_file/transformer.go b/pkg/transformers/pit_file/ilk/transformer.go similarity index 52% rename from pkg/transformers/pit_file/transformer.go rename to pkg/transformers/pit_file/ilk/transformer.go index 3c91c04d..f1a3a1a8 100644 --- a/pkg/transformers/pit_file/transformer.go +++ b/pkg/transformers/pit_file/ilk/transformer.go @@ -1,28 +1,29 @@ -package pit_file +package ilk import ( "github.com/ethereum/go-ethereum/common" "github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" ) -type PitFileTransformer struct { +type PitFileIlkTransformer struct { Config shared.TransformerConfig Converter Converter Fetcher shared.LogFetcher Repository Repository } -type PitFileTransformerInitializer struct { +type PitFileIlkTransformerInitializer struct { Config shared.TransformerConfig } -func (initializer PitFileTransformerInitializer) NewPitFileTransformer(db *postgres.DB, blockChain core.BlockChain) shared.Transformer { - converter := PitFileConverter{} +func (initializer PitFileIlkTransformerInitializer) NewPitFileIlkTransformer(db *postgres.DB, blockChain core.BlockChain) shared.Transformer { + converter := PitFileIlkConverter{} fetcher := shared.NewFetcher(blockChain) - repository := NewPitFileRepository(db) - return PitFileTransformer{ + repository := NewPitFileIlkRepository(db) + return PitFileIlkTransformer{ Config: initializer.Config, Converter: converter, Fetcher: fetcher, @@ -30,23 +31,23 @@ func (initializer PitFileTransformerInitializer) NewPitFileTransformer(db *postg } } -func (transformer PitFileTransformer) Execute() error { +func (transformer PitFileIlkTransformer) Execute() error { missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber) if err != nil { return err } for _, header := range missingHeaders { - topics := [][]common.Hash{{common.HexToHash(shared.PitFileSignatureOne)}} - matchingLogs, err := transformer.Fetcher.FetchLogs(PitFileConfig.ContractAddress, topics, header.BlockNumber) + topics := [][]common.Hash{{common.HexToHash(shared.PitFileIlkSignature)}} + matchingLogs, err := transformer.Fetcher.FetchLogs(pit_file.PitFileConfig.ContractAddress, topics, header.BlockNumber) if err != nil { return err } for _, log := range matchingLogs { - model, err := transformer.Converter.ToModel(PitFileConfig.ContractAddress, shared.PitABI, log) + model, err := transformer.Converter.ToModel(pit_file.PitFileConfig.ContractAddress, shared.PitABI, log) if err != nil { return err } - err = transformer.Repository.Create(header.Id, log.TxIndex, model) + err = transformer.Repository.Create(header.Id, model) if err != nil { return err } diff --git a/pkg/transformers/pit_file/transformer_test.go b/pkg/transformers/pit_file/ilk/transformer_test.go similarity index 65% rename from pkg/transformers/pit_file/transformer_test.go rename to pkg/transformers/pit_file/ilk/transformer_test.go index ea39787d..e4c3d135 100644 --- a/pkg/transformers/pit_file/transformer_test.go +++ b/pkg/transformers/pit_file/ilk/transformer_test.go @@ -1,4 +1,4 @@ -package pit_file_test +package ilk_test import ( "github.com/ethereum/go-ethereum/common" @@ -8,19 +8,20 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/ilk" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks" - pit_file_mocks "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks/pit_file" + pit_file_ilk_mocks "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks/pit_file/ilk" ) -var _ = Describe("Pit file transformer", func() { +var _ = Describe("Pit file ilk transformer", func() { It("gets missing headers for block numbers specified in config", func() { - repository := &pit_file_mocks.MockPitFileRepository{} - transformer := pit_file.PitFileTransformer{ + repository := &pit_file_ilk_mocks.MockPitFileIlkRepository{} + transformer := ilk.PitFileIlkTransformer{ Config: pit_file.PitFileConfig, Fetcher: &mocks.MockLogFetcher{}, - Converter: &pit_file_mocks.MockPitFileConverter{}, + Converter: &pit_file_ilk_mocks.MockPitFileIlkConverter{}, Repository: repository, } @@ -32,11 +33,11 @@ var _ = Describe("Pit file transformer", func() { }) It("returns error if repository returns error for missing headers", func() { - repository := &pit_file_mocks.MockPitFileRepository{} + repository := &pit_file_ilk_mocks.MockPitFileIlkRepository{} repository.SetMissingHeadersErr(fakes.FakeError) - transformer := pit_file.PitFileTransformer{ + transformer := ilk.PitFileIlkTransformer{ Fetcher: &mocks.MockLogFetcher{}, - Converter: &pit_file_mocks.MockPitFileConverter{}, + Converter: &pit_file_ilk_mocks.MockPitFileIlkConverter{}, Repository: repository, } @@ -48,11 +49,11 @@ var _ = Describe("Pit file transformer", func() { It("fetches logs for missing headers", func() { fetcher := &mocks.MockLogFetcher{} - repository := &pit_file_mocks.MockPitFileRepository{} + repository := &pit_file_ilk_mocks.MockPitFileIlkRepository{} repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}, {BlockNumber: 2}}) - transformer := pit_file.PitFileTransformer{ + transformer := ilk.PitFileIlkTransformer{ Fetcher: fetcher, - Converter: &pit_file_mocks.MockPitFileConverter{}, + Converter: &pit_file_ilk_mocks.MockPitFileIlkConverter{}, Repository: repository, } @@ -61,17 +62,17 @@ var _ = Describe("Pit file transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) Expect(fetcher.FetchedContractAddress).To(Equal(pit_file.PitFileConfig.ContractAddress)) - Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.PitFileSignatureOne)}})) + Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.PitFileIlkSignature)}})) }) It("returns error if fetcher returns error", func() { fetcher := &mocks.MockLogFetcher{} fetcher.SetFetcherError(fakes.FakeError) - repository := &pit_file_mocks.MockPitFileRepository{} + repository := &pit_file_ilk_mocks.MockPitFileIlkRepository{} repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) - transformer := pit_file.PitFileTransformer{ + transformer := ilk.PitFileIlkTransformer{ Fetcher: fetcher, - Converter: &pit_file_mocks.MockPitFileConverter{}, + Converter: &pit_file_ilk_mocks.MockPitFileIlkConverter{}, Repository: repository, } @@ -82,12 +83,12 @@ var _ = Describe("Pit file transformer", func() { }) It("converts matching logs", func() { - converter := &pit_file_mocks.MockPitFileConverter{} + converter := &pit_file_ilk_mocks.MockPitFileIlkConverter{} fetcher := &mocks.MockLogFetcher{} - fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileLog}) - repository := &pit_file_mocks.MockPitFileRepository{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileIlkLog}) + repository := &pit_file_ilk_mocks.MockPitFileIlkRepository{} repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) - transformer := pit_file.PitFileTransformer{ + transformer := ilk.PitFileIlkTransformer{ Fetcher: fetcher, Converter: converter, Repository: repository, @@ -98,17 +99,17 @@ var _ = Describe("Pit file transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(converter.PassedContractAddress).To(Equal(pit_file.PitFileConfig.ContractAddress)) Expect(converter.PassedContractABI).To(Equal(pit_file.PitFileConfig.ContractAbi)) - Expect(converter.PassedLog).To(Equal(test_data.EthPitFileLog)) + Expect(converter.PassedLog).To(Equal(test_data.EthPitFileIlkLog)) }) It("returns error if converter returns error", func() { - converter := &pit_file_mocks.MockPitFileConverter{} + converter := &pit_file_ilk_mocks.MockPitFileIlkConverter{} converter.SetConverterError(fakes.FakeError) fetcher := &mocks.MockLogFetcher{} - fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileLog}) - repository := &pit_file_mocks.MockPitFileRepository{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileIlkLog}) + repository := &pit_file_ilk_mocks.MockPitFileIlkRepository{} repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) - transformer := pit_file.PitFileTransformer{ + transformer := ilk.PitFileIlkTransformer{ Fetcher: fetcher, Converter: converter, Repository: repository, @@ -121,13 +122,13 @@ var _ = Describe("Pit file transformer", func() { }) It("persists pit file model", func() { - converter := &pit_file_mocks.MockPitFileConverter{} + converter := &pit_file_ilk_mocks.MockPitFileIlkConverter{} fetcher := &mocks.MockLogFetcher{} - fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileLog}) - repository := &pit_file_mocks.MockPitFileRepository{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileIlkLog}) + repository := &pit_file_ilk_mocks.MockPitFileIlkRepository{} fakeHeader := core.Header{BlockNumber: 1, Id: 2} repository.SetMissingHeaders([]core.Header{fakeHeader}) - transformer := pit_file.PitFileTransformer{ + transformer := ilk.PitFileIlkTransformer{ Fetcher: fetcher, Converter: converter, Repository: repository, @@ -137,18 +138,17 @@ var _ = Describe("Pit file transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id)) - Expect(repository.PassedTransactionIndex).To(Equal(test_data.EthPitFileLog.TxIndex)) - Expect(repository.PassedModel).To(Equal(test_data.PitFileModel)) + Expect(repository.PassedModel).To(Equal(test_data.PitFileIlkModel)) }) It("returns error if repository returns error for create", func() { - converter := &pit_file_mocks.MockPitFileConverter{} + converter := &pit_file_ilk_mocks.MockPitFileIlkConverter{} fetcher := &mocks.MockLogFetcher{} - fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileLog}) - repository := &pit_file_mocks.MockPitFileRepository{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileIlkLog}) + repository := &pit_file_ilk_mocks.MockPitFileIlkRepository{} repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}}) repository.SetCreateError(fakes.FakeError) - transformer := pit_file.PitFileTransformer{ + transformer := ilk.PitFileIlkTransformer{ Fetcher: fetcher, Converter: converter, Repository: repository, diff --git a/pkg/transformers/pit_file/stability_fee/converter.go b/pkg/transformers/pit_file/stability_fee/converter.go new file mode 100644 index 00000000..2864ab5c --- /dev/null +++ b/pkg/transformers/pit_file/stability_fee/converter.go @@ -0,0 +1,27 @@ +package stability_fee + +import ( + "bytes" + "encoding/json" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" +) + +type Converter interface { + ToModel(contractAddress string, contractAbi string, ethLog types.Log) (PitFileStabilityFeeModel, error) +} + +type PitFileStabilityFeeConverter struct{} + +func (PitFileStabilityFeeConverter) ToModel(contractAddress string, contractAbi string, ethLog types.Log) (PitFileStabilityFeeModel, error) { + what := string(bytes.Trim(ethLog.Topics[2].Bytes(), "\x00")) + data := common.HexToAddress(ethLog.Topics[1].String()).Hex() + + raw, err := json.Marshal(ethLog) + return PitFileStabilityFeeModel{ + What: what, + Data: data, + TransactionIndex: ethLog.TxIndex, + Raw: raw, + }, err +} diff --git a/pkg/transformers/pit_file/stability_fee/converter_test.go b/pkg/transformers/pit_file/stability_fee/converter_test.go new file mode 100644 index 00000000..af0e17d4 --- /dev/null +++ b/pkg/transformers/pit_file/stability_fee/converter_test.go @@ -0,0 +1,20 @@ +package stability_fee_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/stability_fee" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" +) + +var _ = Describe("Pit file stability fee converter", func() { + It("converts a log to an model", func() { + converter := stability_fee.PitFileStabilityFeeConverter{} + + model, err := converter.ToModel(test_data.PitAddress, shared.PitABI, test_data.EthPitFileStabilityFeeLog) + + Expect(err).NotTo(HaveOccurred()) + Expect(model).To(Equal(test_data.PitFileStabilityFeeModel)) + }) +}) diff --git a/pkg/transformers/pit_file/stability_fee/model.go b/pkg/transformers/pit_file/stability_fee/model.go new file mode 100644 index 00000000..afa061b5 --- /dev/null +++ b/pkg/transformers/pit_file/stability_fee/model.go @@ -0,0 +1,8 @@ +package stability_fee + +type PitFileStabilityFeeModel struct { + What string + Data string + TransactionIndex uint `db:"tx_idx"` + Raw []byte `db:"raw_log"` +} diff --git a/pkg/transformers/pit_file/stability_fee/repository.go b/pkg/transformers/pit_file/stability_fee/repository.go new file mode 100644 index 00000000..75f41d01 --- /dev/null +++ b/pkg/transformers/pit_file/stability_fee/repository.go @@ -0,0 +1,48 @@ +package stability_fee + +import ( + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" +) + +type Repository interface { + Create(headerID int64, model PitFileStabilityFeeModel) error + MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) +} + +type PitFileStabilityFeeRepository struct { + db *postgres.DB +} + +func NewPitFileStabilityFeeRepository(db *postgres.DB) PitFileStabilityFeeRepository { + return PitFileStabilityFeeRepository{ + db: db, + } +} + +func (repository PitFileStabilityFeeRepository) Create(headerID int64, model PitFileStabilityFeeModel) error { + _, err := repository.db.Exec( + `INSERT into maker.pit_file_stability_fee (header_id, what, data, tx_idx, raw_log) + VALUES($1, $2, $3, $4, $5)`, + headerID, model.What, model.Data, model.TransactionIndex, model.Raw, + ) + return err +} + +func (repository PitFileStabilityFeeRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { + var result []core.Header + err := repository.db.Select( + &result, + `SELECT headers.id, headers.block_number FROM headers + LEFT JOIN maker.pit_file_stability_fee on headers.id = header_id + WHERE header_id ISNULL + AND headers.block_number >= $1 + AND headers.block_number <= $2 + AND headers.eth_node_fingerprint = $3`, + startingBlockNumber, + endingBlockNumber, + repository.db.Node.ID, + ) + + return result, err +} diff --git a/pkg/transformers/pit_file/repository_test.go b/pkg/transformers/pit_file/stability_fee/repository_test.go similarity index 69% rename from pkg/transformers/pit_file/repository_test.go rename to pkg/transformers/pit_file/stability_fee/repository_test.go index bb7624ee..14a0a243 100644 --- a/pkg/transformers/pit_file/repository_test.go +++ b/pkg/transformers/pit_file/stability_fee/repository_test.go @@ -1,37 +1,38 @@ -package pit_file_test +package stability_fee_test import ( "database/sql" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" - "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/stability_fee" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/test_config" ) -var _ = Describe("Pit file repository", func() { +var _ = Describe("", func() { Describe("Create", func() { - It("adds a pit file event", func() { + It("adds a pit file stability fee event", func() { db := test_config.NewTestDB(core.Node{}) test_config.CleanTestDB(db) headerRepository := repositories.NewHeaderRepository(db) headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{}) Expect(err).NotTo(HaveOccurred()) - pitFileRepository := pit_file.NewPitFileRepository(db) + pitFileRepository := stability_fee.NewPitFileStabilityFeeRepository(db) - err = pitFileRepository.Create(headerID, 123, test_data.PitFileModel) + err = pitFileRepository.Create(headerID, test_data.PitFileStabilityFeeModel) Expect(err).NotTo(HaveOccurred()) - var dbPitFile pit_file.PitFileModel - err = db.Get(&dbPitFile, `SELECT ilk, what, risk, tx_idx, raw_log FROM maker.pit_file WHERE header_id = $1`, headerID) + var dbPitFile stability_fee.PitFileStabilityFeeModel + err = db.Get(&dbPitFile, `SELECT what, data, tx_idx, raw_log FROM maker.pit_file_stability_fee WHERE header_id = $1`, headerID) Expect(err).NotTo(HaveOccurred()) - Expect(dbPitFile.Ilk).To(Equal(test_data.PitFileModel.Ilk)) - Expect(dbPitFile.What).To(Equal(test_data.PitFileModel.What)) - Expect(dbPitFile.Risk).To(Equal(test_data.PitFileModel.Risk)) - Expect(dbPitFile.TransactionIndex).To(Equal(test_data.PitFileModel.TransactionIndex)) - Expect(dbPitFile.Raw).To(MatchJSON(test_data.PitFileModel.Raw)) + Expect(dbPitFile.What).To(Equal(test_data.PitFileStabilityFeeModel.What)) + Expect(dbPitFile.Data).To(Equal(test_data.PitFileStabilityFeeModel.Data)) + Expect(dbPitFile.TransactionIndex).To(Equal(test_data.PitFileStabilityFeeModel.TransactionIndex)) + Expect(dbPitFile.Raw).To(MatchJSON(test_data.PitFileStabilityFeeModel.Raw)) }) It("does not duplicate pit file events", func() { @@ -40,11 +41,11 @@ var _ = Describe("Pit file repository", func() { headerRepository := repositories.NewHeaderRepository(db) headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{}) Expect(err).NotTo(HaveOccurred()) - pitFileRepository := pit_file.NewPitFileRepository(db) - err = pitFileRepository.Create(headerID, 123, test_data.PitFileModel) + pitFileRepository := stability_fee.NewPitFileStabilityFeeRepository(db) + err = pitFileRepository.Create(headerID, test_data.PitFileStabilityFeeModel) Expect(err).NotTo(HaveOccurred()) - err = pitFileRepository.Create(headerID, 123, test_data.PitFileModel) + err = pitFileRepository.Create(headerID, test_data.PitFileStabilityFeeModel) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint")) @@ -56,15 +57,15 @@ var _ = Describe("Pit file repository", func() { headerRepository := repositories.NewHeaderRepository(db) headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{}) Expect(err).NotTo(HaveOccurred()) - pitFileRepository := pit_file.NewPitFileRepository(db) - err = pitFileRepository.Create(headerID, 123, test_data.PitFileModel) + pitFileRepository := stability_fee.NewPitFileStabilityFeeRepository(db) + err = pitFileRepository.Create(headerID, test_data.PitFileStabilityFeeModel) Expect(err).NotTo(HaveOccurred()) _, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID) Expect(err).NotTo(HaveOccurred()) - var dbPitFile pit_file.PitFileModel - err = db.Get(&dbPitFile, `SELECT ilk, what, risk, tx_idx, raw_log FROM maker.pit_file WHERE header_id = $1`, headerID) + var dbPitFile stability_fee.PitFileStabilityFeeModel + err = db.Get(&dbPitFile, `SELECT what, data, tx_idx, raw_log FROM maker.pit_file_stability_fee WHERE header_id = $1`, headerID) Expect(err).To(HaveOccurred()) Expect(err).To(MatchError(sql.ErrNoRows)) }) @@ -85,8 +86,8 @@ var _ = Describe("Pit file repository", func() { headerIDs = append(headerIDs, headerID) Expect(err).NotTo(HaveOccurred()) } - pitFileRepository := pit_file.NewPitFileRepository(db) - err := pitFileRepository.Create(headerIDs[1], 123, test_data.PitFileModel) + pitFileRepository := stability_fee.NewPitFileStabilityFeeRepository(db) + err := pitFileRepository.Create(headerIDs[1], test_data.PitFileStabilityFeeModel) Expect(err).NotTo(HaveOccurred()) headers, err := pitFileRepository.MissingHeaders(startingBlockNumber, endingBlockNumber) @@ -112,9 +113,9 @@ var _ = Describe("Pit file repository", func() { _, err = headerRepositoryTwo.CreateOrUpdateHeader(core.Header{BlockNumber: n}) Expect(err).NotTo(HaveOccurred()) } - pitFileRepository := pit_file.NewPitFileRepository(db) - pitFileRepositoryTwo := pit_file.NewPitFileRepository(dbTwo) - err := pitFileRepository.Create(headerIDs[0], 0, test_data.PitFileModel) + pitFileRepository := stability_fee.NewPitFileStabilityFeeRepository(db) + pitFileRepositoryTwo := stability_fee.NewPitFileStabilityFeeRepository(dbTwo) + err := pitFileRepository.Create(headerIDs[0], test_data.PitFileStabilityFeeModel) Expect(err).NotTo(HaveOccurred()) nodeOneMissingHeaders, err := pitFileRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) diff --git a/pkg/transformers/pit_file/stability_fee/stability_fee_suite_test.go b/pkg/transformers/pit_file/stability_fee/stability_fee_suite_test.go new file mode 100644 index 00000000..c7d645a9 --- /dev/null +++ b/pkg/transformers/pit_file/stability_fee/stability_fee_suite_test.go @@ -0,0 +1,13 @@ +package stability_fee_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestStabilityFee(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "StabilityFee Suite") +} diff --git a/pkg/transformers/pit_file/stability_fee/transformer.go b/pkg/transformers/pit_file/stability_fee/transformer.go new file mode 100644 index 00000000..f19ef343 --- /dev/null +++ b/pkg/transformers/pit_file/stability_fee/transformer.go @@ -0,0 +1,57 @@ +package stability_fee + +import ( + "github.com/ethereum/go-ethereum/common" + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" +) + +type PitFileStabilityFeeTransformer struct { + Config shared.TransformerConfig + Converter Converter + Fetcher shared.LogFetcher + Repository Repository +} + +type PitFileStabilityFeeTransformerInitializer struct { + Config shared.TransformerConfig +} + +func (initializer PitFileStabilityFeeTransformerInitializer) NewPitFileStabilityFeeTransformer(db *postgres.DB, blockChain core.BlockChain) shared.Transformer { + converter := PitFileStabilityFeeConverter{} + fetcher := shared.NewFetcher(blockChain) + repository := NewPitFileStabilityFeeRepository(db) + return PitFileStabilityFeeTransformer{ + Config: initializer.Config, + Converter: converter, + Fetcher: fetcher, + Repository: repository, + } +} + +func (transformer PitFileStabilityFeeTransformer) Execute() error { + missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber) + if err != nil { + return err + } + for _, header := range missingHeaders { + topics := [][]common.Hash{{common.HexToHash(shared.PitFileStabilityFeeSignature)}} + matchingLogs, err := transformer.Fetcher.FetchLogs(pit_file.PitFileConfig.ContractAddress, topics, header.BlockNumber) + if err != nil { + return err + } + for _, log := range matchingLogs { + model, err := transformer.Converter.ToModel(pit_file.PitFileConfig.ContractAddress, shared.PitABI, log) + if err != nil { + return err + } + err = transformer.Repository.Create(header.Id, model) + if err != nil { + return err + } + } + } + return nil +} diff --git a/pkg/transformers/pit_file/stability_fee/transformer_test.go b/pkg/transformers/pit_file/stability_fee/transformer_test.go new file mode 100644 index 00000000..be70b670 --- /dev/null +++ b/pkg/transformers/pit_file/stability_fee/transformer_test.go @@ -0,0 +1,163 @@ +package stability_fee_test + +import ( + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/fakes" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/stability_fee" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks" + stability_fee_mocks "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks/pit_file/stability_fee" +) + +var _ = Describe("", func() { + It("gets missing headers for block numbers specified in config", func() { + repository := &stability_fee_mocks.MockPitFileStabilityFeeRepository{} + transformer := stability_fee.PitFileStabilityFeeTransformer{ + Config: pit_file.PitFileConfig, + Fetcher: &mocks.MockLogFetcher{}, + Converter: &stability_fee_mocks.MockPitFileStabilityFeeConverter{}, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).NotTo(HaveOccurred()) + Expect(repository.PassedStartingBlockNumber).To(Equal(pit_file.PitFileConfig.StartingBlockNumber)) + Expect(repository.PassedEndingBlockNumber).To(Equal(pit_file.PitFileConfig.EndingBlockNumber)) + }) + + It("returns error if repository returns error for missing headers", func() { + repository := &stability_fee_mocks.MockPitFileStabilityFeeRepository{} + repository.SetMissingHeadersErr(fakes.FakeError) + transformer := stability_fee.PitFileStabilityFeeTransformer{ + Fetcher: &mocks.MockLogFetcher{}, + Converter: &stability_fee_mocks.MockPitFileStabilityFeeConverter{}, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("fetches logs for missing headers", func() { + fetcher := &mocks.MockLogFetcher{} + repository := &stability_fee_mocks.MockPitFileStabilityFeeRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}, {BlockNumber: 2}}) + transformer := stability_fee.PitFileStabilityFeeTransformer{ + Fetcher: fetcher, + Converter: &stability_fee_mocks.MockPitFileStabilityFeeConverter{}, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).NotTo(HaveOccurred()) + Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) + Expect(fetcher.FetchedContractAddress).To(Equal(pit_file.PitFileConfig.ContractAddress)) + Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.PitFileStabilityFeeSignature)}})) + }) + + It("returns error if fetcher returns error", func() { + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetcherError(fakes.FakeError) + repository := &stability_fee_mocks.MockPitFileStabilityFeeRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) + transformer := stability_fee.PitFileStabilityFeeTransformer{ + Fetcher: fetcher, + Converter: &stability_fee_mocks.MockPitFileStabilityFeeConverter{}, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("converts matching logs", func() { + converter := &stability_fee_mocks.MockPitFileStabilityFeeConverter{} + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileStabilityFeeLog}) + repository := &stability_fee_mocks.MockPitFileStabilityFeeRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) + transformer := stability_fee.PitFileStabilityFeeTransformer{ + Fetcher: fetcher, + Converter: converter, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).NotTo(HaveOccurred()) + Expect(converter.PassedContractAddress).To(Equal(pit_file.PitFileConfig.ContractAddress)) + Expect(converter.PassedContractABI).To(Equal(pit_file.PitFileConfig.ContractAbi)) + Expect(converter.PassedLog).To(Equal(test_data.EthPitFileStabilityFeeLog)) + }) + + It("returns error if converter returns error", func() { + converter := &stability_fee_mocks.MockPitFileStabilityFeeConverter{} + converter.SetConverterError(fakes.FakeError) + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileStabilityFeeLog}) + repository := &stability_fee_mocks.MockPitFileStabilityFeeRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) + transformer := stability_fee.PitFileStabilityFeeTransformer{ + Fetcher: fetcher, + Converter: converter, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("persists pit file model", func() { + converter := &stability_fee_mocks.MockPitFileStabilityFeeConverter{} + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileStabilityFeeLog}) + repository := &stability_fee_mocks.MockPitFileStabilityFeeRepository{} + fakeHeader := core.Header{BlockNumber: 1, Id: 2} + repository.SetMissingHeaders([]core.Header{fakeHeader}) + transformer := stability_fee.PitFileStabilityFeeTransformer{ + Fetcher: fetcher, + Converter: converter, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).NotTo(HaveOccurred()) + Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id)) + Expect(repository.PassedModel).To(Equal(test_data.PitFileStabilityFeeModel)) + }) + + It("returns error if repository returns error for create", func() { + converter := &stability_fee_mocks.MockPitFileStabilityFeeConverter{} + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileStabilityFeeLog}) + repository := &stability_fee_mocks.MockPitFileStabilityFeeRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}}) + repository.SetCreateError(fakes.FakeError) + transformer := stability_fee.PitFileStabilityFeeTransformer{ + Fetcher: fetcher, + Converter: converter, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) +}) diff --git a/pkg/transformers/shared/constants.go b/pkg/transformers/shared/constants.go index c417e088..38bfb010 100644 --- a/pkg/transformers/shared/constants.go +++ b/pkg/transformers/shared/constants.go @@ -15,13 +15,13 @@ package shared var ( - biteMethod = "Bite(bytes32,bytes32,uint256,uint256,uint256,uint256,uint256)" - flipKickMethod = "Kick(uint256,uint256,uint256,address,uint48,bytes32,uint256)" - frobMethod = "Frob(bytes32,bytes32,uint256,uint256,int256,int256,uint256)" - pitFileMethodOne = "file(bytes32,bytes32,uint256)" - pitFileMethodThree = "file(bytes32,address)" - pitFileMethodTwo = "file(bytes32,uint256)" - tendMethod = "tend(uint256,uint256,uint256)" + biteMethod = "Bite(bytes32,bytes32,uint256,uint256,uint256,uint256,uint256)" + flipKickMethod = "Kick(uint256,uint256,uint256,address,uint48,bytes32,uint256)" + frobMethod = "Frob(bytes32,bytes32,uint256,uint256,int256,int256,uint256)" + pitFileIlkMethod = "file(bytes32,bytes32,uint256)" + pitFileStabilityFeeMethod = "file(bytes32,address)" + pitFileDebtCeilingMethod = "file(bytes32,uint256)" + tendMethod = "tend(uint256,uint256,uint256)" CatABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"vat\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"vow\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"flips\",\"outputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"lad\",\"type\":\"bytes32\"},{\"name\":\"ink\",\"type\":\"uint256\"},{\"name\":\"tab\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"nflip\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"live\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"wards\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"ilks\",\"outputs\":[{\"name\":\"flip\",\"type\":\"address\"},{\"name\":\"chop\",\"type\":\"uint256\"},{\"name\":\"lump\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"pit\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"vat_\",\"type\":\"address\"},{\"name\":\"pit_\",\"type\":\"address\"},{\"name\":\"vow_\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"ilk\",\"type\":\"bytes32\"},{\"indexed\":true,\"name\":\"lad\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"ink\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"art\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"tab\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"flip\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"iArt\",\"type\":\"uint256\"}],\"name\":\"Bite\",\"type\":\"event\"},{\"anonymous\":true,\"inputs\":[{\"indexed\":true,\"name\":\"sig\",\"type\":\"bytes4\"},{\"indexed\":true,\"name\":\"guy\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"foo\",\"type\":\"bytes32\"},{\"indexed\":true,\"name\":\"bar\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"wad\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"fax\",\"type\":\"bytes\"}],\"name\":\"LogNote\",\"type\":\"event\"},{\"constant\":false,\"inputs\":[{\"name\":\"guy\",\"type\":\"address\"}],\"name\":\"rely\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"guy\",\"type\":\"address\"}],\"name\":\"deny\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"what\",\"type\":\"bytes32\"},{\"name\":\"data\",\"type\":\"uint256\"}],\"name\":\"file\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"what\",\"type\":\"bytes32\"},{\"name\":\"flip\",\"type\":\"address\"}],\"name\":\"file\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"lad\",\"type\":\"bytes32\"}],\"name\":\"bite\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"n\",\"type\":\"uint256\"},{\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"flip\",\"outputs\":[{\"name\":\"id\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" FlipperABI = `[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"bids","outputs":[{"name":"bid","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"guy","type":"address"},{"name":"tic","type":"uint48"},{"name":"end","type":"uint48"},{"name":"urn","type":"bytes32"},{"name":"gal","type":"address"},{"name":"tab","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x4423c5f1"},{"constant":true,"inputs":[],"name":"ttl","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x4e8b1dd5"},{"constant":true,"inputs":[],"name":"gem","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x7bd2bea7"},{"constant":true,"inputs":[],"name":"beg","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x7d780d82"},{"constant":true,"inputs":[],"name":"tau","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xcfc4af55"},{"constant":true,"inputs":[],"name":"kicks","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xcfdd3302"},{"constant":true,"inputs":[],"name":"dai","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xf4b9fa75"},{"inputs":[{"name":"dai_","type":"address"},{"name":"gem_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor","signature":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"id","type":"uint256"},{"indexed":false,"name":"lot","type":"uint256"},{"indexed":false,"name":"bid","type":"uint256"},{"indexed":false,"name":"gal","type":"address"},{"indexed":false,"name":"end","type":"uint48"},{"indexed":true,"name":"urn","type":"bytes32"},{"indexed":false,"name":"tab","type":"uint256"}],"name":"Kick","type":"event","signature":"0xbac86238bdba81d21995024470425ecb370078fa62b7271b90cf28cbd1e3e87e"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event","signature":"0x644843f351d3fba4abcd60109eaff9f54bac8fb8ccf0bab941009c21df21cf31"},{"constant":true,"inputs":[],"name":"era","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x143e55e0"},{"constant":false,"inputs":[{"name":"urn","type":"bytes32"},{"name":"gal","type":"address"},{"name":"tab","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"kick","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xeae19d9e"},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"tick","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xfc7b6aee"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"tend","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x4b43ed12"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"dent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x5ff3a382"},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"deal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xc959c42b"}]` @@ -30,12 +30,12 @@ var ( FlipperContractAddress = "0x6b59c42097e2fff7cad96cb08ceefd601081ad9c" //this is a temporary address deployed locally - BiteSignature = GetEventSignature(biteMethod) - FlipKickSignature = GetEventSignature(flipKickMethod) - FrobSignature = GetEventSignature(frobMethod) - LogValueSignature = GetEventSignature("") - PitFileSignatureOne = GetLogNoteSignature(pitFileMethodOne) - PitFileSignatureThree = GetLogNoteSignature(pitFileMethodThree) - PitFileSignatureTwo = GetLogNoteSignature(pitFileMethodTwo) - TendFunctionSignature = GetLogNoteSignature(tendMethod) + BiteSignature = GetEventSignature(biteMethod) + FlipKickSignature = GetEventSignature(flipKickMethod) + FrobSignature = GetEventSignature(frobMethod) + LogValueSignature = GetEventSignature("") + PitFileIlkSignature = GetLogNoteSignature(pitFileIlkMethod) + PitFileStabilityFeeSignature = GetLogNoteSignature(pitFileStabilityFeeMethod) + PitFileDebtCeilingSignature = GetLogNoteSignature(pitFileDebtCeilingMethod) + TendFunctionSignature = GetLogNoteSignature(tendMethod) ) diff --git a/pkg/transformers/test_data/mocks/pit_file/converter.go b/pkg/transformers/test_data/mocks/pit_file/ilk/converter.go similarity index 51% rename from pkg/transformers/test_data/mocks/pit_file/converter.go rename to pkg/transformers/test_data/mocks/pit_file/ilk/converter.go index 45693ea4..89fe53e7 100644 --- a/pkg/transformers/test_data/mocks/pit_file/converter.go +++ b/pkg/transformers/test_data/mocks/pit_file/ilk/converter.go @@ -1,26 +1,26 @@ -package pit_file +package ilk import ( "github.com/ethereum/go-ethereum/core/types" - "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/ilk" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" ) -type MockPitFileConverter struct { +type MockPitFileIlkConverter struct { PassedContractAddress string PassedContractABI string PassedLog types.Log converterError error } -func (converter *MockPitFileConverter) SetConverterError(err error) { +func (converter *MockPitFileIlkConverter) SetConverterError(err error) { converter.converterError = err } -func (converter *MockPitFileConverter) ToModel(contractAddress string, contractAbi string, ethLog types.Log) (pit_file.PitFileModel, error) { +func (converter *MockPitFileIlkConverter) ToModel(contractAddress string, contractAbi string, ethLog types.Log) (ilk.PitFileIlkModel, error) { converter.PassedContractAddress = contractAddress converter.PassedContractABI = contractAbi converter.PassedLog = ethLog - return test_data.PitFileModel, converter.converterError + return test_data.PitFileIlkModel, converter.converterError } diff --git a/pkg/transformers/test_data/mocks/pit_file/ilk/repository.go b/pkg/transformers/test_data/mocks/pit_file/ilk/repository.go new file mode 100644 index 00000000..b1571a67 --- /dev/null +++ b/pkg/transformers/test_data/mocks/pit_file/ilk/repository.go @@ -0,0 +1,40 @@ +package ilk + +import ( + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/ilk" +) + +type MockPitFileIlkRepository struct { + createError error + PassedEndingBlockNumber int64 + PassedModel ilk.PitFileIlkModel + PassedHeaderID int64 + PassedStartingBlockNumber int64 + missingHeaders []core.Header + missingHeadersErr error +} + +func (repository *MockPitFileIlkRepository) SetCreateError(err error) { + repository.createError = err +} + +func (repository *MockPitFileIlkRepository) SetMissingHeadersErr(err error) { + repository.missingHeadersErr = err +} + +func (repository *MockPitFileIlkRepository) SetMissingHeaders(headers []core.Header) { + repository.missingHeaders = headers +} + +func (repository *MockPitFileIlkRepository) Create(headerID int64, model ilk.PitFileIlkModel) error { + repository.PassedHeaderID = headerID + repository.PassedModel = model + return repository.createError +} + +func (repository *MockPitFileIlkRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { + repository.PassedStartingBlockNumber = startingBlockNumber + repository.PassedEndingBlockNumber = endingBlockNumber + return repository.missingHeaders, repository.missingHeadersErr +} diff --git a/pkg/transformers/test_data/mocks/pit_file/repository.go b/pkg/transformers/test_data/mocks/pit_file/repository.go deleted file mode 100644 index 9475adaa..00000000 --- a/pkg/transformers/test_data/mocks/pit_file/repository.go +++ /dev/null @@ -1,42 +0,0 @@ -package pit_file - -import ( - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" -) - -type MockPitFileRepository struct { - createError error - PassedEndingBlockNumber int64 - PassedModel pit_file.PitFileModel - PassedHeaderID int64 - PassedStartingBlockNumber int64 - PassedTransactionIndex uint - missingHeaders []core.Header - missingHeadersErr error -} - -func (repository *MockPitFileRepository) SetCreateError(err error) { - repository.createError = err -} - -func (repository *MockPitFileRepository) SetMissingHeadersErr(err error) { - repository.missingHeadersErr = err -} - -func (repository *MockPitFileRepository) SetMissingHeaders(headers []core.Header) { - repository.missingHeaders = headers -} - -func (repository *MockPitFileRepository) Create(headerID int64, transactionIndex uint, model pit_file.PitFileModel) error { - repository.PassedHeaderID = headerID - repository.PassedTransactionIndex = transactionIndex - repository.PassedModel = model - return repository.createError -} - -func (repository *MockPitFileRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - repository.PassedStartingBlockNumber = startingBlockNumber - repository.PassedEndingBlockNumber = endingBlockNumber - return repository.missingHeaders, repository.missingHeadersErr -} diff --git a/pkg/transformers/test_data/mocks/pit_file/stability_fee/converter.go b/pkg/transformers/test_data/mocks/pit_file/stability_fee/converter.go new file mode 100644 index 00000000..9e3d9583 --- /dev/null +++ b/pkg/transformers/test_data/mocks/pit_file/stability_fee/converter.go @@ -0,0 +1,25 @@ +package stability_fee + +import ( + "github.com/ethereum/go-ethereum/core/types" + + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/stability_fee" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" +) + +type MockPitFileStabilityFeeConverter struct { + converterErr error + PassedContractAddress string + PassedContractABI string + PassedLog types.Log +} + +func (converter *MockPitFileStabilityFeeConverter) ToModel(contractAddress string, contractAbi string, ethLog types.Log) (stability_fee.PitFileStabilityFeeModel, error) { + converter.PassedContractAddress = contractAddress + converter.PassedContractABI = contractAbi + converter.PassedLog = ethLog + return test_data.PitFileStabilityFeeModel, converter.converterErr +} +func (converter *MockPitFileStabilityFeeConverter) SetConverterError(e error) { + converter.converterErr = e +} diff --git a/pkg/transformers/test_data/mocks/pit_file/stability_fee/repository.go b/pkg/transformers/test_data/mocks/pit_file/stability_fee/repository.go new file mode 100644 index 00000000..d97274ba --- /dev/null +++ b/pkg/transformers/test_data/mocks/pit_file/stability_fee/repository.go @@ -0,0 +1,38 @@ +package stability_fee + +import ( + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/stability_fee" +) + +type MockPitFileStabilityFeeRepository struct { + createErr error + missingHeaders []core.Header + missingHeadersErr error + PassedStartingBlockNumber int64 + PassedEndingBlockNumber int64 + PassedHeaderID int64 + PassedModel stability_fee.PitFileStabilityFeeModel +} + +func (repository *MockPitFileStabilityFeeRepository) Create(headerID int64, model stability_fee.PitFileStabilityFeeModel) error { + repository.PassedModel = model + repository.PassedHeaderID = headerID + return repository.createErr +} + +func (repository *MockPitFileStabilityFeeRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { + repository.PassedStartingBlockNumber = startingBlockNumber + repository.PassedEndingBlockNumber = endingBlockNumber + return repository.missingHeaders, repository.missingHeadersErr +} + +func (repository *MockPitFileStabilityFeeRepository) SetMissingHeadersErr(e error) { + repository.missingHeadersErr = e +} +func (repository *MockPitFileStabilityFeeRepository) SetMissingHeaders(headers []core.Header) { + repository.missingHeaders = headers +} +func (repository *MockPitFileStabilityFeeRepository) SetCreateError(e error) { + repository.createErr = e +} diff --git a/pkg/transformers/test_data/pit_file.go b/pkg/transformers/test_data/pit_file.go index 49232706..664e3452 100644 --- a/pkg/transformers/test_data/pit_file.go +++ b/pkg/transformers/test_data/pit_file.go @@ -5,7 +5,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" - "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" + ilk2 "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/ilk" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/stability_fee" "math/big" ) @@ -13,7 +14,7 @@ var ( PitAddress = "0xff3f2400f1600f3f493a9a92704a29b96795af1a" ) -var EthPitFileLog = types.Log{ +var EthPitFileIlkLog = types.Log{ Address: common.HexToAddress(PitAddress), Topics: []common.Hash{ common.HexToHash("0x1a0b287e00000000000000000000000000000000000000000000000000000000"), @@ -30,11 +31,36 @@ var EthPitFileLog = types.Log{ Removed: false, } -var rawPitFileLog, _ = json.Marshal(EthPitFileLog) -var PitFileModel = pit_file.PitFileModel{ +var rawPitFileIlkLog, _ = json.Marshal(EthPitFileIlkLog) +var PitFileIlkModel = ilk2.PitFileIlkModel{ Ilk: "fake ilk", What: "spot", - Risk: big.NewInt(123).String(), - TransactionIndex: EthPitFileLog.TxIndex, - Raw: rawPitFileLog, + Data: big.NewInt(123).String(), + TransactionIndex: EthPitFileIlkLog.TxIndex, + Raw: rawPitFileIlkLog, +} + +var EthPitFileStabilityFeeLog = types.Log{ + Address: common.HexToAddress("0x6b59c42097e2Fff7cad96cb08cEeFd601081aD9c"), + Topics: []common.Hash{ + common.HexToHash("0xd4e8be8300000000000000000000000000000000000000000000000000000000"), + common.HexToHash("0x00000000000000000000000064d922894153be9eef7b7218dc565d1d0ce2a092"), + common.HexToHash("0x6472697000000000000000000000000000000000000000000000000000000000"), + common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), + }, + Data: hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000044d4e8be8364726970000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"), + BlockNumber: 12, + TxHash: common.HexToHash("0x78cdc62316ccf8e31515d09745cc724f557569f01a557d0d09b1066bf7079fd2"), + TxIndex: 0, + BlockHash: common.HexToHash("0xe3d8e458421533170871b4033f978a3793ef10b7e33a9328a13c09e2fd90208d"), + Index: 0, + Removed: false, +} + +var rawPitFileStabilityFeeLog, _ = json.Marshal(EthPitFileStabilityFeeLog) +var PitFileStabilityFeeModel = stability_fee.PitFileStabilityFeeModel{ + What: "drip", + Data: "0x64d922894153BE9EEf7b7218dc565d1D0Ce2a092", + TransactionIndex: 0, + Raw: rawPitFileStabilityFeeLog, } diff --git a/pkg/transformers/transformers.go b/pkg/transformers/transformers.go index a8af1a44..a83a7e15 100644 --- a/pkg/transformers/transformers.go +++ b/pkg/transformers/transformers.go @@ -19,6 +19,8 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick" "github.com/vulcanize/vulcanizedb/pkg/transformers/frob" "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/ilk" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/stability_fee" "github.com/vulcanize/vulcanizedb/pkg/transformers/price_feeds" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/tend" @@ -30,7 +32,8 @@ func TransformerInitializers() []shared.TransformerInitializer { frobConfig := frob.FrobConfig frobTransformerInitializer := frob.FrobTransformerInitializer{Config: frobConfig} pitFileConfig := pit_file.PitFileConfig - pitFileTransformerInitializer := pit_file.PitFileTransformerInitializer{Config: pitFileConfig} + pitFileIlkTransformerInitializer := ilk.PitFileIlkTransformerInitializer{Config: pitFileConfig} + pitFileStabilityFeeTransformerInitializer := stability_fee.PitFileStabilityFeeTransformerInitializer{Config: pitFileConfig} priceFeedConfig := price_feeds.PriceFeedConfig priceFeedTransformerInitializer := price_feeds.PriceFeedTransformerInitializer{Config: priceFeedConfig} tendConfig := tend.TendConfig @@ -41,7 +44,8 @@ func TransformerInitializers() []shared.TransformerInitializer { biteTransformerInitializer.NewBiteTransformer, flipKickTransformerInitializer.NewFlipKickTransformer, frobTransformerInitializer.NewFrobTransformer, - pitFileTransformerInitializer.NewPitFileTransformer, + pitFileIlkTransformerInitializer.NewPitFileIlkTransformer, + pitFileStabilityFeeTransformerInitializer.NewPitFileStabilityFeeTransformer, priceFeedTransformerInitializer.NewPriceFeedTransformer, tendTransformerInitializer.NewTendTransformer, } diff --git a/test_config/test_config.go b/test_config/test_config.go index 29bf6ca1..5e14d6e5 100644 --- a/test_config/test_config.go +++ b/test_config/test_config.go @@ -77,7 +77,8 @@ func CleanTestDB(db *postgres.DB) { db.MustExec("DELETE FROM headers") db.MustExec("DELETE FROM log_filters") db.MustExec("DELETE FROM logs") - db.MustExec("DELETE FROM maker.pit_file") + db.MustExec("DELETE FROM maker.pit_file_ilk") + db.MustExec("DELETE FROM maker.pit_file_stability_fee") db.MustExec("DELETE FROM receipts") db.MustExec("DELETE FROM transactions") db.MustExec("DELETE FROM watched_contracts") From d48cf380704701176e276e19dd96d9c05e59a61b Mon Sep 17 00:00:00 2001 From: Rob Mulholand Date: Wed, 5 Sep 2018 13:51:18 -0500 Subject: [PATCH 5/5] Add Pit file debt ceiling event --- .../1535667935_create_pit_file_table.down.sql | 3 +- .../1535667935_create_pit_file_table.up.sql | 12 +- db/schema.sql | 65 +++++++ .../pit_file/debt_ceiling/converter.go | 29 ++++ .../pit_file/debt_ceiling/converter_test.go | 25 +++ .../pit_file/debt_ceiling/model.go | 8 + .../pit_file/debt_ceiling/repository.go | 48 ++++++ .../pit_file/debt_ceiling/repository_test.go | 130 ++++++++++++++ .../pit_file/debt_ceiling/transformer.go | 57 ++++++ .../pit_file/debt_ceiling/transformer_test.go | 162 ++++++++++++++++++ pkg/transformers/shared/constants.go | 4 +- .../mocks/pit_file/debt_ceiling/converter.go | 25 +++ .../mocks/pit_file/debt_ceiling/repository.go | 40 +++++ pkg/transformers/test_data/pit_file.go | 30 +++- pkg/transformers/transformers.go | 3 + 15 files changed, 635 insertions(+), 6 deletions(-) create mode 100644 pkg/transformers/pit_file/debt_ceiling/converter.go create mode 100644 pkg/transformers/pit_file/debt_ceiling/converter_test.go create mode 100644 pkg/transformers/pit_file/debt_ceiling/model.go create mode 100644 pkg/transformers/pit_file/debt_ceiling/repository.go create mode 100644 pkg/transformers/pit_file/debt_ceiling/repository_test.go create mode 100644 pkg/transformers/pit_file/debt_ceiling/transformer.go create mode 100644 pkg/transformers/pit_file/debt_ceiling/transformer_test.go create mode 100644 pkg/transformers/test_data/mocks/pit_file/debt_ceiling/converter.go create mode 100644 pkg/transformers/test_data/mocks/pit_file/debt_ceiling/repository.go diff --git a/db/migrations/1535667935_create_pit_file_table.down.sql b/db/migrations/1535667935_create_pit_file_table.down.sql index 0b8b947d..f08e0913 100644 --- a/db/migrations/1535667935_create_pit_file_table.down.sql +++ b/db/migrations/1535667935_create_pit_file_table.down.sql @@ -1,2 +1,3 @@ DROP TABLE maker.pit_file_ilk; -DROP TABLE maker.pit_file_stability_fee; \ No newline at end of file +DROP TABLE maker.pit_file_stability_fee; +DROP TABLE maker.pit_file_debt_ceiling; \ No newline at end of file diff --git a/db/migrations/1535667935_create_pit_file_table.up.sql b/db/migrations/1535667935_create_pit_file_table.up.sql index 8c0dd5ae..a86fd681 100644 --- a/db/migrations/1535667935_create_pit_file_table.up.sql +++ b/db/migrations/1535667935_create_pit_file_table.up.sql @@ -17,4 +17,14 @@ CREATE TABLE maker.pit_file_stability_fee ( tx_idx INTEGER NOT NULL, raw_log JSONB, UNIQUE (header_id, tx_idx) -) \ No newline at end of file +); + +CREATE TABLE maker.pit_file_debt_ceiling ( + id SERIAL PRIMARY KEY, + header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, + what TEXT, + data NUMERIC, + tx_idx INTEGER NOT NULL, + raw_log JSONB, + UNIQUE (header_id, tx_idx) +); \ No newline at end of file diff --git a/db/schema.sql b/db/schema.sql index a84f76af..739b9e1f 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -156,6 +156,40 @@ CREATE SEQUENCE maker.frob_id_seq ALTER SEQUENCE maker.frob_id_seq OWNED BY maker.frob.id; +-- +-- Name: pit_file_debt_ceiling; Type: TABLE; Schema: maker; Owner: - +-- + +CREATE TABLE maker.pit_file_debt_ceiling ( + id integer NOT NULL, + header_id integer NOT NULL, + what text, + data numeric, + tx_idx integer NOT NULL, + raw_log jsonb +); + + +-- +-- Name: pit_file_debt_ceiling_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- + +CREATE SEQUENCE maker.pit_file_debt_ceiling_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: pit_file_debt_ceiling_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- + +ALTER SEQUENCE maker.pit_file_debt_ceiling_id_seq OWNED BY maker.pit_file_debt_ceiling.id; + + -- -- Name: pit_file_ilk; Type: TABLE; Schema: maker; Owner: - -- @@ -689,6 +723,13 @@ ALTER TABLE ONLY maker.flip_kick ALTER COLUMN db_id SET DEFAULT nextval('maker.f ALTER TABLE ONLY maker.frob ALTER COLUMN id SET DEFAULT nextval('maker.frob_id_seq'::regclass); +-- +-- Name: pit_file_debt_ceiling id; Type: DEFAULT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.pit_file_debt_ceiling ALTER COLUMN id SET DEFAULT nextval('maker.pit_file_debt_ceiling_id_seq'::regclass); + + -- -- Name: pit_file_ilk id; Type: DEFAULT; Schema: maker; Owner: - -- @@ -828,6 +869,22 @@ ALTER TABLE ONLY maker.frob ADD CONSTRAINT frob_pkey PRIMARY KEY (id); +-- +-- Name: pit_file_debt_ceiling pit_file_debt_ceiling_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.pit_file_debt_ceiling + ADD CONSTRAINT pit_file_debt_ceiling_header_id_tx_idx_key UNIQUE (header_id, tx_idx); + + +-- +-- Name: pit_file_debt_ceiling pit_file_debt_ceiling_pkey; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.pit_file_debt_ceiling + ADD CONSTRAINT pit_file_debt_ceiling_pkey PRIMARY KEY (id); + + -- -- Name: pit_file_ilk pit_file_ilk_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: - -- @@ -1055,6 +1112,14 @@ ALTER TABLE ONLY maker.price_feeds ADD CONSTRAINT headers_fk FOREIGN KEY (header_id) REFERENCES public.headers(id) ON DELETE CASCADE; +-- +-- Name: pit_file_debt_ceiling pit_file_debt_ceiling_header_id_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.pit_file_debt_ceiling + ADD CONSTRAINT pit_file_debt_ceiling_header_id_fkey FOREIGN KEY (header_id) REFERENCES public.headers(id) ON DELETE CASCADE; + + -- -- Name: pit_file_ilk pit_file_ilk_header_id_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: - -- diff --git a/pkg/transformers/pit_file/debt_ceiling/converter.go b/pkg/transformers/pit_file/debt_ceiling/converter.go new file mode 100644 index 00000000..fbc78ed8 --- /dev/null +++ b/pkg/transformers/pit_file/debt_ceiling/converter.go @@ -0,0 +1,29 @@ +package debt_ceiling + +import ( + "encoding/json" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "math/big" +) + +type Converter interface { + ToModel(contractAddress string, contractAbi string, ethLog types.Log) (PitFileDebtCeilingModel, error) +} + +type PitFileDebtCeilingConverter struct{} + +func (PitFileDebtCeilingConverter) ToModel(contractAddress string, contractAbi string, ethLog types.Log) (PitFileDebtCeilingModel, error) { + what := common.HexToAddress(ethLog.Topics[1].String()).String() + itemByteLength := 32 + riskBytes := ethLog.Data[len(ethLog.Data)-itemByteLength:] + data := big.NewInt(0).SetBytes(riskBytes).String() + + raw, err := json.Marshal(ethLog) + return PitFileDebtCeilingModel{ + What: what, + Data: data, + TransactionIndex: ethLog.TxIndex, + Raw: raw, + }, err +} diff --git a/pkg/transformers/pit_file/debt_ceiling/converter_test.go b/pkg/transformers/pit_file/debt_ceiling/converter_test.go new file mode 100644 index 00000000..c8975d4e --- /dev/null +++ b/pkg/transformers/pit_file/debt_ceiling/converter_test.go @@ -0,0 +1,25 @@ +package debt_ceiling_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" +) + +var _ = Describe("", func() { + It("converts a log to an model", func() { + converter := debt_ceiling.PitFileDebtCeilingConverter{} + + model, err := converter.ToModel(test_data.PitAddress, shared.PitABI, test_data.EthPitFileDebtCeilingLog) + + Expect(err).NotTo(HaveOccurred()) + Expect(model.What).To(Equal(test_data.PitFileDebtCeilingModel.What)) + Expect(model.Data).To(Equal(test_data.PitFileDebtCeilingModel.Data)) + Expect(model.TransactionIndex).To(Equal(test_data.PitFileDebtCeilingModel.TransactionIndex)) + Expect(model.Raw).To(Equal(test_data.PitFileDebtCeilingModel.Raw)) + Expect(model).To(Equal(test_data.PitFileDebtCeilingModel)) + }) +}) diff --git a/pkg/transformers/pit_file/debt_ceiling/model.go b/pkg/transformers/pit_file/debt_ceiling/model.go new file mode 100644 index 00000000..f1ff45f4 --- /dev/null +++ b/pkg/transformers/pit_file/debt_ceiling/model.go @@ -0,0 +1,8 @@ +package debt_ceiling + +type PitFileDebtCeilingModel struct { + What string + Data string + TransactionIndex uint `db:"tx_idx"` + Raw []byte `db:"raw_log"` +} diff --git a/pkg/transformers/pit_file/debt_ceiling/repository.go b/pkg/transformers/pit_file/debt_ceiling/repository.go new file mode 100644 index 00000000..4fde4c5b --- /dev/null +++ b/pkg/transformers/pit_file/debt_ceiling/repository.go @@ -0,0 +1,48 @@ +package debt_ceiling + +import ( + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" +) + +type Repository interface { + Create(headerID int64, model PitFileDebtCeilingModel) error + MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) +} + +type PitFileDebtCeilingRepository struct { + db *postgres.DB +} + +func NewPitFileDebtCeilingRepository(db *postgres.DB) PitFileDebtCeilingRepository { + return PitFileDebtCeilingRepository{ + db: db, + } +} + +func (repository PitFileDebtCeilingRepository) Create(headerID int64, model PitFileDebtCeilingModel) error { + _, err := repository.db.Exec( + `INSERT into maker.pit_file_debt_ceiling (header_id, what, data, tx_idx, raw_log) + VALUES($1, $2, $3::NUMERIC, $4, $5)`, + headerID, model.What, model.Data, model.TransactionIndex, model.Raw, + ) + return err +} + +func (repository PitFileDebtCeilingRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { + var result []core.Header + err := repository.db.Select( + &result, + `SELECT headers.id, headers.block_number FROM headers + LEFT JOIN maker.pit_file_debt_ceiling on headers.id = header_id + WHERE header_id ISNULL + AND headers.block_number >= $1 + AND headers.block_number <= $2 + AND headers.eth_node_fingerprint = $3`, + startingBlockNumber, + endingBlockNumber, + repository.db.Node.ID, + ) + + return result, err +} diff --git a/pkg/transformers/pit_file/debt_ceiling/repository_test.go b/pkg/transformers/pit_file/debt_ceiling/repository_test.go new file mode 100644 index 00000000..60df3c91 --- /dev/null +++ b/pkg/transformers/pit_file/debt_ceiling/repository_test.go @@ -0,0 +1,130 @@ +package debt_ceiling_test + +import ( + "database/sql" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" + "github.com/vulcanize/vulcanizedb/test_config" +) + +var _ = Describe("", func() { + Describe("Create", func() { + It("adds a pit file debt ceiling event", func() { + db := test_config.NewTestDB(core.Node{}) + test_config.CleanTestDB(db) + headerRepository := repositories.NewHeaderRepository(db) + headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{}) + Expect(err).NotTo(HaveOccurred()) + pitFileRepository := debt_ceiling.NewPitFileDebtCeilingRepository(db) + + err = pitFileRepository.Create(headerID, test_data.PitFileDebtCeilingModel) + + Expect(err).NotTo(HaveOccurred()) + var dbPitFile debt_ceiling.PitFileDebtCeilingModel + err = db.Get(&dbPitFile, `SELECT what, data, tx_idx, raw_log FROM maker.pit_file_debt_ceiling WHERE header_id = $1`, headerID) + Expect(err).NotTo(HaveOccurred()) + Expect(dbPitFile.What).To(Equal(test_data.PitFileDebtCeilingModel.What)) + Expect(dbPitFile.Data).To(Equal(test_data.PitFileDebtCeilingModel.Data)) + Expect(dbPitFile.TransactionIndex).To(Equal(test_data.PitFileDebtCeilingModel.TransactionIndex)) + Expect(dbPitFile.Raw).To(MatchJSON(test_data.PitFileDebtCeilingModel.Raw)) + }) + + It("does not duplicate pit file events", func() { + db := test_config.NewTestDB(core.Node{}) + test_config.CleanTestDB(db) + headerRepository := repositories.NewHeaderRepository(db) + headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{}) + Expect(err).NotTo(HaveOccurred()) + pitFileRepository := debt_ceiling.NewPitFileDebtCeilingRepository(db) + err = pitFileRepository.Create(headerID, test_data.PitFileDebtCeilingModel) + Expect(err).NotTo(HaveOccurred()) + + err = pitFileRepository.Create(headerID, test_data.PitFileDebtCeilingModel) + + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint")) + }) + + It("removes pit file if corresponding header is deleted", func() { + db := test_config.NewTestDB(core.Node{}) + test_config.CleanTestDB(db) + headerRepository := repositories.NewHeaderRepository(db) + headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{}) + Expect(err).NotTo(HaveOccurred()) + pitFileRepository := debt_ceiling.NewPitFileDebtCeilingRepository(db) + err = pitFileRepository.Create(headerID, test_data.PitFileDebtCeilingModel) + Expect(err).NotTo(HaveOccurred()) + + _, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID) + + Expect(err).NotTo(HaveOccurred()) + var dbPitFile debt_ceiling.PitFileDebtCeilingModel + err = db.Get(&dbPitFile, `SELECT what, data, tx_idx, raw_log FROM maker.pit_file_debt_ceiling WHERE header_id = $1`, headerID) + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(sql.ErrNoRows)) + }) + }) + + Describe("MissingHeaders", func() { + It("returns headers with no associated pit file event", func() { + db := test_config.NewTestDB(core.Node{}) + test_config.CleanTestDB(db) + headerRepository := repositories.NewHeaderRepository(db) + startingBlockNumber := int64(1) + pitFileBlockNumber := int64(2) + endingBlockNumber := int64(3) + blockNumbers := []int64{startingBlockNumber, pitFileBlockNumber, endingBlockNumber, endingBlockNumber + 1} + var headerIDs []int64 + for _, n := range blockNumbers { + headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{BlockNumber: n}) + headerIDs = append(headerIDs, headerID) + Expect(err).NotTo(HaveOccurred()) + } + pitFileRepository := debt_ceiling.NewPitFileDebtCeilingRepository(db) + err := pitFileRepository.Create(headerIDs[1], test_data.PitFileDebtCeilingModel) + Expect(err).NotTo(HaveOccurred()) + + headers, err := pitFileRepository.MissingHeaders(startingBlockNumber, endingBlockNumber) + + Expect(err).NotTo(HaveOccurred()) + Expect(len(headers)).To(Equal(2)) + Expect(headers[0].BlockNumber).To(Or(Equal(startingBlockNumber), Equal(endingBlockNumber))) + Expect(headers[1].BlockNumber).To(Or(Equal(startingBlockNumber), Equal(endingBlockNumber))) + }) + + It("only returns headers associated with the current node", func() { + db := test_config.NewTestDB(core.Node{}) + test_config.CleanTestDB(db) + blockNumbers := []int64{1, 2, 3} + headerRepository := repositories.NewHeaderRepository(db) + dbTwo := test_config.NewTestDB(core.Node{ID: "second"}) + headerRepositoryTwo := repositories.NewHeaderRepository(dbTwo) + var headerIDs []int64 + for _, n := range blockNumbers { + headerID, err := headerRepository.CreateOrUpdateHeader(core.Header{BlockNumber: n}) + Expect(err).NotTo(HaveOccurred()) + headerIDs = append(headerIDs, headerID) + _, err = headerRepositoryTwo.CreateOrUpdateHeader(core.Header{BlockNumber: n}) + Expect(err).NotTo(HaveOccurred()) + } + pitFileRepository := debt_ceiling.NewPitFileDebtCeilingRepository(db) + pitFileRepositoryTwo := debt_ceiling.NewPitFileDebtCeilingRepository(dbTwo) + err := pitFileRepository.Create(headerIDs[0], test_data.PitFileDebtCeilingModel) + Expect(err).NotTo(HaveOccurred()) + + nodeOneMissingHeaders, err := pitFileRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) + Expect(err).NotTo(HaveOccurred()) + Expect(len(nodeOneMissingHeaders)).To(Equal(len(blockNumbers) - 1)) + + nodeTwoMissingHeaders, err := pitFileRepositoryTwo.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) + Expect(err).NotTo(HaveOccurred()) + Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers))) + }) + }) +}) diff --git a/pkg/transformers/pit_file/debt_ceiling/transformer.go b/pkg/transformers/pit_file/debt_ceiling/transformer.go new file mode 100644 index 00000000..9d7bddb9 --- /dev/null +++ b/pkg/transformers/pit_file/debt_ceiling/transformer.go @@ -0,0 +1,57 @@ +package debt_ceiling + +import ( + "github.com/ethereum/go-ethereum/common" + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" +) + +type PitFileDebtCeilingTransformer struct { + Config shared.TransformerConfig + Converter Converter + Fetcher shared.LogFetcher + Repository Repository +} + +type PitFileDebtCeilingTransformerInitializer struct { + Config shared.TransformerConfig +} + +func (initializer PitFileDebtCeilingTransformerInitializer) NewPitFileDebtCeilingTransformer(db *postgres.DB, blockChain core.BlockChain) shared.Transformer { + converter := PitFileDebtCeilingConverter{} + fetcher := shared.NewFetcher(blockChain) + repository := NewPitFileDebtCeilingRepository(db) + return PitFileDebtCeilingTransformer{ + Config: initializer.Config, + Converter: converter, + Fetcher: fetcher, + Repository: repository, + } +} + +func (transformer PitFileDebtCeilingTransformer) Execute() error { + missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber) + if err != nil { + return err + } + for _, header := range missingHeaders { + topics := [][]common.Hash{{common.HexToHash(shared.PitFileDebtCeilingSignature)}} + matchingLogs, err := transformer.Fetcher.FetchLogs(pit_file.PitFileConfig.ContractAddress, topics, header.BlockNumber) + if err != nil { + return err + } + for _, log := range matchingLogs { + model, err := transformer.Converter.ToModel(pit_file.PitFileConfig.ContractAddress, shared.PitABI, log) + if err != nil { + return err + } + err = transformer.Repository.Create(header.Id, model) + if err != nil { + return err + } + } + } + return nil +} diff --git a/pkg/transformers/pit_file/debt_ceiling/transformer_test.go b/pkg/transformers/pit_file/debt_ceiling/transformer_test.go new file mode 100644 index 00000000..cfd8006b --- /dev/null +++ b/pkg/transformers/pit_file/debt_ceiling/transformer_test.go @@ -0,0 +1,162 @@ +package debt_ceiling_test + +import ( + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/fakes" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks" + debt_ceiling_mocks "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks/pit_file/debt_ceiling" +) + +var _ = Describe("", func() { + It("gets missing headers for block numbers specified in config", func() { + repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{} + transformer := debt_ceiling.PitFileDebtCeilingTransformer{ + Config: pit_file.PitFileConfig, + Fetcher: &mocks.MockLogFetcher{}, + Converter: &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{}, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).NotTo(HaveOccurred()) + Expect(repository.PassedStartingBlockNumber).To(Equal(pit_file.PitFileConfig.StartingBlockNumber)) + Expect(repository.PassedEndingBlockNumber).To(Equal(pit_file.PitFileConfig.EndingBlockNumber)) + }) + + It("returns error if repository returns error for missing headers", func() { + repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{} + repository.SetMissingHeadersErr(fakes.FakeError) + transformer := debt_ceiling.PitFileDebtCeilingTransformer{ + Fetcher: &mocks.MockLogFetcher{}, + Converter: &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{}, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("fetches logs for missing headers", func() { + fetcher := &mocks.MockLogFetcher{} + repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}, {BlockNumber: 2}}) + transformer := debt_ceiling.PitFileDebtCeilingTransformer{ + Fetcher: fetcher, + Converter: &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{}, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).NotTo(HaveOccurred()) + Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) + Expect(fetcher.FetchedContractAddress).To(Equal(pit_file.PitFileConfig.ContractAddress)) + Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.PitFileDebtCeilingSignature)}})) + }) + + It("returns error if fetcher returns error", func() { + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetcherError(fakes.FakeError) + repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) + transformer := debt_ceiling.PitFileDebtCeilingTransformer{ + Fetcher: fetcher, + Converter: &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{}, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("converts matching logs", func() { + converter := &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{} + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileDebtCeilingLog}) + repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) + transformer := debt_ceiling.PitFileDebtCeilingTransformer{ + Fetcher: fetcher, + Converter: converter, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).NotTo(HaveOccurred()) + Expect(converter.PassedContractAddress).To(Equal(pit_file.PitFileConfig.ContractAddress)) + Expect(converter.PassedContractABI).To(Equal(pit_file.PitFileConfig.ContractAbi)) + Expect(converter.PassedLog).To(Equal(test_data.EthPitFileDebtCeilingLog)) + }) + + It("returns error if converter returns error", func() { + converter := &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{} + converter.SetConverterError(fakes.FakeError) + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileDebtCeilingLog}) + repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}}) + transformer := debt_ceiling.PitFileDebtCeilingTransformer{ + Fetcher: fetcher, + Converter: converter, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("persists pit file model", func() { + converter := &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{} + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileDebtCeilingLog}) + repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{} + fakeHeader := core.Header{BlockNumber: 1, Id: 2} + repository.SetMissingHeaders([]core.Header{fakeHeader}) + transformer := debt_ceiling.PitFileDebtCeilingTransformer{ + Fetcher: fetcher, + Converter: converter, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).NotTo(HaveOccurred()) + Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id)) + Expect(repository.PassedModel).To(Equal(test_data.PitFileDebtCeilingModel)) + }) + + It("returns error if repository returns error for create", func() { + converter := &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{} + fetcher := &mocks.MockLogFetcher{} + fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileDebtCeilingLog}) + repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{} + repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}}) + repository.SetCreateError(fakes.FakeError) + transformer := debt_ceiling.PitFileDebtCeilingTransformer{ + Fetcher: fetcher, + Converter: converter, + Repository: repository, + } + + err := transformer.Execute() + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) +}) diff --git a/pkg/transformers/shared/constants.go b/pkg/transformers/shared/constants.go index 38bfb010..41f71643 100644 --- a/pkg/transformers/shared/constants.go +++ b/pkg/transformers/shared/constants.go @@ -18,9 +18,9 @@ var ( biteMethod = "Bite(bytes32,bytes32,uint256,uint256,uint256,uint256,uint256)" flipKickMethod = "Kick(uint256,uint256,uint256,address,uint48,bytes32,uint256)" frobMethod = "Frob(bytes32,bytes32,uint256,uint256,int256,int256,uint256)" + pitFileDebtCeilingMethod = "file(bytes32,uint256)" pitFileIlkMethod = "file(bytes32,bytes32,uint256)" pitFileStabilityFeeMethod = "file(bytes32,address)" - pitFileDebtCeilingMethod = "file(bytes32,uint256)" tendMethod = "tend(uint256,uint256,uint256)" CatABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"vat\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"vow\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"flips\",\"outputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"lad\",\"type\":\"bytes32\"},{\"name\":\"ink\",\"type\":\"uint256\"},{\"name\":\"tab\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"nflip\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"live\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"wards\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"ilks\",\"outputs\":[{\"name\":\"flip\",\"type\":\"address\"},{\"name\":\"chop\",\"type\":\"uint256\"},{\"name\":\"lump\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"pit\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"vat_\",\"type\":\"address\"},{\"name\":\"pit_\",\"type\":\"address\"},{\"name\":\"vow_\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"ilk\",\"type\":\"bytes32\"},{\"indexed\":true,\"name\":\"lad\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"ink\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"art\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"tab\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"flip\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"iArt\",\"type\":\"uint256\"}],\"name\":\"Bite\",\"type\":\"event\"},{\"anonymous\":true,\"inputs\":[{\"indexed\":true,\"name\":\"sig\",\"type\":\"bytes4\"},{\"indexed\":true,\"name\":\"guy\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"foo\",\"type\":\"bytes32\"},{\"indexed\":true,\"name\":\"bar\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"wad\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"fax\",\"type\":\"bytes\"}],\"name\":\"LogNote\",\"type\":\"event\"},{\"constant\":false,\"inputs\":[{\"name\":\"guy\",\"type\":\"address\"}],\"name\":\"rely\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"guy\",\"type\":\"address\"}],\"name\":\"deny\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"what\",\"type\":\"bytes32\"},{\"name\":\"data\",\"type\":\"uint256\"}],\"name\":\"file\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"what\",\"type\":\"bytes32\"},{\"name\":\"flip\",\"type\":\"address\"}],\"name\":\"file\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"ilk\",\"type\":\"bytes32\"},{\"name\":\"lad\",\"type\":\"bytes32\"}],\"name\":\"bite\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"n\",\"type\":\"uint256\"},{\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"flip\",\"outputs\":[{\"name\":\"id\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" @@ -34,8 +34,8 @@ var ( FlipKickSignature = GetEventSignature(flipKickMethod) FrobSignature = GetEventSignature(frobMethod) LogValueSignature = GetEventSignature("") + PitFileDebtCeilingSignature = GetLogNoteSignature(pitFileDebtCeilingMethod) PitFileIlkSignature = GetLogNoteSignature(pitFileIlkMethod) PitFileStabilityFeeSignature = GetLogNoteSignature(pitFileStabilityFeeMethod) - PitFileDebtCeilingSignature = GetLogNoteSignature(pitFileDebtCeilingMethod) TendFunctionSignature = GetLogNoteSignature(tendMethod) ) diff --git a/pkg/transformers/test_data/mocks/pit_file/debt_ceiling/converter.go b/pkg/transformers/test_data/mocks/pit_file/debt_ceiling/converter.go new file mode 100644 index 00000000..5ba4bb43 --- /dev/null +++ b/pkg/transformers/test_data/mocks/pit_file/debt_ceiling/converter.go @@ -0,0 +1,25 @@ +package debt_ceiling + +import ( + "github.com/ethereum/go-ethereum/core/types" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" +) + +type MockPitFileDebtCeilingConverter struct { + converterErr error + PassedContractAddress string + PassedContractABI string + PassedLog types.Log +} + +func (converter *MockPitFileDebtCeilingConverter) ToModel(contractAddress string, contractAbi string, ethLog types.Log) (debt_ceiling.PitFileDebtCeilingModel, error) { + converter.PassedContractAddress = contractAddress + converter.PassedContractABI = contractAbi + converter.PassedLog = ethLog + return test_data.PitFileDebtCeilingModel, converter.converterErr +} + +func (converter *MockPitFileDebtCeilingConverter) SetConverterError(e error) { + converter.converterErr = e +} diff --git a/pkg/transformers/test_data/mocks/pit_file/debt_ceiling/repository.go b/pkg/transformers/test_data/mocks/pit_file/debt_ceiling/repository.go new file mode 100644 index 00000000..2ad41b16 --- /dev/null +++ b/pkg/transformers/test_data/mocks/pit_file/debt_ceiling/repository.go @@ -0,0 +1,40 @@ +package debt_ceiling + +import ( + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling" +) + +type MockPitFileDebtCeilingRepository struct { + createErr error + missingHeaders []core.Header + missingHeadersErr error + PassedStartingBlockNumber int64 + PassedEndingBlockNumber int64 + PassedHeaderID int64 + PassedModel debt_ceiling.PitFileDebtCeilingModel +} + +func (repository *MockPitFileDebtCeilingRepository) Create(headerID int64, model debt_ceiling.PitFileDebtCeilingModel) error { + repository.PassedHeaderID = headerID + repository.PassedModel = model + return repository.createErr +} + +func (repository *MockPitFileDebtCeilingRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { + repository.PassedStartingBlockNumber = startingBlockNumber + repository.PassedEndingBlockNumber = endingBlockNumber + return repository.missingHeaders, repository.missingHeadersErr +} + +func (repository *MockPitFileDebtCeilingRepository) SetMissingHeadersErr(e error) { + repository.missingHeadersErr = e +} + +func (repository *MockPitFileDebtCeilingRepository) SetMissingHeaders(headers []core.Header) { + repository.missingHeaders = headers +} + +func (repository *MockPitFileDebtCeilingRepository) SetCreateError(e error) { + repository.createErr = e +} diff --git a/pkg/transformers/test_data/pit_file.go b/pkg/transformers/test_data/pit_file.go index 664e3452..d5e78380 100644 --- a/pkg/transformers/test_data/pit_file.go +++ b/pkg/transformers/test_data/pit_file.go @@ -5,6 +5,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling" ilk2 "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/ilk" "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/stability_fee" "math/big" @@ -14,6 +15,31 @@ var ( PitAddress = "0xff3f2400f1600f3f493a9a92704a29b96795af1a" ) +var EthPitFileDebtCeilingLog = types.Log{ + Address: common.HexToAddress(PitAddress), + Topics: []common.Hash{ + common.HexToHash("0x29ae811400000000000000000000000000000000000000000000000000000000"), + common.HexToHash("0x00000000000000000000000064d922894153be9eef7b7218dc565d1d0ce2a092"), + common.HexToHash("0x6472697000000000000000000000000000000000000000000000000000000000"), + common.HexToHash("0x000000000000000000000000000000000000000000000000000000000000007b"), + }, + Data: hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000004429ae81146472697000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007b"), + BlockNumber: 22, + TxHash: common.HexToHash("0xd744878a0b6655e3ba729e1019f56b563b4a16750196b8ad6104f3977db43f42"), + TxIndex: 333, + BlockHash: common.HexToHash("0xa54d9d99c315bea3dda7256a36e51773ed009a01c0859295c5382d4b83d7eeb9"), + Index: 0, + Removed: false, +} + +var rawPitFileDebtCeilingLog, _ = json.Marshal(EthPitFileDebtCeilingLog) +var PitFileDebtCeilingModel = debt_ceiling.PitFileDebtCeilingModel{ + What: "0x64d922894153BE9EEf7b7218dc565d1D0Ce2a092", + Data: big.NewInt(123).String(), + TransactionIndex: EthPitFileDebtCeilingLog.TxIndex, + Raw: rawPitFileDebtCeilingLog, +} + var EthPitFileIlkLog = types.Log{ Address: common.HexToAddress(PitAddress), Topics: []common.Hash{ @@ -51,7 +77,7 @@ var EthPitFileStabilityFeeLog = types.Log{ Data: hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000044d4e8be8364726970000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"), BlockNumber: 12, TxHash: common.HexToHash("0x78cdc62316ccf8e31515d09745cc724f557569f01a557d0d09b1066bf7079fd2"), - TxIndex: 0, + TxIndex: 222, BlockHash: common.HexToHash("0xe3d8e458421533170871b4033f978a3793ef10b7e33a9328a13c09e2fd90208d"), Index: 0, Removed: false, @@ -61,6 +87,6 @@ var rawPitFileStabilityFeeLog, _ = json.Marshal(EthPitFileStabilityFeeLog) var PitFileStabilityFeeModel = stability_fee.PitFileStabilityFeeModel{ What: "drip", Data: "0x64d922894153BE9EEf7b7218dc565d1D0Ce2a092", - TransactionIndex: 0, + TransactionIndex: EthPitFileStabilityFeeLog.TxIndex, Raw: rawPitFileStabilityFeeLog, } diff --git a/pkg/transformers/transformers.go b/pkg/transformers/transformers.go index a83a7e15..26fe9f78 100644 --- a/pkg/transformers/transformers.go +++ b/pkg/transformers/transformers.go @@ -19,6 +19,7 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick" "github.com/vulcanize/vulcanizedb/pkg/transformers/frob" "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file" + "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling" "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/ilk" "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/stability_fee" "github.com/vulcanize/vulcanizedb/pkg/transformers/price_feeds" @@ -32,6 +33,7 @@ func TransformerInitializers() []shared.TransformerInitializer { frobConfig := frob.FrobConfig frobTransformerInitializer := frob.FrobTransformerInitializer{Config: frobConfig} pitFileConfig := pit_file.PitFileConfig + pitFileDebtCeilingTransformerInitializer := debt_ceiling.PitFileDebtCeilingTransformerInitializer{Config: pitFileConfig} pitFileIlkTransformerInitializer := ilk.PitFileIlkTransformerInitializer{Config: pitFileConfig} pitFileStabilityFeeTransformerInitializer := stability_fee.PitFileStabilityFeeTransformerInitializer{Config: pitFileConfig} priceFeedConfig := price_feeds.PriceFeedConfig @@ -44,6 +46,7 @@ func TransformerInitializers() []shared.TransformerInitializer { biteTransformerInitializer.NewBiteTransformer, flipKickTransformerInitializer.NewFlipKickTransformer, frobTransformerInitializer.NewFrobTransformer, + pitFileDebtCeilingTransformerInitializer.NewPitFileDebtCeilingTransformer, pitFileIlkTransformerInitializer.NewPitFileIlkTransformer, pitFileStabilityFeeTransformerInitializer.NewPitFileStabilityFeeTransformer, priceFeedTransformerInitializer.NewPriceFeedTransformer,