|
7 | 7 |
|
8 | 8 | import pytest |
9 | 9 | import math |
| 10 | +from typing import Optional |
10 | 11 |
|
11 | 12 | from ethereum_test_tools import ( |
12 | 13 | Account, |
@@ -97,50 +98,70 @@ def test_non_partial( |
97 | 98 |
|
98 | 99 | @pytest.mark.valid_from("EIP6800Transition") |
99 | 100 | @pytest.mark.parametrize( |
100 | | - "account_configs", |
| 101 | + "storage_slots_overlow", |
| 102 | + [ |
| 103 | + 2, |
| 104 | + 1, |
| 105 | + 0, |
| 106 | + ], |
| 107 | + ids=[ |
| 108 | + "Two storage slots overflowed to next block", |
| 109 | + "One storage slot overflowed to next block", |
| 110 | + "Storage slots fit in one block", |
| 111 | + ], |
| 112 | +) |
| 113 | +@pytest.mark.parametrize( |
| 114 | + "account_prefix", |
101 | 115 | [ |
102 | | - # No prefix |
103 | | - [AccountConfig(31 * 2 + 1, stride + 2)], |
104 | | - [AccountConfig(31 * 2 + 1, stride + 1)], |
105 | | - [AccountConfig(31 + 2 + 1, stride)], |
106 | | - # EOA prefix |
107 | | - [AccountConfig(0, 0), AccountConfig(42, -1 + stride + 2)], |
108 | | - [AccountConfig(0, 0), AccountConfig(42, -1 + stride + 1)], |
109 | | - [AccountConfig(0, 0), AccountConfig(42, -1 + stride)], |
110 | | - # Contract prefix |
111 | | - [AccountConfig(10, 1), AccountConfig(42, -3 + stride + 2)], |
112 | | - [AccountConfig(10, 1), AccountConfig(42, -3 + stride + 1)], |
113 | | - [AccountConfig(10, 1), AccountConfig(42, -3 + stride)], |
| 116 | + None, |
| 117 | + AccountConfig(0, 0), |
| 118 | + AccountConfig(10, 1), |
114 | 119 | ], |
115 | 120 | ids=[ |
116 | | - "No prefix & boundary at two storage slots before finishing storage trie", |
117 | | - "No prefix & boundary at one storage slot before finishing storage trie", |
118 | | - "No prefix & boundary matching exactly the end of the storage trie", |
119 | | - "EOA prefix & boundary at two storage slots before finishing storage trie", |
120 | | - "EOA prefix & boundary at one storage slot before finishing storage trie", |
121 | | - "EOA prefix & boundary matching exactly the end of the storage trie", |
122 | | - "Contract prefix & boundary at two storage slots before finishing storage trie", |
123 | | - "Contract prefix & boundary at one storage slot before finishing storage trie", |
124 | | - "Contract prefix & boundary matching exactly the end of the storage trie", |
| 121 | + "No prefix", |
| 122 | + "EOA prefix", |
| 123 | + "Contract prefix", |
125 | 124 | ], |
126 | 125 | ) |
| 126 | +@pytest.mark.parametrize( |
| 127 | + "empty_code", |
| 128 | + [True, False], |
| 129 | +) |
127 | 130 | @pytest.mark.parametrize( |
128 | 131 | "fill_first_block", |
129 | | - [False, True], |
| 132 | + [True, False], |
130 | 133 | ) |
131 | 134 | @pytest.mark.parametrize( |
132 | 135 | "fill_last_block", |
133 | | - [False, True], |
| 136 | + [True, False], |
134 | 137 | ) |
135 | 138 | def test_partial( |
136 | 139 | blockchain_test: BlockchainTestFiller, |
137 | | - account_configs: list[AccountConfig], |
| 140 | + storage_slots_overlow: int, |
| 141 | + account_prefix: Optional[AccountConfig], |
| 142 | + empty_code: bool, |
138 | 143 | fill_first_block: bool, |
139 | 144 | fill_last_block: bool, |
140 | 145 | ): |
141 | 146 | """ |
142 | 147 | Test partial account conversions. |
143 | 148 | """ |
| 149 | + conversion_unit_offset = 0 |
| 150 | + account_configs = [] |
| 151 | + if account_prefix is not None: |
| 152 | + conversion_unit_offset += 1 # Account basic data |
| 153 | + conversion_unit_offset += math.ceil(account_prefix.code_length / 31) # Code-chunks |
| 154 | + conversion_unit_offset += account_prefix.storage_slots_count |
| 155 | + account_configs.append(account_prefix) |
| 156 | + |
| 157 | + code_length = 0 if empty_code else 31 |
| 158 | + # For the `stride` quota in this block, we already used `conversion_unit_offset` units from the accounts prefixes. |
| 159 | + # For the remaining quota (i.e., `stride-conversion_unit_offset`), we should configure the contract having |
| 160 | + # `(stride - conversion_unit_offset)+storage_slots_overlow` so we can overflow the desired storage slots to the |
| 161 | + # next block. |
| 162 | + num_storage_slots = stride - conversion_unit_offset + storage_slots_overlow |
| 163 | + account_configs.append(AccountConfig(code_length, num_storage_slots)) |
| 164 | + |
144 | 165 | _generic_conversion(blockchain_test, account_configs, fill_first_block, fill_last_block) |
145 | 166 |
|
146 | 167 |
|
|
0 commit comments