forked from cerc-io/ipld-eth-server
Add test for updating existing checked header row
This commit is contained in:
parent
e37447ae9a
commit
745b3a460e
@ -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
|
||||
|
||||
|
@ -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"))
|
||||
|
@ -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"))
|
||||
|
@ -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"))
|
||||
|
@ -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())
|
||||
|
@ -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"))
|
||||
|
@ -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"))
|
||||
|
@ -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"))
|
||||
|
@ -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() {
|
||||
|
@ -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())
|
||||
|
@ -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"))
|
||||
|
@ -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"))
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user