Merge pull request #139 from vulcanize/contract-watcher-uint8
Correctly parse uint8 values in contract watcher
This commit is contained in:
commit
dc30099a7c
@ -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{}
|
||||
|
File diff suppressed because one or more lines are too long
@ -239,6 +239,24 @@ func SetupMarketPlaceContract(wantedEvents, wantedMethods []string) *contract.Co
|
||||
}.Init()
|
||||
}
|
||||
|
||||
func SetupMolochContract(wantedEvents, wantedMethods []string) *contract.Contract {
|
||||
p := mocks.NewParser(constants.MolochAbiString)
|
||||
err := p.Parse()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
return contract.Contract{
|
||||
Name: "Moloch",
|
||||
Address: constants.MolochContractAddress,
|
||||
StartingBlock: 7218566,
|
||||
Abi: p.Abi(),
|
||||
ParsedAbi: p.ParsedAbi(),
|
||||
Events: p.GetEvents(wantedEvents),
|
||||
Methods: p.GetSelectMethods(wantedMethods),
|
||||
FilterArgs: map[string]bool{},
|
||||
MethodArgs: map[string]bool{},
|
||||
}.Init()
|
||||
}
|
||||
|
||||
// TODO: tear down/setup DB from migrations so this doesn't alter the schema between tests
|
||||
func TearDown(db *postgres.DB) {
|
||||
tx, err := db.Beginx()
|
||||
|
@ -295,6 +295,23 @@ var MockOrderCreatedLog = types.Log{
|
||||
Removed: false,
|
||||
}
|
||||
|
||||
var MockSubmitVoteLog = types.Log{
|
||||
Address: common.HexToAddress(constants.MolochContractAddress),
|
||||
Topics: []common.Hash{
|
||||
common.HexToHash("0x29bf0061f2faa9daa482f061b116195432d435536d8af4ae6b3c5dd78223679b"),
|
||||
common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000061"),
|
||||
common.HexToHash("0x0000000000000000000000006ddf1b8e6d71b5b33912607098be123ffe62ae53"),
|
||||
common.HexToHash("0x00000000000000000000000037385081870ef47e055410fefd582e2a95d2960b"),
|
||||
},
|
||||
Data: hexutil.MustDecode("0x0000000000000000000000000000000000000000000000000000000000000001"),
|
||||
BlockNumber: 8517621,
|
||||
TxHash: common.HexToHash("0xcc7390a2099812d0dfc9baef201afbc7a44bfae145050c9dc700b77cbd3cd752"),
|
||||
TxIndex: 103,
|
||||
BlockHash: common.HexToHash("0x3e82681d8036b1225fcaa8bcd4cdbe757b39f13468286b303cde22146385525e"),
|
||||
Index: 132,
|
||||
Removed: false,
|
||||
}
|
||||
|
||||
var ens = strings.ToLower(constants.EnsContractAddress)
|
||||
var tusd = strings.ToLower(constants.TusdContractAddress)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user