@layerzerolabs/framework-solana-anchor-trait 0.2.62 → 0.2.64

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.
Files changed (50) hide show
  1. package/Cargo.toml +3 -0
  2. package/README.md +316 -0
  3. package/examples/shapes/Cargo.lock +4126 -0
  4. package/examples/shapes/Cargo.toml +16 -0
  5. package/examples/shapes/macros/src/audit.rs +15 -0
  6. package/examples/shapes/macros/src/instructions/clear.rs +19 -0
  7. package/examples/shapes/macros/src/instructions/compute_area.rs +18 -20
  8. package/examples/shapes/macros/src/instructions/compute_perimeter.rs +18 -20
  9. package/examples/shapes/macros/src/instructions/get_dimension.rs +19 -0
  10. package/examples/shapes/macros/src/instructions/get_dimension_count.rs +19 -17
  11. package/examples/shapes/macros/src/instructions/mod.rs +8 -0
  12. package/examples/shapes/macros/src/instructions/reset.rs +50 -0
  13. package/examples/shapes/macros/src/instructions/scale.rs +52 -0
  14. package/examples/shapes/macros/src/lib.rs +14 -11
  15. package/examples/shapes/macros/src/shapes.rs +21 -26
  16. package/examples/shapes/macros/src/state_types.rs +14 -0
  17. package/examples/shapes/programs/ellipse/Cargo.toml +7 -0
  18. package/examples/shapes/programs/ellipse/src/lib.rs +69 -17
  19. package/examples/shapes/programs/ellipse/tests/ellipse/helpers.rs +110 -0
  20. package/examples/shapes/programs/ellipse/tests/ellipse/negative.rs +49 -0
  21. package/examples/shapes/programs/ellipse/tests/ellipse/positive.rs +231 -0
  22. package/examples/shapes/programs/ellipse/tests/ellipse.rs +23 -0
  23. package/examples/shapes/programs/triangle/Cargo.toml +7 -0
  24. package/examples/shapes/programs/triangle/src/lib.rs +69 -16
  25. package/examples/shapes/programs/triangle/tests/triangle/helpers.rs +123 -0
  26. package/examples/shapes/programs/triangle/tests/triangle/negative.rs +49 -0
  27. package/examples/shapes/programs/triangle/tests/triangle/positive.rs +225 -0
  28. package/examples/shapes/programs/triangle/tests/triangle.rs +23 -0
  29. package/examples/shapes/target/deploy/shapes_ellipse-keypair.json +1 -0
  30. package/examples/shapes/target/deploy/shapes_ellipse.so +0 -0
  31. package/examples/shapes/target/deploy/shapes_triangle-keypair.json +1 -0
  32. package/examples/shapes/target/deploy/shapes_triangle.so +0 -0
  33. package/package.json +20 -9
  34. package/src/assembly.rs +41 -6
  35. package/src/generation.rs +108 -131
  36. package/src/lib.rs +6 -4
  37. package/src/overrides.rs +56 -81
  38. package/tests/assembly.rs +154 -23
  39. package/tests/common/mod.rs +68 -14
  40. package/tests/generation.rs +137 -65
  41. package/tests/override.rs +93 -55
  42. package/tests/snapshots/snapshots__tests__snapshot_all_defaults.snap +32 -5
  43. package/tests/snapshots/snapshots__tests__snapshot_full_override.snap +35 -7
  44. package/tests/snapshots/snapshots__tests__snapshot_handler_override.snap +37 -7
  45. package/tests/snapshots/snapshots__tests__snapshot_mixed_overrides.snap +40 -9
  46. package/tests/snapshots/snapshots__tests__snapshot_with_extend_macro.snap +82 -0
  47. package/tests/snapshots.rs +51 -18
  48. package/examples/shapes/Anchor.toml +0 -19
  49. package/examples/shapes/programs/ellipse/src/state.rs +0 -9
  50. package/examples/shapes/programs/triangle/src/state.rs +0 -9
@@ -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! { #[program] });
56
+ let output = assemble_formatted(&module, quote! {}, quote! {});
47
57
  insta::assert_snapshot!(output);
48
58
  }
49
59
 
50
60
  // -----------------------------------------------------------------------
51
- // Snapshot: handler override (custom handler, default accounts)
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! { #[program] });
81
+ let output = assemble_formatted(&module, quote! {}, quote! {});
72
82
  insta::assert_snapshot!(output);
73
83
  }
74
84
 
75
85
  // -----------------------------------------------------------------------
76
- // Snapshot: full override (custom handler + custom accounts)
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! { #[program] });
106
+ let output = assemble_formatted(&module, quote! {}, quote! {});
97
107
  insta::assert_snapshot!(output);
98
108
  }
99
109
 
100
110
  // -----------------------------------------------------------------------
101
- // Snapshot: mixed (all override levels in one program)
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
- // Handler override — custom logic, default accounts
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
- // Full override — custom accounts + custom logic
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
- assemble_formatted(&module, quote! { struct PreludeMarker; }, quote! { #[program] });
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"
@@ -1,9 +0,0 @@
1
- use anchor_lang::prelude::*;
2
-
3
- #[account]
4
- #[derive(InitSpace)]
5
- pub struct ShapeState {
6
- pub width: u64,
7
- pub height: u64,
8
- pub bump: u8,
9
- }
@@ -1,9 +0,0 @@
1
- use anchor_lang::prelude::*;
2
-
3
- #[account]
4
- #[derive(InitSpace)]
5
- pub struct ShapeState {
6
- pub width: u64,
7
- pub height: u64,
8
- pub bump: u8,
9
- }