99from faster_web3 .types import RPCEndpoint
1010from 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
1514def 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
2724REQUEST_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 ))
4844def 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 ))
5651def 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)
6458PROOF_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 ))
190183def 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 ))
198190def test_faster_PYTHONIC_RESULT_FORMATTERS (
199191 benchmark : BenchmarkFixture , endpoint : RPCEndpoint
0 commit comments