Update vat_move tests

This commit is contained in:
Edvard 2018-10-09 16:04:32 +02:00
parent af1dfbc489
commit 155569a1d8
2 changed files with 30 additions and 31 deletions

View File

@ -38,7 +38,7 @@ var _ = Describe("Vat Move", func() {
db = test_config.NewTestDB(core.Node{}) db = test_config.NewTestDB(core.Node{})
test_config.CleanTestDB(db) test_config.CleanTestDB(db)
headerRepository = repositories.NewHeaderRepository(db) headerRepository = repositories.NewHeaderRepository(db)
vatMoveRepository = vat_move.NewVatMoveRepository(db) vatMoveRepository = vat_move.VatMoveRepository{DB: db}
}) })
Describe("Create", func() { Describe("Create", func() {
@ -48,7 +48,7 @@ var _ = Describe("Vat Move", func() {
BeforeEach(func() { BeforeEach(func() {
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
err = vatMoveRepository.Create(headerID, []vat_move.VatMoveModel{test_data.VatMoveModel}) err = vatMoveRepository.Create(headerID, []interface{}{test_data.VatMoveModel})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
@ -71,7 +71,7 @@ var _ = Describe("Vat Move", func() {
}) })
It("returns an error if insertion fails", func() { It("returns an error if insertion fails", func() {
err = vatMoveRepository.Create(headerID, []vat_move.VatMoveModel{test_data.VatMoveModel}) err = vatMoveRepository.Create(headerID, []interface{}{test_data.VatMoveModel})
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"))
}) })
@ -145,8 +145,8 @@ var _ = Describe("Vat Move", func() {
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n)) _, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
} }
vatMoveRepositoryTwo := vat_move.NewVatMoveRepository(dbTwo) vatMoveRepositoryTwo := vat_move.VatMoveRepository{DB: dbTwo}
err := vatMoveRepository.Create(headerIDs[0], []vat_move.VatMoveModel{test_data.VatMoveModel}) err := vatMoveRepository.Create(headerIDs[0], []interface{}{test_data.VatMoveModel})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
nodeOneMissingHeaders, err := vatMoveRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) nodeOneMissingHeaders, err := vatMoveRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1])
@ -157,7 +157,6 @@ var _ = Describe("Vat Move", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers))) Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers)))
}) })
}) })
Describe("MarkHeaderChecked", func() { Describe("MarkHeaderChecked", func() {

View File

@ -21,6 +21,7 @@ import (
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"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/factories"
"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"
@ -45,12 +46,12 @@ var _ = Describe("Vat move transformer", func() {
}) })
It("gets missing headers for block numbers specified in config", func() { It("gets missing headers for block numbers specified in config", func() {
transformer := vat_move.VatMoveTransformer{ transformer := factories.Transformer{
Config: config, Config: vat_move.VatMoveConfig,
Converter: &converter, Converter: &converter,
Fetcher: &fetcher,
Repository: &repository, Repository: &repository,
} Fetcher: &fetcher,
}.NewTransformer(nil, nil)
err := transformer.Execute() err := transformer.Execute()
@ -61,13 +62,12 @@ var _ = Describe("Vat move transformer", func() {
It("returns error if repository returns error for missing headers", func() { It("returns error if repository returns error for missing headers", func() {
repository.SetMissingHeadersError(fakes.FakeError) repository.SetMissingHeadersError(fakes.FakeError)
transformer := vat_move.VatMoveTransformer{ transformer := factories.Transformer{
Config: config, Config: config,
Converter: &converter, Converter: &converter,
Fetcher: &fetcher, Fetcher: &fetcher,
Repository: &repository, Repository: &repository,
} }.NewTransformer(nil, nil)
err := transformer.Execute() err := transformer.Execute()
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
@ -76,12 +76,12 @@ var _ = Describe("Vat move transformer", func() {
It("fetches logs for missing headers", func() { It("fetches logs for missing headers", func() {
repository.SetMissingHeaders([]core.Header{headerOne, headerTwo}) repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
transformer := vat_move.VatMoveTransformer{ transformer := factories.Transformer{
Config: config, Config: config,
Fetcher: &fetcher, Fetcher: &fetcher,
Converter: &vat_move_mocks.MockVatMoveConverter{}, Converter: &converter,
Repository: &repository, Repository: &repository,
} }.NewTransformer(nil, nil)
err := transformer.Execute() err := transformer.Execute()
@ -97,12 +97,12 @@ var _ = Describe("Vat move transformer", func() {
It("returns error if fetcher returns error", func() { It("returns error if fetcher returns error", func() {
fetcher.SetFetcherError(fakes.FakeError) fetcher.SetFetcherError(fakes.FakeError)
repository.SetMissingHeaders([]core.Header{headerOne}) repository.SetMissingHeaders([]core.Header{headerOne})
transformer := vat_move.VatMoveTransformer{ transformer := factories.Transformer{
Config: config, Config: config,
Fetcher: &fetcher, Fetcher: &fetcher,
Converter: &converter, Converter: &converter,
Repository: &repository, Repository: &repository,
} }.NewTransformer(nil, nil)
err := transformer.Execute() err := transformer.Execute()
@ -113,12 +113,12 @@ var _ = Describe("Vat move transformer", func() {
It("converts matching logs", func() { It("converts matching logs", func() {
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatMoveLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthVatMoveLog})
repository.SetMissingHeaders([]core.Header{headerOne}) repository.SetMissingHeaders([]core.Header{headerOne})
transformer := vat_move.VatMoveTransformer{ transformer := factories.Transformer{
Config: config, Config: config,
Fetcher: &fetcher, Fetcher: &fetcher,
Converter: &converter, Converter: &converter,
Repository: &repository, Repository: &repository,
} }.NewTransformer(nil, nil)
err := transformer.Execute() err := transformer.Execute()
@ -130,12 +130,12 @@ var _ = Describe("Vat move transformer", func() {
converter.SetConverterError(fakes.FakeError) converter.SetConverterError(fakes.FakeError)
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatMoveLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthVatMoveLog})
repository.SetMissingHeaders([]core.Header{headerOne}) repository.SetMissingHeaders([]core.Header{headerOne})
transformer := vat_move.VatMoveTransformer{ transformer := factories.Transformer{
Config: config, Config: config,
Fetcher: &fetcher, Fetcher: &fetcher,
Converter: &converter, Converter: &converter,
Repository: &repository, Repository: &repository,
} }.NewTransformer(nil, nil)
err := transformer.Execute() err := transformer.Execute()
@ -146,12 +146,12 @@ var _ = Describe("Vat move transformer", func() {
It("marks header as checked even if no logs were returned", func() { It("marks header as checked even if no logs were returned", func() {
repository.SetMissingHeaders([]core.Header{headerOne, headerTwo}) repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
fetcher.SetFetchedLogs([]types.Log{}) fetcher.SetFetchedLogs([]types.Log{})
transformer := vat_move.VatMoveTransformer{ transformer := factories.Transformer{
Config: config, Config: config,
Converter: &converter, Converter: &converter,
Fetcher: &fetcher, Fetcher: &fetcher,
Repository: &repository, Repository: &repository,
} }.NewTransformer(nil, nil)
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
@ -163,12 +163,12 @@ var _ = Describe("Vat move transformer", func() {
repository.SetMissingHeaders([]core.Header{headerOne, headerTwo}) repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
repository.SetCheckedHeaderError(fakes.FakeError) repository.SetCheckedHeaderError(fakes.FakeError)
fetcher.SetFetchedLogs([]types.Log{}) fetcher.SetFetchedLogs([]types.Log{})
transformer := vat_move.VatMoveTransformer{ transformer := factories.Transformer{
Config: config, Config: config,
Converter: &converter, Converter: &converter,
Fetcher: &fetcher, Fetcher: &fetcher,
Repository: &repository, Repository: &repository,
} }.NewTransformer(nil, nil)
err := transformer.Execute() err := transformer.Execute()
@ -179,30 +179,30 @@ var _ = Describe("Vat move transformer", func() {
It("persists vat move model", func() { It("persists vat move model", func() {
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatMoveLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthVatMoveLog})
repository.SetMissingHeaders([]core.Header{headerOne}) repository.SetMissingHeaders([]core.Header{headerOne})
transformer := vat_move.VatMoveTransformer{ transformer := factories.Transformer{
Config: config, Config: config,
Fetcher: &fetcher, Fetcher: &fetcher,
Converter: &converter, Converter: &converter,
Repository: &repository, Repository: &repository,
} }.NewTransformer(nil, nil)
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(repository.PassedHeaderID).To(Equal(headerOne.Id)) Expect(repository.PassedHeaderID).To(Equal(headerOne.Id))
Expect(repository.PassedModels).To(Equal([]vat_move.VatMoveModel{test_data.VatMoveModel})) Expect(repository.PassedModels).To(Equal([]interface{}{test_data.VatMoveModel}))
}) })
It("returns error if repository returns error for create", func() { It("returns error if repository returns error for create", func() {
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatMoveLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthVatMoveLog})
repository.SetMissingHeaders([]core.Header{headerOne}) repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetCreateError(fakes.FakeError) repository.SetCreateError(fakes.FakeError)
transformer := vat_move.VatMoveTransformer{ transformer := factories.Transformer{
Config: config, Config: config,
Fetcher: &fetcher, Fetcher: &fetcher,
Converter: &converter, Converter: &converter,
Repository: &repository, Repository: &repository,
} }.NewTransformer(nil, nil)
err := transformer.Execute() err := transformer.Execute()