Skip to content

test_invalid_log_length()

Documentation for tests/prague/eip6110_deposits/test_modified_contract.py::test_invalid_log_length@v5.0.0.

Generate fixtures for these test cases for Osaka with:

fill -v tests/prague/eip6110_deposits/test_modified_contract.py::test_invalid_log_length --fork Osaka

Test deposit contract emitting logs with invalid log length (one byte more or less).

Source code in tests/prague/eip6110_deposits/test_modified_contract.py
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
@pytest.mark.parametrize(
    "slice_bytes",
    [
        pytest.param(
            True,
            marks=pytest.mark.pre_alloc_group(
                "deposit_log_length_short", reason="Deposit contract with shortened log data"
            ),
        ),
        pytest.param(
            False,
            marks=pytest.mark.pre_alloc_group(
                "deposit_log_length_long", reason="Deposit contract with lengthened log data"
            ),
        ),
    ],
)
@pytest.mark.exception_test
def test_invalid_log_length(blockchain_test: BlockchainTestFiller, pre: Alloc, slice_bytes: bool):
    """Test deposit contract emitting logs with invalid log length (one byte more or less)."""
    changed_log = DEFAULT_REQUEST_LOG[:-1] if slice_bytes else DEFAULT_REQUEST_LOG + b"\x00"

    bytecode = Om.MSTORE(changed_log) + Op.LOG1(
        0,
        len(changed_log),
        Spec.DEPOSIT_EVENT_SIGNATURE_HASH,
    )
    bytecode += Op.STOP

    pre[Spec.DEPOSIT_CONTRACT_ADDRESS] = Account(
        code=bytecode,
        nonce=1,
        balance=0,
    )
    sender = pre.fund_eoa()

    tx = Transaction(
        to=Spec.DEPOSIT_CONTRACT_ADDRESS,
        sender=sender,
        gas_limit=100_000,
    )

    blockchain_test(
        pre=pre,
        blocks=[
            Block(txs=[tx], exception=BlockException.INVALID_DEPOSIT_EVENT_LAYOUT),
        ],
        post={},
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) slice_bytes
...fork_Prague-blockchain_test-slice_bytes_True True
...fork_Prague-blockchain_test-slice_bytes_False False
...fork_Osaka-blockchain_test-slice_bytes_True True
...fork_Osaka-blockchain_test-slice_bytes_False False