test_clz_code_copy_operation()
Documentation for tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py::test_clz_code_copy_operation@892e6d1e.
Generate fixtures for these test cases for Amsterdam with:
fill -v tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py::test_clz_code_copy_operation --fork Amsterdam
Test CLZ opcode with code copy operation.
Source code in tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528 | @pytest.mark.valid_from("Osaka")
@pytest.mark.parametrize("bits", [0, 64, 255])
@pytest.mark.parametrize("opcode", [Op.CODECOPY, Op.EXTCODECOPY])
def test_clz_code_copy_operation(
state_test: StateTestFiller, pre: Alloc, bits: int, opcode: Op
) -> None:
"""Test CLZ opcode with code copy operation."""
storage = Storage()
expected_value = 255 - bits
clz_code_offset = len(Op.CLZ(1 << bits)) - 1 # Offset to CLZ opcode
mload_value = Spec.CLZ << 248 # CLZ opcode in MSB position (0x1E000...000)
target_address = pre.deploy_contract(code=Op.CLZ(1 << bits))
clz_contract_address = pre.deploy_contract(
code=(
Op.CLZ(1 << bits) # Calculate CLZ of the value
+ Op.SSTORE(
storage.store_next(expected_value), Op.CLZ(1 << bits)
) # Store CLZ result
+ ( # Load CLZ byte from code with CODECOPY or EXTCODECOPY
Op.CODECOPY(dest_offset=0, offset=clz_code_offset, size=1)
if opcode == Op.CODECOPY
else Op.EXTCODECOPY(
address=target_address,
dest_offset=0,
offset=clz_code_offset,
size=1,
)
)
# Store loaded CLZ byte
+ Op.SSTORE(storage.store_next(mload_value), Op.MLOAD(0))
),
storage={"0x00": "0xdeadbeef"},
)
post = {
clz_contract_address: Account(
storage={
"0x00": expected_value,
"0x01": mload_value,
}
)
}
tx = Transaction(
to=clz_contract_address,
sender=pre.fund_eoa(),
gas_limit=200_000,
)
state_test(pre=pre, post=post, tx=tx)
|
Parametrized Test Cases
This test generates 6 parametrized test cases across 2 forks.