Skip to content

Commit 34f91a3

Browse files
committed
Peripheral London updates:
- update `buildTransaction()` to default to dynamic fee transaction params - add default values for dynamic fee transaction params - update core tests to use dynamic fee transactions by default where appropriate
1 parent 625e0e6 commit 34f91a3

File tree

11 files changed

+165
-71
lines changed

11 files changed

+165
-71
lines changed

docs/web3.eth.account.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ To sign a transaction locally that will invoke a smart contract:
313313

314314
>>> unicorn_txn
315315
{'value': 0,
316-
'type': '0x2',
317316
'chainId': 1,
318317
'gas': 70000,
319318
'maxFeePerGas': 2000000000,

newsfragments/2205.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updates to core tests and contract buildTransaction() method to default to dynamic fee transactions

tests/core/contracts/test_contract_buildTransaction.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def test_build_transaction_not_paying_to_nonpayable_function(
5454
'to': payable_tester_contract.address,
5555
'data': '0xe4cb8f5c',
5656
'value': 0,
57-
'gasPrice': 10 ** 9,
57+
'maxFeePerGas': 2750000000,
58+
'maxPriorityFeePerGas': 10 ** 9,
5859
'chainId': 61,
5960
}
6061

@@ -75,7 +76,8 @@ def test_build_transaction_with_contract_no_arguments(web3, math_contract, build
7576
'to': math_contract.address,
7677
'data': '0xd09de08a',
7778
'value': 0,
78-
'gasPrice': 10 ** 9,
79+
'maxFeePerGas': 2750000000,
80+
'maxPriorityFeePerGas': 10 ** 9,
7981
'chainId': 61,
8082
}
8183

@@ -86,7 +88,8 @@ def test_build_transaction_with_contract_fallback_function(web3, fallback_functi
8688
'to': fallback_function_contract.address,
8789
'data': '0x',
8890
'value': 0,
89-
'gasPrice': 10 ** 9,
91+
'maxFeePerGas': 2750000000,
92+
'maxPriorityFeePerGas': 10 ** 9,
9093
'chainId': 61,
9194
}
9295

@@ -105,7 +108,8 @@ def test_build_transaction_with_contract_class_method(
105108
'to': math_contract.address,
106109
'data': '0xd09de08a',
107110
'value': 0,
108-
'gasPrice': 10 ** 9,
111+
'maxFeePerGas': 2750000000,
112+
'maxPriorityFeePerGas': 10 ** 9,
109113
'chainId': 61,
110114
}
111115

@@ -119,7 +123,8 @@ def test_build_transaction_with_contract_default_account_is_set(
119123
'to': math_contract.address,
120124
'data': '0xd09de08a',
121125
'value': 0,
122-
'gasPrice': 10 ** 9,
126+
'maxFeePerGas': 2750000000,
127+
'maxPriorityFeePerGas': 10 ** 9,
123128
'chainId': 61,
124129
}
125130

@@ -162,38 +167,50 @@ def test_build_transaction_with_contract_to_address_supplied_errors(web3,
162167
(
163168
{}, (5,), {}, {
164169
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
165-
'value': 0, 'gasPrice': 10 ** 9, 'chainId': 61,
170+
'value': 0, 'maxFeePerGas': 2750000000, 'maxPriorityFeePerGas': 1000000000,
171+
'chainId': 61,
166172
}, False
167173
),
168174
(
169175
{'gas': 800000}, (5,), {}, {
170176
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
171-
'value': 0, 'gasPrice': 10 ** 9, 'chainId': 61,
177+
'value': 0, 'maxFeePerGas': 2750000000, 'maxPriorityFeePerGas': 1000000000,
178+
'chainId': 61,
179+
}, False
180+
),
181+
( # legacy transaction, explicit gasPrice
182+
{'gasPrice': 22 ** 8}, (5,), {}, {
183+
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
184+
'value': 0, 'gasPrice': 22 ** 8, 'chainId': 61,
172185
}, False
173186
),
174187
(
175-
{'gasPrice': 10 ** 9}, (5,), {}, {
188+
{'maxFeePerGas': 22 ** 8, 'maxPriorityFeePerGas': 22 ** 8}, (5,), {}, {
176189
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
177-
'value': 0, 'gasPrice': 10 ** 9, 'chainId': 61,
190+
'value': 0, 'maxFeePerGas': 22 ** 8, 'maxPriorityFeePerGas': 22 ** 8,
191+
'chainId': 61,
178192
}, False
179193
),
180194
(
181195
{'nonce': 7}, (5,), {}, {
182196
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
183-
'value': 0, 'gasPrice': 10 ** 9, 'nonce': 7, 'chainId': 61,
197+
'value': 0, 'maxFeePerGas': 2750000000, 'maxPriorityFeePerGas': 1000000000,
198+
'nonce': 7, 'chainId': 61,
184199
}, True
185200
),
186201
(
187202
{'value': 20000}, (5,), {}, {
188203
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
189-
'value': 20000, 'gasPrice': 10 ** 9, 'chainId': 61,
204+
'value': 20000, 'maxFeePerGas': 2750000000, 'maxPriorityFeePerGas': 1000000000,
205+
'chainId': 61,
190206
}, False
191207
),
192208
),
193209
ids=[
194210
'Standard',
195211
'Explicit Gas',
196212
'Explicit Gas Price',
213+
'Explicit Dynamic Fees',
197214
'Explicit Nonce',
198215
'With Value',
199216
]

tests/core/contracts/test_contract_caller_interface.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def transaction_dict(web3, address):
4343
return {
4444
'from': address,
4545
'gas': 210000,
46-
'gasPrice': web3.toWei(.001, 'ether'),
46+
'maxFeePerGas': web3.toWei(1, 'gwei'),
47+
'maxPriorityFeePerGas': web3.toWei(1, 'gwei'),
4748
'value': 12345,
4849
}
4950

tests/core/eth-module/test_accounts.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,32 @@ def test_eth_account_sign(acct,
290290
232940010090391255679819602567388136081614408698362277324138554019997613600,
291291
38,
292292
),
293+
(
294+
{
295+
"gas": 100000,
296+
"gasPrice": 1000000000,
297+
"data": "0x5544",
298+
"nonce": "0x2",
299+
"to": "0x96216849c49358B10257cb55b28eA603c874b05E",
300+
"value": "0x5af3107a4000",
301+
"type": "0x1",
302+
"accessList": (
303+
{
304+
"address": "0x0000000000000000000000000000000000000001",
305+
"storageKeys": (
306+
"0x0100000000000000000000000000000000000000000000000000000000000000",
307+
),
308+
},
309+
),
310+
"chainId": 1,
311+
},
312+
'0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318',
313+
HexBytes('0x01f8a70102843b9aca00830186a09496216849c49358b10257cb55b28ea603c874b05e865af3107a4000825544f838f7940000000000000000000000000000000000000001e1a0010000000000000000000000000000000000000000000000000000000000000080a059a827f04246489aca139510f2f82896fd5bd1d34f05228b3fe0c60141db4246a07a28a925eae2e3ee173cf691de2737cbff9160fc527ca4305740a31f154758c5'), # noqa: 501
314+
HexBytes('0x5daf67cf0dd95f338e98b7b8ee7635f3667b7127be8f42011536c239f8ed4f50'),
315+
40552949476267726331782755436085615371483644858950895384477411974599262552646,
316+
55254008827136682571969715431199989606887296450225146219777298167488873715909,
317+
0,
318+
),
293319
(
294320
{
295321
"gas": 100000,
@@ -337,7 +363,13 @@ def test_eth_account_sign(acct,
337363
0,
338364
)
339365
),
340-
ids=['web3js_example', '31byte_r_and_s', 'dynamic_fee_txn_example', 'dynamic_fee_txn_hex_fees'],
366+
ids=[
367+
'web3js_example',
368+
'31byte_r_and_s',
369+
'access_list_txn',
370+
'dynamic_fee_txn',
371+
'dynamic_fee_txn_hex_fees',
372+
],
341373
)
342374
def test_eth_account_sign_transaction(acct, txn, private_key, expected_raw_tx, tx_hash, r, s, v):
343375
signed = acct.sign_transaction(txn, private_key)

tests/core/filtering/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ def emitter(web3, Emitter, wait_for_transaction, wait_for_block, address_convers
7676
deploy_txn_hash = Emitter.constructor().transact({
7777
'from': web3.eth.coinbase,
7878
'gas': 1000000,
79-
'gasPrice': 10 ** 9})
79+
'maxFeePerGas': 10 ** 9,
80+
'maxPriorityFeePerGas': 10 ** 9,
81+
})
8082
deploy_receipt = wait_for_transaction(web3, deploy_txn_hash)
8183
contract_address = address_conversion_func(deploy_receipt['contractAddress'])
8284

tests/core/filtering/test_contract_data_filters.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ def emitter(web3, Emitter, wait_for_transaction, wait_for_block, address_convers
7070
deploy_txn_hash = Emitter.constructor().transact({
7171
'from': web3.eth.coinbase,
7272
'gas': 1000000,
73-
'gasPrice': 10 ** 9})
73+
'maxFeePerGas': 10 ** 9,
74+
'maxPriorityFeePerGas': 10 ** 9,
75+
})
7476
deploy_receipt = wait_for_transaction(web3, deploy_txn_hash)
7577
contract_address = address_conversion_func(deploy_receipt['contractAddress'])
7678

@@ -153,10 +155,10 @@ def test_data_filters_with_dynamic_arguments(
153155
txn_hashes = [
154156
emitter.functions.logDynamicArgs(
155157
arg0=vals['matching'], arg1=vals['matching']).transact(
156-
{'gasPrice': 10 ** 9, 'gas': 400000}),
158+
{'maxFeePerGas': 10 ** 9, 'maxPriorityFeePerGas': 10 ** 9, 'gas': 400000}),
157159
emitter.functions.logDynamicArgs(
158160
arg0=vals['non_matching'][0], arg1=vals['non_matching'][0]).transact(
159-
{'gasPrice': 10 ** 9, 'gas': 400000}),
161+
{'maxFeePerGas': 10 ** 9, 'maxPriorityFeePerGas': 10 ** 9, 'gas': 400000}),
160162
]
161163

162164
for txn_hash in txn_hashes:
@@ -200,13 +202,17 @@ def test_data_filters_with_fixed_arguments(
200202
arg0=vals['matching'][0],
201203
arg1=vals['matching'][1],
202204
arg2=vals['matching'][2],
203-
arg3=vals['matching'][3]).transact({'gasPrice': 10 ** 9, 'gas': 100000}))
205+
arg3=vals['matching'][3]).transact({
206+
'maxFeePerGas': 10 ** 9, 'maxPriorityFeePerGas': 10 ** 9, 'gas': 100000
207+
}))
204208
txn_hashes.append(emitter.functions.logQuadruple(
205209
which=5,
206210
arg0=vals['non_matching'][0],
207211
arg1=vals['non_matching'][1],
208212
arg2=vals['non_matching'][2],
209-
arg3=vals['non_matching'][3]).transact({'gasPrice': 10 ** 9, 'gas': 100000}))
213+
arg3=vals['non_matching'][3]).transact({
214+
'maxFeePerGas': 10 ** 9, 'maxPriorityFeePerGas': 10 ** 9, 'gas': 100000
215+
}))
210216

211217
for txn_hash in txn_hashes:
212218
wait_for_transaction(web3, txn_hash)
@@ -239,16 +245,16 @@ def test_data_filters_with_list_arguments(
239245
txn_hashes = []
240246
txn_hashes.append(emitter.functions.logListArgs(
241247
arg0=matching,
242-
arg1=matching).transact({'gasPrice': 10 ** 9}))
248+
arg1=matching).transact({'maxFeePerGas': 10 ** 9, 'maxPriorityFeePerGas': 10 ** 9}))
243249
txn_hashes.append(emitter.functions.logListArgs(
244250
arg0=non_matching,
245-
arg1=non_matching).transact({'gasPrice': 10 ** 9}))
251+
arg1=non_matching).transact({'maxFeePerGas': 10 ** 9, 'maxPriorityFeePerGas': 10 ** 9}))
246252
txn_hashes.append(emitter.functions.logListArgs(
247253
arg0=non_matching,
248-
arg1=matching).transact({'gasPrice': 10 ** 9}))
254+
arg1=matching).transact({'maxFeePerGas': 10 ** 9, 'maxPriorityFeePerGas': 10 ** 9}))
249255
txn_hashes.append(emitter.functions.logListArgs(
250256
arg0=matching,
251-
arg1=non_matching).transact({'gasPrice': 10 ** 9}))
257+
arg1=non_matching).transact({'maxFeePerGas': 10 ** 9, 'maxPriorityFeePerGas': 10 ** 9}))
252258

253259
for txn_hash in txn_hashes:
254260
wait_for_transaction(web3, txn_hash)

tests/core/filtering/test_contract_topic_filters.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,14 @@ def test_topic_filters_with_dynamic_arguments(
8181
txn_hashes = [
8282
emitter.functions.logDynamicArgs(
8383
arg0=vals['matching'],
84-
arg1=vals['matching']).transact({'gasPrice': 10 ** 9, 'gas': 60000}),
84+
arg1=vals['matching']).transact({
85+
'maxFeePerGas': 10 ** 9, 'maxPriorityFeePerGas': 10 ** 9, 'gas': 60000
86+
}),
8587
emitter.functions.logDynamicArgs(
8688
arg0=vals['non_matching'][0],
87-
arg1=vals['non_matching'][0]).transact({'gasPrice': 10 ** 9, 'gas': 60000})
89+
arg1=vals['non_matching'][0]).transact({
90+
'maxFeePerGas': 10 ** 9, 'maxPriorityFeePerGas': 10 ** 9, 'gas': 60000
91+
})
8892
]
8993

9094
for txn_hash in txn_hashes:
@@ -130,13 +134,17 @@ def test_topic_filters_with_fixed_arguments(
130134
arg0=vals['matching'][0],
131135
arg1=vals['matching'][1],
132136
arg2=vals['matching'][2],
133-
arg3=vals['matching'][3]).transact({'gasPrice': 10 ** 9, 'gas': 60000}))
137+
arg3=vals['matching'][3]).transact({
138+
'maxFeePerGas': 10 ** 9, 'maxPriorityFeePerGas': 10 ** 9, 'gas': 60000
139+
}))
134140
txn_hashes.append(emitter.functions.logQuadruple(
135141
which=11,
136142
arg0=vals['non_matching'][0],
137143
arg1=vals['non_matching'][1],
138144
arg2=vals['non_matching'][2],
139-
arg3=vals['non_matching'][3]).transact({'gasPrice': 10 ** 9, 'gas': 60000}))
145+
arg3=vals['non_matching'][3]).transact({
146+
'maxFeePerGas': 10 ** 9, 'maxPriorityFeePerGas': 10 ** 9, 'gas': 60000
147+
}))
140148

141149
for txn_hash in txn_hashes:
142150
wait_for_transaction(web3, txn_hash)
@@ -167,10 +175,10 @@ def test_topic_filters_with_list_arguments(
167175
txn_hashes = []
168176
txn_hashes.append(emitter.functions.logListArgs(
169177
arg0=matching,
170-
arg1=matching).transact({'gasPrice': 10 ** 9}))
178+
arg1=matching).transact({'maxFeePerGas': 10 ** 9, 'maxPriorityFeePerGas': 10 ** 9}))
171179
txn_hashes.append(emitter.functions.logListArgs(
172180
arg0=non_matching,
173-
arg1=non_matching).transact({'gasPrice': 10 ** 9}))
181+
arg1=non_matching).transact({'maxFeePerGas': 10 ** 9, 'maxPriorityFeePerGas': 10 ** 9}))
174182

175183
for txn_hash in txn_hashes:
176184
wait_for_transaction(web3, txn_hash)

tests/core/utilities/test_valid_transaction_params.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ def test_assert_valid_transaction_params_all_params():
1717
'gasPrice': 5000000,
1818
'maxFeePerGas': 2000000000,
1919
'maxPriorityFeePerGas': 1000000000,
20+
'accessList': (
21+
{
22+
'address': '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae',
23+
'storageKeys': (
24+
'0x0000000000000000000000000000000000000000000000000000000000000003',
25+
'0x0000000000000000000000000000000000000000000000000000000000000007',
26+
)
27+
},
28+
{
29+
'address': '0xbb9bc244d798123fde783fcc1c72d3bb8c189413',
30+
'storageKeys': ()
31+
},
32+
),
2033
'value': 1,
2134
'data': '0x0',
2235
'nonce': 2,
@@ -54,6 +67,19 @@ def test_assert_valid_transaction_params_invalid_param():
5467
'value': 3,
5568
'nonce': 2,
5669
'chainId': 1,
70+
'accessList': (
71+
{
72+
'address': '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae',
73+
'storageKeys': (
74+
'0x0000000000000000000000000000000000000000000000000000000000000003',
75+
'0x0000000000000000000000000000000000000000000000000000000000000007',
76+
)
77+
},
78+
{
79+
'address': '0xbb9bc244d798123fde783fcc1c72d3bb8c189413',
80+
'storageKeys': ()
81+
},
82+
),
5783
}
5884

5985

@@ -117,28 +143,9 @@ def test_fill_transaction_defaults_for_all_params(web3):
117143
'chainId': web3.eth.chain_id,
118144
'data': b'',
119145
'gas': web3.eth.estimate_gas({}),
120-
'gasPrice': web3.eth.gas_price,
146+
'maxFeePerGas': (
147+
web3.eth.max_priority_fee + (2 * web3.eth.get_block('latest')['baseFeePerGas'])
148+
),
149+
'maxPriorityFeePerGas': web3.eth.max_priority_fee,
121150
'value': 0,
122151
}
123-
124-
125-
def test_fill_transaction_defaults_sets_type_with_dynamic_fee_txn_params_and_no_gas_price(web3):
126-
dynamic_fee_transaction = {
127-
'chainId': 1,
128-
'data': b'123',
129-
'gas': 21000,
130-
'maxFeePerGas': 2000000000,
131-
'maxPriorityFeePerGas': 1000000000,
132-
'value': 2,
133-
}
134-
dynamic_fee_transaction_type_added = fill_transaction_defaults(web3, dynamic_fee_transaction)
135-
136-
assert dynamic_fee_transaction_type_added == {
137-
'chainId': 1,
138-
'data': b'123',
139-
'gas': 21000,
140-
'maxFeePerGas': 2000000000,
141-
'maxPriorityFeePerGas': 1000000000,
142-
'type': '0x2', # type is added and defaults to '0x2' when dynamic fee txn params present
143-
'value': 2,
144-
}

0 commit comments

Comments
 (0)