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
+2
View File
@@ -51,6 +51,7 @@ func (FlipKickConverter) ToEntities(contractAbi string, ethLogs []types.Log) (re
}
entity.Raw = ethLog
entity.TransactionIndex = ethLog.TxIndex
entity.LogIndex = ethLog.Index
results = append(results, *entity)
}
@@ -86,6 +87,7 @@ func (FlipKickConverter) ToModels(flipKicks []FlipKickEntity) (results []FlipKic
Urn: urn,
Tab: tab,
TransactionIndex: flipKick.TransactionIndex,
LogIndex: flipKick.LogIndex,
Raw: rawLogString,
}
results = append(results, model)
+1 -8
View File
@@ -38,14 +38,7 @@ var _ = Describe("FlipKick Converter", func() {
Expect(err).NotTo(HaveOccurred())
Expect(len(entities)).To(Equal(1))
entity := entities[0]
Expect(entity.Id).To(Equal(test_data.FlipKickEntity.Id))
Expect(entity.Lot).To(Equal(test_data.FlipKickEntity.Lot))
Expect(entity.Bid).To(Equal(test_data.FlipKickEntity.Bid))
Expect(entity.Gal).To(Equal(test_data.FlipKickEntity.Gal))
Expect(entity.End).To(Equal(test_data.FlipKickEntity.End))
Expect(entity.Urn).To(Equal(test_data.FlipKickEntity.Urn))
Expect(entity.Tab).To(Equal(test_data.FlipKickEntity.Tab))
Expect(entity.Raw).To(Equal(test_data.FlipKickEntity.Raw))
Expect(entity).To(Equal(test_data.FlipKickEntity))
})
It("returns an error if converting log to entity fails", func() {
+1
View File
@@ -30,5 +30,6 @@ type FlipKickEntity struct {
Urn [32]byte
Tab *big.Int
TransactionIndex uint
LogIndex uint
Raw types.Log
}
+1
View File
@@ -25,5 +25,6 @@ type FlipKickModel struct {
Urn string
Tab string
TransactionIndex uint `db:"tx_idx"`
LogIndex uint `db:"log_idx"`
Raw string `db:"raw_log"`
}
+3 -3
View File
@@ -41,9 +41,9 @@ func (fkr FlipKickRepository) Create(headerId int64, flipKicks []FlipKickModel)
}
for _, flipKick := range flipKicks {
_, err := tx.Exec(
`INSERT into maker.flip_kick (header_id, bid_id, lot, bid, gal, "end", urn, tab, tx_idx, raw_log)
VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`,
headerId, flipKick.BidId, flipKick.Lot, flipKick.Bid, flipKick.Gal, flipKick.End, flipKick.Urn, flipKick.Tab, flipKick.TransactionIndex, flipKick.Raw,
`INSERT into maker.flip_kick (header_id, bid_id, lot, bid, gal, "end", urn, tab, tx_idx, log_idx, raw_log)
VALUES($1, $2::NUMERIC, $3::NUMERIC, $4::NUMERIC, $5, $6, $7, $8::NUMERIC, $9, $10, $11)`,
headerId, flipKick.BidId, flipKick.Lot, flipKick.Bid, flipKick.Gal, flipKick.End, flipKick.Urn, flipKick.Tab, flipKick.TransactionIndex, flipKick.LogIndex, flipKick.Raw,
)
if err != nil {
tx.Rollback()
@@ -69,6 +69,7 @@ var _ = Describe("FlipKick Repository", func() {
Expect(dbResult.Urn).To(Equal(flipKick.Urn))
Expect(dbResult.Tab).To(Equal(flipKick.Tab))
Expect(dbResult.TransactionIndex).To(Equal(flipKick.TransactionIndex))
Expect(dbResult.LogIndex).To(Equal(flipKick.LogIndex))
Expect(dbResult.Raw).To(MatchJSON(flipKick.Raw))
})
@@ -82,6 +83,18 @@ var _ = Describe("FlipKick 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 = flipKickRepository.Create(headerId, []flip_kick.FlipKickModel{flipKick})
Expect(err).NotTo(HaveOccurred())
var headerChecked bool
err = db.Get(&headerChecked, `SELECT flip_kick_checked FROM public.checked_headers WHERE header_id = $1`, headerId)
Expect(err).NotTo(HaveOccurred())
Expect(headerChecked).To(BeTrue())
})
It("returns an error if inserting the flip_kick record fails", func() {
err := flipKickRepository.Create(headerId, []flip_kick.FlipKickModel{flipKick})
Expect(err).NotTo(HaveOccurred())
@@ -91,6 +104,14 @@ var _ = Describe("FlipKick Repository", func() {
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
})
It("allows for multiple flip kick events in one transaction if they have different log indexes", func() {
newFlipKick := test_data.FlipKickModel
newFlipKick.LogIndex = newFlipKick.LogIndex + 1
err := flipKickRepository.Create(headerId, []flip_kick.FlipKickModel{newFlipKick})
Expect(err).NotTo(HaveOccurred())
})
It("deletes the flip_kick records if its corresponding header record is deleted", func() {
err := flipKickRepository.Create(headerId, []flip_kick.FlipKickModel{flipKick})
Expect(err).NotTo(HaveOccurred())