Skip to content

Commit

Permalink
new(tests): EIP-7702: Add many-delegations test (#923)
Browse files Browse the repository at this point in the history
* new(tests): EIP-7702: many delegations test

* changelog

* fix(tests): skip test on execute

* fix(tests): reduce gas on execute version
  • Loading branch information
marioevz authored Oct 31, 2024
1 parent ff96593 commit 83de6e1
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Test fixtures for use by clients are available for each release on the [Github r
- ✨ Update [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) tests for Devnet-3 ([#733](https://github.com/ethereum/execution-spec-tests/pull/733))
- 🐞 Fix [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702)+EOF tests due to incorrect test expectations and faulty `Conditional` test generator in EOF mode ([#821](https://github.com/ethereum/execution-spec-tests/pull/821))
- 💥 `PragueEIP7692` fork in tests has been updated to `Osaka` ([#869](https://github.com/ethereum/execution-spec-tests/pull/869))
- ✨ Update [EIP-6110](https://eips.ethereum.org/EIPS/eip-6110), [EIP-7002](https://eips.ethereum.org/EIPS/eip-7002), [EIP-7251](https://eips.ethereum.org/EIPS/eip-7251), [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685), and [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) tests for Devnet-4 ([#832](https://github.com/ethereum/execution-spec-tests/pull/832))
-[EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) many delegations test ([#923](https://github.com/ethereum/execution-spec-tests/pull/923))

### 🛠️ Framework

Expand Down
82 changes: 82 additions & 0 deletions tests/prague/eip7702_set_code_tx/test_set_code_txs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3187,3 +3187,85 @@ def test_deploying_delegation_designation_contract(
tx.created_contract: Account.NONEXISTENT,
},
)


@pytest.mark.parametrize(
"signer_balance",
[
pytest.param(0, id="empty_balance"),
pytest.param(
1,
id="non_empty_balance",
marks=pytest.mark.execute(pytest.mark.skip(reason="excessive pre-fund txs")),
),
],
)
@pytest.mark.parametrize(
"max_gas",
[
pytest.param(
120_000_000,
id="120m",
marks=pytest.mark.execute(pytest.mark.skip(reason="excessive gas")),
),
pytest.param(
20_000_000,
id="20m",
marks=pytest.mark.fill(pytest.mark.skip(reason="execute-only test")),
),
],
)
def test_many_delegations(
state_test: StateTestFiller,
pre: Alloc,
max_gas: int,
signer_balance: int,
):
"""
Perform as many delegations as possible in a single 120 million gas transaction.
Every delegation comes from a different signer.
The account of can be empty or not depending on the `signer_balance` parameter.
The transaction is expected to succeed and the state after the transaction is expected to have
the code of the entry contract set to 1.
"""
gas_for_delegations = max_gas - 21_000 - 20_000 - (3 * 2)

delegation_count = gas_for_delegations // Spec.PER_EMPTY_ACCOUNT_COST

success_slot = 1
entry_code = Op.SSTORE(success_slot, 1) + Op.STOP
entry_address = pre.deploy_contract(entry_code)

signers = [pre.fund_eoa(signer_balance) for _ in range(delegation_count)]

tx = Transaction(
gas_limit=max_gas,
to=entry_address,
value=0,
authorization_list=[
AuthorizationTuple(
address=Address(i + 1),
nonce=0,
signer=signer,
)
for (i, signer) in enumerate(signers)
],
sender=pre.fund_eoa(),
)

post = {entry_address: Account(storage={success_slot: 1},),} | {
signer: Account(
code=Spec.delegation_designation(Address(i + 1)),
)
for (i, signer) in enumerate(signers)
}

state_test(
env=Environment(),
pre=pre,
tx=tx,
post=post,
)

0 comments on commit 83de6e1

Please sign in to comment.