|
| 1 | +import asyncio |
1 | 2 | import json
|
2 | 3 | import math
|
3 | 4 | import pytest
|
@@ -992,9 +993,8 @@ async def test_eth_getBlockByNumber_not_found(
|
992 | 993 | async def test_eth_getBlockByNumber_pending(
|
993 | 994 | self, async_w3: "AsyncWeb3", async_empty_block: BlockData
|
994 | 995 | ) -> None:
|
995 |
| - current_block_number = await async_w3.eth.block_number |
996 | 996 | block = await async_w3.eth.get_block("pending")
|
997 |
| - assert block["number"] == current_block_number + 1 |
| 997 | + assert block["hash"] is None |
998 | 998 |
|
999 | 999 | @pytest.mark.asyncio
|
1000 | 1000 | async def test_eth_getBlockByNumber_earliest(
|
@@ -1086,16 +1086,23 @@ async def test_eth_get_raw_transaction_by_block(
|
1086 | 1086 | async_keyfile_account_address_dual_type: ChecksumAddress,
|
1087 | 1087 | ) -> None:
|
1088 | 1088 | # eth_getRawTransactionByBlockNumberAndIndex: block identifier
|
1089 |
| - # send a tx and wait until the latest block includes it |
1090 |
| - tx_hash = await async_w3.eth.send_transaction( |
| 1089 | + await async_w3.eth.send_transaction( |
1091 | 1090 | {
|
1092 | 1091 | "from": async_keyfile_account_address_dual_type,
|
1093 | 1092 | "to": async_keyfile_account_address_dual_type,
|
1094 | 1093 | "value": Wei(1),
|
1095 | 1094 | }
|
1096 | 1095 | )
|
1097 |
| - await async_w3.eth.wait_for_transaction_receipt(tx_hash) |
1098 |
| - raw_txn = await async_w3.eth.get_raw_transaction_by_block("latest", 0) |
| 1096 | + |
| 1097 | + async def wait_for_block_with_txn() -> HexBytes: |
| 1098 | + while True: |
| 1099 | + try: |
| 1100 | + return await async_w3.eth.get_raw_transaction_by_block("latest", 0) |
| 1101 | + except TransactionNotFound: |
| 1102 | + await asyncio.sleep(0.1) |
| 1103 | + continue |
| 1104 | + |
| 1105 | + raw_txn = await asyncio.wait_for(wait_for_block_with_txn(), timeout=5) |
1099 | 1106 | assert is_bytes(raw_txn)
|
1100 | 1107 |
|
1101 | 1108 | # eth_getRawTransactionByBlockNumberAndIndex: block number
|
@@ -4698,16 +4705,20 @@ def test_eth_get_raw_transaction_by_block(
|
4698 | 4705 | block_with_txn: BlockData,
|
4699 | 4706 | ) -> None:
|
4700 | 4707 | # eth_getRawTransactionByBlockNumberAndIndex: block identifier
|
4701 |
| - # send a tx and wait until the latest block includes it |
4702 |
| - tx_hash = w3.eth.send_transaction( |
| 4708 | + w3.eth.send_transaction( |
4703 | 4709 | {
|
4704 | 4710 | "from": keyfile_account_address_dual_type,
|
4705 | 4711 | "to": keyfile_account_address_dual_type,
|
4706 | 4712 | "value": Wei(1),
|
4707 | 4713 | }
|
4708 | 4714 | )
|
4709 |
| - w3.eth.wait_for_transaction_receipt(tx_hash) |
4710 |
| - raw_transaction = w3.eth.get_raw_transaction_by_block("latest", 0) |
| 4715 | + raw_transaction = None |
| 4716 | + while not raw_transaction: |
| 4717 | + try: |
| 4718 | + raw_transaction = w3.eth.get_raw_transaction_by_block("latest", 0) |
| 4719 | + except TransactionNotFound: |
| 4720 | + continue |
| 4721 | + |
4711 | 4722 | assert is_bytes(raw_transaction)
|
4712 | 4723 |
|
4713 | 4724 | # eth_getRawTransactionByBlockNumberAndIndex: block number
|
|
0 commit comments