Skip to content

Commit

Permalink
abi2: bugfix. not matching events based on number of indexed fields
Browse files Browse the repository at this point in the history
I noticed that certain abi events were not being saved to my table and
upon further inspection I realized that when I had setup my integration
I only selected 1 out of 3 of the indexed fields on the event.

When an integration is testing a log to see if it should index it, it
uses two methods:

1. topics[0] byte comparison
2. the number of non-empty remaining topics matches number of indexed
   inputs in the abi

In my case, the 2nd method was failing because of a bug. The code was
reporting the number of indexed inputs based upon the selected inputs.
Instead, we should simply look at all the top level inputs to see if
Indexed=true.
  • Loading branch information
ryandotsmith committed Nov 1, 2023
1 parent 6346b75 commit e3eade2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion abi2/abi2.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func (e Event) Selected() []Input {

func (e Event) numIndexed() int {
var res int
for _, inp := range e.Selected() {
for _, inp := range e.Inputs {
if inp.Indexed {
res++
}
Expand Down
12 changes: 12 additions & 0 deletions abi2/abi2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,15 @@ func TestSelected(t *testing.T) {
}
diff.Test(t, t.Errorf, want, event.Selected())
}

func TestNumIndexed(t *testing.T) {
event := Event{
Name: "",
Inputs: []Input{
Input{Indexed: true, Name: "a"},
Input{Indexed: true, Name: "b", Column: "b"},
Input{Indexed: true, Name: "c", Column: "c"},
},
}
diff.Test(t, t.Errorf, 3, event.numIndexed())
}

0 comments on commit e3eade2

Please sign in to comment.