Skip to content

Commit 0afb6bc

Browse files
committed
Tweak formatters comparison % match; add syncing tests
- Add tests for ``syncing`` eth_subscribe requests - Tweak formatters keyset match to 75% match. Across all eth_subscribe requests, the keys are not close to being similar so we can afford a more relaxed check here.
1 parent 525d91e commit 0afb6bc

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

web3/_utils/method_formatters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,13 +643,13 @@ def subscription_formatter(value: Any) -> Union[HexBytes, HexStr, Dict[str, Any]
643643
result_formatter = block_formatter
644644

645645
elif either_set_is_a_subset(
646-
result_key_set, set(LOG_ENTRY_FORMATTERS.keys()), percentage=90
646+
result_key_set, set(LOG_ENTRY_FORMATTERS.keys()), percentage=75
647647
):
648648
# logs
649649
result_formatter = log_entry_formatter
650650

651651
elif either_set_is_a_subset(
652-
result_key_set, set(TRANSACTION_RESULT_FORMATTERS.keys()), percentage=90
652+
result_key_set, set(TRANSACTION_RESULT_FORMATTERS.keys()), percentage=75
653653
):
654654
# newPendingTransactions, full transactions
655655
result_formatter = transaction_result_formatter
@@ -663,7 +663,7 @@ def subscription_formatter(value: Any) -> Union[HexBytes, HexStr, Dict[str, Any]
663663
elif either_set_is_a_subset(
664664
result_key_set,
665665
set(SYNCING_FORMATTERS.keys()),
666-
percentage=90,
666+
percentage=75,
667667
):
668668
# syncing response object
669669
result_formatter = syncing_formatter

web3/_utils/module_testing/persistent_connection_provider.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,50 @@ class PersistentConnectionProviderTest:
238238
}
239239
),
240240
),
241+
(
242+
("syncing",),
243+
{
244+
"jsonrpc": "2.0",
245+
"method": "eth_subscription",
246+
"params": {
247+
"subscription": "0x28d37f96bc784de4abf96ee4f8005a79",
248+
"result": False,
249+
},
250+
},
251+
False,
252+
),
253+
(
254+
("syncing",),
255+
{
256+
"jsonrpc": "2.0",
257+
"method": "eth_subscription",
258+
"params": {
259+
"subscription": "0x28d37f96bc784de4abf96ee4f8005a79",
260+
"result": {
261+
"isSyncing": True,
262+
"startingBlock": "0x0",
263+
"currentBlock": "0x4346fe",
264+
"highestBlock": "0x434806",
265+
},
266+
},
267+
},
268+
AttributeDict(
269+
{
270+
"isSyncing": True,
271+
"startingBlock": 0,
272+
"currentBlock": 4409086,
273+
"highestBlock": 4409350,
274+
}
275+
),
276+
),
241277
),
242278
ids=[
243279
"newHeads",
244280
"newPendingTransactions-FullTxs",
245281
"newPendingTransactions-TxHashes",
246282
"logs",
283+
"syncing-False",
284+
"syncing-True",
247285
],
248286
)
249287
async def test_async_eth_subscribe_mocked(

0 commit comments

Comments
 (0)