Skip to content

Commit fc32e8f

Browse files
committed
fix
1 parent 68800d7 commit fc32e8f

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

benchmarks/web3/_utils/params.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Shared parameterizations and real-world data for microbenchmarks
22
# All data below is based on real mainnet-style values or representative realistic examples.
33

4+
# Shared 32-byte hash
5+
HASH32 = "0x5e1d3a76fbf824220e1c5e0c2e5e7e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e"
6+
47
# Transaction dict (mainnet-style)
58
TX_DICT = {
69
"from": "0xFEB4acf3df3cDEA7399794D0869ef76A6EfAff52",
@@ -22,14 +25,14 @@
2225
],
2326
"data": "0x00000000000000000000000000000000000000000000000000000000000003e8",
2427
"blockNumber": 12345678,
25-
"transactionHash": "0x5e1d3a76fbf824220e1c5e0c2e5e7e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1",
28+
"transactionHash": HASH32,
2629
"logIndex": 0,
2730
}
2831

2932
# Block dict (mainnet-style, minimal for formatter)
3033
BLOCK_DICT = {
3134
"number": 12345678,
32-
"hash": "0x5e1d3a76fbf824220e1c5e0c2e5e7e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1",
35+
"hash": HASH32,
3336
"transactions": [TX_DICT, TX_DICT],
3437
"logs": [LOG_ENTRY, LOG_ENTRY],
3538
"miner": "0x829BD824B016326A401d083B33D092293333A830",
@@ -42,7 +45,7 @@
4245
"blockHash": BLOCK_DICT["hash"],
4346
"blockNumber": BLOCK_DICT["number"],
4447
"transactionIndex": 0,
45-
"transactionHash": TX_DICT["from"],
48+
"transactionHash": HASH32,
4649
"cumulativeGasUsed": 21000,
4750
"status": 1,
4851
"gasUsed": 21000,

benchmarks/web3/_utils/test_method_formatters_benchmarks.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,16 @@
99
from faster_web3.types import RPCEndpoint
1010
from pytest_codspeed import BenchmarkFixture
1111

12-
from benchmarks.web3._utils.params import BLOCK_DICT, FEE_HISTORY_DICT, LOG_ENTRY, RECEIPT_DICT, TX_DICT
13-
12+
from benchmarks.web3._utils.params import BLOCK_DICT, FEE_HISTORY_DICT, HASH32, LOG_ENTRY, RECEIPT_DICT, TX_DICT
1413

1514
def run_1000(fn, *args):
1615
for _ in range(1000):
1716
fn(*args)
1817

19-
2018
# --- SYSTEMATIC BENCHMARKS FOR PYTHONIC_RESULT_FORMATTERS ---
2119

2220
# NOTE: These are explicit, non-parameterized, one-per-key test stubs for both web3 and faster_web3.
2321

24-
2522
# PYTHONIC_REQUEST_FORMATTERS
2623

2724
REQUEST_DATA = {
@@ -33,8 +30,8 @@ def run_1000(fn, *args):
3330
"eth_getTransactionByBlockNumberAndIndex": ("latest", "0x0"),
3431
"eth_getRawTransactionByBlockNumberAndIndex": ("latest", "0x0"),
3532
"eth_getUncleByBlockNumberAndIndex": ("latest", "0x0"),
36-
"eth_getRawTransactionByBlockHashAndIndex": ("0xabc", "0x0"),
37-
"eth_getUncleByBlockHashAndIndex": ("0xabc", "0x0"),
33+
"eth_getRawTransactionByBlockHashAndIndex": (HASH32, "0x0"),
34+
"eth_getUncleByBlockHashAndIndex": (HASH32, "0x0"),
3835
"eth_getBlockByNumber": ("latest", True),
3936
"eth_getCode": ("0x742d35Cc6634C0532925a3b844Bc454e4438f44e", "latest"),
4037
"eth_getTransactionCount": ("0x742d35Cc6634C0532925a3b844Bc454e4438f44e", "latest"),
@@ -43,23 +40,20 @@ def run_1000(fn, *args):
4340
"eth_newFilter": ({"address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"},),
4441
}
4542

46-
4743
@pytest.mark.parametrize("endpoint", list(REQUEST_DATA))
4844
def test_PYTHONIC_REQUEST_FORMATTERS(
4945
benchmark: BenchmarkFixture, endpoint: RPCEndpoint
5046
) -> None:
5147
f = web3._utils.method_formatters.PYTHONIC_REQUEST_FORMATTERS[endpoint]
5248
benchmark(run_1000, f, REQUEST_DATA[endpoint])
5349

54-
5550
@pytest.mark.parametrize("endpoint", list(REQUEST_DATA))
5651
def test_faster_PYTHONIC_REQUEST_FORMATTERS(
5752
benchmark: BenchmarkFixture, endpoint: RPCEndpoint
5853
) -> None:
5954
f = faster_web3._utils.method_formatters.PYTHONIC_REQUEST_FORMATTERS[endpoint]
6055
benchmark(run_1000, f, REQUEST_DATA[endpoint])
6156

62-
6357
# Realistic RLP-encoded proof nodes (hex, plausible structure)
6458
PROOF_NODE_1 = (
6559
"0xf90211a0b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2"
@@ -111,7 +105,7 @@ def test_faster_PYTHONIC_REQUEST_FORMATTERS(
111105
"eth_sign": "0x2c6401ff0c2b6a1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1",
112106
"eth_sendTransaction": "0xfeedbabe1234567890cafebabe1234567890feedbabe1234567890cafebabe12",
113107
"eth_signTypedData": "0x1c6401ff0c2b6a1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1",
114-
"eth_getRawTransactionByHash": "0x5e1d3a76fbf824220e3d1e4b8b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1",
108+
"eth_getRawTransactionByHash": HASH32,
115109
"eth_getTransactionByHash": TX_DICT,
116110
"eth_getUncleCountByBlockHash": "0x2",
117111
"eth_getUncleCountByBlockNumber": "0x2",
@@ -129,7 +123,7 @@ def test_faster_PYTHONIC_REQUEST_FORMATTERS(
129123
"eth_getTransactionByBlockHashAndIndex": TX_DICT,
130124
"eth_getTransactionByBlockNumberAndIndex": TX_DICT,
131125
"eth_subscribe": {
132-
"result": "0x5e1d3a76fbf824220e3d1e4b8b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1"
126+
"result": HASH32
133127
},
134128
"eth_simulateV1": [
135129
{
@@ -176,24 +170,22 @@ def test_faster_PYTHONIC_REQUEST_FORMATTERS(
176170
"eth_getLogs": [LOG_ENTRY],
177171
"eth_getTransactionReceipt": RECEIPT_DICT,
178172
"eth_signTransaction": TX_DICT,
179-
"trace_block": [{"action": {}, "result": {}, "blockHash": "0xabc", "blockNumber": 1, "transactionHash": "0xdef"}],
180-
"trace_transaction": [{"action": {}, "result": {}, "blockHash": "0xabc", "blockNumber": 1, "transactionHash": "0xdef"}],
181-
"trace_filter": [{"action": {}, "result": {}, "blockHash": "0xabc", "blockNumber": 1, "transactionHash": "0xdef"}],
182-
"trace_rawTransaction": {"trace": [], "output": "0x", "transactionHash": "0xabc"},
183-
"trace_replayTransaction": {"trace": [], "output": "0x", "transactionHash": "0xabc"},
184-
"trace_replayBlockTransactions": {"trace": [], "output": "0x", "transactionHash": "0xabc"},
173+
"trace_block": [{"action": {}, "result": {}, "blockHash": HASH32, "blockNumber": 1, "transactionHash": HASH32}],
174+
"trace_transaction": [{"action": {}, "result": {}, "blockHash": HASH32, "blockNumber": 1, "transactionHash": HASH32}],
175+
"trace_filter": [{"action": {}, "result": {}, "blockHash": HASH32, "blockNumber": 1, "transactionHash": HASH32}],
176+
"trace_rawTransaction": {"trace": [], "output": "0x", "transactionHash": HASH32},
177+
"trace_replayTransaction": {"trace": [], "output": "0x", "transactionHash": HASH32},
178+
"trace_replayBlockTransactions": {"trace": [], "output": "0x", "transactionHash": HASH32},
185179
"trace_call": {"from": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"},
186180
}
187181

188-
189182
@pytest.mark.parametrize("endpoint", list(RESULT_DATA))
190183
def test_PYTHONIC_RESULT_FORMATTERS(
191184
benchmark: BenchmarkFixture, endpoint: RPCEndpoint
192185
) -> None:
193186
f = web3._utils.method_formatters.PYTHONIC_RESULT_FORMATTERS[endpoint]
194187
benchmark(run_1000, f, RESULT_DATA[endpoint])
195188

196-
197189
@pytest.mark.parametrize("endpoint", list(RESULT_DATA))
198190
def test_faster_PYTHONIC_RESULT_FORMATTERS(
199191
benchmark: BenchmarkFixture, endpoint: RPCEndpoint

0 commit comments

Comments
 (0)