Skip to content

test_authorization_reusing_nonce()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_authorization_reusing_nonce@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_authorization_reusing_nonce --fork Amsterdam

Test an authorization reusing the same nonce as a prior transaction included in the same block.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
def test_authorization_reusing_nonce(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test an authorization reusing the same nonce as a prior transaction
    included in the same block.
    """
    auth_signer = pre.fund_eoa()
    sender = pre.fund_eoa()
    recipient = pre.fund_eoa(amount=0)

    intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator()
    # Tx1: value transfer to an empty recipient -- pays the intrinsic
    # value-transfer surcharges plus the top-frame ``NEW_ACCOUNT``
    # state-gas charge.
    tx1_intrinsic = intrinsic_gas_calculator(
        recipient_type=RecipientType.EMPTY_ACCOUNT,
        sends_value=True,
    )
    tx1_top_frame_state = fork.transaction_top_frame_state_gas(
        recipient_type=RecipientType.EMPTY_ACCOUNT,
        sends_value=True,
    )
    tx1_gas = tx1_intrinsic + tx1_top_frame_state

    # Tx2: recipient is now alive (received 1 wei in tx1), so the
    # recipient is an EOA and no top-frame charge fires. The auth
    # list adds one ``AUTH_PER_EMPTY_ACCOUNT`` to intrinsic.
    tx2_gas = intrinsic_gas_calculator(
        recipient_type=RecipientType.EOA,
        authorization_list_or_count=1,
    )

    txs = [
        Transaction(
            sender=auth_signer,
            nonce=0,
            gas_limit=tx1_gas,
            to=recipient,
            value=1,
        ),
        Transaction(
            sender=sender,
            to=recipient,
            value=0,
            gas_limit=tx2_gas,
            authorization_list=[
                AuthorizationTuple(
                    address=Address(1),
                    nonce=0,
                    signer=auth_signer,
                ),
            ],
        ),
    ]

    blockchain_test(
        pre=pre,
        blocks=[Block(txs=txs)],
        post={
            recipient: Account(balance=1),
            auth_signer: Account(nonce=1, code=b""),
            sender: Account(nonce=1),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 3 forks.