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

Anchor fails to create expected IDL name #3353

Open
Sabnock01 opened this issue Nov 8, 2024 · 2 comments
Open

Anchor fails to create expected IDL name #3353

Sabnock01 opened this issue Nov 8, 2024 · 2 comments
Labels
bug Something isn't working ts

Comments

@Sabnock01
Copy link

Sabnock01 commented Nov 8, 2024

If you have a program with a name like program_v1, the resulting IDL will be named program_v1.json yet the Mocha tests will expect program_v_1.json.

Tests should use the same name resolution as Anchor in generating the IDL.

Reproduced:
image

@acheroncrypto acheroncrypto added bug Something isn't working ts labels Nov 8, 2024
@acheroncrypto
Copy link
Collaborator

Reason explained here:

// Check whether the program name contains any digits
if (/\d/.test(programName)) {
// Numbers cannot be properly converted from camelCase to snake_case,
// e.g. if the `programName` is `myProgram2`, the actual program name could
// be `my_program2` or `my_program_2`. This implementation assumes the
// latter as the default and always converts to `_numbers`.
//
// A solution to the conversion of program names with numbers in them
// would be to always convert the `programName` to camelCase instead of
// snake_case. The problem with this approach is that it would require
// converting everything else e.g. program names in Anchor.toml and IDL
// file names which are both snake_case.
programName = programName
.replace(/\d+/g, (match) => "_" + match)
.replace("__", "_");
}

I guess we could add an edge case to check both versions, but generally speaking, you'd have much better time if you avoid using numbers in your identifiers (program name, function name, account name...) because case conversion cross-language can be inconsistent or lossy.

@dkrizhanovskyi
Copy link

Hi! Thank you for identifying this issue. I noticed that the current naming conversion can cause inconsistencies, especially with numbers in program names.

One idea could be to add a fallback check for both naming formats (program_v1.json and program_v_1.json) to maintain compatibility while avoiding test failures.

Additionally, it might help to clarify in the documentation how program names are converted and recommend avoiding numbers in identifiers to prevent cross-language issues.

I’m new to contributing, but I’d be happy to help with testing or making small changes if needed. Let me know what you think!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ts
Projects
None yet
Development

No branches or pull requests

3 participants