forked from cerc-io/ipld-eth-server
Update cat file transformer tests
This commit is contained in:
parent
28ab5f92ab
commit
e6e2ed3308
@ -15,6 +15,8 @@
|
||||
package chop_lump_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
@ -25,3 +27,7 @@ func TestChopLump(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "ChopLump Suite")
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
log.SetOutput(ioutil.Discard)
|
||||
})
|
||||
|
@ -25,34 +25,34 @@ import (
|
||||
)
|
||||
|
||||
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() {
|
||||
converter := chop_lump.CatFileChopLumpConverter{}
|
||||
badLog := types.Log{
|
||||
Data: []byte{1, 1, 1, 1, 1},
|
||||
}
|
||||
|
||||
_, err := converter.ToModels([]types.Log{badLog})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
|
||||
It("returns err if log is missing data", func() {
|
||||
converter := chop_lump.CatFileChopLumpConverter{}
|
||||
badLog := types.Log{
|
||||
Topics: []common.Hash{{}, {}, {}, {}},
|
||||
}
|
||||
|
||||
_, err := converter.ToModels([]types.Log{badLog})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
|
||||
It("converts a log to an model", func() {
|
||||
converter := chop_lump.CatFileChopLumpConverter{}
|
||||
|
||||
model, err := converter.ToModels([]types.Log{test_data.EthCatFileChopLumpLog})
|
||||
models, err := converter.ToModels([]types.Log{test_data.EthCatFileChopLumpLog})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(model).To(Equal([]chop_lump.CatFileChopLumpModel{test_data.CatFileChopLumpModel}))
|
||||
Expect(models).To(Equal([]interface{}{test_data.CatFileChopLumpModel}))
|
||||
})
|
||||
})
|
||||
|
@ -42,7 +42,8 @@ var _ = Describe("Cat file chop lump repository", func() {
|
||||
db = test_config.NewTestDB(test_config.NewTestNode())
|
||||
test_config.CleanTestDB(db)
|
||||
headerRepository = repositories.NewHeaderRepository(db)
|
||||
catFileRepository = chop_lump.NewCatFileChopLumpRepository(db)
|
||||
catFileRepository = chop_lump.CatFileChopLumpRepository{}
|
||||
catFileRepository.SetDB(db)
|
||||
})
|
||||
|
||||
Describe("Create", func() {
|
||||
@ -52,7 +53,7 @@ var _ = Describe("Cat file chop lump repository", func() {
|
||||
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||
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())
|
||||
})
|
||||
|
||||
@ -76,7 +77,7 @@ var _ = Describe("Cat file chop lump repository", 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.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() {
|
||||
newCatFileChopLump := test_data.CatFileChopLumpModel
|
||||
newCatFileChopLump.LogIndex = newCatFileChopLump.LogIndex + 1
|
||||
err = catFileRepository.Create(headerID, []chop_lump.CatFileChopLumpModel{newCatFileChopLump})
|
||||
err = catFileRepository.Create(headerID, []interface{}{newCatFileChopLump})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
@ -187,7 +188,8 @@ var _ = Describe("Cat file chop lump repository", func() {
|
||||
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||
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])
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
@ -19,42 +19,57 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
|
||||
"math/rand"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"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/shared"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
"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() {
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
repository := &chop_lump_mocks.MockCatFileChopLumpRepository{}
|
||||
transformer := chop_lump.CatFileChopLumpTransformer{
|
||||
Config: cat_file.CatFileConfig,
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &chop_lump_mocks.MockCatFileChopLumpConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
var (
|
||||
config = chop_lump.CatFileChopLumpConfig
|
||||
repository mocks.MockRepository
|
||||
converter mocks.MockConverter
|
||||
fetcher mocks.MockLogFetcher
|
||||
transformer shared.Transformer
|
||||
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()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.PassedStartingBlockNumber).To(Equal(cat_file.CatFileConfig.StartingBlockNumber))
|
||||
Expect(repository.PassedEndingBlockNumber).To(Equal(cat_file.CatFileConfig.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 := &chop_lump_mocks.MockCatFileChopLumpRepository{}
|
||||
repository.SetMissingHeadersErr(fakes.FakeError)
|
||||
transformer := chop_lump.CatFileChopLumpTransformer{
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &chop_lump_mocks.MockCatFileChopLumpConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeadersError(fakes.FakeError)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -63,33 +78,20 @@ var _ = Describe("Cat file chop lump transformer", func() {
|
||||
})
|
||||
|
||||
It("fetches logs for missing headers", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
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,
|
||||
}
|
||||
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{cat_file.CatFileConfig.ContractAddresses, cat_file.CatFileConfig.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.CatFileChopLumpSignature)}}))
|
||||
})
|
||||
|
||||
It("returns error if fetcher returns error", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetcherError(fakes.FakeError)
|
||||
repository := &chop_lump_mocks.MockCatFileChopLumpRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := chop_lump.CatFileChopLumpTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: &chop_lump_mocks.MockCatFileChopLumpConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -98,34 +100,17 @@ var _ = Describe("Cat file chop lump transformer", func() {
|
||||
})
|
||||
|
||||
It("marks header checked if no logs returned", func() {
|
||||
mockConverter := &chop_lump_mocks.MockCatFileChopLumpConverter{}
|
||||
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,
|
||||
}
|
||||
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 := &chop_lump_mocks.MockCatFileChopLumpConverter{}
|
||||
mockRepository := &chop_lump_mocks.MockCatFileChopLumpRepository{}
|
||||
mockRepository.SetMissingHeaders([]core.Header{{Id: int64(123)}})
|
||||
mockRepository.SetMarkHeaderCheckedErr(fakes.FakeError)
|
||||
mockFetcher := &mocks.MockLogFetcher{}
|
||||
transformer := chop_lump.CatFileChopLumpTransformer{
|
||||
Converter: mockConverter,
|
||||
Fetcher: mockFetcher,
|
||||
Repository: mockRepository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetMarkHeaderCheckedError(fakes.FakeError)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -134,16 +119,8 @@ var _ = Describe("Cat file chop lump transformer", func() {
|
||||
})
|
||||
|
||||
It("converts matching logs", func() {
|
||||
converter := &chop_lump_mocks.MockCatFileChopLumpConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileChopLumpLog})
|
||||
repository := &chop_lump_mocks.MockCatFileChopLumpRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := chop_lump.CatFileChopLumpTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -152,17 +129,9 @@ var _ = Describe("Cat file chop lump transformer", func() {
|
||||
})
|
||||
|
||||
It("returns error if converter returns error", func() {
|
||||
converter := &chop_lump_mocks.MockCatFileChopLumpConverter{}
|
||||
converter.SetConverterError(fakes.FakeError)
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileChopLumpLog})
|
||||
repository := &chop_lump_mocks.MockCatFileChopLumpRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := chop_lump.CatFileChopLumpTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -171,37 +140,20 @@ var _ = Describe("Cat file chop lump transformer", func() {
|
||||
})
|
||||
|
||||
It("persists cat file chop lump model", func() {
|
||||
converter := &chop_lump_mocks.MockCatFileChopLumpConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileChopLumpLog})
|
||||
repository := &chop_lump_mocks.MockCatFileChopLumpRepository{}
|
||||
fakeHeader := core.Header{BlockNumber: 1, Id: 2}
|
||||
repository.SetMissingHeaders([]core.Header{fakeHeader})
|
||||
transformer := chop_lump.CatFileChopLumpTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
converter.SetReturnModels([]interface{}{test_data.CatFileChopLumpModel})
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]chop_lump.CatFileChopLumpModel{test_data.CatFileChopLumpModel}))
|
||||
Expect(repository.PassedHeaderID).To(Equal(headerOne.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]interface{}{test_data.CatFileChopLumpModel}))
|
||||
})
|
||||
|
||||
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})
|
||||
repository := &chop_lump_mocks.MockCatFileChopLumpRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetCreateError(fakes.FakeError)
|
||||
transformer := chop_lump.CatFileChopLumpTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
|
@ -25,34 +25,34 @@ import (
|
||||
)
|
||||
|
||||
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() {
|
||||
converter := flip.CatFileFlipConverter{}
|
||||
badLog := types.Log{
|
||||
Data: []byte{1, 1, 1, 1, 1},
|
||||
}
|
||||
|
||||
_, err := converter.ToModels([]types.Log{badLog})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
|
||||
It("returns err if log is missing data", func() {
|
||||
converter := flip.CatFileFlipConverter{}
|
||||
badLog := types.Log{
|
||||
Topics: []common.Hash{{}, {}, {}, {}},
|
||||
}
|
||||
|
||||
_, err := converter.ToModels([]types.Log{badLog})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
|
||||
It("converts a log to an model", func() {
|
||||
converter := flip.CatFileFlipConverter{}
|
||||
|
||||
model, err := converter.ToModels([]types.Log{test_data.EthCatFileFlipLog})
|
||||
models, err := converter.ToModels([]types.Log{test_data.EthCatFileFlipLog})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(model).To(Equal([]flip.CatFileFlipModel{test_data.CatFileFlipModel}))
|
||||
Expect(models).To(Equal([]interface{}{test_data.CatFileFlipModel}))
|
||||
})
|
||||
})
|
||||
|
@ -15,6 +15,8 @@
|
||||
package flip_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
@ -25,3 +27,7 @@ func TestFlip(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Flip Suite")
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
log.SetOutput(ioutil.Discard)
|
||||
})
|
||||
|
@ -42,7 +42,8 @@ var _ = Describe("Cat file flip repository", func() {
|
||||
db = test_config.NewTestDB(test_config.NewTestNode())
|
||||
test_config.CleanTestDB(db)
|
||||
headerRepository = repositories.NewHeaderRepository(db)
|
||||
catFileRepository = flip.NewCatFileFlipRepository(db)
|
||||
catFileRepository = flip.CatFileFlipRepository{}
|
||||
catFileRepository.SetDB(db)
|
||||
})
|
||||
|
||||
Describe("Create", func() {
|
||||
@ -52,7 +53,7 @@ var _ = Describe("Cat file flip repository", func() {
|
||||
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||
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())
|
||||
})
|
||||
|
||||
@ -76,7 +77,7 @@ var _ = Describe("Cat file flip repository", 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.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() {
|
||||
catFileFlip := test_data.CatFileFlipModel
|
||||
catFileFlip.LogIndex = catFileFlip.LogIndex + 1
|
||||
err = catFileRepository.Create(headerID, []flip.CatFileFlipModel{catFileFlip})
|
||||
err = catFileRepository.Create(headerID, []interface{}{catFileFlip})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
@ -187,7 +188,8 @@ var _ = Describe("Cat file flip repository", func() {
|
||||
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
catFileRepositoryTwo := flip.NewCatFileFlipRepository(dbTwo)
|
||||
catFileRepositoryTwo := flip.CatFileFlipRepository{}
|
||||
catFileRepositoryTwo.SetDB(dbTwo)
|
||||
|
||||
nodeOneMissingHeaders, err := catFileRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1])
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
@ -19,42 +19,57 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
|
||||
"math/rand"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"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/shared"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
"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() {
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
repository := &flip_mocks.MockCatFileFlipRepository{}
|
||||
transformer := flip.CatFileFlipTransformer{
|
||||
Config: cat_file.CatFileConfig,
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &flip_mocks.MockCatFileFlipConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
var (
|
||||
config = flip.CatFileFlipConfig
|
||||
repository mocks.MockRepository
|
||||
converter mocks.MockConverter
|
||||
fetcher mocks.MockLogFetcher
|
||||
transformer shared.Transformer
|
||||
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()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.PassedStartingBlockNumber).To(Equal(cat_file.CatFileConfig.StartingBlockNumber))
|
||||
Expect(repository.PassedEndingBlockNumber).To(Equal(cat_file.CatFileConfig.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 := &flip_mocks.MockCatFileFlipRepository{}
|
||||
repository.SetMissingHeadersErr(fakes.FakeError)
|
||||
transformer := flip.CatFileFlipTransformer{
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &flip_mocks.MockCatFileFlipConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeadersError(fakes.FakeError)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -63,33 +78,20 @@ var _ = Describe("Cat file flip transformer", func() {
|
||||
})
|
||||
|
||||
It("fetches logs for missing headers", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
repository := &flip_mocks.MockCatFileFlipRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}, {BlockNumber: 2}})
|
||||
transformer := flip.CatFileFlipTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: &flip_mocks.MockCatFileFlipConverter{},
|
||||
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{cat_file.CatFileConfig.ContractAddresses, cat_file.CatFileConfig.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.CatFileFlipSignature)}}))
|
||||
})
|
||||
|
||||
It("returns error if fetcher returns error", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetcherError(fakes.FakeError)
|
||||
repository := &flip_mocks.MockCatFileFlipRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := flip.CatFileFlipTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: &flip_mocks.MockCatFileFlipConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -98,34 +100,17 @@ var _ = Describe("Cat file flip transformer", func() {
|
||||
})
|
||||
|
||||
It("marks header checked if no logs returned", func() {
|
||||
mockConverter := &flip_mocks.MockCatFileFlipConverter{}
|
||||
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,
|
||||
}
|
||||
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 := &flip_mocks.MockCatFileFlipConverter{}
|
||||
mockRepository := &flip_mocks.MockCatFileFlipRepository{}
|
||||
mockRepository.SetMissingHeaders([]core.Header{{Id: int64(123)}})
|
||||
mockRepository.SetMarkHeaderCheckedErr(fakes.FakeError)
|
||||
mockFetcher := &mocks.MockLogFetcher{}
|
||||
transformer := flip.CatFileFlipTransformer{
|
||||
Converter: mockConverter,
|
||||
Fetcher: mockFetcher,
|
||||
Repository: mockRepository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetMarkHeaderCheckedError(fakes.FakeError)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -134,16 +119,8 @@ var _ = Describe("Cat file flip transformer", func() {
|
||||
})
|
||||
|
||||
It("converts matching logs", func() {
|
||||
converter := &flip_mocks.MockCatFileFlipConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileFlipLog})
|
||||
repository := &flip_mocks.MockCatFileFlipRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := flip.CatFileFlipTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -152,17 +129,9 @@ var _ = Describe("Cat file flip transformer", func() {
|
||||
})
|
||||
|
||||
It("returns error if converter returns error", func() {
|
||||
converter := &flip_mocks.MockCatFileFlipConverter{}
|
||||
converter.SetConverterError(fakes.FakeError)
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileFlipLog})
|
||||
repository := &flip_mocks.MockCatFileFlipRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := flip.CatFileFlipTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -171,37 +140,21 @@ var _ = Describe("Cat file flip transformer", func() {
|
||||
})
|
||||
|
||||
It("persists cat file flip model", func() {
|
||||
converter := &flip_mocks.MockCatFileFlipConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileFlipLog})
|
||||
repository := &flip_mocks.MockCatFileFlipRepository{}
|
||||
fakeHeader := core.Header{BlockNumber: 1, Id: 2}
|
||||
repository.SetMissingHeaders([]core.Header{fakeHeader})
|
||||
transformer := flip.CatFileFlipTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
converter.SetReturnModels([]interface{}{test_data.CatFileFlipModel})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]flip.CatFileFlipModel{test_data.CatFileFlipModel}))
|
||||
Expect(repository.PassedHeaderID).To(Equal(headerOne.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]interface{}{test_data.CatFileFlipModel}))
|
||||
})
|
||||
|
||||
It("returns error if repository returns error for create", func() {
|
||||
converter := &flip_mocks.MockCatFileFlipConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFileFlipLog})
|
||||
repository := &flip_mocks.MockCatFileFlipRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetCreateError(fakes.FakeError)
|
||||
transformer := flip.CatFileFlipTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
|
@ -25,34 +25,34 @@ import (
|
||||
)
|
||||
|
||||
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() {
|
||||
converter := pit_vow.CatFilePitVowConverter{}
|
||||
badLog := types.Log{
|
||||
Data: []byte{1, 1, 1, 1, 1},
|
||||
}
|
||||
|
||||
_, err := converter.ToModels([]types.Log{badLog})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
|
||||
It("returns err if log is missing data", func() {
|
||||
converter := pit_vow.CatFilePitVowConverter{}
|
||||
badLog := types.Log{
|
||||
Topics: []common.Hash{{}, {}, {}, {}},
|
||||
}
|
||||
|
||||
_, err := converter.ToModels([]types.Log{badLog})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
|
||||
It("converts a log to an model", func() {
|
||||
converter := pit_vow.CatFilePitVowConverter{}
|
||||
|
||||
model, err := converter.ToModels([]types.Log{test_data.EthCatFilePitVowLog})
|
||||
models, err := converter.ToModels([]types.Log{test_data.EthCatFilePitVowLog})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(model).To(Equal([]pit_vow.CatFilePitVowModel{test_data.CatFilePitVowModel}))
|
||||
Expect(models).To(Equal([]interface{}{test_data.CatFilePitVowModel}))
|
||||
})
|
||||
})
|
||||
|
@ -15,6 +15,8 @@
|
||||
package pit_vow_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
@ -25,3 +27,7 @@ func TestPitVow(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "PitVow Suite")
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
log.SetOutput(ioutil.Discard)
|
||||
})
|
||||
|
@ -42,7 +42,8 @@ var _ = Describe("Cat file pit vow repository", func() {
|
||||
db = test_config.NewTestDB(test_config.NewTestNode())
|
||||
test_config.CleanTestDB(db)
|
||||
headerRepository = repositories.NewHeaderRepository(db)
|
||||
catFileRepository = pit_vow.NewCatFilePitVowRepository(db)
|
||||
catFileRepository = pit_vow.CatFilePitVowRepository{}
|
||||
catFileRepository.SetDB(db)
|
||||
})
|
||||
|
||||
Describe("Create", func() {
|
||||
@ -52,7 +53,7 @@ var _ = Describe("Cat file pit vow repository", func() {
|
||||
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||
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())
|
||||
})
|
||||
|
||||
@ -75,7 +76,7 @@ var _ = Describe("Cat file pit vow repository", 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.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() {
|
||||
catFilePitVow := test_data.CatFilePitVowModel
|
||||
catFilePitVow.LogIndex = catFilePitVow.LogIndex + 1
|
||||
err = catFileRepository.Create(headerID, []pit_vow.CatFilePitVowModel{catFilePitVow})
|
||||
err = catFileRepository.Create(headerID, []interface{}{catFilePitVow})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
@ -186,7 +187,8 @@ var _ = Describe("Cat file pit vow repository", func() {
|
||||
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||
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])
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
@ -19,42 +19,57 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
|
||||
"math/rand"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"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/shared"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
"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() {
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
repository := &pit_vow_mocks.MockCatFilePitVowRepository{}
|
||||
transformer := pit_vow.CatFilePitVowTransformer{
|
||||
Config: cat_file.CatFileConfig,
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &pit_vow_mocks.MockCatFilePitVowConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
var (
|
||||
config = pit_vow.CatFilePitVowConfig
|
||||
repository mocks.MockRepository
|
||||
converter mocks.MockConverter
|
||||
fetcher mocks.MockLogFetcher
|
||||
transformer shared.Transformer
|
||||
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()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.PassedStartingBlockNumber).To(Equal(cat_file.CatFileConfig.StartingBlockNumber))
|
||||
Expect(repository.PassedEndingBlockNumber).To(Equal(cat_file.CatFileConfig.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 := &pit_vow_mocks.MockCatFilePitVowRepository{}
|
||||
repository.SetMissingHeadersErr(fakes.FakeError)
|
||||
transformer := pit_vow.CatFilePitVowTransformer{
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &pit_vow_mocks.MockCatFilePitVowConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeadersError(fakes.FakeError)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -63,33 +78,20 @@ var _ = Describe("Cat file pit vow transformer", func() {
|
||||
})
|
||||
|
||||
It("fetches logs for missing headers", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
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,
|
||||
}
|
||||
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{cat_file.CatFileConfig.ContractAddresses, cat_file.CatFileConfig.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.CatFilePitVowSignature)}}))
|
||||
})
|
||||
|
||||
It("returns error if fetcher returns error", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetcherError(fakes.FakeError)
|
||||
repository := &pit_vow_mocks.MockCatFilePitVowRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := pit_vow.CatFilePitVowTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: &pit_vow_mocks.MockCatFilePitVowConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -98,34 +100,17 @@ var _ = Describe("Cat file pit vow transformer", func() {
|
||||
})
|
||||
|
||||
It("marks header checked if no logs returned", func() {
|
||||
mockConverter := &pit_vow_mocks.MockCatFilePitVowConverter{}
|
||||
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,
|
||||
}
|
||||
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 := &pit_vow_mocks.MockCatFilePitVowConverter{}
|
||||
mockRepository := &pit_vow_mocks.MockCatFilePitVowRepository{}
|
||||
mockRepository.SetMissingHeaders([]core.Header{{Id: int64(123)}})
|
||||
mockRepository.SetMarkHeaderCheckedErr(fakes.FakeError)
|
||||
mockFetcher := &mocks.MockLogFetcher{}
|
||||
transformer := pit_vow.CatFilePitVowTransformer{
|
||||
Converter: mockConverter,
|
||||
Fetcher: mockFetcher,
|
||||
Repository: mockRepository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetMarkHeaderCheckedError(fakes.FakeError)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -134,16 +119,8 @@ var _ = Describe("Cat file pit vow transformer", func() {
|
||||
})
|
||||
|
||||
It("converts matching logs", func() {
|
||||
converter := &pit_vow_mocks.MockCatFilePitVowConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFilePitVowLog})
|
||||
repository := &pit_vow_mocks.MockCatFilePitVowRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := pit_vow.CatFilePitVowTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -152,17 +129,9 @@ var _ = Describe("Cat file pit vow transformer", func() {
|
||||
})
|
||||
|
||||
It("returns error if converter returns error", func() {
|
||||
converter := &pit_vow_mocks.MockCatFilePitVowConverter{}
|
||||
converter.SetConverterError(fakes.FakeError)
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFilePitVowLog})
|
||||
repository := &pit_vow_mocks.MockCatFilePitVowRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := pit_vow.CatFilePitVowTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -171,37 +140,21 @@ var _ = Describe("Cat file pit vow transformer", func() {
|
||||
})
|
||||
|
||||
It("persists cat file pit vow model", func() {
|
||||
converter := &pit_vow_mocks.MockCatFilePitVowConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthCatFilePitVowLog})
|
||||
repository := &pit_vow_mocks.MockCatFilePitVowRepository{}
|
||||
fakeHeader := core.Header{BlockNumber: 1, Id: 2}
|
||||
repository.SetMissingHeaders([]core.Header{fakeHeader})
|
||||
transformer := pit_vow.CatFilePitVowTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
converter.SetReturnModels([]interface{}{test_data.CatFilePitVowModel})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]pit_vow.CatFilePitVowModel{test_data.CatFilePitVowModel}))
|
||||
Expect(repository.PassedHeaderID).To(Equal(headerOne.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]interface{}{test_data.CatFilePitVowModel}))
|
||||
})
|
||||
|
||||
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})
|
||||
repository := &pit_vow_mocks.MockCatFilePitVowRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetCreateError(fakes.FakeError)
|
||||
transformer := pit_vow.CatFilePitVowTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
package integration_tests
|
||||
|
||||
import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
"sort"
|
||||
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
@ -24,7 +26,6 @@ import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
"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/flip"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/pit_vow"
|
||||
@ -56,12 +57,17 @@ var _ = Describe("Cat File transformer", func() {
|
||||
err = persistHeader(db, chopLumpBlockNumber)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
config := cat_file.CatFileConfig
|
||||
config := chop_lump.CatFileChopLumpConfig
|
||||
config.StartingBlockNumber = chopLumpBlockNumber
|
||||
config.EndingBlockNumber = chopLumpBlockNumber
|
||||
|
||||
initializer := chop_lump.CatFileChopLumpTransformerInitializer{Config: config}
|
||||
transformer := initializer.NewCatFileChopLumpTransformer(db, blockchain)
|
||||
initializer := factories.Transformer{
|
||||
Config: config,
|
||||
Converter: &chop_lump.CatFileChopLumpConverter{},
|
||||
Repository: &chop_lump.CatFileChopLumpRepository{},
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}
|
||||
transformer := initializer.NewTransformer(db, blockchain)
|
||||
err := transformer.Execute()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
@ -89,12 +95,17 @@ var _ = Describe("Cat File transformer", func() {
|
||||
err = persistHeader(db, flipBlockNumber)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
config := cat_file.CatFileConfig
|
||||
config := flip.CatFileFlipConfig
|
||||
config.StartingBlockNumber = flipBlockNumber
|
||||
config.EndingBlockNumber = flipBlockNumber
|
||||
|
||||
initializer := flip.CatFileFlipTransformerInitializer{Config: config}
|
||||
transformer := initializer.NewCatFileFlipTransformer(db, blockchain)
|
||||
initializer := factories.Transformer{
|
||||
Config: config,
|
||||
Converter: &flip.CatFileFlipConverter{},
|
||||
Repository: &flip.CatFileFlipRepository{},
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}
|
||||
transformer := initializer.NewTransformer(db, blockchain)
|
||||
err := transformer.Execute()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
@ -114,12 +125,17 @@ var _ = Describe("Cat File transformer", func() {
|
||||
err = persistHeader(db, pitVowBlockNumber)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
config := cat_file.CatFileConfig
|
||||
config := pit_vow.CatFilePitVowConfig
|
||||
config.StartingBlockNumber = pitVowBlockNumber
|
||||
config.EndingBlockNumber = pitVowBlockNumber
|
||||
|
||||
initializer := pit_vow.CatFilePitVowTransformerInitializer{Config: config}
|
||||
transformer := initializer.NewCatFilePitVowTransformer(db, blockchain)
|
||||
initializer := factories.Transformer{
|
||||
Config: config,
|
||||
Converter: &pit_vow.CatFilePitVowConverter{},
|
||||
Repository: &pit_vow.CatFilePitVowRepository{},
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}
|
||||
transformer := initializer.NewTransformer(db, blockchain)
|
||||
err := transformer.Execute()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user