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 · 1 comment
Open

Anchor fails to create expected IDL name #3353

Sabnock01 opened this issue Nov 8, 2024 · 1 comment
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.

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

2 participants