@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/override.rs
CHANGED
|
@@ -49,7 +49,6 @@ mod tests {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
fn spec(self, _ctx: &()) -> InstructionSpec<()> {
|
|
52
|
-
// Not called by collect() — only needed for generation tests later.
|
|
53
52
|
unimplemented!("TestIx::spec() is not used in override collection tests")
|
|
54
53
|
}
|
|
55
54
|
}
|
|
@@ -105,20 +104,19 @@ mod tests {
|
|
|
105
104
|
let module: syn::ItemMod = syn::parse_quote! {
|
|
106
105
|
mod my_program {
|
|
107
106
|
#[test_instruction]
|
|
108
|
-
pub fn set_peer(ctx: Context<MyAccounts>, params: SetPeerParams) -> Result<()> {
|
|
107
|
+
pub fn set_peer(ctx: &mut Context<MyAccounts>, params: &SetPeerParams) -> Result<()> {
|
|
109
108
|
Ok(())
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
};
|
|
113
112
|
let overrides = collect_ok(&module);
|
|
114
113
|
|
|
115
|
-
// SetPeer should be detected
|
|
116
114
|
let meta = overrides.get(TestIx::SetPeer).expect("SetPeer override should exist");
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
assert!(
|
|
116
|
+
meta.context_type.to_token_stream().to_string().contains("MyAccounts"),
|
|
117
|
+
"context_type should contain MyAccounts"
|
|
118
|
+
);
|
|
119
119
|
assert_eq!(meta.wrapper_mod.to_string(), "__test_instruction__set_peer_handler");
|
|
120
|
-
|
|
121
|
-
// Others untouched
|
|
122
120
|
assert!(overrides.get(TestIx::GetPeer).is_none());
|
|
123
121
|
assert!(overrides.get(TestIx::LzReceive).is_none());
|
|
124
122
|
}
|
|
@@ -128,12 +126,12 @@ mod tests {
|
|
|
128
126
|
let module: syn::ItemMod = syn::parse_quote! {
|
|
129
127
|
mod my_program {
|
|
130
128
|
#[test_instruction]
|
|
131
|
-
pub fn set_peer(ctx: Context<PeerAccounts>, params: SetPeerParams) -> Result<()> {
|
|
129
|
+
pub fn set_peer(ctx: &mut Context<PeerAccounts>, params: &SetPeerParams) -> Result<()> {
|
|
132
130
|
Ok(())
|
|
133
131
|
}
|
|
134
132
|
|
|
135
133
|
#[test_instruction]
|
|
136
|
-
pub fn lz_receive(ctx: Context<ReceiveAccounts>, params: LzReceiveParams) -> Result<()> {
|
|
134
|
+
pub fn lz_receive(ctx: &mut Context<ReceiveAccounts>, params: &LzReceiveParams) -> Result<()> {
|
|
137
135
|
Ok(())
|
|
138
136
|
}
|
|
139
137
|
}
|
|
@@ -141,12 +139,16 @@ mod tests {
|
|
|
141
139
|
let overrides = collect_ok(&module);
|
|
142
140
|
|
|
143
141
|
let peer = overrides.get(TestIx::SetPeer).expect("SetPeer should exist");
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
assert!(
|
|
143
|
+
peer.context_type.to_token_stream().to_string().contains("PeerAccounts"),
|
|
144
|
+
"context_type should contain PeerAccounts"
|
|
145
|
+
);
|
|
146
146
|
|
|
147
147
|
let recv = overrides.get(TestIx::LzReceive).expect("LzReceive should exist");
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
assert!(
|
|
149
|
+
recv.context_type.to_token_stream().to_string().contains("ReceiveAccounts"),
|
|
150
|
+
"context_type should contain ReceiveAccounts"
|
|
151
|
+
);
|
|
150
152
|
|
|
151
153
|
assert!(overrides.get(TestIx::GetPeer).is_none());
|
|
152
154
|
}
|
|
@@ -157,8 +159,8 @@ mod tests {
|
|
|
157
159
|
mod my_program {
|
|
158
160
|
#[test_instruction]
|
|
159
161
|
pub fn lz_receive<'info>(
|
|
160
|
-
ctx: Context<'_, '_, '_, 'info, MyReceiveAccounts<'info>>,
|
|
161
|
-
params: LzReceiveParams,
|
|
162
|
+
ctx: &mut Context<'_, '_, '_, 'info, MyReceiveAccounts<'info>>,
|
|
163
|
+
params: &LzReceiveParams,
|
|
162
164
|
) -> Result<()> {
|
|
163
165
|
Ok(())
|
|
164
166
|
}
|
|
@@ -167,14 +169,6 @@ mod tests {
|
|
|
167
169
|
let overrides = collect_ok(&module);
|
|
168
170
|
let meta = overrides.get(TestIx::LzReceive).expect("LzReceive should exist");
|
|
169
171
|
|
|
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
172
|
let full_ctx = meta.context_type.to_token_stream().to_string();
|
|
179
173
|
assert!(full_ctx.contains("Context"), "context_type should contain Context: {full_ctx}");
|
|
180
174
|
assert!(
|
|
@@ -186,7 +180,6 @@ mod tests {
|
|
|
186
180
|
"context_type should preserve named lifetimes: {full_ctx}"
|
|
187
181
|
);
|
|
188
182
|
|
|
189
|
-
// Function-level generics should capture <'info>
|
|
190
183
|
let generics = meta.fn_generics.to_token_stream().to_string();
|
|
191
184
|
assert!(generics.contains("'info"), "fn_generics should contain 'info: {generics}");
|
|
192
185
|
}
|
|
@@ -196,7 +189,7 @@ mod tests {
|
|
|
196
189
|
let module: syn::ItemMod = syn::parse_quote! {
|
|
197
190
|
mod my_program {
|
|
198
191
|
#[test_instruction]
|
|
199
|
-
pub fn set_peer(ctx: Context<MyAccounts>, params: SetPeerParams) -> Result<()> {
|
|
192
|
+
pub fn set_peer(ctx: &mut Context<MyAccounts>, params: &SetPeerParams) -> Result<()> {
|
|
200
193
|
Ok(())
|
|
201
194
|
}
|
|
202
195
|
|
|
@@ -212,10 +205,7 @@ mod tests {
|
|
|
212
205
|
let overrides = collect_ok(&module);
|
|
213
206
|
let filtered = overrides.filtered_items(&module).to_string();
|
|
214
207
|
|
|
215
|
-
// Override handler should be removed
|
|
216
208
|
assert!(!filtered.contains("set_peer"), "overridden handler should be filtered out");
|
|
217
|
-
|
|
218
|
-
// Regular items should remain
|
|
219
209
|
assert!(filtered.contains("helper_function"), "regular fn should be kept");
|
|
220
210
|
assert!(filtered.contains("MyState"), "struct should be kept");
|
|
221
211
|
}
|
|
@@ -229,36 +219,49 @@ mod tests {
|
|
|
229
219
|
let module: syn::ItemMod = syn::parse_quote! {
|
|
230
220
|
mod my_program {
|
|
231
221
|
#[test_instruction]
|
|
232
|
-
pub fn get_peer(ctx: Context<GetPeerAccounts>, params: GetPeerParams) -> Result<[u8; 32]> {
|
|
222
|
+
pub fn get_peer(ctx: &Context<GetPeerAccounts>, params: &GetPeerParams) -> Result<[u8; 32]> {
|
|
233
223
|
Ok([0u8; 32])
|
|
234
224
|
}
|
|
235
225
|
}
|
|
236
226
|
};
|
|
237
227
|
let overrides = collect_ok(&module);
|
|
238
|
-
let wrapper = overrides.wrapper_defs.to_string();
|
|
239
228
|
|
|
240
|
-
//
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
"
|
|
244
|
-
);
|
|
229
|
+
// Parse wrapper_defs as a file so we can make structural AST assertions
|
|
230
|
+
// instead of fragile string checks.
|
|
231
|
+
let wrapper_file: syn::File =
|
|
232
|
+
syn::parse2(overrides.wrapper_defs.clone()).expect("wrapper_defs should parse as file");
|
|
245
233
|
|
|
246
|
-
|
|
247
|
-
|
|
234
|
+
let wrapper_mod = wrapper_file
|
|
235
|
+
.items
|
|
236
|
+
.iter()
|
|
237
|
+
.find_map(|item| match item {
|
|
238
|
+
syn::Item::Mod(m) if m.ident == "__test_instruction__get_peer_handler" => Some(m),
|
|
239
|
+
_ => None,
|
|
240
|
+
})
|
|
241
|
+
.expect("wrapper module __test_instruction__get_peer_handler should exist");
|
|
248
242
|
|
|
249
|
-
|
|
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
|
-
);
|
|
243
|
+
let wrapper_items = &wrapper_mod.content.as_ref().expect("wrapper should have body").1;
|
|
256
244
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
245
|
+
let has_handler_fn = wrapper_items
|
|
246
|
+
.iter()
|
|
247
|
+
.any(|item| matches!(item, syn::Item::Fn(f) if f.sig.ident == "get_peer"));
|
|
248
|
+
assert!(has_handler_fn, "handler fn `get_peer` should be inside wrapper module");
|
|
249
|
+
|
|
250
|
+
let handler_fn = wrapper_items
|
|
251
|
+
.iter()
|
|
252
|
+
.find_map(|item| match item {
|
|
253
|
+
syn::Item::Fn(f) if f.sig.ident == "get_peer" => Some(f),
|
|
254
|
+
_ => None,
|
|
255
|
+
})
|
|
256
|
+
.unwrap();
|
|
257
|
+
let has_override_attr =
|
|
258
|
+
handler_fn.attrs.iter().any(|a| a.path().is_ident("test_instruction"));
|
|
259
|
+
assert!(!has_override_attr, "override attr should be stripped in wrapper");
|
|
260
|
+
|
|
261
|
+
let has_use_super = wrapper_items.iter().any(|item| {
|
|
262
|
+
matches!(item, syn::Item::Use(u) if u.to_token_stream().to_string().contains("super :: *"))
|
|
263
|
+
});
|
|
264
|
+
assert!(has_use_super, "wrapper should have `use super::*`");
|
|
262
265
|
}
|
|
263
266
|
|
|
264
267
|
// -----------------------------------------------------------------------
|
|
@@ -325,6 +328,20 @@ mod tests {
|
|
|
325
328
|
assert!(err.contains("Context"), "error should mention Context<T>: {err}");
|
|
326
329
|
}
|
|
327
330
|
|
|
331
|
+
#[test]
|
|
332
|
+
fn error_handler_reference_to_non_context_type() {
|
|
333
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
334
|
+
mod my_program {
|
|
335
|
+
#[test_instruction]
|
|
336
|
+
pub fn set_peer(ctx: &SomethingElse) -> Result<()> {
|
|
337
|
+
Ok(())
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
let err = collect_err(&module);
|
|
342
|
+
assert!(err.contains("Context"), "error should mention Context<T>: {err}");
|
|
343
|
+
}
|
|
344
|
+
|
|
328
345
|
#[test]
|
|
329
346
|
fn error_bare_function_name_collision() {
|
|
330
347
|
let module: syn::ItemMod = syn::parse_quote! {
|
|
@@ -341,6 +358,7 @@ mod tests {
|
|
|
341
358
|
|
|
342
359
|
#[test]
|
|
343
360
|
fn error_duplicate_attribute_on_single_function() {
|
|
361
|
+
// Two `#[test_instruction]` attrs on the same function — caught by `at_most_one()`.
|
|
344
362
|
let module: syn::ItemMod = syn::parse_quote! {
|
|
345
363
|
mod my_program {
|
|
346
364
|
#[test_instruction]
|
|
@@ -354,6 +372,29 @@ mod tests {
|
|
|
354
372
|
assert!(err.contains("duplicate"), "error should mention duplicate: {err}");
|
|
355
373
|
}
|
|
356
374
|
|
|
375
|
+
#[test]
|
|
376
|
+
fn error_two_handlers_overriding_same_instruction() {
|
|
377
|
+
// Two separate functions both named `set_peer` — the second hits
|
|
378
|
+
// `collected.handlers.contains_key(&target)`, a distinct path from
|
|
379
|
+
// the same-function duplicate-attr check above.
|
|
380
|
+
let module: syn::ItemMod = syn::parse_quote! {
|
|
381
|
+
mod my_program {
|
|
382
|
+
#[test_instruction]
|
|
383
|
+
pub fn set_peer(ctx: &mut Context<AccountsA>, params: &SetPeerParams) -> Result<()> {
|
|
384
|
+
Ok(())
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
#[test_instruction]
|
|
388
|
+
pub fn set_peer(ctx: &mut Context<AccountsB>, params: &SetPeerParams) -> Result<()> {
|
|
389
|
+
Ok(())
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
let err = collect_err(&module);
|
|
394
|
+
assert!(err.contains("duplicate"), "error should mention duplicate: {err}");
|
|
395
|
+
assert!(err.contains("set_peer"), "error should mention the instruction name: {err}");
|
|
396
|
+
}
|
|
397
|
+
|
|
357
398
|
// -----------------------------------------------------------------------
|
|
358
399
|
// Tests — boundary conditions
|
|
359
400
|
// -----------------------------------------------------------------------
|
|
@@ -385,13 +426,13 @@ mod tests {
|
|
|
385
426
|
|
|
386
427
|
#[test]
|
|
387
428
|
fn non_override_attrs_preserved_in_wrapper() {
|
|
388
|
-
// A handler with both the override attr and
|
|
389
|
-
// non-override attr should survive relocation into the wrapper module.
|
|
429
|
+
// A handler with both the override attr and a non-override attr —
|
|
430
|
+
// the non-override attr should survive relocation into the wrapper module.
|
|
390
431
|
let module: syn::ItemMod = syn::parse_quote! {
|
|
391
432
|
mod my_program {
|
|
392
433
|
#[inline(always)]
|
|
393
434
|
#[test_instruction]
|
|
394
|
-
pub fn set_peer(ctx: Context<MyAccounts>, params: SetPeerParams) -> Result<()> {
|
|
435
|
+
pub fn set_peer(ctx: &mut Context<MyAccounts>, params: &SetPeerParams) -> Result<()> {
|
|
395
436
|
Ok(())
|
|
396
437
|
}
|
|
397
438
|
}
|
|
@@ -399,13 +440,10 @@ mod tests {
|
|
|
399
440
|
let overrides = collect_ok(&module);
|
|
400
441
|
let wrapper = overrides.wrapper_defs.to_string();
|
|
401
442
|
|
|
402
|
-
// The override attr should be stripped
|
|
403
443
|
assert!(
|
|
404
444
|
!wrapper.contains("# [test_instruction"),
|
|
405
445
|
"override attr should be stripped: {wrapper}"
|
|
406
446
|
);
|
|
407
|
-
|
|
408
|
-
// The #[inline(always)] attr should be preserved
|
|
409
447
|
assert!(
|
|
410
448
|
wrapper.contains("inline"),
|
|
411
449
|
"non-override attrs should be preserved in wrapper: {wrapper}"
|
|
@@ -4,13 +4,40 @@ expression: output
|
|
|
4
4
|
---
|
|
5
5
|
mod __test_instruction__lz_receive_handler {
|
|
6
6
|
use super::*;
|
|
7
|
-
pub fn lz_receive(
|
|
7
|
+
pub fn lz_receive(
|
|
8
|
+
ctx: &mut Context<MyReceive>,
|
|
9
|
+
params: &LzReceiveParams,
|
|
10
|
+
) -> Result<()> {
|
|
8
11
|
Ok(())
|
|
9
12
|
}
|
|
10
13
|
}
|
|
11
|
-
|
|
12
|
-
struct
|
|
13
|
-
|
|
14
|
+
#[derive(Accounts)]
|
|
15
|
+
pub struct StdSetPeer<'info> {
|
|
16
|
+
pub placeholder: UncheckedAccount<'info>,
|
|
17
|
+
}
|
|
18
|
+
impl StdSetPeer<'_> {
|
|
19
|
+
pub fn apply(_ctx: &mut Context<Self>, _params: &SetPeerParams) -> Result<()> {
|
|
20
|
+
unimplemented!()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
#[derive(Accounts)]
|
|
24
|
+
pub struct StdGetPeer<'info> {
|
|
25
|
+
pub placeholder: UncheckedAccount<'info>,
|
|
26
|
+
}
|
|
27
|
+
impl StdGetPeer<'_> {
|
|
28
|
+
pub fn apply(_ctx: &Context<Self>, _params: &GetPeerParams) -> Result<[u8; 32]> {
|
|
29
|
+
unimplemented!()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
#[derive(Accounts)]
|
|
33
|
+
pub struct StdToken<'info> {
|
|
34
|
+
pub placeholder: UncheckedAccount<'info>,
|
|
35
|
+
}
|
|
36
|
+
impl StdToken<'_> {
|
|
37
|
+
pub fn apply(_ctx: &Context<Self>) -> Result<Pubkey> {
|
|
38
|
+
unimplemented!()
|
|
39
|
+
}
|
|
40
|
+
}
|
|
14
41
|
#[program]
|
|
15
42
|
pub mod my_program {
|
|
16
43
|
use super::*;
|
|
@@ -27,7 +54,7 @@ pub mod my_program {
|
|
|
27
54
|
mut ctx: Context<MyReceive>,
|
|
28
55
|
params: LzReceiveParams,
|
|
29
56
|
) -> Result<()> {
|
|
30
|
-
__test_instruction__lz_receive_handler::lz_receive(ctx, params)
|
|
57
|
+
__test_instruction__lz_receive_handler::lz_receive(&mut ctx, ¶ms)
|
|
31
58
|
}
|
|
32
59
|
pub fn token(ctx: Context<StdToken>) -> Result<Pubkey> {
|
|
33
60
|
StdToken::apply(&ctx)
|
|
@@ -5,8 +5,8 @@ expression: output
|
|
|
5
5
|
mod __test_instruction__set_peer_handler {
|
|
6
6
|
use super::*;
|
|
7
7
|
pub fn set_peer(
|
|
8
|
-
ctx: Context<MyCustomAccounts>,
|
|
9
|
-
params: SetPeerParams,
|
|
8
|
+
ctx: &mut Context<MyCustomAccounts>,
|
|
9
|
+
params: &SetPeerParams,
|
|
10
10
|
) -> Result<()> {
|
|
11
11
|
msg!("fully custom set_peer");
|
|
12
12
|
Ok(())
|
|
@@ -14,12 +14,40 @@ mod __test_instruction__set_peer_handler {
|
|
|
14
14
|
}
|
|
15
15
|
mod __test_instruction__lz_receive_handler {
|
|
16
16
|
use super::*;
|
|
17
|
-
pub fn lz_receive(
|
|
17
|
+
pub fn lz_receive(
|
|
18
|
+
ctx: &mut Context<MyReceive>,
|
|
19
|
+
params: &LzReceiveParams,
|
|
20
|
+
) -> Result<()> {
|
|
18
21
|
Ok(())
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
struct
|
|
24
|
+
#[derive(Accounts)]
|
|
25
|
+
pub struct StdSetPeer<'info> {
|
|
26
|
+
pub placeholder: UncheckedAccount<'info>,
|
|
27
|
+
}
|
|
28
|
+
impl StdSetPeer<'_> {
|
|
29
|
+
pub fn apply(_ctx: &mut Context<Self>, _params: &SetPeerParams) -> Result<()> {
|
|
30
|
+
unimplemented!()
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
#[derive(Accounts)]
|
|
34
|
+
pub struct StdGetPeer<'info> {
|
|
35
|
+
pub placeholder: UncheckedAccount<'info>,
|
|
36
|
+
}
|
|
37
|
+
impl StdGetPeer<'_> {
|
|
38
|
+
pub fn apply(_ctx: &Context<Self>, _params: &GetPeerParams) -> Result<[u8; 32]> {
|
|
39
|
+
unimplemented!()
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
#[derive(Accounts)]
|
|
43
|
+
pub struct StdToken<'info> {
|
|
44
|
+
pub placeholder: UncheckedAccount<'info>,
|
|
45
|
+
}
|
|
46
|
+
impl StdToken<'_> {
|
|
47
|
+
pub fn apply(_ctx: &Context<Self>) -> Result<Pubkey> {
|
|
48
|
+
unimplemented!()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
23
51
|
#[program]
|
|
24
52
|
pub mod my_program {
|
|
25
53
|
use super::*;
|
|
@@ -27,7 +55,7 @@ pub mod my_program {
|
|
|
27
55
|
mut ctx: Context<MyCustomAccounts>,
|
|
28
56
|
params: SetPeerParams,
|
|
29
57
|
) -> Result<()> {
|
|
30
|
-
__test_instruction__set_peer_handler::set_peer(ctx, params)
|
|
58
|
+
__test_instruction__set_peer_handler::set_peer(&mut ctx, ¶ms)
|
|
31
59
|
}
|
|
32
60
|
pub fn get_peer(
|
|
33
61
|
ctx: Context<StdGetPeer>,
|
|
@@ -39,7 +67,7 @@ pub mod my_program {
|
|
|
39
67
|
mut ctx: Context<MyReceive>,
|
|
40
68
|
params: LzReceiveParams,
|
|
41
69
|
) -> Result<()> {
|
|
42
|
-
__test_instruction__lz_receive_handler::lz_receive(ctx, params)
|
|
70
|
+
__test_instruction__lz_receive_handler::lz_receive(&mut ctx, ¶ms)
|
|
43
71
|
}
|
|
44
72
|
pub fn token(ctx: Context<StdToken>) -> Result<Pubkey> {
|
|
45
73
|
StdToken::apply(&ctx)
|
|
@@ -4,25 +4,55 @@ expression: output
|
|
|
4
4
|
---
|
|
5
5
|
mod __test_instruction__set_peer_handler {
|
|
6
6
|
use super::*;
|
|
7
|
-
pub fn set_peer(
|
|
7
|
+
pub fn set_peer(
|
|
8
|
+
ctx: &mut Context<StdSetPeer>,
|
|
9
|
+
params: &SetPeerParams,
|
|
10
|
+
) -> Result<()> {
|
|
8
11
|
msg!("custom set_peer logic");
|
|
9
12
|
Ok(())
|
|
10
13
|
}
|
|
11
14
|
}
|
|
12
15
|
mod __test_instruction__lz_receive_handler {
|
|
13
16
|
use super::*;
|
|
14
|
-
pub fn lz_receive(
|
|
17
|
+
pub fn lz_receive(
|
|
18
|
+
ctx: &mut Context<MyReceive>,
|
|
19
|
+
params: &LzReceiveParams,
|
|
20
|
+
) -> Result<()> {
|
|
15
21
|
Ok(())
|
|
16
22
|
}
|
|
17
23
|
}
|
|
18
|
-
|
|
19
|
-
struct
|
|
20
|
-
|
|
24
|
+
#[derive(Accounts)]
|
|
25
|
+
pub struct StdSetPeer<'info> {
|
|
26
|
+
pub placeholder: UncheckedAccount<'info>,
|
|
27
|
+
}
|
|
28
|
+
impl StdSetPeer<'_> {
|
|
29
|
+
pub fn apply(_ctx: &mut Context<Self>, _params: &SetPeerParams) -> Result<()> {
|
|
30
|
+
unimplemented!()
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
#[derive(Accounts)]
|
|
34
|
+
pub struct StdGetPeer<'info> {
|
|
35
|
+
pub placeholder: UncheckedAccount<'info>,
|
|
36
|
+
}
|
|
37
|
+
impl StdGetPeer<'_> {
|
|
38
|
+
pub fn apply(_ctx: &Context<Self>, _params: &GetPeerParams) -> Result<[u8; 32]> {
|
|
39
|
+
unimplemented!()
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
#[derive(Accounts)]
|
|
43
|
+
pub struct StdToken<'info> {
|
|
44
|
+
pub placeholder: UncheckedAccount<'info>,
|
|
45
|
+
}
|
|
46
|
+
impl StdToken<'_> {
|
|
47
|
+
pub fn apply(_ctx: &Context<Self>) -> Result<Pubkey> {
|
|
48
|
+
unimplemented!()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
21
51
|
#[program]
|
|
22
52
|
pub mod my_program {
|
|
23
53
|
use super::*;
|
|
24
54
|
pub fn set_peer(mut ctx: Context<StdSetPeer>, params: SetPeerParams) -> Result<()> {
|
|
25
|
-
__test_instruction__set_peer_handler::set_peer(ctx, params)
|
|
55
|
+
__test_instruction__set_peer_handler::set_peer(&mut ctx, ¶ms)
|
|
26
56
|
}
|
|
27
57
|
pub fn get_peer(
|
|
28
58
|
ctx: Context<StdGetPeer>,
|
|
@@ -34,7 +64,7 @@ pub mod my_program {
|
|
|
34
64
|
mut ctx: Context<MyReceive>,
|
|
35
65
|
params: LzReceiveParams,
|
|
36
66
|
) -> Result<()> {
|
|
37
|
-
__test_instruction__lz_receive_handler::lz_receive(ctx, params)
|
|
67
|
+
__test_instruction__lz_receive_handler::lz_receive(&mut ctx, ¶ms)
|
|
38
68
|
}
|
|
39
69
|
pub fn token(ctx: Context<StdToken>) -> Result<Pubkey> {
|
|
40
70
|
StdToken::apply(&ctx)
|
|
@@ -5,7 +5,10 @@ expression: output
|
|
|
5
5
|
struct PreludeMarker;
|
|
6
6
|
mod __test_instruction__set_peer_handler {
|
|
7
7
|
use super::*;
|
|
8
|
-
pub fn set_peer(
|
|
8
|
+
pub fn set_peer(
|
|
9
|
+
ctx: &mut Context<StdSetPeer>,
|
|
10
|
+
params: &SetPeerParams,
|
|
11
|
+
) -> Result<()> {
|
|
9
12
|
msg!("handler override set_peer");
|
|
10
13
|
Ok(())
|
|
11
14
|
}
|
|
@@ -13,20 +16,48 @@ mod __test_instruction__set_peer_handler {
|
|
|
13
16
|
mod __test_instruction__get_peer_handler {
|
|
14
17
|
use super::*;
|
|
15
18
|
pub fn get_peer(
|
|
16
|
-
ctx: Context<MyCustomGetPeer>,
|
|
17
|
-
params: GetPeerParams,
|
|
19
|
+
ctx: &Context<MyCustomGetPeer>,
|
|
20
|
+
params: &GetPeerParams,
|
|
18
21
|
) -> Result<[u8; 32]> {
|
|
19
22
|
Ok([0u8; 32])
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
mod __test_instruction__lz_receive_handler {
|
|
23
26
|
use super::*;
|
|
24
|
-
pub fn lz_receive(
|
|
27
|
+
pub fn lz_receive(
|
|
28
|
+
ctx: &mut Context<MyReceive>,
|
|
29
|
+
params: &LzReceiveParams,
|
|
30
|
+
) -> Result<()> {
|
|
25
31
|
Ok(())
|
|
26
32
|
}
|
|
27
33
|
}
|
|
28
|
-
|
|
29
|
-
struct
|
|
34
|
+
#[derive(Accounts)]
|
|
35
|
+
pub struct StdSetPeer<'info> {
|
|
36
|
+
pub placeholder: UncheckedAccount<'info>,
|
|
37
|
+
}
|
|
38
|
+
impl StdSetPeer<'_> {
|
|
39
|
+
pub fn apply(_ctx: &mut Context<Self>, _params: &SetPeerParams) -> Result<()> {
|
|
40
|
+
unimplemented!()
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
#[derive(Accounts)]
|
|
44
|
+
pub struct StdGetPeer<'info> {
|
|
45
|
+
pub placeholder: UncheckedAccount<'info>,
|
|
46
|
+
}
|
|
47
|
+
impl StdGetPeer<'_> {
|
|
48
|
+
pub fn apply(_ctx: &Context<Self>, _params: &GetPeerParams) -> Result<[u8; 32]> {
|
|
49
|
+
unimplemented!()
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
#[derive(Accounts)]
|
|
53
|
+
pub struct StdToken<'info> {
|
|
54
|
+
pub placeholder: UncheckedAccount<'info>,
|
|
55
|
+
}
|
|
56
|
+
impl StdToken<'_> {
|
|
57
|
+
pub fn apply(_ctx: &Context<Self>) -> Result<Pubkey> {
|
|
58
|
+
unimplemented!()
|
|
59
|
+
}
|
|
60
|
+
}
|
|
30
61
|
#[program]
|
|
31
62
|
pub mod my_program {
|
|
32
63
|
use super::*;
|
|
@@ -37,19 +68,19 @@ pub mod my_program {
|
|
|
37
68
|
value: u64,
|
|
38
69
|
}
|
|
39
70
|
pub fn set_peer(mut ctx: Context<StdSetPeer>, params: SetPeerParams) -> Result<()> {
|
|
40
|
-
__test_instruction__set_peer_handler::set_peer(ctx, params)
|
|
71
|
+
__test_instruction__set_peer_handler::set_peer(&mut ctx, ¶ms)
|
|
41
72
|
}
|
|
42
73
|
pub fn get_peer(
|
|
43
74
|
ctx: Context<MyCustomGetPeer>,
|
|
44
75
|
params: GetPeerParams,
|
|
45
76
|
) -> Result<[u8; 32]> {
|
|
46
|
-
__test_instruction__get_peer_handler::get_peer(ctx, params)
|
|
77
|
+
__test_instruction__get_peer_handler::get_peer(&ctx, ¶ms)
|
|
47
78
|
}
|
|
48
79
|
pub fn lz_receive(
|
|
49
80
|
mut ctx: Context<MyReceive>,
|
|
50
81
|
params: LzReceiveParams,
|
|
51
82
|
) -> Result<()> {
|
|
52
|
-
__test_instruction__lz_receive_handler::lz_receive(ctx, params)
|
|
83
|
+
__test_instruction__lz_receive_handler::lz_receive(&mut ctx, ¶ms)
|
|
53
84
|
}
|
|
54
85
|
pub fn token(ctx: Context<StdToken>) -> Result<Pubkey> {
|
|
55
86
|
StdToken::apply(&ctx)
|
|
@@ -0,0 +1,82 @@
|
|
|
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(
|
|
8
|
+
ctx: &mut Context<MyReceive>,
|
|
9
|
+
params: &LzReceiveParams,
|
|
10
|
+
) -> Result<()> {
|
|
11
|
+
Ok(())
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
#[derive(Accounts)]
|
|
15
|
+
pub struct StdSetPeer<'info> {
|
|
16
|
+
pub placeholder: UncheckedAccount<'info>,
|
|
17
|
+
}
|
|
18
|
+
impl StdSetPeer<'_> {
|
|
19
|
+
pub fn apply(_ctx: &mut Context<Self>, _params: &SetPeerParams) -> Result<()> {
|
|
20
|
+
unimplemented!()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
#[derive(Accounts)]
|
|
24
|
+
pub struct StdGetPeer<'info> {
|
|
25
|
+
pub placeholder: UncheckedAccount<'info>,
|
|
26
|
+
}
|
|
27
|
+
impl StdGetPeer<'_> {
|
|
28
|
+
pub fn apply(_ctx: &Context<Self>, _params: &GetPeerParams) -> Result<[u8; 32]> {
|
|
29
|
+
unimplemented!()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
#[derive(Accounts)]
|
|
33
|
+
pub struct StdToken<'info> {
|
|
34
|
+
pub placeholder: UncheckedAccount<'info>,
|
|
35
|
+
}
|
|
36
|
+
impl StdToken<'_> {
|
|
37
|
+
pub fn apply(_ctx: &Context<Self>) -> Result<Pubkey> {
|
|
38
|
+
unimplemented!()
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
#[allow(unused_macros)]
|
|
42
|
+
macro_rules! test_extend_accounts {
|
|
43
|
+
(set_peer, $name:ident, { $($extra:tt)* }) => {
|
|
44
|
+
#[derive(Accounts)] pub struct $name < 'info > { pub placeholder :
|
|
45
|
+
UncheckedAccount < 'info >, $($extra)* } impl $name < '_ > { pub fn apply(_ctx :
|
|
46
|
+
& mut Context < Self >, _params : & SetPeerParams) -> Result < () > {
|
|
47
|
+
unimplemented!() } }
|
|
48
|
+
};
|
|
49
|
+
(get_peer, $name:ident, { $($extra:tt)* }) => {
|
|
50
|
+
#[derive(Accounts)] pub struct $name < 'info > { pub placeholder :
|
|
51
|
+
UncheckedAccount < 'info >, $($extra)* } impl $name < '_ > { pub fn apply(_ctx :
|
|
52
|
+
& Context < Self >, _params : & GetPeerParams) -> Result < [u8; 32] > {
|
|
53
|
+
unimplemented!() } }
|
|
54
|
+
};
|
|
55
|
+
(token, $name:ident, { $($extra:tt)* }) => {
|
|
56
|
+
#[derive(Accounts)] pub struct $name < 'info > { pub placeholder :
|
|
57
|
+
UncheckedAccount < 'info >, $($extra)* } impl $name < '_ > { pub fn apply(_ctx :
|
|
58
|
+
& Context < Self >) -> Result < Pubkey > { unimplemented!() } }
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
#[program]
|
|
62
|
+
pub mod my_program {
|
|
63
|
+
use super::*;
|
|
64
|
+
pub fn set_peer(mut ctx: Context<StdSetPeer>, params: SetPeerParams) -> Result<()> {
|
|
65
|
+
StdSetPeer::apply(&mut ctx, ¶ms)
|
|
66
|
+
}
|
|
67
|
+
pub fn get_peer(
|
|
68
|
+
ctx: Context<StdGetPeer>,
|
|
69
|
+
params: GetPeerParams,
|
|
70
|
+
) -> Result<[u8; 32]> {
|
|
71
|
+
StdGetPeer::apply(&ctx, ¶ms)
|
|
72
|
+
}
|
|
73
|
+
pub fn lz_receive(
|
|
74
|
+
mut ctx: Context<MyReceive>,
|
|
75
|
+
params: LzReceiveParams,
|
|
76
|
+
) -> Result<()> {
|
|
77
|
+
__test_instruction__lz_receive_handler::lz_receive(&mut ctx, ¶ms)
|
|
78
|
+
}
|
|
79
|
+
pub fn token(ctx: Context<StdToken>) -> Result<Pubkey> {
|
|
80
|
+
StdToken::apply(&ctx)
|
|
81
|
+
}
|
|
82
|
+
}
|