Further refactor move and init tests
This commit is contained in:
parent
c4d3783f8b
commit
4d36f6200d
@ -75,14 +75,14 @@ var (
|
||||
VatInitTransformerInitializer = factories.Transformer{
|
||||
Config: vat_init.VatInitConfig,
|
||||
Converter: &vat_init.VatInitConverter{},
|
||||
Repository: &vat_init.VatInitRepository{DB: nil},
|
||||
Repository: &vat_init.VatInitRepository{},
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}.NewTransformer
|
||||
|
||||
VatMoveTransformerInitializer = factories.Transformer{
|
||||
Config: vat_move.VatMoveConfig,
|
||||
Converter: &vat_move.VatMoveConverter{},
|
||||
Repository: &vat_move.VatMoveRepository{DB: nil},
|
||||
Repository: &vat_move.VatMoveRepository{},
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}.NewTransformer
|
||||
VatHealTransformerInitializer = vat_heal.VatHealTransformerInitializer{Config: vat_heal.VatHealConfig}.NewVatHealTransformer
|
||||
|
@ -24,18 +24,20 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("Vat init converter", func() {
|
||||
It("returns err if log missing topics", func() {
|
||||
converter := vat_init.VatInitConverter{}
|
||||
badLog := types.Log{}
|
||||
var converter vat_init.VatInitConverter
|
||||
|
||||
BeforeEach(func() {
|
||||
converter = vat_init.VatInitConverter{}
|
||||
})
|
||||
|
||||
It("returns err if log missing topics", func() {
|
||||
badLog := types.Log{}
|
||||
_, err := converter.ToModels([]types.Log{badLog})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
|
||||
It("converts a log to an model", func() {
|
||||
converter := vat_init.VatInitConverter{}
|
||||
|
||||
models, err := converter.ToModels([]types.Log{test_data.EthVatInitLog})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
@ -36,6 +36,7 @@ var _ = Describe("Vat init transformer", func() {
|
||||
converter vat_init_mocks.MockVatInitConverter
|
||||
repository vat_init_mocks.MockVatInitRepository
|
||||
fetcher mocks.MockLogFetcher
|
||||
transformer shared.Transformer
|
||||
headerOne core.Header
|
||||
headerTwo core.Header
|
||||
)
|
||||
@ -46,16 +47,15 @@ var _ = Describe("Vat init transformer", func() {
|
||||
fetcher = mocks.MockLogFetcher{}
|
||||
headerOne = core.Header{Id: GinkgoRandomSeed(), BlockNumber: GinkgoRandomSeed()}
|
||||
headerTwo = core.Header{Id: GinkgoRandomSeed(), BlockNumber: GinkgoRandomSeed()}
|
||||
transformer = factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}.NewTransformer(nil, nil)
|
||||
})
|
||||
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &vat_init_mocks.MockVatInitConverter{},
|
||||
Repository: &repository,
|
||||
}.NewTransformer(nil, nil)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@ -65,12 +65,6 @@ var _ = Describe("Vat init transformer", func() {
|
||||
|
||||
It("returns error if repository returns error for missing headers", func() {
|
||||
repository.SetMissingHeadersError(fakes.FakeError)
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &vat_init_mocks.MockVatInitConverter{},
|
||||
Repository: &repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -80,31 +74,19 @@ var _ = Describe("Vat init transformer", func() {
|
||||
|
||||
It("fetches logs for missing headers", func() {
|
||||
repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(fetcher.FetchedBlocks).To(Equal([]int64{headerOne.BlockNumber, headerTwo.BlockNumber}))
|
||||
Expect(fetcher.FetchedContractAddresses).To(Equal(
|
||||
[][]string{transformer.Config.ContractAddresses, transformer.Config.ContractAddresses}))
|
||||
[][]string{config.ContractAddresses, config.ContractAddresses}))
|
||||
Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.VatInitSignature)}}))
|
||||
})
|
||||
|
||||
It("returns error if fetcher returns error", func() {
|
||||
fetcher.SetFetcherError(fakes.FakeError)
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -114,12 +96,6 @@ var _ = Describe("Vat init transformer", func() {
|
||||
|
||||
It("marks header checked if no logs returned", func() {
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -130,12 +106,6 @@ var _ = Describe("Vat init transformer", func() {
|
||||
It("returns error if marking header checked returns err", func() {
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetMarkHeaderCheckedError(fakes.FakeError)
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -146,12 +116,6 @@ var _ = Describe("Vat init transformer", func() {
|
||||
It("converts matching logs", func() {
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatInitLog})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -163,12 +127,6 @@ var _ = Describe("Vat init transformer", func() {
|
||||
converter.SetConverterError(fakes.FakeError)
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatInitLog})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -179,12 +137,6 @@ var _ = Describe("Vat init transformer", func() {
|
||||
It("persists vat init model", func() {
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatInitLog})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -197,12 +149,6 @@ var _ = Describe("Vat init transformer", func() {
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatInitLog})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetCreateError(fakes.FakeError)
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
|
@ -24,18 +24,20 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("Vat move converter", func() {
|
||||
It("returns err if logs are missing topics", func() {
|
||||
converter := vat_move.VatMoveConverter{}
|
||||
badLog := types.Log{}
|
||||
var converter vat_move.VatMoveConverter
|
||||
|
||||
BeforeEach(func() {
|
||||
converter = vat_move.VatMoveConverter{}
|
||||
})
|
||||
|
||||
It("returns err if logs are missing topics", func() {
|
||||
badLog := types.Log{}
|
||||
_, err := converter.ToModels([]types.Log{badLog})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
|
||||
It("converts a log to a model", func() {
|
||||
converter := vat_move.VatMoveConverter{}
|
||||
|
||||
models, err := converter.ToModels([]types.Log{test_data.EthVatMoveLog})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
@ -30,10 +30,11 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("Vat move transformer", func() {
|
||||
var config = vat_move.VatMoveConfig
|
||||
var fetcher mocks.MockLogFetcher
|
||||
var converter vat_move_mocks.MockVatMoveConverter
|
||||
var repository vat_move_mocks.MockVatMoveRepository
|
||||
var config = vat_move.VatMoveConfig
|
||||
var transformer shared.Transformer
|
||||
var headerOne core.Header
|
||||
var headerTwo core.Header
|
||||
|
||||
@ -43,16 +44,15 @@ var _ = Describe("Vat move transformer", func() {
|
||||
repository = vat_move_mocks.MockVatMoveRepository{}
|
||||
headerOne = core.Header{Id: GinkgoRandomSeed(), BlockNumber: GinkgoRandomSeed()}
|
||||
headerTwo = core.Header{Id: GinkgoRandomSeed(), BlockNumber: GinkgoRandomSeed()}
|
||||
transformer = factories.Transformer{
|
||||
Config: config,
|
||||
Converter: &converter,
|
||||
Fetcher: &fetcher,
|
||||
Repository: &repository,
|
||||
}.NewTransformer(nil, nil)
|
||||
})
|
||||
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
Fetcher: &fetcher,
|
||||
}.NewTransformer(nil, nil)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@ -62,12 +62,7 @@ var _ = Describe("Vat move transformer", func() {
|
||||
|
||||
It("returns error if repository returns error for missing headers", func() {
|
||||
repository.SetMissingHeadersError(fakes.FakeError)
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Converter: &converter,
|
||||
Fetcher: &fetcher,
|
||||
Repository: &repository,
|
||||
}.NewTransformer(nil, nil)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
@ -76,12 +71,6 @@ var _ = Describe("Vat move transformer", func() {
|
||||
|
||||
It("fetches logs for missing headers", func() {
|
||||
repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}.NewTransformer(nil, nil)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -97,12 +86,6 @@ var _ = Describe("Vat move transformer", func() {
|
||||
It("returns error if fetcher returns error", func() {
|
||||
fetcher.SetFetcherError(fakes.FakeError)
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}.NewTransformer(nil, nil)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -113,12 +96,6 @@ var _ = Describe("Vat move transformer", func() {
|
||||
It("converts matching logs", func() {
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatMoveLog})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}.NewTransformer(nil, nil)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -130,12 +107,6 @@ var _ = Describe("Vat move transformer", func() {
|
||||
converter.SetConverterError(fakes.FakeError)
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatMoveLog})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}.NewTransformer(nil, nil)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -146,12 +117,6 @@ var _ = Describe("Vat move transformer", func() {
|
||||
It("marks header as checked even if no logs were returned", func() {
|
||||
repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
|
||||
fetcher.SetFetchedLogs([]types.Log{})
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Converter: &converter,
|
||||
Fetcher: &fetcher,
|
||||
Repository: &repository,
|
||||
}.NewTransformer(nil, nil)
|
||||
|
||||
err := transformer.Execute()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@ -163,12 +128,6 @@ var _ = Describe("Vat move transformer", func() {
|
||||
repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
|
||||
repository.SetCheckedHeaderError(fakes.FakeError)
|
||||
fetcher.SetFetchedLogs([]types.Log{})
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Converter: &converter,
|
||||
Fetcher: &fetcher,
|
||||
Repository: &repository,
|
||||
}.NewTransformer(nil, nil)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -179,12 +138,6 @@ var _ = Describe("Vat move transformer", func() {
|
||||
It("persists vat move model", func() {
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatMoveLog})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}.NewTransformer(nil, nil)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -197,12 +150,6 @@ var _ = Describe("Vat move transformer", func() {
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatMoveLog})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetCreateError(fakes.FakeError)
|
||||
transformer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}.NewTransformer(nil, nil)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user