Skip to content

Commit 6f9f7d9

Browse files
tests: Move IDL related tests in misc to idl (solana-foundation#2606)
1 parent 6eacad4 commit 6f9f7d9

26 files changed

Lines changed: 587 additions & 641 deletions

File tree

tests/idl/Anchor.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
seeds = true
33

44
[programs.localnet]
5+
client_interactions = "C1ient1nteractions1111111111111111111111111"
6+
docs = "Docs111111111111111111111111111111111111111"
57
external = "Externa1111111111111111111111111111111111111"
68
generics = "Generics111111111111111111111111111111111111"
79
idl = "id11111111111111111111111111111111111111111"

tests/idl/idls/build.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
"type": "u8",
1111
"value": "6"
1212
},
13+
{
14+
"name": "BYTE_STR",
15+
"type": "u8",
16+
"value": "116"
17+
},
1318
{
1419
"name": "FOO_CONST",
1520
"type": "u128",

tests/idl/idls/parse.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
"name": "BAR_CONST",
1515
"type": "u8",
1616
"value": "6"
17+
},
18+
{
19+
"name": "BYTES_STR",
20+
"type": "bytes",
21+
"value": "[116, 101, 115, 116]"
22+
},
23+
{
24+
"name": "BYTE_STR",
25+
"type": "u8",
26+
"value": "116"
1727
}
1828
],
1929
"instructions": [
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
2-
name = "idl_doc"
2+
name = "client-interactions"
33
version = "0.1.0"
44
description = "Created with Anchor"
55
rust-version = "1.60"
66
edition = "2021"
77

88
[lib]
99
crate-type = ["cdylib", "lib"]
10-
name = "idl_doc"
10+
name = "client_interactions"
1111

1212
[features]
1313
no-entrypoint = []
@@ -16,4 +16,4 @@ cpi = ["no-entrypoint"]
1616
default = []
1717

1818
[dependencies]
19-
anchor-lang = { path = "../../../../lang", features = ["init-if-needed"] }
19+
anchor-lang = { path = "../../../../lang" }
File renamed without changes.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
use anchor_lang::prelude::*;
2+
3+
declare_id!("C1ient1nteractions1111111111111111111111111");
4+
5+
#[program]
6+
pub mod client_interactions {
7+
use super::*;
8+
9+
pub fn int(ctx: Context<Int>, i8: i8, i16: i16, i32: i32, i64: i64, i128: i128) -> Result<()> {
10+
ctx.accounts.account.i8 = i8;
11+
ctx.accounts.account.i16 = i16;
12+
ctx.accounts.account.i32 = i32;
13+
ctx.accounts.account.i64 = i64;
14+
ctx.accounts.account.i128 = i128;
15+
Ok(())
16+
}
17+
18+
pub fn uint(
19+
ctx: Context<UnsignedInt>,
20+
u8: u8,
21+
u16: u16,
22+
u32: u32,
23+
u64: u64,
24+
u128: u128,
25+
) -> Result<()> {
26+
ctx.accounts.account.u8 = u8;
27+
ctx.accounts.account.u16 = u16;
28+
ctx.accounts.account.u32 = u32;
29+
ctx.accounts.account.u64 = u64;
30+
ctx.accounts.account.u128 = u128;
31+
Ok(())
32+
}
33+
34+
pub fn enm(ctx: Context<Enum>, enum_arg: MyEnum) -> Result<()> {
35+
ctx.accounts.account.enum_field = enum_arg;
36+
Ok(())
37+
}
38+
}
39+
40+
#[derive(Accounts)]
41+
pub struct Int<'info> {
42+
#[account(zero)]
43+
pub account: Account<'info, IntAccount>,
44+
}
45+
46+
#[account]
47+
pub struct IntAccount {
48+
pub i8: i8,
49+
pub i16: i16,
50+
pub i32: i32,
51+
pub i64: i64,
52+
pub i128: i128,
53+
}
54+
55+
#[derive(Accounts)]
56+
pub struct UnsignedInt<'info> {
57+
#[account(zero)]
58+
pub account: Account<'info, UnsignedIntAccount>,
59+
}
60+
61+
#[account]
62+
pub struct UnsignedIntAccount {
63+
pub u8: u8,
64+
pub u16: u16,
65+
pub u32: u32,
66+
pub u64: u64,
67+
pub u128: u128,
68+
}
69+
70+
#[derive(Accounts)]
71+
pub struct Enum<'info> {
72+
#[account(zero)]
73+
pub account: Account<'info, EnumAccount>,
74+
}
75+
76+
#[account]
77+
pub struct EnumAccount {
78+
pub enum_field: MyEnum,
79+
}
80+
81+
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug, Eq, PartialEq)]
82+
pub enum MyEnum {
83+
Unit,
84+
Named { x: u64, y: u64 },
85+
Unnamed(u8, u8, u16, u16),
86+
UnnamedStruct(MyStruct),
87+
}
88+
89+
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug, Eq, PartialEq)]
90+
pub struct MyStruct {
91+
pub u8: u8,
92+
pub u16: u16,
93+
pub u32: u32,
94+
pub u64: u64,
95+
}

tests/idl/programs/docs/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "docs"
3+
version = "0.1.0"
4+
description = "Created with Anchor"
5+
rust-version = "1.60"
6+
edition = "2021"
7+
8+
[lib]
9+
crate-type = ["cdylib", "lib"]
10+
name = "docs"
11+
12+
[features]
13+
no-entrypoint = []
14+
no-idl = []
15+
cpi = ["no-entrypoint"]
16+
default = []
17+
18+
[dependencies]
19+
anchor-lang = { path = "../../../../lang" }

tests/idl/programs/docs/Xargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.bpfel-unknown-unknown.dependencies.std]
2+
features = []
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22
33
use anchor_lang::prelude::*;
44

5-
6-
declare_id!("BqmKjZGVa8fqyWuojJzG16zaKSV1GjAisZToNuvEaz6m");
5+
declare_id!("Docs111111111111111111111111111111111111111");
76

87
/// This is a doc comment for the program
98
#[program]
10-
pub mod idl_doc {
9+
pub mod docs {
1110
use super::*;
1211

1312
/// This instruction doc should appear in the IDL
14-
pub fn test_idl_doc_parse(
15-
_ctx: Context<TestIdlDocParse>,
16-
) -> Result<()> {
13+
pub fn test_idl_doc_parse(_ctx: Context<TestIdlDocParse>) -> Result<()> {
1714
Ok(())
1815
}
1916
}
@@ -25,7 +22,6 @@ pub struct DataWithDoc {
2522
pub data: u16,
2623
}
2724

28-
2925
#[derive(Accounts)]
3026
pub struct TestIdlDocParse<'info> {
3127
/// This account doc comment should appear in the IDL

tests/idl/programs/idl/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ declare_id!("id11111111111111111111111111111111111111111");
55

66
#[constant]
77
pub const FOO_CONST: u128 = 1_000_000;
8+
89
#[constant]
910
pub const BAR_CONST: u8 = 6;
1011

12+
#[constant]
13+
pub const BYTES_STR: &[u8] = b"test";
14+
15+
#[constant]
16+
pub const BYTE_STR: u8 = b't';
17+
18+
pub const NO_IDL: u16 = 55;
19+
1120
/// IDL test program documentation.
1221
#[program]
1322
pub mod idl {

0 commit comments

Comments
 (0)