Update cat file transformer tests

This commit is contained in:
Edvard 2018-10-25 17:27:14 +02:00 committed by Rob Mulholand
parent 28ab5f92ab
commit e6e2ed3308
13 changed files with 239 additions and 341 deletions

View File

@ -15,6 +15,8 @@
package chop_lump_test package chop_lump_test
import ( import (
"io/ioutil"
"log"
"testing" "testing"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
@ -25,3 +27,7 @@ func TestChopLump(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "ChopLump Suite") RunSpecs(t, "ChopLump Suite")
} }
var _ = BeforeSuite(func() {
log.SetOutput(ioutil.Discard)
})

View File

@ -25,34 +25,34 @@ import (
) )
var _ = Describe("Cat file chop lump converter", func() { var _ = Describe("Cat file chop lump converter", func() {
var converter chop_lump.CatFileChopLumpConverter
BeforeEach(func() {
converter = chop_lump.CatFileChopLumpConverter{}
})
It("returns err if log is missing topics", func() { It("returns err if log is missing topics", func() {
converter := chop_lump.CatFileChopLumpConverter{}
badLog := types.Log{ badLog := types.Log{
Data: []byte{1, 1, 1, 1, 1}, Data: []byte{1, 1, 1, 1, 1},
} }
_, err := converter.ToModels([]types.Log{badLog}) _, err := converter.ToModels([]types.Log{badLog})
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
}) })
It("returns err if log is missing data", func() { It("returns err if log is missing data", func() {
converter := chop_lump.CatFileChopLumpConverter{}
badLog := types.Log{ badLog := types.Log{
Topics: []common.Hash{{}, {}, {}, {}}, Topics: []common.Hash{{}, {}, {}, {}},
} }
_, err := converter.ToModels([]types.Log{badLog}) _, err := converter.ToModels([]types.Log{badLog})
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
}) })
It("converts a log to an model", func() { It("converts a log to an model", func() {
converter := chop_lump.CatFileChopLumpConverter{} models, err := converter.ToModels([]types.Log{test_data.EthCatFileChopLumpLog})
model, err := converter.ToModels([]types.Log{test_data.EthCatFileChopLumpLog})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(model).To(Equal([]chop_lump.CatFileChopLumpModel{test_data.CatFileChopLumpModel})) Expect(models).To(Equal([]interface{}{test_data.CatFileChopLumpModel}))
}) })
}) })

View File

@ -42,7 +42,8 @@ var _ = Describe("Cat file chop lump repository", func() {
db = test_config.NewTestDB(test_config.NewTestNode()) db = test_config.NewTestDB(test_config.NewTestNode())
test_config.CleanTestDB(db) test_config.CleanTestDB(db)
headerRepository = repositories.NewHeaderRepository(db) headerRepository = repositories.NewHeaderRepository(db)
catFileRepository = chop_lump.NewCatFileChopLumpRepository(db) catFileRepository = chop_lump.CatFileChopLumpRepository{}
catFileRepository.SetDB(db)
}) })
Describe("Create", func() { Describe("Create", func() {
@ -52,7 +53,7 @@ var _ = Describe("Cat file chop lump repository", func() {
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
err = catFileRepository.Create(headerID, []chop_lump.CatFileChopLumpModel{test_data.CatFileChopLumpModel}) err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileChopLumpModel})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
@ -76,7 +77,7 @@ var _ = Describe("Cat file chop lump repository", func() {
}) })
It("does not duplicate cat file chop lump events", func() { It("does not duplicate cat file chop lump events", func() {
err = catFileRepository.Create(headerID, []chop_lump.CatFileChopLumpModel{test_data.CatFileChopLumpModel}) err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileChopLumpModel})
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint")) Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
@ -85,7 +86,7 @@ var _ = Describe("Cat file chop lump repository", func() {
It("allows for multiple cat file chop lump events in one transaction if they have different log indexes", func() { It("allows for multiple cat file chop lump events in one transaction if they have different log indexes", func() {
newCatFileChopLump := test_data.CatFileChopLumpModel newCatFileChopLump := test_data.CatFileChopLumpModel
newCatFileChopLump.LogIndex = newCatFileChopLump.LogIndex + 1 newCatFileChopLump.LogIndex = newCatFileChopLump.LogIndex + 1
err = catFileRepository.Create(headerID, []chop_lump.CatFileChopLumpModel{newCatFileChopLump}) err = catFileRepository.Create(headerID, []interface{}{newCatFileChopLump})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
@ -187,7 +188,8 @@ var _ = Describe("Cat file chop lump repository", func() {
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n)) _, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
} }
catFileRepositoryTwo := chop_lump.NewCatFileChopLumpRepository(dbTwo) catFileRepositoryTwo := chop_lump.CatFileChopLumpRepository{}
catFileRepositoryTwo.SetDB(dbTwo)
nodeOneMissingHeaders, err := catFileRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) nodeOneMissingHeaders, err := catFileRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1])
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())

View File

@ -19,42 +19,57 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
"math/rand"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file"
"github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/chop_lump" "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/chop_lump"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks"
chop_lump_mocks "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks/cat_file/chop_lump"
) )
var _ = Describe("Cat file chop lump transformer", func() { var _ = Describe("Cat file chop lump transformer", func() {
It("gets missing headers for block numbers specified in config", func() { var (
repository := &chop_lump_mocks.MockCatFileChopLumpRepository{} config = chop_lump.CatFileChopLumpConfig
transformer := chop_lump.CatFileChopLumpTransformer{ repository mocks.MockRepository
Config: cat_file.CatFileConfig, converter mocks.MockConverter
Fetcher: &mocks.MockLogFetcher{}, fetcher mocks.MockLogFetcher
Converter: &chop_lump_mocks.MockCatFileChopLumpConverter{}, transformer shared.Transformer
Repository: repository, headerOne core.Header
} headerTwo core.Header
)
BeforeEach(func() {
repository = mocks.MockRepository{}
converter = mocks.MockConverter{}
fetcher = mocks.MockLogFetcher{}
transformer = factories.Transformer{
Config: config,
Converter: &converter,
Repository: &repository,
Fetcher: &fetcher,
}.NewTransformer(nil, nil)
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
})
It("sets the blockchain and database", func() {
Expect(fetcher.SetBcCalled).To(BeTrue())
Expect(repository.SetDbCalled).To(BeTrue())
})
It("gets missing headers for block numbers specified in config", func() {
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(repository.PassedStartingBlockNumber).To(Equal(cat_file.CatFileConfig.StartingBlockNumber)) Expect(repository.PassedStartingBlockNumber).To(Equal(config.StartingBlockNumber))
Expect(repository.PassedEndingBlockNumber).To(Equal(cat_file.CatFileConfig.EndingBlockNumber)) Expect(repository.PassedEndingBlockNumber).To(Equal(config.EndingBlockNumber))
}) })
It("returns error if repository returns error for missing headers", func() { It("returns error if repository returns error for missing headers", func() {
repository := &chop_lump_mocks.MockCatFileChopLumpRepository{} repository.SetMissingHeadersError(fakes.FakeError)
repository.SetMissingHeadersErr(fakes.FakeError)
transformer := chop_lump.CatFileChopLumpTransformer{
Fetcher: &mocks.MockLogFetcher{},
Converter: &chop_lump_mocks.MockCatFileChopLumpConverter{},
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -63,33 +78,20 @@ var _ = Describe("Cat file chop lump transformer", func() {
}) })
It("fetches logs for missing headers", func() { It("fetches logs for missing headers", func() {
fetcher := &mocks.MockLogFetcher{} repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
repository := &chop_lump_mocks.MockCatFileChopLumpRepository{}
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}, {BlockNumber: 2}})
transformer := chop_lump.CatFileChopLumpTransformer{
Fetcher: fetcher,
Converter: &chop_lump_mocks.MockCatFileChopLumpConverter{},
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) Expect(fetcher.FetchedBlocks).To(Equal([]int64{headerOne.BlockNumber, headerTwo.BlockNumber}))
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{cat_file.CatFileConfig.ContractAddresses, cat_file.CatFileConfig.ContractAddresses})) Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{
config.ContractAddresses, config.ContractAddresses}))
Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.CatFileChopLumpSignature)}})) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.CatFileChopLumpSignature)}}))
}) })
It("returns error if fetcher returns error", func() { It("returns error if fetcher returns error", func() {
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetcherError(fakes.FakeError) fetcher.SetFetcherError(fakes.FakeError)
repository := &chop_lump_mocks.MockCatFileChopLumpRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
transformer := chop_lump.CatFileChopLumpTransformer{
Fetcher: fetcher,
Converter: &chop_lump_mocks.MockCatFileChopLumpConverter{},
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -98,34 +100,17 @@ var _ = Describe("Cat file chop lump transformer", func() {
}) })
It("marks header checked if no logs returned", func() { It("marks header checked if no logs returned", func() {
mockConverter := &chop_lump_mocks.MockCatFileChopLumpConverter{} repository.SetMissingHeaders([]core.Header{headerOne})
mockRepository := &chop_lump_mocks.MockCatFileChopLumpRepository{}
headerID := int64(123)
mockRepository.SetMissingHeaders([]core.Header{{Id: headerID}})
mockFetcher := &mocks.MockLogFetcher{}
transformer := chop_lump.CatFileChopLumpTransformer{
Converter: mockConverter,
Fetcher: mockFetcher,
Repository: mockRepository,
}
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
mockRepository.AssertMarkHeaderCheckedCalledWith(headerID) repository.AssertMarkHeaderCheckedCalledWith(headerOne.Id)
}) })
It("returns error if marking header checked returns err", func() { It("returns error if marking header checked returns err", func() {
mockConverter := &chop_lump_mocks.MockCatFileChopLumpConverter{} repository.SetMissingHeaders([]core.Header{headerOne})
mockRepository := &chop_lump_mocks.MockCatFileChopLumpRepository{} repository.SetMarkHeaderCheckedError(fakes.FakeError)
mockRepository.SetMissingHeaders([]core.Header{{Id: int64(123)}})
mockRepository.SetMarkHeaderCheckedErr(fakes.FakeError)
mockFetcher := &mocks.MockLogFetcher{}
transformer := chop_lump.CatFileChopLumpTransformer{
Converter: mockConverter,
Fetcher: mockFetcher,
Repository: mockRepository,
}
err := transformer.Execute() err := transformer.Execute()
@ -134,16 +119,8 @@ var _ = Describe("Cat file chop lump transformer", func() {
}) })
It("converts matching logs", func() { It("converts matching logs", func() {
converter := &chop_lump_mocks.MockCatFileChopLumpConverter{}
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileChopLumpLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileChopLumpLog})
repository := &chop_lump_mocks.MockCatFileChopLumpRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
transformer := chop_lump.CatFileChopLumpTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -152,17 +129,9 @@ var _ = Describe("Cat file chop lump transformer", func() {
}) })
It("returns error if converter returns error", func() { It("returns error if converter returns error", func() {
converter := &chop_lump_mocks.MockCatFileChopLumpConverter{}
converter.SetConverterError(fakes.FakeError) converter.SetConverterError(fakes.FakeError)
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileChopLumpLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileChopLumpLog})
repository := &chop_lump_mocks.MockCatFileChopLumpRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
transformer := chop_lump.CatFileChopLumpTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -171,37 +140,20 @@ var _ = Describe("Cat file chop lump transformer", func() {
}) })
It("persists cat file chop lump model", func() { It("persists cat file chop lump model", func() {
converter := &chop_lump_mocks.MockCatFileChopLumpConverter{}
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileChopLumpLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileChopLumpLog})
repository := &chop_lump_mocks.MockCatFileChopLumpRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
fakeHeader := core.Header{BlockNumber: 1, Id: 2} converter.SetReturnModels([]interface{}{test_data.CatFileChopLumpModel})
repository.SetMissingHeaders([]core.Header{fakeHeader})
transformer := chop_lump.CatFileChopLumpTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id)) Expect(repository.PassedHeaderID).To(Equal(headerOne.Id))
Expect(repository.PassedModels).To(Equal([]chop_lump.CatFileChopLumpModel{test_data.CatFileChopLumpModel})) Expect(repository.PassedModels).To(Equal([]interface{}{test_data.CatFileChopLumpModel}))
}) })
It("returns error if repository returns error for create", func() { It("returns error if repository returns error for create", func() {
converter := &chop_lump_mocks.MockCatFileChopLumpConverter{}
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileChopLumpLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileChopLumpLog})
repository := &chop_lump_mocks.MockCatFileChopLumpRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}})
repository.SetCreateError(fakes.FakeError) repository.SetCreateError(fakes.FakeError)
transformer := chop_lump.CatFileChopLumpTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()

View File

@ -25,34 +25,34 @@ import (
) )
var _ = Describe("Cat file flip converter", func() { var _ = Describe("Cat file flip converter", func() {
var converter flip.CatFileFlipConverter
BeforeEach(func() {
converter = flip.CatFileFlipConverter{}
})
It("returns err if log is missing topics", func() { It("returns err if log is missing topics", func() {
converter := flip.CatFileFlipConverter{}
badLog := types.Log{ badLog := types.Log{
Data: []byte{1, 1, 1, 1, 1}, Data: []byte{1, 1, 1, 1, 1},
} }
_, err := converter.ToModels([]types.Log{badLog}) _, err := converter.ToModels([]types.Log{badLog})
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
}) })
It("returns err if log is missing data", func() { It("returns err if log is missing data", func() {
converter := flip.CatFileFlipConverter{}
badLog := types.Log{ badLog := types.Log{
Topics: []common.Hash{{}, {}, {}, {}}, Topics: []common.Hash{{}, {}, {}, {}},
} }
_, err := converter.ToModels([]types.Log{badLog}) _, err := converter.ToModels([]types.Log{badLog})
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
}) })
It("converts a log to an model", func() { It("converts a log to an model", func() {
converter := flip.CatFileFlipConverter{} models, err := converter.ToModels([]types.Log{test_data.EthCatFileFlipLog})
model, err := converter.ToModels([]types.Log{test_data.EthCatFileFlipLog})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(model).To(Equal([]flip.CatFileFlipModel{test_data.CatFileFlipModel})) Expect(models).To(Equal([]interface{}{test_data.CatFileFlipModel}))
}) })
}) })

View File

@ -15,6 +15,8 @@
package flip_test package flip_test
import ( import (
"io/ioutil"
"log"
"testing" "testing"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
@ -25,3 +27,7 @@ func TestFlip(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Flip Suite") RunSpecs(t, "Flip Suite")
} }
var _ = BeforeSuite(func() {
log.SetOutput(ioutil.Discard)
})

View File

@ -42,7 +42,8 @@ var _ = Describe("Cat file flip repository", func() {
db = test_config.NewTestDB(test_config.NewTestNode()) db = test_config.NewTestDB(test_config.NewTestNode())
test_config.CleanTestDB(db) test_config.CleanTestDB(db)
headerRepository = repositories.NewHeaderRepository(db) headerRepository = repositories.NewHeaderRepository(db)
catFileRepository = flip.NewCatFileFlipRepository(db) catFileRepository = flip.CatFileFlipRepository{}
catFileRepository.SetDB(db)
}) })
Describe("Create", func() { Describe("Create", func() {
@ -52,7 +53,7 @@ var _ = Describe("Cat file flip repository", func() {
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
err = catFileRepository.Create(headerID, []flip.CatFileFlipModel{test_data.CatFileFlipModel}) err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileFlipModel})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
@ -76,7 +77,7 @@ var _ = Describe("Cat file flip repository", func() {
}) })
It("does not duplicate cat file flip events", func() { It("does not duplicate cat file flip events", func() {
err = catFileRepository.Create(headerID, []flip.CatFileFlipModel{test_data.CatFileFlipModel}) err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileFlipModel})
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint")) Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
@ -85,7 +86,7 @@ var _ = Describe("Cat file flip repository", func() {
It("allows for multiple cat file flip events in one transaction if they have different log indexes", func() { It("allows for multiple cat file flip events in one transaction if they have different log indexes", func() {
catFileFlip := test_data.CatFileFlipModel catFileFlip := test_data.CatFileFlipModel
catFileFlip.LogIndex = catFileFlip.LogIndex + 1 catFileFlip.LogIndex = catFileFlip.LogIndex + 1
err = catFileRepository.Create(headerID, []flip.CatFileFlipModel{catFileFlip}) err = catFileRepository.Create(headerID, []interface{}{catFileFlip})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
@ -187,7 +188,8 @@ var _ = Describe("Cat file flip repository", func() {
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n)) _, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
} }
catFileRepositoryTwo := flip.NewCatFileFlipRepository(dbTwo) catFileRepositoryTwo := flip.CatFileFlipRepository{}
catFileRepositoryTwo.SetDB(dbTwo)
nodeOneMissingHeaders, err := catFileRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) nodeOneMissingHeaders, err := catFileRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1])
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())

View File

@ -19,42 +19,57 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
"math/rand"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file"
"github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/flip" "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/flip"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks"
flip_mocks "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks/cat_file/flip"
) )
var _ = Describe("Cat file flip transformer", func() { var _ = Describe("Cat file flip transformer", func() {
It("gets missing headers for block numbers specified in config", func() { var (
repository := &flip_mocks.MockCatFileFlipRepository{} config = flip.CatFileFlipConfig
transformer := flip.CatFileFlipTransformer{ repository mocks.MockRepository
Config: cat_file.CatFileConfig, converter mocks.MockConverter
Fetcher: &mocks.MockLogFetcher{}, fetcher mocks.MockLogFetcher
Converter: &flip_mocks.MockCatFileFlipConverter{}, transformer shared.Transformer
Repository: repository, headerOne core.Header
} headerTwo core.Header
)
BeforeEach(func() {
repository = mocks.MockRepository{}
converter = mocks.MockConverter{}
fetcher = mocks.MockLogFetcher{}
transformer = factories.Transformer{
Config: config,
Converter: &converter,
Repository: &repository,
Fetcher: &fetcher,
}.NewTransformer(nil, nil)
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
})
It("sets the blockchain and database", func() {
Expect(fetcher.SetBcCalled).To(BeTrue())
Expect(repository.SetDbCalled).To(BeTrue())
})
It("gets missing headers for block numbers specified in config", func() {
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(repository.PassedStartingBlockNumber).To(Equal(cat_file.CatFileConfig.StartingBlockNumber)) Expect(repository.PassedStartingBlockNumber).To(Equal(config.StartingBlockNumber))
Expect(repository.PassedEndingBlockNumber).To(Equal(cat_file.CatFileConfig.EndingBlockNumber)) Expect(repository.PassedEndingBlockNumber).To(Equal(config.EndingBlockNumber))
}) })
It("returns error if repository returns error for missing headers", func() { It("returns error if repository returns error for missing headers", func() {
repository := &flip_mocks.MockCatFileFlipRepository{} repository.SetMissingHeadersError(fakes.FakeError)
repository.SetMissingHeadersErr(fakes.FakeError)
transformer := flip.CatFileFlipTransformer{
Fetcher: &mocks.MockLogFetcher{},
Converter: &flip_mocks.MockCatFileFlipConverter{},
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -63,33 +78,20 @@ var _ = Describe("Cat file flip transformer", func() {
}) })
It("fetches logs for missing headers", func() { It("fetches logs for missing headers", func() {
fetcher := &mocks.MockLogFetcher{} repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
repository := &flip_mocks.MockCatFileFlipRepository{}
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}, {BlockNumber: 2}})
transformer := flip.CatFileFlipTransformer{
Fetcher: fetcher,
Converter: &flip_mocks.MockCatFileFlipConverter{},
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) Expect(fetcher.FetchedBlocks).To(Equal([]int64{headerOne.BlockNumber, headerTwo.BlockNumber}))
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{cat_file.CatFileConfig.ContractAddresses, cat_file.CatFileConfig.ContractAddresses})) Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{
config.ContractAddresses, config.ContractAddresses}))
Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.CatFileFlipSignature)}})) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.CatFileFlipSignature)}}))
}) })
It("returns error if fetcher returns error", func() { It("returns error if fetcher returns error", func() {
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetcherError(fakes.FakeError) fetcher.SetFetcherError(fakes.FakeError)
repository := &flip_mocks.MockCatFileFlipRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
transformer := flip.CatFileFlipTransformer{
Fetcher: fetcher,
Converter: &flip_mocks.MockCatFileFlipConverter{},
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -98,34 +100,17 @@ var _ = Describe("Cat file flip transformer", func() {
}) })
It("marks header checked if no logs returned", func() { It("marks header checked if no logs returned", func() {
mockConverter := &flip_mocks.MockCatFileFlipConverter{} repository.SetMissingHeaders([]core.Header{headerOne})
mockRepository := &flip_mocks.MockCatFileFlipRepository{}
headerID := int64(123)
mockRepository.SetMissingHeaders([]core.Header{{Id: headerID}})
mockFetcher := &mocks.MockLogFetcher{}
transformer := flip.CatFileFlipTransformer{
Converter: mockConverter,
Fetcher: mockFetcher,
Repository: mockRepository,
}
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
mockRepository.AssertMarkHeaderCheckedCalledWith(headerID) repository.AssertMarkHeaderCheckedCalledWith(headerOne.Id)
}) })
It("returns error if marking header checked returns err", func() { It("returns error if marking header checked returns err", func() {
mockConverter := &flip_mocks.MockCatFileFlipConverter{} repository.SetMissingHeaders([]core.Header{headerOne})
mockRepository := &flip_mocks.MockCatFileFlipRepository{} repository.SetMarkHeaderCheckedError(fakes.FakeError)
mockRepository.SetMissingHeaders([]core.Header{{Id: int64(123)}})
mockRepository.SetMarkHeaderCheckedErr(fakes.FakeError)
mockFetcher := &mocks.MockLogFetcher{}
transformer := flip.CatFileFlipTransformer{
Converter: mockConverter,
Fetcher: mockFetcher,
Repository: mockRepository,
}
err := transformer.Execute() err := transformer.Execute()
@ -134,16 +119,8 @@ var _ = Describe("Cat file flip transformer", func() {
}) })
It("converts matching logs", func() { It("converts matching logs", func() {
converter := &flip_mocks.MockCatFileFlipConverter{}
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileFlipLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileFlipLog})
repository := &flip_mocks.MockCatFileFlipRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
transformer := flip.CatFileFlipTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -152,17 +129,9 @@ var _ = Describe("Cat file flip transformer", func() {
}) })
It("returns error if converter returns error", func() { It("returns error if converter returns error", func() {
converter := &flip_mocks.MockCatFileFlipConverter{}
converter.SetConverterError(fakes.FakeError) converter.SetConverterError(fakes.FakeError)
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileFlipLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileFlipLog})
repository := &flip_mocks.MockCatFileFlipRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
transformer := flip.CatFileFlipTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -171,37 +140,21 @@ var _ = Describe("Cat file flip transformer", func() {
}) })
It("persists cat file flip model", func() { It("persists cat file flip model", func() {
converter := &flip_mocks.MockCatFileFlipConverter{}
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileFlipLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileFlipLog})
repository := &flip_mocks.MockCatFileFlipRepository{} converter.SetReturnModels([]interface{}{test_data.CatFileFlipModel})
fakeHeader := core.Header{BlockNumber: 1, Id: 2} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{fakeHeader})
transformer := flip.CatFileFlipTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id)) Expect(repository.PassedHeaderID).To(Equal(headerOne.Id))
Expect(repository.PassedModels).To(Equal([]flip.CatFileFlipModel{test_data.CatFileFlipModel})) Expect(repository.PassedModels).To(Equal([]interface{}{test_data.CatFileFlipModel}))
}) })
It("returns error if repository returns error for create", func() { It("returns error if repository returns error for create", func() {
converter := &flip_mocks.MockCatFileFlipConverter{}
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileFlipLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileFlipLog})
repository := &flip_mocks.MockCatFileFlipRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}})
repository.SetCreateError(fakes.FakeError) repository.SetCreateError(fakes.FakeError)
transformer := flip.CatFileFlipTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()

View File

@ -25,34 +25,34 @@ import (
) )
var _ = Describe("Cat file pit vow converter", func() { var _ = Describe("Cat file pit vow converter", func() {
var converter pit_vow.CatFilePitVowConverter
BeforeEach(func() {
converter = pit_vow.CatFilePitVowConverter{}
})
It("returns err if log is missing topics", func() { It("returns err if log is missing topics", func() {
converter := pit_vow.CatFilePitVowConverter{}
badLog := types.Log{ badLog := types.Log{
Data: []byte{1, 1, 1, 1, 1}, Data: []byte{1, 1, 1, 1, 1},
} }
_, err := converter.ToModels([]types.Log{badLog}) _, err := converter.ToModels([]types.Log{badLog})
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
}) })
It("returns err if log is missing data", func() { It("returns err if log is missing data", func() {
converter := pit_vow.CatFilePitVowConverter{}
badLog := types.Log{ badLog := types.Log{
Topics: []common.Hash{{}, {}, {}, {}}, Topics: []common.Hash{{}, {}, {}, {}},
} }
_, err := converter.ToModels([]types.Log{badLog}) _, err := converter.ToModels([]types.Log{badLog})
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
}) })
It("converts a log to an model", func() { It("converts a log to an model", func() {
converter := pit_vow.CatFilePitVowConverter{} models, err := converter.ToModels([]types.Log{test_data.EthCatFilePitVowLog})
model, err := converter.ToModels([]types.Log{test_data.EthCatFilePitVowLog})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(model).To(Equal([]pit_vow.CatFilePitVowModel{test_data.CatFilePitVowModel})) Expect(models).To(Equal([]interface{}{test_data.CatFilePitVowModel}))
}) })
}) })

View File

@ -15,6 +15,8 @@
package pit_vow_test package pit_vow_test
import ( import (
"io/ioutil"
"log"
"testing" "testing"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
@ -25,3 +27,7 @@ func TestPitVow(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "PitVow Suite") RunSpecs(t, "PitVow Suite")
} }
var _ = BeforeSuite(func() {
log.SetOutput(ioutil.Discard)
})

View File

@ -42,7 +42,8 @@ var _ = Describe("Cat file pit vow repository", func() {
db = test_config.NewTestDB(test_config.NewTestNode()) db = test_config.NewTestDB(test_config.NewTestNode())
test_config.CleanTestDB(db) test_config.CleanTestDB(db)
headerRepository = repositories.NewHeaderRepository(db) headerRepository = repositories.NewHeaderRepository(db)
catFileRepository = pit_vow.NewCatFilePitVowRepository(db) catFileRepository = pit_vow.CatFilePitVowRepository{}
catFileRepository.SetDB(db)
}) })
Describe("Create", func() { Describe("Create", func() {
@ -52,7 +53,7 @@ var _ = Describe("Cat file pit vow repository", func() {
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
err = catFileRepository.Create(headerID, []pit_vow.CatFilePitVowModel{test_data.CatFilePitVowModel}) err = catFileRepository.Create(headerID, []interface{}{test_data.CatFilePitVowModel})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
@ -75,7 +76,7 @@ var _ = Describe("Cat file pit vow repository", func() {
}) })
It("does not duplicate cat file pit vow events", func() { It("does not duplicate cat file pit vow events", func() {
err = catFileRepository.Create(headerID, []pit_vow.CatFilePitVowModel{test_data.CatFilePitVowModel}) err = catFileRepository.Create(headerID, []interface{}{test_data.CatFilePitVowModel})
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint")) Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
@ -84,7 +85,7 @@ var _ = Describe("Cat file pit vow repository", func() {
It("allows for multiple cat file pit events in one transaction if they have different log indexes", func() { It("allows for multiple cat file pit events in one transaction if they have different log indexes", func() {
catFilePitVow := test_data.CatFilePitVowModel catFilePitVow := test_data.CatFilePitVowModel
catFilePitVow.LogIndex = catFilePitVow.LogIndex + 1 catFilePitVow.LogIndex = catFilePitVow.LogIndex + 1
err = catFileRepository.Create(headerID, []pit_vow.CatFilePitVowModel{catFilePitVow}) err = catFileRepository.Create(headerID, []interface{}{catFilePitVow})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
@ -186,7 +187,8 @@ var _ = Describe("Cat file pit vow repository", func() {
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n)) _, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
} }
catFileRepositoryTwo := pit_vow.NewCatFilePitVowRepository(dbTwo) catFileRepositoryTwo := pit_vow.CatFilePitVowRepository{}
catFileRepositoryTwo.SetDB(dbTwo)
nodeOneMissingHeaders, err := catFileRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) nodeOneMissingHeaders, err := catFileRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1])
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())

View File

@ -19,42 +19,57 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
"math/rand"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file"
"github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/pit_vow" "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/pit_vow"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks"
pit_vow_mocks "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks/cat_file/pit_vow"
) )
var _ = Describe("Cat file pit vow transformer", func() { var _ = Describe("Cat file pit vow transformer", func() {
It("gets missing headers for block numbers specified in config", func() { var (
repository := &pit_vow_mocks.MockCatFilePitVowRepository{} config = pit_vow.CatFilePitVowConfig
transformer := pit_vow.CatFilePitVowTransformer{ repository mocks.MockRepository
Config: cat_file.CatFileConfig, converter mocks.MockConverter
Fetcher: &mocks.MockLogFetcher{}, fetcher mocks.MockLogFetcher
Converter: &pit_vow_mocks.MockCatFilePitVowConverter{}, transformer shared.Transformer
Repository: repository, headerOne core.Header
} headerTwo core.Header
)
BeforeEach(func() {
repository = mocks.MockRepository{}
converter = mocks.MockConverter{}
fetcher = mocks.MockLogFetcher{}
transformer = factories.Transformer{
Config: config,
Converter: &converter,
Repository: &repository,
Fetcher: &fetcher,
}.NewTransformer(nil, nil)
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
})
It("sets the blockchain and database", func() {
Expect(fetcher.SetBcCalled).To(BeTrue())
Expect(repository.SetDbCalled).To(BeTrue())
})
It("gets missing headers for block numbers specified in config", func() {
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(repository.PassedStartingBlockNumber).To(Equal(cat_file.CatFileConfig.StartingBlockNumber)) Expect(repository.PassedStartingBlockNumber).To(Equal(config.StartingBlockNumber))
Expect(repository.PassedEndingBlockNumber).To(Equal(cat_file.CatFileConfig.EndingBlockNumber)) Expect(repository.PassedEndingBlockNumber).To(Equal(config.EndingBlockNumber))
}) })
It("returns error if repository returns error for missing headers", func() { It("returns error if repository returns error for missing headers", func() {
repository := &pit_vow_mocks.MockCatFilePitVowRepository{} repository.SetMissingHeadersError(fakes.FakeError)
repository.SetMissingHeadersErr(fakes.FakeError)
transformer := pit_vow.CatFilePitVowTransformer{
Fetcher: &mocks.MockLogFetcher{},
Converter: &pit_vow_mocks.MockCatFilePitVowConverter{},
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -63,33 +78,20 @@ var _ = Describe("Cat file pit vow transformer", func() {
}) })
It("fetches logs for missing headers", func() { It("fetches logs for missing headers", func() {
fetcher := &mocks.MockLogFetcher{} repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
repository := &pit_vow_mocks.MockCatFilePitVowRepository{}
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}, {BlockNumber: 2}})
transformer := pit_vow.CatFilePitVowTransformer{
Fetcher: fetcher,
Converter: &pit_vow_mocks.MockCatFilePitVowConverter{},
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) Expect(fetcher.FetchedBlocks).To(Equal([]int64{headerOne.BlockNumber, headerTwo.BlockNumber}))
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{cat_file.CatFileConfig.ContractAddresses, cat_file.CatFileConfig.ContractAddresses})) Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{
config.ContractAddresses, config.ContractAddresses}))
Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.CatFilePitVowSignature)}})) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.CatFilePitVowSignature)}}))
}) })
It("returns error if fetcher returns error", func() { It("returns error if fetcher returns error", func() {
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetcherError(fakes.FakeError) fetcher.SetFetcherError(fakes.FakeError)
repository := &pit_vow_mocks.MockCatFilePitVowRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
transformer := pit_vow.CatFilePitVowTransformer{
Fetcher: fetcher,
Converter: &pit_vow_mocks.MockCatFilePitVowConverter{},
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -98,34 +100,17 @@ var _ = Describe("Cat file pit vow transformer", func() {
}) })
It("marks header checked if no logs returned", func() { It("marks header checked if no logs returned", func() {
mockConverter := &pit_vow_mocks.MockCatFilePitVowConverter{} repository.SetMissingHeaders([]core.Header{headerOne})
mockRepository := &pit_vow_mocks.MockCatFilePitVowRepository{}
headerID := int64(123)
mockRepository.SetMissingHeaders([]core.Header{{Id: headerID}})
mockFetcher := &mocks.MockLogFetcher{}
transformer := pit_vow.CatFilePitVowTransformer{
Converter: mockConverter,
Fetcher: mockFetcher,
Repository: mockRepository,
}
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
mockRepository.AssertMarkHeaderCheckedCalledWith(headerID) repository.AssertMarkHeaderCheckedCalledWith(headerOne.Id)
}) })
It("returns error if marking header checked returns err", func() { It("returns error if marking header checked returns err", func() {
mockConverter := &pit_vow_mocks.MockCatFilePitVowConverter{} repository.SetMissingHeaders([]core.Header{headerOne})
mockRepository := &pit_vow_mocks.MockCatFilePitVowRepository{} repository.SetMarkHeaderCheckedError(fakes.FakeError)
mockRepository.SetMissingHeaders([]core.Header{{Id: int64(123)}})
mockRepository.SetMarkHeaderCheckedErr(fakes.FakeError)
mockFetcher := &mocks.MockLogFetcher{}
transformer := pit_vow.CatFilePitVowTransformer{
Converter: mockConverter,
Fetcher: mockFetcher,
Repository: mockRepository,
}
err := transformer.Execute() err := transformer.Execute()
@ -134,16 +119,8 @@ var _ = Describe("Cat file pit vow transformer", func() {
}) })
It("converts matching logs", func() { It("converts matching logs", func() {
converter := &pit_vow_mocks.MockCatFilePitVowConverter{}
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFilePitVowLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFilePitVowLog})
repository := &pit_vow_mocks.MockCatFilePitVowRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
transformer := pit_vow.CatFilePitVowTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -152,17 +129,9 @@ var _ = Describe("Cat file pit vow transformer", func() {
}) })
It("returns error if converter returns error", func() { It("returns error if converter returns error", func() {
converter := &pit_vow_mocks.MockCatFilePitVowConverter{}
converter.SetConverterError(fakes.FakeError) converter.SetConverterError(fakes.FakeError)
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFilePitVowLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFilePitVowLog})
repository := &pit_vow_mocks.MockCatFilePitVowRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
transformer := pit_vow.CatFilePitVowTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -171,37 +140,21 @@ var _ = Describe("Cat file pit vow transformer", func() {
}) })
It("persists cat file pit vow model", func() { It("persists cat file pit vow model", func() {
converter := &pit_vow_mocks.MockCatFilePitVowConverter{}
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFilePitVowLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFilePitVowLog})
repository := &pit_vow_mocks.MockCatFilePitVowRepository{} converter.SetReturnModels([]interface{}{test_data.CatFilePitVowModel})
fakeHeader := core.Header{BlockNumber: 1, Id: 2} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{fakeHeader})
transformer := pit_vow.CatFilePitVowTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id)) Expect(repository.PassedHeaderID).To(Equal(headerOne.Id))
Expect(repository.PassedModels).To(Equal([]pit_vow.CatFilePitVowModel{test_data.CatFilePitVowModel})) Expect(repository.PassedModels).To(Equal([]interface{}{test_data.CatFilePitVowModel}))
}) })
It("returns error if repository returns error for create", func() { It("returns error if repository returns error for create", func() {
converter := &pit_vow_mocks.MockCatFilePitVowConverter{}
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFilePitVowLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFilePitVowLog})
repository := &pit_vow_mocks.MockCatFilePitVowRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}})
repository.SetCreateError(fakes.FakeError) repository.SetCreateError(fakes.FakeError)
transformer := pit_vow.CatFilePitVowTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()

View File

@ -15,6 +15,8 @@
package integration_tests package integration_tests
import ( import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"sort" "sort"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
@ -24,7 +26,6 @@ import (
"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/geth/client" "github.com/vulcanize/vulcanizedb/pkg/geth/client"
"github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file"
"github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/chop_lump" "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/chop_lump"
"github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/flip" "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/flip"
"github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/pit_vow" "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/pit_vow"
@ -56,12 +57,17 @@ var _ = Describe("Cat File transformer", func() {
err = persistHeader(db, chopLumpBlockNumber) err = persistHeader(db, chopLumpBlockNumber)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
config := cat_file.CatFileConfig config := chop_lump.CatFileChopLumpConfig
config.StartingBlockNumber = chopLumpBlockNumber config.StartingBlockNumber = chopLumpBlockNumber
config.EndingBlockNumber = chopLumpBlockNumber config.EndingBlockNumber = chopLumpBlockNumber
initializer := chop_lump.CatFileChopLumpTransformerInitializer{Config: config} initializer := factories.Transformer{
transformer := initializer.NewCatFileChopLumpTransformer(db, blockchain) Config: config,
Converter: &chop_lump.CatFileChopLumpConverter{},
Repository: &chop_lump.CatFileChopLumpRepository{},
Fetcher: &shared.Fetcher{},
}
transformer := initializer.NewTransformer(db, blockchain)
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
@ -89,12 +95,17 @@ var _ = Describe("Cat File transformer", func() {
err = persistHeader(db, flipBlockNumber) err = persistHeader(db, flipBlockNumber)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
config := cat_file.CatFileConfig config := flip.CatFileFlipConfig
config.StartingBlockNumber = flipBlockNumber config.StartingBlockNumber = flipBlockNumber
config.EndingBlockNumber = flipBlockNumber config.EndingBlockNumber = flipBlockNumber
initializer := flip.CatFileFlipTransformerInitializer{Config: config} initializer := factories.Transformer{
transformer := initializer.NewCatFileFlipTransformer(db, blockchain) Config: config,
Converter: &flip.CatFileFlipConverter{},
Repository: &flip.CatFileFlipRepository{},
Fetcher: &shared.Fetcher{},
}
transformer := initializer.NewTransformer(db, blockchain)
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
@ -114,12 +125,17 @@ var _ = Describe("Cat File transformer", func() {
err = persistHeader(db, pitVowBlockNumber) err = persistHeader(db, pitVowBlockNumber)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
config := cat_file.CatFileConfig config := pit_vow.CatFilePitVowConfig
config.StartingBlockNumber = pitVowBlockNumber config.StartingBlockNumber = pitVowBlockNumber
config.EndingBlockNumber = pitVowBlockNumber config.EndingBlockNumber = pitVowBlockNumber
initializer := pit_vow.CatFilePitVowTransformerInitializer{Config: config} initializer := factories.Transformer{
transformer := initializer.NewCatFilePitVowTransformer(db, blockchain) Config: config,
Converter: &pit_vow.CatFilePitVowConverter{},
Repository: &pit_vow.CatFilePitVowRepository{},
Fetcher: &shared.Fetcher{},
}
transformer := initializer.NewTransformer(db, blockchain)
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())