diff --git a/itests/eth_conformance_test.go b/itests/eth_conformance_test.go index 700427ce4..5d04b5948 100644 --- a/itests/eth_conformance_test.go +++ b/itests/eth_conformance_test.go @@ -3,6 +3,7 @@ package itests import ( "bytes" "context" + "encoding/binary" "encoding/hex" "encoding/json" "os" @@ -87,7 +88,7 @@ func TestEthOpenRPCConformance(t *testing.T) { client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC(), kit.WithEthRPC()) ens.InterconnectAll().BeginMining(10 * time.Millisecond) - contractHex, err := os.ReadFile(EventMatrixContract.Filename) + contractHex, err := os.ReadFile("contracts/EventMatrix.hex") require.NoError(t, err) // strip any trailing newlines from the file @@ -109,7 +110,7 @@ func TestEthOpenRPCConformance(t *testing.T) { blockFilterID, err := client.EthNewBlockFilter(ctx) require.NoError(t, err) - filterAllLogs := newEthFilterBuilder().FromBlockEpoch(0).Filter() + filterAllLogs := kit.NewEthFilterBuilder().FromBlockEpoch(0).Filter() logFilterID, err := client.EthNewFilter(ctx, filterAllLogs) require.NoError(t, err) @@ -488,31 +489,31 @@ func createRawSignedEthTx(ctx context.Context, t *testing.T, client *kit.TestFul } func waitForMessageWithEvents(ctx context.Context, t *testing.T, client *kit.TestFullNode, sender address.Address, target address.Address) (ethtypes.EthHash, ethtypes.EthHash, ethtypes.EthUint64) { - // send a message that exercises event logs - messages := invokeAndWaitUntilAllOnChain(t, client, []Invocation{ - { - Sender: sender, - Target: target, - Selector: EventMatrixContract.Fn["logEventThreeIndexedWithData"], - Data: packUint64Values(44, 27, 19, 12), - }, - }) - - require.NotEmpty(t, messages) - - for msgHash, mts := range messages { - ts := mts.ts - blockNumber := ethtypes.EthUint64(ts.Height()) - - tsCid, err := ts.Key().Cid() - require.NoError(t, err) - - blockHash, err := ethtypes.EthHashFromCid(tsCid) - require.NoError(t, err) - return msgHash, blockHash, blockNumber + vals := []uint64{44, 27, 19, 12} + inputData := []byte{} + for _, v := range vals { + buf := make([]byte, 32) + binary.BigEndian.PutUint64(buf[24:], v) + inputData = append(inputData, buf...) } - // should not get here - t.FailNow() - return ethtypes.EthHash{}, ethtypes.EthHash{}, 0 + // send a message that exercises event logs + ret := client.EVM().InvokeSolidity(ctx, sender, target, kit.EventMatrixContract.Fn["logEventThreeIndexedWithData"], inputData) + require.True(t, ret.Receipt.ExitCode.IsSuccess(), "contract execution failed") + + msgHash, err := client.EthGetTransactionHashByCid(ctx, ret.Message) + require.NoError(t, err) + require.NotNil(t, msgHash) + + ts, err := client.ChainGetTipSet(ctx, ret.TipSet) + require.NoError(t, err) + + blockNumber := ethtypes.EthUint64(ts.Height()) + + tsCid, err := ts.Key().Cid() + require.NoError(t, err) + + blockHash, err := ethtypes.EthHashFromCid(tsCid) + require.NoError(t, err) + return *msgHash, blockHash, blockNumber } diff --git a/itests/eth_filter_test.go b/itests/eth_filter_test.go index a15f6d09a..028126a78 100644 --- a/itests/eth_filter_test.go +++ b/itests/eth_filter_test.go @@ -16,7 +16,6 @@ import ( "github.com/ipfs/go-cid" "github.com/stretchr/testify/require" cbg "github.com/whyrusleeping/cbor-gen" - "golang.org/x/crypto/sha3" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" @@ -30,53 +29,6 @@ import ( "github.com/filecoin-project/lotus/itests/kit" ) -// SolidityContractDef holds information about one of the test contracts -type SolidityContractDef struct { - Filename string // filename of the hex of the contract, e.g. contracts/EventMatrix.hex - Fn map[string][]byte // mapping of function names to 32-bit selector - Ev map[string][]byte // mapping of event names to 256-bit signature hashes -} - -var EventMatrixContract = SolidityContractDef{ - Filename: "contracts/EventMatrix.hex", - Fn: map[string][]byte{ - "logEventZeroData": ethFunctionHash("logEventZeroData()"), - "logEventOneData": ethFunctionHash("logEventOneData(uint256)"), - "logEventTwoData": ethFunctionHash("logEventTwoData(uint256,uint256)"), - "logEventThreeData": ethFunctionHash("logEventThreeData(uint256,uint256,uint256)"), - "logEventFourData": ethFunctionHash("logEventFourData(uint256,uint256,uint256,uint256)"), - "logEventOneIndexed": ethFunctionHash("logEventOneIndexed(uint256)"), - "logEventTwoIndexed": ethFunctionHash("logEventTwoIndexed(uint256,uint256)"), - "logEventThreeIndexed": ethFunctionHash("logEventThreeIndexed(uint256,uint256,uint256)"), - "logEventOneIndexedWithData": ethFunctionHash("logEventOneIndexedWithData(uint256,uint256)"), - "logEventTwoIndexedWithData": ethFunctionHash("logEventTwoIndexedWithData(uint256,uint256,uint256)"), - "logEventThreeIndexedWithData": ethFunctionHash("logEventThreeIndexedWithData(uint256,uint256,uint256,uint256)"), - }, - Ev: map[string][]byte{ - "EventZeroData": ethTopicHash("EventZeroData()"), - "EventOneData": ethTopicHash("EventOneData(uint256)"), - "EventTwoData": ethTopicHash("EventTwoData(uint256,uint256)"), - "EventThreeData": ethTopicHash("EventThreeData(uint256,uint256,uint256)"), - "EventFourData": ethTopicHash("EventFourData(uint256,uint256,uint256,uint256)"), - "EventOneIndexed": ethTopicHash("EventOneIndexed(uint256)"), - "EventTwoIndexed": ethTopicHash("EventTwoIndexed(uint256,uint256)"), - "EventThreeIndexed": ethTopicHash("EventThreeIndexed(uint256,uint256,uint256)"), - "EventOneIndexedWithData": ethTopicHash("EventOneIndexedWithData(uint256,uint256)"), - "EventTwoIndexedWithData": ethTopicHash("EventTwoIndexedWithData(uint256,uint256,uint256)"), - "EventThreeIndexedWithData": ethTopicHash("EventThreeIndexedWithData(uint256,uint256,uint256,uint256)"), - }, -} - -var EventsContract = SolidityContractDef{ - Filename: "contracts/events.bin", - Fn: map[string][]byte{ - "log_zero_data": {0x00, 0x00, 0x00, 0x00}, - "log_zero_nodata": {0x00, 0x00, 0x00, 0x01}, - "log_four_data": {0x00, 0x00, 0x00, 0x02}, - }, - Ev: map[string][]byte{}, -} - func TestEthNewPendingTransactionFilter(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -381,7 +333,7 @@ func TestEthGetLogsBasic(t *testing.T) { ethContractAddr, received := invokeLogFourData(t, client, invocations) // Build filter spec - spec := newEthFilterBuilder(). + spec := kit.NewEthFilterBuilder(). FromBlockEpoch(0). Topic1OneOf(paddedEthHash([]byte{0x11, 0x11})). Filter() @@ -699,7 +651,7 @@ func TestEthGetLogsWithBlockRanges(t *testing.T) { // Select events for partitioning for _, m := range messages { - if bytes.Equal(m.invocation.Selector, EventMatrixContract.Fn["logEventTwoIndexedWithData"]) { + if bytes.Equal(m.invocation.Selector, kit.EventMatrixContract.Fn["logEventTwoIndexedWithData"]) { addr := getEthAddress(ctx, t, client, m.invocation.Target) args := unpackUint64Values(m.invocation.Data) require.Equal(3, len(args), "logEventTwoIndexedWithData should have 3 arguments") @@ -708,7 +660,7 @@ func TestEthGetLogsWithBlockRanges(t *testing.T) { expectedByHeight[m.ts.Height()] = append(expectedByHeight[m.ts.Height()], ExpectedEthLog{ Address: addr, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexedWithData"], + kit.EventMatrixContract.Ev["EventTwoIndexedWithData"], paddedUint64(args[0]), paddedUint64(args[1]), }, @@ -773,7 +725,7 @@ func TestEthGetLogsWithBlockRanges(t *testing.T) { require.True(len(partition3.expected) > 0, "partition should have events") // these are the topics we selected for partitioning earlier - topics := []ethtypes.EthHash{paddedEthHash(EventMatrixContract.Ev["EventTwoIndexedWithData"])} + topics := []ethtypes.EthHash{paddedEthHash(kit.EventMatrixContract.Ev["EventTwoIndexedWithData"])} union := func(lists ...[]ExpectedEthLog) []ExpectedEthLog { ret := []ExpectedEthLog{} @@ -790,91 +742,91 @@ func TestEthGetLogsWithBlockRanges(t *testing.T) { }{ { name: "find all events from genesis", - spec: newEthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(topics...).Filter(), + spec: kit.NewEthFilterBuilder().FromBlockEpoch(0).Topic1OneOf(topics...).Filter(), expected: union(partition1.expected, partition2.expected, partition3.expected), }, { name: "find all from start of partition1", - spec: newEthFilterBuilder().FromBlockEpoch(partition1.start).Topic1OneOf(topics...).Filter(), + spec: kit.NewEthFilterBuilder().FromBlockEpoch(partition1.start).Topic1OneOf(topics...).Filter(), expected: union(partition1.expected, partition2.expected, partition3.expected), }, { name: "find all from start of partition2", - spec: newEthFilterBuilder().FromBlockEpoch(partition2.start).Topic1OneOf(topics...).Filter(), + spec: kit.NewEthFilterBuilder().FromBlockEpoch(partition2.start).Topic1OneOf(topics...).Filter(), expected: union(partition2.expected, partition3.expected), }, { name: "find all from start of partition3", - spec: newEthFilterBuilder().FromBlockEpoch(partition3.start).Topic1OneOf(topics...).Filter(), + spec: kit.NewEthFilterBuilder().FromBlockEpoch(partition3.start).Topic1OneOf(topics...).Filter(), expected: union(partition3.expected), }, { name: "find none after end of partition3", - spec: newEthFilterBuilder().FromBlockEpoch(partition3.end + 1).Topic1OneOf(topics...).Filter(), + spec: kit.NewEthFilterBuilder().FromBlockEpoch(partition3.end + 1).Topic1OneOf(topics...).Filter(), expected: nil, }, { name: "find all events from genesis to end of partition1", - spec: newEthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition1.end).Topic1OneOf(topics...).Filter(), + spec: kit.NewEthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition1.end).Topic1OneOf(topics...).Filter(), expected: union(partition1.expected), }, { name: "find all events from genesis to end of partition2", - spec: newEthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition2.end).Topic1OneOf(topics...).Filter(), + spec: kit.NewEthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition2.end).Topic1OneOf(topics...).Filter(), expected: union(partition1.expected, partition2.expected), }, { name: "find all events from genesis to end of partition3", - spec: newEthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition3.end).Topic1OneOf(topics...).Filter(), + spec: kit.NewEthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition3.end).Topic1OneOf(topics...).Filter(), expected: union(partition1.expected, partition2.expected, partition3.expected), }, { name: "find none from genesis to start of partition1", - spec: newEthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition1.start - 1).Topic1OneOf(topics...).Filter(), + spec: kit.NewEthFilterBuilder().FromBlockEpoch(0).ToBlockEpoch(partition1.start - 1).Topic1OneOf(topics...).Filter(), expected: nil, }, { name: "find all events in partition1", - spec: newEthFilterBuilder().FromBlockEpoch(partition1.start).ToBlockEpoch(partition1.end).Topic1OneOf(topics...).Filter(), + spec: kit.NewEthFilterBuilder().FromBlockEpoch(partition1.start).ToBlockEpoch(partition1.end).Topic1OneOf(topics...).Filter(), expected: union(partition1.expected), }, { name: "find all events in partition2", - spec: newEthFilterBuilder().FromBlockEpoch(partition2.start).ToBlockEpoch(partition2.end).Topic1OneOf(topics...).Filter(), + spec: kit.NewEthFilterBuilder().FromBlockEpoch(partition2.start).ToBlockEpoch(partition2.end).Topic1OneOf(topics...).Filter(), expected: union(partition2.expected), }, { name: "find all events in partition3", - spec: newEthFilterBuilder().FromBlockEpoch(partition3.start).ToBlockEpoch(partition3.end).Topic1OneOf(topics...).Filter(), + spec: kit.NewEthFilterBuilder().FromBlockEpoch(partition3.start).ToBlockEpoch(partition3.end).Topic1OneOf(topics...).Filter(), expected: union(partition3.expected), }, { name: "find all events from earliest to end of partition1", - spec: newEthFilterBuilder().FromBlock("earliest").ToBlockEpoch(partition1.end).Topic1OneOf(topics...).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock("earliest").ToBlockEpoch(partition1.end).Topic1OneOf(topics...).Filter(), expected: union(partition1.expected), }, { name: "find all events from start of partition3 to latest", - spec: newEthFilterBuilder().FromBlockEpoch(partition3.start).ToBlock("latest").Topic1OneOf(topics...).Filter(), + spec: kit.NewEthFilterBuilder().FromBlockEpoch(partition3.start).ToBlock("latest").Topic1OneOf(topics...).Filter(), expected: union(partition3.expected), }, { name: "find all events from earliest to latest", - spec: newEthFilterBuilder().FromBlock("earliest").ToBlock("latest").Topic1OneOf(topics...).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock("earliest").ToBlock("latest").Topic1OneOf(topics...).Filter(), expected: union(partition1.expected, partition2.expected, partition3.expected), }, } @@ -904,20 +856,20 @@ func TestEthNewFilterMergesHistoricWithRealtime(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() - sender, contract := client.EVM().DeployContractFromFilename(ctx, EventMatrixContract.Filename) + sender, contract := client.EVM().DeployContractFromFilename(ctx, kit.EventMatrixContract.Filename) // generate some events before the creation of the filter preInvocations := []Invocation{ { Sender: sender, Target: contract, - Selector: EventMatrixContract.Fn["logEventOneData"], + Selector: kit.EventMatrixContract.Fn["logEventOneData"], Data: packUint64Values(1), }, { Sender: sender, Target: contract, - Selector: EventMatrixContract.Fn["logEventOneIndexed"], + Selector: kit.EventMatrixContract.Fn["logEventOneIndexed"], Data: packUint64Values(2), }, } @@ -925,7 +877,7 @@ func TestEthNewFilterMergesHistoricWithRealtime(t *testing.T) { messages := invokeAndWaitUntilAllOnChain(t, client, preInvocations) // now install filter - spec := newEthFilterBuilder().FromBlock("earliest").Filter() + spec := kit.NewEthFilterBuilder().FromBlock("earliest").Filter() filterID, err := client.EthNewFilter(ctx, spec) require.NoError(err) @@ -935,13 +887,13 @@ func TestEthNewFilterMergesHistoricWithRealtime(t *testing.T) { { Sender: sender, Target: contract, - Selector: EventMatrixContract.Fn["logEventOneData"], + Selector: kit.EventMatrixContract.Fn["logEventOneData"], Data: packUint64Values(3), }, { Sender: sender, Target: contract, - Selector: EventMatrixContract.Fn["logEventOneIndexed"], + Selector: kit.EventMatrixContract.Fn["logEventOneIndexed"], Data: packUint64Values(4), }, } @@ -962,28 +914,28 @@ func TestEthNewFilterMergesHistoricWithRealtime(t *testing.T) { { Address: ethContractAddr, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneData"], + kit.EventMatrixContract.Ev["EventOneData"], }, Data: paddedUint64(1), }, { Address: ethContractAddr, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexed"], + kit.EventMatrixContract.Ev["EventOneIndexed"], paddedUint64(2), }, }, { Address: ethContractAddr, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneData"], + kit.EventMatrixContract.Ev["EventOneData"], }, Data: paddedUint64(3), }, { Address: ethContractAddr, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexed"], + kit.EventMatrixContract.Ev["EventOneIndexed"], paddedUint64(4), }, }, @@ -1143,14 +1095,14 @@ func invokeLogFourData(t *testing.T, client *kit.TestFullNode, iterations int) ( ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() - fromAddr, idAddr := client.EVM().DeployContractFromFilename(ctx, EventsContract.Filename) + fromAddr, idAddr := client.EVM().DeployContractFromFilename(ctx, kit.EventsContract.Filename) invocations := make([]Invocation, iterations) for i := range invocations { invocations[i] = Invocation{ Sender: fromAddr, Target: idAddr, - Selector: EventsContract.Fn["log_four_data"], + Selector: kit.EventsContract.Fn["log_four_data"], Data: nil, } } @@ -1163,8 +1115,8 @@ func invokeLogFourData(t *testing.T, client *kit.TestFullNode, iterations int) ( } func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *kit.TestFullNode) (ethtypes.EthAddress, ethtypes.EthAddress, []Invocation) { - sender1, contract1 := client.EVM().DeployContractFromFilename(ctx, EventMatrixContract.Filename) - sender2, contract2 := client.EVM().DeployContractFromFilename(ctx, EventMatrixContract.Filename) + sender1, contract1 := client.EVM().DeployContractFromFilename(ctx, kit.EventMatrixContract.Filename) + sender2, contract2 := client.EVM().DeployContractFromFilename(ctx, kit.EventMatrixContract.Filename) invocations := []Invocation{ // log EventZeroData() @@ -1172,7 +1124,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender1, Target: contract1, - Selector: EventMatrixContract.Fn["logEventZeroData"], + Selector: kit.EventMatrixContract.Fn["logEventZeroData"], Data: nil, }, @@ -1182,7 +1134,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender1, Target: contract1, - Selector: EventMatrixContract.Fn["logEventOneData"], + Selector: kit.EventMatrixContract.Fn["logEventOneData"], Data: packUint64Values(23), }, @@ -1192,7 +1144,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender1, Target: contract1, - Selector: EventMatrixContract.Fn["logEventOneIndexed"], + Selector: kit.EventMatrixContract.Fn["logEventOneIndexed"], Data: packUint64Values(44), }, @@ -1203,7 +1155,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender2, Target: contract2, - Selector: EventMatrixContract.Fn["logEventTwoIndexed"], + Selector: kit.EventMatrixContract.Fn["logEventTwoIndexed"], Data: packUint64Values(44, 19), }, @@ -1213,7 +1165,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender1, Target: contract1, - Selector: EventMatrixContract.Fn["logEventOneData"], + Selector: kit.EventMatrixContract.Fn["logEventOneData"], Data: packUint64Values(44), }, @@ -1223,7 +1175,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender1, Target: contract1, - Selector: EventMatrixContract.Fn["logEventTwoData"], + Selector: kit.EventMatrixContract.Fn["logEventTwoData"], Data: packUint64Values(555, 666), }, @@ -1232,7 +1184,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender2, Target: contract2, - Selector: EventMatrixContract.Fn["logEventZeroData"], + Selector: kit.EventMatrixContract.Fn["logEventZeroData"], Data: nil, }, @@ -1242,7 +1194,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender1, Target: contract1, - Selector: EventMatrixContract.Fn["logEventThreeData"], + Selector: kit.EventMatrixContract.Fn["logEventThreeData"], Data: packUint64Values(1, 2, 3), }, @@ -1254,7 +1206,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender1, Target: contract2, - Selector: EventMatrixContract.Fn["logEventThreeIndexed"], + Selector: kit.EventMatrixContract.Fn["logEventThreeIndexed"], Data: packUint64Values(44, 27, 19), }, @@ -1265,7 +1217,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender1, Target: contract1, - Selector: EventMatrixContract.Fn["logEventOneIndexedWithData"], + Selector: kit.EventMatrixContract.Fn["logEventOneIndexedWithData"], Data: packUint64Values(44, 19), }, @@ -1276,7 +1228,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender1, Target: contract1, - Selector: EventMatrixContract.Fn["logEventOneIndexedWithData"], + Selector: kit.EventMatrixContract.Fn["logEventOneIndexedWithData"], Data: packUint64Values(46, 12), }, @@ -1288,7 +1240,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender1, Target: contract1, - Selector: EventMatrixContract.Fn["logEventTwoIndexedWithData"], + Selector: kit.EventMatrixContract.Fn["logEventTwoIndexedWithData"], Data: packUint64Values(44, 27, 19), }, @@ -1301,7 +1253,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender1, Target: contract1, - Selector: EventMatrixContract.Fn["logEventThreeIndexedWithData"], + Selector: kit.EventMatrixContract.Fn["logEventThreeIndexedWithData"], Data: packUint64Values(44, 27, 19, 12), }, @@ -1312,7 +1264,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender2, Target: contract2, - Selector: EventMatrixContract.Fn["logEventOneIndexedWithData"], + Selector: kit.EventMatrixContract.Fn["logEventOneIndexedWithData"], Data: packUint64Values(50, 9), }, @@ -1324,7 +1276,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender1, Target: contract1, - Selector: EventMatrixContract.Fn["logEventTwoIndexedWithData"], + Selector: kit.EventMatrixContract.Fn["logEventTwoIndexedWithData"], Data: packUint64Values(46, 27, 19), }, @@ -1336,7 +1288,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender1, Target: contract1, - Selector: EventMatrixContract.Fn["logEventTwoIndexedWithData"], + Selector: kit.EventMatrixContract.Fn["logEventTwoIndexedWithData"], Data: packUint64Values(46, 14, 19), }, // log EventTwoIndexed(44,19) from contract1 @@ -1346,7 +1298,7 @@ func prepareEventMatrixInvocations(ctx context.Context, t *testing.T, client *ki { Sender: sender1, Target: contract1, - Selector: EventMatrixContract.Fn["logEventTwoIndexed"], + Selector: kit.EventMatrixContract.Fn["logEventTwoIndexed"], Data: packUint64Values(40, 20), }, } @@ -1374,20 +1326,20 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock return []filterTestCase{ { name: "find all EventZeroData events", - spec: newEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventZeroData"])).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventZeroData"])).Filter(), expected: []ExpectedEthLog{ { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventZeroData"], + kit.EventMatrixContract.Ev["EventZeroData"], }, Data: nil, }, { Address: contract2, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventZeroData"], + kit.EventMatrixContract.Ev["EventZeroData"], }, Data: nil, }, @@ -1395,20 +1347,20 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock }, { name: "find all EventOneData events", - spec: newEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventOneData"])).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventOneData"])).Filter(), expected: []ExpectedEthLog{ { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneData"], + kit.EventMatrixContract.Ev["EventOneData"], }, Data: packUint64Values(23), }, { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneData"], + kit.EventMatrixContract.Ev["EventOneData"], }, Data: packUint64Values(44), }, @@ -1416,13 +1368,13 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock }, { name: "find all EventTwoData events", - spec: newEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoData"])).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventTwoData"])).Filter(), expected: []ExpectedEthLog{ { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoData"], + kit.EventMatrixContract.Ev["EventTwoData"], }, Data: packUint64Values(555, 666), }, @@ -1430,13 +1382,13 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock }, { name: "find all EventThreeData events", - spec: newEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventThreeData"])).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventThreeData"])).Filter(), expected: []ExpectedEthLog{ { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventThreeData"], + kit.EventMatrixContract.Ev["EventThreeData"], }, Data: packUint64Values(1, 2, 3), }, @@ -1444,13 +1396,13 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock }, { name: "find all EventOneIndexed events", - spec: newEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventOneIndexed"])).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventOneIndexed"])).Filter(), expected: []ExpectedEthLog{ { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexed"], + kit.EventMatrixContract.Ev["EventOneIndexed"], paddedUint64(44), }, Data: nil, @@ -1459,13 +1411,13 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock }, { name: "find all EventTwoIndexed events", - spec: newEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoIndexed"])).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventTwoIndexed"])).Filter(), expected: []ExpectedEthLog{ { Address: contract2, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexed"], + kit.EventMatrixContract.Ev["EventTwoIndexed"], paddedUint64(44), paddedUint64(19), }, @@ -1474,7 +1426,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexed"], + kit.EventMatrixContract.Ev["EventTwoIndexed"], paddedUint64(40), paddedUint64(20), }, @@ -1484,13 +1436,13 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock }, { name: "find all EventThreeIndexed events", - spec: newEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventThreeIndexed"])).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventThreeIndexed"])).Filter(), expected: []ExpectedEthLog{ { Address: contract2, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventThreeIndexed"], + kit.EventMatrixContract.Ev["EventThreeIndexed"], paddedUint64(44), paddedUint64(27), paddedUint64(19), @@ -1501,13 +1453,13 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock }, { name: "find all EventOneIndexedWithData events", - spec: newEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventOneIndexedWithData"])).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventOneIndexedWithData"])).Filter(), expected: []ExpectedEthLog{ { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexedWithData"], + kit.EventMatrixContract.Ev["EventOneIndexedWithData"], paddedUint64(44), }, Data: paddedUint64(19), @@ -1515,7 +1467,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexedWithData"], + kit.EventMatrixContract.Ev["EventOneIndexedWithData"], paddedUint64(46), }, Data: paddedUint64(12), @@ -1523,7 +1475,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract2, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexedWithData"], + kit.EventMatrixContract.Ev["EventOneIndexedWithData"], paddedUint64(50), }, Data: paddedUint64(9), @@ -1532,13 +1484,13 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock }, { name: "find all EventTwoIndexedWithData events", - spec: newEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoIndexedWithData"])).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventTwoIndexedWithData"])).Filter(), expected: []ExpectedEthLog{ { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexedWithData"], + kit.EventMatrixContract.Ev["EventTwoIndexedWithData"], paddedUint64(44), paddedUint64(27), }, @@ -1547,7 +1499,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexedWithData"], + kit.EventMatrixContract.Ev["EventTwoIndexedWithData"], paddedUint64(46), paddedUint64(27), }, @@ -1556,7 +1508,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexedWithData"], + kit.EventMatrixContract.Ev["EventTwoIndexedWithData"], paddedUint64(46), paddedUint64(14), }, @@ -1566,13 +1518,13 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock }, { name: "find all EventThreeIndexedWithData events", - spec: newEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventThreeIndexedWithData"])).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventThreeIndexedWithData"])).Filter(), expected: []ExpectedEthLog{ { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventThreeIndexedWithData"], + kit.EventMatrixContract.Ev["EventThreeIndexedWithData"], paddedUint64(44), paddedUint64(27), paddedUint64(19), @@ -1584,13 +1536,13 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { name: "find all events with topic2 of 44", - spec: newEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(paddedEthHash(paddedUint64(44))).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(paddedEthHash(paddedUint64(44))).Filter(), expected: []ExpectedEthLog{ { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexed"], + kit.EventMatrixContract.Ev["EventOneIndexed"], paddedUint64(44), }, Data: nil, @@ -1598,7 +1550,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract2, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexed"], + kit.EventMatrixContract.Ev["EventTwoIndexed"], paddedUint64(44), paddedUint64(19), }, @@ -1607,7 +1559,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract2, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventThreeIndexed"], + kit.EventMatrixContract.Ev["EventThreeIndexed"], paddedUint64(44), paddedUint64(27), paddedUint64(19), @@ -1617,7 +1569,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexedWithData"], + kit.EventMatrixContract.Ev["EventOneIndexedWithData"], paddedUint64(44), }, Data: paddedUint64(19), @@ -1625,7 +1577,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexedWithData"], + kit.EventMatrixContract.Ev["EventTwoIndexedWithData"], paddedUint64(44), paddedUint64(27), }, @@ -1634,7 +1586,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventThreeIndexedWithData"], + kit.EventMatrixContract.Ev["EventThreeIndexedWithData"], paddedUint64(44), paddedUint64(27), paddedUint64(19), @@ -1645,13 +1597,13 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock }, { name: "find all events with topic2 of 46", - spec: newEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(paddedEthHash(paddedUint64(46))).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(paddedEthHash(paddedUint64(46))).Filter(), expected: []ExpectedEthLog{ { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexedWithData"], + kit.EventMatrixContract.Ev["EventOneIndexedWithData"], paddedUint64(46), }, Data: paddedUint64(12), @@ -1659,7 +1611,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexedWithData"], + kit.EventMatrixContract.Ev["EventTwoIndexedWithData"], paddedUint64(46), paddedUint64(27), }, @@ -1668,7 +1620,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexedWithData"], + kit.EventMatrixContract.Ev["EventTwoIndexedWithData"], paddedUint64(46), paddedUint64(14), }, @@ -1678,13 +1630,13 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock }, { name: "find all events with topic2 of 50", - spec: newEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(paddedEthHash(paddedUint64(50))).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(paddedEthHash(paddedUint64(50))).Filter(), expected: []ExpectedEthLog{ { Address: contract2, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexedWithData"], + kit.EventMatrixContract.Ev["EventOneIndexedWithData"], paddedUint64(50), }, Data: paddedUint64(9), @@ -1693,13 +1645,13 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock }, { name: "find all events with topic2 of 46 or 50", - spec: newEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(paddedEthHash(paddedUint64(46)), paddedEthHash(paddedUint64(50))).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(paddedEthHash(paddedUint64(46)), paddedEthHash(paddedUint64(50))).Filter(), expected: []ExpectedEthLog{ { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexedWithData"], + kit.EventMatrixContract.Ev["EventOneIndexedWithData"], paddedUint64(46), }, Data: paddedUint64(12), @@ -1707,7 +1659,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexedWithData"], + kit.EventMatrixContract.Ev["EventTwoIndexedWithData"], paddedUint64(46), paddedUint64(27), }, @@ -1716,7 +1668,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexedWithData"], + kit.EventMatrixContract.Ev["EventTwoIndexedWithData"], paddedUint64(46), paddedUint64(14), }, @@ -1725,7 +1677,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract2, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexedWithData"], + kit.EventMatrixContract.Ev["EventOneIndexedWithData"], paddedUint64(50), }, Data: paddedUint64(9), @@ -1735,9 +1687,9 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { name: "find all events with topic1 of EventTwoIndexedWithData and topic3 of 27", - spec: newEthFilterBuilder(). + spec: kit.NewEthFilterBuilder(). FromBlockEpoch(0). - Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoIndexedWithData"])). + Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventTwoIndexedWithData"])). Topic3OneOf(paddedEthHash(paddedUint64(27))). Filter(), @@ -1745,7 +1697,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexedWithData"], + kit.EventMatrixContract.Ev["EventTwoIndexedWithData"], paddedUint64(44), paddedUint64(27), }, @@ -1754,7 +1706,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexedWithData"], + kit.EventMatrixContract.Ev["EventTwoIndexedWithData"], paddedUint64(46), paddedUint64(27), }, @@ -1765,9 +1717,9 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { name: "find all events with topic1 of EventTwoIndexedWithData or EventOneIndexed and topic2 of 44", - spec: newEthFilterBuilder(). + spec: kit.NewEthFilterBuilder(). FromBlockEpoch(0). - Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventTwoIndexedWithData"]), paddedEthHash(EventMatrixContract.Ev["EventOneIndexed"])). + Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventTwoIndexedWithData"]), paddedEthHash(kit.EventMatrixContract.Ev["EventOneIndexed"])). Topic2OneOf(paddedEthHash(paddedUint64(44))). Filter(), @@ -1775,7 +1727,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexedWithData"], + kit.EventMatrixContract.Ev["EventTwoIndexedWithData"], paddedUint64(44), paddedUint64(27), }, @@ -1784,7 +1736,7 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexed"], + kit.EventMatrixContract.Ev["EventOneIndexed"], paddedUint64(44), }, Data: nil, @@ -1799,20 +1751,20 @@ func getAddressFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlo return []filterTestCase{ { name: "find all events from contract2", - spec: newEthFilterBuilder().FromBlock(fromBlock).AddressOneOf(contract2).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).AddressOneOf(contract2).Filter(), expected: []ExpectedEthLog{ { Address: contract2, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventZeroData"], + kit.EventMatrixContract.Ev["EventZeroData"], }, Data: nil, }, { Address: contract2, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventThreeIndexed"], + kit.EventMatrixContract.Ev["EventThreeIndexed"], paddedUint64(44), paddedUint64(27), paddedUint64(19), @@ -1822,7 +1774,7 @@ func getAddressFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlo { Address: contract2, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexed"], + kit.EventMatrixContract.Ev["EventTwoIndexed"], paddedUint64(44), paddedUint64(19), }, @@ -1831,7 +1783,7 @@ func getAddressFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlo { Address: contract2, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexedWithData"], + kit.EventMatrixContract.Ev["EventOneIndexedWithData"], paddedUint64(50), }, Data: paddedUint64(9), @@ -1841,13 +1793,13 @@ func getAddressFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlo { name: "find all events with topic2 of 44 from contract2", - spec: newEthFilterBuilder().FromBlock(fromBlock).AddressOneOf(contract2).Topic2OneOf(paddedEthHash(paddedUint64(44))).Filter(), + spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).AddressOneOf(contract2).Topic2OneOf(paddedEthHash(paddedUint64(44))).Filter(), expected: []ExpectedEthLog{ { Address: contract2, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventThreeIndexed"], + kit.EventMatrixContract.Ev["EventThreeIndexed"], paddedUint64(44), paddedUint64(27), paddedUint64(19), @@ -1857,7 +1809,7 @@ func getAddressFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlo { Address: contract2, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventTwoIndexed"], + kit.EventMatrixContract.Ev["EventTwoIndexed"], paddedUint64(44), paddedUint64(19), }, @@ -1868,17 +1820,17 @@ func getAddressFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlo { name: "find all EventOneIndexedWithData events from contract1 or contract2", - spec: newEthFilterBuilder(). + spec: kit.NewEthFilterBuilder(). FromBlockEpoch(0). AddressOneOf(contract1, contract2). - Topic1OneOf(paddedEthHash(EventMatrixContract.Ev["EventOneIndexedWithData"])). + Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventOneIndexedWithData"])). Filter(), expected: []ExpectedEthLog{ { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexedWithData"], + kit.EventMatrixContract.Ev["EventOneIndexedWithData"], paddedUint64(44), }, Data: paddedUint64(19), @@ -1886,7 +1838,7 @@ func getAddressFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlo { Address: contract1, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexedWithData"], + kit.EventMatrixContract.Ev["EventOneIndexedWithData"], paddedUint64(46), }, Data: paddedUint64(12), @@ -1894,7 +1846,7 @@ func getAddressFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlo { Address: contract2, Topics: []ethtypes.EthBytes{ - EventMatrixContract.Ev["EventOneIndexedWithData"], + kit.EventMatrixContract.Ev["EventOneIndexedWithData"], paddedUint64(50), }, Data: paddedUint64(9), @@ -2195,18 +2147,6 @@ func paddedEthHash(orig []byte) ethtypes.EthHash { return ret } -func ethTopicHash(sig string) []byte { - hasher := sha3.NewLegacyKeccak256() - hasher.Write([]byte(sig)) - return hasher.Sum(nil) -} - -func ethFunctionHash(sig string) []byte { - hasher := sha3.NewLegacyKeccak256() - hasher.Write([]byte(sig)) - return hasher.Sum(nil)[:4] -} - func packUint64Values(vals ...uint64) []byte { ret := []byte{} for _, v := range vals { @@ -2229,78 +2169,6 @@ func unpackUint64Values(data []byte) []uint64 { return vals } -func newEthFilterBuilder() *ethFilterBuilder { return ðFilterBuilder{} } - -type ethFilterBuilder struct { - filter ethtypes.EthFilterSpec -} - -func (e *ethFilterBuilder) Filter() *ethtypes.EthFilterSpec { return &e.filter } - -func (e *ethFilterBuilder) FromBlock(v string) *ethFilterBuilder { - e.filter.FromBlock = &v - return e -} - -func (e *ethFilterBuilder) FromBlockEpoch(v abi.ChainEpoch) *ethFilterBuilder { - s := ethtypes.EthUint64(v).Hex() - e.filter.FromBlock = &s - return e -} - -func (e *ethFilterBuilder) ToBlock(v string) *ethFilterBuilder { - e.filter.ToBlock = &v - return e -} - -func (e *ethFilterBuilder) ToBlockEpoch(v abi.ChainEpoch) *ethFilterBuilder { - s := ethtypes.EthUint64(v).Hex() - e.filter.ToBlock = &s - return e -} - -func (e *ethFilterBuilder) BlockHash(h ethtypes.EthHash) *ethFilterBuilder { - e.filter.BlockHash = &h - return e -} - -func (e *ethFilterBuilder) AddressOneOf(as ...ethtypes.EthAddress) *ethFilterBuilder { - e.filter.Address = as - return e -} - -func (e *ethFilterBuilder) Topic1OneOf(hs ...ethtypes.EthHash) *ethFilterBuilder { - if len(e.filter.Topics) == 0 { - e.filter.Topics = make(ethtypes.EthTopicSpec, 1) - } - e.filter.Topics[0] = hs - return e -} - -func (e *ethFilterBuilder) Topic2OneOf(hs ...ethtypes.EthHash) *ethFilterBuilder { - for len(e.filter.Topics) < 2 { - e.filter.Topics = append(e.filter.Topics, nil) - } - e.filter.Topics[1] = hs - return e -} - -func (e *ethFilterBuilder) Topic3OneOf(hs ...ethtypes.EthHash) *ethFilterBuilder { - for len(e.filter.Topics) < 3 { - e.filter.Topics = append(e.filter.Topics, nil) - } - e.filter.Topics[2] = hs - return e -} - -func (e *ethFilterBuilder) Topic4OneOf(hs ...ethtypes.EthHash) *ethFilterBuilder { - for len(e.filter.Topics) < 4 { - e.filter.Topics = append(e.filter.Topics, nil) - } - e.filter.Topics[3] = hs - return e -} - func decodeLogBytes(orig []byte) []byte { if len(orig) == 0 { return orig diff --git a/itests/kit/evm.go b/itests/kit/evm.go index b3693ea45..71f8583aa 100644 --- a/itests/kit/evm.go +++ b/itests/kit/evm.go @@ -252,6 +252,7 @@ func (e *EVM) InvokeContractByFuncNameExpectExit(ctx context.Context, fromAddr a require.Equal(e.t, exit, wait.Receipt.ExitCode) } + // function signatures are the first 4 bytes of the hash of the function name and types func CalcFuncSignature(funcName string) []byte { hasher := sha3.NewLegacyKeccak256() @@ -310,3 +311,77 @@ func removeLeadingZeros(data []byte) []byte { } return data[firstNonZeroIndex:] } + +func NewEthFilterBuilder() *EthFilterBuilder { + return &EthFilterBuilder{} +} + +type EthFilterBuilder struct { + filter ethtypes.EthFilterSpec +} + +func (e *EthFilterBuilder) Filter() *ethtypes.EthFilterSpec { return &e.filter } + +func (e *EthFilterBuilder) FromBlock(v string) *EthFilterBuilder { + e.filter.FromBlock = &v + return e +} + +func (e *EthFilterBuilder) FromBlockEpoch(v abi.ChainEpoch) *EthFilterBuilder { + s := ethtypes.EthUint64(v).Hex() + e.filter.FromBlock = &s + return e +} + +func (e *EthFilterBuilder) ToBlock(v string) *EthFilterBuilder { + e.filter.ToBlock = &v + return e +} + +func (e *EthFilterBuilder) ToBlockEpoch(v abi.ChainEpoch) *EthFilterBuilder { + s := ethtypes.EthUint64(v).Hex() + e.filter.ToBlock = &s + return e +} + +func (e *EthFilterBuilder) BlockHash(h ethtypes.EthHash) *EthFilterBuilder { + e.filter.BlockHash = &h + return e +} + +func (e *EthFilterBuilder) AddressOneOf(as ...ethtypes.EthAddress) *EthFilterBuilder { + e.filter.Address = as + return e +} + +func (e *EthFilterBuilder) Topic1OneOf(hs ...ethtypes.EthHash) *EthFilterBuilder { + if len(e.filter.Topics) == 0 { + e.filter.Topics = make(ethtypes.EthTopicSpec, 1) + } + e.filter.Topics[0] = hs + return e +} + +func (e *EthFilterBuilder) Topic2OneOf(hs ...ethtypes.EthHash) *EthFilterBuilder { + for len(e.filter.Topics) < 2 { + e.filter.Topics = append(e.filter.Topics, nil) + } + e.filter.Topics[1] = hs + return e +} + +func (e *EthFilterBuilder) Topic3OneOf(hs ...ethtypes.EthHash) *EthFilterBuilder { + for len(e.filter.Topics) < 3 { + e.filter.Topics = append(e.filter.Topics, nil) + } + e.filter.Topics[2] = hs + return e +} + +func (e *EthFilterBuilder) Topic4OneOf(hs ...ethtypes.EthHash) *EthFilterBuilder { + for len(e.filter.Topics) < 4 { + e.filter.Topics = append(e.filter.Topics, nil) + } + e.filter.Topics[3] = hs + return e +} diff --git a/itests/kit/solidity.go b/itests/kit/solidity.go new file mode 100644 index 000000000..ea9d452f4 --- /dev/null +++ b/itests/kit/solidity.go @@ -0,0 +1,64 @@ +package kit + +import ( + "golang.org/x/crypto/sha3" +) + +func EthTopicHash(sig string) []byte { + hasher := sha3.NewLegacyKeccak256() + hasher.Write([]byte(sig)) + return hasher.Sum(nil) +} + +func EthFunctionHash(sig string) []byte { + hasher := sha3.NewLegacyKeccak256() + hasher.Write([]byte(sig)) + return hasher.Sum(nil)[:4] +} + +// SolidityContractDef holds information about one of the test contracts +type SolidityContractDef struct { + Filename string // filename of the hex of the contract, e.g. contracts/EventMatrix.hex + Fn map[string][]byte // mapping of function names to 32-bit selector + Ev map[string][]byte // mapping of event names to 256-bit signature hashes +} + +var EventMatrixContract = SolidityContractDef{ + Filename: "contracts/EventMatrix.hex", + Fn: map[string][]byte{ + "logEventZeroData": EthFunctionHash("logEventZeroData()"), + "logEventOneData": EthFunctionHash("logEventOneData(uint256)"), + "logEventTwoData": EthFunctionHash("logEventTwoData(uint256,uint256)"), + "logEventThreeData": EthFunctionHash("logEventThreeData(uint256,uint256,uint256)"), + "logEventFourData": EthFunctionHash("logEventFourData(uint256,uint256,uint256,uint256)"), + "logEventOneIndexed": EthFunctionHash("logEventOneIndexed(uint256)"), + "logEventTwoIndexed": EthFunctionHash("logEventTwoIndexed(uint256,uint256)"), + "logEventThreeIndexed": EthFunctionHash("logEventThreeIndexed(uint256,uint256,uint256)"), + "logEventOneIndexedWithData": EthFunctionHash("logEventOneIndexedWithData(uint256,uint256)"), + "logEventTwoIndexedWithData": EthFunctionHash("logEventTwoIndexedWithData(uint256,uint256,uint256)"), + "logEventThreeIndexedWithData": EthFunctionHash("logEventThreeIndexedWithData(uint256,uint256,uint256,uint256)"), + }, + Ev: map[string][]byte{ + "EventZeroData": EthTopicHash("EventZeroData()"), + "EventOneData": EthTopicHash("EventOneData(uint256)"), + "EventTwoData": EthTopicHash("EventTwoData(uint256,uint256)"), + "EventThreeData": EthTopicHash("EventThreeData(uint256,uint256,uint256)"), + "EventFourData": EthTopicHash("EventFourData(uint256,uint256,uint256,uint256)"), + "EventOneIndexed": EthTopicHash("EventOneIndexed(uint256)"), + "EventTwoIndexed": EthTopicHash("EventTwoIndexed(uint256,uint256)"), + "EventThreeIndexed": EthTopicHash("EventThreeIndexed(uint256,uint256,uint256)"), + "EventOneIndexedWithData": EthTopicHash("EventOneIndexedWithData(uint256,uint256)"), + "EventTwoIndexedWithData": EthTopicHash("EventTwoIndexedWithData(uint256,uint256,uint256)"), + "EventThreeIndexedWithData": EthTopicHash("EventThreeIndexedWithData(uint256,uint256,uint256,uint256)"), + }, +} + +var EventsContract = SolidityContractDef{ + Filename: "contracts/events.bin", + Fn: map[string][]byte{ + "log_zero_data": {0x00, 0x00, 0x00, 0x00}, + "log_zero_nodata": {0x00, 0x00, 0x00, 0x01}, + "log_four_data": {0x00, 0x00, 0x00, 0x02}, + }, + Ev: map[string][]byte{}, +}