forked from cerc-io/ipld-eth-server
Merge pull request #141 from vulcanize/contract-watcher-duplicate-inserts
Do nothing on duplicate log insert in contract watcher
This commit is contained in:
commit
a596966b7c
@ -128,7 +128,7 @@ func (r *eventRepository) persistHeaderSyncLogs(logs []types.Log, eventInfo type
|
|||||||
for i := 0; i < el; i++ {
|
for i := 0; i < el; i++ {
|
||||||
pgStr = pgStr + fmt.Sprintf(", $%d", i+6)
|
pgStr = pgStr + fmt.Sprintf(", $%d", i+6)
|
||||||
}
|
}
|
||||||
pgStr = pgStr + ")"
|
pgStr = pgStr + ") ON CONFLICT DO NOTHING"
|
||||||
|
|
||||||
// Add this query to the transaction
|
// Add this query to the transaction
|
||||||
_, err = tx.Exec(pgStr, data...)
|
_, err = tx.Exec(pgStr, data...)
|
||||||
|
@ -320,17 +320,13 @@ var _ = Describe("Repository", func() {
|
|||||||
err = hr.AddCheckColumn(event.Name + "_" + con.Address)
|
err = hr.AddCheckColumn(event.Name + "_" + con.Address)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
// Try and fail to persist the same log twice in a single call
|
// Successfully persist the two unique logs
|
||||||
err = dataStore.PersistLogs([]types.Log{logs[0], logs[0]}, event, con.Address, con.Name)
|
|
||||||
Expect(err).To(HaveOccurred())
|
|
||||||
|
|
||||||
// Successfuly persist the two unique logs
|
|
||||||
err = dataStore.PersistLogs(logs, event, con.Address, con.Name)
|
err = dataStore.PersistLogs(logs, event, con.Address, con.Name)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
// Try and fail to persist the same logs again in separate call
|
// Try to insert the same logs again
|
||||||
err = dataStore.PersistLogs([]types.Log{*log}, event, con.Address, con.Name)
|
err = dataStore.PersistLogs(logs, event, con.Address, con.Name)
|
||||||
Expect(err).To(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
// Show that no new logs were entered
|
// Show that no new logs were entered
|
||||||
var count int
|
var count int
|
||||||
@ -339,6 +335,26 @@ var _ = Describe("Repository", func() {
|
|||||||
Expect(count).To(Equal(2))
|
Expect(count).To(Equal(2))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("inserts additional log if only some are duplicate", func() {
|
||||||
|
hr := lr.NewHeaderRepository(db)
|
||||||
|
err = hr.AddCheckColumn(event.Name + "_" + con.Address)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
// Successfully persist first log
|
||||||
|
err = dataStore.PersistLogs([]types.Log{logs[0]}, event, con.Address, con.Name)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
// Successfully persist second log even though first already persisted
|
||||||
|
err = dataStore.PersistLogs(logs, event, con.Address, con.Name)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
// Show that both logs were entered
|
||||||
|
var count int
|
||||||
|
err = db.Get(&count, fmt.Sprintf("SELECT COUNT(*) FROM header_%s.transfer_event", constants.TusdContractAddress))
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(count).To(Equal(2))
|
||||||
|
})
|
||||||
|
|
||||||
It("Fails if the persisted event does not have a corresponding eventID column in the checked_headers table", func() {
|
It("Fails if the persisted event does not have a corresponding eventID column in the checked_headers table", func() {
|
||||||
err = dataStore.PersistLogs(logs, event, con.Address, con.Name)
|
err = dataStore.PersistLogs(logs, event, con.Address, con.Name)
|
||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
|
Loading…
Reference in New Issue
Block a user