This repository was archived by the owner on Jul 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
test(fees): cover allocation tree emit trap gates #309
Open
dohernandez
wants to merge
1
commit into
main
Choose a base branch
from
test/message-fee-allocation-emission
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
tests/cases/stable/py/intercontract/alloc_budget_exhausted.jsonnet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| local simple_deploy = import 'templates/simple_deploy.jsonnet'; | ||
| local util = import 'templates/util.jsonnet'; | ||
| // A matching wildcard internal-finalized node, but budget=1 (< the computed | ||
| // message_fee, which is ~34836 for foo(1,2) on finalized). The find_map matches, | ||
| // then consume_message_fee_internal must trap on `fee_cost > node.budget`. | ||
| // Mirrors origin/fees.py DEFAULT_INTERNAL_FIN_MESSAGE_ALLOC with budget lowered. | ||
| {entry: util.addPaths([simple_deploy.run('${jsonnetDir}/${fileBaseName}.py') { | ||
| message_fee_allocation: [ | ||
| { | ||
| budget: 1, | ||
| recipient: null, | ||
| call_key: null, | ||
| on: 'finalized', | ||
| fee_params: { | ||
| Internal: { | ||
| execution_budget_per_round: 1024, | ||
| rotations: [4, 4, 4, 4, 4], | ||
| leader_timeunits_allocation: 5, | ||
| validator_timeunits_allocation: 5, | ||
| }, | ||
| }, | ||
| children: [], | ||
| }, | ||
| ], | ||
| }])} |
16 changes: 16 additions & 0 deletions
16
tests/cases/stable/py/intercontract/alloc_budget_exhausted.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # { "Depends": "py-genlayer:test" } | ||
| import genlayer as gl | ||
| from genlayer.types import * | ||
|
|
||
|
|
||
| # Regression guard (genvm fee-allocation item #8): node MATCHES but its budget is | ||
| # too small. | ||
| # | ||
| # Here the allocation tree has a matching wildcard internal-finalized node, so the | ||
| # find_map succeeds, but its `budget` is below the computed message_fee. genvm must | ||
| # hard-trap in consume_message_fee_internal ("message fee cost exceeds node budget" | ||
| # -> oom_trap fees().internal()), never silently emit. This pins the second trap | ||
| # gate (budget), distinct from the no-matching-node gate. | ||
| class Contract(gl.contract.Contract): | ||
| def __init__(self): | ||
| gl.contract.get_at(gl.Address(b'\x30' * 20)).emit().foo(1, 2) | ||
7 changes: 7 additions & 0 deletions
7
tests/cases/stable/py/intercontract/alloc_empty_deploy.jsonnet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| local simple_deploy = import 'templates/simple_deploy.jsonnet'; | ||
| local util = import 'templates/util.jsonnet'; | ||
| // Empty allocation tree => the DeployContract emit (matched by Address::zero() + | ||
| // CallKey::DEPLOY) has no node and must hard-trap (OOM fees internal). | ||
| {entry: util.addPaths([simple_deploy.run('${jsonnetDir}/${fileBaseName}.py') { | ||
| message_fee_allocation: [], | ||
| }])} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # { "Depends": "py-genlayer:test" } | ||
| import genlayer as gl | ||
| from genlayer.types import * | ||
|
|
||
|
|
||
| # Regression guard (genvm fee-allocation item #8): DeployContract variant. | ||
| # | ||
| # An empty message-fee-allocation tree must make a deploy emission hard-trap | ||
| # (genlayer_sdk.rs DeployContract path: no matching node -> oom_trap fees().internal()), | ||
| # never silently emit nothing. | ||
| # | ||
| # Paired positive case: ../intercontract/deploy.py (default tree -> DeployContract | ||
| # emission succeeds). | ||
| class Contract(gl.contract.Contract): | ||
| def __init__(self): | ||
| gl.contract.deploy(code='not really a contract'.encode('utf-8')) |
7 changes: 7 additions & 0 deletions
7
tests/cases/stable/py/intercontract/alloc_empty_eth_send.jsonnet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| local simple_deploy = import 'templates/simple_deploy.jsonnet'; | ||
| local util = import 'templates/util.jsonnet'; | ||
| // Empty allocation tree => the external EthSend has no matching node and must | ||
| // hard-trap (OOM fees external). | ||
| {entry: util.addPaths([simple_deploy.run('${jsonnetDir}/${fileBaseName}.py') { | ||
| message_fee_allocation: [], | ||
| }])} |
27 changes: 27 additions & 0 deletions
27
tests/cases/stable/py/intercontract/alloc_empty_eth_send.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # { "Depends": "py-genlayer:test" } | ||
| import genlayer as gl | ||
| from genlayer.types import * | ||
|
|
||
|
|
||
| # Regression guard (genvm fee-allocation item #8): EthSend (external) variant. | ||
| # | ||
| # An empty message-fee-allocation tree must make an external (eth) send hard-trap | ||
| # (genlayer_sdk.rs EthSend path: no matching node -> oom_trap fees().external()), | ||
| # never silently emit nothing. The balance check (value=30 <= 100) passes first, | ||
| # so the trap comes from the allocation lookup, not from balance. | ||
| # | ||
| # Paired positive case: ../intercontract/send_message_eth.py (default tree -> | ||
| # EthSend emission succeeds). | ||
| @gl.evm.contract_interface | ||
| class Ghost: | ||
| class View: | ||
| pass | ||
|
|
||
| class Write: | ||
| def test(self, x: u256, /) -> None: ... | ||
|
|
||
|
|
||
| class Contract(gl.contract.Contract): | ||
| def __init__(self): | ||
| print(self.balance) | ||
| Ghost(Address(b'\x30' * 20)).emit(value=30).test(10) |
8 changes: 8 additions & 0 deletions
8
tests/cases/stable/py/intercontract/alloc_empty_post_message.jsonnet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| local simple_deploy = import 'templates/simple_deploy.jsonnet'; | ||
| local util = import 'templates/util.jsonnet'; | ||
| // Empty message-fee-allocation tree => the PostMessage emit has no matching node | ||
| // and must hard-trap (OOM fees internal). Overrides the runner default of three | ||
| // wildcard catch-all nodes (origin/fees.py DEFAULT_*_MESSAGE_ALLOC). | ||
| {entry: util.addPaths([simple_deploy.run('${jsonnetDir}/${fileBaseName}.py') { | ||
| message_fee_allocation: [], | ||
| }])} |
19 changes: 19 additions & 0 deletions
19
tests/cases/stable/py/intercontract/alloc_empty_post_message.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # { "Depends": "py-genlayer:test" } | ||
| import genlayer as gl | ||
| from genlayer.types import * | ||
|
|
||
|
|
||
| # Regression guard (genvm fee-allocation item #8). | ||
| # | ||
| # genvm is a pure CONSUMER of the message-fee-allocation tree the node provides. | ||
| # With an EMPTY tree, emitting an internal message MUST hard-trap (the find_map | ||
| # in genlayer_sdk.rs finds no matching node -> `oom_trap(... .fees().internal())`), | ||
| # it must NEVER silently emit nothing. A silent-0 here was the exact symptom of | ||
| # the consensus/node DisallowedFeeAllocation([]) bug investigated cross-repo; this | ||
| # test pins genvm's side so it can't regress to "0 emissions, no error". | ||
| # | ||
| # Paired positive case: ../intercontract/send_message.py (default wildcard tree | ||
| # -> the same emit succeeds with a PostMessage emission). | ||
| class Contract(gl.contract.Contract): | ||
| def __init__(self): | ||
| gl.contract.get_at(gl.Address(b'\x30' * 20)).emit().foo(1, 2) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
🧰 Tools
🪛 Ruff (0.15.15)
[error] 3-3:
from genlayer.types import *used; unable to detect undefined names(F403)
🤖 Prompt for AI Agents
Source: Linters/SAST tools