@layerzerolabs/protocol-stellar-v2 0.2.20 → 0.2.21

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 (198) hide show
  1. package/.turbo/turbo-build.log +783 -802
  2. package/.turbo/turbo-lint.log +320 -157
  3. package/.turbo/turbo-test.log +1414 -1457
  4. package/Cargo.lock +109 -108
  5. package/Cargo.toml +32 -18
  6. package/contracts/common-macros/Cargo.toml +7 -7
  7. package/contracts/common-macros/src/auth.rs +18 -37
  8. package/contracts/common-macros/src/contract_ttl.rs +2 -2
  9. package/contracts/common-macros/src/lib.rs +27 -10
  10. package/contracts/common-macros/src/lz_contract.rs +38 -7
  11. package/contracts/common-macros/src/storage.rs +251 -292
  12. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_multisig_code.snap +6 -12
  13. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_ownable_code.snap +12 -17
  14. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +2 -7
  15. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__upgradeable__snapshot_generated_upgradeable_code.snap +20 -9
  16. package/contracts/common-macros/src/tests/upgradeable.rs +26 -4
  17. package/contracts/common-macros/src/ttl_configurable.rs +2 -10
  18. package/contracts/common-macros/src/ttl_extendable.rs +2 -10
  19. package/contracts/common-macros/src/upgradeable.rs +56 -15
  20. package/contracts/common-macros/src/utils.rs +0 -9
  21. package/contracts/endpoint-v2/src/lib.rs +3 -2
  22. package/contracts/endpoint-v2/src/tests/endpoint_v2/clear.rs +2 -2
  23. package/contracts/endpoint-v2/src/tests/endpoint_v2/lz_receive_alert.rs +3 -3
  24. package/contracts/endpoint-v2/src/tests/endpoint_v2/send.rs +4 -4
  25. package/contracts/endpoint-v2/src/tests/endpoint_v2/set_delegate.rs +17 -5
  26. package/contracts/endpoint-v2/src/tests/endpoint_v2/set_zro.rs +4 -4
  27. package/contracts/endpoint-v2/src/tests/endpoint_v2/verify.rs +2 -2
  28. package/contracts/endpoint-v2/src/tests/message_lib_manager/register_library.rs +2 -2
  29. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_lib_timeout.rs +6 -6
  30. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_library.rs +67 -37
  31. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_send_library.rs +5 -5
  32. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library.rs +44 -54
  33. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library_timeout.rs +7 -7
  34. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_send_library.rs +8 -8
  35. package/contracts/endpoint-v2/src/tests/messaging_channel/burn.rs +3 -3
  36. package/contracts/endpoint-v2/src/tests/messaging_channel/nilify.rs +4 -4
  37. package/contracts/endpoint-v2/src/tests/messaging_channel/skip.rs +3 -3
  38. package/contracts/endpoint-v2/src/tests/messaging_composer/clear_compose.rs +2 -2
  39. package/contracts/endpoint-v2/src/tests/messaging_composer/lz_compose_alert.rs +3 -3
  40. package/contracts/endpoint-v2/src/tests/messaging_composer/send_compose.rs +2 -2
  41. package/contracts/layerzero-views/Cargo.toml +0 -1
  42. package/contracts/layerzero-views/src/layerzero_view.rs +1 -13
  43. package/contracts/macro-integration-tests/Cargo.toml +5 -15
  44. package/contracts/macro-integration-tests/tests/runtime/oapp/mod.rs +48 -0
  45. package/contracts/macro-integration-tests/tests/runtime/oapp/oapp_core.rs +170 -0
  46. package/contracts/macro-integration-tests/tests/runtime/oapp/options_type3.rs +154 -0
  47. package/contracts/macro-integration-tests/tests/runtime/oapp/receiver.rs +338 -0
  48. package/contracts/macro-integration-tests/tests/runtime/oapp/sender.rs +435 -0
  49. package/contracts/macro-integration-tests/tests/runtime.rs +1 -0
  50. package/contracts/macro-integration-tests/tests/ui/oapp/fail/custom_wrong_value.rs +8 -0
  51. package/contracts/macro-integration-tests/tests/ui/oapp/fail/custom_wrong_value.stderr +5 -0
  52. package/contracts/macro-integration-tests/tests/ui/oapp/fail/missing_lz_receive_internal.rs +8 -0
  53. package/contracts/macro-integration-tests/tests/ui/oapp/fail/missing_lz_receive_internal.stderr +71 -0
  54. package/contracts/macro-integration-tests/tests/ui/oapp/fail/non_struct_input.rs +10 -0
  55. package/contracts/macro-integration-tests/tests/ui/oapp/fail/non_struct_input.stderr +5 -0
  56. package/contracts/macro-integration-tests/tests/ui/oapp/fail/unknown_custom_option.rs +8 -0
  57. package/contracts/macro-integration-tests/tests/ui/oapp/fail/unknown_custom_option.stderr +5 -0
  58. package/contracts/macro-integration-tests/tests/ui/oapp/fail/wrong_key.rs +8 -0
  59. package/contracts/macro-integration-tests/tests/ui/oapp/fail/wrong_key.stderr +5 -0
  60. package/contracts/macro-integration-tests/tests/ui/oapp/pass/custom_all.rs +38 -0
  61. package/contracts/macro-integration-tests/tests/ui/oapp/pass/custom_single_trait.rs +96 -0
  62. package/contracts/macro-integration-tests/tests/ui/oapp/pass/minimal_contract.rs +64 -0
  63. package/contracts/macro-integration-tests/tests/ui/oapp/pass/struct_with_fields.rs +46 -0
  64. package/contracts/macro-integration-tests/tests/ui/ownable/fail/only_auth_missing_env.stderr +8 -0
  65. package/contracts/macro-integration-tests/tests/ui/ownable/pass/namespacing_and_imports.rs +1 -1
  66. package/contracts/macro-integration-tests/tests/ui/ownable/pass/only_auth_env_param_variants.rs +1 -1
  67. package/contracts/macro-integration-tests/tests/ui_oapp.rs +11 -0
  68. package/contracts/message-libs/message-lib-common/Cargo.toml +0 -1
  69. package/contracts/message-libs/message-lib-common/src/errors.rs +1 -1
  70. package/contracts/message-libs/treasury/Cargo.toml +0 -2
  71. package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +2 -2
  72. package/contracts/message-libs/uln-302/src/tests/receive_uln302/effective_receive_uln_config.rs +2 -2
  73. package/contracts/message-libs/uln-302/src/tests/receive_uln302/set_default_receive_uln_configs.rs +2 -2
  74. package/contracts/message-libs/uln-302/src/tests/receive_uln302/verify.rs +2 -2
  75. package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_executor_config.rs +2 -2
  76. package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_send_uln_config.rs +2 -2
  77. package/contracts/message-libs/uln-302/src/tests/send_uln302/send.rs +7 -27
  78. package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_executor_configs.rs +2 -2
  79. package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_send_uln_configs.rs +2 -2
  80. package/contracts/oapps/counter/Cargo.toml +4 -6
  81. package/contracts/oapps/counter/integration_tests/utils.rs +19 -12
  82. package/contracts/oapps/oapp/src/errors.rs +1 -1
  83. package/contracts/oapps/oapp/src/interfaces/mod.rs +3 -0
  84. package/contracts/oapps/oapp/src/interfaces/oapp_msg_inspector.rs +47 -0
  85. package/contracts/oapps/oapp/src/lib.rs +1 -0
  86. package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +4 -4
  87. package/contracts/oapps/oapp/src/oapp_core.rs +5 -5
  88. package/contracts/oapps/oapp/src/oapp_options_type3.rs +12 -4
  89. package/contracts/oapps/oapp/src/oapp_receiver.rs +14 -9
  90. package/contracts/oapps/oapp/src/tests/mod.rs +4 -4
  91. package/contracts/oapps/oapp/src/tests/{test_oapp_core.rs → oapp_core.rs} +4 -4
  92. package/contracts/oapps/oapp/src/tests/{test_oapp_options_type3.rs → oapp_options_type3.rs} +3 -4
  93. package/contracts/oapps/oapp-macros/Cargo.toml +8 -4
  94. package/contracts/oapps/oapp-macros/src/generators.rs +9 -34
  95. package/contracts/oapps/oapp-macros/src/lib.rs +3 -0
  96. package/contracts/oapps/oapp-macros/src/tests/mod.rs +2 -0
  97. package/contracts/oapps/oapp-macros/src/tests/oapp.rs +88 -0
  98. package/contracts/oapps/oapp-macros/src/tests/parse_custom_impls.rs +86 -0
  99. package/contracts/oapps/oapp-macros/src/tests/snapshots/oapp_macros__tests__oapp__snapshot_generate_oapp.snap +103 -0
  100. package/contracts/oapps/oft/integration-tests/utils.rs +28 -8
  101. package/contracts/oapps/oft/src/extensions/oft_fee.rs +136 -74
  102. package/contracts/oapps/oft/src/extensions/pausable.rs +44 -10
  103. package/contracts/oapps/oft/src/extensions/rate_limiter.rs +170 -130
  104. package/contracts/oapps/oft/src/oft.rs +19 -12
  105. package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +1 -1
  106. package/contracts/oapps/oft/src/oft_types/mint_burn.rs +1 -1
  107. package/contracts/oapps/oft-core/Cargo.toml +1 -4
  108. package/contracts/oapps/oft-core/integration-tests/setup.rs +2 -2
  109. package/contracts/oapps/oft-core/integration-tests/utils.rs +21 -3
  110. package/contracts/oapps/oft-core/src/errors.rs +3 -2
  111. package/contracts/oapps/oft-core/src/events.rs +6 -0
  112. package/contracts/oapps/oft-core/src/lib.rs +1 -1
  113. package/contracts/oapps/oft-core/src/oft_core.rs +115 -60
  114. package/contracts/oapps/oft-core/src/storage.rs +7 -3
  115. package/contracts/oapps/oft-core/src/tests/mod.rs +1 -0
  116. package/contracts/oapps/oft-core/src/tests/test_decimals.rs +37 -2
  117. package/contracts/oapps/oft-core/src/tests/test_lz_receive.rs +2 -2
  118. package/contracts/oapps/oft-core/src/tests/test_msg_inspector.rs +323 -0
  119. package/contracts/oapps/oft-core/src/tests/test_send.rs +2 -2
  120. package/contracts/oapps/oft-core/src/tests/test_utils.rs +59 -14
  121. package/contracts/utils/Cargo.toml +0 -1
  122. package/contracts/utils/src/errors.rs +1 -1
  123. package/contracts/utils/src/multisig.rs +17 -8
  124. package/contracts/utils/src/ownable.rs +6 -6
  125. package/contracts/utils/src/testing_utils.rs +124 -54
  126. package/contracts/utils/src/tests/multisig.rs +12 -12
  127. package/contracts/utils/src/tests/ownable.rs +6 -6
  128. package/contracts/utils/src/tests/testing_utils.rs +50 -167
  129. package/contracts/utils/src/tests/ttl_configurable.rs +5 -5
  130. package/contracts/utils/src/tests/upgradeable.rs +1 -1
  131. package/contracts/utils/src/ttl_configurable.rs +10 -4
  132. package/contracts/utils/src/upgradeable.rs +5 -5
  133. package/contracts/workers/dvn/Cargo.toml +5 -6
  134. package/contracts/workers/dvn/src/dvn.rs +2 -12
  135. package/contracts/workers/dvn-fee-lib/Cargo.toml +1 -1
  136. package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +37 -19
  137. package/contracts/workers/dvn-fee-lib/src/lib.rs +12 -2
  138. package/contracts/workers/dvn-fee-lib/src/tests/dvn_fee_lib.rs +15 -13
  139. package/contracts/workers/executor/Cargo.toml +3 -0
  140. package/contracts/workers/executor/src/executor.rs +2 -12
  141. package/contracts/workers/executor/src/lib.rs +2 -2
  142. package/contracts/workers/executor/src/tests/auth.rs +394 -0
  143. package/contracts/workers/executor/src/tests/executor.rs +410 -0
  144. package/contracts/workers/executor/src/tests/mod.rs +3 -0
  145. package/contracts/workers/executor/src/tests/setup.rs +250 -0
  146. package/contracts/workers/executor-fee-lib/Cargo.toml +5 -0
  147. package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +1 -12
  148. package/contracts/workers/executor-fee-lib/src/lib.rs +8 -2
  149. package/contracts/workers/executor-helper/Cargo.toml +0 -1
  150. package/contracts/workers/price-feed/Cargo.toml +5 -0
  151. package/contracts/workers/price-feed/src/lib.rs +9 -4
  152. package/contracts/workers/price-feed/src/price_feed.rs +1 -11
  153. package/contracts/workers/worker/src/errors.rs +1 -1
  154. package/contracts/workers/worker/src/tests/setup.rs +1 -1
  155. package/contracts/workers/worker/src/tests/worker.rs +55 -41
  156. package/contracts/workers/worker/src/worker.rs +34 -25
  157. package/docs/error-spec.md +55 -0
  158. package/docs/layerzero-v2-on-stellar.md +447 -0
  159. package/docs/oapp-guide.md +212 -0
  160. package/docs/oft-guide.md +314 -0
  161. package/package.json +3 -3
  162. package/sdk/.turbo/turbo-test.log +260 -257
  163. package/sdk/dist/generated/bml.d.ts +3 -3
  164. package/sdk/dist/generated/bml.js +4 -4
  165. package/sdk/dist/generated/counter.d.ts +295 -295
  166. package/sdk/dist/generated/counter.js +43 -43
  167. package/sdk/dist/generated/dvn.d.ts +91 -91
  168. package/sdk/dist/generated/dvn.js +24 -24
  169. package/sdk/dist/generated/dvn_fee_lib.d.ts +92 -92
  170. package/sdk/dist/generated/dvn_fee_lib.js +25 -25
  171. package/sdk/dist/generated/endpoint.d.ts +99 -99
  172. package/sdk/dist/generated/endpoint.js +16 -16
  173. package/sdk/dist/generated/executor.d.ts +91 -91
  174. package/sdk/dist/generated/executor.js +24 -24
  175. package/sdk/dist/generated/executor_fee_lib.d.ts +92 -92
  176. package/sdk/dist/generated/executor_fee_lib.js +25 -25
  177. package/sdk/dist/generated/executor_helper.d.ts +3 -3
  178. package/sdk/dist/generated/executor_helper.js +4 -4
  179. package/sdk/dist/generated/layerzero_view.d.ts +186 -186
  180. package/sdk/dist/generated/layerzero_view.js +35 -35
  181. package/sdk/dist/generated/oft.d.ts +366 -352
  182. package/sdk/dist/generated/oft.js +74 -79
  183. package/sdk/dist/generated/price_feed.d.ts +198 -198
  184. package/sdk/dist/generated/price_feed.js +39 -39
  185. package/sdk/dist/generated/sml.d.ts +99 -99
  186. package/sdk/dist/generated/sml.js +16 -16
  187. package/sdk/dist/generated/treasury.d.ts +99 -99
  188. package/sdk/dist/generated/treasury.js +16 -16
  189. package/sdk/dist/generated/uln302.d.ts +99 -99
  190. package/sdk/dist/generated/uln302.js +16 -16
  191. package/sdk/dist/generated/upgrader.d.ts +3 -3
  192. package/sdk/dist/generated/upgrader.js +3 -3
  193. package/sdk/package.json +1 -1
  194. package/sdk/test/suites/localnet.ts +84 -20
  195. package/contracts/ERROR_SPEC.md +0 -51
  196. package/contracts/endpoint-v2/ARCHITECTURE.md +0 -233
  197. /package/contracts/oapps/oapp/src/tests/{test_oapp_receiver.rs → oapp_receiver.rs} +0 -0
  198. /package/contracts/oapps/oapp/src/tests/{test_oapp_sender.rs → oapp_sender.rs} +0 -0
@@ -149,10 +149,10 @@ mod test_full_manual_options {
149
149
  extern crate self as oapp;
150
150
 
151
151
  use endpoint_v2::Origin;
152
- use oapp::oapp_options_type3::{EnforcedOptionParam, OAppOptionsType3};
152
+ use oapp::oapp_options_type3::OAppOptionsType3;
153
153
  use oapp::oapp_receiver::LzReceiveInternal;
154
154
  use oapp_macros::oapp;
155
- use soroban_sdk::{contractimpl, Address, Bytes, BytesN, Env, Vec};
155
+ use soroban_sdk::{contractimpl, Address, Bytes, BytesN, Env};
156
156
 
157
157
  #[oapp(custom = [options_type3])]
158
158
  struct TestFullManualOptions;
@@ -354,12 +354,12 @@ mod test_full_manual_all {
354
354
  use endpoint_v2::Origin;
355
355
  use oapp::{
356
356
  oapp_core::OAppCore,
357
- oapp_options_type3::{EnforcedOptionParam, OAppOptionsType3},
357
+ oapp_options_type3::OAppOptionsType3,
358
358
  oapp_receiver::{LzReceiveInternal, OAppReceiver},
359
359
  oapp_sender::OAppSenderInternal,
360
360
  };
361
361
  use oapp_macros::oapp;
362
- use soroban_sdk::{contractimpl, Address, Bytes, BytesN, Env, Vec};
362
+ use soroban_sdk::{contractimpl, Address, Bytes, BytesN, Env};
363
363
 
364
364
  #[oapp(custom = [core, sender, receiver, options_type3])]
365
365
  struct TestFullManualAll;
@@ -57,7 +57,7 @@ pub trait OAppCore: Ownable {
57
57
  /// A tuple containing:
58
58
  /// - `sender_version`: The version of the OAppSender
59
59
  /// - `receiver_version`: The version of the OAppReceiver
60
- fn oapp_version(_env: &Env) -> (u64, u64) {
60
+ fn oapp_version(_env: &soroban_sdk::Env) -> (u64, u64) {
61
61
  (1, 1)
62
62
  }
63
63
 
@@ -65,7 +65,7 @@ pub trait OAppCore: Ownable {
65
65
  ///
66
66
  /// # Returns
67
67
  /// The LayerZero endpoint address
68
- fn endpoint(env: &Env) -> Address {
68
+ fn endpoint(env: &soroban_sdk::Env) -> soroban_sdk::Address {
69
69
  OAppCoreStorage::endpoint(env).unwrap()
70
70
  }
71
71
 
@@ -76,7 +76,7 @@ pub trait OAppCore: Ownable {
76
76
  ///
77
77
  /// # Returns
78
78
  /// The peer address (OApp instance) associated with the corresponding endpoint
79
- fn peer(env: &Env, eid: u32) -> Option<BytesN<32>> {
79
+ fn peer(env: &soroban_sdk::Env, eid: u32) -> Option<soroban_sdk::BytesN<32>> {
80
80
  OAppCoreStorage::peer(env, eid)
81
81
  }
82
82
 
@@ -86,7 +86,7 @@ pub trait OAppCore: Ownable {
86
86
  /// * `eid` - The endpoint ID
87
87
  /// * `peer` - The address of the peer to be associated with the corresponding endpoint, or None to remove the peer
88
88
  #[only_auth]
89
- fn set_peer(env: &Env, eid: u32, peer: &Option<BytesN<32>>) {
89
+ fn set_peer(env: &soroban_sdk::Env, eid: u32, peer: &Option<soroban_sdk::BytesN<32>>) {
90
90
  OAppCoreStorage::set_or_remove_peer(env, eid, peer);
91
91
  PeerSet { eid, peer: peer.clone() }.publish(env);
92
92
  }
@@ -96,7 +96,7 @@ pub trait OAppCore: Ownable {
96
96
  /// # Arguments
97
97
  /// * `delegate` - The address of the delegate to be set, or None to remove the delegate
98
98
  #[only_auth]
99
- fn set_delegate(env: &Env, delegate: &Option<Address>) {
99
+ fn set_delegate(env: &soroban_sdk::Env, delegate: &Option<soroban_sdk::Address>) {
100
100
  endpoint_client::<Self>(env).set_delegate(&env.current_contract_address(), delegate);
101
101
  }
102
102
  }
@@ -1,4 +1,4 @@
1
- use crate::errors::OAppError;
1
+ use crate::{self as oapp, errors::OAppError};
2
2
  use common_macros::{contract_trait, only_auth, storage};
3
3
  use soroban_sdk::{assert_with_error, contractevent, contracttype, panic_with_error, Bytes, Env, Vec};
4
4
  use utils::{buffer_reader::BufferReader, ownable::Ownable};
@@ -40,7 +40,7 @@ pub trait OAppOptionsType3: Ownable {
40
40
  ///
41
41
  /// # Returns
42
42
  /// The enforced options for the given endpoint and message type
43
- fn enforced_options(env: &Env, eid: u32, msg_type: u32) -> Bytes {
43
+ fn enforced_options(env: &soroban_sdk::Env, eid: u32, msg_type: u32) -> soroban_sdk::Bytes {
44
44
  OAppOptionsType3Storage::enforced_options(env, eid, msg_type)
45
45
  }
46
46
 
@@ -55,7 +55,10 @@ pub trait OAppOptionsType3: Ownable {
55
55
  /// # Arguments
56
56
  /// * `options` - A vector of EnforcedOptionParam structures specifying enforced options
57
57
  #[only_auth]
58
- fn set_enforced_options(env: &Env, options: Vec<EnforcedOptionParam>) {
58
+ fn set_enforced_options(
59
+ env: &soroban_sdk::Env,
60
+ options: soroban_sdk::Vec<oapp::oapp_options_type3::EnforcedOptionParam>,
61
+ ) {
59
62
  for option in &options {
60
63
  assert_option_type3(env, &option.options);
61
64
  OAppOptionsType3Storage::set_enforced_options(env, option.eid, option.msg_type, &option.options);
@@ -77,7 +80,12 @@ pub trait OAppOptionsType3: Ownable {
77
80
  ///
78
81
  /// # Returns
79
82
  /// The combination of caller specified options AND enforced options
80
- fn combine_options(env: &Env, eid: u32, msg_type: u32, extra_options: &Bytes) -> Bytes {
83
+ fn combine_options(
84
+ env: &soroban_sdk::Env,
85
+ eid: u32,
86
+ msg_type: u32,
87
+ extra_options: &soroban_sdk::Bytes,
88
+ ) -> soroban_sdk::Bytes {
81
89
  let mut enforced_options = Self::enforced_options(env, eid, msg_type);
82
90
 
83
91
  if enforced_options.is_empty() {
@@ -78,7 +78,7 @@ pub trait OAppReceiver: OAppCore + LzReceiveInternal {
78
78
  ///
79
79
  /// # Returns
80
80
  /// True if the path can be initialized, false otherwise
81
- fn allow_initialize_path(env: &Env, origin: &Origin) -> bool {
81
+ fn allow_initialize_path(env: &soroban_sdk::Env, origin: &endpoint_v2::Origin) -> bool {
82
82
  let peer = Self::peer(env, origin.src_eid);
83
83
  peer.is_some_and(|peer| peer == origin.sender)
84
84
  }
@@ -96,7 +96,7 @@ pub trait OAppReceiver: OAppCore + LzReceiveInternal {
96
96
  ///
97
97
  /// # Returns
98
98
  /// The next nonce
99
- fn next_nonce(_env: &Env, _src_eid: u32, _sender: &BytesN<32>) -> u64 {
99
+ fn next_nonce(_env: &soroban_sdk::Env, _src_eid: u32, _sender: &soroban_sdk::BytesN<32>) -> u64 {
100
100
  0
101
101
  }
102
102
 
@@ -116,12 +116,12 @@ pub trait OAppReceiver: OAppCore + LzReceiveInternal {
116
116
  /// * `extra_data` - Additional arbitrary data provided by the corresponding executor
117
117
  /// * `value` - The native token value sent with the message
118
118
  fn lz_receive(
119
- env: &Env,
120
- executor: &Address,
121
- origin: &Origin,
122
- guid: &BytesN<32>,
123
- message: &Bytes,
124
- extra_data: &Bytes,
119
+ env: &soroban_sdk::Env,
120
+ executor: &soroban_sdk::Address,
121
+ origin: &endpoint_v2::Origin,
122
+ guid: &soroban_sdk::BytesN<32>,
123
+ message: &soroban_sdk::Bytes,
124
+ extra_data: &soroban_sdk::Bytes,
125
125
  value: i128,
126
126
  ) {
127
127
  clear_payload_and_transfer::<Self>(env, executor, origin, guid, message, value);
@@ -140,7 +140,12 @@ pub trait OAppReceiver: OAppCore + LzReceiveInternal {
140
140
  ///
141
141
  /// # Returns
142
142
  /// True if the sender is a valid composeMsg sender, false otherwise
143
- fn is_compose_msg_sender(env: &Env, _origin: &Origin, _message: &Bytes, sender: &Address) -> bool {
143
+ fn is_compose_msg_sender(
144
+ env: &soroban_sdk::Env,
145
+ _origin: &endpoint_v2::Origin,
146
+ _message: &soroban_sdk::Bytes,
147
+ sender: &soroban_sdk::Address,
148
+ ) -> bool {
144
149
  env.current_contract_address() == *sender
145
150
  }
146
151
  }
@@ -1,4 +1,4 @@
1
- mod test_oapp_core;
2
- mod test_oapp_options_type3;
3
- mod test_oapp_receiver;
4
- mod test_oapp_sender;
1
+ mod oapp_core;
2
+ mod oapp_options_type3;
3
+ mod oapp_receiver;
4
+ mod oapp_sender;
@@ -5,7 +5,7 @@ use soroban_sdk::{
5
5
  testutils::{Address as _, MockAuth, MockAuthInvoke},
6
6
  Address, Bytes, BytesN, Env, IntoVal,
7
7
  };
8
- use utils::testing_utils::assert_event;
8
+ use utils::testing_utils::assert_eq_event;
9
9
 
10
10
  #[contract]
11
11
  pub struct DummyEndpoint;
@@ -144,7 +144,7 @@ fn test_peer_lifecycle_set_get_update_remove_and_events() {
144
144
  let peer_v1_option = Some(peer_v1.clone());
145
145
  set_peer_with_auth(&env, &owner, &oapp_client, REMOTE_EID, &peer_v1_option);
146
146
 
147
- assert_event(&env, &oapp_client.address, PeerSet { eid: REMOTE_EID, peer: Some(peer_v1.clone()) });
147
+ assert_eq_event(&env, &oapp_client.address, PeerSet { eid: REMOTE_EID, peer: Some(peer_v1.clone()) });
148
148
  assert_eq!(Some(peer_v1), oapp_client.peer(&REMOTE_EID));
149
149
  assert_eq!(None, oapp_client.peer(&UNSET_EID));
150
150
 
@@ -153,13 +153,13 @@ fn test_peer_lifecycle_set_get_update_remove_and_events() {
153
153
  let peer_v2_option = Some(peer_v2.clone());
154
154
  set_peer_with_auth(&env, &owner, &oapp_client, REMOTE_EID, &peer_v2_option);
155
155
 
156
- assert_event(&env, &oapp_client.address, PeerSet { eid: REMOTE_EID, peer: Some(peer_v2.clone()) });
156
+ assert_eq_event(&env, &oapp_client.address, PeerSet { eid: REMOTE_EID, peer: Some(peer_v2.clone()) });
157
157
  assert_eq!(Some(peer_v2), oapp_client.peer(&REMOTE_EID));
158
158
 
159
159
  // Remove peer
160
160
  let none_peer: Option<BytesN<32>> = None;
161
161
  set_peer_with_auth(&env, &owner, &oapp_client, REMOTE_EID, &none_peer);
162
- assert_event(&env, &oapp_client.address, PeerSet { eid: REMOTE_EID, peer: None });
162
+ assert_eq_event(&env, &oapp_client.address, PeerSet { eid: REMOTE_EID, peer: None });
163
163
  assert_eq!(None, oapp_client.peer(&REMOTE_EID));
164
164
  }
165
165
 
@@ -6,13 +6,12 @@ use crate::{
6
6
  oapp_receiver::{LzReceiveInternal, OAppReceiver},
7
7
  };
8
8
  use common_macros::contract_impl;
9
- use endpoint_v2::Origin;
10
9
  use soroban_sdk::{
11
10
  contract, contractimpl,
12
11
  testutils::{Address as _, MockAuth, MockAuthInvoke},
13
12
  vec, Address, Bytes, BytesN, Env, IntoVal,
14
13
  };
15
- use utils::testing_utils::assert_event;
14
+ use utils::testing_utils::assert_eq_event;
16
15
 
17
16
  const OPTION_TYPE_3: u32 = 3;
18
17
  const REMOTE_EID_1: u32 = 100;
@@ -120,7 +119,7 @@ fn test_enforced_options_lifecycle() {
120
119
  set_enforced_options_with_auth(&env, &owner, &oapp_client, &enforced_params);
121
120
 
122
121
  // assert events
123
- assert_event(&env, &oapp_client.address, EnforcedOptionSet { enforced_option_params: enforced_params.clone() });
122
+ assert_eq_event(&env, &oapp_client.address, EnforcedOptionSet { enforced_option_params: enforced_params.clone() });
124
123
 
125
124
  // Verify options were set correctly
126
125
  assert_eq!(oapp_client.enforced_options(&REMOTE_EID_1, &MSG_TYPE_SEND), enforced1.clone());
@@ -131,7 +130,7 @@ fn test_enforced_options_lifecycle() {
131
130
  let update_params =
132
131
  vec![&env, EnforcedOptionParam { eid: REMOTE_EID_1, msg_type: MSG_TYPE_SEND, options: updated.clone() }];
133
132
  set_enforced_options_with_auth(&env, &owner, &oapp_client, &update_params);
134
- assert_event(&env, &oapp_client.address, EnforcedOptionSet { enforced_option_params: update_params.clone() });
133
+ assert_eq_event(&env, &oapp_client.address, EnforcedOptionSet { enforced_option_params: update_params.clone() });
135
134
  assert_eq!(oapp_client.enforced_options(&REMOTE_EID_1, &MSG_TYPE_SEND), updated);
136
135
  }
137
136
 
@@ -9,7 +9,11 @@ publish = false
9
9
  proc-macro = true
10
10
 
11
11
  [dependencies]
12
- heck = "0.5"
13
- proc-macro2 = "1.0"
14
- quote = "1.0"
15
- syn = { version = "2.0", features = ["full", "extra-traits"] }
12
+ heck = { workspace = true }
13
+ proc-macro2 = { workspace = true }
14
+ quote = { workspace = true }
15
+ syn = { workspace = true }
16
+
17
+ [dev-dependencies]
18
+ insta = { workspace = true }
19
+ prettyplease = { workspace = true }
@@ -1,7 +1,6 @@
1
1
  //! Code generators for OApp trait implementations.
2
2
 
3
3
  use crate::CustomImpls;
4
- use heck::ToSnakeCase;
5
4
  use proc_macro2::TokenStream;
6
5
  use quote::quote;
7
6
  use syn::{Ident, ItemStruct};
@@ -43,17 +42,11 @@ fn generate_oapp_core(name: &Ident, custom: bool) -> TokenStream {
43
42
  return TokenStream::new();
44
43
  }
45
44
 
46
- let impl_mod = impl_mod_ident(name, "core");
47
-
48
45
  quote! {
49
- #[doc(hidden)]
50
- mod #impl_mod {
51
- use super::*;
52
- use oapp::oapp_core::OAppCore;
46
+ use oapp::oapp_core::OAppCore as _;
53
47
 
54
- #[soroban_sdk::contractimpl(contracttrait)]
55
- impl OAppCore for #name {}
56
- }
48
+ #[soroban_sdk::contractimpl(contracttrait)]
49
+ impl oapp::oapp_core::OAppCore for #name {}
57
50
  }
58
51
  }
59
52
 
@@ -84,17 +77,11 @@ fn generate_oapp_receiver(name: &Ident, custom: bool) -> TokenStream {
84
77
  return TokenStream::new();
85
78
  }
86
79
 
87
- let impl_mod = impl_mod_ident(name, "receiver");
88
-
89
80
  quote! {
90
- #[doc(hidden)]
91
- mod #impl_mod {
92
- use super::*;
93
- use oapp::oapp_receiver::OAppReceiver;
81
+ use oapp::oapp_receiver::OAppReceiver as _;
94
82
 
95
- #[soroban_sdk::contractimpl(contracttrait)]
96
- impl OAppReceiver for #name {}
97
- }
83
+ #[soroban_sdk::contractimpl(contracttrait)]
84
+ impl oapp::oapp_receiver::OAppReceiver for #name {}
98
85
  }
99
86
  }
100
87
 
@@ -107,22 +94,10 @@ fn generate_oapp_options_type3(name: &Ident, custom: bool) -> TokenStream {
107
94
  return TokenStream::new();
108
95
  }
109
96
 
110
- let impl_mod = impl_mod_ident(name, "options_type3");
111
-
112
97
  quote! {
113
- #[doc(hidden)]
114
- mod #impl_mod {
115
- use super::*;
116
- use soroban_sdk::Vec;
117
- use oapp::oapp_options_type3::{EnforcedOptionParam, OAppOptionsType3};
98
+ use oapp::oapp_options_type3::OAppOptionsType3 as _;
118
99
 
119
- #[soroban_sdk::contractimpl(contracttrait)]
120
- impl OAppOptionsType3 for #name {}
121
- }
100
+ #[soroban_sdk::contractimpl(contracttrait)]
101
+ impl oapp::oapp_options_type3::OAppOptionsType3 for #name {}
122
102
  }
123
103
  }
124
-
125
- /// Creates a unique hidden module identifier for trait implementations.
126
- fn impl_mod_ident(struct_name: &Ident, trait_name: &str) -> Ident {
127
- Ident::new(&format!("__oapp_{}_impl_{}", trait_name, struct_name.to_string().to_snake_case()), struct_name.span())
128
- }
@@ -132,6 +132,9 @@ use syn::{
132
132
  Error, Ident, ItemStruct, Token,
133
133
  };
134
134
 
135
+ #[cfg(test)]
136
+ mod tests;
137
+
135
138
  /// Derives a complete OApp: `#[contract]` + `#[ownable]` + Core + Sender + Receiver + OptionsType3.
136
139
  ///
137
140
  /// ## Usage
@@ -0,0 +1,2 @@
1
+ mod oapp;
2
+ mod parse_custom_impls;
@@ -0,0 +1,88 @@
1
+ use quote::quote;
2
+
3
+ // ============================================
4
+ // Snapshot Tests: OApp Code Generation
5
+ // ============================================
6
+
7
+ #[test]
8
+ fn snapshot_generate_oapp() {
9
+ let input = quote! {
10
+ pub struct MyOApp;
11
+ };
12
+ let item_struct: syn::ItemStruct = syn::parse2(input).expect("failed to parse struct");
13
+
14
+ let all_defaults = {
15
+ let result = crate::generators::generate_oapp(item_struct.clone(), crate::CustomImpls::default());
16
+ prettyplease::unparse(&syn::parse2::<syn::File>(result).expect("failed to parse generated code"))
17
+ };
18
+
19
+ let custom_core_only = {
20
+ let result = crate::generators::generate_oapp(
21
+ item_struct.clone(),
22
+ crate::CustomImpls { core: true, sender: false, receiver: false, options_type3: false },
23
+ );
24
+ prettyplease::unparse(&syn::parse2::<syn::File>(result).expect("failed to parse generated code"))
25
+ };
26
+
27
+ let custom_sender_only = {
28
+ let result = crate::generators::generate_oapp(
29
+ item_struct.clone(),
30
+ crate::CustomImpls { core: false, sender: true, receiver: false, options_type3: false },
31
+ );
32
+ prettyplease::unparse(&syn::parse2::<syn::File>(result).expect("failed to parse generated code"))
33
+ };
34
+
35
+ let custom_receiver_only = {
36
+ let result = crate::generators::generate_oapp(
37
+ item_struct.clone(),
38
+ crate::CustomImpls { core: false, sender: false, receiver: true, options_type3: false },
39
+ );
40
+ prettyplease::unparse(&syn::parse2::<syn::File>(result).expect("failed to parse generated code"))
41
+ };
42
+
43
+ let custom_options_type3_only = {
44
+ let result = crate::generators::generate_oapp(
45
+ item_struct.clone(),
46
+ crate::CustomImpls { core: false, sender: false, receiver: false, options_type3: true },
47
+ );
48
+ prettyplease::unparse(&syn::parse2::<syn::File>(result).expect("failed to parse generated code"))
49
+ };
50
+
51
+ let custom_all = {
52
+ let result = crate::generators::generate_oapp(
53
+ item_struct.clone(),
54
+ crate::CustomImpls { core: true, sender: true, receiver: true, options_type3: true },
55
+ );
56
+ prettyplease::unparse(&syn::parse2::<syn::File>(result).expect("failed to parse generated code"))
57
+ };
58
+
59
+ let preserves_struct_attributes_and_fields = {
60
+ let fancy_input = quote! {
61
+ #[derive(Clone, Debug)]
62
+ pub struct FancyOApp {
63
+ pub x: u32,
64
+ }
65
+ };
66
+ let fancy_struct: syn::ItemStruct = syn::parse2(fancy_input).expect("failed to parse struct");
67
+ let result = crate::generators::generate_oapp(fancy_struct, crate::CustomImpls::default());
68
+ prettyplease::unparse(&syn::parse2::<syn::File>(result).expect("failed to parse generated code"))
69
+ };
70
+
71
+ let combined = format!(
72
+ "// === Default (no custom impls) ===\n\n{}\n\n\
73
+ // === custom = [core] ===\n\n{}\n\n\
74
+ // === custom = [sender] ===\n\n{}\n\n\
75
+ // === custom = [receiver] ===\n\n{}\n\n\
76
+ // === custom = [options_type3] ===\n\n{}\n\n\
77
+ // === custom = [core, sender, receiver, options_type3] ===\n\n{}\n\n\
78
+ // === Struct attributes + fields are preserved ===\n\n{}",
79
+ all_defaults,
80
+ custom_core_only,
81
+ custom_sender_only,
82
+ custom_receiver_only,
83
+ custom_options_type3_only,
84
+ custom_all,
85
+ preserves_struct_attributes_and_fields
86
+ );
87
+ insta::assert_snapshot!(combined);
88
+ }
@@ -0,0 +1,86 @@
1
+ use quote::quote;
2
+
3
+ // ============================================
4
+ // Unit Tests: #[oapp(custom = [...])] parsing
5
+ // ============================================
6
+
7
+ #[test]
8
+ fn test_custom_impls_parse_empty_is_default() {
9
+ let parsed: crate::CustomImpls = syn::parse2(quote! {}).expect("failed to parse empty attrs");
10
+ assert!(!parsed.core);
11
+ assert!(!parsed.sender);
12
+ assert!(!parsed.receiver);
13
+ assert!(!parsed.options_type3);
14
+ }
15
+
16
+ #[test]
17
+ fn test_custom_impls_parse_valid_all_list() {
18
+ let parsed: crate::CustomImpls =
19
+ syn::parse2(quote! { custom = [core, sender, receiver, options_type3] }).expect("failed to parse attrs");
20
+ assert!(parsed.core);
21
+ assert!(parsed.sender);
22
+ assert!(parsed.receiver);
23
+ assert!(parsed.options_type3);
24
+ }
25
+
26
+ #[test]
27
+ fn test_custom_impls_parse_empty_custom_list_is_default() {
28
+ let parsed: crate::CustomImpls = syn::parse2(quote! { custom = [] }).expect("failed to parse attrs");
29
+ assert!(!parsed.core);
30
+ assert!(!parsed.sender);
31
+ assert!(!parsed.receiver);
32
+ assert!(!parsed.options_type3);
33
+ }
34
+
35
+ #[test]
36
+ fn test_custom_impls_allows_trailing_comma() {
37
+ let parsed: crate::CustomImpls = syn::parse2(quote! { custom = [core,] }).expect("failed to parse attrs");
38
+ assert!(parsed.core);
39
+ assert!(!parsed.sender);
40
+ assert!(!parsed.receiver);
41
+ assert!(!parsed.options_type3);
42
+ }
43
+
44
+ #[test]
45
+ fn test_custom_impls_allows_duplicates() {
46
+ // Duplicates are harmless and should not cause parsing to fail.
47
+ let parsed: crate::CustomImpls =
48
+ syn::parse2(quote! { custom = [core, core, receiver, receiver] }).expect("failed to parse attrs");
49
+ assert!(parsed.core);
50
+ assert!(!parsed.sender);
51
+ assert!(parsed.receiver);
52
+ assert!(!parsed.options_type3);
53
+ }
54
+
55
+ #[test]
56
+ fn test_custom_impls_rejects_wrong_key() {
57
+ let err = syn::parse2::<crate::CustomImpls>(quote! { nope = [core] }).expect_err("expected parse failure");
58
+ assert!(err.to_string().contains("expected `custom`"), "unexpected error: {err}");
59
+ }
60
+
61
+ #[test]
62
+ fn test_custom_impls_rejects_unknown_ident() {
63
+ let err =
64
+ syn::parse2::<crate::CustomImpls>(quote! { custom = [core, not_a_real_option] }).expect_err("expected failure");
65
+ assert!(
66
+ err.to_string().contains("expected one of `core`, `sender`, `receiver`, `options_type3`"),
67
+ "unexpected error: {err}"
68
+ );
69
+ }
70
+
71
+ #[test]
72
+ fn test_custom_impls_rejects_trailing_tokens_after_list() {
73
+ // `syn::parse2` expects the parser to consume the full stream.
74
+ syn::parse2::<crate::CustomImpls>(quote! { custom = [core] extra })
75
+ .expect_err("expected parse failure due to trailing tokens");
76
+ }
77
+
78
+ #[test]
79
+ fn test_custom_impls_rejects_missing_equals() {
80
+ syn::parse2::<crate::CustomImpls>(quote! { custom [core] }).expect_err("expected parse failure (missing `=`)");
81
+ }
82
+
83
+ #[test]
84
+ fn test_custom_impls_rejects_non_bracketed_list() {
85
+ syn::parse2::<crate::CustomImpls>(quote! { custom = (core) }).expect_err("expected parse failure (not `[...]`)");
86
+ }
@@ -0,0 +1,103 @@
1
+ ---
2
+ source: contracts/oapps/oapp-macros/src/tests/oapp.rs
3
+ assertion_line: 87
4
+ expression: combined
5
+ ---
6
+ // === Default (no custom impls) ===
7
+
8
+ #[common_macros::lz_contract]
9
+ pub struct MyOApp;
10
+ use oapp::oapp_core::OAppCore as _;
11
+ #[soroban_sdk::contractimpl(contracttrait)]
12
+ impl oapp::oapp_core::OAppCore for MyOApp {}
13
+ use oapp::oapp_sender::OAppSenderInternal as _;
14
+ impl oapp::oapp_sender::OAppSenderInternal for MyOApp {}
15
+ use oapp::oapp_receiver::OAppReceiver as _;
16
+ #[soroban_sdk::contractimpl(contracttrait)]
17
+ impl oapp::oapp_receiver::OAppReceiver for MyOApp {}
18
+ use oapp::oapp_options_type3::OAppOptionsType3 as _;
19
+ #[soroban_sdk::contractimpl(contracttrait)]
20
+ impl oapp::oapp_options_type3::OAppOptionsType3 for MyOApp {}
21
+
22
+
23
+ // === custom = [core] ===
24
+
25
+ #[common_macros::lz_contract]
26
+ pub struct MyOApp;
27
+ use oapp::oapp_sender::OAppSenderInternal as _;
28
+ impl oapp::oapp_sender::OAppSenderInternal for MyOApp {}
29
+ use oapp::oapp_receiver::OAppReceiver as _;
30
+ #[soroban_sdk::contractimpl(contracttrait)]
31
+ impl oapp::oapp_receiver::OAppReceiver for MyOApp {}
32
+ use oapp::oapp_options_type3::OAppOptionsType3 as _;
33
+ #[soroban_sdk::contractimpl(contracttrait)]
34
+ impl oapp::oapp_options_type3::OAppOptionsType3 for MyOApp {}
35
+
36
+
37
+ // === custom = [sender] ===
38
+
39
+ #[common_macros::lz_contract]
40
+ pub struct MyOApp;
41
+ use oapp::oapp_core::OAppCore as _;
42
+ #[soroban_sdk::contractimpl(contracttrait)]
43
+ impl oapp::oapp_core::OAppCore for MyOApp {}
44
+ use oapp::oapp_receiver::OAppReceiver as _;
45
+ #[soroban_sdk::contractimpl(contracttrait)]
46
+ impl oapp::oapp_receiver::OAppReceiver for MyOApp {}
47
+ use oapp::oapp_options_type3::OAppOptionsType3 as _;
48
+ #[soroban_sdk::contractimpl(contracttrait)]
49
+ impl oapp::oapp_options_type3::OAppOptionsType3 for MyOApp {}
50
+
51
+
52
+ // === custom = [receiver] ===
53
+
54
+ #[common_macros::lz_contract]
55
+ pub struct MyOApp;
56
+ use oapp::oapp_core::OAppCore as _;
57
+ #[soroban_sdk::contractimpl(contracttrait)]
58
+ impl oapp::oapp_core::OAppCore for MyOApp {}
59
+ use oapp::oapp_sender::OAppSenderInternal as _;
60
+ impl oapp::oapp_sender::OAppSenderInternal for MyOApp {}
61
+ use oapp::oapp_options_type3::OAppOptionsType3 as _;
62
+ #[soroban_sdk::contractimpl(contracttrait)]
63
+ impl oapp::oapp_options_type3::OAppOptionsType3 for MyOApp {}
64
+
65
+
66
+ // === custom = [options_type3] ===
67
+
68
+ #[common_macros::lz_contract]
69
+ pub struct MyOApp;
70
+ use oapp::oapp_core::OAppCore as _;
71
+ #[soroban_sdk::contractimpl(contracttrait)]
72
+ impl oapp::oapp_core::OAppCore for MyOApp {}
73
+ use oapp::oapp_sender::OAppSenderInternal as _;
74
+ impl oapp::oapp_sender::OAppSenderInternal for MyOApp {}
75
+ use oapp::oapp_receiver::OAppReceiver as _;
76
+ #[soroban_sdk::contractimpl(contracttrait)]
77
+ impl oapp::oapp_receiver::OAppReceiver for MyOApp {}
78
+
79
+
80
+ // === custom = [core, sender, receiver, options_type3] ===
81
+
82
+ #[common_macros::lz_contract]
83
+ pub struct MyOApp;
84
+
85
+
86
+ // === Struct attributes + fields are preserved ===
87
+
88
+ #[common_macros::lz_contract]
89
+ #[derive(Clone, Debug)]
90
+ pub struct FancyOApp {
91
+ pub x: u32,
92
+ }
93
+ use oapp::oapp_core::OAppCore as _;
94
+ #[soroban_sdk::contractimpl(contracttrait)]
95
+ impl oapp::oapp_core::OAppCore for FancyOApp {}
96
+ use oapp::oapp_sender::OAppSenderInternal as _;
97
+ impl oapp::oapp_sender::OAppSenderInternal for FancyOApp {}
98
+ use oapp::oapp_receiver::OAppReceiver as _;
99
+ #[soroban_sdk::contractimpl(contracttrait)]
100
+ impl oapp::oapp_receiver::OAppReceiver for FancyOApp {}
101
+ use oapp::oapp_options_type3::OAppOptionsType3 as _;
102
+ #[soroban_sdk::contractimpl(contracttrait)]
103
+ impl oapp::oapp_options_type3::OAppOptionsType3 for FancyOApp {}