Update tests with new adding of transformers
This commit is contained in:
parent
dc43547612
commit
882a6dd7a2
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"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"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers"
|
|
||||||
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/pkg/transformers/test_data/mocks"
|
||||||
"github.com/vulcanize/vulcanizedb/test_config"
|
"github.com/vulcanize/vulcanizedb/test_config"
|
||||||
@ -47,48 +46,51 @@ func fakeTransformerInitializer(db *postgres.DB) shared2.Transformer {
|
|||||||
return &MockTransformer{}
|
return &MockTransformer{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var fakeTransformerConfig = []shared2.TransformerConfig{{
|
||||||
|
TransformerName: "FakeTransformer",
|
||||||
|
ContractAddresses: []string{"FakeAddress"},
|
||||||
|
Topic: "FakeTopic",
|
||||||
|
}}
|
||||||
|
|
||||||
var _ = Describe("Watcher", func() {
|
var _ = Describe("Watcher", func() {
|
||||||
It("initialises correctly", func() {
|
It("initialises correctly", func() {
|
||||||
db := test_config.NewTestDB(core.Node{ID: "testNode"})
|
db := test_config.NewTestDB(core.Node{ID: "testNode"})
|
||||||
fetcher := mocks.MockLogFetcher{}
|
fetcher := &mocks.MockLogFetcher{}
|
||||||
repository := &mocks.MockWatcherRepository{}
|
repository := &mocks.MockWatcherRepository{}
|
||||||
configA := shared2.TransformerConfig{
|
chunker := shared2.NewLogChunker()
|
||||||
ContractAddresses: []string{"0xA"},
|
|
||||||
Topic: "0xA",
|
watcher := shared.NewWatcher(db, fetcher, repository, chunker)
|
||||||
}
|
|
||||||
configB := shared2.TransformerConfig{
|
|
||||||
ContractAddresses: []string{"0xB"},
|
|
||||||
Topic: "0xB",
|
|
||||||
}
|
|
||||||
configs := []shared2.TransformerConfig{configA, configB}
|
|
||||||
watcher := shared.NewWatcher(db, &fetcher, repository, configs)
|
|
||||||
|
|
||||||
Expect(watcher.DB).To(Equal(db))
|
Expect(watcher.DB).To(Equal(db))
|
||||||
Expect(watcher.Fetcher).NotTo(BeNil())
|
Expect(watcher.Fetcher).To(Equal(fetcher))
|
||||||
Expect(watcher.Chunker).NotTo(BeNil())
|
Expect(watcher.Chunker).To(Equal(chunker))
|
||||||
Expect(watcher.Repository).To(Equal(repository))
|
Expect(watcher.Repository).To(Equal(repository))
|
||||||
Expect(watcher.Topics).To(And(
|
|
||||||
ContainElement(common.HexToHash("0xA")), ContainElement(common.HexToHash("0xB"))))
|
|
||||||
Expect(watcher.Addresses).To(And(
|
|
||||||
ContainElement(common.HexToAddress("0xA")), ContainElement(common.HexToAddress("0xB"))))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("adds transformers", func() {
|
It("adds transformers", func() {
|
||||||
watcher := shared.Watcher{}
|
chunker := shared2.NewLogChunker()
|
||||||
|
watcher := shared.NewWatcher(nil, nil, nil, chunker)
|
||||||
|
|
||||||
watcher.AddTransformers([]shared2.TransformerInitializer{fakeTransformerInitializer})
|
watcher.AddTransformers([]shared2.TransformerInitializer{fakeTransformerInitializer}, fakeTransformerConfig)
|
||||||
|
|
||||||
Expect(len(watcher.Transformers)).To(Equal(1))
|
Expect(len(watcher.Transformers)).To(Equal(1))
|
||||||
Expect(watcher.Transformers).To(ConsistOf(&MockTransformer{}))
|
Expect(watcher.Transformers).To(ConsistOf(&MockTransformer{}))
|
||||||
|
Expect(watcher.Topics).To(Equal([]common.Hash{common.HexToHash("FakeTopic")}))
|
||||||
|
Expect(watcher.Addresses).To(Equal([]common.Address{common.HexToAddress("FakeAddress")}))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("adds transformers from multiple sources", func() {
|
It("adds transformers from multiple sources", func() {
|
||||||
watcher := shared.Watcher{}
|
chunker := shared2.NewLogChunker()
|
||||||
|
watcher := shared.NewWatcher(nil, nil, nil, chunker)
|
||||||
|
|
||||||
watcher.AddTransformers([]shared2.TransformerInitializer{fakeTransformerInitializer})
|
watcher.AddTransformers([]shared2.TransformerInitializer{fakeTransformerInitializer}, fakeTransformerConfig)
|
||||||
watcher.AddTransformers([]shared2.TransformerInitializer{fakeTransformerInitializer})
|
watcher.AddTransformers([]shared2.TransformerInitializer{fakeTransformerInitializer}, fakeTransformerConfig)
|
||||||
|
|
||||||
Expect(len(watcher.Transformers)).To(Equal(2))
|
Expect(len(watcher.Transformers)).To(Equal(2))
|
||||||
|
Expect(watcher.Topics).To(Equal([]common.Hash{common.HexToHash("FakeTopic"),
|
||||||
|
common.HexToHash("FakeTopic")}))
|
||||||
|
Expect(watcher.Addresses).To(Equal([]common.Address{common.HexToAddress("FakeAddress"),
|
||||||
|
common.HexToAddress("FakeAddress")}))
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("with missing headers", func() {
|
Describe("with missing headers", func() {
|
||||||
@ -99,6 +101,7 @@ var _ = Describe("Watcher", func() {
|
|||||||
headerRepository repositories.HeaderRepository
|
headerRepository repositories.HeaderRepository
|
||||||
mockFetcher mocks.MockLogFetcher
|
mockFetcher mocks.MockLogFetcher
|
||||||
repository mocks.MockWatcherRepository
|
repository mocks.MockWatcherRepository
|
||||||
|
chunker *shared2.LogChunker
|
||||||
)
|
)
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
@ -108,9 +111,10 @@ var _ = Describe("Watcher", func() {
|
|||||||
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())
|
||||||
|
chunker = shared2.NewLogChunker()
|
||||||
|
|
||||||
repository = mocks.MockWatcherRepository{}
|
repository = mocks.MockWatcherRepository{}
|
||||||
watcher = shared.NewWatcher(db, &mockFetcher, &repository, transformers.TransformerConfigs())
|
watcher = shared.NewWatcher(db, &mockFetcher, &repository, chunker)
|
||||||
})
|
})
|
||||||
|
|
||||||
It("executes each transformer", func() {
|
It("executes each transformer", func() {
|
||||||
@ -155,8 +159,10 @@ var _ = Describe("Watcher", func() {
|
|||||||
Topics: []common.Hash{common.HexToHash("0xB")}}
|
Topics: []common.Hash{common.HexToHash("0xB")}}
|
||||||
mockFetcher.SetFetchedLogs([]types.Log{logA, logB})
|
mockFetcher.SetFetchedLogs([]types.Log{logA, logB})
|
||||||
|
|
||||||
|
chunker.AddConfigs(configs)
|
||||||
|
|
||||||
repository.SetMissingHeaders([]core.Header{fakes.FakeHeader})
|
repository.SetMissingHeaders([]core.Header{fakes.FakeHeader})
|
||||||
watcher = shared.NewWatcher(db, &mockFetcher, &repository, configs)
|
watcher = shared.NewWatcher(db, &mockFetcher, &repository, chunker)
|
||||||
watcher.Transformers = []shared2.Transformer{transformerA, transformerB}
|
watcher.Transformers = []shared2.Transformer{transformerA, transformerB}
|
||||||
|
|
||||||
err := watcher.Execute()
|
err := watcher.Execute()
|
||||||
|
@ -40,7 +40,7 @@ var _ = Describe("Cat File transformer", func() {
|
|||||||
rpcClient client.RpcClient
|
rpcClient client.RpcClient
|
||||||
err error
|
err error
|
||||||
ethClient *ethclient.Client
|
ethClient *ethclient.Client
|
||||||
fetcher shared.Fetcher
|
fetcher *shared.Fetcher
|
||||||
)
|
)
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
|
@ -34,7 +34,7 @@ var _ = Describe("Deal transformer", func() {
|
|||||||
blockChain core.BlockChain
|
blockChain core.BlockChain
|
||||||
config shared.TransformerConfig
|
config shared.TransformerConfig
|
||||||
initializer factories.LogNoteTransformer
|
initializer factories.LogNoteTransformer
|
||||||
fetcher shared.Fetcher
|
fetcher *shared.Fetcher
|
||||||
addresses []common.Address
|
addresses []common.Address
|
||||||
topics []common.Hash
|
topics []common.Hash
|
||||||
)
|
)
|
||||||
|
@ -18,7 +18,7 @@ var _ = Describe("Dent transformer", func() {
|
|||||||
var (
|
var (
|
||||||
db *postgres.DB
|
db *postgres.DB
|
||||||
blockChain core.BlockChain
|
blockChain core.BlockChain
|
||||||
fetcher shared.Fetcher
|
fetcher *shared.Fetcher
|
||||||
transformer shared.Transformer
|
transformer shared.Transformer
|
||||||
config shared.TransformerConfig
|
config shared.TransformerConfig
|
||||||
addresses []common.Address
|
addresses []common.Address
|
||||||
|
@ -35,7 +35,7 @@ var _ = Describe("Frob Transformer", func() {
|
|||||||
var (
|
var (
|
||||||
db *postgres.DB
|
db *postgres.DB
|
||||||
blockChain core.BlockChain
|
blockChain core.BlockChain
|
||||||
fetcher shared.Fetcher
|
fetcher *shared.Fetcher
|
||||||
config shared.TransformerConfig
|
config shared.TransformerConfig
|
||||||
initializer factories.Transformer
|
initializer factories.Transformer
|
||||||
)
|
)
|
||||||
|
@ -33,7 +33,7 @@ var _ = Describe("Price feeds transformer", func() {
|
|||||||
db *postgres.DB
|
db *postgres.DB
|
||||||
blockChain core.BlockChain
|
blockChain core.BlockChain
|
||||||
config shared.TransformerConfig
|
config shared.TransformerConfig
|
||||||
fetcher shared.Fetcher
|
fetcher *shared.Fetcher
|
||||||
initializer factories.LogNoteTransformer
|
initializer factories.LogNoteTransformer
|
||||||
topics []common.Hash
|
topics []common.Hash
|
||||||
)
|
)
|
||||||
|
@ -32,7 +32,7 @@ var _ = Describe("Tend LogNoteTransformer", func() {
|
|||||||
db *postgres.DB
|
db *postgres.DB
|
||||||
blockChain core.BlockChain
|
blockChain core.BlockChain
|
||||||
config shared.TransformerConfig
|
config shared.TransformerConfig
|
||||||
fetcher shared.Fetcher
|
fetcher *shared.Fetcher
|
||||||
initializer factories.LogNoteTransformer
|
initializer factories.LogNoteTransformer
|
||||||
addresses []common.Address
|
addresses []common.Address
|
||||||
topics []common.Hash
|
topics []common.Hash
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
var _ = Describe("Log chunker", func() {
|
var _ = Describe("Log chunker", func() {
|
||||||
var (
|
var (
|
||||||
configs []shared.TransformerConfig
|
configs []shared.TransformerConfig
|
||||||
chunker shared.LogChunker
|
chunker *shared.LogChunker
|
||||||
)
|
)
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
@ -47,7 +47,8 @@ var _ = Describe("Log chunker", func() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configs = []shared.TransformerConfig{configA, configB, configC}
|
configs = []shared.TransformerConfig{configA, configB, configC}
|
||||||
chunker = shared.NewLogChunker(configs)
|
chunker = shared.NewLogChunker()
|
||||||
|
chunker.AddConfigs(configs)
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("initialisation", func() {
|
Describe("initialisation", func() {
|
||||||
@ -66,6 +67,20 @@ var _ = Describe("Log chunker", func() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Describe("AddConfigs", func() {
|
||||||
|
It("can add more configs later", func() {
|
||||||
|
configD := shared.TransformerConfig{
|
||||||
|
TransformerName: "TransformerD",
|
||||||
|
ContractAddresses: []string{"0x000000000000000000000000000000000000000D"},
|
||||||
|
Topic: "0xD",
|
||||||
|
}
|
||||||
|
chunker.AddConfigs([]shared.TransformerConfig{configD})
|
||||||
|
|
||||||
|
Expect(chunker.AddressToNames).To(ContainElement([]string{"TransformerD"}))
|
||||||
|
Expect(chunker.NameToTopic0).To(ContainElement(common.HexToHash("0xD")))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
Describe("ChunkLogs", func() {
|
Describe("ChunkLogs", func() {
|
||||||
It("only associates logs with relevant topic0 and address to transformers", func() {
|
It("only associates logs with relevant topic0 and address to transformers", func() {
|
||||||
logs := []types.Log{log1, log2, log3, log4, log5}
|
logs := []types.Log{log1, log2, log3, log4, log5}
|
||||||
|
Loading…
Reference in New Issue
Block a user