Skip to content

Commit ca50c23

Browse files
idl: Fix address constraint not resolving constants that have numbers in their identifiers (otter-sec#4144)
1 parent 60510b5 commit ca50c23

4 files changed

Lines changed: 10 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The minor version will be incremented upon a breaking change and the patch versi
2121
- idl: Fix defined types with unsupported fields not producing an error ([#4088](https://github.com/solana-foundation/anchor/pull/4088)).
2222
- lang: Fix using non-instruction composite accounts multiple times with `declare_program!` ([#4113](https://github.com/solana-foundation/anchor/pull/4113)).
2323
- lang: Fix `declare_program!` messing up IDL errors generation ([#4126](https://github.com/solana-foundation/anchor/pull/4126)).
24+
- idl: Fix `address` constraint not resolving constants that have numbers in their identifiers ([#4144](https://github.com/solana-foundation/anchor/pull/4144)).
2425

2526
### Breaking
2627

lang/syn/src/idl/accounts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fn get_address(acc: &Field) -> TokenStream {
175175
.ident
176176
.to_string()
177177
.chars()
178-
.all(|c| c.is_uppercase() || c == '_'),
178+
.all(|c| c.is_ascii_uppercase() || c.is_ascii_digit() || c == '_'),
179179
// Allow `const fn`s (assume any stand-alone function call without an argument)
180180
// e.g. `crate::id()`
181181
syn::Expr::Call(expr) => expr.args.is_empty(),

tests/relations-derivation/programs/relations-derivation/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,17 @@ pub struct TestRelation<'info> {
6565
nested: Nested<'info>,
6666
}
6767

68+
// Test https://github.com/solana-foundation/anchor/issues/4143
69+
pub const ADDRESS_WITH_NUMBER_V2: Pubkey = pubkey!("D8cy77BBepLMngZx6ZukaTff5hCt1HrWyKk3Hnd9oitf");
70+
6871
#[derive(Accounts)]
6972
pub struct TestAddress<'info> {
7073
// Included wit the `address` field in IDL
7174
// It's actually `static` but it doesn't matter for our purposes
7275
#[account(address = crate::ID)]
7376
constant: UncheckedAccount<'info>,
77+
#[account(address = ADDRESS_WITH_NUMBER_V2)]
78+
const_with_number: UncheckedAccount<'info>,
7479
#[account(address = crate::id())]
7580
const_fn: UncheckedAccount<'info>,
7681

tests/relations-derivation/tests/typescript.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ describe("typescript", () => {
4545
const ix = program.idl.instructions.find(
4646
(ix) => ix.name === "testAddress"
4747
)!;
48+
4849
expect(ix.accounts.find((acc) => acc.name === "constant")!.address).to.not
4950
.be.undefined;
51+
expect(ix.accounts.find((acc) => acc.name === "constWithNumber")!.address)
52+
.to.not.be.undefined;
5053
expect(ix.accounts.find((acc) => acc.name === "constFn")!.address).to.not.be
5154
.undefined;
5255
});

0 commit comments

Comments
 (0)