diff --git a/pkg/transformers/drip_file/ilk/repository_test.go b/pkg/transformers/drip_file/ilk/repository_test.go index 80245b95..c1870e1c 100644 --- a/pkg/transformers/drip_file/ilk/repository_test.go +++ b/pkg/transformers/drip_file/ilk/repository_test.go @@ -16,8 +16,11 @@ package ilk_test import ( "database/sql" + "math/rand" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/datastore" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" @@ -51,11 +54,12 @@ var _ = Describe("Drip file ilk repository", func() { headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) Expect(err).NotTo(HaveOccurred()) - err = dripFileIlkRepository.Create(headerID, []interface{}{test_data.DripFileIlkModel}) - Expect(err).NotTo(HaveOccurred()) }) It("adds a drip file ilk event", func() { + err = dripFileIlkRepository.Create(headerID, []interface{}{test_data.DripFileIlkModel}) + + Expect(err).NotTo(HaveOccurred()) var dbDripFileIlk ilk.DripFileIlkModel err = db.Get(&dbDripFileIlk, `SELECT ilk, vow, tax, log_idx, tx_idx, raw_log FROM maker.drip_file_ilk WHERE header_id = $1`, headerID) Expect(err).NotTo(HaveOccurred()) @@ -68,6 +72,22 @@ var _ = Describe("Drip file ilk repository", func() { }) It("marks header as checked for logs", func() { + err = dripFileIlkRepository.Create(headerID, []interface{}{test_data.DripFileIlkModel}) + + Expect(err).NotTo(HaveOccurred()) + var headerChecked bool + err = db.Get(&headerChecked, `SELECT drip_file_ilk_checked FROM public.checked_headers WHERE header_id = $1`, headerID) + Expect(err).NotTo(HaveOccurred()) + Expect(headerChecked).To(BeTrue()) + }) + + It("updates the header to checked if checked headers row already exists", func() { + _, err = db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerID) + Expect(err).NotTo(HaveOccurred()) + + err = dripFileIlkRepository.Create(headerID, []interface{}{test_data.DripFileIlkModel}) + + Expect(err).NotTo(HaveOccurred()) var headerChecked bool err = db.Get(&headerChecked, `SELECT drip_file_ilk_checked FROM public.checked_headers WHERE header_id = $1`, headerID) Expect(err).NotTo(HaveOccurred()) @@ -75,6 +95,9 @@ var _ = Describe("Drip file ilk repository", func() { }) It("does not duplicate drip file events", func() { + err = dripFileIlkRepository.Create(headerID, []interface{}{test_data.DripFileIlkModel}) + Expect(err).NotTo(HaveOccurred()) + err = dripFileIlkRepository.Create(headerID, []interface{}{test_data.DripFileIlkModel}) Expect(err).To(HaveOccurred()) @@ -82,6 +105,9 @@ var _ = Describe("Drip file ilk repository", func() { }) It("removes drip file if corresponding header is deleted", func() { + err = dripFileIlkRepository.Create(headerID, []interface{}{test_data.DripFileIlkModel}) + Expect(err).NotTo(HaveOccurred()) + _, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID) Expect(err).NotTo(HaveOccurred()) @@ -91,7 +117,7 @@ var _ = Describe("Drip file ilk repository", func() { Expect(err).To(MatchError(sql.ErrNoRows)) }) - It("Returns an error if model is of wrong type", func() { + It("returns an error if model is of wrong type", func() { err = dripFileIlkRepository.Create(headerID, []interface{}{test_data.WrongModel{}}) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("model of type")) @@ -136,7 +162,7 @@ var _ = Describe("Drip file ilk repository", func() { ) BeforeEach(func() { - startingBlock = GinkgoRandomSeed() + startingBlock = rand.Int63() dripFileBlock = startingBlock + 1 endingBlock = startingBlock + 2 diff --git a/pkg/transformers/drip_file/repo/repository_test.go b/pkg/transformers/drip_file/repo/repository_test.go index 6e63f901..dc9e75ed 100644 --- a/pkg/transformers/drip_file/repo/repository_test.go +++ b/pkg/transformers/drip_file/repo/repository_test.go @@ -53,12 +53,12 @@ var _ = Describe("Drip file repo repository", func() { BeforeEach(func() { headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) Expect(err).NotTo(HaveOccurred()) - - err = dripFileRepoRepository.Create(headerID, []interface{}{test_data.DripFileRepoModel}) - Expect(err).NotTo(HaveOccurred()) }) It("adds a drip file repo event", func() { + err = dripFileRepoRepository.Create(headerID, []interface{}{test_data.DripFileRepoModel}) + + Expect(err).NotTo(HaveOccurred()) var dbDripFileRepo repo.DripFileRepoModel err = db.Get(&dbDripFileRepo, `SELECT what, data, log_idx, tx_idx, raw_log FROM maker.drip_file_repo WHERE header_id = $1`, headerID) Expect(err).NotTo(HaveOccurred()) @@ -70,6 +70,22 @@ var _ = Describe("Drip file repo repository", func() { }) It("marks header as checked for logs", func() { + err = dripFileRepoRepository.Create(headerID, []interface{}{test_data.DripFileRepoModel}) + + Expect(err).NotTo(HaveOccurred()) + var headerChecked bool + err = db.Get(&headerChecked, `SELECT drip_file_repo_checked FROM public.checked_headers WHERE header_id = $1`, headerID) + Expect(err).NotTo(HaveOccurred()) + Expect(headerChecked).To(BeTrue()) + }) + + It("updates the header to checked if checked headers row already exists", func() { + _, err = db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerID) + Expect(err).NotTo(HaveOccurred()) + + err = dripFileRepoRepository.Create(headerID, []interface{}{test_data.DripFileRepoModel}) + + Expect(err).NotTo(HaveOccurred()) var headerChecked bool err = db.Get(&headerChecked, `SELECT drip_file_repo_checked FROM public.checked_headers WHERE header_id = $1`, headerID) Expect(err).NotTo(HaveOccurred()) @@ -77,6 +93,9 @@ var _ = Describe("Drip file repo repository", func() { }) It("does not duplicate drip file events", func() { + err = dripFileRepoRepository.Create(headerID, []interface{}{test_data.DripFileRepoModel}) + Expect(err).NotTo(HaveOccurred()) + err = dripFileRepoRepository.Create(headerID, []interface{}{test_data.DripFileRepoModel}) Expect(err).To(HaveOccurred()) @@ -84,6 +103,8 @@ var _ = Describe("Drip file repo repository", func() { }) It("removes drip file if corresponding header is deleted", func() { + err = dripFileRepoRepository.Create(headerID, []interface{}{test_data.DripFileRepoModel}) + Expect(err).NotTo(HaveOccurred()) _, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID) Expect(err).NotTo(HaveOccurred()) @@ -93,7 +114,7 @@ var _ = Describe("Drip file repo repository", func() { Expect(err).To(MatchError(sql.ErrNoRows)) }) - It("Returns an error if model is of wrong type", func() { + It("returns an error if model is of wrong type", func() { err = dripFileRepoRepository.Create(headerID, []interface{}{test_data.WrongModel{}}) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("model of type")) diff --git a/pkg/transformers/drip_file/vow/repository_test.go b/pkg/transformers/drip_file/vow/repository_test.go index 914f5fb6..d8b8016b 100644 --- a/pkg/transformers/drip_file/vow/repository_test.go +++ b/pkg/transformers/drip_file/vow/repository_test.go @@ -53,12 +53,12 @@ var _ = Describe("Drip file vow repository", func() { BeforeEach(func() { headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) Expect(err).NotTo(HaveOccurred()) - - err = dripFileVowRepository.Create(headerID, []interface{}{test_data.DripFileVowModel}) - Expect(err).NotTo(HaveOccurred()) }) It("adds a drip file vow event", func() { + err = dripFileVowRepository.Create(headerID, []interface{}{test_data.DripFileVowModel}) + + Expect(err).NotTo(HaveOccurred()) var dbDripFileVow vow.DripFileVowModel err = db.Get(&dbDripFileVow, `SELECT what, data, log_idx, tx_idx, raw_log FROM maker.drip_file_vow WHERE header_id = $1`, headerID) Expect(err).NotTo(HaveOccurred()) @@ -70,6 +70,22 @@ var _ = Describe("Drip file vow repository", func() { }) It("marks header as checked for logs", func() { + err = dripFileVowRepository.Create(headerID, []interface{}{test_data.DripFileVowModel}) + + Expect(err).NotTo(HaveOccurred()) + var headerChecked bool + err = db.Get(&headerChecked, `SELECT drip_file_vow_checked FROM public.checked_headers WHERE header_id = $1`, headerID) + Expect(err).NotTo(HaveOccurred()) + Expect(headerChecked).To(BeTrue()) + }) + + It("updates the header to checked if checked headers row already exists", func() { + _, err = db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerID) + Expect(err).NotTo(HaveOccurred()) + + err = dripFileVowRepository.Create(headerID, []interface{}{test_data.DripFileVowModel}) + + Expect(err).NotTo(HaveOccurred()) var headerChecked bool err = db.Get(&headerChecked, `SELECT drip_file_vow_checked FROM public.checked_headers WHERE header_id = $1`, headerID) Expect(err).NotTo(HaveOccurred()) @@ -77,6 +93,9 @@ var _ = Describe("Drip file vow repository", func() { }) It("does not duplicate drip file events", func() { + err = dripFileVowRepository.Create(headerID, []interface{}{test_data.DripFileVowModel}) + Expect(err).NotTo(HaveOccurred()) + err = dripFileVowRepository.Create(headerID, []interface{}{test_data.DripFileVowModel}) Expect(err).To(HaveOccurred()) @@ -84,6 +103,8 @@ var _ = Describe("Drip file vow repository", func() { }) It("removes drip file if corresponding header is deleted", func() { + err = dripFileVowRepository.Create(headerID, []interface{}{test_data.DripFileVowModel}) + Expect(err).NotTo(HaveOccurred()) _, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID) Expect(err).NotTo(HaveOccurred()) @@ -93,7 +114,7 @@ var _ = Describe("Drip file vow repository", func() { Expect(err).To(MatchError(sql.ErrNoRows)) }) - It("Returns an error if model is of wrong type", func() { + It("returns an error if model is of wrong type", func() { err = dripFileVowRepository.Create(headerID, []interface{}{test_data.WrongModel{}}) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("model of type")) diff --git a/pkg/transformers/flog/repository_test.go b/pkg/transformers/flog/repository_test.go index a5326c76..ed44dd86 100644 --- a/pkg/transformers/flog/repository_test.go +++ b/pkg/transformers/flog/repository_test.go @@ -16,7 +16,6 @@ package flog_test import ( "database/sql" - "github.com/vulcanize/vulcanizedb/pkg/transformers/flog" "math/rand" . "github.com/onsi/ginkgo" @@ -27,6 +26,7 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/fakes" + "github.com/vulcanize/vulcanizedb/pkg/transformers/flog" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/test_config" ) @@ -110,7 +110,7 @@ var _ = Describe("Flog repository", func() { Expect(err).To(MatchError(sql.ErrNoRows)) }) - It("Returns an error if model is of wrong type", func() { + It("returns an error if model is of wrong type", func() { err = flogRepository.Create(headerID, []interface{}{test_data.WrongModel{}}) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("model of type")) diff --git a/pkg/transformers/pit_file/debt_ceiling/repository_test.go b/pkg/transformers/pit_file/debt_ceiling/repository_test.go index d0965a13..cbbfca40 100644 --- a/pkg/transformers/pit_file/debt_ceiling/repository_test.go +++ b/pkg/transformers/pit_file/debt_ceiling/repository_test.go @@ -115,7 +115,7 @@ var _ = Describe("Pit file debt ceiling repository", func() { Expect(err).To(MatchError(sql.ErrNoRows)) }) - It("Returns an error if model is of wrong type", func() { + It("returns an error if model is of wrong type", func() { err = pitFileDebtCeilingRepository.Create(headerID, []interface{}{test_data.WrongModel{}}) Expect(err).To(HaveOccurred()) diff --git a/pkg/transformers/pit_file/ilk/repository_test.go b/pkg/transformers/pit_file/ilk/repository_test.go index cba4e0ba..f93c9545 100644 --- a/pkg/transformers/pit_file/ilk/repository_test.go +++ b/pkg/transformers/pit_file/ilk/repository_test.go @@ -116,7 +116,7 @@ var _ = Describe("Pit file ilk repository", func() { Expect(err).To(MatchError(sql.ErrNoRows)) }) - It("Returns an error if model is of wrong type", func() { + It("returns an error if model is of wrong type", func() { err = pitFileRepository.Create(headerID, []interface{}{test_data.WrongModel{}}) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("model of type")) diff --git a/pkg/transformers/pit_file/stability_fee/repository_test.go b/pkg/transformers/pit_file/stability_fee/repository_test.go index ae2764fc..f6694018 100644 --- a/pkg/transformers/pit_file/stability_fee/repository_test.go +++ b/pkg/transformers/pit_file/stability_fee/repository_test.go @@ -115,7 +115,7 @@ var _ = Describe("Pit file stability fee repository", func() { Expect(err).To(MatchError(sql.ErrNoRows)) }) - It("Returns an error if model is of wrong type", func() { + It("returns an error if model is of wrong type", func() { err = pitFileStabilityFeeRepository.Create(headerID, []interface{}{test_data.WrongModel{}}) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("model of type")) diff --git a/pkg/transformers/tend/repository_test.go b/pkg/transformers/tend/repository_test.go index 4381cd04..f985751e 100644 --- a/pkg/transformers/tend/repository_test.go +++ b/pkg/transformers/tend/repository_test.go @@ -15,9 +15,10 @@ package tend_test import ( + "math/rand" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "math/rand" "github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" @@ -124,7 +125,7 @@ var _ = Describe("TendRepository", func() { Expect(count).To(Equal(0)) }) - It("Returns an error if model is of wrong type", func() { + It("returns an error if model is of wrong type", func() { err = tendRepository.Create(headerId, []interface{}{test_data.WrongModel{}}) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("model of type")) diff --git a/pkg/transformers/vat_flux/repository_test.go b/pkg/transformers/vat_flux/repository_test.go index 92e4a452..86933bea 100644 --- a/pkg/transformers/vat_flux/repository_test.go +++ b/pkg/transformers/vat_flux/repository_test.go @@ -15,8 +15,11 @@ package vat_flux_test import ( + "math/rand" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" @@ -24,7 +27,6 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_flux" "github.com/vulcanize/vulcanizedb/test_config" - "math/rand" ) var _ = Describe("VatFlux Repository", func() { diff --git a/pkg/transformers/vat_fold/repository_test.go b/pkg/transformers/vat_fold/repository_test.go index 937b88df..863618f0 100644 --- a/pkg/transformers/vat_fold/repository_test.go +++ b/pkg/transformers/vat_fold/repository_test.go @@ -104,16 +104,6 @@ var _ = Describe("Vat.fold repository", func() { Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint")) }) - It("does not mark header checked if not all models persisted", func() { - err = repository.Create(headerID, []interface{}{test_data.VatFoldModel, test_data.VatFoldModel}) - - Expect(err).To(HaveOccurred()) - var headerChecked bool - err = db.Get(&headerChecked, `SELECT vat_fold_checked FROM public.checked_headers WHERE header_id = $1`, headerID) - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(sql.ErrNoRows)) - }) - It("removes vat fold if corresponding header is deleted", func() { err = repository.Create(headerID, []interface{}{test_data.VatFoldModel}) Expect(err).NotTo(HaveOccurred()) diff --git a/pkg/transformers/vat_init/repository_test.go b/pkg/transformers/vat_init/repository_test.go index 8f0a8fa8..d732d43c 100644 --- a/pkg/transformers/vat_init/repository_test.go +++ b/pkg/transformers/vat_init/repository_test.go @@ -113,7 +113,7 @@ var _ = Describe("Vat init repository", func() { Expect(headerChecked).To(BeTrue()) }) - It("Returns an error if model is of wrong type", func() { + It("returns an error if model is of wrong type", func() { err = vatInitRepository.Create(headerID, []interface{}{test_data.WrongModel{}}) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("model of type")) diff --git a/pkg/transformers/vat_move/repository_test.go b/pkg/transformers/vat_move/repository_test.go index 7586b19b..d8318d2f 100644 --- a/pkg/transformers/vat_move/repository_test.go +++ b/pkg/transformers/vat_move/repository_test.go @@ -112,7 +112,7 @@ var _ = Describe("Vat Move", func() { Expect(err).To(MatchError(sql.ErrNoRows)) }) - It("Returns an error if model is of wrong type", func() { + It("returns an error if model is of wrong type", func() { err = vatMoveRepository.Create(headerID, []interface{}{test_data.WrongModel{}}) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("model of type")) diff --git a/pkg/transformers/vat_slip/repository_test.go b/pkg/transformers/vat_slip/repository_test.go index 6841d0f0..5ed48c68 100644 --- a/pkg/transformers/vat_slip/repository_test.go +++ b/pkg/transformers/vat_slip/repository_test.go @@ -2,6 +2,7 @@ package vat_slip_test import ( "database/sql" + "math/rand" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -156,7 +157,7 @@ var _ = Describe("Vat slip repository", func() { ) BeforeEach(func() { - startingBlock = GinkgoRandomSeed() + startingBlock = rand.Int63() vatSlipBlock = startingBlock + 1 endingBlock = startingBlock + 2