Skip to content

test(fees): cover allocation tree emit trap gates#309

Open
dohernandez wants to merge 1 commit into
mainfrom
test/message-fee-allocation-emission
Open

test(fees): cover allocation tree emit trap gates#309
dohernandez wants to merge 1 commit into
mainfrom
test/message-fee-allocation-emission

Conversation

@dohernandez

@dohernandez dohernandez commented Jun 7, 2026

Copy link
Copy Markdown
Member

Description

Adds four intercontract integration cases pinning genvm's behavior when the node-provided message-fee-allocation tree cannot fund an emitted message. genvm is a pure consumer of this tree (executor/src/wasi/genlayer_sdk.rs); when no matching node exists or its budget is too small, an emit must hard-trap, never silently produce zero emissions.

These guard the genvm side of a cross-repo issue where an empty allocation tree (the node's DisallowedFeeAllocation([]) fallback, returned when the deployed consensus provisioned nothing) led to zero internal messages while the parent still finalized. Root cause is consensus/node; this locks genvm so a silent-zero cannot regress here.

Tests

  • alloc_empty_post_message — empty tree, PostMessage emit must trap (OOM fees internal)
  • alloc_empty_deploy — empty tree, DeployContract emit must trap
  • alloc_empty_eth_send — empty tree, external EthSend must trap (OOM fees external); the balance check passes first, so the trap comes from the allocation lookup
  • alloc_budget_exhausted — a matching wildcard node but budget below the computed message fee, must trap on the budget gate

The positive direction (populated wildcard tree -> emission succeeds) is already covered by the existing send_message / deploy / send_message_eth cases.

Golden files

The .stdout / .hash expected files are intentionally not included. The runner auto-blesses them on first run, but the nix test shell only instantiates on Linux (it pulls glibc), so they must be generated on Linux/CI. Run the four alloc_* cases once on Linux and commit the blessed goldens.

Test-only change; no runtime behavior change.

Summary by CodeRabbit

  • Tests
    • Added comprehensive regression test cases covering message fee allocation scenarios, including budget exhaustion, empty allocations for deployments, external ETH transfers, and internal post-message operations.

Add intercontract cases asserting that an empty or under-budget
message-fee-allocation tree makes emit hard-trap instead of silently
emitting nothing. Golden stdout/hash files are produced on Linux CI;
the nix test shell does not instantiate on macOS.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds four regression test scenarios covering message fee allocation failure modes. The tests verify that genvm hard-traps (rather than silently emitting) when budget is exhausted or when allocation trees are empty across internal messaging, deployment, external ETH send, and post-message emission paths.

Changes

Intercontract Fee Allocation Regression Tests

Layer / File(s) Summary
Budget exhaustion scenario
tests/cases/stable/py/intercontract/alloc_budget_exhausted.jsonnet, alloc_budget_exhausted.py
Jsonnet configuration and Python contract test that exercise hard-trap when an internal finalized allocation node's budget: 1 is insufficient to cover the computed message fee cost.
Empty allocation tree scenarios
tests/cases/stable/py/intercontract/alloc_empty_deploy.jsonnet, alloc_empty_deploy.py, alloc_empty_eth_send.jsonnet, alloc_empty_eth_send.py, alloc_empty_post_message.jsonnet, alloc_empty_post_message.py
Three test pairs verifying hard-trap behavior when message-fee-allocation is an empty array, preventing allocation node lookup for: deploy contract emission (address zero), external ETH send (emit(...).test(...)), and internal post-message chaining (.foo(1, 2)). Each pair includes a Jsonnet configuration passing empty allocation and a Python contract that triggers the respective emission path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Hoppy tests now guard the fee allocations bright,
When budgets run low or the trees take flight,
Hard-traps shall spring, no silent emission,
Four scenarios tested with bunny precision! 🎯

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding test cases that verify hard-trap behavior when allocation tree gates are triggered during message emission.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/message-fee-allocation-emission

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/cases/stable/py/intercontract/alloc_budget_exhausted.py`:
- Line 3: The file currently uses a wildcard import ("from genlayer.types import
*") which triggers Ruff F403; replace it with explicit imports of only the
symbols used in this test (inspect the file for identifiers from genlayer.types
and import them directly, e.g. "from genlayer.types import SymbolA, SymbolB"
replacing SymbolA/SymbolB with the actual names), ensuring no unused names
remain so lint passes; keep the import statement on the same line where "from
genlayer.types import *" appears and remove the wildcard.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 25e9d63d-41c7-427a-a9d7-31c447431c39

📥 Commits

Reviewing files that changed from the base of the PR and between 99c0211 and bc135e8.

📒 Files selected for processing (8)
  • tests/cases/stable/py/intercontract/alloc_budget_exhausted.jsonnet
  • tests/cases/stable/py/intercontract/alloc_budget_exhausted.py
  • tests/cases/stable/py/intercontract/alloc_empty_deploy.jsonnet
  • tests/cases/stable/py/intercontract/alloc_empty_deploy.py
  • tests/cases/stable/py/intercontract/alloc_empty_eth_send.jsonnet
  • tests/cases/stable/py/intercontract/alloc_empty_eth_send.py
  • tests/cases/stable/py/intercontract/alloc_empty_post_message.jsonnet
  • tests/cases/stable/py/intercontract/alloc_empty_post_message.py

@@ -0,0 +1,16 @@
# { "Depends": "py-genlayer:test" }
import genlayer as gl
from genlayer.types import *

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Replace wildcard import to satisfy Ruff F403.

Line 3 uses from genlayer.types import *, which Ruff flags and can fail lint-gated CI. Import only referenced symbols explicitly.

Suggested fix
-from genlayer.types import *
+from genlayer.types import Address
🧰 Tools
🪛 Ruff (0.15.15)

[error] 3-3: from genlayer.types import * used; unable to detect undefined names

(F403)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/cases/stable/py/intercontract/alloc_budget_exhausted.py` at line 3, The
file currently uses a wildcard import ("from genlayer.types import *") which
triggers Ruff F403; replace it with explicit imports of only the symbols used in
this test (inspect the file for identifiers from genlayer.types and import them
directly, e.g. "from genlayer.types import SymbolA, SymbolB" replacing
SymbolA/SymbolB with the actual names), ensuring no unused names remain so lint
passes; keep the import statement on the same line where "from genlayer.types
import *" appears and remove the wildcard.

Source: Linters/SAST tools

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.

2 participants