Skip to content
This repository was archived by the owner on Jul 22, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/cases/stable/py/intercontract/alloc_budget_exhausted.jsonnet
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 tests/cases/stable/py/intercontract/alloc_budget_exhausted.py
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 *

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



# 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)
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: [],
}])}
16 changes: 16 additions & 0 deletions tests/cases/stable/py/intercontract/alloc_empty_deploy.py
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'))
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 tests/cases/stable/py/intercontract/alloc_empty_eth_send.py
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)
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 tests/cases/stable/py/intercontract/alloc_empty_post_message.py
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)
Loading