forked from ethereum/execution-spec-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fixtures,specs,tests): Transaction tests, EIP-7702 convert inval…
…id tx tests (ethereum#933) * new(fixtures): TransactionFixture format * new(specs): TransactionTest format * fix(forks): rename intrinsic cost calc parameter name * fix(tests): rename intrinsic cost calc parameter name * fix(specs): use `fork` intrinsic gas calculator * fix(fixtures): Add `TransactionFixture` to file * fix(fixtures): transaction type optional fields * feat(fixtures): Add fixture format to `_info` for easier parsing * fix(cli/check_fixtures): Allow a single fixture check * fix(types): Address(0) == "" * fix(fixtures,specs): fixes * feat(types): Allow nonce list in auth tuple, for testing purposes * fix(tests): EIP-7702: Convert invalid tx tests * docs: update, changelog * fix(docs): tox * fix(tests): EIP-7702: Move invalid tx tests to its own file * new(docs): Add Transaction Test to `consuming_tests` * fix(fixtures): fix `fixture_type_discriminator` * Update docs/consuming_tests/index.md Co-authored-by: danceratopz <[email protected]> * Apply suggestions from code review (fixture_type_discriminator) Co-authored-by: danceratopz <[email protected]> * nit --------- Co-authored-by: danceratopz <[email protected]>
- Loading branch information
1 parent
d65e6fb
commit 4aa6bc0
Showing
35 changed files
with
707 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Transaction Tests <!-- markdownlint-disable MD051 (MD051=link-fragments "Link fragments should be valid") --> | ||
|
||
The Transaction Test fixture format tests are included in the fixtures subdirectory `transaction_tests`. | ||
|
||
These are produced by the `TransactionTest` test spec. | ||
|
||
## Description | ||
|
||
The transaction test fixture format is used to test client's transaction RLP parsing without executing the transaction on the EVM. | ||
|
||
It does so by defining a transaction binary RLP representation, and whether the transaction should be accepted or rejected by the client in each fork. | ||
|
||
A single JSON fixture file is composed of a JSON object where each key-value pair is a different [`Fixture`](#fixture) test object, with the key string representing the test name. | ||
|
||
The JSON file path plus the test name are used as the unique test identifier. | ||
|
||
The transaction test fixture format could contain multiple test vectors per test object, each represented by an element in the mapping of lists of the `result` field. | ||
|
||
However tests generated by the `execution-spec-tests` repository do **not** use this feature, as every single test object contains only a single test vector. | ||
|
||
## Consumption | ||
|
||
For each [`Fixture`](#fixture) test object in the JSON fixture file, perform the following steps: | ||
|
||
1. Obtain the [`txbytes`](#-txbytes-bytes) serialized bytes of the transaction to be parsed. | ||
2. For each [`Fork`](./common_types.md#fork) key of [`result`](#-result-mappingforkfixtureresult) in the test: | ||
|
||
1. Assume the fork schedule according to the current [`Fork`](./common_types.md#fork) key. | ||
2. Using the [`txbytes`](#-txbytes-bytes), attempt to decode the transaction. | ||
3. If the transaction could not be decoded: | ||
- If the [`hash`](#-hash-hash-none) field is present, fail the test. | ||
- Compare the exception thrown with the expected exception contained in the [`exception`](#-exception-transactionexception) field, and fail the test if they do not match. | ||
- Proceed to the next fork. | ||
4. If the transaction could be decoded: | ||
- Compare the calculated hash with the expected hash contained in the [`hash`](#-hash-hash-none) field, and fail the test if they do not match. | ||
- Compare the calculated intrinsic gas with the expected intrinsic gas contained in the [`intrinsicGas`](#-intrinsicgas-zeropaddedhexnumber) field, and fail the test if they do not match. | ||
- Compare the calculated sender with the expected sender contained in the [`sender`](#-sender-address) field, and fail the test if they do not match. | ||
|
||
## Structures | ||
|
||
### `Fixture` | ||
|
||
#### - `txbytes`: [`Bytes`](./common_types.md#bytes) | ||
|
||
Serialized bytes of the transaction under test. | ||
|
||
#### - `result`: [`Mapping`](./common_types.md#mapping)`[`[`Fork`](./common_types.md#fork)`,`[`FixtureResult`](#fixtureresult) `]` | ||
|
||
Mapping of results for verification per fork, where each key-value represents a single possible outcome of the transaction parsed in the given fork. | ||
|
||
### `FixtureResult` | ||
|
||
#### - `hash`: [`Hash`](./common_types.md#hash) `| None` | ||
|
||
Calculated hash of the transaction (Field is missing if the transaction is expected to fail). | ||
|
||
#### - `intrinsicGas`: [`ZeroPaddedHexNumber`](./common_types.md#zeropaddedhexnumber) | ||
|
||
Total intrinsic gas cost of the transaction (Field is missing if the transaction is expected to fail). | ||
|
||
#### - `sender`: [`Address`](./common_types.md#address) | ||
|
||
Sender address of the transaction (Field is missing if the transaction is expected to fail). | ||
|
||
#### - `exception`: [`TransactionException`](./exceptions.md#transactionexception) | ||
|
||
Exception that is expected to be thrown by the transaction parsing (Field is missing if the transaction is expected to succeed). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
TransactionTest types | ||
""" | ||
|
||
from typing import ClassVar, Mapping | ||
|
||
from pydantic import Field | ||
|
||
from ethereum_test_base_types import Address, Bytes, Hash, ZeroPaddedHexNumber | ||
from ethereum_test_exceptions import TransactionExceptionInstanceOrList | ||
from ethereum_test_types.types import CamelModel | ||
|
||
from .base import BaseFixture | ||
|
||
|
||
class FixtureResult(CamelModel): | ||
""" | ||
The per-network (fork) result structure. | ||
""" | ||
|
||
hash: Hash | None = None | ||
intrinsic_gas: ZeroPaddedHexNumber | ||
sender: Address | None = None | ||
exception: TransactionExceptionInstanceOrList | None = None | ||
|
||
|
||
class Fixture(BaseFixture): | ||
""" | ||
Fixture for a single TransactionTest. | ||
""" | ||
|
||
fixture_format_name: ClassVar[str] = "transaction_test" | ||
description: ClassVar[str] = "Tests that generate a transaction test fixture." | ||
|
||
result: Mapping[str, FixtureResult] | ||
transaction: Bytes = Field(..., alias="txbytes") | ||
|
||
def get_fork(self) -> str | None: | ||
""" | ||
Returns the fork of the fixture as a string. | ||
""" | ||
forks = list(self.result.keys()) | ||
assert len(forks) == 1, "Expected transaction test fixture with single fork" | ||
return forks[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.