|
88 | 88 | )
|
89 | 89 | from web3.middleware import (
|
90 | 90 | ExtraDataToPOAMiddleware,
|
| 91 | + SignAndSendRawMiddlewareBuilder, |
91 | 92 | )
|
92 | 93 | from web3.types import (
|
93 | 94 | ENS,
|
@@ -725,6 +726,26 @@ async def test_async_eth_send_raw_transaction(
|
725 | 726 | txn_hash = await async_w3.eth.send_raw_transaction(signed.raw_transaction)
|
726 | 727 | assert txn_hash == HexBytes(signed.hash)
|
727 | 728 |
|
| 729 | + @pytest.mark.asyncio |
| 730 | + async def test_async_sign_and_send_raw_middleware( |
| 731 | + self, async_w3: "AsyncWeb3", keyfile_account_pkey: HexStr |
| 732 | + ) -> None: |
| 733 | + keyfile_account = async_w3.eth.account.from_key(keyfile_account_pkey) |
| 734 | + txn: TxParams = { |
| 735 | + "from": keyfile_account.address, |
| 736 | + "to": keyfile_account.address, |
| 737 | + "value": Wei(0), |
| 738 | + "gas": 21000, |
| 739 | + } |
| 740 | + async_w3.middleware_onion.add( |
| 741 | + SignAndSendRawMiddlewareBuilder.build(keyfile_account), "signing" |
| 742 | + ) |
| 743 | + txn_hash = await async_w3.eth.send_transaction(txn) |
| 744 | + assert isinstance(txn_hash, HexBytes) |
| 745 | + |
| 746 | + # clean up |
| 747 | + async_w3.middleware_onion.remove("signing") |
| 748 | + |
728 | 749 | @pytest.mark.asyncio
|
729 | 750 | async def test_GasPriceStrategyMiddleware(
|
730 | 751 | self,
|
@@ -3716,6 +3737,25 @@ def test_eth_send_raw_transaction(
|
3716 | 3737 | txn_hash = w3.eth.send_raw_transaction(signed.raw_transaction)
|
3717 | 3738 | assert txn_hash == HexBytes(signed.hash)
|
3718 | 3739 |
|
| 3740 | + def test_sign_and_send_raw_middleware( |
| 3741 | + self, w3: "Web3", keyfile_account_pkey: HexStr |
| 3742 | + ) -> None: |
| 3743 | + keyfile_account = w3.eth.account.from_key(keyfile_account_pkey) |
| 3744 | + txn: TxParams = { |
| 3745 | + "from": keyfile_account.address, |
| 3746 | + "to": keyfile_account.address, |
| 3747 | + "value": Wei(0), |
| 3748 | + "gas": 21000, |
| 3749 | + } |
| 3750 | + w3.middleware_onion.add( |
| 3751 | + SignAndSendRawMiddlewareBuilder.build(keyfile_account), "signing" |
| 3752 | + ) |
| 3753 | + txn_hash = w3.eth.send_transaction(txn) |
| 3754 | + assert isinstance(txn_hash, HexBytes) |
| 3755 | + |
| 3756 | + # cleanup |
| 3757 | + w3.middleware_onion.remove("signing") |
| 3758 | + |
3719 | 3759 | def test_eth_call(self, w3: "Web3", math_contract: "Contract") -> None:
|
3720 | 3760 | txn_params = math_contract._prepare_transaction(
|
3721 | 3761 | abi_element_identifier="add",
|
|
0 commit comments