Skip to content

Commit

Permalink
Convert hex to hash before comparing header hash
Browse files Browse the repository at this point in the history
- When determining equality between diff and db
- Prevents false negatives derived from presence/absence of 0x prefix
  • Loading branch information
rmulhol committed Nov 25, 2019
1 parent 5c9a054 commit d73a988
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libraries/shared/watcher/storage_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (storageWatcher StorageWatcher) getHeaderID(diff utils.StorageDiff) (int64,
if getHeaderErr != nil {
return 0, getHeaderErr
}
if diff.BlockHash.Hex() != header.Hash {
if diff.BlockHash != common.HexToHash(header.Hash) {
return 0, NewErrHeaderMismatch(header.Hash, diff.BlockHash.Hex())
}
return header.Id, nil
Expand Down
14 changes: 14 additions & 0 deletions libraries/shared/watcher/storage_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ var _ = Describe("Storage Watcher", func() {
close(done)
})

It("recognizes header match even if hash hex missing 0x prefix", func(done Done) {
mockHeaderRepository.GetHeaderReturnHash = fakes.FakeHash.Hex()[2:]

go func() {
err := storageWatcher.Execute(time.Hour)
Expect(err).NotTo(HaveOccurred())
}()

Eventually(func() utils.StorageDiff {
return mockTransformer.PassedDiff
}).Should(Equal(csvDiff))
close(done)
})

It("queues diff for later processing if transformer execution fails", func(done Done) {
mockTransformer.ExecuteErr = fakes.FakeError

Expand Down

0 comments on commit d73a988

Please sign in to comment.