Skip to content

simplify import_contract! testing #65

Open

Description

@chadoh

On testnet & mainnet, import_contract! is great, but in dev and testing it has some frustrations. This is highlighted by:

#64 has an elegant workaround for testing. Without including this in the macro somehow, probably lots of teams will retrace the same steps when they adopt import_contract!. Given that we already came up with an elegant solution here, can we incorporate it into the library itself, so consumers have an easier dev/testing experience?

Activity

  1. pselle commented on Oct 14, 2026

    @pselle
    Contributor

    Describing the plan of action here:

    First, stellar-registry will get a testutils feature with register_import!. It resolves a name the same way import_contract! does and registers the imported contract at the address baked in at build time. It registers either the cached Wasm, optionally with constructor args, or a native mock (#77). Next, register_import! supports Stellar Asset Contracts by placing a mintable test asset at the baked SAC address (#82). Then a new stellar registry local up command bootstraps a local network with the registry deployed, so imports can resolve against it during development.

    Once those are released, a PR in stellar-registry/contracts will switch registry-tansu-manager to import_contract!, test it with register_import! and use local up in its justfile. That PR closes this issue.

  2. chadoh commented on Oct 15, 2026

    @chadoh
    MemberAuthor

    Overall, I really like this plan! Just one question:

    stellar registry local up bootstraps a local network

    stellar container start local (and stellar scaffold watch, which automatically runs stellar container start and waits for it to be healthy, if the scaffold config specifies this) already starts the local network. I don't think we should duplicate that logic in Registry CLI. But maybe local up could check that the local network is already running and deploy the Registry contract, if needed?

    Thinking about it more:

    • local up reads nicely but are there other subcommands under local? If not, local-up or some other name might be better, so anyone exploring with -h doesn't need to dig so far.
    • Could register_import! check if the contract is deployed, and deploy it if not? Then we don't need the local up command at all.
  3. chadoh commented on Oct 15, 2026

    @chadoh
    MemberAuthor

    Oh wait hm, during development. 🤔 How would that actually work? 🤔 Dev build doesn't use test_utils or register_import!. Does local up use the test setup? Or does it do something else with the import_contract! macro?

  4. pselle commented on Oct 15, 2026

    @pselle
    Contributor

    stellar registry local up Yeah, that's fair, let's not duplicate the network bit.

    And namespaces: Yes, simpler when we can. local-up sounds fine.

    register_import! is only for testing purposes, while local-up is for dev builds so import_contract! can look up addresses on the local registry at build time. The two things live in different worlds, really

  5. chadoh commented on Oct 15, 2026

    @chadoh
    MemberAuthor

    Talking this through with @zachfedor, here's what we thought made sense:

    • testing: register_import! is great! Seems like exactly the tool for the job. (PR review incoming on feat: add register_import! for testing import_contract! callers #77)

    • local dev: if STELLAR_NETWORK == "local" and local Registry contract is not deployed or the requested contract is not registered in it, fail with an error that says something like:

      `STELLAR_NETWORK=local` and {contract_name} is not in local Registry. 
      For predictable local builds, use Stellar Scaffold: https://stellarscaffold.org
      

      The "configure local dev env with Registry contract & local registered contracts" is still TBD on the Scaffold side, but that seems like the tool for the job. Let's not re-implement with separate logic here. No local-up CLI command.

      Does that make sense to you?

    • Should we also default to testnet, rather than local?

  6. pselle commented on Oct 15, 2026

    @pselle
    Contributor

    Makes sense. Let's drop local-up and leave local setup to Scaffold. I'll make import_contract! (and import_contract_client!) fail with that error when STELLAR_NETWORK=local and the Registry or the contract isn't there.

    I'd keep local as the default, though. Right now an unconfigured build fails noisily. If we default to testnet, it would quietly bake testnet addresses into the contract, and then that could easily go to mainnet, whatever. local is also the default for the cache path in stellar-build and for computing asset contract addresses, so switching would mean changing Scaffold too. I'd rather keep the loud failure and let the new error point people in the right direction.

  7. pselle commented on Oct 15, 2026

    @pselle
    Contributor

    Restatement of the plan, adjusting for "what should happen to run things locally?"

    First, stellar-registry will get a testutils feature with register_import!. It resolves a name the same way import_contract! does and registers the imported contract at the address baked in at build time. It registers either the cached Wasm, optionally with constructor args, or a native mock (#77). Next, register_import! supports Stellar Asset Contracts by placing a mintable test asset at the baked SAC address (#82).

    For local development, the Registry CLI won't set up the local network itself. When STELLAR_NETWORK=local and the local Registry is missing or doesn't have the requested contract, import_contract! will fail with a clear error that points to Stellar Scaffold, which will own local setup. local stays the default network.

    The hello_caller and xlm_tip_jar fixtures in this repo show the full pattern and run in CI, so this issue can close once these are released. registry-tansu-manager, the original motivating case, has moved to Tansu’s repo (stellar-registry/contracts#55), so stellar-registry/contracts#24 can be closed rather than updated.

  8. chadoh commented on Oct 15, 2026

    @chadoh
    MemberAuthor

    That all sounds good though I would like us to implement this somewhere in our own contracts. We could send an update like stellar-registry/contracts#24 to the Tansu repo, or we could update Scaffold's template, or... What other cross-contract calls are we making?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions