Skip to content

Commit

Permalink
Update eth-account version & add eip-1559 eth_signTransaction support
Browse files Browse the repository at this point in the history
Updated the eth-account version to the latest which includes eip-1559 support. Added integration tests and made minor tweaks to support eip-1559 params for eth_signTransaction
  • Loading branch information
fselmo committed Jul 22, 2021
1 parent 4d42d25 commit e20b1f5
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 4 deletions.
1 change: 1 addition & 0 deletions newsfragments/2082.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eth_signTransaction support for eip-1559 params 'maxFeePerGas' and 'maxPriorityFeePerGas'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
install_requires=[
"aiohttp>=3.7.4.post0,<4",
"eth-abi>=2.0.0b6,<3.0.0",
"eth-account>=0.5.3,<0.6.0",
"eth-account>=0.5.5,<0.6.0",
"eth-hash[pycryptodome]>=0.2.0,<1.0.0",
"eth-typing>=2.0.0,<3.0.0",
"eth-utils>=1.9.5,<2.0.0",
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/test_ethereum_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,15 @@ class TestEthereumTesterEthModule(EthModuleTest):
EthModuleTest.test_eth_signTransaction_deprecated,
ValueError
)
test_eth_sign_transaction_legacy = not_implemented(
EthModuleTest.test_eth_sign_transaction_legacy,
ValueError
)
test_eth_sign_transaction = not_implemented(EthModuleTest.test_eth_sign_transaction, ValueError)
test_eth_sign_transaction_hex_fees = not_implemented(
EthModuleTest.test_eth_sign_transaction_hex_fees,
ValueError
)
test_eth_sign_transaction_ens_names = not_implemented(
EthModuleTest.test_eth_sign_transaction_ens_names, ValueError
)
Expand Down
1 change: 1 addition & 0 deletions web3/_utils/method_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ def apply_list_to_array_formatter(formatter: Any) -> Callable[..., Any]:
(is_length(2), estimate_gas_with_block_id),
)),
RPC.eth_sendTransaction: apply_formatter_at_index(transaction_param_formatter, 0),
RPC.eth_signTransaction: apply_formatter_at_index(transaction_param_formatter, 0),
RPC.eth_getProof: apply_formatter_at_index(to_hex_if_integer, 2),
# personal
RPC.personal_importRawKey: apply_formatter_at_index(
Expand Down
62 changes: 59 additions & 3 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,11 @@ def test_invalid_eth_sign_typed_data(
json.loads(invalid_typed_message)
)

def test_eth_sign_transaction(self, web3: "Web3", unlocked_account: ChecksumAddress) -> None:
def test_eth_sign_transaction_legacy(
self,
web3: "Web3",
unlocked_account: ChecksumAddress
) -> None:
txn_params: TxParams = {
'from': unlocked_account,
'to': unlocked_account,
Expand All @@ -957,6 +961,56 @@ def test_eth_sign_transaction(self, web3: "Web3", unlocked_account: ChecksumAddr
assert result['tx']['gasPrice'] == txn_params['gasPrice']
assert result['tx']['nonce'] == txn_params['nonce']

def test_eth_sign_transaction(
self,
web3: "Web3",
unlocked_account: ChecksumAddress
) -> None:
txn_params: TxParams = {
'from': unlocked_account,
'to': unlocked_account,
'value': Wei(1),
'gas': Wei(21000),
'maxFeePerGas': web3.toWei(2, 'gwei'),
'maxPriorityFeePerGas': web3.toWei(1, 'gwei'),
'nonce': Nonce(0),
}
result = web3.eth.sign_transaction(txn_params)
signatory_account = web3.eth.account.recover_transaction(result['raw'])
assert unlocked_account == signatory_account
assert result['tx']['to'] == txn_params['to']
assert result['tx']['value'] == txn_params['value']
assert result['tx']['gas'] == txn_params['gas']
assert result['tx']['maxFeePerGas'] == txn_params['maxFeePerGas']
assert result['tx']['maxPriorityFeePerGas'] == txn_params['maxPriorityFeePerGas']
assert result['tx']['nonce'] == txn_params['nonce']

def test_eth_sign_transaction_hex_fees(
self,
web3: "Web3",
unlocked_account: ChecksumAddress
) -> None:
txn_params: TxParams = {
'from': unlocked_account,
'to': unlocked_account,
'value': Wei(1),
'gas': Wei(21000),
'maxFeePerGas': hex(web3.toWei(2, 'gwei')),
'maxPriorityFeePerGas': hex(web3.toWei(1, 'gwei')),
'nonce': Nonce(0),
}
result = web3.eth.sign_transaction(txn_params)
signatory_account = web3.eth.account.recover_transaction(result['raw'])
assert unlocked_account == signatory_account
assert result['tx']['to'] == txn_params['to']
assert result['tx']['value'] == txn_params['value']
assert result['tx']['gas'] == txn_params['gas']
assert result['tx']['maxFeePerGas'] == int(str(txn_params['maxFeePerGas']), 16)
assert result['tx']['maxPriorityFeePerGas'] == int(
str(txn_params['maxPriorityFeePerGas']), 16
)
assert result['tx']['nonce'] == txn_params['nonce']

def test_eth_signTransaction_deprecated(self,
web3: "Web3",
unlocked_account: ChecksumAddress) -> None:
Expand Down Expand Up @@ -988,7 +1042,8 @@ def test_eth_sign_transaction_ens_names(
'to': 'unlocked-account.eth',
'value': Wei(1),
'gas': Wei(21000),
'gasPrice': web3.eth.gas_price,
'maxFeePerGas': web3.toWei(2, 'gwei'),
'maxPriorityFeePerGas': web3.toWei(1, 'gwei'),
'nonce': Nonce(0),
}
result = web3.eth.sign_transaction(txn_params)
Expand All @@ -997,7 +1052,8 @@ def test_eth_sign_transaction_ens_names(
assert result['tx']['to'] == unlocked_account
assert result['tx']['value'] == txn_params['value']
assert result['tx']['gas'] == txn_params['gas']
assert result['tx']['gasPrice'] == txn_params['gasPrice']
assert result['tx']['maxFeePerGas'] == txn_params['maxFeePerGas']
assert result['tx']['maxPriorityFeePerGas'] == txn_params['maxPriorityFeePerGas']
assert result['tx']['nonce'] == txn_params['nonce']

def test_eth_send_transaction_addr_checksum_required(
Expand Down

0 comments on commit e20b1f5

Please sign in to comment.