Skip to content

Commit

Permalink
tests: Add EIP-1153 loop until out-of-gas tests (#401)
Browse files Browse the repository at this point in the history
* tests: 1153 out-of-gas cases

* changelog

* Update docs/CHANGELOG.md

Co-authored-by: danceratopz <[email protected]>

---------

Co-authored-by: danceratopz <[email protected]>
  • Loading branch information
marioevz and danceratopz authored Jan 25, 2024
1 parent ad35812 commit e2b84cc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Test fixtures for use by clients are available for each release on the [Github r
- 🐞 Fixed `tests/cancun/eip4844_blobs/test_blob_txs.py:test_insufficient_balance_blob_tx` to correctly calculate the minimum balance required for the accounts ([#379](https://github.com/ethereum/execution-spec-tests/pull/379)).
- ✨ Add `tests/cancun/eip4844_blobs/test_blob_txs.py::test_sufficient_balance_blob_tx` and `tests/cancun/eip4844_blobs/test_blob_txs.py::test_sufficient_balance_blob_tx_pre_fund_tx` ([#379](https://github.com/ethereum/execution-spec-tests/pull/379)).
- 🐞 Fix and enable `tests/cancun/eip4844_blobs/test_blob_txs.py::test_invalid_blob_tx_contract_creation` ([#379](https://github.com/ethereum/execution-spec-tests/pull/379)).
- ✨ Adds a callcode gas test when call stipend is applied to gas limit. Covers a bug found in the EthereumJS EVM. ([#371](https://github.com/ethereum/execution-spec-tests/pull/371)).
- ✨ Adds a callcode gas test when call stipend is applied to gas limit. Covers a bug found in the EthereumJS EVM. ([#371](https://github.com/ethereum/execution-spec-tests/pull/371))
-[EIP-1153](https://eips.ethereum.org/EIPS/eip-1153): Add `test_run_until_out_of_gas` for transient storage opcodes ([#401](https://github.com/ethereum/execution-spec-tests/pull/401)).

### 🛠️ Framework

Expand Down
49 changes: 49 additions & 0 deletions tests/cancun/eip1153_tstore/test_tstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,52 @@ def test_gas_usage(
TestAddress: Account(nonce=1),
}
state_test(env=env, pre=pre, tx=tx, post=post)


@unique
class LoopRunUntilOutOfGasCases(PytestParameterEnum):
"""
Test cases to run until out of gas.
"""

TSTORE = {
"description": "Run tstore in loop until out of gas",
"repeat_bytecode": Op.TSTORE(Op.GAS, Op.GAS),
"bytecode_repeat_times": 1000,
}
TSTORE_WIDE_ADDRESS_SPACE = {
"description": "Run tstore in loop until out of gas, using a wide address space",
"repeat_bytecode": Op.TSTORE(Op.ADD(Op.SHL(Op.PC, 1), Op.GAS), Op.GAS),
"bytecode_repeat_times": 32,
}
TSTORE_TLOAD = {
"description": "Run tstore and tload in loop until out of gas",
"repeat_bytecode": Op.GAS + Op.DUP1 + Op.DUP1 + Op.TSTORE + Op.TLOAD + Op.POP,
"bytecode_repeat_times": 1000,
}


@LoopRunUntilOutOfGasCases.parametrize()
def test_run_until_out_of_gas(
state_test: StateTestFiller,
repeat_bytecode: bytes,
bytecode_repeat_times: int,
):
"""
Use TSTORE over and over to different keys until we run out of gas.
"""
bytecode = Op.JUMPDEST + repeat_bytecode * bytecode_repeat_times + Op.JUMP(Op.PUSH0)
pre = {
TestAddress: Account(balance=10_000_000_000_000, nonce=0),
code_address: Account(code=bytecode),
}
tx = Transaction(
to=code_address,
data=b"",
gas_limit=30_000_000,
)
post = {
code_address: Account(code=bytecode, storage={}),
TestAddress: Account(nonce=1),
}
state_test(env=Environment(), pre=pre, tx=tx, post=post)

0 comments on commit e2b84cc

Please sign in to comment.