Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty address in IDL file when multiple crates exist within an Anchor program package #3395

Closed
dhl opened this issue Nov 29, 2024 · 1 comment
Labels
bug Something isn't working idl related to the IDL, either program or client side

Comments

@dhl
Copy link

dhl commented Nov 29, 2024

Problem

When multiple crates exists in an Anchor program (e.g. by including a tests integration folder), the IDL file generated by anchor build will have an empty address property.

Expected Behavior

The IDL JSON file for the program is generated with the correct address property.

Actual Behavior

The address property in the IDL file is empty.

Environment

Component Version
Anchor 0.30.1
Solana CLI 1.18.26

Reproduction Steps

# 1. Generate a new Anchor project
anchor init idl-multi-crate-bug  
cd idl-multi-crate-bug 

# 2. Run a build to confirm the IDL file includes a program address
anchor build
grep address target/idl/idl_multi_crate_bug.json  # => e.g. "address": "7RuRMKRpVsW7A9BBxLfJVijbfNc1F1xAaSHNhEgJRNP4",

# 3. Add a dummy Rust integration test folder
mkdir programs/idl-multi-crate-bug/tests
touch programs/idl-multi-crate-bug/tests/dummy-test.rs

# 4. Trigger another build
anchor build

# 5. Verify the address property in the IDL file is now empty
grep address target/idl/idl_multi_crate_bug.json  # => "address": "", 

Analysis

It appears that when multiple crates exists in a package, the IDL build tool is confused and unable to insert the program address into the program's IDL file.

For example, if a binary crate is included in an Anchor program (e.g. by defining /src/main.rs), the same bug is triggered.

@dhl dhl changed the title Empty address in IDL file when multiple crates exists within an Anchor program package Empty address in IDL file when multiple crates exist within an Anchor program package Nov 29, 2024
@acheroncrypto acheroncrypto added bug Something isn't working idl related to the IDL, either program or client side labels Nov 29, 2024
@acheroncrypto
Copy link
Collaborator

Thanks for creating the issue. I think this should be fixed in #3058, but we don't yet have a release (#3259) that includes the fix unfortunately.

You can install the latest CLI (or the commit 5f1f72c) from git (avm also supports this, see https://www.anchor-lang.com/docs/avm#install) to verify this.

I'm closing this as completed, but feel free to reopen if the problem continues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working idl related to the IDL, either program or client side
Projects
None yet
Development

No branches or pull requests

2 participants