@layerzerolabs/framework-solana-anchor-trait 0.2.61 → 0.2.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +3 -0
- package/README.md +5 -0
- package/SPEC.md +318 -0
- package/examples/shapes/Cargo.lock +4126 -0
- package/examples/shapes/Cargo.toml +16 -0
- package/examples/shapes/macros/src/audit.rs +15 -0
- package/examples/shapes/macros/src/instructions/clear.rs +19 -0
- package/examples/shapes/macros/src/instructions/compute_area.rs +18 -20
- package/examples/shapes/macros/src/instructions/compute_perimeter.rs +18 -20
- package/examples/shapes/macros/src/instructions/get_dimension.rs +19 -0
- package/examples/shapes/macros/src/instructions/get_dimension_count.rs +19 -17
- package/examples/shapes/macros/src/instructions/mod.rs +8 -0
- package/examples/shapes/macros/src/instructions/reset.rs +50 -0
- package/examples/shapes/macros/src/instructions/scale.rs +52 -0
- package/examples/shapes/macros/src/lib.rs +14 -11
- package/examples/shapes/macros/src/shapes.rs +21 -26
- package/examples/shapes/macros/src/state_types.rs +14 -0
- package/examples/shapes/programs/ellipse/Cargo.toml +7 -0
- package/examples/shapes/programs/ellipse/src/lib.rs +69 -17
- package/examples/shapes/programs/ellipse/tests/ellipse/helpers.rs +110 -0
- package/examples/shapes/programs/ellipse/tests/ellipse/negative.rs +49 -0
- package/examples/shapes/programs/ellipse/tests/ellipse/positive.rs +231 -0
- package/examples/shapes/programs/ellipse/tests/ellipse.rs +23 -0
- package/examples/shapes/programs/triangle/Cargo.toml +7 -0
- package/examples/shapes/programs/triangle/src/lib.rs +69 -16
- package/examples/shapes/programs/triangle/tests/triangle/helpers.rs +123 -0
- package/examples/shapes/programs/triangle/tests/triangle/negative.rs +49 -0
- package/examples/shapes/programs/triangle/tests/triangle/positive.rs +225 -0
- package/examples/shapes/programs/triangle/tests/triangle.rs +23 -0
- package/examples/shapes/target/deploy/shapes_ellipse-keypair.json +1 -0
- package/examples/shapes/target/deploy/shapes_ellipse.so +0 -0
- package/examples/shapes/target/deploy/shapes_triangle-keypair.json +1 -0
- package/examples/shapes/target/deploy/shapes_triangle.so +0 -0
- package/package.json +14 -7
- package/src/assembly.rs +41 -6
- package/src/generation.rs +108 -131
- package/src/lib.rs +6 -4
- package/src/overrides.rs +56 -81
- package/tests/assembly.rs +154 -23
- package/tests/common/mod.rs +68 -14
- package/tests/generation.rs +137 -65
- package/tests/override.rs +93 -55
- package/tests/snapshots/snapshots__tests__snapshot_all_defaults.snap +32 -5
- package/tests/snapshots/snapshots__tests__snapshot_full_override.snap +35 -7
- package/tests/snapshots/snapshots__tests__snapshot_handler_override.snap +37 -7
- package/tests/snapshots/snapshots__tests__snapshot_mixed_overrides.snap +40 -9
- package/tests/snapshots/snapshots__tests__snapshot_with_extend_macro.snap +82 -0
- package/tests/snapshots.rs +51 -18
- package/examples/shapes/Anchor.toml +0 -19
- package/examples/shapes/programs/ellipse/src/state.rs +0 -9
- package/examples/shapes/programs/triangle/src/state.rs +0 -9
package/tests/snapshots.rs
CHANGED
|
@@ -12,6 +12,15 @@ mod tests {
|
|
|
12
12
|
module: &syn::ItemMod,
|
|
13
13
|
prelude: TokenStream,
|
|
14
14
|
extra_mod_attrs: TokenStream,
|
|
15
|
+
) -> String {
|
|
16
|
+
assemble_formatted_with_extend(module, prelude, extra_mod_attrs, None)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
fn assemble_formatted_with_extend(
|
|
20
|
+
module: &syn::ItemMod,
|
|
21
|
+
prelude: TokenStream,
|
|
22
|
+
extra_mod_attrs: TokenStream,
|
|
23
|
+
extend_macro_name: Option<proc_macro2::Ident>,
|
|
15
24
|
) -> String {
|
|
16
25
|
let overrides = collect_overrides(module);
|
|
17
26
|
let instructions =
|
|
@@ -22,6 +31,7 @@ mod tests {
|
|
|
22
31
|
instructions,
|
|
23
32
|
extra_mod_attrs,
|
|
24
33
|
source_mod: module.clone(),
|
|
34
|
+
extend_macro_name,
|
|
25
35
|
};
|
|
26
36
|
let output = assembly.assemble();
|
|
27
37
|
let file = syn::parse2::<syn::File>(output).expect("assembly output should parse");
|
|
@@ -37,18 +47,18 @@ mod tests {
|
|
|
37
47
|
let module: syn::ItemMod = syn::parse_quote! {
|
|
38
48
|
pub mod my_program {
|
|
39
49
|
#[test_instruction]
|
|
40
|
-
pub fn lz_receive(ctx: Context<MyReceive>, params: LzReceiveParams) -> Result<()> {
|
|
50
|
+
pub fn lz_receive(ctx: &mut Context<MyReceive>, params: &LzReceiveParams) -> Result<()> {
|
|
41
51
|
Ok(())
|
|
42
52
|
}
|
|
43
53
|
}
|
|
44
54
|
};
|
|
45
55
|
|
|
46
|
-
let output = assemble_formatted(&module, quote! {}, quote! {
|
|
56
|
+
let output = assemble_formatted(&module, quote! {}, quote! {});
|
|
47
57
|
insta::assert_snapshot!(output);
|
|
48
58
|
}
|
|
49
59
|
|
|
50
60
|
// -----------------------------------------------------------------------
|
|
51
|
-
// Snapshot:
|
|
61
|
+
// Snapshot: override reusing default accounts
|
|
52
62
|
// -----------------------------------------------------------------------
|
|
53
63
|
|
|
54
64
|
#[test]
|
|
@@ -56,24 +66,24 @@ mod tests {
|
|
|
56
66
|
let module: syn::ItemMod = syn::parse_quote! {
|
|
57
67
|
pub mod my_program {
|
|
58
68
|
#[test_instruction]
|
|
59
|
-
pub fn set_peer(ctx: Context<StdSetPeer>, params: SetPeerParams) -> Result<()> {
|
|
69
|
+
pub fn set_peer(ctx: &mut Context<StdSetPeer>, params: &SetPeerParams) -> Result<()> {
|
|
60
70
|
msg!("custom set_peer logic");
|
|
61
71
|
Ok(())
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
#[test_instruction]
|
|
65
|
-
pub fn lz_receive(ctx: Context<MyReceive>, params: LzReceiveParams) -> Result<()> {
|
|
75
|
+
pub fn lz_receive(ctx: &mut Context<MyReceive>, params: &LzReceiveParams) -> Result<()> {
|
|
66
76
|
Ok(())
|
|
67
77
|
}
|
|
68
78
|
}
|
|
69
79
|
};
|
|
70
80
|
|
|
71
|
-
let output = assemble_formatted(&module, quote! {}, quote! {
|
|
81
|
+
let output = assemble_formatted(&module, quote! {}, quote! {});
|
|
72
82
|
insta::assert_snapshot!(output);
|
|
73
83
|
}
|
|
74
84
|
|
|
75
85
|
// -----------------------------------------------------------------------
|
|
76
|
-
// Snapshot:
|
|
86
|
+
// Snapshot: override with custom accounts
|
|
77
87
|
// -----------------------------------------------------------------------
|
|
78
88
|
|
|
79
89
|
#[test]
|
|
@@ -81,46 +91,46 @@ mod tests {
|
|
|
81
91
|
let module: syn::ItemMod = syn::parse_quote! {
|
|
82
92
|
pub mod my_program {
|
|
83
93
|
#[test_instruction]
|
|
84
|
-
pub fn set_peer(ctx: Context<MyCustomAccounts>, params: SetPeerParams) -> Result<()> {
|
|
94
|
+
pub fn set_peer(ctx: &mut Context<MyCustomAccounts>, params: &SetPeerParams) -> Result<()> {
|
|
85
95
|
msg!("fully custom set_peer");
|
|
86
96
|
Ok(())
|
|
87
97
|
}
|
|
88
98
|
|
|
89
99
|
#[test_instruction]
|
|
90
|
-
pub fn lz_receive(ctx: Context<MyReceive>, params: LzReceiveParams) -> Result<()> {
|
|
100
|
+
pub fn lz_receive(ctx: &mut Context<MyReceive>, params: &LzReceiveParams) -> Result<()> {
|
|
91
101
|
Ok(())
|
|
92
102
|
}
|
|
93
103
|
}
|
|
94
104
|
};
|
|
95
105
|
|
|
96
|
-
let output = assemble_formatted(&module, quote! {}, quote! {
|
|
106
|
+
let output = assemble_formatted(&module, quote! {}, quote! {});
|
|
97
107
|
insta::assert_snapshot!(output);
|
|
98
108
|
}
|
|
99
109
|
|
|
100
110
|
// -----------------------------------------------------------------------
|
|
101
|
-
// Snapshot: mixed (
|
|
111
|
+
// Snapshot: mixed (default + override in one program)
|
|
102
112
|
// -----------------------------------------------------------------------
|
|
103
113
|
|
|
104
114
|
#[test]
|
|
105
115
|
fn snapshot_mixed_overrides() {
|
|
106
116
|
let module: syn::ItemMod = syn::parse_quote! {
|
|
107
117
|
pub mod my_program {
|
|
108
|
-
//
|
|
118
|
+
// Override — custom logic, reusing default accounts
|
|
109
119
|
#[test_instruction]
|
|
110
|
-
pub fn set_peer(ctx: Context<StdSetPeer>, params: SetPeerParams) -> Result<()> {
|
|
120
|
+
pub fn set_peer(ctx: &mut Context<StdSetPeer>, params: &SetPeerParams) -> Result<()> {
|
|
111
121
|
msg!("handler override set_peer");
|
|
112
122
|
Ok(())
|
|
113
123
|
}
|
|
114
124
|
|
|
115
|
-
//
|
|
125
|
+
// Override — custom accounts + custom logic
|
|
116
126
|
#[test_instruction]
|
|
117
|
-
pub fn get_peer(ctx: Context<MyCustomGetPeer>, params: GetPeerParams) -> Result<[u8; 32]> {
|
|
127
|
+
pub fn get_peer(ctx: &Context<MyCustomGetPeer>, params: &GetPeerParams) -> Result<[u8; 32]> {
|
|
118
128
|
Ok([0u8; 32])
|
|
119
129
|
}
|
|
120
130
|
|
|
121
131
|
// Required — must provide
|
|
122
132
|
#[test_instruction]
|
|
123
|
-
pub fn lz_receive(ctx: Context<MyReceive>, params: LzReceiveParams) -> Result<()> {
|
|
133
|
+
pub fn lz_receive(ctx: &mut Context<MyReceive>, params: &LzReceiveParams) -> Result<()> {
|
|
124
134
|
Ok(())
|
|
125
135
|
}
|
|
126
136
|
|
|
@@ -132,8 +142,31 @@ mod tests {
|
|
|
132
142
|
}
|
|
133
143
|
};
|
|
134
144
|
|
|
135
|
-
let output =
|
|
136
|
-
|
|
145
|
+
let output = assemble_formatted(&module, quote! { struct PreludeMarker; }, quote! {});
|
|
146
|
+
insta::assert_snapshot!(output);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// -----------------------------------------------------------------------
|
|
150
|
+
// Snapshot: extend macro emitted alongside defaults
|
|
151
|
+
// -----------------------------------------------------------------------
|
|
152
|
+
|
|
153
|
+
#[test]
|
|
154
|
+
fn snapshot_with_extend_macro() {
|
|
155
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
156
|
+
pub mod my_program {
|
|
157
|
+
#[test_instruction]
|
|
158
|
+
pub fn lz_receive(ctx: &mut Context<MyReceive>, params: &LzReceiveParams) -> Result<()> {
|
|
159
|
+
Ok(())
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
let output = assemble_formatted_with_extend(
|
|
165
|
+
&module,
|
|
166
|
+
quote! {},
|
|
167
|
+
quote! {},
|
|
168
|
+
Some(quote::format_ident!("test_extend_accounts")),
|
|
169
|
+
);
|
|
137
170
|
insta::assert_snapshot!(output);
|
|
138
171
|
}
|
|
139
172
|
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
[toolchain]
|
|
2
|
-
anchor_version = "0.32.1"
|
|
3
|
-
solana_version = "2.3.0"
|
|
4
|
-
|
|
5
|
-
[features]
|
|
6
|
-
seeds = false
|
|
7
|
-
skip-lint = false
|
|
8
|
-
resolution = false
|
|
9
|
-
|
|
10
|
-
[programs.localnet]
|
|
11
|
-
shapes_triangle = "Tri1111111111111111111111111111111111111111"
|
|
12
|
-
shapes_ellipse = "ELp1111111111111111111111111111111111111111"
|
|
13
|
-
|
|
14
|
-
[registry]
|
|
15
|
-
url = "https://api.apr.dev"
|
|
16
|
-
|
|
17
|
-
[provider]
|
|
18
|
-
cluster = "Localnet"
|
|
19
|
-
wallet = "~/.config/solana/id.json"
|