From 7ee3329bafb385e858c5d58325f01e86f401eb01 Mon Sep 17 00:00:00 2001 From: Edvard Date: Mon, 22 Oct 2018 15:03:41 +0200 Subject: [PATCH] Privatise DB repository field and add transformer test --- pkg/transformers/drip_file/ilk/repository.go | 12 ++++++------ .../drip_file/ilk/repository_test.go | 16 ++++------------ .../drip_file/ilk/transformer_test.go | 7 ++++++- pkg/transformers/drip_file/repo/repository.go | 12 ++++++------ .../drip_file/repo/repository_test.go | 16 ++++------------ .../drip_file/repo/transformer_test.go | 7 ++++++- pkg/transformers/drip_file/vow/repository.go | 12 ++++++------ .../drip_file/vow/repository_test.go | 16 ++++------------ .../drip_file/vow/transformer_test.go | 7 ++++++- .../pit_file/debt_ceiling/repository.go | 12 ++++++------ .../pit_file/debt_ceiling/repository_test.go | 13 +++++++------ .../pit_file/debt_ceiling/transformer_test.go | 7 ++++++- pkg/transformers/pit_file/ilk/repository.go | 12 ++++++------ pkg/transformers/pit_file/ilk/repository_test.go | 6 ++++-- .../pit_file/ilk/transformer_test.go | 5 +++++ .../pit_file/stability_fee/repository.go | 12 ++++++------ .../pit_file/stability_fee/repository_test.go | 6 ++++-- .../pit_file/stability_fee/transformer_test.go | 5 +++++ pkg/transformers/tend/repository.go | 12 ++++++------ pkg/transformers/tend/repository_test.go | 6 ++++-- pkg/transformers/tend/transformer_test.go | 5 +++++ .../test_data/mocks/drip_file/ilk/repository.go | 5 ++++- .../test_data/mocks/drip_file/repo/repository.go | 5 ++++- .../test_data/mocks/drip_file/vow/repository.go | 5 ++++- pkg/transformers/test_data/mocks/log_fetcher.go | 5 ++++- .../mocks/pit_file/debt_ceiling/repository.go | 5 ++++- .../test_data/mocks/pit_file/ilk/repository.go | 5 ++++- .../mocks/pit_file/stability_fee/repository.go | 5 ++++- .../test_data/mocks/tend/repository.go | 5 ++++- .../test_data/mocks/vat_init/repository.go | 5 ++++- .../test_data/mocks/vat_move/repository.go | 5 ++++- pkg/transformers/vat_init/repository.go | 12 ++++++------ pkg/transformers/vat_init/repository_test.go | 15 ++++----------- pkg/transformers/vat_init/transformer_test.go | 5 +++++ pkg/transformers/vat_move/repository.go | 12 ++++++------ pkg/transformers/vat_move/repository_test.go | 15 ++++----------- pkg/transformers/vat_move/transformer_test.go | 5 +++++ 37 files changed, 182 insertions(+), 138 deletions(-) diff --git a/pkg/transformers/drip_file/ilk/repository.go b/pkg/transformers/drip_file/ilk/repository.go index 64480ba3..bde2d152 100644 --- a/pkg/transformers/drip_file/ilk/repository.go +++ b/pkg/transformers/drip_file/ilk/repository.go @@ -21,11 +21,11 @@ import ( ) type DripFileIlkRepository struct { - DB *postgres.DB + db *postgres.DB } func (repository DripFileIlkRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.DB.Begin() + tx, err := repository.db.Begin() if err != nil { return err } @@ -61,7 +61,7 @@ func (repository DripFileIlkRepository) Create(headerID int64, models []interfac } func (repository DripFileIlkRepository) MarkHeaderChecked(headerID int64) error { - _, err := repository.DB.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_ilk_checked) + _, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_ilk_checked) VALUES ($1, $2) ON CONFLICT (header_id) DO UPDATE SET drip_file_ilk_checked = $2`, headerID, true) @@ -70,7 +70,7 @@ func (repository DripFileIlkRepository) MarkHeaderChecked(headerID int64) error func (repository DripFileIlkRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { var result []core.Header - err := repository.DB.Select( + err := repository.db.Select( &result, `SELECT headers.id, headers.block_number FROM headers LEFT JOIN checked_headers on headers.id = header_id @@ -80,11 +80,11 @@ func (repository DripFileIlkRepository) MissingHeaders(startingBlockNumber, endi AND headers.eth_node_fingerprint = $3`, startingBlockNumber, endingBlockNumber, - repository.DB.Node.ID, + repository.db.Node.ID, ) return result, err } func (repository *DripFileIlkRepository) SetDB(db *postgres.DB) { - repository.DB = db + repository.db = db } diff --git a/pkg/transformers/drip_file/ilk/repository_test.go b/pkg/transformers/drip_file/ilk/repository_test.go index fb1a45aa..80245b95 100644 --- a/pkg/transformers/drip_file/ilk/repository_test.go +++ b/pkg/transformers/drip_file/ilk/repository_test.go @@ -40,7 +40,8 @@ var _ = Describe("Drip file ilk repository", func() { db = test_config.NewTestDB(test_config.NewTestNode()) test_config.CleanTestDB(db) headerRepository = repositories.NewHeaderRepository(db) - dripFileIlkRepository = ilk.DripFileIlkRepository{DB: db} + dripFileIlkRepository = ilk.DripFileIlkRepository{} + dripFileIlkRepository.SetDB(db) }) Describe("Create", func() { @@ -182,7 +183,8 @@ var _ = Describe("Drip file ilk repository", func() { _, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n)) Expect(err).NotTo(HaveOccurred()) } - dripFileIlkRepositoryTwo := ilk.DripFileIlkRepository{DB: dbTwo} + dripFileIlkRepositoryTwo := ilk.DripFileIlkRepository{} + dripFileIlkRepositoryTwo.SetDB(dbTwo) err := dripFileIlkRepository.MarkHeaderChecked(headerIDs[0]) Expect(err).NotTo(HaveOccurred()) @@ -195,14 +197,4 @@ var _ = Describe("Drip file ilk repository", func() { Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers))) }) }) - - Describe("SetDB", func() { - It("sets the repository db", func() { - db := test_config.NewTestDB(core.Node{}) - repository := ilk.DripFileIlkRepository{} - Expect(repository.DB).To(BeNil()) - repository.SetDB(db) - Expect(repository.DB).To(Equal(db)) - }) - }) }) diff --git a/pkg/transformers/drip_file/ilk/transformer_test.go b/pkg/transformers/drip_file/ilk/transformer_test.go index 8089fb67..f6547bd8 100644 --- a/pkg/transformers/drip_file/ilk/transformer_test.go +++ b/pkg/transformers/drip_file/ilk/transformer_test.go @@ -50,11 +50,16 @@ var _ = Describe("Drip file ilk transformer", func() { Fetcher: &fetcher, Converter: &converter, Repository: &repository, - } + }.NewTransformer(nil, nil) headerOne = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()} headerTwo = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()} }) + 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() diff --git a/pkg/transformers/drip_file/repo/repository.go b/pkg/transformers/drip_file/repo/repository.go index 03740b40..e7e03cb1 100644 --- a/pkg/transformers/drip_file/repo/repository.go +++ b/pkg/transformers/drip_file/repo/repository.go @@ -21,11 +21,11 @@ import ( ) type DripFileRepoRepository struct { - DB *postgres.DB + db *postgres.DB } func (repository DripFileRepoRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.DB.Begin() + tx, err := repository.db.Begin() if err != nil { return err } @@ -63,7 +63,7 @@ func (repository DripFileRepoRepository) Create(headerID int64, models []interfa } func (repository DripFileRepoRepository) MarkHeaderChecked(headerID int64) error { - _, err := repository.DB.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_repo_checked) + _, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_repo_checked) VALUES ($1, $2) ON CONFLICT (header_id) DO UPDATE SET drip_file_repo_checked = $2`, headerID, true) @@ -72,7 +72,7 @@ func (repository DripFileRepoRepository) MarkHeaderChecked(headerID int64) error func (repository DripFileRepoRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { var result []core.Header - err := repository.DB.Select( + err := repository.db.Select( &result, `SELECT headers.id, headers.block_number FROM headers LEFT JOIN checked_headers on headers.id = header_id @@ -82,11 +82,11 @@ func (repository DripFileRepoRepository) MissingHeaders(startingBlockNumber, end AND headers.eth_node_fingerprint = $3`, startingBlockNumber, endingBlockNumber, - repository.DB.Node.ID, + repository.db.Node.ID, ) return result, err } func (repository *DripFileRepoRepository) SetDB(db *postgres.DB) { - repository.DB = db + repository.db = db } diff --git a/pkg/transformers/drip_file/repo/repository_test.go b/pkg/transformers/drip_file/repo/repository_test.go index 126486c1..6b690c3d 100644 --- a/pkg/transformers/drip_file/repo/repository_test.go +++ b/pkg/transformers/drip_file/repo/repository_test.go @@ -42,7 +42,8 @@ var _ = Describe("Drip file repo repository", func() { db = test_config.NewTestDB(core.Node{}) test_config.CleanTestDB(db) headerRepository = repositories.NewHeaderRepository(db) - dripFileRepoRepository = repo.DripFileRepoRepository{DB: db} + dripFileRepoRepository = repo.DripFileRepoRepository{} + dripFileRepoRepository.SetDB(db) }) Describe("Create", func() { @@ -182,7 +183,8 @@ var _ = Describe("Drip file repo repository", func() { _, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n)) Expect(err).NotTo(HaveOccurred()) } - dripFileRepoRepositoryTwo := repo.DripFileRepoRepository{DB: dbTwo} + dripFileRepoRepositoryTwo := repo.DripFileRepoRepository{} + dripFileRepoRepositoryTwo.SetDB(dbTwo) err := dripFileRepoRepository.MarkHeaderChecked(headerIDs[0]) Expect(err).NotTo(HaveOccurred()) @@ -195,14 +197,4 @@ var _ = Describe("Drip file repo repository", func() { Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers))) }) }) - - Describe("SetDB", func() { - It("sets the repository db", func() { - db := test_config.NewTestDB(core.Node{}) - repository := repo.DripFileRepoRepository{} - Expect(repository.DB).To(BeNil()) - repository.SetDB(db) - Expect(repository.DB).To(Equal(db)) - }) - }) }) diff --git a/pkg/transformers/drip_file/repo/transformer_test.go b/pkg/transformers/drip_file/repo/transformer_test.go index a98a06bf..14a16475 100644 --- a/pkg/transformers/drip_file/repo/transformer_test.go +++ b/pkg/transformers/drip_file/repo/transformer_test.go @@ -50,11 +50,16 @@ var _ = Describe("Drip file repo transformer", func() { Fetcher: &fetcher, Converter: &converter, Repository: &repository, - } + }.NewTransformer(nil, nil) headerOne = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()} headerTwo = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()} }) + 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() diff --git a/pkg/transformers/drip_file/vow/repository.go b/pkg/transformers/drip_file/vow/repository.go index 8d9cc0ef..32a4140a 100644 --- a/pkg/transformers/drip_file/vow/repository.go +++ b/pkg/transformers/drip_file/vow/repository.go @@ -21,11 +21,11 @@ import ( ) type DripFileVowRepository struct { - DB *postgres.DB + db *postgres.DB } func (repository DripFileVowRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.DB.Begin() + tx, err := repository.db.Begin() if err != nil { return err } @@ -62,7 +62,7 @@ func (repository DripFileVowRepository) Create(headerID int64, models []interfac } func (repository DripFileVowRepository) MarkHeaderChecked(headerID int64) error { - _, err := repository.DB.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_vow_checked) + _, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_vow_checked) VALUES ($1, $2) ON CONFLICT (header_id) DO UPDATE SET drip_file_vow_checked = $2`, headerID, true) @@ -71,7 +71,7 @@ func (repository DripFileVowRepository) MarkHeaderChecked(headerID int64) error func (repository DripFileVowRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { var result []core.Header - err := repository.DB.Select( + err := repository.db.Select( &result, `SELECT headers.id, headers.block_number FROM headers LEFT JOIN checked_headers on headers.id = header_id @@ -81,11 +81,11 @@ func (repository DripFileVowRepository) MissingHeaders(startingBlockNumber, endi AND headers.eth_node_fingerprint = $3`, startingBlockNumber, endingBlockNumber, - repository.DB.Node.ID, + repository.db.Node.ID, ) return result, err } func (repository *DripFileVowRepository) SetDB(db *postgres.DB) { - repository.DB = db + repository.db = db } diff --git a/pkg/transformers/drip_file/vow/repository_test.go b/pkg/transformers/drip_file/vow/repository_test.go index 70ddeb6e..0eb48545 100644 --- a/pkg/transformers/drip_file/vow/repository_test.go +++ b/pkg/transformers/drip_file/vow/repository_test.go @@ -42,7 +42,8 @@ var _ = Describe("Drip file vow repository", func() { db = test_config.NewTestDB(core.Node{}) test_config.CleanTestDB(db) headerRepository = repositories.NewHeaderRepository(db) - dripFileVowRepository = vow.DripFileVowRepository{DB: db} + dripFileVowRepository = vow.DripFileVowRepository{} + dripFileVowRepository.SetDB(db) }) Describe("Create", func() { @@ -182,7 +183,8 @@ var _ = Describe("Drip file vow repository", func() { _, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n)) Expect(err).NotTo(HaveOccurred()) } - dripFileVowRepositoryTwo := vow.DripFileVowRepository{DB: dbTwo} + dripFileVowRepositoryTwo := vow.DripFileVowRepository{} + dripFileVowRepositoryTwo.SetDB(dbTwo) err := dripFileVowRepository.MarkHeaderChecked(headerIDs[0]) Expect(err).NotTo(HaveOccurred()) @@ -195,14 +197,4 @@ var _ = Describe("Drip file vow repository", func() { Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers))) }) }) - - Describe("SetDB", func() { - It("sets the repository db", func() { - db := test_config.NewTestDB(core.Node{}) - repository := vow.DripFileVowRepository{} - Expect(repository.DB).To(BeNil()) - repository.SetDB(db) - Expect(repository.DB).To(Equal(db)) - }) - }) }) diff --git a/pkg/transformers/drip_file/vow/transformer_test.go b/pkg/transformers/drip_file/vow/transformer_test.go index 4d9e7d23..40b92736 100644 --- a/pkg/transformers/drip_file/vow/transformer_test.go +++ b/pkg/transformers/drip_file/vow/transformer_test.go @@ -50,11 +50,16 @@ var _ = Describe("Drip file vow transformer", func() { Fetcher: &fetcher, Converter: &converter, Repository: &repository, - } + }.NewTransformer(nil, nil) headerOne = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()} headerTwo = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()} }) + 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() diff --git a/pkg/transformers/pit_file/debt_ceiling/repository.go b/pkg/transformers/pit_file/debt_ceiling/repository.go index d0d28dd6..14b59c16 100644 --- a/pkg/transformers/pit_file/debt_ceiling/repository.go +++ b/pkg/transformers/pit_file/debt_ceiling/repository.go @@ -21,11 +21,11 @@ import ( ) type PitFileDebtCeilingRepository struct { - DB *postgres.DB + db *postgres.DB } func (repository PitFileDebtCeilingRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.DB.Begin() + tx, err := repository.db.Begin() if err != nil { return err } @@ -63,7 +63,7 @@ func (repository PitFileDebtCeilingRepository) Create(headerID int64, models []i } func (repository PitFileDebtCeilingRepository) MarkHeaderChecked(headerID int64) error { - _, err := repository.DB.Exec(`INSERT INTO public.checked_headers (header_id, pit_file_debt_ceiling_checked) + _, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, pit_file_debt_ceiling_checked) VALUES ($1, $2) ON CONFLICT (header_id) DO UPDATE SET pit_file_debt_ceiling_checked = $2`, headerID, true) @@ -72,7 +72,7 @@ func (repository PitFileDebtCeilingRepository) MarkHeaderChecked(headerID int64) func (repository PitFileDebtCeilingRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { var result []core.Header - err := repository.DB.Select( + err := repository.db.Select( &result, `SELECT headers.id, headers.block_number FROM headers LEFT JOIN checked_headers on headers.id = header_id @@ -82,11 +82,11 @@ func (repository PitFileDebtCeilingRepository) MissingHeaders(startingBlockNumbe AND headers.eth_node_fingerprint = $3`, startingBlockNumber, endingBlockNumber, - repository.DB.Node.ID, + repository.db.Node.ID, ) return result, err } func (repository *PitFileDebtCeilingRepository) SetDB(db *postgres.DB) { - repository.DB = db + repository.db = db } diff --git a/pkg/transformers/pit_file/debt_ceiling/repository_test.go b/pkg/transformers/pit_file/debt_ceiling/repository_test.go index 86f5149f..33dcaf95 100644 --- a/pkg/transformers/pit_file/debt_ceiling/repository_test.go +++ b/pkg/transformers/pit_file/debt_ceiling/repository_test.go @@ -42,7 +42,8 @@ var _ = Describe("Pit file debt ceiling repository", func() { db = test_config.NewTestDB(core.Node{}) test_config.CleanTestDB(db) headerRepository = repositories.NewHeaderRepository(db) - pitFileDebtCeilingRepository = debt_ceiling.PitFileDebtCeilingRepository{DB: db} + pitFileDebtCeilingRepository = debt_ceiling.PitFileDebtCeilingRepository{} + pitFileDebtCeilingRepository.SetDB(db) }) Describe("Create", func() { @@ -182,16 +183,16 @@ var _ = Describe("Pit file debt ceiling repository", func() { _, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n)) Expect(err).NotTo(HaveOccurred()) } - pitFileRepository := debt_ceiling.PitFileDebtCeilingRepository{DB: db} - pitFileRepositoryTwo := debt_ceiling.PitFileDebtCeilingRepository{DB: dbTwo} - err := pitFileRepository.MarkHeaderChecked(headerIDs[0]) + pitFileDebtCeilingRepositoryTwo := debt_ceiling.PitFileDebtCeilingRepository{} + pitFileDebtCeilingRepositoryTwo.SetDB(dbTwo) + err := pitFileDebtCeilingRepository.MarkHeaderChecked(headerIDs[0]) Expect(err).NotTo(HaveOccurred()) - nodeOneMissingHeaders, err := pitFileRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) + nodeOneMissingHeaders, err := pitFileDebtCeilingRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) Expect(err).NotTo(HaveOccurred()) Expect(len(nodeOneMissingHeaders)).To(Equal(len(blockNumbers) - 1)) - nodeTwoMissingHeaders, err := pitFileRepositoryTwo.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) + nodeTwoMissingHeaders, err := pitFileDebtCeilingRepositoryTwo.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1]) Expect(err).NotTo(HaveOccurred()) Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers))) }) diff --git a/pkg/transformers/pit_file/debt_ceiling/transformer_test.go b/pkg/transformers/pit_file/debt_ceiling/transformer_test.go index 96c9d9d1..59938c18 100644 --- a/pkg/transformers/pit_file/debt_ceiling/transformer_test.go +++ b/pkg/transformers/pit_file/debt_ceiling/transformer_test.go @@ -52,7 +52,12 @@ var _ = Describe("Pit file debt ceiling transformer", func() { Fetcher: &fetcher, Converter: &converter, Repository: &repository, - } + }.NewTransformer(nil, nil) + }) + + 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() { diff --git a/pkg/transformers/pit_file/ilk/repository.go b/pkg/transformers/pit_file/ilk/repository.go index d7f19eb6..79cc6576 100644 --- a/pkg/transformers/pit_file/ilk/repository.go +++ b/pkg/transformers/pit_file/ilk/repository.go @@ -21,11 +21,11 @@ import ( ) type PitFileIlkRepository struct { - DB *postgres.DB + db *postgres.DB } func (repository PitFileIlkRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.DB.Begin() + tx, err := repository.db.Begin() if err != nil { return err } @@ -59,7 +59,7 @@ func (repository PitFileIlkRepository) Create(headerID int64, models []interface } func (repository PitFileIlkRepository) MarkHeaderChecked(headerID int64) error { - _, err := repository.DB.Exec(`INSERT INTO public.checked_headers (header_id, pit_file_ilk_checked) + _, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, pit_file_ilk_checked) VALUES ($1, $2) ON CONFLICT (header_id) DO UPDATE SET pit_file_ilk_checked = $2`, headerID, true) @@ -68,7 +68,7 @@ func (repository PitFileIlkRepository) MarkHeaderChecked(headerID int64) error { func (repository PitFileIlkRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { var result []core.Header - err := repository.DB.Select( + err := repository.db.Select( &result, `SELECT headers.id, headers.block_number FROM headers LEFT JOIN checked_headers on headers.id = header_id @@ -78,11 +78,11 @@ func (repository PitFileIlkRepository) MissingHeaders(startingBlockNumber, endin AND headers.eth_node_fingerprint = $3`, startingBlockNumber, endingBlockNumber, - repository.DB.Node.ID, + repository.db.Node.ID, ) return result, err } func (repository *PitFileIlkRepository) SetDB(db *postgres.DB) { - repository.DB = db + repository.db = db } diff --git a/pkg/transformers/pit_file/ilk/repository_test.go b/pkg/transformers/pit_file/ilk/repository_test.go index 7794f1ce..9b852970 100644 --- a/pkg/transformers/pit_file/ilk/repository_test.go +++ b/pkg/transformers/pit_file/ilk/repository_test.go @@ -42,7 +42,8 @@ var _ = Describe("Pit file ilk repository", func() { db = test_config.NewTestDB(core.Node{}) test_config.CleanTestDB(db) headerRepository = repositories.NewHeaderRepository(db) - pitFileRepository = ilk.PitFileIlkRepository{DB: db} + pitFileRepository = ilk.PitFileIlkRepository{} + pitFileRepository.SetDB(db) }) Describe("Create", func() { @@ -183,7 +184,8 @@ var _ = Describe("Pit file ilk repository", func() { Expect(err).NotTo(HaveOccurred()) } - pitFileRepositoryTwo := ilk.PitFileIlkRepository{DB: dbTwo} + pitFileRepositoryTwo := ilk.PitFileIlkRepository{} + pitFileRepositoryTwo.SetDB(dbTwo) err := pitFileRepository.MarkHeaderChecked(headerIDs[0]) Expect(err).NotTo(HaveOccurred()) diff --git a/pkg/transformers/pit_file/ilk/transformer_test.go b/pkg/transformers/pit_file/ilk/transformer_test.go index 89474d55..b98b712a 100644 --- a/pkg/transformers/pit_file/ilk/transformer_test.go +++ b/pkg/transformers/pit_file/ilk/transformer_test.go @@ -55,6 +55,11 @@ var _ = Describe("Pit file ilk transformer", func() { }.NewTransformer(nil, nil) }) + 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() diff --git a/pkg/transformers/pit_file/stability_fee/repository.go b/pkg/transformers/pit_file/stability_fee/repository.go index 2b5d1ce0..f0421175 100644 --- a/pkg/transformers/pit_file/stability_fee/repository.go +++ b/pkg/transformers/pit_file/stability_fee/repository.go @@ -21,11 +21,11 @@ import ( ) type PitFileStabilityFeeRepository struct { - DB *postgres.DB + db *postgres.DB } func (repository PitFileStabilityFeeRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.DB.Begin() + tx, err := repository.db.Begin() if err != nil { return err } @@ -63,7 +63,7 @@ func (repository PitFileStabilityFeeRepository) Create(headerID int64, models [] } func (repository PitFileStabilityFeeRepository) MarkHeaderChecked(headerID int64) error { - _, err := repository.DB.Exec(`INSERT INTO public.checked_headers (header_id, pit_file_stability_fee_checked) + _, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, pit_file_stability_fee_checked) VALUES ($1, $2) ON CONFLICT (header_id) DO UPDATE SET pit_file_stability_fee_checked = $2`, headerID, true) @@ -72,7 +72,7 @@ func (repository PitFileStabilityFeeRepository) MarkHeaderChecked(headerID int64 func (repository PitFileStabilityFeeRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { var result []core.Header - err := repository.DB.Select( + err := repository.db.Select( &result, `SELECT headers.id, headers.block_number FROM headers LEFT JOIN checked_headers on headers.id = header_id @@ -82,11 +82,11 @@ func (repository PitFileStabilityFeeRepository) MissingHeaders(startingBlockNumb AND headers.eth_node_fingerprint = $3`, startingBlockNumber, endingBlockNumber, - repository.DB.Node.ID, + repository.db.Node.ID, ) return result, err } func (repository *PitFileStabilityFeeRepository) SetDB(db *postgres.DB) { - repository.DB = db + repository.db = db } diff --git a/pkg/transformers/pit_file/stability_fee/repository_test.go b/pkg/transformers/pit_file/stability_fee/repository_test.go index 0c6fd378..068d5e74 100644 --- a/pkg/transformers/pit_file/stability_fee/repository_test.go +++ b/pkg/transformers/pit_file/stability_fee/repository_test.go @@ -42,7 +42,8 @@ var _ = Describe("Pit file stability fee repository", func() { db = test_config.NewTestDB(core.Node{}) test_config.CleanTestDB(db) headerRepository = repositories.NewHeaderRepository(db) - pitFileStabilityFeeRepository = stability_fee.PitFileStabilityFeeRepository{DB: db} + pitFileStabilityFeeRepository = stability_fee.PitFileStabilityFeeRepository{} + pitFileStabilityFeeRepository.SetDB(db) }) Describe("Create", func() { @@ -182,7 +183,8 @@ var _ = Describe("Pit file stability fee repository", func() { Expect(err).NotTo(HaveOccurred()) } - pitFileRepositoryTwo := stability_fee.PitFileStabilityFeeRepository{DB: dbTwo} + pitFileRepositoryTwo := stability_fee.PitFileStabilityFeeRepository{} + pitFileRepositoryTwo.SetDB(dbTwo) err = pitFileStabilityFeeRepository.MarkHeaderChecked(headerIDs[0]) Expect(err).NotTo(HaveOccurred()) diff --git a/pkg/transformers/pit_file/stability_fee/transformer_test.go b/pkg/transformers/pit_file/stability_fee/transformer_test.go index 633d7feb..17128054 100644 --- a/pkg/transformers/pit_file/stability_fee/transformer_test.go +++ b/pkg/transformers/pit_file/stability_fee/transformer_test.go @@ -55,6 +55,11 @@ var _ = Describe("Pit file stability fee transformer", func() { headerTwo = core.Header{Id: GinkgoRandomSeed(), BlockNumber: GinkgoRandomSeed()} }) + 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() diff --git a/pkg/transformers/tend/repository.go b/pkg/transformers/tend/repository.go index a02cb740..de1ef581 100644 --- a/pkg/transformers/tend/repository.go +++ b/pkg/transformers/tend/repository.go @@ -21,11 +21,11 @@ import ( ) type TendRepository struct { - DB *postgres.DB + db *postgres.DB } func (repository TendRepository) Create(headerId int64, models []interface{}) error { - tx, err := repository.DB.Begin() + tx, err := repository.db.Begin() if err != nil { return err } @@ -61,7 +61,7 @@ func (repository TendRepository) Create(headerId int64, models []interface{}) er } func (repository TendRepository) MarkHeaderChecked(headerId int64) error { - _, err := repository.DB.Exec(`INSERT INTO public.checked_headers (header_id, tend_checked) + _, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, tend_checked) VALUES ($1, $2) ON CONFLICT (header_id) DO UPDATE SET tend_checked = $2`, headerId, true) @@ -70,7 +70,7 @@ func (repository TendRepository) MarkHeaderChecked(headerId int64) error { func (repository TendRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { var result []core.Header - err := repository.DB.Select( + err := repository.db.Select( &result, `SELECT headers.id, headers.block_number FROM headers LEFT JOIN checked_headers on headers.id = header_id @@ -80,12 +80,12 @@ func (repository TendRepository) MissingHeaders(startingBlockNumber, endingBlock AND headers.eth_node_fingerprint = $3`, startingBlockNumber, endingBlockNumber, - repository.DB.Node.ID, + repository.db.Node.ID, ) return result, err } func (repository *TendRepository) SetDB(db *postgres.DB) { - repository.DB = db + repository.db = db } diff --git a/pkg/transformers/tend/repository_test.go b/pkg/transformers/tend/repository_test.go index 1cdc9953..e43e2d5e 100644 --- a/pkg/transformers/tend/repository_test.go +++ b/pkg/transformers/tend/repository_test.go @@ -41,7 +41,8 @@ var _ = Describe("TendRepository", func() { db = test_config.NewTestDB(node) test_config.CleanTestDB(db) headerRepository = repositories.NewHeaderRepository(db) - tendRepository = tend.TendRepository{DB: db} + tendRepository = tend.TendRepository{} + tendRepository.SetDB(db) }) Describe("Create", func() { @@ -187,7 +188,8 @@ var _ = Describe("TendRepository", func() { node2 := core.Node{} db2 := test_config.NewTestDB(node2) headerRepository2 := repositories.NewHeaderRepository(db2) - tendRepository2 := tend.TendRepository{DB: db2} + tendRepository2 := tend.TendRepository{} + tendRepository2.SetDB(db2) for _, number := range []int64{startingBlock, tendBlock, endingBlock} { headerRepository2.CreateOrUpdateHeader(fakes.GetFakeHeader(number)) diff --git a/pkg/transformers/tend/transformer_test.go b/pkg/transformers/tend/transformer_test.go index 271f040b..ff8b3ed0 100644 --- a/pkg/transformers/tend/transformer_test.go +++ b/pkg/transformers/tend/transformer_test.go @@ -56,6 +56,11 @@ var _ = Describe("Tend Transformer", func() { }.NewTransformer(nil, nil) }) + It("sets the blockchain and database", func() { + Expect(fetcher.SetBcCalled).To(BeTrue()) + Expect(repository.SetDbCalled).To(BeTrue()) + }) + It("gets missing headers for blocks in the configured range", func() { err := transformer.Execute() diff --git a/pkg/transformers/test_data/mocks/drip_file/ilk/repository.go b/pkg/transformers/test_data/mocks/drip_file/ilk/repository.go index fe96b361..3f99a840 100644 --- a/pkg/transformers/test_data/mocks/drip_file/ilk/repository.go +++ b/pkg/transformers/test_data/mocks/drip_file/ilk/repository.go @@ -31,6 +31,7 @@ type MockDripFileIlkRepository struct { PassedEndingBlockNumber int64 PassedHeaderID int64 PassedModels []interface{} + SetDbCalled bool } func (repository *MockDripFileIlkRepository) Create(headerID int64, models []interface{}) error { @@ -69,4 +70,6 @@ func (repository *MockDripFileIlkRepository) AssertMarkHeaderCheckedCalledWith(i Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i)) } -func (repository *MockDripFileIlkRepository) SetDB(db *postgres.DB) {} +func (repository *MockDripFileIlkRepository) SetDB(db *postgres.DB) { + repository.SetDbCalled = true +} diff --git a/pkg/transformers/test_data/mocks/drip_file/repo/repository.go b/pkg/transformers/test_data/mocks/drip_file/repo/repository.go index 40131fff..b1ae32c3 100644 --- a/pkg/transformers/test_data/mocks/drip_file/repo/repository.go +++ b/pkg/transformers/test_data/mocks/drip_file/repo/repository.go @@ -31,6 +31,7 @@ type MockDripFileRepoRepository struct { PassedEndingBlockNumber int64 PassedHeaderID int64 PassedModels []interface{} + SetDbCalled bool } func (repository *MockDripFileRepoRepository) Create(headerID int64, models []interface{}) error { @@ -70,4 +71,6 @@ func (repository *MockDripFileRepoRepository) AssertMarkHeaderCheckedCalledWith( Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i)) } -func (repository *MockDripFileRepoRepository) SetDB(db *postgres.DB) {} +func (repository *MockDripFileRepoRepository) SetDB(db *postgres.DB) { + repository.SetDbCalled = true +} diff --git a/pkg/transformers/test_data/mocks/drip_file/vow/repository.go b/pkg/transformers/test_data/mocks/drip_file/vow/repository.go index e365817a..2487ca42 100644 --- a/pkg/transformers/test_data/mocks/drip_file/vow/repository.go +++ b/pkg/transformers/test_data/mocks/drip_file/vow/repository.go @@ -31,6 +31,7 @@ type MockDripFileVowRepository struct { PassedEndingBlockNumber int64 PassedHeaderID int64 PassedModels []interface{} + SetDbCalled bool } func (repository *MockDripFileVowRepository) Create(headerID int64, models []interface{}) error { @@ -69,4 +70,6 @@ func (repository *MockDripFileVowRepository) AssertMarkHeaderCheckedCalledWith(i Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i)) } -func (repository *MockDripFileVowRepository) SetDB(db *postgres.DB) {} +func (repository *MockDripFileVowRepository) SetDB(db *postgres.DB) { + repository.SetDbCalled = true +} diff --git a/pkg/transformers/test_data/mocks/log_fetcher.go b/pkg/transformers/test_data/mocks/log_fetcher.go index b6b591a7..53172207 100644 --- a/pkg/transformers/test_data/mocks/log_fetcher.go +++ b/pkg/transformers/test_data/mocks/log_fetcher.go @@ -26,6 +26,7 @@ type MockLogFetcher struct { FetchedBlocks []int64 fetcherError error FetchedLogs []types.Log + SetBcCalled bool } func (mlf *MockLogFetcher) FetchLogs(contractAddresses []string, topics [][]common.Hash, blockNumber int64) ([]types.Log, error) { @@ -36,7 +37,9 @@ func (mlf *MockLogFetcher) FetchLogs(contractAddresses []string, topics [][]comm return mlf.FetchedLogs, mlf.fetcherError } -func (mlf *MockLogFetcher) SetBC(_ core.BlockChain) {} +func (mlf *MockLogFetcher) SetBC(bc core.BlockChain) { + mlf.SetBcCalled = true +} func (mlf *MockLogFetcher) SetFetcherError(err error) { mlf.fetcherError = err diff --git a/pkg/transformers/test_data/mocks/pit_file/debt_ceiling/repository.go b/pkg/transformers/test_data/mocks/pit_file/debt_ceiling/repository.go index 4ba8ec08..7c9da60f 100644 --- a/pkg/transformers/test_data/mocks/pit_file/debt_ceiling/repository.go +++ b/pkg/transformers/test_data/mocks/pit_file/debt_ceiling/repository.go @@ -31,6 +31,7 @@ type MockPitFileDebtCeilingRepository struct { PassedEndingBlockNumber int64 PassedHeaderID int64 PassedModels []interface{} + SetDbCalled bool } func (repository *MockPitFileDebtCeilingRepository) MarkHeaderChecked(headerID int64) error { @@ -70,4 +71,6 @@ func (repository *MockPitFileDebtCeilingRepository) AssertMarkHeaderCheckedCalle Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i)) } -func (repository *MockPitFileDebtCeilingRepository) SetDB(db *postgres.DB) {} +func (repository *MockPitFileDebtCeilingRepository) SetDB(db *postgres.DB) { + repository.SetDbCalled = true +} diff --git a/pkg/transformers/test_data/mocks/pit_file/ilk/repository.go b/pkg/transformers/test_data/mocks/pit_file/ilk/repository.go index 0ab6fc75..311b01a5 100644 --- a/pkg/transformers/test_data/mocks/pit_file/ilk/repository.go +++ b/pkg/transformers/test_data/mocks/pit_file/ilk/repository.go @@ -31,6 +31,7 @@ type MockPitFileIlkRepository struct { markHeaderCheckedPassedHeaderID int64 missingHeaders []core.Header missingHeadersError error + SetDbCalled bool } func (repository *MockPitFileIlkRepository) SetCreateError(err error) { @@ -70,4 +71,6 @@ func (repository *MockPitFileIlkRepository) AssertMarkHeaderCheckedCalledWith(i Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i)) } -func (repository *MockPitFileIlkRepository) SetDB(db *postgres.DB) {} +func (repository *MockPitFileIlkRepository) SetDB(db *postgres.DB) { + repository.SetDbCalled = true +} diff --git a/pkg/transformers/test_data/mocks/pit_file/stability_fee/repository.go b/pkg/transformers/test_data/mocks/pit_file/stability_fee/repository.go index 53967bd0..e20678e1 100644 --- a/pkg/transformers/test_data/mocks/pit_file/stability_fee/repository.go +++ b/pkg/transformers/test_data/mocks/pit_file/stability_fee/repository.go @@ -31,6 +31,7 @@ type MockPitFileStabilityFeeRepository struct { PassedEndingBlockNumber int64 PassedHeaderID int64 PassedModels []interface{} + SetDbCalled bool } func (repository *MockPitFileStabilityFeeRepository) Create(headerID int64, models []interface{}) error { @@ -70,4 +71,6 @@ func (repository *MockPitFileStabilityFeeRepository) AssertMarkHeaderCheckedCall Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i)) } -func (repository *MockPitFileStabilityFeeRepository) SetDB(db *postgres.DB) {} +func (repository *MockPitFileStabilityFeeRepository) SetDB(db *postgres.DB) { + repository.SetDbCalled = true +} diff --git a/pkg/transformers/test_data/mocks/tend/repository.go b/pkg/transformers/test_data/mocks/tend/repository.go index cfb6e9af..b013b9ab 100644 --- a/pkg/transformers/test_data/mocks/tend/repository.go +++ b/pkg/transformers/test_data/mocks/tend/repository.go @@ -31,6 +31,7 @@ type MockTendRepository struct { markHeaderCheckedPassedHeaderId int64 missingHeaders []core.Header missingHeadersError error + SetDbCalled bool } func (repository *MockTendRepository) Create(headerId int64, tend []interface{}) error { @@ -70,4 +71,6 @@ func (repository *MockTendRepository) AssertMarkHeaderCheckedCalledWith(headerId Expect(repository.markHeaderCheckedPassedHeaderId).To(Equal(headerId)) } -func (repository *MockTendRepository) SetDB(db *postgres.DB) {} +func (repository *MockTendRepository) SetDB(db *postgres.DB) { + repository.SetDbCalled = true +} diff --git a/pkg/transformers/test_data/mocks/vat_init/repository.go b/pkg/transformers/test_data/mocks/vat_init/repository.go index 298c941d..fccbdc0c 100644 --- a/pkg/transformers/test_data/mocks/vat_init/repository.go +++ b/pkg/transformers/test_data/mocks/vat_init/repository.go @@ -31,6 +31,7 @@ type MockVatInitRepository struct { PassedEndingBlockNumber int64 PassedHeaderID int64 PassedModels []interface{} + SetDbCalled bool } func (repository *MockVatInitRepository) Create(headerID int64, models []interface{}) error { @@ -70,4 +71,6 @@ func (repository *MockVatInitRepository) AssertMarkHeaderCheckedCalledWith(i int Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i)) } -func (repository *MockVatInitRepository) SetDB(db *postgres.DB) {} +func (repository *MockVatInitRepository) SetDB(db *postgres.DB) { + repository.SetDbCalled = true +} diff --git a/pkg/transformers/test_data/mocks/vat_move/repository.go b/pkg/transformers/test_data/mocks/vat_move/repository.go index 46c3eb02..d1ce0859 100644 --- a/pkg/transformers/test_data/mocks/vat_move/repository.go +++ b/pkg/transformers/test_data/mocks/vat_move/repository.go @@ -29,6 +29,7 @@ type MockVatMoveRepository struct { PassedModels []interface{} CheckedHeaderIDs []int64 CheckedHeaderError error + SetDbCalled bool } func (repository *MockVatMoveRepository) Create(headerID int64, models []interface{}) error { @@ -64,4 +65,6 @@ func (repository *MockVatMoveRepository) SetCheckedHeaderError(e error) { repository.CheckedHeaderError = e } -func (repository *MockVatMoveRepository) SetDB(db *postgres.DB) {} +func (repository *MockVatMoveRepository) SetDB(db *postgres.DB) { + repository.SetDbCalled = true +} diff --git a/pkg/transformers/vat_init/repository.go b/pkg/transformers/vat_init/repository.go index 010e0a7c..b581b8b1 100644 --- a/pkg/transformers/vat_init/repository.go +++ b/pkg/transformers/vat_init/repository.go @@ -22,11 +22,11 @@ import ( ) type VatInitRepository struct { - DB *postgres.DB + db *postgres.DB } func (repository VatInitRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.DB.Begin() + tx, err := repository.db.Begin() if err != nil { return err } @@ -64,7 +64,7 @@ func (repository VatInitRepository) Create(headerID int64, models []interface{}) } func (repository VatInitRepository) MarkHeaderChecked(headerID int64) error { - _, err := repository.DB.Exec(`INSERT INTO public.checked_headers (header_id, vat_init_checked) + _, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, vat_init_checked) VALUES ($1, $2) ON CONFLICT (header_id) DO UPDATE SET vat_init_checked = $2`, headerID, true) @@ -73,7 +73,7 @@ func (repository VatInitRepository) MarkHeaderChecked(headerID int64) error { func (repository VatInitRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { var result []core.Header - err := repository.DB.Select( + err := repository.db.Select( &result, `SELECT headers.id, headers.block_number FROM headers LEFT JOIN checked_headers on headers.id = header_id @@ -83,11 +83,11 @@ func (repository VatInitRepository) MissingHeaders(startingBlockNumber, endingBl AND headers.eth_node_fingerprint = $3`, startingBlockNumber, endingBlockNumber, - repository.DB.Node.ID, + repository.db.Node.ID, ) return result, err } func (repository *VatInitRepository) SetDB(db *postgres.DB) { - repository.DB = db + repository.db = db } diff --git a/pkg/transformers/vat_init/repository_test.go b/pkg/transformers/vat_init/repository_test.go index a755a8e0..0738db18 100644 --- a/pkg/transformers/vat_init/repository_test.go +++ b/pkg/transformers/vat_init/repository_test.go @@ -40,7 +40,8 @@ var _ = Describe("Vat init repository", func() { BeforeEach(func() { db = test_config.NewTestDB(core.Node{}) test_config.CleanTestDB(db) - vatInitRepository = vat_init.VatInitRepository{DB: db} + vatInitRepository = vat_init.VatInitRepository{} + vatInitRepository.SetDB(db) headerRepository = repositories.NewHeaderRepository(db) }) @@ -180,7 +181,8 @@ var _ = Describe("Vat init repository", func() { Expect(err).NotTo(HaveOccurred()) } - vatInitRepositoryTwo := vat_init.VatInitRepository{DB: dbTwo} + vatInitRepositoryTwo := vat_init.VatInitRepository{} + vatInitRepositoryTwo.SetDB(dbTwo) err = vatInitRepository.MarkHeaderChecked(headerIDs[0]) Expect(err).NotTo(HaveOccurred()) @@ -193,13 +195,4 @@ var _ = Describe("Vat init repository", func() { Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers))) }) }) - - Describe("SetDB", func() { - It("sets the repository db", func() { - vatInitRepository.SetDB(nil) - Expect(vatInitRepository.DB).To(BeNil()) - vatInitRepository.SetDB(db) - Expect(vatInitRepository.DB).To(Equal(db)) - }) - }) }) diff --git a/pkg/transformers/vat_init/transformer_test.go b/pkg/transformers/vat_init/transformer_test.go index d80a1334..406c17a0 100644 --- a/pkg/transformers/vat_init/transformer_test.go +++ b/pkg/transformers/vat_init/transformer_test.go @@ -55,6 +55,11 @@ var _ = Describe("Vat init transformer", func() { }.NewTransformer(nil, nil) }) + 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() diff --git a/pkg/transformers/vat_move/repository.go b/pkg/transformers/vat_move/repository.go index 7d63ef25..91928ae4 100644 --- a/pkg/transformers/vat_move/repository.go +++ b/pkg/transformers/vat_move/repository.go @@ -21,11 +21,11 @@ import ( ) type VatMoveRepository struct { - DB *postgres.DB + db *postgres.DB } func (repository VatMoveRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.DB.Begin() + tx, err := repository.db.Begin() if err != nil { return err } @@ -66,7 +66,7 @@ func (repository VatMoveRepository) Create(headerID int64, models []interface{}) func (repository VatMoveRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { var result []core.Header - err := repository.DB.Select( + err := repository.db.Select( &result, `SELECT headers.id, headers.block_number FROM headers LEFT JOIN checked_headers on headers.id = header_id @@ -76,14 +76,14 @@ func (repository VatMoveRepository) MissingHeaders(startingBlockNumber, endingBl AND headers.eth_node_fingerprint = $3`, startingBlockNumber, endingBlockNumber, - repository.DB.Node.ID, + repository.db.Node.ID, ) return result, err } func (repository VatMoveRepository) MarkHeaderChecked(headerID int64) error { - _, err := repository.DB.Exec(`INSERT INTO public.checked_headers (header_id, vat_move_checked) + _, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, vat_move_checked) VALUES ($1, $2) ON CONFLICT (header_id) DO UPDATE SET vat_move_checked = $2`, headerID, true) @@ -91,5 +91,5 @@ func (repository VatMoveRepository) MarkHeaderChecked(headerID int64) error { } func (repository *VatMoveRepository) SetDB(db *postgres.DB) { - repository.DB = db + repository.db = db } diff --git a/pkg/transformers/vat_move/repository_test.go b/pkg/transformers/vat_move/repository_test.go index 8b6e33ff..0e39567e 100644 --- a/pkg/transformers/vat_move/repository_test.go +++ b/pkg/transformers/vat_move/repository_test.go @@ -37,7 +37,8 @@ var _ = Describe("Vat Move", func() { db = test_config.NewTestDB(core.Node{}) test_config.CleanTestDB(db) headerRepository = repositories.NewHeaderRepository(db) - vatMoveRepository = vat_move.VatMoveRepository{DB: db} + vatMoveRepository = vat_move.VatMoveRepository{} + vatMoveRepository.SetDB(db) }) Describe("Create", func() { @@ -150,7 +151,8 @@ var _ = Describe("Vat Move", func() { _, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n)) Expect(err).NotTo(HaveOccurred()) } - vatMoveRepositoryTwo := vat_move.VatMoveRepository{DB: dbTwo} + vatMoveRepositoryTwo := vat_move.VatMoveRepository{} + vatMoveRepositoryTwo.SetDB(dbTwo) err := vatMoveRepository.Create(headerIDs[0], []interface{}{test_data.VatMoveModel}) Expect(err).NotTo(HaveOccurred()) @@ -195,13 +197,4 @@ var _ = Describe("Vat Move", func() { Expect(headerChecked).To(BeTrue()) }) }) - - Describe("SetDB", func() { - It("sets the repository db", func() { - vatMoveRepository.DB = nil - Expect(vatMoveRepository.DB).To(BeNil()) - vatMoveRepository.SetDB(db) - Expect(vatMoveRepository.DB).To(Equal(db)) - }) - }) }) diff --git a/pkg/transformers/vat_move/transformer_test.go b/pkg/transformers/vat_move/transformer_test.go index 0e35f6d3..069c6f1d 100644 --- a/pkg/transformers/vat_move/transformer_test.go +++ b/pkg/transformers/vat_move/transformer_test.go @@ -52,6 +52,11 @@ var _ = Describe("Vat move transformer", func() { }.NewTransformer(nil, nil) }) + 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()