Fix test suites!
This commit is contained in:
parent
e1ba7ac5b4
commit
637623b752
@ -2,6 +2,7 @@ package shared
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers"
|
||||||
@ -18,7 +19,7 @@ type Watcher struct {
|
|||||||
Topics []common.Hash
|
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()
|
transformerConfigs := transformers.TransformerConfigs()
|
||||||
var contractAddresses []common.Address
|
var contractAddresses []common.Address
|
||||||
var topic0s []common.Hash
|
var topic0s []common.Hash
|
||||||
@ -31,7 +32,6 @@ func NewWatcher(db postgres.DB, bc core.BlockChain) Watcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
chunker := shared.NewLogChunker(transformerConfigs)
|
chunker := shared.NewLogChunker(transformerConfigs)
|
||||||
fetcher := shared.NewFetcher(bc)
|
|
||||||
|
|
||||||
return Watcher{
|
return Watcher{
|
||||||
DB: db,
|
DB: db,
|
||||||
@ -73,6 +73,10 @@ func (watcher *Watcher) Execute() error {
|
|||||||
for _, transformer := range watcher.Transformers {
|
for _, transformer := range watcher.Transformers {
|
||||||
logChunk := chunkedLogs[transformer.Name()]
|
logChunk := chunkedLogs[transformer.Name()]
|
||||||
err = transformer.Execute(logChunk, header)
|
err = transformer.Execute(logChunk, header)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("%v transformer failed to execute: %v", transformer.Name(), err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
||||||
shared2 "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
shared2 "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks"
|
||||||
"github.com/vulcanize/vulcanizedb/test_config"
|
"github.com/vulcanize/vulcanizedb/test_config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ var _ = Describe("Watcher", func() {
|
|||||||
// TODO Add tests for aggregate fetching
|
// TODO Add tests for aggregate fetching
|
||||||
// TODO Add tests for MissingHeaders
|
// TODO Add tests for MissingHeaders
|
||||||
|
|
||||||
It("Adds transformers", func() {
|
It("adds transformers", func() {
|
||||||
watcher := shared.Watcher{}
|
watcher := shared.Watcher{}
|
||||||
|
|
||||||
watcher.AddTransformers([]shared2.TransformerInitializer{fakeTransformerInitializer})
|
watcher.AddTransformers([]shared2.TransformerInitializer{fakeTransformerInitializer})
|
||||||
@ -54,7 +55,7 @@ var _ = Describe("Watcher", func() {
|
|||||||
Expect(watcher.Transformers).To(ConsistOf(&MockTransformer{}))
|
Expect(watcher.Transformers).To(ConsistOf(&MockTransformer{}))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("Adds transformers from multiple sources", func() {
|
It("adds transformers from multiple sources", func() {
|
||||||
watcher := shared.Watcher{}
|
watcher := shared.Watcher{}
|
||||||
|
|
||||||
watcher.AddTransformers([]shared2.TransformerInitializer{fakeTransformerInitializer})
|
watcher.AddTransformers([]shared2.TransformerInitializer{fakeTransformerInitializer})
|
||||||
@ -69,12 +70,14 @@ var _ = Describe("Watcher", func() {
|
|||||||
watcher shared.Watcher
|
watcher shared.Watcher
|
||||||
fakeTransformer *MockTransformer
|
fakeTransformer *MockTransformer
|
||||||
headerRepository repositories.HeaderRepository
|
headerRepository repositories.HeaderRepository
|
||||||
|
mockFetcher shared2.LogFetcher
|
||||||
)
|
)
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
db = test_config.NewTestDB(test_config.NewTestNode())
|
db = test_config.NewTestDB(test_config.NewTestNode())
|
||||||
test_config.CleanTestDB(db)
|
test_config.CleanTestDB(db)
|
||||||
watcher = shared.NewWatcher(*db, nil)
|
mockFetcher = &mocks.MockLogFetcher{}
|
||||||
|
watcher = shared.NewWatcher(*db, nil, mockFetcher)
|
||||||
headerRepository = repositories.NewHeaderRepository(db)
|
headerRepository = repositories.NewHeaderRepository(db)
|
||||||
_, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
_, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
@ -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)
|
log.Printf("Error marking header as checked in %v: %v", transformerName, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
models, err := transformer.Converter.ToModels(logs)
|
models, err := transformer.Converter.ToModels(logs)
|
||||||
|
@ -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)
|
log.Printf("Error marking header as checked in %v: %v", transformerName, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
entities, err := transformer.Converter.ToEntities(config.ContractAbi, logs)
|
entities, err := transformer.Converter.ToEntities(config.ContractAbi, logs)
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type MockLogFetcher struct {
|
type MockLogFetcher struct {
|
||||||
FetchedContractAddresses [][]string
|
FetchedContractAddresses [][]common.Address
|
||||||
FetchedTopics [][]common.Hash
|
FetchedTopics [][]common.Hash
|
||||||
FetchedBlocks []int64
|
FetchedBlocks []int64
|
||||||
fetcherError error
|
fetcherError error
|
||||||
@ -29,9 +29,9 @@ type MockLogFetcher struct {
|
|||||||
SetBcCalled bool
|
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.FetchedContractAddresses = append(mlf.FetchedContractAddresses, contractAddresses)
|
||||||
mlf.FetchedTopics = topics
|
mlf.FetchedTopics = [][]common.Hash{topics}
|
||||||
mlf.FetchedBlocks = append(mlf.FetchedBlocks, header.BlockNumber)
|
mlf.FetchedBlocks = append(mlf.FetchedBlocks, header.BlockNumber)
|
||||||
|
|
||||||
return mlf.FetchedLogs, mlf.fetcherError
|
return mlf.FetchedLogs, mlf.fetcherError
|
||||||
|
Loading…
Reference in New Issue
Block a user