Update drip_file tests
This commit is contained in:
parent
dc4eb009c1
commit
2a9fafca08
@ -56,6 +56,6 @@ var _ = Describe("Drip file ilk converter", func() {
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(models)).To(Equal(1))
|
||||
Expect(models[0]).To(Equal(test_data.DripFileIlkModel))
|
||||
Expect(models[0].(ilk.DripFileIlkModel)).To(Equal(test_data.DripFileIlkModel))
|
||||
})
|
||||
})
|
||||
|
@ -16,10 +16,8 @@ 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"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
@ -33,7 +31,7 @@ import (
|
||||
var _ = Describe("Drip file ilk repository", func() {
|
||||
var (
|
||||
db *postgres.DB
|
||||
dripFileIlkRepository ilk.Repository
|
||||
dripFileIlkRepository ilk.DripFileIlkRepository
|
||||
err error
|
||||
headerRepository datastore.HeaderRepository
|
||||
)
|
||||
@ -42,7 +40,7 @@ var _ = Describe("Drip file ilk repository", func() {
|
||||
db = test_config.NewTestDB(test_config.NewTestNode())
|
||||
test_config.CleanTestDB(db)
|
||||
headerRepository = repositories.NewHeaderRepository(db)
|
||||
dripFileIlkRepository = ilk.NewDripFileIlkRepository(db)
|
||||
dripFileIlkRepository = ilk.DripFileIlkRepository{DB: db}
|
||||
})
|
||||
|
||||
Describe("Create", func() {
|
||||
@ -52,7 +50,7 @@ var _ = Describe("Drip file ilk repository", func() {
|
||||
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = dripFileIlkRepository.Create(headerID, []ilk.DripFileIlkModel{test_data.DripFileIlkModel})
|
||||
err = dripFileIlkRepository.Create(headerID, []interface{}{test_data.DripFileIlkModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
@ -69,7 +67,6 @@ var _ = Describe("Drip file ilk repository", func() {
|
||||
})
|
||||
|
||||
It("marks header as checked for logs", func() {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
var headerChecked bool
|
||||
err = db.Get(&headerChecked, `SELECT drip_file_ilk_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@ -77,7 +74,7 @@ var _ = Describe("Drip file ilk repository", func() {
|
||||
})
|
||||
|
||||
It("does not duplicate drip file events", func() {
|
||||
err = dripFileIlkRepository.Create(headerID, []ilk.DripFileIlkModel{test_data.DripFileIlkModel})
|
||||
err = dripFileIlkRepository.Create(headerID, []interface{}{test_data.DripFileIlkModel})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
|
||||
@ -139,12 +136,12 @@ var _ = Describe("Drip file ilk repository", func() {
|
||||
blockNumbers = []int64{startingBlock, dripFileBlock, endingBlock, endingBlock + 1}
|
||||
|
||||
headerIDs = []int64{}
|
||||
|
||||
for _, n := range blockNumbers {
|
||||
headerID, err := headerRepository.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
headerIDs = append(headerIDs, headerID)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
It("returns headers with no associated drip file event", func() {
|
||||
@ -179,7 +176,7 @@ var _ = Describe("Drip file ilk repository", func() {
|
||||
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
dripFileIlkRepositoryTwo := ilk.NewDripFileIlkRepository(dbTwo)
|
||||
dripFileIlkRepositoryTwo := ilk.DripFileIlkRepository{DB: dbTwo}
|
||||
err := dripFileIlkRepository.MarkHeaderChecked(headerIDs[0])
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
@ -192,4 +189,14 @@ var _ = Describe("Drip file ilk repository", func() {
|
||||
Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers)))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("SetDB", func() {
|
||||
It("sets the repository db", func() {
|
||||
db := test_config.NewTestDB(core.Node{})
|
||||
repository := ilk.DripFileIlkRepository{}
|
||||
Expect(repository.DB).To(BeNil())
|
||||
repository.SetDB(db)
|
||||
Expect(repository.DB).To(Equal(db))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -19,10 +19,10 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/ilk"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
@ -31,31 +31,40 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("Drip file ilk transformer", func() {
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
repository := &ilk_mocks.MockDripFileIlkRepository{}
|
||||
transformer := ilk.DripFileIlkTransformer{
|
||||
Config: drip_file.DripFileConfig,
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &ilk_mocks.MockDripFileIlkConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
var (
|
||||
config = ilk.DripFileIlkConfig
|
||||
fetcher mocks.MockLogFetcher
|
||||
converter ilk_mocks.MockDripFileIlkConverter
|
||||
repository ilk_mocks.MockDripFileIlkRepository
|
||||
transformer shared.Transformer
|
||||
headerOne core.Header
|
||||
headerTwo core.Header
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
fetcher = mocks.MockLogFetcher{}
|
||||
converter = ilk_mocks.MockDripFileIlkConverter{}
|
||||
repository = ilk_mocks.MockDripFileIlkRepository{}
|
||||
transformer = factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}
|
||||
headerOne = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()}
|
||||
headerTwo = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()}
|
||||
})
|
||||
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.PassedStartingBlockNumber).To(Equal(drip_file.DripFileConfig.StartingBlockNumber))
|
||||
Expect(repository.PassedEndingBlockNumber).To(Equal(drip_file.DripFileConfig.EndingBlockNumber))
|
||||
Expect(repository.PassedStartingBlockNumber).To(Equal(config.StartingBlockNumber))
|
||||
Expect(repository.PassedEndingBlockNumber).To(Equal(config.EndingBlockNumber))
|
||||
})
|
||||
|
||||
It("returns error if repository returns error for missing headers", func() {
|
||||
repository := &ilk_mocks.MockDripFileIlkRepository{}
|
||||
repository.SetMissingHeadersErr(fakes.FakeError)
|
||||
transformer := ilk.DripFileIlkTransformer{
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &ilk_mocks.MockDripFileIlkConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
repository.SetMissingHeadersError(fakes.FakeError)
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
@ -63,33 +72,18 @@ var _ = Describe("Drip file ilk transformer", func() {
|
||||
})
|
||||
|
||||
It("fetches logs for missing headers", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
repository := &ilk_mocks.MockDripFileIlkRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}, {BlockNumber: 2}})
|
||||
transformer := ilk.DripFileIlkTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: &ilk_mocks.MockDripFileIlkConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2}))
|
||||
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{drip_file.DripFileConfig.ContractAddresses, drip_file.DripFileConfig.ContractAddresses}))
|
||||
Expect(fetcher.FetchedBlocks).To(Equal([]int64{headerOne.BlockNumber, headerTwo.BlockNumber}))
|
||||
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{config.ContractAddresses, config.ContractAddresses}))
|
||||
Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.DripFileIlkSignature)}}))
|
||||
})
|
||||
|
||||
It("returns error if fetcher returns error", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetcherError(fakes.FakeError)
|
||||
repository := &ilk_mocks.MockDripFileIlkRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := ilk.DripFileIlkTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: &ilk_mocks.MockDripFileIlkConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -98,34 +92,16 @@ var _ = Describe("Drip file ilk transformer", func() {
|
||||
})
|
||||
|
||||
It("marks header checked if no logs returned", func() {
|
||||
mockConverter := &ilk_mocks.MockDripFileIlkConverter{}
|
||||
mockRepository := &ilk_mocks.MockDripFileIlkRepository{}
|
||||
headerID := int64(123)
|
||||
mockRepository.SetMissingHeaders([]core.Header{{Id: headerID}})
|
||||
mockFetcher := &mocks.MockLogFetcher{}
|
||||
transformer := ilk.DripFileIlkTransformer{
|
||||
Converter: mockConverter,
|
||||
Fetcher: mockFetcher,
|
||||
Repository: mockRepository,
|
||||
}
|
||||
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
mockRepository.AssertMarkHeaderCheckedCalledWith(headerID)
|
||||
repository.AssertMarkHeaderCheckedCalledWith(headerOne.Id)
|
||||
})
|
||||
|
||||
It("returns error if marking header checked returns err", func() {
|
||||
mockConverter := &ilk_mocks.MockDripFileIlkConverter{}
|
||||
mockRepository := &ilk_mocks.MockDripFileIlkRepository{}
|
||||
mockRepository.SetMissingHeaders([]core.Header{{Id: int64(123)}})
|
||||
mockRepository.SetMarkHeaderCheckedErr(fakes.FakeError)
|
||||
mockFetcher := &mocks.MockLogFetcher{}
|
||||
transformer := ilk.DripFileIlkTransformer{
|
||||
Converter: mockConverter,
|
||||
Fetcher: mockFetcher,
|
||||
Repository: mockRepository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetMarkHeaderCheckedError(fakes.FakeError)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -134,16 +110,8 @@ var _ = Describe("Drip file ilk transformer", func() {
|
||||
})
|
||||
|
||||
It("converts matching logs", func() {
|
||||
converter := &ilk_mocks.MockDripFileIlkConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripFileIlkLog})
|
||||
repository := &ilk_mocks.MockDripFileIlkRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := ilk.DripFileIlkTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -152,17 +120,9 @@ var _ = Describe("Drip file ilk transformer", func() {
|
||||
})
|
||||
|
||||
It("returns error if converter returns error", func() {
|
||||
converter := &ilk_mocks.MockDripFileIlkConverter{}
|
||||
converter.SetConverterError(fakes.FakeError)
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripFileIlkLog})
|
||||
repository := &ilk_mocks.MockDripFileIlkRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := ilk.DripFileIlkTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -171,37 +131,20 @@ var _ = Describe("Drip file ilk transformer", func() {
|
||||
})
|
||||
|
||||
It("persists drip file model", func() {
|
||||
converter := &ilk_mocks.MockDripFileIlkConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripFileIlkLog})
|
||||
repository := &ilk_mocks.MockDripFileIlkRepository{}
|
||||
fakeHeader := core.Header{BlockNumber: 1, Id: 2}
|
||||
repository.SetMissingHeaders([]core.Header{fakeHeader})
|
||||
transformer := ilk.DripFileIlkTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]ilk.DripFileIlkModel{test_data.DripFileIlkModel}))
|
||||
Expect(repository.PassedHeaderID).To(Equal(headerOne.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]interface{}{test_data.DripFileIlkModel}))
|
||||
})
|
||||
|
||||
It("returns error if repository returns error for create", func() {
|
||||
converter := &ilk_mocks.MockDripFileIlkConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripFileIlkLog})
|
||||
repository := &ilk_mocks.MockDripFileIlkRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetCreateError(fakes.FakeError)
|
||||
transformer := ilk.DripFileIlkTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
|
@ -44,6 +44,6 @@ var _ = Describe("Drip file repo converter", func() {
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(models)).To(Equal(1))
|
||||
Expect(models[0]).To(Equal(test_data.DripFileRepoModel))
|
||||
Expect(models[0].(repo.DripFileRepoModel)).To(Equal(test_data.DripFileRepoModel))
|
||||
})
|
||||
})
|
||||
|
@ -33,7 +33,7 @@ import (
|
||||
var _ = Describe("Drip file repo repository", func() {
|
||||
var (
|
||||
db *postgres.DB
|
||||
dripFileRepoRepository repo.Repository
|
||||
dripFileRepoRepository repo.DripFileRepoRepository
|
||||
err error
|
||||
headerRepository datastore.HeaderRepository
|
||||
)
|
||||
@ -42,7 +42,7 @@ var _ = Describe("Drip file repo repository", func() {
|
||||
db = test_config.NewTestDB(core.Node{})
|
||||
test_config.CleanTestDB(db)
|
||||
headerRepository = repositories.NewHeaderRepository(db)
|
||||
dripFileRepoRepository = repo.NewDripFileRepoRepository(db)
|
||||
dripFileRepoRepository = repo.DripFileRepoRepository{DB: db}
|
||||
})
|
||||
|
||||
Describe("Create", func() {
|
||||
@ -52,7 +52,7 @@ var _ = Describe("Drip file repo repository", func() {
|
||||
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = dripFileRepoRepository.Create(headerID, []repo.DripFileRepoModel{test_data.DripFileRepoModel})
|
||||
err = dripFileRepoRepository.Create(headerID, []interface{}{test_data.DripFileRepoModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
@ -75,7 +75,7 @@ var _ = Describe("Drip file repo repository", func() {
|
||||
})
|
||||
|
||||
It("does not duplicate drip file events", func() {
|
||||
err = dripFileRepoRepository.Create(headerID, []repo.DripFileRepoModel{test_data.DripFileRepoModel})
|
||||
err = dripFileRepoRepository.Create(headerID, []interface{}{test_data.DripFileRepoModel})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
|
||||
@ -176,7 +176,7 @@ var _ = Describe("Drip file repo repository", func() {
|
||||
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
dripFileRepoRepositoryTwo := repo.NewDripFileRepoRepository(dbTwo)
|
||||
dripFileRepoRepositoryTwo := repo.DripFileRepoRepository{DB: dbTwo}
|
||||
err := dripFileRepoRepository.MarkHeaderChecked(headerIDs[0])
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
@ -189,4 +189,14 @@ var _ = Describe("Drip file repo repository", func() {
|
||||
Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers)))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("SetDB", func() {
|
||||
It("sets the repository db", func() {
|
||||
db := test_config.NewTestDB(core.Node{})
|
||||
repository := repo.DripFileRepoRepository{}
|
||||
Expect(repository.DB).To(BeNil())
|
||||
repository.SetDB(db)
|
||||
Expect(repository.DB).To(Equal(db))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -19,10 +19,10 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/repo"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
@ -31,31 +31,40 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("Drip file repo transformer", func() {
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
repository := &repo_mocks.MockDripFileRepoRepository{}
|
||||
transformer := repo.DripFileRepoTransformer{
|
||||
Config: drip_file.DripFileConfig,
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &repo_mocks.MockDripFileRepoConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
var (
|
||||
config = repo.DripFileRepoConfig
|
||||
fetcher mocks.MockLogFetcher
|
||||
converter repo_mocks.MockDripFileRepoConverter
|
||||
repository repo_mocks.MockDripFileRepoRepository
|
||||
transformer shared.Transformer
|
||||
headerOne core.Header
|
||||
headerTwo core.Header
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
fetcher = mocks.MockLogFetcher{}
|
||||
converter = repo_mocks.MockDripFileRepoConverter{}
|
||||
repository = repo_mocks.MockDripFileRepoRepository{}
|
||||
transformer = factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}
|
||||
headerOne = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()}
|
||||
headerTwo = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()}
|
||||
})
|
||||
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.PassedStartingBlockNumber).To(Equal(drip_file.DripFileConfig.StartingBlockNumber))
|
||||
Expect(repository.PassedEndingBlockNumber).To(Equal(drip_file.DripFileConfig.EndingBlockNumber))
|
||||
Expect(repository.PassedStartingBlockNumber).To(Equal(config.StartingBlockNumber))
|
||||
Expect(repository.PassedEndingBlockNumber).To(Equal(config.EndingBlockNumber))
|
||||
})
|
||||
|
||||
It("returns error if repository returns error for missing headers", func() {
|
||||
repository := &repo_mocks.MockDripFileRepoRepository{}
|
||||
repository.SetMissingHeadersErr(fakes.FakeError)
|
||||
transformer := repo.DripFileRepoTransformer{
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &repo_mocks.MockDripFileRepoConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
repository.SetMissingHeadersError(fakes.FakeError)
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
@ -63,33 +72,18 @@ var _ = Describe("Drip file repo transformer", func() {
|
||||
})
|
||||
|
||||
It("fetches logs for missing headers", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
repository := &repo_mocks.MockDripFileRepoRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}, {BlockNumber: 2}})
|
||||
transformer := repo.DripFileRepoTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: &repo_mocks.MockDripFileRepoConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2}))
|
||||
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{drip_file.DripFileConfig.ContractAddresses, drip_file.DripFileConfig.ContractAddresses}))
|
||||
Expect(fetcher.FetchedBlocks).To(Equal([]int64{headerOne.BlockNumber, headerTwo.BlockNumber}))
|
||||
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{config.ContractAddresses, config.ContractAddresses}))
|
||||
Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.DripFileRepoSignature)}}))
|
||||
})
|
||||
|
||||
It("returns error if fetcher returns error", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetcherError(fakes.FakeError)
|
||||
repository := &repo_mocks.MockDripFileRepoRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := repo.DripFileRepoTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: &repo_mocks.MockDripFileRepoConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -98,34 +92,16 @@ var _ = Describe("Drip file repo transformer", func() {
|
||||
})
|
||||
|
||||
It("marks header checked if no logs returned", func() {
|
||||
mockConverter := &repo_mocks.MockDripFileRepoConverter{}
|
||||
mockRepository := &repo_mocks.MockDripFileRepoRepository{}
|
||||
headerID := int64(123)
|
||||
mockRepository.SetMissingHeaders([]core.Header{{Id: headerID}})
|
||||
mockFetcher := &mocks.MockLogFetcher{}
|
||||
transformer := repo.DripFileRepoTransformer{
|
||||
Converter: mockConverter,
|
||||
Fetcher: mockFetcher,
|
||||
Repository: mockRepository,
|
||||
}
|
||||
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
mockRepository.AssertMarkHeaderCheckedCalledWith(headerID)
|
||||
repository.AssertMarkHeaderCheckedCalledWith(headerOne.Id)
|
||||
})
|
||||
|
||||
It("returns error if marking header checked returns err", func() {
|
||||
mockConverter := &repo_mocks.MockDripFileRepoConverter{}
|
||||
mockRepository := &repo_mocks.MockDripFileRepoRepository{}
|
||||
mockRepository.SetMissingHeaders([]core.Header{{Id: int64(123)}})
|
||||
mockRepository.SetMarkHeaderCheckedErr(fakes.FakeError)
|
||||
mockFetcher := &mocks.MockLogFetcher{}
|
||||
transformer := repo.DripFileRepoTransformer{
|
||||
Converter: mockConverter,
|
||||
Fetcher: mockFetcher,
|
||||
Repository: mockRepository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetMarkHeaderCheckedError(fakes.FakeError)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -134,16 +110,8 @@ var _ = Describe("Drip file repo transformer", func() {
|
||||
})
|
||||
|
||||
It("converts matching logs", func() {
|
||||
converter := &repo_mocks.MockDripFileRepoConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripFileRepoLog})
|
||||
repository := &repo_mocks.MockDripFileRepoRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := repo.DripFileRepoTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -152,17 +120,9 @@ var _ = Describe("Drip file repo transformer", func() {
|
||||
})
|
||||
|
||||
It("returns error if converter returns error", func() {
|
||||
converter := &repo_mocks.MockDripFileRepoConverter{}
|
||||
converter.SetConverterError(fakes.FakeError)
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripFileRepoLog})
|
||||
repository := &repo_mocks.MockDripFileRepoRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := repo.DripFileRepoTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -171,37 +131,20 @@ var _ = Describe("Drip file repo transformer", func() {
|
||||
})
|
||||
|
||||
It("persists drip file model", func() {
|
||||
converter := &repo_mocks.MockDripFileRepoConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripFileRepoLog})
|
||||
repository := &repo_mocks.MockDripFileRepoRepository{}
|
||||
fakeHeader := core.Header{BlockNumber: 1, Id: 2}
|
||||
repository.SetMissingHeaders([]core.Header{fakeHeader})
|
||||
transformer := repo.DripFileRepoTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]repo.DripFileRepoModel{test_data.DripFileRepoModel}))
|
||||
Expect(repository.PassedHeaderID).To(Equal(headerOne.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]interface{}{test_data.DripFileRepoModel}))
|
||||
})
|
||||
|
||||
It("returns error if repository returns error for create", func() {
|
||||
converter := &repo_mocks.MockDripFileRepoConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripFileRepoLog})
|
||||
repository := &repo_mocks.MockDripFileRepoRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetCreateError(fakes.FakeError)
|
||||
transformer := repo.DripFileRepoTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
|
@ -44,6 +44,6 @@ var _ = Describe("Drip file repo converter", func() {
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(models)).To(Equal(1))
|
||||
Expect(models[0]).To(Equal(test_data.DripFileVowModel))
|
||||
Expect(models[0].(vow.DripFileVowModel)).To(Equal(test_data.DripFileVowModel))
|
||||
})
|
||||
})
|
||||
|
@ -33,7 +33,7 @@ import (
|
||||
var _ = Describe("Drip file vow repository", func() {
|
||||
var (
|
||||
db *postgres.DB
|
||||
dripFileVowRepository vow.Repository
|
||||
dripFileVowRepository vow.DripFileVowRepository
|
||||
err error
|
||||
headerRepository datastore.HeaderRepository
|
||||
)
|
||||
@ -42,7 +42,7 @@ var _ = Describe("Drip file vow repository", func() {
|
||||
db = test_config.NewTestDB(core.Node{})
|
||||
test_config.CleanTestDB(db)
|
||||
headerRepository = repositories.NewHeaderRepository(db)
|
||||
dripFileVowRepository = vow.NewDripFileVowRepository(db)
|
||||
dripFileVowRepository = vow.DripFileVowRepository{DB: db}
|
||||
})
|
||||
|
||||
Describe("Create", func() {
|
||||
@ -52,7 +52,7 @@ var _ = Describe("Drip file vow repository", func() {
|
||||
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = dripFileVowRepository.Create(headerID, []vow.DripFileVowModel{test_data.DripFileVowModel})
|
||||
err = dripFileVowRepository.Create(headerID, []interface{}{test_data.DripFileVowModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
@ -75,7 +75,7 @@ var _ = Describe("Drip file vow repository", func() {
|
||||
})
|
||||
|
||||
It("does not duplicate drip file events", func() {
|
||||
err = dripFileVowRepository.Create(headerID, []vow.DripFileVowModel{test_data.DripFileVowModel})
|
||||
err = dripFileVowRepository.Create(headerID, []interface{}{test_data.DripFileVowModel})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
|
||||
@ -176,7 +176,7 @@ var _ = Describe("Drip file vow repository", func() {
|
||||
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
dripFileVowRepositoryTwo := vow.NewDripFileVowRepository(dbTwo)
|
||||
dripFileVowRepositoryTwo := vow.DripFileVowRepository{DB: dbTwo}
|
||||
err := dripFileVowRepository.MarkHeaderChecked(headerIDs[0])
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
@ -189,4 +189,14 @@ var _ = Describe("Drip file vow repository", func() {
|
||||
Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers)))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("SetDB", func() {
|
||||
It("sets the repository db", func() {
|
||||
db := test_config.NewTestDB(core.Node{})
|
||||
repository := vow.DripFileVowRepository{}
|
||||
Expect(repository.DB).To(BeNil())
|
||||
repository.SetDB(db)
|
||||
Expect(repository.DB).To(Equal(db))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -19,10 +19,10 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/vow"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
@ -31,31 +31,40 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("Drip file vow transformer", func() {
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
repository := &vow_mocks.MockDripFileVowRepository{}
|
||||
transformer := vow.DripFileVowTransformer{
|
||||
Config: drip_file.DripFileConfig,
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &vow_mocks.MockDripFileVowConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
var (
|
||||
config = vow.DripFileVowConfig
|
||||
fetcher mocks.MockLogFetcher
|
||||
converter vow_mocks.MockDripFileVowConverter
|
||||
repository vow_mocks.MockDripFileVowRepository
|
||||
transformer shared.Transformer
|
||||
headerOne core.Header
|
||||
headerTwo core.Header
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
fetcher = mocks.MockLogFetcher{}
|
||||
converter = vow_mocks.MockDripFileVowConverter{}
|
||||
repository = vow_mocks.MockDripFileVowRepository{}
|
||||
transformer = factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}
|
||||
headerOne = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()}
|
||||
headerTwo = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()}
|
||||
})
|
||||
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.PassedStartingBlockNumber).To(Equal(drip_file.DripFileConfig.StartingBlockNumber))
|
||||
Expect(repository.PassedEndingBlockNumber).To(Equal(drip_file.DripFileConfig.EndingBlockNumber))
|
||||
Expect(repository.PassedStartingBlockNumber).To(Equal(config.StartingBlockNumber))
|
||||
Expect(repository.PassedEndingBlockNumber).To(Equal(config.EndingBlockNumber))
|
||||
})
|
||||
|
||||
It("returns error if repository returns error for missing headers", func() {
|
||||
repository := &vow_mocks.MockDripFileVowRepository{}
|
||||
repository.SetMissingHeadersErr(fakes.FakeError)
|
||||
transformer := vow.DripFileVowTransformer{
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &vow_mocks.MockDripFileVowConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
repository.SetMissingHeadersError(fakes.FakeError)
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
@ -63,33 +72,18 @@ var _ = Describe("Drip file vow transformer", func() {
|
||||
})
|
||||
|
||||
It("fetches logs for missing headers", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
repository := &vow_mocks.MockDripFileVowRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}, {BlockNumber: 2}})
|
||||
transformer := vow.DripFileVowTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: &vow_mocks.MockDripFileVowConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2}))
|
||||
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{drip_file.DripFileConfig.ContractAddresses, drip_file.DripFileConfig.ContractAddresses}))
|
||||
Expect(fetcher.FetchedBlocks).To(Equal([]int64{headerOne.BlockNumber, headerTwo.BlockNumber}))
|
||||
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{config.ContractAddresses, config.ContractAddresses}))
|
||||
Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.DripFileVowSignature)}}))
|
||||
})
|
||||
|
||||
It("returns error if fetcher returns error", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetcherError(fakes.FakeError)
|
||||
repository := &vow_mocks.MockDripFileVowRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := vow.DripFileVowTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: &vow_mocks.MockDripFileVowConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -98,34 +92,16 @@ var _ = Describe("Drip file vow transformer", func() {
|
||||
})
|
||||
|
||||
It("marks header checked if no logs returned", func() {
|
||||
mockConverter := &vow_mocks.MockDripFileVowConverter{}
|
||||
mockRepository := &vow_mocks.MockDripFileVowRepository{}
|
||||
headerID := int64(123)
|
||||
mockRepository.SetMissingHeaders([]core.Header{{Id: headerID}})
|
||||
mockFetcher := &mocks.MockLogFetcher{}
|
||||
transformer := vow.DripFileVowTransformer{
|
||||
Converter: mockConverter,
|
||||
Fetcher: mockFetcher,
|
||||
Repository: mockRepository,
|
||||
}
|
||||
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
mockRepository.AssertMarkHeaderCheckedCalledWith(headerID)
|
||||
repository.AssertMarkHeaderCheckedCalledWith(headerOne.Id)
|
||||
})
|
||||
|
||||
It("returns error if marking header checked returns err", func() {
|
||||
mockConverter := &vow_mocks.MockDripFileVowConverter{}
|
||||
mockRepository := &vow_mocks.MockDripFileVowRepository{}
|
||||
mockRepository.SetMissingHeaders([]core.Header{{Id: int64(123)}})
|
||||
mockRepository.SetMarkHeaderCheckedErr(fakes.FakeError)
|
||||
mockFetcher := &mocks.MockLogFetcher{}
|
||||
transformer := vow.DripFileVowTransformer{
|
||||
Converter: mockConverter,
|
||||
Fetcher: mockFetcher,
|
||||
Repository: mockRepository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetMarkHeaderCheckedError(fakes.FakeError)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -134,16 +110,8 @@ var _ = Describe("Drip file vow transformer", func() {
|
||||
})
|
||||
|
||||
It("converts matching logs", func() {
|
||||
converter := &vow_mocks.MockDripFileVowConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripFileVowLog})
|
||||
repository := &vow_mocks.MockDripFileVowRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := vow.DripFileVowTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -152,17 +120,9 @@ var _ = Describe("Drip file vow transformer", func() {
|
||||
})
|
||||
|
||||
It("returns error if converter returns error", func() {
|
||||
converter := &vow_mocks.MockDripFileVowConverter{}
|
||||
converter.SetConverterError(fakes.FakeError)
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripFileVowLog})
|
||||
repository := &vow_mocks.MockDripFileVowRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := vow.DripFileVowTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -171,37 +131,20 @@ var _ = Describe("Drip file vow transformer", func() {
|
||||
})
|
||||
|
||||
It("persists drip file model", func() {
|
||||
converter := &vow_mocks.MockDripFileVowConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripFileVowLog})
|
||||
repository := &vow_mocks.MockDripFileVowRepository{}
|
||||
fakeHeader := core.Header{BlockNumber: 1, Id: 2}
|
||||
repository.SetMissingHeaders([]core.Header{fakeHeader})
|
||||
transformer := vow.DripFileVowTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]vow.DripFileVowModel{test_data.DripFileVowModel}))
|
||||
Expect(repository.PassedHeaderID).To(Equal(headerOne.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]interface{}{test_data.DripFileVowModel}))
|
||||
})
|
||||
|
||||
It("returns error if repository returns error for create", func() {
|
||||
converter := &vow_mocks.MockDripFileVowConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripFileVowLog})
|
||||
repository := &vow_mocks.MockDripFileVowRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetCreateError(fakes.FakeError)
|
||||
transformer := vow.DripFileVowTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
|
@ -16,20 +16,19 @@ package ilk
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/ilk"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
)
|
||||
|
||||
type MockDripFileIlkConverter struct {
|
||||
converterErr error
|
||||
PassedLogs []types.Log
|
||||
converterError error
|
||||
PassedLogs []types.Log
|
||||
}
|
||||
|
||||
func (converter *MockDripFileIlkConverter) ToModels(ethLogs []types.Log) ([]ilk.DripFileIlkModel, error) {
|
||||
func (converter *MockDripFileIlkConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
|
||||
converter.PassedLogs = ethLogs
|
||||
return []ilk.DripFileIlkModel{test_data.DripFileIlkModel}, converter.converterErr
|
||||
return []interface{}{test_data.DripFileIlkModel}, converter.converterError
|
||||
}
|
||||
|
||||
func (converter *MockDripFileIlkConverter) SetConverterError(e error) {
|
||||
converter.converterErr = e
|
||||
converter.converterError = e
|
||||
}
|
||||
|
@ -16,46 +16,46 @@ package ilk
|
||||
|
||||
import (
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/ilk"
|
||||
)
|
||||
|
||||
type MockDripFileIlkRepository struct {
|
||||
createErr error
|
||||
markHeaderCheckedErr error
|
||||
createError error
|
||||
markHeaderCheckedError error
|
||||
markHeaderCheckedPassedHeaderID int64
|
||||
missingHeaders []core.Header
|
||||
missingHeadersErr error
|
||||
missingHeadersError error
|
||||
PassedStartingBlockNumber int64
|
||||
PassedEndingBlockNumber int64
|
||||
PassedHeaderID int64
|
||||
PassedModels []ilk.DripFileIlkModel
|
||||
PassedModels []interface{}
|
||||
}
|
||||
|
||||
func (repository *MockDripFileIlkRepository) Create(headerID int64, models []ilk.DripFileIlkModel) error {
|
||||
func (repository *MockDripFileIlkRepository) Create(headerID int64, models []interface{}) error {
|
||||
repository.PassedHeaderID = headerID
|
||||
repository.PassedModels = models
|
||||
return repository.createErr
|
||||
return repository.createError
|
||||
}
|
||||
|
||||
func (repository *MockDripFileIlkRepository) MarkHeaderChecked(headerID int64) error {
|
||||
repository.markHeaderCheckedPassedHeaderID = headerID
|
||||
return repository.markHeaderCheckedErr
|
||||
return repository.markHeaderCheckedError
|
||||
}
|
||||
|
||||
func (repository *MockDripFileIlkRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||
repository.PassedStartingBlockNumber = startingBlockNumber
|
||||
repository.PassedEndingBlockNumber = endingBlockNumber
|
||||
return repository.missingHeaders, repository.missingHeadersErr
|
||||
return repository.missingHeaders, repository.missingHeadersError
|
||||
}
|
||||
|
||||
func (repository *MockDripFileIlkRepository) SetMarkHeaderCheckedErr(e error) {
|
||||
repository.markHeaderCheckedErr = e
|
||||
func (repository *MockDripFileIlkRepository) SetMarkHeaderCheckedError(e error) {
|
||||
repository.markHeaderCheckedError = e
|
||||
}
|
||||
|
||||
func (repository *MockDripFileIlkRepository) SetMissingHeadersErr(e error) {
|
||||
repository.missingHeadersErr = e
|
||||
func (repository *MockDripFileIlkRepository) SetMissingHeadersError(e error) {
|
||||
repository.missingHeadersError = e
|
||||
}
|
||||
|
||||
func (repository *MockDripFileIlkRepository) SetMissingHeaders(headers []core.Header) {
|
||||
@ -63,8 +63,10 @@ func (repository *MockDripFileIlkRepository) SetMissingHeaders(headers []core.He
|
||||
}
|
||||
|
||||
func (repository *MockDripFileIlkRepository) SetCreateError(e error) {
|
||||
repository.createErr = e
|
||||
repository.createError = e
|
||||
}
|
||||
func (repository *MockDripFileIlkRepository) AssertMarkHeaderCheckedCalledWith(i int64) {
|
||||
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
||||
}
|
||||
|
||||
func (repository *MockDripFileIlkRepository) SetDB(db *postgres.DB) {}
|
||||
|
@ -16,20 +16,19 @@ package repo
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/repo"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
)
|
||||
|
||||
type MockDripFileRepoConverter struct {
|
||||
converterErr error
|
||||
PassedLogs []types.Log
|
||||
converterError error
|
||||
PassedLogs []types.Log
|
||||
}
|
||||
|
||||
func (converter *MockDripFileRepoConverter) ToModels(ethLogs []types.Log) ([]repo.DripFileRepoModel, error) {
|
||||
func (converter *MockDripFileRepoConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
|
||||
converter.PassedLogs = ethLogs
|
||||
return []repo.DripFileRepoModel{test_data.DripFileRepoModel}, converter.converterErr
|
||||
return []interface{}{test_data.DripFileRepoModel}, converter.converterError
|
||||
}
|
||||
|
||||
func (converter *MockDripFileRepoConverter) SetConverterError(e error) {
|
||||
converter.converterErr = e
|
||||
converter.converterError = e
|
||||
}
|
||||
|
@ -16,46 +16,46 @@ package repo
|
||||
|
||||
import (
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/repo"
|
||||
)
|
||||
|
||||
type MockDripFileRepoRepository struct {
|
||||
createErr error
|
||||
markHeaderCheckedErr error
|
||||
createError error
|
||||
markHeaderCheckedError error
|
||||
markHeaderCheckedPassedHeaderID int64
|
||||
missingHeaders []core.Header
|
||||
missingHeadersErr error
|
||||
missingHeadersError error
|
||||
PassedStartingBlockNumber int64
|
||||
PassedEndingBlockNumber int64
|
||||
PassedHeaderID int64
|
||||
PassedModels []repo.DripFileRepoModel
|
||||
PassedModels []interface{}
|
||||
}
|
||||
|
||||
func (repository *MockDripFileRepoRepository) Create(headerID int64, models []repo.DripFileRepoModel) error {
|
||||
func (repository *MockDripFileRepoRepository) Create(headerID int64, models []interface{}) error {
|
||||
repository.PassedHeaderID = headerID
|
||||
repository.PassedModels = models
|
||||
return repository.createErr
|
||||
return repository.createError
|
||||
}
|
||||
|
||||
func (repository *MockDripFileRepoRepository) MarkHeaderChecked(headerID int64) error {
|
||||
repository.markHeaderCheckedPassedHeaderID = headerID
|
||||
return repository.markHeaderCheckedErr
|
||||
return repository.markHeaderCheckedError
|
||||
}
|
||||
|
||||
func (repository *MockDripFileRepoRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||
repository.PassedStartingBlockNumber = startingBlockNumber
|
||||
repository.PassedEndingBlockNumber = endingBlockNumber
|
||||
return repository.missingHeaders, repository.missingHeadersErr
|
||||
return repository.missingHeaders, repository.missingHeadersError
|
||||
}
|
||||
|
||||
func (repository *MockDripFileRepoRepository) SetMarkHeaderCheckedErr(e error) {
|
||||
repository.markHeaderCheckedErr = e
|
||||
func (repository *MockDripFileRepoRepository) SetMarkHeaderCheckedError(e error) {
|
||||
repository.markHeaderCheckedError = e
|
||||
}
|
||||
|
||||
func (repository *MockDripFileRepoRepository) SetMissingHeadersErr(e error) {
|
||||
repository.missingHeadersErr = e
|
||||
func (repository *MockDripFileRepoRepository) SetMissingHeadersError(e error) {
|
||||
repository.missingHeadersError = e
|
||||
}
|
||||
|
||||
func (repository *MockDripFileRepoRepository) SetMissingHeaders(headers []core.Header) {
|
||||
@ -63,8 +63,11 @@ func (repository *MockDripFileRepoRepository) SetMissingHeaders(headers []core.H
|
||||
}
|
||||
|
||||
func (repository *MockDripFileRepoRepository) SetCreateError(e error) {
|
||||
repository.createErr = e
|
||||
repository.createError = e
|
||||
}
|
||||
|
||||
func (repository *MockDripFileRepoRepository) AssertMarkHeaderCheckedCalledWith(i int64) {
|
||||
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
||||
}
|
||||
|
||||
func (repository *MockDripFileRepoRepository) SetDB(db *postgres.DB) {}
|
||||
|
@ -16,7 +16,6 @@ package vow
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/vow"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
)
|
||||
|
||||
@ -25,9 +24,9 @@ type MockDripFileVowConverter struct {
|
||||
PassedLogs []types.Log
|
||||
}
|
||||
|
||||
func (converter *MockDripFileVowConverter) ToModels(ethLogs []types.Log) ([]vow.DripFileVowModel, error) {
|
||||
func (converter *MockDripFileVowConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
|
||||
converter.PassedLogs = ethLogs
|
||||
return []vow.DripFileVowModel{test_data.DripFileVowModel}, converter.converterErr
|
||||
return []interface{}{test_data.DripFileVowModel}, converter.converterErr
|
||||
}
|
||||
|
||||
func (converter *MockDripFileVowConverter) SetConverterError(e error) {
|
||||
|
@ -16,46 +16,46 @@ package vow
|
||||
|
||||
import (
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/vow"
|
||||
)
|
||||
|
||||
type MockDripFileVowRepository struct {
|
||||
createErr error
|
||||
markHeaderCheckedErr error
|
||||
createError error
|
||||
markHeaderCheckedError error
|
||||
markHeaderCheckedPassedHeaderID int64
|
||||
missingHeaders []core.Header
|
||||
missingHeadersErr error
|
||||
missingHeadersError error
|
||||
PassedStartingBlockNumber int64
|
||||
PassedEndingBlockNumber int64
|
||||
PassedHeaderID int64
|
||||
PassedModels []vow.DripFileVowModel
|
||||
PassedModels []interface{}
|
||||
}
|
||||
|
||||
func (repository *MockDripFileVowRepository) Create(headerID int64, models []vow.DripFileVowModel) error {
|
||||
func (repository *MockDripFileVowRepository) Create(headerID int64, models []interface{}) error {
|
||||
repository.PassedHeaderID = headerID
|
||||
repository.PassedModels = models
|
||||
return repository.createErr
|
||||
return repository.createError
|
||||
}
|
||||
|
||||
func (repository *MockDripFileVowRepository) MarkHeaderChecked(headerID int64) error {
|
||||
repository.markHeaderCheckedPassedHeaderID = headerID
|
||||
return repository.markHeaderCheckedErr
|
||||
return repository.markHeaderCheckedError
|
||||
}
|
||||
|
||||
func (repository *MockDripFileVowRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||
repository.PassedStartingBlockNumber = startingBlockNumber
|
||||
repository.PassedEndingBlockNumber = endingBlockNumber
|
||||
return repository.missingHeaders, repository.missingHeadersErr
|
||||
return repository.missingHeaders, repository.missingHeadersError
|
||||
}
|
||||
|
||||
func (repository *MockDripFileVowRepository) SetMarkHeaderCheckedErr(e error) {
|
||||
repository.markHeaderCheckedErr = e
|
||||
func (repository *MockDripFileVowRepository) SetMarkHeaderCheckedError(e error) {
|
||||
repository.markHeaderCheckedError = e
|
||||
}
|
||||
|
||||
func (repository *MockDripFileVowRepository) SetMissingHeadersErr(e error) {
|
||||
repository.missingHeadersErr = e
|
||||
func (repository *MockDripFileVowRepository) SetMissingHeadersError(e error) {
|
||||
repository.missingHeadersError = e
|
||||
}
|
||||
|
||||
func (repository *MockDripFileVowRepository) SetMissingHeaders(headers []core.Header) {
|
||||
@ -63,8 +63,10 @@ func (repository *MockDripFileVowRepository) SetMissingHeaders(headers []core.He
|
||||
}
|
||||
|
||||
func (repository *MockDripFileVowRepository) SetCreateError(e error) {
|
||||
repository.createErr = e
|
||||
repository.createError = e
|
||||
}
|
||||
func (repository *MockDripFileVowRepository) AssertMarkHeaderCheckedCalledWith(i int64) {
|
||||
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
||||
}
|
||||
|
||||
func (repository *MockDripFileVowRepository) SetDB(db *postgres.DB) {}
|
||||
|
@ -70,4 +70,4 @@ func (repository *MockPitFileIlkRepository) AssertMarkHeaderCheckedCalledWith(i
|
||||
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
||||
}
|
||||
|
||||
func (repository *MockPitFileIlkRepository) SetDB(db *postgres.DB) {}
|
||||
func (repository *MockPitFileIlkRepository) SetDB(db *postgres.DB) {}
|
||||
|
Loading…
Reference in New Issue
Block a user