From 637623b752bcba068f450333227b8ca6f09ee180 Mon Sep 17 00:00:00 2001 From: Edvard Date: Mon, 10 Dec 2018 15:40:45 +0100 Subject: [PATCH] Fix test suites! --- libraries/shared/watcher.go | 8 ++++++-- libraries/shared/watcher_test.go | 9 ++++++--- pkg/transformers/factories/log_note_transformer.go | 1 + pkg/transformers/factories/transformer.go | 1 + pkg/transformers/test_data/mocks/log_fetcher.go | 6 +++--- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/libraries/shared/watcher.go b/libraries/shared/watcher.go index 89ee5a42..79834d57 100644 --- a/libraries/shared/watcher.go +++ b/libraries/shared/watcher.go @@ -2,6 +2,7 @@ package shared import ( "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/log" "github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers" @@ -18,7 +19,7 @@ type Watcher struct { Topics []common.Hash } -func NewWatcher(db postgres.DB, bc core.BlockChain) Watcher { +func NewWatcher(db postgres.DB, bc core.BlockChain, fetcher shared.LogFetcher) Watcher { transformerConfigs := transformers.TransformerConfigs() var contractAddresses []common.Address var topic0s []common.Hash @@ -31,7 +32,6 @@ func NewWatcher(db postgres.DB, bc core.BlockChain) Watcher { } chunker := shared.NewLogChunker(transformerConfigs) - fetcher := shared.NewFetcher(bc) return Watcher{ DB: db, @@ -73,6 +73,10 @@ func (watcher *Watcher) Execute() error { for _, transformer := range watcher.Transformers { logChunk := chunkedLogs[transformer.Name()] err = transformer.Execute(logChunk, header) + if err != nil { + log.Error("%v transformer failed to execute: %v", transformer.Name(), err) + return err + } } } return err diff --git a/libraries/shared/watcher_test.go b/libraries/shared/watcher_test.go index e6781d04..2386375a 100644 --- a/libraries/shared/watcher_test.go +++ b/libraries/shared/watcher_test.go @@ -11,6 +11,7 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/fakes" shared2 "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" + "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks" "github.com/vulcanize/vulcanizedb/test_config" ) @@ -45,7 +46,7 @@ var _ = Describe("Watcher", func() { // TODO Add tests for aggregate fetching // TODO Add tests for MissingHeaders - It("Adds transformers", func() { + It("adds transformers", func() { watcher := shared.Watcher{} watcher.AddTransformers([]shared2.TransformerInitializer{fakeTransformerInitializer}) @@ -54,7 +55,7 @@ var _ = Describe("Watcher", func() { Expect(watcher.Transformers).To(ConsistOf(&MockTransformer{})) }) - It("Adds transformers from multiple sources", func() { + It("adds transformers from multiple sources", func() { watcher := shared.Watcher{} watcher.AddTransformers([]shared2.TransformerInitializer{fakeTransformerInitializer}) @@ -69,12 +70,14 @@ var _ = Describe("Watcher", func() { watcher shared.Watcher fakeTransformer *MockTransformer headerRepository repositories.HeaderRepository + mockFetcher shared2.LogFetcher ) BeforeEach(func() { db = test_config.NewTestDB(test_config.NewTestNode()) test_config.CleanTestDB(db) - watcher = shared.NewWatcher(*db, nil) + mockFetcher = &mocks.MockLogFetcher{} + watcher = shared.NewWatcher(*db, nil, mockFetcher) headerRepository = repositories.NewHeaderRepository(db) _, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) Expect(err).NotTo(HaveOccurred()) diff --git a/pkg/transformers/factories/log_note_transformer.go b/pkg/transformers/factories/log_note_transformer.go index 849d9619..200f0bce 100644 --- a/pkg/transformers/factories/log_note_transformer.go +++ b/pkg/transformers/factories/log_note_transformer.go @@ -44,6 +44,7 @@ func (transformer LogNoteTransformer) Execute(logs []types.Log, header core.Head log.Printf("Error marking header as checked in %v: %v", transformerName, err) return err } + return nil } models, err := transformer.Converter.ToModels(logs) diff --git a/pkg/transformers/factories/transformer.go b/pkg/transformers/factories/transformer.go index eae4fd7f..d6a4c385 100644 --- a/pkg/transformers/factories/transformer.go +++ b/pkg/transformers/factories/transformer.go @@ -44,6 +44,7 @@ func (transformer Transformer) Execute(logs []types.Log, header core.Header) err log.Printf("Error marking header as checked in %v: %v", transformerName, err) return err } + return nil } entities, err := transformer.Converter.ToEntities(config.ContractAbi, logs) diff --git a/pkg/transformers/test_data/mocks/log_fetcher.go b/pkg/transformers/test_data/mocks/log_fetcher.go index 47ce03aa..1eeee33e 100644 --- a/pkg/transformers/test_data/mocks/log_fetcher.go +++ b/pkg/transformers/test_data/mocks/log_fetcher.go @@ -21,7 +21,7 @@ import ( ) type MockLogFetcher struct { - FetchedContractAddresses [][]string + FetchedContractAddresses [][]common.Address FetchedTopics [][]common.Hash FetchedBlocks []int64 fetcherError error @@ -29,9 +29,9 @@ type MockLogFetcher struct { SetBcCalled bool } -func (mlf *MockLogFetcher) FetchLogs(contractAddresses []string, topics [][]common.Hash, header core.Header) ([]types.Log, error) { +func (mlf *MockLogFetcher) FetchLogs(contractAddresses []common.Address, topics []common.Hash, header core.Header) ([]types.Log, error) { mlf.FetchedContractAddresses = append(mlf.FetchedContractAddresses, contractAddresses) - mlf.FetchedTopics = topics + mlf.FetchedTopics = [][]common.Hash{topics} mlf.FetchedBlocks = append(mlf.FetchedBlocks, header.BlockNumber) return mlf.FetchedLogs, mlf.fetcherError