45
45
check_if_log_matches ,
46
46
)
47
47
from eth_tester .utils .transactions import (
48
+ extract_transaction_type ,
48
49
extract_valid_transaction_params ,
49
50
remove_matching_transaction_from_list ,
50
51
)
@@ -71,7 +72,7 @@ def func_wrapper(self, *args, **kwargs):
71
72
try :
72
73
transaction_hash = func (self , * args , ** kwargs )
73
74
pending_transaction = self .get_transaction_by_hash (transaction_hash )
74
- pending_transaction = _clean_pending_transaction_for_sending (pending_transaction )
75
+ pending_transaction = _clean_pending_transaction (pending_transaction )
75
76
# Remove any pending transactions with the same nonce
76
77
self ._pending_transactions = remove_matching_transaction_from_list (
77
78
self ._pending_transactions , pending_transaction )
@@ -80,17 +81,17 @@ def func_wrapper(self, *args, **kwargs):
80
81
self .revert_to_snapshot (snapshot )
81
82
return transaction_hash
82
83
83
- def _clean_pending_transaction_for_sending (pending_transaction ):
84
+ def _clean_pending_transaction (pending_transaction ):
84
85
cleaned_transaction = dissoc (pending_transaction , 'type' )
85
86
86
87
# TODO: Sometime in early 2022 (the merge?), the inclusion of gas_price will be removed
87
88
# from dynamic fee transactions and we can get rid of this behavior.
88
89
# https://github.com/ethereum/execution-specs/pull/251
90
+ # remove gas_price for dynamic fee transactions
89
91
if 'gas_price' and 'max_fee_per_gas' in pending_transaction :
90
92
cleaned_transaction = dissoc (cleaned_transaction , 'gas_price' )
91
93
92
94
return cleaned_transaction
93
-
94
95
return func_wrapper
95
96
96
97
@@ -264,6 +265,27 @@ def get_nonce(self, account, block_number="latest"):
264
265
# Blocks, Transactions, Receipts
265
266
#
266
267
268
+ @staticmethod
269
+ def _normalize_pending_transaction (pending_transaction ):
270
+ """
271
+ Add the transaction type and, if a dynamic fee transaction, add gas_price =
272
+ max_fee_per_gas as highlighted in the execution-specs link below.
273
+ """
274
+ _type = extract_transaction_type (pending_transaction )
275
+ pending_transaction = assoc (pending_transaction , 'type' , _type )
276
+
277
+ # TODO: Sometime in 2022 the inclusion of gas_price may be removed from dynamic fee
278
+ # transactions and we can get rid of this behavior.
279
+ # https://github.com/ethereum/execution-specs/pull/251
280
+ # add gas_price = max_fee_per_gas to pending dynamic fee transactions
281
+ if _type == '0x2' :
282
+ pending_transaction = assoc (
283
+ pending_transaction ,
284
+ 'gas_price' ,
285
+ pending_transaction ['max_fee_per_gas' ]
286
+ )
287
+ return pending_transaction
288
+
267
289
def _get_pending_transaction_by_hash (self , transaction_hash ):
268
290
for transaction in self ._pending_transactions :
269
291
if transaction ['hash' ] == transaction_hash :
@@ -275,7 +297,8 @@ def _get_pending_transaction_by_hash(self, transaction_hash):
275
297
def get_transaction_by_hash (self , transaction_hash ):
276
298
self .validator .validate_inbound_transaction_hash (transaction_hash )
277
299
try :
278
- return self ._get_pending_transaction_by_hash (transaction_hash )
300
+ pending_transaction = self ._get_pending_transaction_by_hash (transaction_hash )
301
+ return self ._normalize_pending_transaction (pending_transaction )
279
302
except TransactionNotFound :
280
303
raw_transaction_hash = self .normalizer .normalize_inbound_transaction_hash (
281
304
transaction_hash ,
0 commit comments