idl: Fix using `address` constraint with field expressions (#3034)
This commit is contained in:
parent
3c5483f0d0
commit
f326b89c48
|
@ -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)).
|
- 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)).
|
- 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 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
|
### Breaking
|
||||||
|
|
||||||
|
|
|
@ -161,6 +161,7 @@ fn get_address(acc: &Field) -> TokenStream {
|
||||||
.address
|
.address
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|constraint| &constraint.address)
|
.map(|constraint| &constraint.address)
|
||||||
|
.filter(|address| !matches!(address, syn::Expr::Field(_)))
|
||||||
.map(|address| quote! { Some(#address.to_string()) })
|
.map(|address| quote! { Some(#address.to_string()) })
|
||||||
.unwrap_or_else(|| quote! { None }),
|
.unwrap_or_else(|| quote! { None }),
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,18 @@ pub mod relations_derivation {
|
||||||
ctx.accounts.account.bump = ctx.bumps.account;
|
ctx.accounts.account.bump = ctx.bumps.account;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn test_relation(_ctx: Context<TestRelation>) -> Result<()> {
|
pub fn test_relation(_ctx: Context<TestRelation>) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn test_seed_constant(_ctx: Context<TestSeedConstant>) -> Result<()> {
|
pub fn test_seed_constant(_ctx: Context<TestSeedConstant>) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn test_address_relation(_ctx: Context<TestAddressRelation>) -> Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Accounts)]
|
#[derive(Accounts)]
|
||||||
|
@ -80,6 +86,14 @@ pub struct TestSeedConstant<'info> {
|
||||||
system_program: Program<'info, System>,
|
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]
|
#[account]
|
||||||
pub struct MyAccount {
|
pub struct MyAccount {
|
||||||
pub my_account: Pubkey,
|
pub my_account: Pubkey,
|
||||||
|
|
|
@ -44,4 +44,9 @@ describe("typescript", () => {
|
||||||
it("Can use relations derivation with seed constant", async () => {
|
it("Can use relations derivation with seed constant", async () => {
|
||||||
await program.methods.testSeedConstant().accounts({}).rpc();
|
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
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue