Correctly parse uint8 values in contract watcher

- calling string(uint8) => insert errors on numeric columns
This commit is contained in:
Rob Mulholand
2019-09-20 21:37:59 -05:00
parent 8bbd65eabd
commit 3466a51b4d
5 changed files with 60 additions and 7 deletions
@@ -89,9 +89,9 @@ func (c *Converter) Convert(logs []gethTypes.Log, event types.Event, headerID in
if len(b) == 32 {
seenHashes = append(seenHashes, common.HexToHash(strValues[fieldName]))
}
case byte:
b := input.(byte)
strValues[fieldName] = string(b)
case uint8:
u := input.(uint8)
strValues[fieldName] = strconv.Itoa(int(u))
case [32]uint8:
raw := input.([32]uint8)
converted := convertUintSliceToHash(raw)
@@ -173,9 +173,9 @@ func (c *Converter) ConvertBatch(logs []gethTypes.Log, events map[string]types.E
if len(b) == 32 { // collect byte arrays of size 32 as hashes
seenHashes = append(seenHashes, common.BytesToHash(b))
}
case byte:
b := input.(byte)
strValues[fieldName] = string(b)
case uint8:
u := input.(uint8)
strValues[fieldName] = strconv.Itoa(int(u))
case [32]uint8:
raw := input.([32]uint8)
converted := convertUintSliceToHash(raw)
@@ -34,6 +34,7 @@ var _ = Describe("Converter", func() {
var tusdWantedEvents = []string{"Transfer", "Mint"}
var ensWantedEvents = []string{"NewOwner"}
var marketPlaceWantedEvents = []string{"OrderCreated"}
var molochWantedEvents = []string{"SubmitVote"}
var err error
Describe("Update", func() {
@@ -146,7 +147,7 @@ var _ = Describe("Converter", func() {
Expect(ok).To(Equal(false))
})
It("keeps track of hashes derived from bytes32", func() {
It("correctly parses bytes32", func() {
con = test_helpers.SetupMarketPlaceContract(marketPlaceWantedEvents, []string{})
event, ok := con.Events["OrderCreated"]
Expect(ok).To(BeTrue())
@@ -160,6 +161,20 @@ var _ = Describe("Converter", func() {
Expect(result[0].Values["id"]).To(Equal("0x633f94affdcabe07c000231f85c752c97b9cc43966b432ec4d18641e6d178233"))
})
It("correctly parses uint8", func() {
con = test_helpers.SetupMolochContract(molochWantedEvents, []string{})
event, ok := con.Events["SubmitVote"]
Expect(ok).To(BeTrue())
c := converter.Converter{}
c.Update(con)
result, err := c.Convert([]types.Log{mocks.MockSubmitVoteLog}, event, 232)
Expect(err).NotTo(HaveOccurred())
Expect(len(result)).To(Equal(1))
Expect(result[0].Values["uintVote"]).To(Equal("1"))
})
It("Fails with an empty contract", func() {
event := con.Events["Transfer"]
c := converter.Converter{}