idl: Fix using `address` constraint with field expressions (#3034)

This commit is contained in:
acheron 2024-06-18 22:54:40 +02:00 committed by GitHub
parent 3c5483f0d0
commit f326b89c48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 0 deletions

View File

@ -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

View File

@ -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 }),
}

View File

@ -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)]
@ -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,

View File

@ -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
});
});