Skip to content

feat(tests): MIP-4 and reserve balance tests#18

Merged
QEDK merged 3 commits intoforks/monad_ninefrom
mip4-add-test
Mar 20, 2026
Merged

feat(tests): MIP-4 and reserve balance tests#18
QEDK merged 3 commits intoforks/monad_ninefrom
mip4-add-test

Conversation

@pdobacz
Copy link
Collaborator

@pdobacz pdobacz commented Mar 18, 2026

A couple of gaps filled:

  1. Calling MIP-4 precompile as tx.to, with various reasons to fail, similar to how calling from EVM is tested
  2. A new multi block scenario for reserve balance rules (intertwining a credit of various shapes and values into a sequence of txs)

@pdobacz pdobacz requested review from QEDK and mijovic as code owners March 18, 2026 14:13
@greptile-apps
Copy link

greptile-apps bot commented Mar 18, 2026

Greptile Summary

This PR fills two testing gaps for Monad's execution specs: (1) direct-transaction (tx.to) calls to the MIP-4 checkReserveBalance precompile with various failure scenarios, mirroring the existing EVM-opcode call tests; and (2) a new multi-block test_credit_with_value scenario that interleaves value sends and credits of varying amounts/timing/delivery-methods into the reserve-balance test matrix.

Key changes:

  • helpers.py: Adds an opt-in status field to verify_transaction_receipt, which is used by the new tx-level precompile tests to assert success/failure of each transaction receipt.
  • test_precompile_call.py: Introduces _tx_params, test_tx_revert_scenarios, and test_tx_revert_scenario_pairs. NOT_CALL is correctly excluded (no opcodes at tx level), and a new LOW_GAS + EXTRA_CALLDATA incompatible pair is documented with the EIP-7623 floor explanation.
  • test_multi_block.py: Adds test_credit_with_value exercising send/credit position combinations across 4 blocks with both statically-visible (direct transfer) and non-statically-visible (SELFDESTRUCT) credit delivery. The 4-block design is intentional — it places block-0 sends outside the k=3 window, making the "emptying exception" reachable for undelegated senders. Balance accounting (initial_balance = RESERVE_BALANCE + send_value + prepare_tx_fee) and the violation/exception logic are internally consistent.

Confidence Score: 4/5

  • PR is safe to merge; all test logic is consistent with Monad's full-gas-charge model and only one minor style issue was found.
  • The balance arithmetic, violation/exception conditions, and incompatible-scenario sets were verified against the Monad gas model and the EIP-7623 floor. No logic errors found. A minor dead-code branch in the receipt status expression of test_tx_revert_scenario_pairs is the only note.
  • No files require special attention, though the minor style issue in test_precompile_call.py at line 892-896 is worth a quick look.

Important Files Changed

Filename Overview
packages/testing/src/execution_testing/specs/helpers.py Adds an optional status field check in verify_transaction_receipt, gated by is not None to preserve backwards compatibility. Straightforward and correct.
tests/monad_eight/reserve_balance/test_multi_block.py Adds test_credit_with_value — a new 4-block scenario exercising the reserve-balance credit path with parametrised send/credit positions, values, and credit delivery methods (direct vs SELFDESTRUCT). Balance accounting and violation/exception logic are internally consistent after the previously-addressed prepare_tx_gas fix.
tests/monad_nine/mip4_checkreservebalance/test_precompile_call.py Adds tx-level precompile-call tests (test_tx_revert_scenarios, test_tx_revert_scenario_pairs) mirroring the existing EVM-call tests. Correctly excludes NOT_CALL (opcode-only scenario), adds LOW_GAS+EXTRA_CALLDATA as a tx-incompatible pair, and leverages the new TransactionReceipt.status field for receipt assertions. A minor dead-code branch exists in test_tx_revert_scenario_pairs receipt status expression.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[tx to precompile] --> B{DELEGATE_TO_PRECOMPILE?}
    B -- Yes --> C[to = delegated EOA, priority-1 check]
    B -- No --> D[to = RESERVE_BALANCE_PRECOMPILE]
    C --> E[Derive gas_limit / calldata / value from scenarios]
    D --> E
    E --> F[sender funded: gas_limit x gas_price + value]
    F --> G[Execute tx - Monad charges full gas_limit]
    G --> H{Any scenario fails?}
    H -- Yes --> I[status=0, value not transferred, sender balance = value]
    H -- No, SUCCESS only --> J[status=1, value transferred, sender balance = value]
    I --> K[post: sender Account with balance=value]
    J --> K

    subgraph test_credit_with_value
    L[initial_balance = RESERVE_BALANCE + send_value + prepare_tx_fee] --> M[blocks 0-2: setup txs + optional credit]
    M --> N[balance at test tx = RESERVE_BALANCE + credit_value]
    N --> O{credit_value less than 1?}
    O -- Yes, violation=True --> P{is_exception? not pre_delegated AND send outside k=3 window}
    P -- Yes --> Q[tx succeeds]
    P -- No --> R[tx reverts]
    O -- No, violation=False --> Q
    end
Loading

Last reviewed commit: "feat(tests): test_cr..."

Co-Authored-By: Claude claude-opus-4-6
@pdobacz
Copy link
Collaborator Author

pdobacz commented Mar 19, 2026

@greptileai re review

Copy link
Member

@QEDK QEDK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@QEDK QEDK merged commit 38c4211 into forks/monad_nine Mar 20, 2026
5 checks passed
@QEDK QEDK deleted the mip4-add-test branch March 20, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants