ts: Fix loading programs with numbers in their names using workspace
#3450
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Using numbers in program identifiers might result in problems when loading the program using
anchor.workspace
as explained here:anchor/ts/packages/anchor/src/workspace.ts
Lines 27 to 42 in 6ff6655
When I initially was working on the above change, I first made it assume there is no
_
involved e.g. if the user givesmyProgram2
, the program name ismy_program2
. However, with this change, the examples started failing because their names arebasic_<number>
, which then made me change it to its current form.For example, if the program name is
program_v2
, and it's getting loaded withanchor.workspace.programV2
, it results in the following error:This is also one of the most commonly reported problems.
Summary of changes
Fix loading programs with numbers in their names using
anchor.workspace
.Resolves #3353