Skip to content

Commit

Permalink
idl: Fix using address constraint with field expressions (#3034)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored Jun 18, 2024
1 parent 3c5483f commit f326b89
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- cli: Fix upgradeable program clones ([#3010](https://github.com/coral-xyz/anchor/pull/3010)).
- ts: Fix using IDLs that have defined types as generic arguments ([#3016](https://github.com/coral-xyz/anchor/pull/3016)).
- idl: Fix generation with unsupported expressions ([#3033](https://github.com/coral-xyz/anchor/pull/3033)).
- idl: Fix using `address` constraint with field expressions ([#3034](https://github.com/coral-xyz/anchor/pull/3034)).

### Breaking

Expand Down
1 change: 1 addition & 0 deletions lang/syn/src/idl/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ fn get_address(acc: &Field) -> TokenStream {
.address
.as_ref()
.map(|constraint| &constraint.address)
.filter(|address| !matches!(address, syn::Expr::Field(_)))
.map(|address| quote! { Some(#address.to_string()) })
.unwrap_or_else(|| quote! { None }),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ pub mod relations_derivation {
ctx.accounts.account.bump = ctx.bumps.account;
Ok(())
}

pub fn test_relation(_ctx: Context<TestRelation>) -> Result<()> {
Ok(())
}

pub fn test_seed_constant(_ctx: Context<TestSeedConstant>) -> Result<()> {
Ok(())
}

pub fn test_address_relation(_ctx: Context<TestAddressRelation>) -> Result<()> {
Ok(())
}
}

#[derive(Accounts)]
Expand Down Expand Up @@ -80,6 +86,14 @@ pub struct TestSeedConstant<'info> {
system_program: Program<'info, System>,
}

#[derive(Accounts)]
pub struct TestAddressRelation<'info> {
#[account(address = my_account.my_account)]
account: UncheckedAccount<'info>,
#[account(seeds = [b"seed"], bump = my_account.bump)]
my_account: Account<'info, MyAccount>,
}

#[account]
pub struct MyAccount {
pub my_account: Pubkey,
Expand Down
5 changes: 5 additions & 0 deletions tests/relations-derivation/tests/typescript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ describe("typescript", () => {
it("Can use relations derivation with seed constant", async () => {
await program.methods.testSeedConstant().accounts({}).rpc();
});

it("Can use relations derivation with `address` constraint", () => {
// Only compile test for now since the IDL spec doesn't currently support field access
// expressions for the `address` constraint
});
});

0 comments on commit f326b89

Please sign in to comment.