624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732 | @pytest.mark.parametrize(
"test_case",
list(ZeroAmountTestCases),
ids=[case.value for case in ZeroAmountTestCases],
)
@pytest.mark.eels_base_coverage
def test_zero_amount(
blockchain_test: BlockchainTestFiller,
pre: Alloc,
test_case: ZeroAmountTestCases,
) -> None:
"""
Test withdrawal scenarios with a zero amount in a single block.
All the withdrawals in the following scenarios are included in one block.
1. Two withdrawals of zero amount to two different addresses; one to an
untouched account, one to an account with a balance.
2. As 1., but with an additional withdrawal with positive value.
3. As 2., but with an additional withdrawal containing the maximum value
possible.
4. As 3., but with order of withdrawals in the block reversed.
"""
empty_accounts = [pre.fund_eoa(0) for _ in range(3)]
zero_balance_contract = pre.deploy_contract(Op.STOP)
all_withdrawals = [
# No value, untouched account
Withdrawal(
index=0,
validator_index=0,
address=empty_accounts[0],
amount=0,
),
# No value, touched account
Withdrawal(
index=0,
validator_index=0,
address=zero_balance_contract,
amount=0,
),
# Withdrawal with value
Withdrawal(
index=1,
validator_index=0,
address=empty_accounts[1],
amount=1,
),
# Withdrawal with maximum amount
Withdrawal(
index=2,
validator_index=0,
address=empty_accounts[2],
amount=2**64 - 1,
),
]
all_post = {
empty_accounts[0]: Account.NONEXISTENT,
zero_balance_contract: Account(code=Op.STOP, balance=0),
empty_accounts[1]: Account(balance=ONE_GWEI),
empty_accounts[2]: Account(balance=(2**64 - 1) * ONE_GWEI),
}
withdrawals: List[Withdrawal] = []
post: Mapping[Address, Account | object] = {}
if test_case == ZeroAmountTestCases.TWO_ZERO:
withdrawals = all_withdrawals[0:2]
post = {
account: all_post[account]
for account in post
if account in [empty_accounts[0], zero_balance_contract]
}
elif test_case == ZeroAmountTestCases.THREE_ONE_WITH_VALUE:
withdrawals = all_withdrawals[0:3]
post = {
account: all_post[account]
for account in post
if account
in [
empty_accounts[0],
zero_balance_contract,
empty_accounts[1],
]
}
elif test_case == ZeroAmountTestCases.FOUR_ONE_WITH_MAX:
withdrawals = all_withdrawals
post = all_post
elif test_case == ZeroAmountTestCases.FOUR_ONE_WITH_MAX_REVERSED:
for i, w in enumerate(reversed(all_withdrawals)):
withdrawals.append(
Withdrawal(
index=i,
validator_index=w.validator_index,
address=w.address,
amount=w.amount,
)
)
post = all_post
blockchain_test(
pre=pre,
# TODO: Fix in BlockchainTest? post: Mapping[str, Account | object]
# to allow for Account.NONEXISTENT
post=post,
blocks=[Block(withdrawals=withdrawals)],
)
|