Cleanup and fix eth filter tests

This commit is contained in:
Ian Davis 2023-01-19 12:58:23 +00:00
parent 5569c3971b
commit ca5cab4c43
3 changed files with 106 additions and 156 deletions

View File

@ -100,9 +100,18 @@ func (f *EventFilter) CollectEvents(ctx context.Context, te *TipSetEvents, rever
continue continue
} }
decodedEntries := make([]types.EventEntry, len(ev.Entries))
for i, entry := range ev.Entries {
decodedEntries[i] = types.EventEntry{
Flags: entry.Flags,
Key: entry.Key,
Value: decodeLogBytes(entry.Value),
}
}
// event matches filter, so record it // event matches filter, so record it
cev := &CollectedEvent{ cev := &CollectedEvent{
Entries: ev.Entries, Entries: decodedEntries,
EmitterAddr: addr, EmitterAddr: addr,
EventIdx: evIdx, EventIdx: evIdx,
Reverted: revert, Reverted: revert,

View File

@ -81,7 +81,8 @@ var EventsContract = SolidityContractDef{
} }
func TestEthNewPendingTransactionFilter(t *testing.T) { func TestEthNewPendingTransactionFilter(t *testing.T) {
ctx := context.Background() ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
kit.QuietAllLogsExcept("events", "messagepool") kit.QuietAllLogsExcept("events", "messagepool")
@ -113,9 +114,15 @@ func TestEthNewPendingTransactionFilter(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
<-headChangeCh // skip hccurrent <-headChangeCh // skip hccurrent
defer func() {
close(waitAllCh)
}()
count := 0 count := 0
for { for {
select { select {
case <-ctx.Done():
return
case headChanges := <-headChangeCh: case headChanges := <-headChangeCh:
for _, change := range headChanges { for _, change := range headChanges {
if change.Type == store.HCApply { if change.Type == store.HCApply {
@ -123,7 +130,7 @@ func TestEthNewPendingTransactionFilter(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
count += len(msgs) count += len(msgs)
if count == iterations { if count == iterations {
waitAllCh <- struct{}{} return
} }
} }
} }
@ -148,8 +155,8 @@ func TestEthNewPendingTransactionFilter(t *testing.T) {
select { select {
case <-waitAllCh: case <-waitAllCh:
case <-time.After(time.Minute): case <-ctx.Done():
t.Errorf("timeout to wait for pack messages") t.Errorf("timeout waiting to pack messages")
} }
expected := make(map[string]bool) expected := make(map[string]bool)
@ -178,7 +185,8 @@ func TestEthNewPendingTransactionFilter(t *testing.T) {
} }
func TestEthNewBlockFilter(t *testing.T) { func TestEthNewBlockFilter(t *testing.T) {
ctx := context.Background() ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
kit.QuietAllLogsExcept("events", "messagepool") kit.QuietAllLogsExcept("events", "messagepool")
@ -211,17 +219,22 @@ func TestEthNewBlockFilter(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
<-headChangeCh // skip hccurrent <-headChangeCh // skip hccurrent
defer func() {
close(tipsetChan)
close(waitAllCh)
}()
count := 0 count := 0
for { for {
select { select {
case <-ctx.Done():
return
case headChanges := <-headChangeCh: case headChanges := <-headChangeCh:
for _, change := range headChanges { for _, change := range headChanges {
if change.Type == store.HCApply || change.Type == store.HCRevert { if change.Type == store.HCApply || change.Type == store.HCRevert {
count++ count++
tipsetChan <- change.Val tipsetChan <- change.Val
if count == iterations { if count == iterations {
close(tipsetChan)
close(waitAllCh)
return return
} }
} }
@ -244,8 +257,8 @@ func TestEthNewBlockFilter(t *testing.T) {
select { select {
case <-waitAllCh: case <-waitAllCh:
case <-time.After(time.Minute): case <-ctx.Done():
t.Errorf("timeout to wait for pack messages") t.Errorf("timeout waiting to pack messages")
} }
expected := make(map[string]bool) expected := make(map[string]bool)
@ -307,79 +320,8 @@ func TestEthNewFilterCatchAll(t *testing.T) {
filterID, err := client.EthNewFilter(ctx, &ethtypes.EthFilterSpec{}) filterID, err := client.EthNewFilter(ctx, &ethtypes.EthFilterSpec{})
require.NoError(err) require.NoError(err)
const iterations = 10 const iterations = 3
ethContractAddr, received := invokeLogFourData(t, client, iterations)
type msgInTipset struct {
msg api.Message
ts *types.TipSet
}
msgChan := make(chan msgInTipset, iterations)
waitAllCh := make(chan struct{})
go func() {
headChangeCh, err := client.ChainNotify(ctx)
require.NoError(err)
<-headChangeCh // skip hccurrent
count := 0
for {
select {
case headChanges := <-headChangeCh:
for _, change := range headChanges {
if change.Type == store.HCApply || change.Type == store.HCRevert {
msgs, err := client.ChainGetMessagesInTipset(ctx, change.Val.Key())
require.NoError(err)
count += len(msgs)
for _, m := range msgs {
select {
case msgChan <- msgInTipset{msg: m, ts: change.Val}:
default:
}
}
if count == iterations {
close(msgChan)
close(waitAllCh)
return
}
}
}
}
}
}()
time.Sleep(blockTime * 6)
for i := 0; i < iterations; i++ {
// log a four topic event with data
ret := client.EVM().InvokeSolidity(ctx, fromAddr, idAddr, []byte{0x00, 0x00, 0x00, 0x02}, nil)
require.True(ret.Receipt.ExitCode.IsSuccess(), "contract execution failed")
}
select {
case <-waitAllCh:
case <-time.After(time.Minute):
t.Errorf("timeout to wait for pack messages")
}
received := make(map[ethtypes.EthHash]msgInTipset)
for m := range msgChan {
eh, err := ethtypes.EthHashFromCid(m.msg.Cid)
require.NoError(err)
received[eh] = m
}
require.Equal(iterations, len(received), "all messages on chain")
ts, err := client.ChainHead(ctx)
require.NoError(err)
actor, err := client.StateGetActor(ctx, idAddr, ts.Key())
require.NoError(err)
require.NotNil(actor.Address)
ethContractAddr, err := ethtypes.EthAddressFromFilecoinAddress(*actor.Address)
require.NoError(err)
// collect filter results // collect filter results
res, err := client.EthGetFilterChanges(ctx, filterID) res, err := client.EthGetFilterChanges(ctx, filterID)
@ -388,43 +330,42 @@ func TestEthNewFilterCatchAll(t *testing.T) {
// expect to have seen iteration number of events // expect to have seen iteration number of events
require.Equal(iterations, len(res.Results)) require.Equal(iterations, len(res.Results))
topic1 := paddedEthBytes([]byte{0x11, 0x11}) expected := []ExpectedEthLog{
topic2 := paddedEthBytes([]byte{0x22, 0x22}) {
topic3 := paddedEthBytes([]byte{0x33, 0x33}) Address: ethContractAddr,
topic4 := paddedEthBytes([]byte{0x44, 0x44}) Topics: []ethtypes.EthBytes{
data1 := paddedEthBytes([]byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}) paddedEthBytes([]byte{0x11, 0x11}),
paddedEthBytes([]byte{0x22, 0x22}),
for _, r := range res.Results { paddedEthBytes([]byte{0x33, 0x33}),
// since response is a union and Go doesn't support them well, go-jsonrpc won't give us typed results paddedEthBytes([]byte{0x44, 0x44}),
rc, ok := r.(map[string]interface{}) },
require.True(ok, "result type") Data: paddedEthBytes([]byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}),
},
elog, err := ParseEthLog(rc) {
require.NoError(err) Address: ethContractAddr,
Topics: []ethtypes.EthBytes{
require.Equal(ethContractAddr, elog.Address, "event address") paddedEthBytes([]byte{0x11, 0x11}),
require.Equal(ethtypes.EthUint64(0), elog.TransactionIndex, "transaction index") // only one message per tipset paddedEthBytes([]byte{0x22, 0x22}),
paddedEthBytes([]byte{0x33, 0x33}),
msg, exists := received[elog.TransactionHash] paddedEthBytes([]byte{0x44, 0x44}),
require.True(exists, "message seen on chain") },
Data: paddedEthBytes([]byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}),
tsCid, err := msg.ts.Key().Cid() },
require.NoError(err) {
Address: ethContractAddr,
tsCidHash, err := ethtypes.EthHashFromCid(tsCid) Topics: []ethtypes.EthBytes{
require.NoError(err) paddedEthBytes([]byte{0x11, 0x11}),
paddedEthBytes([]byte{0x22, 0x22}),
require.Equal(tsCidHash, elog.BlockHash, "block hash") paddedEthBytes([]byte{0x33, 0x33}),
paddedEthBytes([]byte{0x44, 0x44}),
require.Equal(4, len(elog.Topics), "number of topics") },
require.Equal(topic1, elog.Topics[0], "topic1") Data: paddedEthBytes([]byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}),
require.Equal(topic2, elog.Topics[1], "topic2") },
require.Equal(topic3, elog.Topics[2], "topic3")
require.Equal(topic4, elog.Topics[3], "topic4")
require.Equal(data1, elog.Data, "data1")
} }
elogs, err := parseEthLogsFromFilterResult(res)
require.NoError(err)
AssertEthLogs(t, elogs, expected, received)
} }
func TestEthGetLogsAll(t *testing.T) { func TestEthGetLogsAll(t *testing.T) {
@ -444,7 +385,7 @@ func TestEthGetLogsAll(t *testing.T) {
ethContractAddr, received := invokeLogFourData(t, client, invocations) ethContractAddr, received := invokeLogFourData(t, client, invocations)
// Build filter spec // Build filter spec
spec := EthFilterBuilder(). spec := newEthFilterBuilder().
FromBlockEpoch(0). FromBlockEpoch(0).
Topic1OneOf(paddedEthHash([]byte{0x11, 0x11})). Topic1OneOf(paddedEthHash([]byte{0x11, 0x11})).
Filter() Filter()
@ -594,7 +535,7 @@ func TestEthGetLogs(t *testing.T) {
}{ }{
{ {
name: "find all EventZeroData events", name: "find all EventZeroData events",
spec: EthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventZeroData"])).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventZeroData"])).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -615,7 +556,7 @@ func TestEthGetLogs(t *testing.T) {
}, },
{ {
name: "find all EventOneData events", name: "find all EventOneData events",
spec: EthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventOneData"])).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventOneData"])).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -636,7 +577,7 @@ func TestEthGetLogs(t *testing.T) {
}, },
{ {
name: "find all EventTwoData events", name: "find all EventTwoData events",
spec: EthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoData"])).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoData"])).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -650,7 +591,7 @@ func TestEthGetLogs(t *testing.T) {
}, },
{ {
name: "find all EventThreeData events", name: "find all EventThreeData events",
spec: EthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventThreeData"])).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventThreeData"])).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -664,7 +605,7 @@ func TestEthGetLogs(t *testing.T) {
}, },
{ {
name: "find all EventOneIndexed events", name: "find all EventOneIndexed events",
spec: EthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventOneIndexed"])).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventOneIndexed"])).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -679,7 +620,7 @@ func TestEthGetLogs(t *testing.T) {
}, },
{ {
name: "find all EventTwoIndexed events", name: "find all EventTwoIndexed events",
spec: EthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoIndexed"])).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoIndexed"])).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -704,7 +645,7 @@ func TestEthGetLogs(t *testing.T) {
}, },
{ {
name: "find all EventThreeIndexed events", name: "find all EventThreeIndexed events",
spec: EthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventThreeIndexed"])).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventThreeIndexed"])).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -721,7 +662,7 @@ func TestEthGetLogs(t *testing.T) {
}, },
{ {
name: "find all EventOneIndexedWithData events", name: "find all EventOneIndexedWithData events",
spec: EthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventOneIndexedWithData"])).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventOneIndexedWithData"])).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -752,7 +693,7 @@ func TestEthGetLogs(t *testing.T) {
}, },
{ {
name: "find all EventTwoIndexedWithData events", name: "find all EventTwoIndexedWithData events",
spec: EthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoIndexedWithData"])).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoIndexedWithData"])).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -786,7 +727,7 @@ func TestEthGetLogs(t *testing.T) {
}, },
{ {
name: "find all EventThreeIndexedWithData events", name: "find all EventThreeIndexedWithData events",
spec: EthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventThreeIndexedWithData"])).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventThreeIndexedWithData"])).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -804,7 +745,7 @@ func TestEthGetLogs(t *testing.T) {
{ {
name: "find all events from contract2", name: "find all events from contract2",
spec: EthFilterBuilder().FromBlockEpoch(0).AddressOneOf(contract2).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).AddressOneOf(contract2).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -846,7 +787,7 @@ func TestEthGetLogs(t *testing.T) {
{ {
name: "find all events with topic2 of 44", name: "find all events with topic2 of 44",
spec: EthFilterBuilder().FromBlockEpoch(0).Topic2OneOf(paddedEthHash(paddedUint64(44))).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).Topic2OneOf(paddedEthHash(paddedUint64(44))).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -908,7 +849,7 @@ func TestEthGetLogs(t *testing.T) {
{ {
name: "find all events with topic2 of 44 from contract2", name: "find all events with topic2 of 44 from contract2",
spec: EthFilterBuilder().FromBlockEpoch(0).AddressOneOf(contract2).Topic2OneOf(paddedEthHash(paddedUint64(44))).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).AddressOneOf(contract2).Topic2OneOf(paddedEthHash(paddedUint64(44))).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -935,7 +876,7 @@ func TestEthGetLogs(t *testing.T) {
{ {
name: "find all EventOneIndexedWithData events from contract1 or contract2", name: "find all EventOneIndexedWithData events from contract1 or contract2",
spec: EthFilterBuilder(). spec: newEthFilterBuilder().
FromBlockEpoch(0). FromBlockEpoch(0).
AddressOneOf(contract1, contract2). AddressOneOf(contract1, contract2).
Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventOneIndexedWithData"])). Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventOneIndexedWithData"])).
@ -971,7 +912,7 @@ func TestEthGetLogs(t *testing.T) {
{ {
name: "find all events with topic2 of 46", name: "find all events with topic2 of 46",
spec: EthFilterBuilder().FromBlockEpoch(0).Topic2OneOf(paddedEthHash(paddedUint64(46))).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).Topic2OneOf(paddedEthHash(paddedUint64(46))).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -1004,7 +945,7 @@ func TestEthGetLogs(t *testing.T) {
}, },
{ {
name: "find all events with topic2 of 50", name: "find all events with topic2 of 50",
spec: EthFilterBuilder().FromBlockEpoch(0).Topic2OneOf(paddedEthHash(paddedUint64(50))).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).Topic2OneOf(paddedEthHash(paddedUint64(50))).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -1019,7 +960,7 @@ func TestEthGetLogs(t *testing.T) {
}, },
{ {
name: "find all events with topic2 of 46 or 50", name: "find all events with topic2 of 46 or 50",
spec: EthFilterBuilder().FromBlockEpoch(0).Topic2OneOf(paddedEthHash(paddedUint64(46)), paddedEthHash(paddedUint64(50))).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).Topic2OneOf(paddedEthHash(paddedUint64(46)), paddedEthHash(paddedUint64(50))).Filter(),
expected: []ExpectedEthLog{ expected: []ExpectedEthLog{
{ {
@ -1061,7 +1002,7 @@ func TestEthGetLogs(t *testing.T) {
{ {
name: "find all events with topic1 of EventTwoIndexedWithData and topic3 of 27", name: "find all events with topic1 of EventTwoIndexedWithData and topic3 of 27",
spec: EthFilterBuilder(). spec: newEthFilterBuilder().
FromBlockEpoch(0). FromBlockEpoch(0).
Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoIndexedWithData"])). Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoIndexedWithData"])).
Topic3OneOf(paddedEthHash(paddedUint64(27))). Topic3OneOf(paddedEthHash(paddedUint64(27))).
@ -1091,7 +1032,7 @@ func TestEthGetLogs(t *testing.T) {
{ {
name: "find all events with topic1 of EventTwoIndexedWithData or EventOneIndexed and topic2 of 44", name: "find all events with topic1 of EventTwoIndexedWithData or EventOneIndexed and topic2 of 44",
spec: EthFilterBuilder(). spec: newEthFilterBuilder().
FromBlockEpoch(0). FromBlockEpoch(0).
Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoIndexedWithData"]), paddedEthHash(EventMatrixContract.Ev["EventOneIndexed"])). Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoIndexedWithData"]), paddedEthHash(EventMatrixContract.Ev["EventOneIndexed"])).
Topic2OneOf(paddedEthHash(paddedUint64(44))). Topic2OneOf(paddedEthHash(paddedUint64(44))).
@ -1245,91 +1186,91 @@ func TestEthGetLogsWithBlockRanges(t *testing.T) {
}{ }{
{ {
name: "find all events from genesis", name: "find all events from genesis",
spec: EthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(topics...).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(topics...).Filter(),
expected: union(partition1.expected, partition2.expected, partition3.expected), expected: union(partition1.expected, partition2.expected, partition3.expected),
}, },
{ {
name: "find all from start of partition1", name: "find all from start of partition1",
spec: EthFilterBuilder().FromBlockEpoch(partition1.start).Topic1OneOf(topics...).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(partition1.start).Topic1OneOf(topics...).Filter(),
expected: union(partition1.expected, partition2.expected, partition3.expected), expected: union(partition1.expected, partition2.expected, partition3.expected),
}, },
{ {
name: "find all from start of partition2", name: "find all from start of partition2",
spec: EthFilterBuilder().FromBlockEpoch(partition2.start).Topic1OneOf(topics...).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(partition2.start).Topic1OneOf(topics...).Filter(),
expected: union(partition2.expected, partition3.expected), expected: union(partition2.expected, partition3.expected),
}, },
{ {
name: "find all from start of partition3", name: "find all from start of partition3",
spec: EthFilterBuilder().FromBlockEpoch(partition3.start).Topic1OneOf(topics...).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(partition3.start).Topic1OneOf(topics...).Filter(),
expected: union(partition3.expected), expected: union(partition3.expected),
}, },
{ {
name: "find none after end of partition3", name: "find none after end of partition3",
spec: EthFilterBuilder().FromBlockEpoch(partition3.end + 1).Topic1OneOf(topics...).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(partition3.end + 1).Topic1OneOf(topics...).Filter(),
expected: nil, expected: nil,
}, },
{ {
name: "find all events from genesis to end of partition1", name: "find all events from genesis to end of partition1",
spec: EthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition1.end).Topic1OneOf(topics...).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition1.end).Topic1OneOf(topics...).Filter(),
expected: union(partition1.expected), expected: union(partition1.expected),
}, },
{ {
name: "find all events from genesis to end of partition2", name: "find all events from genesis to end of partition2",
spec: EthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition2.end).Topic1OneOf(topics...).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition2.end).Topic1OneOf(topics...).Filter(),
expected: union(partition1.expected, partition2.expected), expected: union(partition1.expected, partition2.expected),
}, },
{ {
name: "find all events from genesis to end of partition3", name: "find all events from genesis to end of partition3",
spec: EthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition3.end).Topic1OneOf(topics...).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition3.end).Topic1OneOf(topics...).Filter(),
expected: union(partition1.expected, partition2.expected, partition3.expected), expected: union(partition1.expected, partition2.expected, partition3.expected),
}, },
{ {
name: "find none from genesis to start of partition1", name: "find none from genesis to start of partition1",
spec: EthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition1.start - 1).Topic1OneOf(topics...).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition1.start - 1).Topic1OneOf(topics...).Filter(),
expected: nil, expected: nil,
}, },
{ {
name: "find all events in partition1", name: "find all events in partition1",
spec: EthFilterBuilder().FromBlockEpoch(partition1.start).ToBlockEpoch(partition1.end).Topic1OneOf(topics...).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(partition1.start).ToBlockEpoch(partition1.end).Topic1OneOf(topics...).Filter(),
expected: union(partition1.expected), expected: union(partition1.expected),
}, },
{ {
name: "find all events in partition2", name: "find all events in partition2",
spec: EthFilterBuilder().FromBlockEpoch(partition2.start).ToBlockEpoch(partition2.end).Topic1OneOf(topics...).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(partition2.start).ToBlockEpoch(partition2.end).Topic1OneOf(topics...).Filter(),
expected: union(partition2.expected), expected: union(partition2.expected),
}, },
{ {
name: "find all events in partition3", name: "find all events in partition3",
spec: EthFilterBuilder().FromBlockEpoch(partition3.start).ToBlockEpoch(partition3.end).Topic1OneOf(topics...).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(partition3.start).ToBlockEpoch(partition3.end).Topic1OneOf(topics...).Filter(),
expected: union(partition3.expected), expected: union(partition3.expected),
}, },
{ {
name: "find all events from earliest to end of partition1", name: "find all events from earliest to end of partition1",
spec: EthFilterBuilder().FromBlock("earliest").ToBlockEpoch(partition1.end).Topic1OneOf(topics...).Filter(), spec: newEthFilterBuilder().FromBlock("earliest").ToBlockEpoch(partition1.end).Topic1OneOf(topics...).Filter(),
expected: union(partition1.expected), expected: union(partition1.expected),
}, },
{ {
name: "find all events from start of partition3 to latest", name: "find all events from start of partition3 to latest",
spec: EthFilterBuilder().FromBlockEpoch(partition3.start).ToBlock("latest").Topic1OneOf(topics...).Filter(), spec: newEthFilterBuilder().FromBlockEpoch(partition3.start).ToBlock("latest").Topic1OneOf(topics...).Filter(),
expected: union(partition3.expected), expected: union(partition3.expected),
}, },
{ {
name: "find all events from earliest to latest", name: "find all events from earliest to latest",
spec: EthFilterBuilder().FromBlock("earliest").ToBlock("latest").Topic1OneOf(topics...).Filter(), spec: newEthFilterBuilder().FromBlock("earliest").ToBlock("latest").Topic1OneOf(topics...).Filter(),
expected: union(partition1.expected, partition2.expected, partition3.expected), expected: union(partition1.expected, partition2.expected, partition3.expected),
}, },
} }
@ -2050,7 +1991,7 @@ func unpackUint64Values(data []byte) []uint64 {
return vals return vals
} }
func EthFilterBuilder() *ethFilterBuilder { return &ethFilterBuilder{} } func newEthFilterBuilder() *ethFilterBuilder { return &ethFilterBuilder{} }
type ethFilterBuilder struct { type ethFilterBuilder struct {
filter ethtypes.EthFilterSpec filter ethtypes.EthFilterSpec

View File

@ -1673,7 +1673,7 @@ func newEthTxReceipt(ctx context.Context, tx ethtypes.EthTx, lookup *api.MsgLook
} }
for _, entry := range evt.Entries { for _, entry := range evt.Entries {
value := ethtypes.EthBytes(leftpad32(decodeLogBytes(entry.Value))) value := ethtypes.EthBytes(leftpad32(entry.Value)) // value has already been cbor-decoded but see https://github.com/filecoin-project/ref-fvm/issues/1345
if entry.Key == ethtypes.EthTopic1 || entry.Key == ethtypes.EthTopic2 || entry.Key == ethtypes.EthTopic3 || entry.Key == ethtypes.EthTopic4 { if entry.Key == ethtypes.EthTopic1 || entry.Key == ethtypes.EthTopic2 || entry.Key == ethtypes.EthTopic3 || entry.Key == ethtypes.EthTopic4 {
l.Topics = append(l.Topics, value) l.Topics = append(l.Topics, value)
} else { } else {