Skip to content

test_ether_transfers_onchain_receivers()

Documentation for tests/benchmark/stateful/bloatnet/test_transaction_types.py::test_ether_transfers_onchain_receivers@2119b382.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/stateful/bloatnet/test_transaction_types.py::test_ether_transfers_onchain_receivers --gas-benchmark-values 1

Ether transfers to receivers that exist on-chain at run time.

Scenarios: - diff_to_nonexistent: distinct nonexistent receivers (matches AccountMode.NON_EXISTING_ACCOUNT) - diff_to_existent: distinct existent EOA receivers (matches AccountMode.EXISTING_EOA) - diff_to_contract: distinct contract receivers (matches AccountMode.EXISTING_CONTRACT) - diff_to_unique_code_jumpdest_contract: distinct CREATE2 contract receivers each holding unique deployed code

Source code in tests/benchmark/stateful/bloatnet/test_transaction_types.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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
@pytest.mark.repricing
@pytest.mark.parametrize(
    "case_id",
    [
        "diff_to_nonexistent",
        "diff_to_existent",
        "diff_to_contract",
        "diff_to_unique_code_jumpdest_contract",
    ],
)
@pytest.mark.parametrize("transfer_amount", [0, 1])
def test_ether_transfers_onchain_receivers(
    benchmark_test: BenchmarkTestFiller,
    pre: Alloc,
    case_id: str,
    transfer_amount: int,
    fork: Fork,
    gas_benchmark_value: int,
) -> None:
    """
    Ether transfers to receivers that exist on-chain at run time.

    Scenarios:
    - diff_to_nonexistent: distinct nonexistent receivers
      (matches AccountMode.NON_EXISTING_ACCOUNT)
    - diff_to_existent: distinct existent EOA receivers
      (matches AccountMode.EXISTING_EOA)
    - diff_to_contract: distinct contract receivers
      (matches AccountMode.EXISTING_CONTRACT)
    - diff_to_unique_code_jumpdest_contract: distinct CREATE2 contract
      receivers each holding unique deployed code
    """
    senders = yield_distinct_sender()
    receiver_execution_gas = 0
    if case_id == "diff_to_nonexistent":
        receivers = yield_distinct_nonexistent_receiver()
    elif case_id == "diff_to_existent":
        receivers = yield_distinct_existent_receiver()
    elif case_id == "diff_to_contract":
        receivers = yield_distinct_contract_receiver()
        # Runtime code is the same across all the receivers
        # Example contract: https://etherscan.io/address/0xa888df3ef62286dde06a79395760b9bce6c83c83#code
        runtime = (
            Op.MSTORE(0x40, 0x60, new_memory_size=0x60)
            + Op.JUMPI(Op.PUSH2(0x49), Op.ISZERO(Op.CALLDATASIZE))
            + Op.JUMPDEST * 3
            + Op.JUMP(Op.PUSH2(0x50))
            + Op.JUMPDEST
        )
        receiver_execution_gas = runtime.gas_cost(fork)
    elif case_id == "diff_to_unique_code_jumpdest_contract":
        receivers = yield_distinct_unique_code_jumpdest_receiver()
        # Runtime code aligns entry code path.
        runtime = Op.JUMP(Op.PUSH2(0x5FFF)) + Op.JUMPDEST
        receiver_execution_gas = runtime.gas_cost(fork)
    else:
        raise ValueError(f"Unknown case: {case_id}")

    iteration_cost = (
        fork.transaction_intrinsic_cost_calculator()() + receiver_execution_gas
    )
    iteration_count = gas_benchmark_value // iteration_cost

    txs = [
        Transaction(
            to=next(receivers),
            value=transfer_amount,
            gas_limit=iteration_cost,
            sender=next(senders),
        )
        for _ in range(iteration_count)
    ]

    benchmark_test(
        pre=pre,
        post={},
        blocks=[Block(txs=txs)],
        expected_benchmark_gas_used=iteration_count * iteration_cost,
        expected_receipt_status=1,
    )

Parametrized Test Cases

This test generates 8 parametrized test cases across 3 forks.