Skip to content

Commit 3fb3a3e

Browse files
committed
Add test for async eth.send_raw_transaction and cleanup
1 parent f61ad0d commit 3fb3a3e

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

newsfragments/2135.doc.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
- Add async ``eth.send_raw_transaction`` methods.
2-
- Update AsyncHTTPProvider doc Supported Methods to include ``web3.eth.send_raw_transaction()``.
1+
Update AsyncHTTPProvider doc Supported Methods to include ``web3.eth.send_raw_transaction()``.

newsfragments/2135.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add async ``eth.send_raw_transaction`` method

web3/_utils/module_testing/eth_module.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
TYPE_CHECKING,
99
Callable,
1010
Sequence,
11-
Union,
1211
cast,
1312
)
1413

@@ -262,6 +261,18 @@ async def test_eth_send_transaction_max_fee_less_than_tip(
262261
):
263262
await async_w3.eth.send_transaction(txn_params) # type: ignore
264263

264+
@pytest.mark.asyncio
265+
async def test_eth_send_raw_transaction(self, async_w3: "Web3") -> None:
266+
# private key 0x3c2ab4e8f17a7dea191b8c991522660126d681039509dc3bb31af7c9bdb63518
267+
# This is an unfunded account, but the transaction has a 0 gas price, so is valid.
268+
# It never needs to be mined, we just want the transaction hash back to confirm.
269+
# tx = {'to': '0x0000000000000000000000000000000000000000', 'value': 0, 'nonce': 1, 'gas': 21000, 'gasPrice': 0, 'chainId': 131277322940537} # noqa: E501
270+
# NOTE: nonce=1 to make txn unique from the non-async version of this test
271+
raw_txn = HexBytes('0xf8650180825208940000000000000000000000000000000000000000808086eecac466e115a0ffdd42d7dee4ac85427468bc616812e49432e285e4e8f5cd9381163ac3b28108a04ec6b0d89ecbd5e89b0399f336ad50f283fafd70e86593250bf5a2adfb93d17e') # noqa: E501
272+
expected_hash = HexStr('0x52b0ff9cb472f25872fa8ec6a62fa59454fc2ae7901cfcc6cc89d096f49b8fc1')
273+
txn_hash = await async_w3.eth.send_raw_transaction(raw_txn) # type: ignore
274+
assert txn_hash == async_w3.toBytes(hexstr=expected_hash)
275+
265276
@pytest.mark.asyncio
266277
async def test_gas_price_strategy_middleware(
267278
self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress
@@ -1887,27 +1898,14 @@ def test_eth_modifyTransaction_deprecated(
18871898
assert modified_txn['gas'] == 21000
18881899
assert modified_txn['gasPrice'] == cast(int, txn_params['gasPrice']) * 2
18891900

1890-
@pytest.mark.parametrize(
1891-
'raw_transaction, expected_hash',
1892-
[
1893-
(
1894-
# private key 0x3c2ab4e8f17a7dea191b8c991522660126d681039509dc3bb31af7c9bdb63518
1895-
# This is an unfunded account, but the transaction has a 0 gas price, so is valid.
1896-
# It never needs to be mined, we just want the transaction hash back to confirm.
1897-
# tx = {'to': '0x0000000000000000000000000000000000000000', 'value': 0, 'nonce': 0, 'gas': 21000, 'gasPrice': 0, 'chainId': 131277322940537} # noqa: E501
1898-
HexBytes('0xf8658080825208940000000000000000000000000000000000000000808086eecac466e115a038176e5f9f1c25ce470ce77856bacbc02dd728ad647bb8b18434ac62c3e8e14fa03279bb3ee1e5202580668ec62b66a7d01355de3d5c4ef18fcfcb88fac56d5f90'), # noqa: E501
1899-
'0x6ab943e675003de610b4e94f2e289dc711688df6e150da2bc57bd03811ad0f63',
1900-
),
1901-
]
1902-
)
1903-
def test_eth_send_raw_transaction(
1904-
self,
1905-
web3: "Web3",
1906-
raw_transaction: Union[HexStr, bytes],
1907-
funded_account_for_raw_txn: ChecksumAddress,
1908-
expected_hash: HexStr,
1909-
) -> None:
1910-
txn_hash = web3.eth.send_raw_transaction(raw_transaction)
1901+
def test_eth_send_raw_transaction(self, web3: "Web3") -> None:
1902+
# private key 0x3c2ab4e8f17a7dea191b8c991522660126d681039509dc3bb31af7c9bdb63518
1903+
# This is an unfunded account, but the transaction has a 0 gas price, so is valid.
1904+
# It never needs to be mined, we just want the transaction hash back to confirm.
1905+
# tx = {'to': '0x0000000000000000000000000000000000000000', 'value': 0, 'nonce': 0, 'gas': 21000, 'gasPrice': 0, 'chainId': 131277322940537} # noqa: E501
1906+
raw_txn = HexBytes('0xf8658080825208940000000000000000000000000000000000000000808086eecac466e115a038176e5f9f1c25ce470ce77856bacbc02dd728ad647bb8b18434ac62c3e8e14fa03279bb3ee1e5202580668ec62b66a7d01355de3d5c4ef18fcfcb88fac56d5f90') # noqa: E501
1907+
expected_hash = HexStr('0x6ab943e675003de610b4e94f2e289dc711688df6e150da2bc57bd03811ad0f63')
1908+
txn_hash = web3.eth.send_raw_transaction(raw_txn)
19111909
assert txn_hash == web3.toBytes(hexstr=expected_hash)
19121910

19131911
def test_eth_call(

0 commit comments

Comments
 (0)