Skip to content

feat: add register_import! for testing import_contract! callers - #77

Open
pselle wants to merge 11 commits into
mainfrom
feat/register-import
Open

pselle wants to merge 11 commits into
mainfrom
feat/register-import

Conversation

@pselle

@pselle pselle commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Part of #65

Adds register_import! (behind a new testutils feature on stellar-registry), a test helper for contracts that use import_contract!.

import_contract! bakes the imported contract's on-chain address in at build time, so a unit test's Env has nothing at that address. register_import! resolves the name the same way and registers the contract there, so contract code needs no #[cfg(test)] switch around the import.

use stellar_registry::testutils::register_import;

register_import!(&env, our_dao);                           // the imported Wasm
register_import!(&env, our_dao, args = (&admin, 7u32));    // with constructor args
register_import!(&env, our_dao, contract = MockDao);       // a native mock instead

SAC names are a compile error for now; support follows in #82. The hello_caller fixture is excluded from the workspace because it can't compile without seeded cache files; just test-register-import seeds them and runs it in CI.

`import_contract!` bakes a real on-chain address into a contract, and
nothing lives at that address in a sandboxed test `Env`. Add
`stellar_registry::testutils::register_import!` (behind a new `testutils`
feature), which resolves a name through the same code as
`import_contract!` and registers the imported Wasm, or a native mock, at
that address with `Env::register_at`.

Stellar Asset Contracts are a compile error for now.

The new `hello_caller` fixture imports `hello_v1` and tests itself with
`register_import!`. It is excluded from the workspace, since it needs
seeded cache files to compile; `just test-register-import` seeds them and
runs it offline, and CI runs that recipe.

Part of #65

Co-Authored-By: Claude <[email protected]>
@pselle pselle self-assigned this Oct 13, 2026
pselle and others added 2 commits October 13, 2026 14:10
The fixture sits outside the workspace, so it does not pick up the
workspace's soroban-sdk bump.

Co-Authored-By: Claude <[email protected]>
@pselle
pselle marked this pull request as ready for review October 14, 2026 01:18
@pselle
pselle requested a review from chadoh October 14, 2026 01:21
chadoh
chadoh previously requested changes Oct 15, 2026

@chadoh chadoh left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have been thinking about this for hours and I still haven't finished reading it all but it's time to give you my first wall of thoughts!!! 😂 😖 🙇🏼 🙇🏼 🙇🏼

(Take this as a good thing! You came up with an interesting solution to a problem I hadn't yet really thought through and it spurred some ideas!!)

Also, as always, I'm open to pushback on any of this! We don't have to do it the ways I'm contemplating, or we do not need to do them right now. Maybe it's fine to do an initial fast release with a cleanup update later.

Comment thread crates/stellar-registry/README.md
Comment thread crates/stellar-registry/README.md Outdated
Comment thread crates/stellar-registry-test/fixtures/contracts/hello_caller/src/lib.rs Outdated
Comment thread justfile
Comment thread Cargo.toml Outdated
pselle and others added 7 commits October 16, 2026 09:09
Co-authored-by: Chad Ostrowski <[email protected]>
`args = { admin, quorum: 7u32 }` passes constructor arguments by name.
The macro reads the constructor's parameters from the imported Wasm's
spec, orders the values to match, and calls the typed
`Args::__constructor` that `contractimport!` generates, so names and
types are checked at compile time. Leaving out `args` when the
constructor takes parameters is a compile error listing them. The tuple
form still works and is type-checked too.

Co-Authored-By: Claude <[email protected]>
Resolve the Cargo.lock conflict from main's dependency bumps. main moved
stellar-xdr to 30 while soroban-spec 28 uses stellar-xdr 28, so read only
the raw spec section with soroban-spec and parse it with this crate's
stellar-xdr.

Co-Authored-By: Claude <[email protected]>
The new `unverified_caller` fixture imports `unverified`, the root
registry's subregistry on testnet, and tests itself with
`register_import!` and named constructor args. `just
test-register-import-testnet` runs it with `STELLAR_NETWORK=testnet`, so
the id and Wasm are really fetched. It needs network access, so CI
doesn't run it.

Co-Authored-By: Claude <[email protected]>
Drop its committed Cargo.lock (it only runs manually, online) and trim
its comments.

Co-Authored-By: Claude <[email protected]>
`unverified` is the subregistry itself; `unverified/my-token` is an
ordinary registered contract, and its five-argument constructor
exercises named args more fully.

Co-Authored-By: Claude <[email protected]>
@pselle

pselle commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Ok, I've resolved all the comments. I added typed args, but the from_network didn't make sense because STELLAR_NETWORK covers that.

I also added a recipe for testing through a contract build on testnet, alas that adds another fixture so that I can import that specific contract (alternatively, we could deploy hello_v1 or a different fixture to testnet ... but unverified/token is from the oz-wasms and I thought it fit well).

The perk of adding the fixture is that it shows the full example within the repo of how you'd use import_contract and then use register_contract, which I think was what you were aiming for. I like the token one too because it does have a handful of args, so it showcases the typed args well.

@pselle
pselle requested a review from chadoh October 16, 2026 15:20
@pselle
pselle dismissed chadoh’s stale review October 16, 2026 20:29

Resolved comments

Main now derives asset-syntax SAC addresses at runtime, so resolve()
returns a new Resolved::Asset carrying the asset XDR instead of a
build-time address. register_import! rejects it like any other SAC, and
its expansion now tracks the network env so it re-expands alongside
import_contract! when the network changes.

Co-Authored-By: Claude <[email protected]>
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