-
Notifications
You must be signed in to change notification settings - Fork 391
feat(tests): Typed txs are invalid and void before their fork #1754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
6072845
c513f66
9bc682d
56dd98b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -269,6 +269,10 @@ class TransactionException(ExceptionBase): | |
| """ | ||
| Transaction's initcode for a contract-creating transaction is too large. | ||
| """ | ||
| TYPE_1_TX_PRE_FORK = auto() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't catch on to this being duplicate in two files. This might be an artifact of the weld, I'll open an issue.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created #1816. |
||
| """Transaction type 1 included before activation fork.""" | ||
| TYPE_2_TX_PRE_FORK = auto() | ||
| """Transaction type 2 included before activation fork.""" | ||
| TYPE_3_TX_PRE_FORK = auto() | ||
| """Transaction type 3 included before activation fork.""" | ||
| TYPE_3_TX_ZERO_BLOBS_PRE_FORK = auto() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| """Test the tx type validation for EIP-2930.""" | ||
|
|
||
| from typing import Generator | ||
|
|
||
| import pytest | ||
| from execution_testing import ( | ||
| Account, | ||
| Alloc, | ||
| Fork, | ||
| ParameterSet, | ||
| StateTestFiller, | ||
| Transaction, | ||
| TransactionException, | ||
| ) | ||
| from execution_testing import Opcodes as Op | ||
| from execution_testing.forks import Byzantium | ||
|
|
||
| from .spec import ref_spec_2930 | ||
|
|
||
| REFERENCE_SPEC_GIT_PATH = ref_spec_2930.git_path | ||
| REFERENCE_SPEC_VERSION = ref_spec_2930.version | ||
|
|
||
| TX_TYPE = 1 | ||
|
|
||
|
|
||
| def tx_validity(fork: Fork) -> Generator[ParameterSet, None, None]: | ||
| """ | ||
| Return a generator of parameters for the tx validity test. | ||
| """ | ||
| valid = TX_TYPE in fork.tx_types() | ||
| yield pytest.param( | ||
| valid, | ||
| marks=[pytest.mark.exception_test] if not valid else [], | ||
| id="valid" if valid else "invalid", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.ported_from( | ||
| [ | ||
| "https://github.com/ethereum/legacytests/blob/master/src/LegacyTests/Cancun/GeneralStateTestsFiller/stExample/accessListExampleFiller.yml" | ||
| ], | ||
| pr=["https://github.com/ethereum/execution-specs/pull/1754"], | ||
| ) | ||
| @pytest.mark.parametrize_by_fork("valid", tx_validity) | ||
| def test_eip2930_tx_validity( | ||
| state_test: StateTestFiller, | ||
| fork: Fork, | ||
| pre: Alloc, | ||
| valid: bool, | ||
| ) -> None: | ||
| """ | ||
| Tests that an EIP-2930 tx is correctly rejected before fork activation. | ||
| """ | ||
| account = pre.deploy_contract( | ||
| code=Op.SSTORE(0, 1), | ||
| storage={0: 0xDEADBEEF}, | ||
| ) | ||
| sender = pre.fund_eoa() | ||
|
|
||
| tx = Transaction( | ||
| to=account, | ||
| sender=sender, | ||
| gas_limit=100_000, | ||
| access_list=[], | ||
| protected=fork >= Byzantium, | ||
| error=TransactionException.TYPE_1_TX_PRE_FORK if not valid else None, | ||
| ) | ||
|
|
||
| post = {account: Account(storage={0: 0xDEADBEEF if not valid else 1})} | ||
| if not valid: | ||
| post[sender] = pre[sender] # type: ignore | ||
|
|
||
| state_test(pre=pre, post=post, tx=tx) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """ | ||
| Tests for [EIP-1559: Fee market change for ETH 1.0 chain](https://eips.ethereum.org/EIPS/eip-1559). | ||
| """ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| """Defines EIP-1559 specification constants and functions.""" | ||
|
|
||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class ReferenceSpec: | ||
| """Defines the reference spec version and git path.""" | ||
|
|
||
| git_path: str | ||
| version: str | ||
|
|
||
|
|
||
| ref_spec_1559 = ReferenceSpec( | ||
| "EIPS/eip-1559.md", "ba6c342c23164072adb500c3136e3ae6eabff306" | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| """Test the tx type validation for EIP-1559.""" | ||
|
|
||
| from typing import Generator | ||
|
|
||
| import pytest | ||
| from execution_testing import ( | ||
| Account, | ||
| Alloc, | ||
| Fork, | ||
| ParameterSet, | ||
| StateTestFiller, | ||
| Transaction, | ||
| TransactionException, | ||
| ) | ||
| from execution_testing import Opcodes as Op | ||
| from execution_testing.forks import Byzantium | ||
|
|
||
| from .spec import ref_spec_1559 | ||
|
|
||
| REFERENCE_SPEC_GIT_PATH = ref_spec_1559.git_path | ||
| REFERENCE_SPEC_VERSION = ref_spec_1559.version | ||
|
|
||
| TX_TYPE = 2 | ||
|
|
||
|
|
||
| def tx_validity(fork: Fork) -> Generator[ParameterSet, None, None]: | ||
| """ | ||
| Return a generator of parameters for the tx validity test. | ||
| """ | ||
| valid = TX_TYPE in fork.tx_types() | ||
| yield pytest.param( | ||
| valid, | ||
| marks=[pytest.mark.exception_test] if not valid else [], | ||
| id="valid" if valid else "invalid", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.ported_from( | ||
| [ | ||
| "https://github.com/ethereum/legacytests/blob/master/Cancun/GeneralStateTests/stEIP1559/typeTwoBerlin.json" | ||
| ], | ||
| pr=["https://github.com/ethereum/execution-specs/pull/1754"], | ||
| ) | ||
| @pytest.mark.parametrize_by_fork("valid", tx_validity) | ||
| def test_eip1559_tx_validity( | ||
| state_test: StateTestFiller, | ||
| fork: Fork, | ||
| pre: Alloc, | ||
| valid: bool, | ||
| ) -> None: | ||
| """ | ||
| Tests that an EIP-1559 tx has no effect before London. | ||
| """ | ||
| account = pre.deploy_contract( | ||
| code=Op.SSTORE(0, 1), | ||
| storage={0: 0xDEADBEEF}, | ||
| ) | ||
| sender = pre.fund_eoa() | ||
|
|
||
| tx = Transaction( | ||
| to=account, | ||
| sender=sender, | ||
| gas_limit=100_000, | ||
| max_priority_fee_per_gas=1, | ||
| protected=fork >= Byzantium, | ||
| error=TransactionException.TYPE_2_TX_PRE_FORK if not valid else None, | ||
| ) | ||
|
|
||
| post = {account: Account(storage={0: 0xDEADBEEF if not valid else 1})} | ||
| if not valid: | ||
| post[sender] = pre[sender] # type: ignore | ||
|
|
||
| state_test(pre=pre, post=post, tx=tx) |
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.