Skip to content

Commit 794c359

Browse files
committed
Fix up raw transaction tests; use keyfile acct pkey
1 parent fea2929 commit 794c359

File tree

6 files changed

+48
-42
lines changed

6 files changed

+48
-42
lines changed

tests/integration/generate_fixtures/go_ethereum.py

+1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ def setup_chain_state(w3):
341341

342342
geth_fixture = {
343343
"keyfile_account_address": common.KEYFILE_ACCOUNT_ADDRESS,
344+
"keyfile_account_pkey": common.KEYFILE_ACCOUNT_PKEY,
344345
"math_deploy_txn_hash": math_deploy_receipt["transactionHash"],
345346
"math_address": math_deploy_receipt["contractAddress"],
346347
"emitter_deploy_txn_hash": emitter_deploy_receipt["transactionHash"],
-46.9 KB
Binary file not shown.
86 Bytes
Binary file not shown.

tests/integration/go_ethereum/conftest.py

+5
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ def emitter_contract_address(emitter_contract, address_conversion_func):
192192
return address_conversion_func(emitter_contract.address)
193193

194194

195+
@pytest.fixture(scope="module")
196+
def keyfile_account_pkey(geth_fixture_data):
197+
return geth_fixture_data["keyfile_account_pkey"]
198+
199+
195200
@pytest.fixture(scope="module")
196201
def keyfile_account_address(geth_fixture_data):
197202
return geth_fixture_data["keyfile_account_address"]

tests/integration/test_ethereum_tester.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ def block_with_txn(w3):
151151
"to": w3.eth.coinbase,
152152
"value": w3.to_wei(1, "gwei"),
153153
"gas": 21000,
154-
"gasPrice": w3.to_wei(10**9, "gwei"), # needs to be > base_fee post London
154+
"gasPrice": w3.to_wei(
155+
10**9, "gwei"
156+
), # needs to be > base_fee post London
155157
}
156158
)
157159
txn = w3.eth.get_transaction(txn_hash)
@@ -204,6 +206,11 @@ def panic_errors_contract(w3):
204206
return _deploy_contract(w3, panic_errors_contract_factory)
205207

206208

209+
@pytest.fixture(scope="module")
210+
def keyfile_account_pkey():
211+
yield KEYFILE_ACCOUNT_PKEY
212+
213+
207214
@pytest.fixture(scope="module")
208215
def keyfile_account_address():
209216
yield KEYFILE_ACCOUNT_ADDRESS
@@ -611,15 +618,6 @@ def test_eth_send_transaction_legacy(self, eth_tester, w3, keyfile_account_addre
611618
super().test_eth_send_transaction_legacy(w3, keyfile_account_address)
612619

613620
def test_eth_send_raw_transaction(self, eth_tester, w3):
614-
# fund address 0x6E6d469fa47ab2f6630bAfc03ECca1212c29B114
615-
w3.eth.send_transaction(
616-
{
617-
"from": w3.eth.coinbase,
618-
"to": "0x6E6d469fa47ab2f6630bAfc03ECca1212c29B114",
619-
"value": w3.to_wei(0.5, "ether"),
620-
"gas": 21000,
621-
}
622-
)
623621
super().test_eth_send_raw_transaction(w3)
624622

625623
@disable_auto_mine

web3/_utils/module_testing/eth_module.py

+34-32
Original file line numberDiff line numberDiff line change
@@ -702,22 +702,24 @@ async def test_ExtraDataToPOAMiddleware(
702702
async_w3.middleware_onion.remove("poa")
703703

704704
@pytest.mark.asyncio
705-
async def test_eth_send_raw_transaction(self, async_w3: "AsyncWeb3") -> None:
706-
# address 0x6E6d469fa47ab2f6630bAfc03ECca1212c29B114
707-
# private key 0x3c2ab4e8f17a7dea191b8c991522660126d681039509dc3bb31af7c9bdb63518
708-
# This is an unfunded account, but the transaction has a 0 gas price, so is
709-
# valid. It never needs to be mined, we just want the transaction hash back
710-
# to confirm.
711-
# tx = {'to': '0x0000000000000000000000000000000000000000', 'value': 0, 'nonce': 1, 'gas': 21000, 'gasPrice': 10**9, 'chainId': 131277322940537} # noqa: E501
712-
# NOTE: nonce=1 to make txn unique from the non-async version of this test
713-
raw_txn = HexBytes(
714-
"0xf86901843b9aca00825208940000000000000000000000000000000000000000808086eecac466e116a00c35ef06cefed3667cb9936ed1ed87177fd37654a86de9c8a7739011348cfc1ba00873e59bc3baf78faf7e526866e59f0b3c44063921790fe3f52862b679cd8c61" # noqa: E501
715-
)
716-
expected_hash = HexStr(
717-
"0x87638eb356dd219b3c9e3288e7631be2adb619c93f76a9c749112632184eb861"
718-
)
719-
txn_hash = await async_w3.eth.send_raw_transaction(raw_txn)
720-
assert txn_hash == async_w3.to_bytes(hexstr=expected_hash)
705+
async def test_async_eth_send_raw_transaction(
706+
self, async_w3: "AsyncWeb3", keyfile_account_pkey: HexStr
707+
) -> None:
708+
keyfile_account = async_w3.eth.account.from_key(keyfile_account_pkey)
709+
txn = {
710+
"chainId": 131277322940537, # the chainId set for the fixture
711+
"from": keyfile_account.address,
712+
"to": keyfile_account.address,
713+
"value": Wei(0),
714+
"gas": 21000,
715+
"nonce": await async_w3.eth.get_transaction_count(
716+
keyfile_account.address, "pending"
717+
),
718+
"gasPrice": 1,
719+
}
720+
signed = keyfile_account.sign_transaction(txn)
721+
txn_hash = await async_w3.eth.send_raw_transaction(signed.rawTransaction)
722+
assert txn_hash == HexBytes(signed.hash)
721723

722724
@pytest.mark.asyncio
723725
async def test_GasPriceStrategyMiddleware(
@@ -3701,22 +3703,22 @@ def test_eth_modify_transaction(
37013703
)
37023704
assert modified_txn["maxFeePerGas"] == cast(Wei, txn_params["maxFeePerGas"]) * 2
37033705

3704-
def test_eth_send_raw_transaction(self, w3: "Web3") -> None:
3705-
# address 0x6E6d469fa47ab2f6630bAfc03ECca1212c29B114
3706-
# private key 0x3c2ab4e8f17a7dea191b8c991522660126d681039509dc3bb31af7c9bdb63518
3707-
# This is an unfunded account, but the transaction has a 0 gas price, so is
3708-
# valid. It never needs to be mined, we just want the transaction hash back
3709-
# to confirm.
3710-
# tx = {'to': '0x0000000000000000000000000000000000000000', 'value': 0, 'nonce': 0, 'gas': 21000, 'gasPrice': 10**9, 'chainId': 131277322940537} # noqa: E501
3711-
# NOTE: nonce=0 to make txn unique from the async version of this test
3712-
raw_txn = HexBytes(
3713-
"0xf86980843b9aca00825208940000000000000000000000000000000000000000808086eecac466e115a064c3ae78af36ee5014e3437ad6587966f4b06cd96327bb5dc48b78b0c1cc8ae7a01b1b9ba32935bbf95bc453ad4995a90de10f61879a77b45ca07451a99cd58fd5" # noqa: E501
3714-
)
3715-
expected_hash = HexStr(
3716-
"0x42c2440fc4425952544c2300f33083c8135c3800de4b4918e1e2f06b7bd74269"
3717-
)
3718-
txn_hash = w3.eth.send_raw_transaction(raw_txn)
3719-
assert txn_hash == w3.to_bytes(hexstr=expected_hash)
3706+
def test_eth_send_raw_transaction(
3707+
self, w3: "Web3", keyfile_account_pkey: HexStr
3708+
) -> None:
3709+
keyfile_account = w3.eth.account.from_key(keyfile_account_pkey)
3710+
txn = {
3711+
"chainId": 131277322940537, # the chainId set for the fixture
3712+
"from": keyfile_account.address,
3713+
"to": keyfile_account.address,
3714+
"value": Wei(0),
3715+
"gas": 21000,
3716+
"nonce": w3.eth.get_transaction_count(keyfile_account.address, "pending"),
3717+
"gasPrice": 1,
3718+
}
3719+
signed = keyfile_account.sign_transaction(txn)
3720+
txn_hash = w3.eth.send_raw_transaction(signed.rawTransaction)
3721+
assert txn_hash == HexBytes(signed.hash)
37203722

37213723
def test_eth_call(self, w3: "Web3", math_contract: "Contract") -> None:
37223724
coinbase = w3.eth.coinbase

0 commit comments

Comments
 (0)