@layerzerolabs/framework-solana-anchor-trait 0.2.60
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 +18 -0
- package/examples/shapes/Anchor.toml +19 -0
- package/examples/shapes/macros/Cargo.toml +17 -0
- package/examples/shapes/macros/src/instructions/compute_area.rs +50 -0
- package/examples/shapes/macros/src/instructions/compute_perimeter.rs +50 -0
- package/examples/shapes/macros/src/instructions/get_dimension_count.rs +44 -0
- package/examples/shapes/macros/src/instructions/get_name.rs +18 -0
- package/examples/shapes/macros/src/instructions/initialize.rs +18 -0
- package/examples/shapes/macros/src/instructions/mod.rs +26 -0
- package/examples/shapes/macros/src/lib.rs +50 -0
- package/examples/shapes/macros/src/shapes.rs +56 -0
- package/examples/shapes/programs/ellipse/Cargo.toml +30 -0
- package/examples/shapes/programs/ellipse/src/lib.rs +88 -0
- package/examples/shapes/programs/ellipse/src/state.rs +9 -0
- package/examples/shapes/programs/triangle/Cargo.toml +30 -0
- package/examples/shapes/programs/triangle/src/lib.rs +83 -0
- package/examples/shapes/programs/triangle/src/state.rs +9 -0
- package/package.json +36 -0
- package/rust-toolchain.toml +3 -0
- package/rustfmt.toml +23 -0
- package/src/assembly.rs +63 -0
- package/src/generation.rs +226 -0
- package/src/lib.rs +126 -0
- package/src/overrides.rs +289 -0
- package/tests/assembly.rs +339 -0
- package/tests/common/mod.rs +206 -0
- package/tests/declare_instructions.rs +206 -0
- package/tests/generation.rs +358 -0
- package/tests/override.rs +414 -0
- package/tests/snapshots/snapshots__tests__snapshot_all_defaults.snap +35 -0
- package/tests/snapshots/snapshots__tests__snapshot_full_override.snap +47 -0
- package/tests/snapshots/snapshots__tests__snapshot_handler_override.snap +42 -0
- package/tests/snapshots/snapshots__tests__snapshot_mixed_overrides.snap +57 -0
- package/tests/snapshots.rs +139 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
#[cfg(test)]
|
|
2
|
+
mod tests {
|
|
3
|
+
use anchor_trait::{InstructionOverrides, InstructionSet, InstructionSpec, OverrideConfig};
|
|
4
|
+
use quote::ToTokens;
|
|
5
|
+
|
|
6
|
+
// -----------------------------------------------------------------------
|
|
7
|
+
// Test fixtures
|
|
8
|
+
// -----------------------------------------------------------------------
|
|
9
|
+
//
|
|
10
|
+
// NOTE: This file intentionally does NOT use tests/common/mod.rs.
|
|
11
|
+
// Override collection tests use a minimal TestIx (3 variants, no Token,
|
|
12
|
+
// unimplemented spec) to prove that collect() works without needing
|
|
13
|
+
// real InstructionSpec values. Sharing common's 4-variant TestIx would
|
|
14
|
+
// obscure that property and add unnecessary coupling.
|
|
15
|
+
|
|
16
|
+
/// Minimal instruction set for testing. Three variants covering:
|
|
17
|
+
/// - SetPeer: a typical mutable instruction (has default impl in real usage)
|
|
18
|
+
/// - GetPeer: a typical view instruction (has default impl in real usage)
|
|
19
|
+
/// - LzReceive: a required instruction (no default impl in real usage)
|
|
20
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
|
21
|
+
enum TestIx {
|
|
22
|
+
SetPeer,
|
|
23
|
+
GetPeer,
|
|
24
|
+
LzReceive,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
impl InstructionSet for TestIx {
|
|
28
|
+
type Ctx = ();
|
|
29
|
+
|
|
30
|
+
fn all() -> &'static [Self] {
|
|
31
|
+
&[Self::SetPeer, Self::GetPeer, Self::LzReceive]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fn from_ident(ident: &syn::Ident) -> Option<Self> {
|
|
35
|
+
match ident.to_string().as_str() {
|
|
36
|
+
"set_peer" => Some(Self::SetPeer),
|
|
37
|
+
"get_peer" => Some(Self::GetPeer),
|
|
38
|
+
"lz_receive" => Some(Self::LzReceive),
|
|
39
|
+
_ => None,
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
fn canonical_name(&self) -> &'static str {
|
|
44
|
+
match self {
|
|
45
|
+
Self::SetPeer => "set_peer",
|
|
46
|
+
Self::GetPeer => "get_peer",
|
|
47
|
+
Self::LzReceive => "lz_receive",
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fn spec(self, _ctx: &()) -> InstructionSpec<()> {
|
|
52
|
+
// Not called by collect() — only needed for generation tests later.
|
|
53
|
+
unimplemented!("TestIx::spec() is not used in override collection tests")
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const TEST_CONFIG: OverrideConfig =
|
|
58
|
+
OverrideConfig { attr_name: "test_instruction", domain: "Test" };
|
|
59
|
+
|
|
60
|
+
/// Helper: assert collect() succeeds and return the overrides.
|
|
61
|
+
fn collect_ok(module: &syn::ItemMod) -> InstructionOverrides<TestIx> {
|
|
62
|
+
InstructionOverrides::<TestIx>::collect(module, TEST_CONFIG)
|
|
63
|
+
.expect("collect() should succeed")
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// Helper: assert collect() fails and return the error message.
|
|
67
|
+
fn collect_err(module: &syn::ItemMod) -> String {
|
|
68
|
+
match InstructionOverrides::<TestIx>::collect(module, TEST_CONFIG) {
|
|
69
|
+
Err(e) => e.to_string(),
|
|
70
|
+
Ok(_) => panic!("collect() should have failed but succeeded"),
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// -----------------------------------------------------------------------
|
|
75
|
+
// Tests — override collection (happy path)
|
|
76
|
+
// -----------------------------------------------------------------------
|
|
77
|
+
|
|
78
|
+
#[test]
|
|
79
|
+
fn empty_module_returns_no_overrides() {
|
|
80
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
81
|
+
mod my_program {}
|
|
82
|
+
};
|
|
83
|
+
let overrides = collect_ok(&module);
|
|
84
|
+
assert!(overrides.get(TestIx::SetPeer).is_none());
|
|
85
|
+
assert!(overrides.get(TestIx::GetPeer).is_none());
|
|
86
|
+
assert!(overrides.get(TestIx::LzReceive).is_none());
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#[test]
|
|
90
|
+
fn non_handler_functions_are_ignored() {
|
|
91
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
92
|
+
mod my_program {
|
|
93
|
+
fn some_helper() -> u64 { 42 }
|
|
94
|
+
fn another_helper(x: u32) -> u32 { x + 1 }
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
let overrides = collect_ok(&module);
|
|
98
|
+
assert!(overrides.get(TestIx::SetPeer).is_none());
|
|
99
|
+
assert!(overrides.get(TestIx::GetPeer).is_none());
|
|
100
|
+
assert!(overrides.get(TestIx::LzReceive).is_none());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#[test]
|
|
104
|
+
fn single_handler_override_detected() {
|
|
105
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
106
|
+
mod my_program {
|
|
107
|
+
#[test_instruction]
|
|
108
|
+
pub fn set_peer(ctx: Context<MyAccounts>, params: SetPeerParams) -> Result<()> {
|
|
109
|
+
Ok(())
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
let overrides = collect_ok(&module);
|
|
114
|
+
|
|
115
|
+
// SetPeer should be detected
|
|
116
|
+
let meta = overrides.get(TestIx::SetPeer).expect("SetPeer override should exist");
|
|
117
|
+
assert_eq!(meta.fn_ident, "set_peer");
|
|
118
|
+
assert_eq!(meta.accounts_type.to_token_stream().to_string(), "MyAccounts");
|
|
119
|
+
assert_eq!(meta.wrapper_mod.to_string(), "__test_instruction__set_peer_handler");
|
|
120
|
+
|
|
121
|
+
// Others untouched
|
|
122
|
+
assert!(overrides.get(TestIx::GetPeer).is_none());
|
|
123
|
+
assert!(overrides.get(TestIx::LzReceive).is_none());
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
#[test]
|
|
127
|
+
fn multiple_unique_overrides() {
|
|
128
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
129
|
+
mod my_program {
|
|
130
|
+
#[test_instruction]
|
|
131
|
+
pub fn set_peer(ctx: Context<PeerAccounts>, params: SetPeerParams) -> Result<()> {
|
|
132
|
+
Ok(())
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
#[test_instruction]
|
|
136
|
+
pub fn lz_receive(ctx: Context<ReceiveAccounts>, params: LzReceiveParams) -> Result<()> {
|
|
137
|
+
Ok(())
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
let overrides = collect_ok(&module);
|
|
142
|
+
|
|
143
|
+
let peer = overrides.get(TestIx::SetPeer).expect("SetPeer should exist");
|
|
144
|
+
assert_eq!(peer.fn_ident, "set_peer");
|
|
145
|
+
assert_eq!(peer.accounts_type.to_token_stream().to_string(), "PeerAccounts");
|
|
146
|
+
|
|
147
|
+
let recv = overrides.get(TestIx::LzReceive).expect("LzReceive should exist");
|
|
148
|
+
assert_eq!(recv.fn_ident, "lz_receive");
|
|
149
|
+
assert_eq!(recv.accounts_type.to_token_stream().to_string(), "ReceiveAccounts");
|
|
150
|
+
|
|
151
|
+
assert!(overrides.get(TestIx::GetPeer).is_none());
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
#[test]
|
|
155
|
+
fn handler_with_lifetime_generics() {
|
|
156
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
157
|
+
mod my_program {
|
|
158
|
+
#[test_instruction]
|
|
159
|
+
pub fn lz_receive<'info>(
|
|
160
|
+
ctx: Context<'_, '_, '_, 'info, MyReceiveAccounts<'info>>,
|
|
161
|
+
params: LzReceiveParams,
|
|
162
|
+
) -> Result<()> {
|
|
163
|
+
Ok(())
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
let overrides = collect_ok(&module);
|
|
168
|
+
let meta = overrides.get(TestIx::LzReceive).expect("LzReceive should exist");
|
|
169
|
+
|
|
170
|
+
// Inner type is the last type arg: MyReceiveAccounts<'info>
|
|
171
|
+
assert!(meta
|
|
172
|
+
.accounts_type
|
|
173
|
+
.to_token_stream()
|
|
174
|
+
.to_string()
|
|
175
|
+
.contains("MyReceiveAccounts < 'info >"));
|
|
176
|
+
|
|
177
|
+
// Full context_type preserves all lifetimes
|
|
178
|
+
let full_ctx = meta.context_type.to_token_stream().to_string();
|
|
179
|
+
assert!(full_ctx.contains("Context"), "context_type should contain Context: {full_ctx}");
|
|
180
|
+
assert!(
|
|
181
|
+
full_ctx.contains("'_"),
|
|
182
|
+
"context_type should preserve anonymous lifetimes: {full_ctx}"
|
|
183
|
+
);
|
|
184
|
+
assert!(
|
|
185
|
+
full_ctx.contains("'info"),
|
|
186
|
+
"context_type should preserve named lifetimes: {full_ctx}"
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
// Function-level generics should capture <'info>
|
|
190
|
+
let generics = meta.fn_generics.to_token_stream().to_string();
|
|
191
|
+
assert!(generics.contains("'info"), "fn_generics should contain 'info: {generics}");
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
#[test]
|
|
195
|
+
fn filtered_items_removes_overridden_handlers() {
|
|
196
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
197
|
+
mod my_program {
|
|
198
|
+
#[test_instruction]
|
|
199
|
+
pub fn set_peer(ctx: Context<MyAccounts>, params: SetPeerParams) -> Result<()> {
|
|
200
|
+
Ok(())
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
pub fn helper_function() -> u64 {
|
|
204
|
+
42
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
struct MyState {
|
|
208
|
+
value: u64,
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
let overrides = collect_ok(&module);
|
|
213
|
+
let filtered = overrides.filtered_items(&module).to_string();
|
|
214
|
+
|
|
215
|
+
// Override handler should be removed
|
|
216
|
+
assert!(!filtered.contains("set_peer"), "overridden handler should be filtered out");
|
|
217
|
+
|
|
218
|
+
// Regular items should remain
|
|
219
|
+
assert!(filtered.contains("helper_function"), "regular fn should be kept");
|
|
220
|
+
assert!(filtered.contains("MyState"), "struct should be kept");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// -----------------------------------------------------------------------
|
|
224
|
+
// Tests — wrapper module generation
|
|
225
|
+
// -----------------------------------------------------------------------
|
|
226
|
+
|
|
227
|
+
#[test]
|
|
228
|
+
fn wrapper_defs_contain_relocated_handler() {
|
|
229
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
230
|
+
mod my_program {
|
|
231
|
+
#[test_instruction]
|
|
232
|
+
pub fn get_peer(ctx: Context<GetPeerAccounts>, params: GetPeerParams) -> Result<[u8; 32]> {
|
|
233
|
+
Ok([0u8; 32])
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
let overrides = collect_ok(&module);
|
|
238
|
+
let wrapper = overrides.wrapper_defs.to_string();
|
|
239
|
+
|
|
240
|
+
// Wrapper module should exist with the correct name
|
|
241
|
+
assert!(
|
|
242
|
+
wrapper.contains("__test_instruction__get_peer_handler"),
|
|
243
|
+
"wrapper module should be named correctly: {wrapper}"
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
// Handler function should be inside the wrapper
|
|
247
|
+
assert!(wrapper.contains("get_peer"), "handler fn should be inside wrapper: {wrapper}");
|
|
248
|
+
|
|
249
|
+
// The override attribute should be stripped from the relocated handler.
|
|
250
|
+
// The module name itself contains "test_instruction", so check for the
|
|
251
|
+
// attribute syntax specifically: `# [test_instruction` (tokenized form).
|
|
252
|
+
assert!(
|
|
253
|
+
!wrapper.contains("# [test_instruction"),
|
|
254
|
+
"override attr should be stripped in wrapper: {wrapper}"
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
// Wrapper should import parent scope
|
|
258
|
+
assert!(
|
|
259
|
+
wrapper.contains("use super :: *"),
|
|
260
|
+
"wrapper should have `use super::*`: {wrapper}"
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// -----------------------------------------------------------------------
|
|
265
|
+
// Tests — error cases
|
|
266
|
+
// -----------------------------------------------------------------------
|
|
267
|
+
|
|
268
|
+
#[test]
|
|
269
|
+
fn error_unknown_instruction_name() {
|
|
270
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
271
|
+
mod my_program {
|
|
272
|
+
#[test_instruction]
|
|
273
|
+
pub fn nonexistent(ctx: Context<Foo>) -> Result<()> {
|
|
274
|
+
Ok(())
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
let err = collect_err(&module);
|
|
279
|
+
assert!(err.contains("unsupported"), "error should mention unsupported: {err}");
|
|
280
|
+
assert!(err.contains("nonexistent"), "error should mention the bad name: {err}");
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
#[test]
|
|
284
|
+
fn error_attribute_with_arguments_rejected() {
|
|
285
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
286
|
+
mod my_program {
|
|
287
|
+
#[test_instruction(set_peer)]
|
|
288
|
+
pub fn set_peer(ctx: Context<Foo>) -> Result<()> {
|
|
289
|
+
Ok(())
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
let err = collect_err(&module);
|
|
294
|
+
assert!(
|
|
295
|
+
err.contains("does not accept arguments"),
|
|
296
|
+
"error should mention no arguments allowed: {err}"
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
#[test]
|
|
301
|
+
fn error_handler_missing_context_param() {
|
|
302
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
303
|
+
mod my_program {
|
|
304
|
+
#[test_instruction]
|
|
305
|
+
pub fn set_peer() -> Result<()> {
|
|
306
|
+
Ok(())
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
let err = collect_err(&module);
|
|
311
|
+
assert!(err.contains("Context"), "error should mention Context<T>: {err}");
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
#[test]
|
|
315
|
+
fn error_handler_wrong_first_param_type() {
|
|
316
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
317
|
+
mod my_program {
|
|
318
|
+
#[test_instruction]
|
|
319
|
+
pub fn set_peer(x: u64) -> Result<()> {
|
|
320
|
+
Ok(())
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
let err = collect_err(&module);
|
|
325
|
+
assert!(err.contains("Context"), "error should mention Context<T>: {err}");
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
#[test]
|
|
329
|
+
fn error_bare_function_name_collision() {
|
|
330
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
331
|
+
mod my_program {
|
|
332
|
+
pub fn set_peer(ctx: Context<Foo>) -> Result<()> {
|
|
333
|
+
Ok(())
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
let err = collect_err(&module);
|
|
338
|
+
assert!(err.contains("conflicts"), "error should mention conflict: {err}");
|
|
339
|
+
assert!(err.contains("set_peer"), "error should mention the function name: {err}");
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
#[test]
|
|
343
|
+
fn error_duplicate_attribute_on_single_function() {
|
|
344
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
345
|
+
mod my_program {
|
|
346
|
+
#[test_instruction]
|
|
347
|
+
#[test_instruction]
|
|
348
|
+
pub fn set_peer(ctx: Context<Foo>) -> Result<()> {
|
|
349
|
+
Ok(())
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
let err = collect_err(&module);
|
|
354
|
+
assert!(err.contains("duplicate"), "error should mention duplicate: {err}");
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// -----------------------------------------------------------------------
|
|
358
|
+
// Tests — boundary conditions
|
|
359
|
+
// -----------------------------------------------------------------------
|
|
360
|
+
|
|
361
|
+
#[test]
|
|
362
|
+
fn bodiless_module_returns_no_overrides() {
|
|
363
|
+
// `mod foo;` (no body) — collect should return empty, not panic.
|
|
364
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
365
|
+
mod my_program;
|
|
366
|
+
};
|
|
367
|
+
let overrides = collect_ok(&module);
|
|
368
|
+
assert!(overrides.get(TestIx::SetPeer).is_none());
|
|
369
|
+
assert!(overrides.get(TestIx::GetPeer).is_none());
|
|
370
|
+
assert!(overrides.get(TestIx::LzReceive).is_none());
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
#[test]
|
|
374
|
+
fn filtered_items_on_bodiless_module_returns_empty() {
|
|
375
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
376
|
+
mod my_program;
|
|
377
|
+
};
|
|
378
|
+
let overrides = collect_ok(&module);
|
|
379
|
+
let filtered = overrides.filtered_items(&module).to_string();
|
|
380
|
+
assert!(
|
|
381
|
+
filtered.is_empty(),
|
|
382
|
+
"filtered_items on bodiless module should be empty: {filtered}"
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
#[test]
|
|
387
|
+
fn non_override_attrs_preserved_in_wrapper() {
|
|
388
|
+
// A handler with both the override attr and another attr — the
|
|
389
|
+
// non-override attr should survive relocation into the wrapper module.
|
|
390
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
391
|
+
mod my_program {
|
|
392
|
+
#[inline(always)]
|
|
393
|
+
#[test_instruction]
|
|
394
|
+
pub fn set_peer(ctx: Context<MyAccounts>, params: SetPeerParams) -> Result<()> {
|
|
395
|
+
Ok(())
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
let overrides = collect_ok(&module);
|
|
400
|
+
let wrapper = overrides.wrapper_defs.to_string();
|
|
401
|
+
|
|
402
|
+
// The override attr should be stripped
|
|
403
|
+
assert!(
|
|
404
|
+
!wrapper.contains("# [test_instruction"),
|
|
405
|
+
"override attr should be stripped: {wrapper}"
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
// The #[inline(always)] attr should be preserved
|
|
409
|
+
assert!(
|
|
410
|
+
wrapper.contains("inline"),
|
|
411
|
+
"non-override attrs should be preserved in wrapper: {wrapper}"
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
source: crates/anchor-trait/tests/snapshots.rs
|
|
3
|
+
expression: output
|
|
4
|
+
---
|
|
5
|
+
mod __test_instruction__lz_receive_handler {
|
|
6
|
+
use super::*;
|
|
7
|
+
pub fn lz_receive(ctx: Context<MyReceive>, params: LzReceiveParams) -> Result<()> {
|
|
8
|
+
Ok(())
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
struct StdSetPeer;
|
|
12
|
+
struct StdGetPeer;
|
|
13
|
+
struct StdToken;
|
|
14
|
+
#[program]
|
|
15
|
+
pub mod my_program {
|
|
16
|
+
use super::*;
|
|
17
|
+
pub fn set_peer(mut ctx: Context<StdSetPeer>, params: SetPeerParams) -> Result<()> {
|
|
18
|
+
StdSetPeer::apply(&mut ctx, ¶ms)
|
|
19
|
+
}
|
|
20
|
+
pub fn get_peer(
|
|
21
|
+
ctx: Context<StdGetPeer>,
|
|
22
|
+
params: GetPeerParams,
|
|
23
|
+
) -> Result<[u8; 32]> {
|
|
24
|
+
StdGetPeer::apply(&ctx, ¶ms)
|
|
25
|
+
}
|
|
26
|
+
pub fn lz_receive(
|
|
27
|
+
mut ctx: Context<MyReceive>,
|
|
28
|
+
params: LzReceiveParams,
|
|
29
|
+
) -> Result<()> {
|
|
30
|
+
__test_instruction__lz_receive_handler::lz_receive(ctx, params)
|
|
31
|
+
}
|
|
32
|
+
pub fn token(ctx: Context<StdToken>) -> Result<Pubkey> {
|
|
33
|
+
StdToken::apply(&ctx)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
source: crates/anchor-trait/tests/snapshots.rs
|
|
3
|
+
expression: output
|
|
4
|
+
---
|
|
5
|
+
mod __test_instruction__set_peer_handler {
|
|
6
|
+
use super::*;
|
|
7
|
+
pub fn set_peer(
|
|
8
|
+
ctx: Context<MyCustomAccounts>,
|
|
9
|
+
params: SetPeerParams,
|
|
10
|
+
) -> Result<()> {
|
|
11
|
+
msg!("fully custom set_peer");
|
|
12
|
+
Ok(())
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
mod __test_instruction__lz_receive_handler {
|
|
16
|
+
use super::*;
|
|
17
|
+
pub fn lz_receive(ctx: Context<MyReceive>, params: LzReceiveParams) -> Result<()> {
|
|
18
|
+
Ok(())
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
struct StdGetPeer;
|
|
22
|
+
struct StdToken;
|
|
23
|
+
#[program]
|
|
24
|
+
pub mod my_program {
|
|
25
|
+
use super::*;
|
|
26
|
+
pub fn set_peer(
|
|
27
|
+
mut ctx: Context<MyCustomAccounts>,
|
|
28
|
+
params: SetPeerParams,
|
|
29
|
+
) -> Result<()> {
|
|
30
|
+
__test_instruction__set_peer_handler::set_peer(ctx, params)
|
|
31
|
+
}
|
|
32
|
+
pub fn get_peer(
|
|
33
|
+
ctx: Context<StdGetPeer>,
|
|
34
|
+
params: GetPeerParams,
|
|
35
|
+
) -> Result<[u8; 32]> {
|
|
36
|
+
StdGetPeer::apply(&ctx, ¶ms)
|
|
37
|
+
}
|
|
38
|
+
pub fn lz_receive(
|
|
39
|
+
mut ctx: Context<MyReceive>,
|
|
40
|
+
params: LzReceiveParams,
|
|
41
|
+
) -> Result<()> {
|
|
42
|
+
__test_instruction__lz_receive_handler::lz_receive(ctx, params)
|
|
43
|
+
}
|
|
44
|
+
pub fn token(ctx: Context<StdToken>) -> Result<Pubkey> {
|
|
45
|
+
StdToken::apply(&ctx)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
source: crates/anchor-trait/tests/snapshots.rs
|
|
3
|
+
expression: output
|
|
4
|
+
---
|
|
5
|
+
mod __test_instruction__set_peer_handler {
|
|
6
|
+
use super::*;
|
|
7
|
+
pub fn set_peer(ctx: Context<StdSetPeer>, params: SetPeerParams) -> Result<()> {
|
|
8
|
+
msg!("custom set_peer logic");
|
|
9
|
+
Ok(())
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
mod __test_instruction__lz_receive_handler {
|
|
13
|
+
use super::*;
|
|
14
|
+
pub fn lz_receive(ctx: Context<MyReceive>, params: LzReceiveParams) -> Result<()> {
|
|
15
|
+
Ok(())
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
struct StdSetPeer;
|
|
19
|
+
struct StdGetPeer;
|
|
20
|
+
struct StdToken;
|
|
21
|
+
#[program]
|
|
22
|
+
pub mod my_program {
|
|
23
|
+
use super::*;
|
|
24
|
+
pub fn set_peer(mut ctx: Context<StdSetPeer>, params: SetPeerParams) -> Result<()> {
|
|
25
|
+
__test_instruction__set_peer_handler::set_peer(ctx, params)
|
|
26
|
+
}
|
|
27
|
+
pub fn get_peer(
|
|
28
|
+
ctx: Context<StdGetPeer>,
|
|
29
|
+
params: GetPeerParams,
|
|
30
|
+
) -> Result<[u8; 32]> {
|
|
31
|
+
StdGetPeer::apply(&ctx, ¶ms)
|
|
32
|
+
}
|
|
33
|
+
pub fn lz_receive(
|
|
34
|
+
mut ctx: Context<MyReceive>,
|
|
35
|
+
params: LzReceiveParams,
|
|
36
|
+
) -> Result<()> {
|
|
37
|
+
__test_instruction__lz_receive_handler::lz_receive(ctx, params)
|
|
38
|
+
}
|
|
39
|
+
pub fn token(ctx: Context<StdToken>) -> Result<Pubkey> {
|
|
40
|
+
StdToken::apply(&ctx)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
source: crates/anchor-trait/tests/snapshots.rs
|
|
3
|
+
expression: output
|
|
4
|
+
---
|
|
5
|
+
struct PreludeMarker;
|
|
6
|
+
mod __test_instruction__set_peer_handler {
|
|
7
|
+
use super::*;
|
|
8
|
+
pub fn set_peer(ctx: Context<StdSetPeer>, params: SetPeerParams) -> Result<()> {
|
|
9
|
+
msg!("handler override set_peer");
|
|
10
|
+
Ok(())
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
mod __test_instruction__get_peer_handler {
|
|
14
|
+
use super::*;
|
|
15
|
+
pub fn get_peer(
|
|
16
|
+
ctx: Context<MyCustomGetPeer>,
|
|
17
|
+
params: GetPeerParams,
|
|
18
|
+
) -> Result<[u8; 32]> {
|
|
19
|
+
Ok([0u8; 32])
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
mod __test_instruction__lz_receive_handler {
|
|
23
|
+
use super::*;
|
|
24
|
+
pub fn lz_receive(ctx: Context<MyReceive>, params: LzReceiveParams) -> Result<()> {
|
|
25
|
+
Ok(())
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
struct StdSetPeer;
|
|
29
|
+
struct StdToken;
|
|
30
|
+
#[program]
|
|
31
|
+
pub mod my_program {
|
|
32
|
+
use super::*;
|
|
33
|
+
pub fn helper() -> u64 {
|
|
34
|
+
42
|
|
35
|
+
}
|
|
36
|
+
struct MyState {
|
|
37
|
+
value: u64,
|
|
38
|
+
}
|
|
39
|
+
pub fn set_peer(mut ctx: Context<StdSetPeer>, params: SetPeerParams) -> Result<()> {
|
|
40
|
+
__test_instruction__set_peer_handler::set_peer(ctx, params)
|
|
41
|
+
}
|
|
42
|
+
pub fn get_peer(
|
|
43
|
+
ctx: Context<MyCustomGetPeer>,
|
|
44
|
+
params: GetPeerParams,
|
|
45
|
+
) -> Result<[u8; 32]> {
|
|
46
|
+
__test_instruction__get_peer_handler::get_peer(ctx, params)
|
|
47
|
+
}
|
|
48
|
+
pub fn lz_receive(
|
|
49
|
+
mut ctx: Context<MyReceive>,
|
|
50
|
+
params: LzReceiveParams,
|
|
51
|
+
) -> Result<()> {
|
|
52
|
+
__test_instruction__lz_receive_handler::lz_receive(ctx, params)
|
|
53
|
+
}
|
|
54
|
+
pub fn token(ctx: Context<StdToken>) -> Result<Pubkey> {
|
|
55
|
+
StdToken::apply(&ctx)
|
|
56
|
+
}
|
|
57
|
+
}
|