Skip to content

Commit 47dabd7

Browse files
committed
[WIP] initial dirty commit, getting tests to pass locally with py-evm london changes. Change txn_type across codebase to clarify against an actual transaction type that now exists (typed transactions). Some spelling fixes. Some refactoring.
1 parent c99194c commit 47dabd7

File tree

13 files changed

+204
-106
lines changed

13 files changed

+204
-106
lines changed

eth_tester/backends/pyevm/main.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,20 @@ def generate_genesis_state_for_keys(account_keys, overrides=None):
120120

121121
def get_default_genesis_params(overrides=None):
122122
default_genesis_params = {
123-
"bloom": 0,
123+
# "bloom": 0,
124124
"coinbase": GENESIS_COINBASE,
125125
"difficulty": GENESIS_DIFFICULTY,
126126
"extra_data": GENESIS_EXTRA_DATA,
127127
"gas_limit": GENESIS_GAS_LIMIT,
128-
"gas_used": 0,
128+
# "gas_used": 0,
129129
"mix_hash": GENESIS_MIX_HASH,
130130
"nonce": GENESIS_NONCE,
131-
"block_number": GENESIS_BLOCK_NUMBER,
132-
"parent_hash": GENESIS_PARENT_HASH,
131+
# "block_number": GENESIS_BLOCK_NUMBER,
132+
# "parent_hash": GENESIS_PARENT_HASH,
133133
"receipt_root": BLANK_ROOT_HASH,
134134
"timestamp": int(time.time()),
135135
"transaction_root": BLANK_ROOT_HASH,
136-
"uncles_hash": EMPTY_RLP_LIST_HASH
136+
# "uncles_hash": EMPTY_RLP_LIST_HASH
137137
}
138138
if overrides is not None:
139139
genesis_params = merge_genesis_overrides(default_genesis_params, overrides=overrides)
@@ -156,8 +156,8 @@ def setup_tester_chain(
156156
from eth.db import get_db_backend
157157

158158
if vm_configuration is None:
159-
from eth.vm.forks import BerlinVM
160-
no_proof_vms = ((0, BerlinVM.configure(consensus_class=NoProofConsensus)),)
159+
from eth.vm.forks import LondonVM
160+
no_proof_vms = ((0, LondonVM.configure(consensus_class=NoProofConsensus)),)
161161
else:
162162
consensus_applier = ConsensusApplier(NoProofConsensus)
163163
no_proof_vms = consensus_applier.amend_vm_configuration(vm_configuration)
@@ -178,6 +178,10 @@ def create_header_from_parent(self, parent_header, **header_params):
178178
if genesis_state:
179179
num_accounts = len(genesis_state)
180180

181+
# TODO: maybe the below?
182+
# if genesis_params["block_number"] >= 12965000:
183+
# genesis_params["base_fee_per_gas"] = 1000000000
184+
181185
account_keys = get_default_account_keys(quantity=num_accounts)
182186

183187
if genesis_state is None:
@@ -435,7 +439,7 @@ def _normalize_transaction(self, transaction, block_number='latest'):
435439
if 'data' not in transaction:
436440
yield 'data', b''
437441
if 'gas_price' not in transaction:
438-
yield 'gas_price', 1
442+
yield 'gas_price', 1000000000
439443
if 'value' not in transaction:
440444
yield 'value', 0
441445
if 'to' not in transaction:

eth_tester/constants.py

+10
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@
1515
FORK_SPURIOUS_DRAGON = 'FORK_SPURIOUS_DRAGON'
1616
FORK_TANGERINE_WHISTLE = 'FORK_TANGERINE_WHISTLE'
1717
FORK_BYZANTIUM = 'FORK_BYZANTIUM'
18+
FORK_PETERSBURG = 'FORK_PETERSBURG'
19+
FORK_ISTANBUL = 'FORK_ISTANBUL'
20+
FORK_MUIR_GLACIER = 'FORK_MUIR_GLACIER'
21+
FORK_BERLIN = 'FORK_BERLIN'
22+
FORK_LONDON = 'FORK_LONDON'
1823

1924
KNOWN_FORKS = {
2025
FORK_HOMESTEAD,
2126
FORK_DAO,
2227
FORK_SPURIOUS_DRAGON,
2328
FORK_TANGERINE_WHISTLE,
2429
FORK_BYZANTIUM,
30+
FORK_PETERSBURG,
31+
FORK_ISTANBUL,
32+
FORK_MUIR_GLACIER,
33+
FORK_BERLIN,
34+
FORK_LONDON,
2535
}
2636

2737

eth_tester/main.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def _pop_pending_transactions_to_pending_block(self):
382382
def _add_all_to_pending_block(self, pending_transactions):
383383
for pending in pending_transactions:
384384
txn = extract_valid_transaction_params(pending)
385-
yield self._add_transaction_to_pending_block(txn, txn_type='send_signed')
385+
yield self._add_transaction_to_pending_block(txn, txn_internal_type='send_signed')
386386

387387
#
388388
# Transaction Sending
@@ -419,7 +419,7 @@ def send_transaction(self, transaction):
419419
return self._add_transaction_to_pending_block(transaction)
420420

421421
def call(self, transaction, block_number="latest"):
422-
self.validator.validate_inbound_transaction(transaction, txn_type='call')
422+
self.validator.validate_inbound_transaction(transaction, txn_internal_type='call')
423423
raw_transaction = self.normalizer.normalize_inbound_transaction(transaction)
424424
self.validator.validate_inbound_block_number(block_number)
425425
raw_block_number = self.normalizer.normalize_inbound_block_number(block_number)
@@ -429,7 +429,7 @@ def call(self, transaction, block_number="latest"):
429429
return result
430430

431431
def estimate_gas(self, transaction, block_number="latest"):
432-
self.validator.validate_inbound_transaction(transaction, txn_type='estimate')
432+
self.validator.validate_inbound_transaction(transaction, txn_internal_type='estimate')
433433
raw_transaction = self.normalizer.normalize_inbound_transaction(transaction)
434434
self.validator.validate_inbound_block_number(block_number)
435435
raw_block_number = self.normalizer.normalize_inbound_block_number(block_number)
@@ -441,8 +441,11 @@ def estimate_gas(self, transaction, block_number="latest"):
441441
#
442442
# Private Transaction API
443443
#
444-
def _add_transaction_to_pending_block(self, transaction, txn_type='send'):
445-
self.validator.validate_inbound_transaction(transaction, txn_type=txn_type)
444+
def _add_transaction_to_pending_block(self, transaction, txn_internal_type='send'):
445+
self.validator.validate_inbound_transaction(
446+
transaction,
447+
txn_internal_type=txn_internal_type
448+
)
446449
raw_transaction = self.normalizer.normalize_inbound_transaction(transaction)
447450

448451
if raw_transaction['from'] in self._account_passwords:

eth_tester/normalization/inbound.py

+5
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,18 @@ def normalize_private_key(value):
8282
))
8383

8484
TRANSACTION_NORMALIZERS = {
85+
'chain_id': identity,
86+
'type': identity,
8587
'from': to_canonical_address,
8688
'to': to_empty_or_canonical_address,
8789
'gas': identity,
8890
'gas_price': identity,
91+
'max_fee_per_gas': identity,
92+
'max_priority_fee_per_gas': identity,
8993
'nonce': identity,
9094
'value': identity,
9195
'data': decode_hex,
96+
'access_list': identity,
9297
'r': identity,
9398
's': identity,
9499
'v': identity,

eth_tester/normalization/outbound.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
))
3333

3434
TRANSACTION_NORMALIZERS = {
35+
"chain_id": identity,
36+
"type": identity,
3537
"hash": encode_hex,
3638
"nonce": identity,
3739
"block_hash": partial(normalize_if, conditional_fn=is_bytes, normalizer=encode_hex),
@@ -42,13 +44,14 @@
4244
"value": identity,
4345
"gas": identity,
4446
"gas_price": identity,
47+
"max_fee_per_gas": identity,
48+
"max_priority_fee_per_gas": identity,
4549
"data": encode_hex,
50+
"access_list": identity,
4651
"v": identity,
4752
"r": identity,
4853
"s": identity,
4954
}
50-
51-
5255
normalize_transaction = partial(normalize_dict, normalizers=TRANSACTION_NORMALIZERS)
5356

5457

@@ -65,6 +68,7 @@ def is_transaction_object_list(value):
6568
"hash": encode_hex,
6669
"parent_hash": encode_hex,
6770
"nonce": encode_hex,
71+
"base_fee_per_gas": identity,
6872
"sha3_uncles": encode_hex,
6973
"logs_bloom": identity,
7074
"transactions_root": encode_hex,

eth_tester/utils/backend_testing.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
PK_A = '0x58d23b55bc9cdce1f18c2500f40ff4ab7245df9a89505e9b1fa4851f623d241d'
5757
PK_A_ADDRESS = '0xdc544d1aa88ff8bbd2f2aec754b1f1e99e1812fd'
5858

59-
NON_DEFAULT_GAS_PRICE = 504
59+
NON_DEFAULT_GAS_PRICE = 1000000000
6060

6161
SIMPLE_TRANSACTION = {
6262
"to": BURN_ADDRESS,
@@ -96,16 +96,21 @@
9696
"timestamp",
9797
"transactions",
9898
"uncles",
99+
"base_fee_per_gas"
99100
}
100101

101102

102103
def _validate_serialized_block(block):
103104
missing_keys = BLOCK_KEYS.difference(block.keys())
104105
if missing_keys:
105-
error_message = "Serialized block is missing the following keys: {}".format(
106-
"|".join(sorted(missing_keys)),
107-
)
108-
raise AssertionError(error_message)
106+
if block.get('number') < 12965000 and 'base_fee_per_gas' in missing_keys:
107+
# if before london fork, ignore missing base_fee_per_gas
108+
pass
109+
else:
110+
error_message = "Serialized block is missing the following keys: {}".format(
111+
"|".join(sorted(missing_keys)),
112+
)
113+
raise AssertionError(error_message)
109114

110115

111116
class BaseTestBackendDirect:
@@ -265,10 +270,12 @@ def test_send_raw_transaction_valid_raw_transaction(self, eth_tester, is_pending
265270
"gas": 21000,
266271
"value": 1 * denoms.ether,
267272
})
268-
# transaction: nonce=0, gas_price=1, gas=21000, to=BURN_ADDRESS, value=50000, data=b'',
269-
# and signed with `test_key`
270-
transaction_hex = "0xf861800182520894dead00000000000000000000000000000000000082c350801ba073128146b850e2d38a4742d1afa48544e0ac6bc4b4dcb562583cd2224ad9a082a0680086a2801d02b12431cc3c79ec6c6a0cb846a0b3a8ec970f6e1b76d55ee7e2" # noqa: E501
271273

274+
# transaction: 'to': '0x19E7E376E7C213B7E7e7e46cc70A5dD086DAff2A', 'from':
275+
# '0x19E7E376E7C213B7E7e7e46cc70A5dD086DAff2A', 'value': 1337, 'nonce': 0
276+
# 'gas': 21000, 'gasPrice': 1000000000, and signed with `test_key`
277+
278+
transaction_hex = "0xf86580843b9aca008252089419e7e376e7c213b7e7e7e46cc70a5dd086daff2a820539801ba0b101c1f9dc0c588c0194a1093f06e6b30d1fd16d31014ef5851311b7bfbf419ea01cfa8757b7863a630ef7491c62b03d9cd9dff395f61b5df500cc665f0fa5b027" # noqa: E501
272279
if is_pending:
273280
eth_tester.disable_auto_mine_transactions()
274281

eth_tester/validation/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def validate_inbound_raw_transaction(self, raw_transaction_hex):
2929
def validate_inbound_timestamp(self, timestamp):
3030
raise NotImplementedError("must be implemented by subclasses")
3131

32-
def validate_inbound_transaction(self, transaction, txn_type):
32+
def validate_inbound_transaction(self, transaction, txn_internal_type):
3333
raise NotImplementedError("must be implemented by subclasses")
3434

3535
def validate_inbound_transaction_hash(self, transaction_hash):

eth_tester/validation/common.py

+27-7
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,35 @@ def validate_no_extra_keys(value, allowed_keys):
112112
def validate_has_required_keys(value, required_keys):
113113
missing_keys = tuple(sorted(set(required_keys).difference(value.keys())))
114114
if missing_keys:
115-
raise ValidationError(
116-
"Blocks must contain all of the keys '{}'. Missing the keys: '{}'".format(
117-
"/".join(tuple(sorted(required_keys))),
118-
"/".join(missing_keys),
115+
if "base_fee_per_gas" in missing_keys and value["number"] < 12965000:
116+
pass
117+
else:
118+
raise ValidationError(
119+
"Blocks must contain all of the keys '{}'. Missing the keys: '{}'".format(
120+
"/".join(tuple(sorted(required_keys))),
121+
"/".join(missing_keys),
122+
)
119123
)
120-
)
124+
125+
126+
def validate_transaction_params(value):
127+
if "gas_price" in value and any(_ in value for _ in (
128+
"max_fee_per_gas", "max_priority_fee_per_gas"
129+
)):
130+
raise ValidationError("legacy gas price and dynamic fee transaction parameters present")
131+
if "type" in value:
132+
if value["type"] in ("0x1", 1) and "access_list" not in value:
133+
raise ValidationError("type 1 transaction is missing access_list")
134+
if value["type"] in ("0x2", 2) and not all(_ in value for _ in (
135+
"max_fee_per_gas", "max_priority_fee_per_gas"
136+
)):
137+
raise ValidationError("type 2 transaction is missing fee values")
121138

122139

123140
@to_dict
124141
def _accumulate_dict_errors(value, validators):
125142
for key, validator_fn in validators.items():
126-
item = value[key]
143+
item = value.get(key)
127144
try:
128145
validator_fn(item)
129146
except ValidationError as err:
@@ -133,7 +150,10 @@ def _accumulate_dict_errors(value, validators):
133150
def validate_dict(value, key_validators):
134151
validate_is_dict(value)
135152
validate_no_extra_keys(value, key_validators.keys())
136-
validate_has_required_keys(value, key_validators.keys())
153+
if "gas" in value:
154+
validate_transaction_params(value)
155+
else:
156+
validate_has_required_keys(value, key_validators.keys())
137157

138158
key_errors = _accumulate_dict_errors(value, key_validators)
139159
if key_errors:

0 commit comments

Comments
 (0)