@layerzerolabs/oapp-stellar-contracts 0.2.122
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 +44 -0
- package/LICENSE +23 -0
- package/README.md +5 -0
- package/clippy.toml +6 -0
- package/package.json +53 -0
- package/rust-toolchain.toml +4 -0
- package/rustfmt.toml +15 -0
- package/src/errors.rs +13 -0
- package/src/interfaces/mod.rs +3 -0
- package/src/interfaces/oapp_msg_inspector.rs +70 -0
- package/src/lib.rs +15 -0
- package/src/oapp_core.rs +143 -0
- package/src/oapp_options_type3.rs +133 -0
- package/src/oapp_receiver.rs +195 -0
- package/src/oapp_sender.rs +152 -0
- package/src/tests/mod.rs +5 -0
- package/src/tests/oapp_core.rs +225 -0
- package/src/tests/oapp_options_type3.rs +246 -0
- package/src/tests/oapp_receiver.rs +383 -0
- package/src/tests/oapp_sender.rs +570 -0
- package/src/tests/test_macros.rs +434 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Test 1: Full OApp with all defaults
|
|
3
|
+
// ============================================================================
|
|
4
|
+
mod test_full_default {
|
|
5
|
+
extern crate self as oapp;
|
|
6
|
+
|
|
7
|
+
use endpoint_v2::Origin;
|
|
8
|
+
use oapp::oapp_receiver::LzReceiveInternal;
|
|
9
|
+
use oapp_macros::oapp;
|
|
10
|
+
use soroban_sdk::{Address, Bytes, BytesN, Env};
|
|
11
|
+
|
|
12
|
+
#[oapp]
|
|
13
|
+
#[common_macros::lz_contract]
|
|
14
|
+
struct TestFullDefault;
|
|
15
|
+
|
|
16
|
+
impl LzReceiveInternal for TestFullDefault {
|
|
17
|
+
fn __lz_receive(
|
|
18
|
+
_env: &Env,
|
|
19
|
+
_origin: &Origin,
|
|
20
|
+
_guid: &BytesN<32>,
|
|
21
|
+
_message: &Bytes,
|
|
22
|
+
_extra_data: &Bytes,
|
|
23
|
+
_executor: &Address,
|
|
24
|
+
_value: i128,
|
|
25
|
+
) {
|
|
26
|
+
// Default behavior
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ============================================================================
|
|
32
|
+
// Test 2: Full OApp with manual core implementation
|
|
33
|
+
// ============================================================================
|
|
34
|
+
mod test_full_manual_core {
|
|
35
|
+
extern crate self as oapp;
|
|
36
|
+
|
|
37
|
+
use endpoint_v2::Origin;
|
|
38
|
+
use oapp::oapp_core::OAppCore;
|
|
39
|
+
use oapp::oapp_receiver::LzReceiveInternal;
|
|
40
|
+
use oapp_macros::oapp;
|
|
41
|
+
use soroban_sdk::{contractimpl, Address, Bytes, BytesN, Env};
|
|
42
|
+
|
|
43
|
+
#[oapp(custom = [core])]
|
|
44
|
+
#[common_macros::lz_contract]
|
|
45
|
+
struct TestFullManualCore;
|
|
46
|
+
|
|
47
|
+
#[soroban_sdk::contractimpl(contracttrait)]
|
|
48
|
+
impl utils::rbac::RoleBasedAccessControl for TestFullManualCore {}
|
|
49
|
+
|
|
50
|
+
#[contractimpl(contracttrait)]
|
|
51
|
+
impl OAppCore for TestFullManualCore {
|
|
52
|
+
fn oapp_version(_env: &Env) -> (u64, u64) {
|
|
53
|
+
(2, 0)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
impl LzReceiveInternal for TestFullManualCore {
|
|
58
|
+
fn __lz_receive(
|
|
59
|
+
_env: &Env,
|
|
60
|
+
_origin: &Origin,
|
|
61
|
+
_guid: &BytesN<32>,
|
|
62
|
+
_message: &Bytes,
|
|
63
|
+
_extra_data: &Bytes,
|
|
64
|
+
_executor: &Address,
|
|
65
|
+
_value: i128,
|
|
66
|
+
) {
|
|
67
|
+
// Custom logic
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ============================================================================
|
|
73
|
+
// Test 3: Full OApp with manual sender implementation
|
|
74
|
+
// ============================================================================
|
|
75
|
+
mod test_full_manual_sender {
|
|
76
|
+
extern crate self as oapp;
|
|
77
|
+
|
|
78
|
+
use endpoint_v2::Origin;
|
|
79
|
+
use oapp::oapp_receiver::LzReceiveInternal;
|
|
80
|
+
use oapp::oapp_sender::OAppSenderInternal;
|
|
81
|
+
use oapp_macros::oapp;
|
|
82
|
+
use soroban_sdk::{Address, Bytes, BytesN, Env};
|
|
83
|
+
|
|
84
|
+
#[oapp(custom = [sender])]
|
|
85
|
+
#[common_macros::lz_contract]
|
|
86
|
+
struct TestFullManualSender;
|
|
87
|
+
|
|
88
|
+
impl OAppSenderInternal for TestFullManualSender {
|
|
89
|
+
// Custom sender implementation
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
impl LzReceiveInternal for TestFullManualSender {
|
|
93
|
+
fn __lz_receive(
|
|
94
|
+
_env: &Env,
|
|
95
|
+
_origin: &Origin,
|
|
96
|
+
_guid: &BytesN<32>,
|
|
97
|
+
_message: &Bytes,
|
|
98
|
+
_extra_data: &Bytes,
|
|
99
|
+
_executor: &Address,
|
|
100
|
+
_value: i128,
|
|
101
|
+
) {
|
|
102
|
+
// Implementation
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ============================================================================
|
|
108
|
+
// Test 4: Full OApp with manual receiver implementation
|
|
109
|
+
// ============================================================================
|
|
110
|
+
mod test_full_manual_receiver {
|
|
111
|
+
extern crate self as oapp;
|
|
112
|
+
|
|
113
|
+
use endpoint_v2::Origin;
|
|
114
|
+
use oapp::oapp_receiver::{LzReceiveInternal, OAppReceiver};
|
|
115
|
+
use oapp_macros::oapp;
|
|
116
|
+
use soroban_sdk::{contractimpl, Address, Bytes, BytesN, Env};
|
|
117
|
+
|
|
118
|
+
#[oapp(custom = [receiver])]
|
|
119
|
+
#[common_macros::lz_contract]
|
|
120
|
+
struct TestFullManualReceiver;
|
|
121
|
+
|
|
122
|
+
impl LzReceiveInternal for TestFullManualReceiver {
|
|
123
|
+
fn __lz_receive(
|
|
124
|
+
_env: &Env,
|
|
125
|
+
_origin: &Origin,
|
|
126
|
+
_guid: &BytesN<32>,
|
|
127
|
+
_message: &Bytes,
|
|
128
|
+
_extra_data: &Bytes,
|
|
129
|
+
_executor: &Address,
|
|
130
|
+
_value: i128,
|
|
131
|
+
) {
|
|
132
|
+
// Custom implementation
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
#[contractimpl(contracttrait)]
|
|
137
|
+
impl OAppReceiver for TestFullManualReceiver {
|
|
138
|
+
fn is_compose_msg_sender(_env: &Env, _origin: &Origin, _message: &Bytes, _sender: &Address) -> bool {
|
|
139
|
+
true
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
fn allow_initialize_path(_env: &Env, _origin: &Origin) -> bool {
|
|
143
|
+
true
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
fn next_nonce(_env: &Env, _src_eid: u32, _sender: &BytesN<32>) -> u64 {
|
|
147
|
+
1 // Ordered delivery
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ============================================================================
|
|
153
|
+
// Test 5: Full OApp with manual options_type3 implementation
|
|
154
|
+
// ============================================================================
|
|
155
|
+
mod test_full_manual_options {
|
|
156
|
+
extern crate self as oapp;
|
|
157
|
+
|
|
158
|
+
use endpoint_v2::Origin;
|
|
159
|
+
use oapp::oapp_options_type3::OAppOptionsType3;
|
|
160
|
+
use oapp::oapp_receiver::LzReceiveInternal;
|
|
161
|
+
use oapp_macros::oapp;
|
|
162
|
+
use soroban_sdk::{contractimpl, Address, Bytes, BytesN, Env};
|
|
163
|
+
|
|
164
|
+
#[oapp(custom = [options_type3])]
|
|
165
|
+
#[common_macros::lz_contract]
|
|
166
|
+
struct TestFullManualOptions;
|
|
167
|
+
|
|
168
|
+
impl LzReceiveInternal for TestFullManualOptions {
|
|
169
|
+
fn __lz_receive(
|
|
170
|
+
_env: &Env,
|
|
171
|
+
_origin: &Origin,
|
|
172
|
+
_guid: &BytesN<32>,
|
|
173
|
+
_message: &Bytes,
|
|
174
|
+
_extra_data: &Bytes,
|
|
175
|
+
_executor: &Address,
|
|
176
|
+
_value: i128,
|
|
177
|
+
) {
|
|
178
|
+
// Implementation
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
#[contractimpl(contracttrait)]
|
|
183
|
+
impl OAppOptionsType3 for TestFullManualOptions {
|
|
184
|
+
// Custom options implementation
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// ============================================================================
|
|
189
|
+
// Test 6: Full OApp with manual core + sender
|
|
190
|
+
// ============================================================================
|
|
191
|
+
mod test_full_manual_core_sender {
|
|
192
|
+
extern crate self as oapp;
|
|
193
|
+
|
|
194
|
+
use endpoint_v2::Origin;
|
|
195
|
+
use oapp::{oapp_core::OAppCore, oapp_receiver::LzReceiveInternal, oapp_sender::OAppSenderInternal};
|
|
196
|
+
use oapp_macros::oapp;
|
|
197
|
+
use soroban_sdk::{contractimpl, Address, Bytes, BytesN, Env};
|
|
198
|
+
|
|
199
|
+
#[oapp(custom = [core, sender])]
|
|
200
|
+
#[common_macros::lz_contract]
|
|
201
|
+
struct TestFullManualCoreSender;
|
|
202
|
+
|
|
203
|
+
#[soroban_sdk::contractimpl(contracttrait)]
|
|
204
|
+
impl utils::rbac::RoleBasedAccessControl for TestFullManualCoreSender {}
|
|
205
|
+
|
|
206
|
+
#[contractimpl(contracttrait)]
|
|
207
|
+
impl OAppCore for TestFullManualCoreSender {
|
|
208
|
+
fn oapp_version(_env: &Env) -> (u64, u64) {
|
|
209
|
+
(3, 0)
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
impl OAppSenderInternal for TestFullManualCoreSender {
|
|
214
|
+
// Custom sender implementation
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
impl LzReceiveInternal for TestFullManualCoreSender {
|
|
218
|
+
fn __lz_receive(
|
|
219
|
+
_env: &Env,
|
|
220
|
+
_origin: &Origin,
|
|
221
|
+
_guid: &BytesN<32>,
|
|
222
|
+
_message: &Bytes,
|
|
223
|
+
_extra_data: &Bytes,
|
|
224
|
+
_executor: &Address,
|
|
225
|
+
_value: i128,
|
|
226
|
+
) {
|
|
227
|
+
// Implementation
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// ============================================================================
|
|
233
|
+
// Test 7: Full OApp with manual core + receiver
|
|
234
|
+
// ============================================================================
|
|
235
|
+
mod test_full_manual_core_receiver {
|
|
236
|
+
extern crate self as oapp;
|
|
237
|
+
|
|
238
|
+
use endpoint_v2::Origin;
|
|
239
|
+
use oapp::{
|
|
240
|
+
oapp_core::OAppCore,
|
|
241
|
+
oapp_receiver::{LzReceiveInternal, OAppReceiver},
|
|
242
|
+
};
|
|
243
|
+
use oapp_macros::oapp;
|
|
244
|
+
use soroban_sdk::{contractimpl, Address, Bytes, BytesN, Env};
|
|
245
|
+
|
|
246
|
+
#[oapp(custom = [core, receiver])]
|
|
247
|
+
#[common_macros::lz_contract]
|
|
248
|
+
struct TestFullManualCoreReceiver;
|
|
249
|
+
|
|
250
|
+
#[soroban_sdk::contractimpl(contracttrait)]
|
|
251
|
+
impl utils::rbac::RoleBasedAccessControl for TestFullManualCoreReceiver {}
|
|
252
|
+
|
|
253
|
+
#[contractimpl(contracttrait)]
|
|
254
|
+
impl OAppCore for TestFullManualCoreReceiver {
|
|
255
|
+
fn oapp_version(_env: &Env) -> (u64, u64) {
|
|
256
|
+
(4, 0)
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
impl LzReceiveInternal for TestFullManualCoreReceiver {
|
|
261
|
+
fn __lz_receive(
|
|
262
|
+
_env: &Env,
|
|
263
|
+
_origin: &Origin,
|
|
264
|
+
_guid: &BytesN<32>,
|
|
265
|
+
_message: &Bytes,
|
|
266
|
+
_extra_data: &Bytes,
|
|
267
|
+
_executor: &Address,
|
|
268
|
+
_value: i128,
|
|
269
|
+
) {
|
|
270
|
+
// Custom receiver implementation
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
#[contractimpl(contracttrait)]
|
|
275
|
+
impl OAppReceiver for TestFullManualCoreReceiver {}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// ============================================================================
|
|
279
|
+
// Test 8: Full OApp with manual sender + receiver
|
|
280
|
+
// ============================================================================
|
|
281
|
+
mod test_full_manual_sender_receiver {
|
|
282
|
+
extern crate self as oapp;
|
|
283
|
+
|
|
284
|
+
use endpoint_v2::Origin;
|
|
285
|
+
use oapp::{
|
|
286
|
+
oapp_receiver::{LzReceiveInternal, OAppReceiver},
|
|
287
|
+
oapp_sender::OAppSenderInternal,
|
|
288
|
+
};
|
|
289
|
+
use oapp_macros::oapp;
|
|
290
|
+
use soroban_sdk::{contractimpl, Address, Bytes, BytesN, Env};
|
|
291
|
+
|
|
292
|
+
#[oapp(custom = [sender, receiver])]
|
|
293
|
+
#[common_macros::lz_contract]
|
|
294
|
+
struct TestFullManualSenderReceiver;
|
|
295
|
+
|
|
296
|
+
impl OAppSenderInternal for TestFullManualSenderReceiver {
|
|
297
|
+
// Custom sender implementation
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
impl LzReceiveInternal for TestFullManualSenderReceiver {
|
|
301
|
+
fn __lz_receive(
|
|
302
|
+
_env: &Env,
|
|
303
|
+
_origin: &Origin,
|
|
304
|
+
_guid: &BytesN<32>,
|
|
305
|
+
_message: &Bytes,
|
|
306
|
+
_extra_data: &Bytes,
|
|
307
|
+
_executor: &Address,
|
|
308
|
+
_value: i128,
|
|
309
|
+
) {
|
|
310
|
+
// Custom receiver implementation
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
#[contractimpl(contracttrait)]
|
|
315
|
+
impl OAppReceiver for TestFullManualSenderReceiver {}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// ============================================================================
|
|
319
|
+
// Test 9: Full OApp with manual core + sender + receiver (all except options)
|
|
320
|
+
// ============================================================================
|
|
321
|
+
mod test_full_manual_all_except_options {
|
|
322
|
+
extern crate self as oapp;
|
|
323
|
+
|
|
324
|
+
use endpoint_v2::Origin;
|
|
325
|
+
use oapp::{
|
|
326
|
+
oapp_core::OAppCore,
|
|
327
|
+
oapp_receiver::{LzReceiveInternal, OAppReceiver},
|
|
328
|
+
oapp_sender::OAppSenderInternal,
|
|
329
|
+
};
|
|
330
|
+
use oapp_macros::oapp;
|
|
331
|
+
use soroban_sdk::{contractimpl, Address, Bytes, BytesN, Env};
|
|
332
|
+
|
|
333
|
+
#[oapp(custom = [core, sender, receiver])]
|
|
334
|
+
#[common_macros::lz_contract]
|
|
335
|
+
struct TestFullManualAllExceptOptions;
|
|
336
|
+
|
|
337
|
+
#[soroban_sdk::contractimpl(contracttrait)]
|
|
338
|
+
impl utils::rbac::RoleBasedAccessControl for TestFullManualAllExceptOptions {}
|
|
339
|
+
|
|
340
|
+
#[contractimpl(contracttrait)]
|
|
341
|
+
impl OAppCore for TestFullManualAllExceptOptions {
|
|
342
|
+
fn oapp_version(_env: &Env) -> (u64, u64) {
|
|
343
|
+
(5, 0)
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
impl OAppSenderInternal for TestFullManualAllExceptOptions {
|
|
348
|
+
// Custom sender implementation
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
impl LzReceiveInternal for TestFullManualAllExceptOptions {
|
|
352
|
+
fn __lz_receive(
|
|
353
|
+
_env: &Env,
|
|
354
|
+
_origin: &Origin,
|
|
355
|
+
_guid: &BytesN<32>,
|
|
356
|
+
_message: &Bytes,
|
|
357
|
+
_extra_data: &Bytes,
|
|
358
|
+
_executor: &Address,
|
|
359
|
+
_value: i128,
|
|
360
|
+
) {
|
|
361
|
+
// Custom receiver implementation
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
#[contractimpl(contracttrait)]
|
|
366
|
+
impl OAppReceiver for TestFullManualAllExceptOptions {}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// ============================================================================
|
|
370
|
+
// Test 10: Full OApp with all manual implementations
|
|
371
|
+
// ============================================================================
|
|
372
|
+
mod test_full_manual_all {
|
|
373
|
+
extern crate self as oapp;
|
|
374
|
+
|
|
375
|
+
use endpoint_v2::Origin;
|
|
376
|
+
use oapp::{
|
|
377
|
+
oapp_core::OAppCore,
|
|
378
|
+
oapp_options_type3::OAppOptionsType3,
|
|
379
|
+
oapp_receiver::{LzReceiveInternal, OAppReceiver},
|
|
380
|
+
oapp_sender::OAppSenderInternal,
|
|
381
|
+
};
|
|
382
|
+
use oapp_macros::oapp;
|
|
383
|
+
use soroban_sdk::{contractimpl, Address, Bytes, BytesN, Env};
|
|
384
|
+
|
|
385
|
+
#[oapp(custom = [core, sender, receiver, options_type3])]
|
|
386
|
+
#[common_macros::lz_contract]
|
|
387
|
+
struct TestFullManualAll;
|
|
388
|
+
|
|
389
|
+
#[soroban_sdk::contractimpl(contracttrait)]
|
|
390
|
+
impl utils::rbac::RoleBasedAccessControl for TestFullManualAll {}
|
|
391
|
+
|
|
392
|
+
#[contractimpl(contracttrait)]
|
|
393
|
+
impl OAppCore for TestFullManualAll {
|
|
394
|
+
fn oapp_version(_env: &Env) -> (u64, u64) {
|
|
395
|
+
(6, 0)
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
impl OAppSenderInternal for TestFullManualAll {
|
|
400
|
+
// Custom sender implementation
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
impl LzReceiveInternal for TestFullManualAll {
|
|
404
|
+
fn __lz_receive(
|
|
405
|
+
_env: &Env,
|
|
406
|
+
_origin: &Origin,
|
|
407
|
+
_guid: &BytesN<32>,
|
|
408
|
+
_message: &Bytes,
|
|
409
|
+
_extra_data: &Bytes,
|
|
410
|
+
_executor: &Address,
|
|
411
|
+
_value: i128,
|
|
412
|
+
) {
|
|
413
|
+
// Custom receiver implementation
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
#[contractimpl(contracttrait)]
|
|
418
|
+
impl OAppReceiver for TestFullManualAll {}
|
|
419
|
+
|
|
420
|
+
#[contractimpl(contracttrait)]
|
|
421
|
+
impl OAppOptionsType3 for TestFullManualAll {
|
|
422
|
+
// Custom options implementation
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// ============================================================================
|
|
427
|
+
// Tests
|
|
428
|
+
// ============================================================================
|
|
429
|
+
|
|
430
|
+
#[test]
|
|
431
|
+
fn test_macros_compile() {
|
|
432
|
+
// This test verifies that all macro combinations compile successfully
|
|
433
|
+
assert!(true);
|
|
434
|
+
}
|