|
1 | 1 | import pytest
|
2 | 2 |
|
| 3 | +from itertools import chain |
3 | 4 | from typing import Optional
|
4 | 5 | from ethereum_test_tools import BlockchainTestFiller, Transaction, Account, TestAddress
|
5 | 6 | from ethereum_test_tools.vm.opcode import Opcodes as Op
|
|
32 | 33 | [True, False],
|
33 | 34 | )
|
34 | 35 | def test_modified_contract(
|
35 |
| - blockchain_test: BlockchainTestFiller, |
36 |
| - storage_slot_write: int, |
37 |
| - tx_send_value: bool, |
| 36 | + blockchain_test: BlockchainTestFiller, storage_slot_write: int, tx_send_value: bool |
38 | 37 | ):
|
39 | 38 | """
|
40 | 39 | Test converting a modified contract where a previous transaction writes to:
|
@@ -99,4 +98,76 @@ def _convert_modified_account(
|
99 | 98 | gas_price=10,
|
100 | 99 | )
|
101 | 100 |
|
102 |
| - _state_conversion(blockchain_test, pre_state, stride, 1, [ConversionTx(tx, 0)]) |
| 101 | + _state_conversion(blockchain_test, pre_state, stride, 2, [ConversionTx(tx, 0)]) |
| 102 | + |
| 103 | + |
| 104 | +@pytest.mark.valid_from("EIP6800Transition") |
| 105 | +def test_modified_eoa_conversion_units(blockchain_test: BlockchainTestFiller): |
| 106 | + """ |
| 107 | + Test stale EOA are properly counted as used conversion units. |
| 108 | + """ |
| 109 | + pre_state = {} |
| 110 | + pre_state[TestAddress] = Account(balance=1000000000000000000000) |
| 111 | + |
| 112 | + # TODO(hack): today the testing-framework does not support us signaling that we want to |
| 113 | + # put the `ConversionTx(tx, **0**)` at the first block after genesis. To simulate that, we have |
| 114 | + # to do this here so we "shift" the target account to the second block in the fork. |
| 115 | + # If this is ever supported, remove this. |
| 116 | + for i in range(stride): |
| 117 | + pre_state[accounts[i]] = Account(balance=100 + 1000 * i) |
| 118 | + |
| 119 | + txs = [] |
| 120 | + for i in range(stride + 3): |
| 121 | + pre_state[accounts[stride + i]] = Account(balance=1_000, nonce=0) |
| 122 | + if i < stride: |
| 123 | + tx = Transaction( |
| 124 | + ty=0x0, |
| 125 | + chain_id=0x01, |
| 126 | + nonce=i, |
| 127 | + to=accounts[stride + i], |
| 128 | + value=100, |
| 129 | + gas_limit=100_000, |
| 130 | + gas_price=10, |
| 131 | + ) |
| 132 | + txs.append(ConversionTx(tx, 0)) |
| 133 | + |
| 134 | + _state_conversion(blockchain_test, pre_state, stride, 3, txs) |
| 135 | + |
| 136 | + |
| 137 | +@pytest.mark.valid_from("EIP6800Transition") |
| 138 | +def test_modified_contract_conversion_units(blockchain_test: BlockchainTestFiller): |
| 139 | + """ |
| 140 | + Test stale contract storage slots are properly counted as used conversion units. |
| 141 | + """ |
| 142 | + pre_state = {} |
| 143 | + pre_state[TestAddress] = Account(balance=1000000000000000000000) |
| 144 | + |
| 145 | + # TODO(hack): today the testing-framework does not support us signaling that we want to |
| 146 | + # put the `ConversionTx(tx, **0**)` at the first block after genesis. To simulate that, we have |
| 147 | + # to do this here so we "shift" the target account to the second block in the fork. |
| 148 | + # If this is ever supported, remove this. |
| 149 | + for i in range(stride): |
| 150 | + pre_state[accounts[i]] = Account(balance=100 + 1000 * i) |
| 151 | + |
| 152 | + target_account = accounts[stride] |
| 153 | + pre_state[target_account] = Account( |
| 154 | + balance=1_000, |
| 155 | + nonce=0, |
| 156 | + code=sum([Op.SSTORE(ss, 10_000 + i) for i, ss in enumerate(range(stride))]), |
| 157 | + storage={ss: 100 + i for i, ss in enumerate(range(stride))}, |
| 158 | + ) |
| 159 | + for i in range(3): |
| 160 | + pre_state[accounts[stride + 1 + i]] = Account(balance=1_000 + i, nonce=0) |
| 161 | + |
| 162 | + # Send tx that writes all existing storage slots. |
| 163 | + tx = Transaction( |
| 164 | + ty=0x0, |
| 165 | + chain_id=0x01, |
| 166 | + nonce=0, |
| 167 | + to=target_account, |
| 168 | + value=100, |
| 169 | + gas_limit=100_000, |
| 170 | + gas_price=10, |
| 171 | + ) |
| 172 | + |
| 173 | + _state_conversion(blockchain_test, pre_state, stride, 3, [ConversionTx(tx, 0)]) |
0 commit comments