Skip to content

fix(direct): resolve SDK modules from the current genlayer.py layout - #114

Open
HusseinAdeiza wants to merge 1 commit into
genlayerlabs:v0.30-devfrom
HusseinAdeiza:fix/direct-sdk-module-layout
Open

HusseinAdeiza wants to merge 1 commit into
genlayerlabs:v0.30-devfrom
HusseinAdeiza:fix/direct-sdk-module-layout

Conversation

@HusseinAdeiza

Copy link
Copy Markdown

What

gltest/direct/sdk_compat.py imported the SDK's calldata and types modules from the package root:

from genlayer import calldata
from genlayer import types as sdk_types

The SDK moved both under genlayer.py in 0.6. On a 0.6 runner those imports raise ImportError, and _inject_message_to_fd0 swallows it:

try:
    calldata = import_calldata()
    Address = import_address()
except ImportError:
    return

So the encoded message is never written to fd 0, and the SDK decodes real stdin at import time instead — surfacing as a decode error against a contract that never got its context:

ImportError: Failed to load contract: unexpected end of memory

Not specific to Address constructor args

I reproduced on 0.30.0rc2 / 0.19.0rc2 and the failure covers every constructor shape I tried, no-arg included:

Constructor Result
() fails
(a: u256) fails
(a: Address) fails
(a: Address, b: Address) fails
(a: DynArray[str]) fails

The two-Address constructor is just the smallest case, which is likely why it read as type-specific.

Fix

Import from the current location, falling back to the legacy one so older pinned runners keep resolving:

def _import_sdk_module(name: str) -> Any:
    try:
        return importlib.import_module(f"genlayer.py.{name}")
    except ModuleNotFoundError:
        return importlib.import_module(f"genlayer.{name}")

Testing

  • tests/gltest_direct: 58 passed (52 before, plus 6 new).
  • Full suite unchanged at 22 pre-existing failures / 2 errors in tests/examples and tests/test_bug_hunt_v030.py, identical before and after.
  • Each new test fails on the unpatched tree and passes with the fix.

The reporter's related question about cross-contract calls in direct mode is untouched here — that path needs a _gl_call_hook and is a separate question.

Fixes #113

The SDK moved its Python-side modules under `genlayer.py` (v0.6+), but
`import_calldata`/`import_types` still imported them from the package
root. On a 0.6 runner that raised ImportError, which
`_inject_message_to_fd0` swallowed, so the encoded message was never
written to fd 0 and the SDK decoded real stdin instead:

    ImportError: Failed to load contract: unexpected end of memory

Import from the current location first and fall back to the legacy
path so older pinned runners keep working.

Fixes genlayerlabs#113
@coderabbitai

coderabbitai Bot commented Sep 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 90f63f49-51bc-4ab2-9265-5f38c86657d3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

This branch has not been deployed

No deployments
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.

1 participant