forked from cerc-io/ipld-eth-server
Privatise DB repository field and add transformer test
This commit is contained in:
parent
cb74cbe990
commit
7ee3329baf
@ -21,11 +21,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DripFileIlkRepository struct {
|
type DripFileIlkRepository struct {
|
||||||
DB *postgres.DB
|
db *postgres.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository DripFileIlkRepository) Create(headerID int64, models []interface{}) error {
|
func (repository DripFileIlkRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.DB.Begin()
|
tx, err := repository.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ func (repository DripFileIlkRepository) Create(headerID int64, models []interfac
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository DripFileIlkRepository) MarkHeaderChecked(headerID int64) error {
|
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)
|
VALUES ($1, $2)
|
||||||
ON CONFLICT (header_id) DO
|
ON CONFLICT (header_id) DO
|
||||||
UPDATE SET drip_file_ilk_checked = $2`, headerID, true)
|
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) {
|
func (repository DripFileIlkRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||||
var result []core.Header
|
var result []core.Header
|
||||||
err := repository.DB.Select(
|
err := repository.db.Select(
|
||||||
&result,
|
&result,
|
||||||
`SELECT headers.id, headers.block_number FROM headers
|
`SELECT headers.id, headers.block_number FROM headers
|
||||||
LEFT JOIN checked_headers on headers.id = header_id
|
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`,
|
AND headers.eth_node_fingerprint = $3`,
|
||||||
startingBlockNumber,
|
startingBlockNumber,
|
||||||
endingBlockNumber,
|
endingBlockNumber,
|
||||||
repository.DB.Node.ID,
|
repository.db.Node.ID,
|
||||||
)
|
)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *DripFileIlkRepository) SetDB(db *postgres.DB) {
|
func (repository *DripFileIlkRepository) SetDB(db *postgres.DB) {
|
||||||
repository.DB = db
|
repository.db = db
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,8 @@ var _ = Describe("Drip file ilk repository", func() {
|
|||||||
db = test_config.NewTestDB(test_config.NewTestNode())
|
db = test_config.NewTestDB(test_config.NewTestNode())
|
||||||
test_config.CleanTestDB(db)
|
test_config.CleanTestDB(db)
|
||||||
headerRepository = repositories.NewHeaderRepository(db)
|
headerRepository = repositories.NewHeaderRepository(db)
|
||||||
dripFileIlkRepository = ilk.DripFileIlkRepository{DB: db}
|
dripFileIlkRepository = ilk.DripFileIlkRepository{}
|
||||||
|
dripFileIlkRepository.SetDB(db)
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("Create", func() {
|
Describe("Create", func() {
|
||||||
@ -182,7 +183,8 @@ var _ = Describe("Drip file ilk repository", func() {
|
|||||||
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
}
|
}
|
||||||
dripFileIlkRepositoryTwo := ilk.DripFileIlkRepository{DB: dbTwo}
|
dripFileIlkRepositoryTwo := ilk.DripFileIlkRepository{}
|
||||||
|
dripFileIlkRepositoryTwo.SetDB(dbTwo)
|
||||||
err := dripFileIlkRepository.MarkHeaderChecked(headerIDs[0])
|
err := dripFileIlkRepository.MarkHeaderChecked(headerIDs[0])
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
@ -195,14 +197,4 @@ var _ = Describe("Drip file ilk repository", func() {
|
|||||||
Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers)))
|
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))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
@ -50,11 +50,16 @@ var _ = Describe("Drip file ilk transformer", func() {
|
|||||||
Fetcher: &fetcher,
|
Fetcher: &fetcher,
|
||||||
Converter: &converter,
|
Converter: &converter,
|
||||||
Repository: &repository,
|
Repository: &repository,
|
||||||
}
|
}.NewTransformer(nil, nil)
|
||||||
headerOne = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()}
|
headerOne = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()}
|
||||||
headerTwo = 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() {
|
It("gets missing headers for block numbers specified in config", func() {
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
|
@ -21,11 +21,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DripFileRepoRepository struct {
|
type DripFileRepoRepository struct {
|
||||||
DB *postgres.DB
|
db *postgres.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository DripFileRepoRepository) Create(headerID int64, models []interface{}) error {
|
func (repository DripFileRepoRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.DB.Begin()
|
tx, err := repository.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ func (repository DripFileRepoRepository) Create(headerID int64, models []interfa
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository DripFileRepoRepository) MarkHeaderChecked(headerID int64) error {
|
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)
|
VALUES ($1, $2)
|
||||||
ON CONFLICT (header_id) DO
|
ON CONFLICT (header_id) DO
|
||||||
UPDATE SET drip_file_repo_checked = $2`, headerID, true)
|
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) {
|
func (repository DripFileRepoRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||||
var result []core.Header
|
var result []core.Header
|
||||||
err := repository.DB.Select(
|
err := repository.db.Select(
|
||||||
&result,
|
&result,
|
||||||
`SELECT headers.id, headers.block_number FROM headers
|
`SELECT headers.id, headers.block_number FROM headers
|
||||||
LEFT JOIN checked_headers on headers.id = header_id
|
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`,
|
AND headers.eth_node_fingerprint = $3`,
|
||||||
startingBlockNumber,
|
startingBlockNumber,
|
||||||
endingBlockNumber,
|
endingBlockNumber,
|
||||||
repository.DB.Node.ID,
|
repository.db.Node.ID,
|
||||||
)
|
)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *DripFileRepoRepository) SetDB(db *postgres.DB) {
|
func (repository *DripFileRepoRepository) SetDB(db *postgres.DB) {
|
||||||
repository.DB = db
|
repository.db = db
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,8 @@ var _ = Describe("Drip file repo repository", 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)
|
||||||
dripFileRepoRepository = repo.DripFileRepoRepository{DB: db}
|
dripFileRepoRepository = repo.DripFileRepoRepository{}
|
||||||
|
dripFileRepoRepository.SetDB(db)
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("Create", func() {
|
Describe("Create", func() {
|
||||||
@ -182,7 +183,8 @@ var _ = Describe("Drip file repo repository", func() {
|
|||||||
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
}
|
}
|
||||||
dripFileRepoRepositoryTwo := repo.DripFileRepoRepository{DB: dbTwo}
|
dripFileRepoRepositoryTwo := repo.DripFileRepoRepository{}
|
||||||
|
dripFileRepoRepositoryTwo.SetDB(dbTwo)
|
||||||
err := dripFileRepoRepository.MarkHeaderChecked(headerIDs[0])
|
err := dripFileRepoRepository.MarkHeaderChecked(headerIDs[0])
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
@ -195,14 +197,4 @@ var _ = Describe("Drip file repo repository", func() {
|
|||||||
Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers)))
|
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))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
@ -50,11 +50,16 @@ var _ = Describe("Drip file repo transformer", func() {
|
|||||||
Fetcher: &fetcher,
|
Fetcher: &fetcher,
|
||||||
Converter: &converter,
|
Converter: &converter,
|
||||||
Repository: &repository,
|
Repository: &repository,
|
||||||
}
|
}.NewTransformer(nil, nil)
|
||||||
headerOne = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()}
|
headerOne = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()}
|
||||||
headerTwo = 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() {
|
It("gets missing headers for block numbers specified in config", func() {
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
|
@ -21,11 +21,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DripFileVowRepository struct {
|
type DripFileVowRepository struct {
|
||||||
DB *postgres.DB
|
db *postgres.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository DripFileVowRepository) Create(headerID int64, models []interface{}) error {
|
func (repository DripFileVowRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.DB.Begin()
|
tx, err := repository.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ func (repository DripFileVowRepository) Create(headerID int64, models []interfac
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository DripFileVowRepository) MarkHeaderChecked(headerID int64) error {
|
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)
|
VALUES ($1, $2)
|
||||||
ON CONFLICT (header_id) DO
|
ON CONFLICT (header_id) DO
|
||||||
UPDATE SET drip_file_vow_checked = $2`, headerID, true)
|
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) {
|
func (repository DripFileVowRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||||
var result []core.Header
|
var result []core.Header
|
||||||
err := repository.DB.Select(
|
err := repository.db.Select(
|
||||||
&result,
|
&result,
|
||||||
`SELECT headers.id, headers.block_number FROM headers
|
`SELECT headers.id, headers.block_number FROM headers
|
||||||
LEFT JOIN checked_headers on headers.id = header_id
|
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`,
|
AND headers.eth_node_fingerprint = $3`,
|
||||||
startingBlockNumber,
|
startingBlockNumber,
|
||||||
endingBlockNumber,
|
endingBlockNumber,
|
||||||
repository.DB.Node.ID,
|
repository.db.Node.ID,
|
||||||
)
|
)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *DripFileVowRepository) SetDB(db *postgres.DB) {
|
func (repository *DripFileVowRepository) SetDB(db *postgres.DB) {
|
||||||
repository.DB = db
|
repository.db = db
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,8 @@ var _ = Describe("Drip file vow repository", 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)
|
||||||
dripFileVowRepository = vow.DripFileVowRepository{DB: db}
|
dripFileVowRepository = vow.DripFileVowRepository{}
|
||||||
|
dripFileVowRepository.SetDB(db)
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("Create", func() {
|
Describe("Create", func() {
|
||||||
@ -182,7 +183,8 @@ var _ = Describe("Drip file vow repository", func() {
|
|||||||
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
}
|
}
|
||||||
dripFileVowRepositoryTwo := vow.DripFileVowRepository{DB: dbTwo}
|
dripFileVowRepositoryTwo := vow.DripFileVowRepository{}
|
||||||
|
dripFileVowRepositoryTwo.SetDB(dbTwo)
|
||||||
err := dripFileVowRepository.MarkHeaderChecked(headerIDs[0])
|
err := dripFileVowRepository.MarkHeaderChecked(headerIDs[0])
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
@ -195,14 +197,4 @@ var _ = Describe("Drip file vow repository", func() {
|
|||||||
Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers)))
|
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))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
@ -50,11 +50,16 @@ var _ = Describe("Drip file vow transformer", func() {
|
|||||||
Fetcher: &fetcher,
|
Fetcher: &fetcher,
|
||||||
Converter: &converter,
|
Converter: &converter,
|
||||||
Repository: &repository,
|
Repository: &repository,
|
||||||
}
|
}.NewTransformer(nil, nil)
|
||||||
headerOne = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()}
|
headerOne = core.Header{BlockNumber: GinkgoRandomSeed(), Id: GinkgoRandomSeed()}
|
||||||
headerTwo = 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() {
|
It("gets missing headers for block numbers specified in config", func() {
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
|
@ -21,11 +21,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type PitFileDebtCeilingRepository struct {
|
type PitFileDebtCeilingRepository struct {
|
||||||
DB *postgres.DB
|
db *postgres.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository PitFileDebtCeilingRepository) Create(headerID int64, models []interface{}) error {
|
func (repository PitFileDebtCeilingRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.DB.Begin()
|
tx, err := repository.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ func (repository PitFileDebtCeilingRepository) Create(headerID int64, models []i
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository PitFileDebtCeilingRepository) MarkHeaderChecked(headerID int64) error {
|
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)
|
VALUES ($1, $2)
|
||||||
ON CONFLICT (header_id) DO
|
ON CONFLICT (header_id) DO
|
||||||
UPDATE SET pit_file_debt_ceiling_checked = $2`, headerID, true)
|
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) {
|
func (repository PitFileDebtCeilingRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||||
var result []core.Header
|
var result []core.Header
|
||||||
err := repository.DB.Select(
|
err := repository.db.Select(
|
||||||
&result,
|
&result,
|
||||||
`SELECT headers.id, headers.block_number FROM headers
|
`SELECT headers.id, headers.block_number FROM headers
|
||||||
LEFT JOIN checked_headers on headers.id = header_id
|
LEFT JOIN checked_headers on headers.id = header_id
|
||||||
@ -82,11 +82,11 @@ func (repository PitFileDebtCeilingRepository) MissingHeaders(startingBlockNumbe
|
|||||||
AND headers.eth_node_fingerprint = $3`,
|
AND headers.eth_node_fingerprint = $3`,
|
||||||
startingBlockNumber,
|
startingBlockNumber,
|
||||||
endingBlockNumber,
|
endingBlockNumber,
|
||||||
repository.DB.Node.ID,
|
repository.db.Node.ID,
|
||||||
)
|
)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *PitFileDebtCeilingRepository) SetDB(db *postgres.DB) {
|
func (repository *PitFileDebtCeilingRepository) SetDB(db *postgres.DB) {
|
||||||
repository.DB = db
|
repository.db = db
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,8 @@ var _ = Describe("Pit file debt ceiling repository", 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)
|
||||||
pitFileDebtCeilingRepository = debt_ceiling.PitFileDebtCeilingRepository{DB: db}
|
pitFileDebtCeilingRepository = debt_ceiling.PitFileDebtCeilingRepository{}
|
||||||
|
pitFileDebtCeilingRepository.SetDB(db)
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("Create", func() {
|
Describe("Create", func() {
|
||||||
@ -182,16 +183,16 @@ var _ = Describe("Pit file debt ceiling repository", func() {
|
|||||||
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
}
|
}
|
||||||
pitFileRepository := debt_ceiling.PitFileDebtCeilingRepository{DB: db}
|
pitFileDebtCeilingRepositoryTwo := debt_ceiling.PitFileDebtCeilingRepository{}
|
||||||
pitFileRepositoryTwo := debt_ceiling.PitFileDebtCeilingRepository{DB: dbTwo}
|
pitFileDebtCeilingRepositoryTwo.SetDB(dbTwo)
|
||||||
err := pitFileRepository.MarkHeaderChecked(headerIDs[0])
|
err := pitFileDebtCeilingRepository.MarkHeaderChecked(headerIDs[0])
|
||||||
Expect(err).NotTo(HaveOccurred())
|
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(err).NotTo(HaveOccurred())
|
||||||
Expect(len(nodeOneMissingHeaders)).To(Equal(len(blockNumbers) - 1))
|
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(err).NotTo(HaveOccurred())
|
||||||
Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers)))
|
Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers)))
|
||||||
})
|
})
|
||||||
|
@ -52,7 +52,12 @@ var _ = Describe("Pit file debt ceiling transformer", func() {
|
|||||||
Fetcher: &fetcher,
|
Fetcher: &fetcher,
|
||||||
Converter: &converter,
|
Converter: &converter,
|
||||||
Repository: &repository,
|
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() {
|
It("gets missing headers for block numbers specified in config", func() {
|
||||||
|
@ -21,11 +21,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type PitFileIlkRepository struct {
|
type PitFileIlkRepository struct {
|
||||||
DB *postgres.DB
|
db *postgres.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository PitFileIlkRepository) Create(headerID int64, models []interface{}) error {
|
func (repository PitFileIlkRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.DB.Begin()
|
tx, err := repository.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ func (repository PitFileIlkRepository) Create(headerID int64, models []interface
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository PitFileIlkRepository) MarkHeaderChecked(headerID int64) error {
|
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)
|
VALUES ($1, $2)
|
||||||
ON CONFLICT (header_id) DO
|
ON CONFLICT (header_id) DO
|
||||||
UPDATE SET pit_file_ilk_checked = $2`, headerID, true)
|
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) {
|
func (repository PitFileIlkRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||||
var result []core.Header
|
var result []core.Header
|
||||||
err := repository.DB.Select(
|
err := repository.db.Select(
|
||||||
&result,
|
&result,
|
||||||
`SELECT headers.id, headers.block_number FROM headers
|
`SELECT headers.id, headers.block_number FROM headers
|
||||||
LEFT JOIN checked_headers on headers.id = header_id
|
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`,
|
AND headers.eth_node_fingerprint = $3`,
|
||||||
startingBlockNumber,
|
startingBlockNumber,
|
||||||
endingBlockNumber,
|
endingBlockNumber,
|
||||||
repository.DB.Node.ID,
|
repository.db.Node.ID,
|
||||||
)
|
)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *PitFileIlkRepository) SetDB(db *postgres.DB) {
|
func (repository *PitFileIlkRepository) SetDB(db *postgres.DB) {
|
||||||
repository.DB = db
|
repository.db = db
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,8 @@ var _ = Describe("Pit file ilk repository", 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)
|
||||||
pitFileRepository = ilk.PitFileIlkRepository{DB: db}
|
pitFileRepository = ilk.PitFileIlkRepository{}
|
||||||
|
pitFileRepository.SetDB(db)
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("Create", func() {
|
Describe("Create", func() {
|
||||||
@ -183,7 +184,8 @@ var _ = Describe("Pit file ilk repository", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
}
|
}
|
||||||
|
|
||||||
pitFileRepositoryTwo := ilk.PitFileIlkRepository{DB: dbTwo}
|
pitFileRepositoryTwo := ilk.PitFileIlkRepository{}
|
||||||
|
pitFileRepositoryTwo.SetDB(dbTwo)
|
||||||
err := pitFileRepository.MarkHeaderChecked(headerIDs[0])
|
err := pitFileRepository.MarkHeaderChecked(headerIDs[0])
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
@ -55,6 +55,11 @@ var _ = Describe("Pit file ilk transformer", func() {
|
|||||||
}.NewTransformer(nil, nil)
|
}.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() {
|
It("gets missing headers for block numbers specified in config", func() {
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
|
@ -21,11 +21,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type PitFileStabilityFeeRepository struct {
|
type PitFileStabilityFeeRepository struct {
|
||||||
DB *postgres.DB
|
db *postgres.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository PitFileStabilityFeeRepository) Create(headerID int64, models []interface{}) error {
|
func (repository PitFileStabilityFeeRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.DB.Begin()
|
tx, err := repository.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ func (repository PitFileStabilityFeeRepository) Create(headerID int64, models []
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository PitFileStabilityFeeRepository) MarkHeaderChecked(headerID int64) error {
|
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)
|
VALUES ($1, $2)
|
||||||
ON CONFLICT (header_id) DO
|
ON CONFLICT (header_id) DO
|
||||||
UPDATE SET pit_file_stability_fee_checked = $2`, headerID, true)
|
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) {
|
func (repository PitFileStabilityFeeRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||||
var result []core.Header
|
var result []core.Header
|
||||||
err := repository.DB.Select(
|
err := repository.db.Select(
|
||||||
&result,
|
&result,
|
||||||
`SELECT headers.id, headers.block_number FROM headers
|
`SELECT headers.id, headers.block_number FROM headers
|
||||||
LEFT JOIN checked_headers on headers.id = header_id
|
LEFT JOIN checked_headers on headers.id = header_id
|
||||||
@ -82,11 +82,11 @@ func (repository PitFileStabilityFeeRepository) MissingHeaders(startingBlockNumb
|
|||||||
AND headers.eth_node_fingerprint = $3`,
|
AND headers.eth_node_fingerprint = $3`,
|
||||||
startingBlockNumber,
|
startingBlockNumber,
|
||||||
endingBlockNumber,
|
endingBlockNumber,
|
||||||
repository.DB.Node.ID,
|
repository.db.Node.ID,
|
||||||
)
|
)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *PitFileStabilityFeeRepository) SetDB(db *postgres.DB) {
|
func (repository *PitFileStabilityFeeRepository) SetDB(db *postgres.DB) {
|
||||||
repository.DB = db
|
repository.db = db
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,8 @@ var _ = Describe("Pit file stability fee repository", 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)
|
||||||
pitFileStabilityFeeRepository = stability_fee.PitFileStabilityFeeRepository{DB: db}
|
pitFileStabilityFeeRepository = stability_fee.PitFileStabilityFeeRepository{}
|
||||||
|
pitFileStabilityFeeRepository.SetDB(db)
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("Create", func() {
|
Describe("Create", func() {
|
||||||
@ -182,7 +183,8 @@ var _ = Describe("Pit file stability fee repository", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
}
|
}
|
||||||
|
|
||||||
pitFileRepositoryTwo := stability_fee.PitFileStabilityFeeRepository{DB: dbTwo}
|
pitFileRepositoryTwo := stability_fee.PitFileStabilityFeeRepository{}
|
||||||
|
pitFileRepositoryTwo.SetDB(dbTwo)
|
||||||
err = pitFileStabilityFeeRepository.MarkHeaderChecked(headerIDs[0])
|
err = pitFileStabilityFeeRepository.MarkHeaderChecked(headerIDs[0])
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
@ -55,6 +55,11 @@ var _ = Describe("Pit file stability fee transformer", func() {
|
|||||||
headerTwo = core.Header{Id: GinkgoRandomSeed(), BlockNumber: GinkgoRandomSeed()}
|
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() {
|
It("gets missing headers for block numbers specified in config", func() {
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
|
@ -21,11 +21,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TendRepository struct {
|
type TendRepository struct {
|
||||||
DB *postgres.DB
|
db *postgres.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository TendRepository) Create(headerId int64, models []interface{}) error {
|
func (repository TendRepository) Create(headerId int64, models []interface{}) error {
|
||||||
tx, err := repository.DB.Begin()
|
tx, err := repository.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ func (repository TendRepository) Create(headerId int64, models []interface{}) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository TendRepository) MarkHeaderChecked(headerId int64) error {
|
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)
|
VALUES ($1, $2)
|
||||||
ON CONFLICT (header_id) DO
|
ON CONFLICT (header_id) DO
|
||||||
UPDATE SET tend_checked = $2`, headerId, true)
|
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) {
|
func (repository TendRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||||
var result []core.Header
|
var result []core.Header
|
||||||
err := repository.DB.Select(
|
err := repository.db.Select(
|
||||||
&result,
|
&result,
|
||||||
`SELECT headers.id, headers.block_number FROM headers
|
`SELECT headers.id, headers.block_number FROM headers
|
||||||
LEFT JOIN checked_headers on headers.id = header_id
|
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`,
|
AND headers.eth_node_fingerprint = $3`,
|
||||||
startingBlockNumber,
|
startingBlockNumber,
|
||||||
endingBlockNumber,
|
endingBlockNumber,
|
||||||
repository.DB.Node.ID,
|
repository.db.Node.ID,
|
||||||
)
|
)
|
||||||
|
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *TendRepository) SetDB(db *postgres.DB) {
|
func (repository *TendRepository) SetDB(db *postgres.DB) {
|
||||||
repository.DB = db
|
repository.db = db
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,8 @@ var _ = Describe("TendRepository", func() {
|
|||||||
db = test_config.NewTestDB(node)
|
db = test_config.NewTestDB(node)
|
||||||
test_config.CleanTestDB(db)
|
test_config.CleanTestDB(db)
|
||||||
headerRepository = repositories.NewHeaderRepository(db)
|
headerRepository = repositories.NewHeaderRepository(db)
|
||||||
tendRepository = tend.TendRepository{DB: db}
|
tendRepository = tend.TendRepository{}
|
||||||
|
tendRepository.SetDB(db)
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("Create", func() {
|
Describe("Create", func() {
|
||||||
@ -187,7 +188,8 @@ var _ = Describe("TendRepository", func() {
|
|||||||
node2 := core.Node{}
|
node2 := core.Node{}
|
||||||
db2 := test_config.NewTestDB(node2)
|
db2 := test_config.NewTestDB(node2)
|
||||||
headerRepository2 := repositories.NewHeaderRepository(db2)
|
headerRepository2 := repositories.NewHeaderRepository(db2)
|
||||||
tendRepository2 := tend.TendRepository{DB: db2}
|
tendRepository2 := tend.TendRepository{}
|
||||||
|
tendRepository2.SetDB(db2)
|
||||||
|
|
||||||
for _, number := range []int64{startingBlock, tendBlock, endingBlock} {
|
for _, number := range []int64{startingBlock, tendBlock, endingBlock} {
|
||||||
headerRepository2.CreateOrUpdateHeader(fakes.GetFakeHeader(number))
|
headerRepository2.CreateOrUpdateHeader(fakes.GetFakeHeader(number))
|
||||||
|
@ -56,6 +56,11 @@ var _ = Describe("Tend Transformer", func() {
|
|||||||
}.NewTransformer(nil, nil)
|
}.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() {
|
It("gets missing headers for blocks in the configured range", func() {
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ type MockDripFileIlkRepository struct {
|
|||||||
PassedEndingBlockNumber int64
|
PassedEndingBlockNumber int64
|
||||||
PassedHeaderID int64
|
PassedHeaderID int64
|
||||||
PassedModels []interface{}
|
PassedModels []interface{}
|
||||||
|
SetDbCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockDripFileIlkRepository) Create(headerID int64, models []interface{}) error {
|
func (repository *MockDripFileIlkRepository) Create(headerID int64, models []interface{}) error {
|
||||||
@ -69,4 +70,6 @@ func (repository *MockDripFileIlkRepository) AssertMarkHeaderCheckedCalledWith(i
|
|||||||
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockDripFileIlkRepository) SetDB(db *postgres.DB) {}
|
func (repository *MockDripFileIlkRepository) SetDB(db *postgres.DB) {
|
||||||
|
repository.SetDbCalled = true
|
||||||
|
}
|
||||||
|
@ -31,6 +31,7 @@ type MockDripFileRepoRepository struct {
|
|||||||
PassedEndingBlockNumber int64
|
PassedEndingBlockNumber int64
|
||||||
PassedHeaderID int64
|
PassedHeaderID int64
|
||||||
PassedModels []interface{}
|
PassedModels []interface{}
|
||||||
|
SetDbCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockDripFileRepoRepository) Create(headerID int64, models []interface{}) error {
|
func (repository *MockDripFileRepoRepository) Create(headerID int64, models []interface{}) error {
|
||||||
@ -70,4 +71,6 @@ func (repository *MockDripFileRepoRepository) AssertMarkHeaderCheckedCalledWith(
|
|||||||
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockDripFileRepoRepository) SetDB(db *postgres.DB) {}
|
func (repository *MockDripFileRepoRepository) SetDB(db *postgres.DB) {
|
||||||
|
repository.SetDbCalled = true
|
||||||
|
}
|
||||||
|
@ -31,6 +31,7 @@ type MockDripFileVowRepository struct {
|
|||||||
PassedEndingBlockNumber int64
|
PassedEndingBlockNumber int64
|
||||||
PassedHeaderID int64
|
PassedHeaderID int64
|
||||||
PassedModels []interface{}
|
PassedModels []interface{}
|
||||||
|
SetDbCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockDripFileVowRepository) Create(headerID int64, models []interface{}) error {
|
func (repository *MockDripFileVowRepository) Create(headerID int64, models []interface{}) error {
|
||||||
@ -69,4 +70,6 @@ func (repository *MockDripFileVowRepository) AssertMarkHeaderCheckedCalledWith(i
|
|||||||
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockDripFileVowRepository) SetDB(db *postgres.DB) {}
|
func (repository *MockDripFileVowRepository) SetDB(db *postgres.DB) {
|
||||||
|
repository.SetDbCalled = true
|
||||||
|
}
|
||||||
|
@ -26,6 +26,7 @@ type MockLogFetcher struct {
|
|||||||
FetchedBlocks []int64
|
FetchedBlocks []int64
|
||||||
fetcherError error
|
fetcherError error
|
||||||
FetchedLogs []types.Log
|
FetchedLogs []types.Log
|
||||||
|
SetBcCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mlf *MockLogFetcher) FetchLogs(contractAddresses []string, topics [][]common.Hash, blockNumber int64) ([]types.Log, error) {
|
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
|
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) {
|
func (mlf *MockLogFetcher) SetFetcherError(err error) {
|
||||||
mlf.fetcherError = err
|
mlf.fetcherError = err
|
||||||
|
@ -31,6 +31,7 @@ type MockPitFileDebtCeilingRepository struct {
|
|||||||
PassedEndingBlockNumber int64
|
PassedEndingBlockNumber int64
|
||||||
PassedHeaderID int64
|
PassedHeaderID int64
|
||||||
PassedModels []interface{}
|
PassedModels []interface{}
|
||||||
|
SetDbCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockPitFileDebtCeilingRepository) MarkHeaderChecked(headerID int64) error {
|
func (repository *MockPitFileDebtCeilingRepository) MarkHeaderChecked(headerID int64) error {
|
||||||
@ -70,4 +71,6 @@ func (repository *MockPitFileDebtCeilingRepository) AssertMarkHeaderCheckedCalle
|
|||||||
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockPitFileDebtCeilingRepository) SetDB(db *postgres.DB) {}
|
func (repository *MockPitFileDebtCeilingRepository) SetDB(db *postgres.DB) {
|
||||||
|
repository.SetDbCalled = true
|
||||||
|
}
|
||||||
|
@ -31,6 +31,7 @@ type MockPitFileIlkRepository struct {
|
|||||||
markHeaderCheckedPassedHeaderID int64
|
markHeaderCheckedPassedHeaderID int64
|
||||||
missingHeaders []core.Header
|
missingHeaders []core.Header
|
||||||
missingHeadersError error
|
missingHeadersError error
|
||||||
|
SetDbCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockPitFileIlkRepository) SetCreateError(err error) {
|
func (repository *MockPitFileIlkRepository) SetCreateError(err error) {
|
||||||
@ -70,4 +71,6 @@ func (repository *MockPitFileIlkRepository) AssertMarkHeaderCheckedCalledWith(i
|
|||||||
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockPitFileIlkRepository) SetDB(db *postgres.DB) {}
|
func (repository *MockPitFileIlkRepository) SetDB(db *postgres.DB) {
|
||||||
|
repository.SetDbCalled = true
|
||||||
|
}
|
||||||
|
@ -31,6 +31,7 @@ type MockPitFileStabilityFeeRepository struct {
|
|||||||
PassedEndingBlockNumber int64
|
PassedEndingBlockNumber int64
|
||||||
PassedHeaderID int64
|
PassedHeaderID int64
|
||||||
PassedModels []interface{}
|
PassedModels []interface{}
|
||||||
|
SetDbCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockPitFileStabilityFeeRepository) Create(headerID int64, models []interface{}) error {
|
func (repository *MockPitFileStabilityFeeRepository) Create(headerID int64, models []interface{}) error {
|
||||||
@ -70,4 +71,6 @@ func (repository *MockPitFileStabilityFeeRepository) AssertMarkHeaderCheckedCall
|
|||||||
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockPitFileStabilityFeeRepository) SetDB(db *postgres.DB) {}
|
func (repository *MockPitFileStabilityFeeRepository) SetDB(db *postgres.DB) {
|
||||||
|
repository.SetDbCalled = true
|
||||||
|
}
|
||||||
|
@ -31,6 +31,7 @@ type MockTendRepository struct {
|
|||||||
markHeaderCheckedPassedHeaderId int64
|
markHeaderCheckedPassedHeaderId int64
|
||||||
missingHeaders []core.Header
|
missingHeaders []core.Header
|
||||||
missingHeadersError error
|
missingHeadersError error
|
||||||
|
SetDbCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockTendRepository) Create(headerId int64, tend []interface{}) error {
|
func (repository *MockTendRepository) Create(headerId int64, tend []interface{}) error {
|
||||||
@ -70,4 +71,6 @@ func (repository *MockTendRepository) AssertMarkHeaderCheckedCalledWith(headerId
|
|||||||
Expect(repository.markHeaderCheckedPassedHeaderId).To(Equal(headerId))
|
Expect(repository.markHeaderCheckedPassedHeaderId).To(Equal(headerId))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockTendRepository) SetDB(db *postgres.DB) {}
|
func (repository *MockTendRepository) SetDB(db *postgres.DB) {
|
||||||
|
repository.SetDbCalled = true
|
||||||
|
}
|
||||||
|
@ -31,6 +31,7 @@ type MockVatInitRepository struct {
|
|||||||
PassedEndingBlockNumber int64
|
PassedEndingBlockNumber int64
|
||||||
PassedHeaderID int64
|
PassedHeaderID int64
|
||||||
PassedModels []interface{}
|
PassedModels []interface{}
|
||||||
|
SetDbCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockVatInitRepository) Create(headerID int64, models []interface{}) error {
|
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))
|
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockVatInitRepository) SetDB(db *postgres.DB) {}
|
func (repository *MockVatInitRepository) SetDB(db *postgres.DB) {
|
||||||
|
repository.SetDbCalled = true
|
||||||
|
}
|
||||||
|
@ -29,6 +29,7 @@ type MockVatMoveRepository struct {
|
|||||||
PassedModels []interface{}
|
PassedModels []interface{}
|
||||||
CheckedHeaderIDs []int64
|
CheckedHeaderIDs []int64
|
||||||
CheckedHeaderError error
|
CheckedHeaderError error
|
||||||
|
SetDbCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockVatMoveRepository) Create(headerID int64, models []interface{}) error {
|
func (repository *MockVatMoveRepository) Create(headerID int64, models []interface{}) error {
|
||||||
@ -64,4 +65,6 @@ func (repository *MockVatMoveRepository) SetCheckedHeaderError(e error) {
|
|||||||
repository.CheckedHeaderError = e
|
repository.CheckedHeaderError = e
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockVatMoveRepository) SetDB(db *postgres.DB) {}
|
func (repository *MockVatMoveRepository) SetDB(db *postgres.DB) {
|
||||||
|
repository.SetDbCalled = true
|
||||||
|
}
|
||||||
|
@ -22,11 +22,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type VatInitRepository struct {
|
type VatInitRepository struct {
|
||||||
DB *postgres.DB
|
db *postgres.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository VatInitRepository) Create(headerID int64, models []interface{}) error {
|
func (repository VatInitRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.DB.Begin()
|
tx, err := repository.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ func (repository VatInitRepository) Create(headerID int64, models []interface{})
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository VatInitRepository) MarkHeaderChecked(headerID int64) error {
|
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)
|
VALUES ($1, $2)
|
||||||
ON CONFLICT (header_id) DO
|
ON CONFLICT (header_id) DO
|
||||||
UPDATE SET vat_init_checked = $2`, headerID, true)
|
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) {
|
func (repository VatInitRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||||
var result []core.Header
|
var result []core.Header
|
||||||
err := repository.DB.Select(
|
err := repository.db.Select(
|
||||||
&result,
|
&result,
|
||||||
`SELECT headers.id, headers.block_number FROM headers
|
`SELECT headers.id, headers.block_number FROM headers
|
||||||
LEFT JOIN checked_headers on headers.id = header_id
|
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`,
|
AND headers.eth_node_fingerprint = $3`,
|
||||||
startingBlockNumber,
|
startingBlockNumber,
|
||||||
endingBlockNumber,
|
endingBlockNumber,
|
||||||
repository.DB.Node.ID,
|
repository.db.Node.ID,
|
||||||
)
|
)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *VatInitRepository) SetDB(db *postgres.DB) {
|
func (repository *VatInitRepository) SetDB(db *postgres.DB) {
|
||||||
repository.DB = db
|
repository.db = db
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,8 @@ var _ = Describe("Vat init repository", func() {
|
|||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
db = test_config.NewTestDB(core.Node{})
|
db = test_config.NewTestDB(core.Node{})
|
||||||
test_config.CleanTestDB(db)
|
test_config.CleanTestDB(db)
|
||||||
vatInitRepository = vat_init.VatInitRepository{DB: db}
|
vatInitRepository = vat_init.VatInitRepository{}
|
||||||
|
vatInitRepository.SetDB(db)
|
||||||
headerRepository = repositories.NewHeaderRepository(db)
|
headerRepository = repositories.NewHeaderRepository(db)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -180,7 +181,8 @@ var _ = Describe("Vat init repository", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
}
|
}
|
||||||
|
|
||||||
vatInitRepositoryTwo := vat_init.VatInitRepository{DB: dbTwo}
|
vatInitRepositoryTwo := vat_init.VatInitRepository{}
|
||||||
|
vatInitRepositoryTwo.SetDB(dbTwo)
|
||||||
err = vatInitRepository.MarkHeaderChecked(headerIDs[0])
|
err = vatInitRepository.MarkHeaderChecked(headerIDs[0])
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
@ -193,13 +195,4 @@ var _ = Describe("Vat init repository", func() {
|
|||||||
Expect(len(nodeTwoMissingHeaders)).To(Equal(len(blockNumbers)))
|
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))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
@ -55,6 +55,11 @@ var _ = Describe("Vat init transformer", func() {
|
|||||||
}.NewTransformer(nil, nil)
|
}.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() {
|
It("gets missing headers for block numbers specified in config", func() {
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
|
@ -21,11 +21,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type VatMoveRepository struct {
|
type VatMoveRepository struct {
|
||||||
DB *postgres.DB
|
db *postgres.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository VatMoveRepository) Create(headerID int64, models []interface{}) error {
|
func (repository VatMoveRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.DB.Begin()
|
tx, err := repository.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ func (repository VatMoveRepository) Create(headerID int64, models []interface{})
|
|||||||
|
|
||||||
func (repository VatMoveRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
func (repository VatMoveRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||||
var result []core.Header
|
var result []core.Header
|
||||||
err := repository.DB.Select(
|
err := repository.db.Select(
|
||||||
&result,
|
&result,
|
||||||
`SELECT headers.id, headers.block_number FROM headers
|
`SELECT headers.id, headers.block_number FROM headers
|
||||||
LEFT JOIN checked_headers on headers.id = header_id
|
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`,
|
AND headers.eth_node_fingerprint = $3`,
|
||||||
startingBlockNumber,
|
startingBlockNumber,
|
||||||
endingBlockNumber,
|
endingBlockNumber,
|
||||||
repository.DB.Node.ID,
|
repository.db.Node.ID,
|
||||||
)
|
)
|
||||||
|
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository VatMoveRepository) MarkHeaderChecked(headerID int64) error {
|
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)
|
VALUES ($1, $2)
|
||||||
ON CONFLICT (header_id) DO
|
ON CONFLICT (header_id) DO
|
||||||
UPDATE SET vat_move_checked = $2`, headerID, true)
|
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) {
|
func (repository *VatMoveRepository) SetDB(db *postgres.DB) {
|
||||||
repository.DB = db
|
repository.db = db
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,8 @@ 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.VatMoveRepository{DB: db}
|
vatMoveRepository = vat_move.VatMoveRepository{}
|
||||||
|
vatMoveRepository.SetDB(db)
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("Create", func() {
|
Describe("Create", func() {
|
||||||
@ -150,7 +151,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.VatMoveRepository{DB: dbTwo}
|
vatMoveRepositoryTwo := vat_move.VatMoveRepository{}
|
||||||
|
vatMoveRepositoryTwo.SetDB(dbTwo)
|
||||||
err := vatMoveRepository.Create(headerIDs[0], []interface{}{test_data.VatMoveModel})
|
err := vatMoveRepository.Create(headerIDs[0], []interface{}{test_data.VatMoveModel})
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
@ -195,13 +197,4 @@ var _ = Describe("Vat Move", func() {
|
|||||||
Expect(headerChecked).To(BeTrue())
|
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))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
@ -52,6 +52,11 @@ var _ = Describe("Vat move transformer", func() {
|
|||||||
}.NewTransformer(nil, nil)
|
}.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() {
|
It("gets missing headers for block numbers specified in config", func() {
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user