Skip to content

Commit

Permalink
Add test for async eth.send_raw_transaction and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed Sep 7, 2021
1 parent e465ce2 commit 4b658dd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
3 changes: 1 addition & 2 deletions newsfragments/2135.doc.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
- Add async ``eth.send_raw_transaction`` methods.
- Update AsyncHTTPProvider doc Supported Methods to include ``web3.eth.send_raw_transaction()``.
Update AsyncHTTPProvider doc Supported Methods to include ``web3.eth.send_raw_transaction()``.
1 change: 1 addition & 0 deletions newsfragments/2135.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add async ``eth.send_raw_transaction`` method
41 changes: 19 additions & 22 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
TYPE_CHECKING,
Callable,
Sequence,
Union,
cast,
)

Expand Down Expand Up @@ -262,6 +261,17 @@ async def test_eth_send_transaction_max_fee_less_than_tip(
):
await async_w3.eth.send_transaction(txn_params) # type: ignore

@pytest.mark.asyncio
async def test_eth_send_raw_transaction(self, async_w3: "Web3") -> None:
# private key 0x3c2ab4e8f17a7dea191b8c991522660126d681039509dc3bb31af7c9bdb63518
# This is an unfunded account, but the transaction has a 0 gas price, so is valid.
# It never needs to be mined, we just want the transaction hash back to confirm.
# tx = {'to': '0x0000000000000000000000000000000000000000', 'value': 0, 'nonce': 0, 'gas': 21000, 'gasPrice': 0, 'chainId': 131277322940537} # noqa: E501
raw_txn = HexBytes('0xf8658080825208940000000000000000000000000000000000000000808086eecac466e115a038176e5f9f1c25ce470ce77856bacbc02dd728ad647bb8b18434ac62c3e8e14fa03279bb3ee1e5202580668ec62b66a7d01355de3d5c4ef18fcfcb88fac56d5f90') # noqa: E501
expected_hash = HexStr('0x6ab943e675003de610b4e94f2e289dc711688df6e150da2bc57bd03811ad0f63')
txn_hash = await async_w3.eth.send_raw_transaction(raw_txn) # type: ignore
assert txn_hash == async_w3.toBytes(hexstr=expected_hash)

@pytest.mark.asyncio
async def test_gas_price_strategy_middleware(
self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress
Expand Down Expand Up @@ -1887,27 +1897,14 @@ def test_eth_modifyTransaction_deprecated(
assert modified_txn['gas'] == 21000
assert modified_txn['gasPrice'] == cast(int, txn_params['gasPrice']) * 2

@pytest.mark.parametrize(
'raw_transaction, expected_hash',
[
(
# private key 0x3c2ab4e8f17a7dea191b8c991522660126d681039509dc3bb31af7c9bdb63518
# This is an unfunded account, but the transaction has a 0 gas price, so is valid.
# It never needs to be mined, we just want the transaction hash back to confirm.
# tx = {'to': '0x0000000000000000000000000000000000000000', 'value': 0, 'nonce': 0, 'gas': 21000, 'gasPrice': 0, 'chainId': 131277322940537} # noqa: E501
HexBytes('0xf8658080825208940000000000000000000000000000000000000000808086eecac466e115a038176e5f9f1c25ce470ce77856bacbc02dd728ad647bb8b18434ac62c3e8e14fa03279bb3ee1e5202580668ec62b66a7d01355de3d5c4ef18fcfcb88fac56d5f90'), # noqa: E501
'0x6ab943e675003de610b4e94f2e289dc711688df6e150da2bc57bd03811ad0f63',
),
]
)
def test_eth_send_raw_transaction(
self,
web3: "Web3",
raw_transaction: Union[HexStr, bytes],
funded_account_for_raw_txn: ChecksumAddress,
expected_hash: HexStr,
) -> None:
txn_hash = web3.eth.send_raw_transaction(raw_transaction)
def test_eth_send_raw_transaction(self, web3: "Web3") -> None:
# private key 0x3c2ab4e8f17a7dea191b8c991522660126d681039509dc3bb31af7c9bdb63518
# This is an unfunded account, but the transaction has a 0 gas price, so is valid.
# It never needs to be mined, we just want the transaction hash back to confirm.
# tx = {'to': '0x0000000000000000000000000000000000000000', 'value': 0, 'nonce': 0, 'gas': 21000, 'gasPrice': 0, 'chainId': 131277322940537} # noqa: E501
raw_txn = HexBytes('0xf8658080825208940000000000000000000000000000000000000000808086eecac466e115a038176e5f9f1c25ce470ce77856bacbc02dd728ad647bb8b18434ac62c3e8e14fa03279bb3ee1e5202580668ec62b66a7d01355de3d5c4ef18fcfcb88fac56d5f90') # noqa: E501
expected_hash = HexStr('0x6ab943e675003de610b4e94f2e289dc711688df6e150da2bc57bd03811ad0f63')
txn_hash = web3.eth.send_raw_transaction(raw_txn)
assert txn_hash == web3.toBytes(hexstr=expected_hash)

def test_eth_call(
Expand Down

0 comments on commit 4b658dd

Please sign in to comment.