Fix filters with alternate topic values
This commit is contained in:
parent
6f66ef595e
commit
5569c3971b
@ -933,6 +933,42 @@ func TestEthGetLogs(t *testing.T) {
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "find all EventOneIndexedWithData events from contract1 or contract2",
|
||||
spec: EthFilterBuilder().
|
||||
FromBlockEpoch(0).
|
||||
AddressOneOf(contract1, contract2).
|
||||
Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventOneIndexedWithData"])).
|
||||
Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
EventMatrixContract.Ev["EventOneIndexedWithData"],
|
||||
paddedUint64(44),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
EventMatrixContract.Ev["EventOneIndexedWithData"],
|
||||
paddedUint64(46),
|
||||
},
|
||||
Data: paddedUint64(12),
|
||||
},
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
EventMatrixContract.Ev["EventOneIndexedWithData"],
|
||||
paddedUint64(50),
|
||||
},
|
||||
Data: paddedUint64(9),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "find all events with topic2 of 46",
|
||||
spec: EthFilterBuilder().FromBlockEpoch(0).Topic2OneOf(paddedEthHash(paddedUint64(46))).Filter(),
|
||||
@ -1052,6 +1088,35 @@ func TestEthGetLogs(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "find all events with topic1 of EventTwoIndexedWithData or EventOneIndexed and topic2 of 44",
|
||||
spec: EthFilterBuilder().
|
||||
FromBlockEpoch(0).
|
||||
Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoIndexedWithData"]), paddedEthHash(EventMatrixContract.Ev["EventOneIndexed"])).
|
||||
Topic2OneOf(paddedEthHash(paddedUint64(44))).
|
||||
Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
EventMatrixContract.Ev["EventTwoIndexedWithData"],
|
||||
paddedUint64(44),
|
||||
paddedUint64(27),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
EventMatrixContract.Ev["EventOneIndexed"],
|
||||
paddedUint64(44),
|
||||
},
|
||||
Data: nil,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
@ -914,13 +914,16 @@ func (e *EthEvent) installEthFilterSpec(ctx context.Context, filterSpec *ethtype
|
||||
}
|
||||
|
||||
for idx, vals := range filterSpec.Topics {
|
||||
if len(vals) == 0 {
|
||||
continue
|
||||
}
|
||||
// Ethereum topics are emitted using `LOG{0..4}` opcodes resulting in topics1..4
|
||||
key := fmt.Sprintf("topic%d", idx+1)
|
||||
keyvals := make([][]byte, len(vals))
|
||||
for i, v := range vals {
|
||||
keyvals[i] = v[:]
|
||||
for _, v := range vals {
|
||||
buf := make([]byte, len(v[:]))
|
||||
copy(buf, v[:])
|
||||
keys[key] = append(keys[key], buf)
|
||||
}
|
||||
keys[key] = keyvals
|
||||
}
|
||||
|
||||
return e.EventFilterManager.Install(ctx, minHeight, maxHeight, tipsetCid, addresses, keys)
|
||||
|
Loading…
Reference in New Issue
Block a user