-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: Make conflicting account names a compile-time error (#2621)
- Loading branch information
1 parent
b9fa898
commit a1e4453
Showing
6 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "idl-build-features" | ||
version = "0.1.0" | ||
description = "Created with Anchor" | ||
rust-version = "1.60" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "lib"] | ||
name = "idl_build_features" | ||
|
||
[features] | ||
no-entrypoint = [] | ||
no-idl = [] | ||
cpi = ["no-entrypoint"] | ||
idl-build = ["anchor-lang/idl-build"] | ||
default = [] | ||
|
||
[dependencies] | ||
anchor-lang = { path = "../../../../lang" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[target.bpfel-unknown-unknown.dependencies.std] | ||
features = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
declare_id!("id1Bui1dFeatures111111111111111111111111111"); | ||
|
||
#[program] | ||
pub mod idl_build_features { | ||
use super::*; | ||
|
||
pub fn full_path( | ||
ctx: Context<FullPath>, | ||
my_struct: MyStruct, | ||
some_module_my_struct: some_module::MyStruct, | ||
) -> Result<()> { | ||
ctx.accounts.account.my_struct = my_struct; | ||
ctx.accounts.account.some_module_my_struct = some_module_my_struct; | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct FullPath<'info> { | ||
#[account(zero)] | ||
pub account: Account<'info, FullPathAccount>, | ||
} | ||
|
||
#[account] | ||
pub struct FullPathAccount { | ||
pub my_struct: MyStruct, | ||
pub some_module_my_struct: some_module::MyStruct, | ||
} | ||
|
||
mod some_module { | ||
use super::*; | ||
|
||
#[derive(AnchorSerialize, AnchorDeserialize, Clone)] | ||
pub struct MyStruct { | ||
pub data: u8, | ||
} | ||
} | ||
|
||
#[derive(AnchorSerialize, AnchorDeserialize, Clone)] | ||
pub struct MyStruct { | ||
pub u8: u8, | ||
pub u16: u16, | ||
pub u32: u32, | ||
pub u64: u64, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as anchor from "@coral-xyz/anchor"; | ||
import { assert } from "chai"; | ||
|
||
import { IdlBuildFeatures } from "../target/types/idl_build_features"; | ||
|
||
describe("idl-build features", () => { | ||
anchor.setProvider(anchor.AnchorProvider.env()); | ||
const program = anchor.workspace | ||
.idlBuildFeatures as anchor.Program<IdlBuildFeatures>; | ||
|
||
it("Can use full module path types", async () => { | ||
const kp = anchor.web3.Keypair.generate(); | ||
|
||
const outerMyStructArg = { u8: 1, u16: 2, u32: 3, u64: new anchor.BN(4) }; | ||
const someModuleMyStructArg = { data: 5 }; | ||
|
||
await program.methods | ||
.fullPath(outerMyStructArg, someModuleMyStructArg) | ||
.accounts({ account: kp.publicKey }) | ||
.preInstructions([ | ||
await program.account.fullPathAccount.createInstruction(kp), | ||
]) | ||
.signers([kp]) | ||
.rpc(); | ||
|
||
const fullPathAccount = await program.account.fullPathAccount.fetch( | ||
kp.publicKey | ||
); | ||
assert.strictEqual(fullPathAccount.myStruct.u8, outerMyStructArg.u8); | ||
assert.strictEqual(fullPathAccount.myStruct.u16, outerMyStructArg.u16); | ||
assert.strictEqual(fullPathAccount.myStruct.u32, outerMyStructArg.u32); | ||
assert(fullPathAccount.myStruct.u64.eq(outerMyStructArg.u64)); | ||
assert.deepEqual(fullPathAccount.someModuleMyStruct, someModuleMyStructArg); | ||
}); | ||
}); |
a1e4453
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
anchor-docs – ./
anchor-docs-git-master-200ms.vercel.app
anchor-docs-200ms.vercel.app
www.anchor-lang.com
anchor-lang.com