diff --git a/src/schemas/filter.yaml b/src/schemas/filter.yaml index 5da814a7a..cd19dba08 100644 --- a/src/schemas/filter.yaml +++ b/src/schemas/filter.yaml @@ -71,6 +71,8 @@ FilterTopics: FilterTopic: title: Filter Topic List Entry oneOf: + - title: Any Topic Match + type: 'null' - title: Single Topic Match $ref: '#/components/schemas/bytes32' - title: Multiple Topic Match diff --git a/tests/eth_getLogs/topic-null-wildcard.io b/tests/eth_getLogs/topic-null-wildcard.io new file mode 100644 index 000000000..5d1df4024 --- /dev/null +++ b/tests/eth_getLogs/topic-null-wildcard.io @@ -0,0 +1,3 @@ +// queries for logs with a null topic in position zero, acting as a wildcard for that position +>> {"jsonrpc":"2.0","id":1,"method":"eth_getLogs","params":[{"fromBlock":"0x3","toBlock":"0x6","topics":[null,["0x4238ace0bf7e66fd40fea01bdf43f4f30423f48432efd0da3af5fcb17a977fd4"]]}]} +<< {"jsonrpc":"2.0","id":1,"result":[{"address":"0x7dcd17433742f4c0ca53122ab541d0ba67fc27df","topics":["0x00000000000000000000000000000000000000000000000000000000656d6974","0x4238ace0bf7e66fd40fea01bdf43f4f30423f48432efd0da3af5fcb17a977fd4"],"data":"0x0000000000000000000000000000000000000000000000000000000000000001","blockNumber":"0x4","transactionHash":"0xf047c5133c96c405a79d01038b4ccf8208c03e296dd9f6bea083727c9513f805","transactionIndex":"0x0","blockHash":"0x29cc6f97784c864cbe29b3502934ad874f48ddc89580018f5a32e01652c88f0a","blockTimestamp":"0x28","logIndex":"0x0","removed":false}]} diff --git a/tools/testgen/generators.go b/tools/testgen/generators.go index 71007a764..c26f07d8c 100644 --- a/tools/testgen/generators.go +++ b/tools/testgen/generators.go @@ -2168,6 +2168,34 @@ var EthGetLogs = MethodTests{ return nil }, }, + { + Name: "topic-null-wildcard", + About: "queries for logs with a null topic in position zero, acting as a wildcard for that position", + Run: func(ctx context.Context, t *T) error { + // Find a topic. + i := slices.IndexFunc(t.chain.txinfo.LegacyEmit, func(tx TxInfo) bool { + return tx.Block > 2 + }) + if i == -1 { + return fmt.Errorf("no suitable tx found") + } + info := t.chain.txinfo.LegacyEmit[i] + startBlock := uint64(info.Block - 1) + endBlock := uint64(info.Block + 2) + result, err := t.eth.FilterLogs(ctx, ethereum.FilterQuery{ + FromBlock: new(big.Int).SetUint64(startBlock), + ToBlock: new(big.Int).SetUint64(endBlock), + Topics: [][]common.Hash{nil, {*info.LogTopic1}}, + }) + if err != nil { + return err + } + if len(result) != 1 { + return fmt.Errorf("result contains %d logs, want 1", len(result)) + } + return nil + }, + }, { Name: "filter-with-blockHash", About: "queries for all logs of a block, identified by blockHash",