update from pr feedback; update tests and use shared fake header
This commit is contained in:
parent
f32a4fa2a5
commit
2f64269ab3
@ -28,8 +28,8 @@ var VatFluxLog = types.Log{
|
||||
Address: common.HexToAddress("0x239e6f0ab02713f1f8aa90ebeded9fc66dc96cd6"),
|
||||
Topics: []common.Hash{
|
||||
common.HexToHash("0xa6e4182100000000000000000000000000000000000000000000000000000000"),
|
||||
common.HexToHash("0x0000000000000000000000007340e006f4135ba6970d43bf43d88dcad4e7a8ca"),
|
||||
common.HexToHash("0x0000000000000000000000007fa9ef6609ca7921112231f8f195138ebba29770"),
|
||||
common.HexToHash("0x0000000000000000000000007340e006f4135BA6970D43bf43d88DCAD4e7a8CA"),
|
||||
common.HexToHash("0x0000000000000000000000007FA9EF6609Ca7921112231f8f195138ebba29770"),
|
||||
common.HexToHash("0x00000000000000000000000093086347c52a8878af71bb818509d484c6a2e1bf"),
|
||||
},
|
||||
Data: hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000084a6e418217340e006f4135ba6970d43bf43d88dcad4e7a8ca00000000000000000000000007fa9ef6609ca7921112231f8f195138ebba297700000000000000000000000093086347c52a8878af71bb818509d484c6a2e1bf000000000000000000000000000000000000000000000000000000000000000000000000000000000000007b"),
|
||||
@ -44,7 +44,7 @@ var VatFluxLog = types.Log{
|
||||
var rawFluxLog, _ = json.Marshal(VatFluxLog)
|
||||
var VatFluxModel = vat_flux.VatFluxModel{
|
||||
Ilk: "0x7340e006f4135BA6970D43bf43d88DCAD4e7a8CA",
|
||||
Src: "0x07Fa9eF6609cA7921112231F8f195138ebbA2977",
|
||||
Src: "0x7FA9EF6609Ca7921112231f8f195138ebba29770",
|
||||
Dst: "0x93086347c52a8878af71bB818509d484c6a2e1bF",
|
||||
Rad: "123",
|
||||
TransactionIndex: 0,
|
||||
|
@ -30,6 +30,7 @@ var _ = Describe("VatFlux converter", func() {
|
||||
models, err := converter.ToModels([]types.Log{test_data.VatFluxLog})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(models)).To(Equal(1))
|
||||
Expect(models[0].Ilk).To(Equal(test_data.VatFluxModel.Ilk))
|
||||
Expect(models[0].Src).To(Equal(test_data.VatFluxModel.Src))
|
||||
Expect(models[0].Dst).To(Equal(test_data.VatFluxModel.Dst))
|
||||
|
@ -41,7 +41,7 @@ func (repository VatFluxRepository) Create(headerId int64, models []VatFluxModel
|
||||
|
||||
for _, model := range models {
|
||||
_, err := tx.Exec(`INSERT INTO maker.vat_flux (header_id, ilk, dst, src, rad, tx_idx, raw_log)
|
||||
VALUES($1, $2, $3, $4, $5, $6, $7)`,
|
||||
VALUES($1, $2, $3, $4, $5::numeric, $6, $7)`,
|
||||
headerId, model.Ilk, model.Dst, model.Src, model.Rad, model.TransactionIndex, model.Raw)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"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/test_data"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_flux"
|
||||
"github.com/vulcanize/vulcanizedb/test_config"
|
||||
@ -38,7 +39,7 @@ var _ = Describe("VatFlux Repository", func() {
|
||||
test_config.CleanTestDB(db)
|
||||
repository = vat_flux.VatFluxRepository{DB: db}
|
||||
headerRepository = repositories.NewHeaderRepository(db)
|
||||
headerId, err = headerRepository.CreateOrUpdateHeader(core.Header{})
|
||||
headerId, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
@ -122,7 +123,7 @@ var _ = Describe("VatFlux Repository", func() {
|
||||
var headerIds []int64
|
||||
blockNumbers := []int64{startingBlock, vatFluxBlock, endingBlock, outsideRangeBlock}
|
||||
for _, n := range blockNumbers {
|
||||
headerId, err := headerRepository.CreateOrUpdateHeader(core.Header{BlockNumber: n})
|
||||
headerId, err := headerRepository.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
headerIds = append(headerIds, headerId)
|
||||
}
|
||||
@ -146,7 +147,7 @@ var _ = Describe("VatFlux Repository", func() {
|
||||
var headerIds []int64
|
||||
blockNumbers := []int64{startingBlock, vatFluxBlock, endingBlock, outsideRangeBlock}
|
||||
for _, n := range blockNumbers {
|
||||
headerId, err := headerRepository.CreateOrUpdateHeader(core.Header{BlockNumber: n})
|
||||
headerId, err := headerRepository.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
headerIds = append(headerIds, headerId)
|
||||
}
|
||||
@ -174,11 +175,11 @@ var _ = Describe("VatFlux Repository", func() {
|
||||
var headerIds []int64
|
||||
blockNumbers := []int64{startingBlock, vatFluxBlock, endingBlock, outsideRangeBlock}
|
||||
for _, n := range blockNumbers {
|
||||
headerId, err := headerRepository.CreateOrUpdateHeader(core.Header{BlockNumber: n})
|
||||
headerId, err := headerRepository.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
headerIds = append(headerIds, headerId)
|
||||
|
||||
_, err = headerRepository2.CreateOrUpdateHeader(core.Header{BlockNumber: n})
|
||||
_, err = headerRepository2.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,55 @@ import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_flux"
|
||||
)
|
||||
|
||||
type setupOptions struct {
|
||||
setMissingHeadersError bool
|
||||
setFetcherError bool
|
||||
setConverterError bool
|
||||
setCreateError bool
|
||||
fetchedLogs []types.Log
|
||||
missingHeaders []core.Header
|
||||
}
|
||||
|
||||
func setup(options setupOptions) (
|
||||
vat_flux.VatFluxTransformer,
|
||||
*mocks.MockLogFetcher,
|
||||
*vat_flux_mocks.MockVatFlux,
|
||||
*vat_flux_mocks.MockVatFluxRepository,
|
||||
) {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
if options.setFetcherError {
|
||||
fetcher.SetFetcherError(fakes.FakeError)
|
||||
}
|
||||
if len(options.fetchedLogs) > 0 {
|
||||
fetcher.SetFetchedLogs(options.fetchedLogs)
|
||||
}
|
||||
|
||||
converter := &vat_flux_mocks.MockVatFlux{}
|
||||
if options.setConverterError {
|
||||
converter.SetConverterError(fakes.FakeError)
|
||||
}
|
||||
|
||||
repository := &vat_flux_mocks.MockVatFluxRepository{}
|
||||
if options.setMissingHeadersError {
|
||||
repository.SetMissingHeadersErr(fakes.FakeError)
|
||||
}
|
||||
if options.setCreateError {
|
||||
repository.SetCreateError(fakes.FakeError)
|
||||
}
|
||||
if len(options.missingHeaders) > 0 {
|
||||
repository.SetMissingHeaders(options.missingHeaders)
|
||||
}
|
||||
|
||||
transformer := vat_flux.VatFluxTransformer{
|
||||
Config: vat_flux.VatFluxConfig,
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
return transformer, fetcher, converter, repository
|
||||
}
|
||||
|
||||
var _ = Describe("Vat flux transformer", func() {
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
repository := &vat_flux_mocks.MockVatFluxRepository{}
|
||||
@ -47,6 +96,18 @@ var _ = Describe("Vat flux transformer", func() {
|
||||
Expect(err).To(MatchError(fakes.FakeError))
|
||||
})
|
||||
|
||||
It("marks the header as checked when there are no logs", func() {
|
||||
header := core.Header{Id: GinkgoRandomSeed()}
|
||||
transformer, _, _, repository := setup(setupOptions{
|
||||
missingHeaders: []core.Header{header},
|
||||
})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.MarkHeaderCheckedPassedHeaderID).To(Equal(header.Id))
|
||||
})
|
||||
|
||||
It("fetches logs for missing headers", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
repository := &vat_flux_mocks.MockVatFluxRepository{}
|
||||
|
Loading…
Reference in New Issue
Block a user