test_exchange_preserves_other_items()
Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_exchange.py::test_exchange_preserves_other_items@c74f1a67.
Generate fixtures for these test cases for Amsterdam with:
fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_exchange.py::test_exchange_preserves_other_items --fork Amsterdam
Test EXCHANGE only swaps specified items, leaving others unchanged.
Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_exchange.py
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209 | def test_exchange_preserves_other_items(
pre: Alloc,
state_test: StateTestFiller,
) -> None:
"""Test EXCHANGE only swaps specified items, leaving others unchanged."""
sender = pre.fund_eoa()
# Use n=1, m=5 - EXCHANGE swaps positions (n+1)=2 and (m+1)=6
n, m = 1, 5
# Create a stack with 6 distinct values
code = Bytecode()
code += Op.PUSH2(0x1111) # Position 6 from top (will be swapped)
code += Op.PUSH2(0x2222) # Position 5 from top
code += Op.PUSH2(0x3333) # Position 4 from top
code += Op.PUSH2(0x4444) # Position 3 from top
code += Op.PUSH2(0x5555) # Position 2 from top (will be swapped)
code += Op.PUSH2(0x6666) # Position 1 (top)
# EXCHANGE swaps position 2 with position 6
# Pass n and m directly - encoder will handle encoding
code += Op.EXCHANGE[n, m]
# Store all values
code += Op.PUSH1(0) + Op.SSTORE # Position 1 (0x6666, unchanged)
code += Op.PUSH1(1) + Op.SSTORE # Position 2 (was 0x1111, swapped from 6)
code += Op.PUSH1(2) + Op.SSTORE # Position 3 (0x4444, unchanged)
code += Op.PUSH1(3) + Op.SSTORE # Position 4 (0x3333, unchanged)
code += Op.PUSH1(4) + Op.SSTORE # Position 5 (0x2222, unchanged)
code += Op.PUSH1(5) + Op.SSTORE # Position 6 (was 0x5555, swapped from 2)
code += Op.STOP
contract_address = pre.deploy_contract(code=code)
tx = Transaction(to=contract_address, sender=sender)
post = {
contract_address: Account(
storage={
0: 0x6666, # Position 1 unchanged
1: 0x1111, # Was at position 6, now at position 2
2: 0x4444, # Position 3 unchanged
3: 0x3333, # Position 4 unchanged
4: 0x2222, # Position 5 unchanged
5: 0x5555, # Was at position 2, now at position 6
}
)
}
state_test(pre=pre, post=post, tx=tx)
|
Parametrized Test Cases
This test generates 1 parametrized test case across 1 fork.