Add log index to various events (#78)

* Add log_index field to flip kick

* Add log index to flop kick

* Add repo tests for Cat.file

* Add log_index to vat_flux

* Add log_index to vat_slip

* Add log_index to vat_toll

* Add log_index to vat_tune

* Add test to repos for updating checked headers
This commit is contained in:
Elizabeth
2018-10-23 16:33:04 -05:00
committed by GitHub
parent 28f8861f81
commit 5682ee988b
45 changed files with 292 additions and 84 deletions
+1
View File
@@ -59,6 +59,7 @@ func (VatFluxConverter) ToModels(ethLogs []types.Log) ([]VatFluxModel, error) {
Dst: dst.String(),
Rad: rad,
TransactionIndex: ethLog.TxIndex,
LogIndex: ethLog.Index,
Raw: rawLogJson,
}
+1 -6
View File
@@ -31,12 +31,7 @@ var _ = Describe("VatFlux converter", func() {
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))
Expect(models[0].Rad).To(Equal(test_data.VatFluxModel.Rad))
Expect(models[0].TransactionIndex).To(Equal(test_data.VatFluxModel.TransactionIndex))
Expect(models[0].Raw).To(Equal(test_data.VatFluxModel.Raw))
Expect(models[0]).To(Equal(test_data.VatFluxModel))
})
It("Returns an error there are missing topics", func() {
+1
View File
@@ -20,5 +20,6 @@ type VatFluxModel struct {
Dst string
Rad string
TransactionIndex uint `db:"tx_idx"`
LogIndex uint `db:"log_idx"`
Raw []byte `db:"raw_log"`
}
+3 -3
View File
@@ -40,9 +40,9 @@ 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::numeric, $6, $7)`,
headerId, model.Ilk, model.Dst, model.Src, model.Rad, model.TransactionIndex, model.Raw)
_, err := tx.Exec(`INSERT INTO maker.vat_flux (header_id, ilk, dst, src, rad, tx_idx, log_idx, raw_log)
VALUES($1, $2, $3, $4, $5::NUMERIC, $6, $7, $8)`,
headerId, model.Ilk, model.Dst, model.Src, model.Rad, model.TransactionIndex, model.LogIndex, model.Raw)
if err != nil {
tx.Rollback()
return err
@@ -69,6 +69,7 @@ var _ = Describe("VatFlux Repository", func() {
Expect(dbResult[0].Rad).To(Equal(test_data.VatFluxModel.Rad))
Expect(dbResult[0].TransactionIndex).To(Equal(test_data.VatFluxModel.TransactionIndex))
Expect(dbResult[1].TransactionIndex).To(Equal(test_data.VatFluxModel.TransactionIndex + 1))
Expect(dbResult[0].LogIndex).To(Equal(test_data.VatFluxModel.LogIndex))
Expect(dbResult[0].Raw).To(MatchJSON(test_data.VatFluxModel.Raw))
Expect(dbResult[0].HeaderId).To(Equal(headerId))
})
@@ -81,6 +82,17 @@ var _ = Describe("VatFlux Repository", func() {
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
})
It("allows for multiple vat flux events in one transaction if they have different log indexes", func() {
err = repository.Create(headerId, []vat_flux.VatFluxModel{test_data.VatFluxModel})
Expect(err).NotTo(HaveOccurred())
anotherVatFlux := test_data.VatFluxModel
anotherVatFlux.LogIndex = anotherVatFlux.LogIndex + 1
err = repository.Create(headerId, []vat_flux.VatFluxModel{anotherVatFlux})
Expect(err).NotTo(HaveOccurred())
})
It("marks the header as checked for vat flux logs", func() {
err = repository.Create(headerId, []vat_flux.VatFluxModel{test_data.VatFluxModel})
Expect(err).NotTo(HaveOccurred())
@@ -91,6 +103,18 @@ var _ = Describe("VatFlux Repository", func() {
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 = repository.Create(headerId, []vat_flux.VatFluxModel{test_data.VatFluxModel})
Expect(err).NotTo(HaveOccurred())
var headerChecked bool
err = db.Get(&headerChecked, `SELECT vat_flux_checked FROM public.checked_headers WHERE header_id = $1`, headerId)
Expect(err).NotTo(HaveOccurred())
Expect(headerChecked).To(BeTrue())
})
It("removes vat flux if corresponding header is deleted", func() {
err = repository.Create(headerId, []vat_flux.VatFluxModel{test_data.VatFluxModel})
Expect(err).NotTo(HaveOccurred())