@layerzerolabs/protocol-stellar-v2 0.2.8

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 (265) hide show
  1. package/.turbo/turbo-build.log +727 -0
  2. package/.turbo/turbo-lint.log +158 -0
  3. package/.turbo/turbo-test.log +796 -0
  4. package/Cargo.lock +2237 -0
  5. package/Cargo.toml +63 -0
  6. package/clippy.toml +7 -0
  7. package/contracts/common-macros/Cargo.toml +20 -0
  8. package/contracts/common-macros/src/error.rs +53 -0
  9. package/contracts/common-macros/src/event.rs +16 -0
  10. package/contracts/common-macros/src/lib.rs +255 -0
  11. package/contracts/common-macros/src/ownable.rs +63 -0
  12. package/contracts/common-macros/src/snapshots/common_macros__tests__tests__snapshot_generated_storage_code.snap +310 -0
  13. package/contracts/common-macros/src/storage.rs +439 -0
  14. package/contracts/common-macros/src/tests.rs +287 -0
  15. package/contracts/common-macros/src/ttl_configurable.rs +60 -0
  16. package/contracts/endpoint-v2/ARCHITECTURE.md +233 -0
  17. package/contracts/endpoint-v2/Cargo.toml +30 -0
  18. package/contracts/endpoint-v2/src/constants.rs +52 -0
  19. package/contracts/endpoint-v2/src/endpoint_v2.rs +305 -0
  20. package/contracts/endpoint-v2/src/errors.rs +29 -0
  21. package/contracts/endpoint-v2/src/events.rs +207 -0
  22. package/contracts/endpoint-v2/src/interfaces/layerzero_composer.rs +26 -0
  23. package/contracts/endpoint-v2/src/interfaces/layerzero_endpoint_v2.rs +170 -0
  24. package/contracts/endpoint-v2/src/interfaces/layerzero_receiver.rs +43 -0
  25. package/contracts/endpoint-v2/src/interfaces/message_lib.rs +62 -0
  26. package/contracts/endpoint-v2/src/interfaces/message_lib_manager.rs +220 -0
  27. package/contracts/endpoint-v2/src/interfaces/messaging_channel.rs +121 -0
  28. package/contracts/endpoint-v2/src/interfaces/messaging_composer.rs +63 -0
  29. package/contracts/endpoint-v2/src/interfaces/mod.rs +17 -0
  30. package/contracts/endpoint-v2/src/interfaces/send_lib.rs +70 -0
  31. package/contracts/endpoint-v2/src/lib.rs +22 -0
  32. package/contracts/endpoint-v2/src/message_lib_manager.rs +315 -0
  33. package/contracts/endpoint-v2/src/messaging_channel.rs +218 -0
  34. package/contracts/endpoint-v2/src/messaging_composer.rs +76 -0
  35. package/contracts/endpoint-v2/src/storage.rs +78 -0
  36. package/contracts/endpoint-v2/src/tests/endpoint_setup.rs +131 -0
  37. package/contracts/endpoint-v2/src/tests/endpoint_v2/clear.rs +237 -0
  38. package/contracts/endpoint-v2/src/tests/endpoint_v2/delegate.rs +42 -0
  39. package/contracts/endpoint-v2/src/tests/endpoint_v2/initializable.rs +76 -0
  40. package/contracts/endpoint-v2/src/tests/endpoint_v2/lz_receive_alert.rs +211 -0
  41. package/contracts/endpoint-v2/src/tests/endpoint_v2/mod.rs +18 -0
  42. package/contracts/endpoint-v2/src/tests/endpoint_v2/native_token.rs +10 -0
  43. package/contracts/endpoint-v2/src/tests/endpoint_v2/owner.rs +10 -0
  44. package/contracts/endpoint-v2/src/tests/endpoint_v2/pay_messaging_fees.rs +424 -0
  45. package/contracts/endpoint-v2/src/tests/endpoint_v2/quote.rs +144 -0
  46. package/contracts/endpoint-v2/src/tests/endpoint_v2/recover_token.rs +72 -0
  47. package/contracts/endpoint-v2/src/tests/endpoint_v2/require_oapp_auth.rs +29 -0
  48. package/contracts/endpoint-v2/src/tests/endpoint_v2/send.rs +513 -0
  49. package/contracts/endpoint-v2/src/tests/endpoint_v2/set_delegate.rs +43 -0
  50. package/contracts/endpoint-v2/src/tests/endpoint_v2/set_zro.rs +27 -0
  51. package/contracts/endpoint-v2/src/tests/endpoint_v2/transfer_ownership.rs +30 -0
  52. package/contracts/endpoint-v2/src/tests/endpoint_v2/ttl_config.rs +202 -0
  53. package/contracts/endpoint-v2/src/tests/endpoint_v2/verifiable.rs +59 -0
  54. package/contracts/endpoint-v2/src/tests/endpoint_v2/verify.rs +172 -0
  55. package/contracts/endpoint-v2/src/tests/endpoint_v2/zro.rs +23 -0
  56. package/contracts/endpoint-v2/src/tests/message_lib_manager/mod.rs +10 -0
  57. package/contracts/endpoint-v2/src/tests/message_lib_manager/register_library.rs +131 -0
  58. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_registered.rs +35 -0
  59. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_supported_eid.rs +28 -0
  60. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_config.rs +79 -0
  61. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_lib_timeout.rs +246 -0
  62. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_library.rs +285 -0
  63. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_send_library.rs +180 -0
  64. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library.rs +405 -0
  65. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library_timeout.rs +80 -0
  66. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_send_library.rs +131 -0
  67. package/contracts/endpoint-v2/src/tests/messaging_channel/burn.rs +358 -0
  68. package/contracts/endpoint-v2/src/tests/messaging_channel/clear.rs +316 -0
  69. package/contracts/endpoint-v2/src/tests/messaging_channel/inbound_nonce.rs +288 -0
  70. package/contracts/endpoint-v2/src/tests/messaging_channel/inbound_payload_hash.rs +316 -0
  71. package/contracts/endpoint-v2/src/tests/messaging_channel/internal.rs +388 -0
  72. package/contracts/endpoint-v2/src/tests/messaging_channel/lazy_inbound_nonce.rs +307 -0
  73. package/contracts/endpoint-v2/src/tests/messaging_channel/mod.rs +10 -0
  74. package/contracts/endpoint-v2/src/tests/messaging_channel/next_guid.rs +239 -0
  75. package/contracts/endpoint-v2/src/tests/messaging_channel/nilify.rs +324 -0
  76. package/contracts/endpoint-v2/src/tests/messaging_channel/outbound_nonce.rs +242 -0
  77. package/contracts/endpoint-v2/src/tests/messaging_channel/skip.rs +232 -0
  78. package/contracts/endpoint-v2/src/tests/messaging_composer/clear_compose.rs +212 -0
  79. package/contracts/endpoint-v2/src/tests/messaging_composer/compose_queue.rs +213 -0
  80. package/contracts/endpoint-v2/src/tests/messaging_composer/lz_compose_alert.rs +269 -0
  81. package/contracts/endpoint-v2/src/tests/messaging_composer/mod.rs +4 -0
  82. package/contracts/endpoint-v2/src/tests/messaging_composer/send_compose.rs +173 -0
  83. package/contracts/endpoint-v2/src/tests/mock.rs +132 -0
  84. package/contracts/endpoint-v2/src/tests/mod.rs +12 -0
  85. package/contracts/endpoint-v2/src/tests/util/build_payload.rs +126 -0
  86. package/contracts/endpoint-v2/src/tests/util/compute_guid.rs +82 -0
  87. package/contracts/endpoint-v2/src/tests/util/keccak256.rs +115 -0
  88. package/contracts/endpoint-v2/src/tests/util/mod.rs +3 -0
  89. package/contracts/endpoint-v2/src/util.rs +52 -0
  90. package/contracts/message-libs/Cargo.toml +12 -0
  91. package/contracts/message-libs/block-message-lib/Cargo.toml +19 -0
  92. package/contracts/message-libs/block-message-lib/src/lib.rs +70 -0
  93. package/contracts/message-libs/lib.rs +2 -0
  94. package/contracts/message-libs/message-lib-common/Cargo.toml +24 -0
  95. package/contracts/message-libs/message-lib-common/src/errors.rs +20 -0
  96. package/contracts/message-libs/message-lib-common/src/interfaces/dvn.rs +55 -0
  97. package/contracts/message-libs/message-lib-common/src/interfaces/executor.rs +46 -0
  98. package/contracts/message-libs/message-lib-common/src/interfaces/mod.rs +7 -0
  99. package/contracts/message-libs/message-lib-common/src/interfaces/treasury.rs +17 -0
  100. package/contracts/message-libs/message-lib-common/src/lib.rs +14 -0
  101. package/contracts/message-libs/message-lib-common/src/packet_codec_v1.rs +99 -0
  102. package/contracts/message-libs/message-lib-common/src/testing_utils.rs +27 -0
  103. package/contracts/message-libs/message-lib-common/src/tests/mod.rs +2 -0
  104. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1.rs +162 -0
  105. package/contracts/message-libs/message-lib-common/src/tests/worker_options.rs +319 -0
  106. package/contracts/message-libs/message-lib-common/src/worker_options.rs +190 -0
  107. package/contracts/message-libs/simple-message-lib/Cargo.toml +26 -0
  108. package/contracts/message-libs/simple-message-lib/src/errors.rs +11 -0
  109. package/contracts/message-libs/simple-message-lib/src/lib.rs +14 -0
  110. package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +136 -0
  111. package/contracts/message-libs/simple-message-lib/src/storage.rs +27 -0
  112. package/contracts/message-libs/simple-message-lib/src/test.rs +280 -0
  113. package/contracts/message-libs/treasury/Cargo.toml +27 -0
  114. package/contracts/message-libs/treasury/src/errors.rs +10 -0
  115. package/contracts/message-libs/treasury/src/events.rs +28 -0
  116. package/contracts/message-libs/treasury/src/interfaces/mod.rs +3 -0
  117. package/contracts/message-libs/treasury/src/interfaces/zro_fee_lib.rs +20 -0
  118. package/contracts/message-libs/treasury/src/lib.rs +20 -0
  119. package/contracts/message-libs/treasury/src/storage.rs +18 -0
  120. package/contracts/message-libs/treasury/src/tests/mod.rs +2 -0
  121. package/contracts/message-libs/treasury/src/tests/setup.rs +112 -0
  122. package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +562 -0
  123. package/contracts/message-libs/treasury/src/treasury.rs +140 -0
  124. package/contracts/message-libs/uln-302/Cargo.toml +28 -0
  125. package/contracts/message-libs/uln-302/src/config_validation.rs +173 -0
  126. package/contracts/message-libs/uln-302/src/errors.rs +29 -0
  127. package/contracts/message-libs/uln-302/src/events.rs +72 -0
  128. package/contracts/message-libs/uln-302/src/interfaces/mod.rs +5 -0
  129. package/contracts/message-libs/uln-302/src/interfaces/receive.rs +82 -0
  130. package/contracts/message-libs/uln-302/src/interfaces/send.rs +159 -0
  131. package/contracts/message-libs/uln-302/src/lib.rs +20 -0
  132. package/contracts/message-libs/uln-302/src/receive.rs +199 -0
  133. package/contracts/message-libs/uln-302/src/send.rs +349 -0
  134. package/contracts/message-libs/uln-302/src/storage.rs +47 -0
  135. package/contracts/message-libs/uln-302/src/tests/config/mod.rs +2 -0
  136. package/contracts/message-libs/uln-302/src/tests/config/oapp_uln_config.rs +291 -0
  137. package/contracts/message-libs/uln-302/src/tests/config/uln_config.rs +163 -0
  138. package/contracts/message-libs/uln-302/src/tests/mod.rs +7 -0
  139. package/contracts/message-libs/uln-302/src/tests/receive_uln302/commit_verification.rs +183 -0
  140. package/contracts/message-libs/uln-302/src/tests/receive_uln302/confirmations.rs +128 -0
  141. package/contracts/message-libs/uln-302/src/tests/receive_uln302/effective_receive_uln_config.rs +104 -0
  142. package/contracts/message-libs/uln-302/src/tests/receive_uln302/mod.rs +66 -0
  143. package/contracts/message-libs/uln-302/src/tests/receive_uln302/set_default_receive_uln_configs.rs +79 -0
  144. package/contracts/message-libs/uln-302/src/tests/receive_uln302/verifiable.rs +463 -0
  145. package/contracts/message-libs/uln-302/src/tests/receive_uln302/verify.rs +173 -0
  146. package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_executor_config.rs +132 -0
  147. package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_send_uln_config.rs +117 -0
  148. package/contracts/message-libs/uln-302/src/tests/send_uln302/mod.rs +6 -0
  149. package/contracts/message-libs/uln-302/src/tests/send_uln302/quote.rs +586 -0
  150. package/contracts/message-libs/uln-302/src/tests/send_uln302/send.rs +834 -0
  151. package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_executor_configs.rs +95 -0
  152. package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_send_uln_configs.rs +80 -0
  153. package/contracts/message-libs/uln-302/src/tests/setup.rs +268 -0
  154. package/contracts/message-libs/uln-302/src/tests/testing_utils.rs +47 -0
  155. package/contracts/message-libs/uln-302/src/tests/uln302/get_app_receive_uln_config.rs +51 -0
  156. package/contracts/message-libs/uln-302/src/tests/uln302/get_app_send_uln_config.rs +51 -0
  157. package/contracts/message-libs/uln-302/src/tests/uln302/get_oapp_executor_config.rs +48 -0
  158. package/contracts/message-libs/uln-302/src/tests/uln302/mod.rs +4 -0
  159. package/contracts/message-libs/uln-302/src/tests/uln302/set_config.rs +998 -0
  160. package/contracts/message-libs/uln-302/src/uln302.rs +117 -0
  161. package/contracts/oapp-macros/Cargo.toml +21 -0
  162. package/contracts/oapp-macros/src/lib.rs +408 -0
  163. package/contracts/oapp-macros/src/oapp_core.rs +49 -0
  164. package/contracts/oapp-macros/src/oapp_full.rs +15 -0
  165. package/contracts/oapp-macros/src/oapp_options_type3.rs +46 -0
  166. package/contracts/oapp-macros/src/oapp_receiver.rs +67 -0
  167. package/contracts/oapp-macros/src/oapp_sender.rs +23 -0
  168. package/contracts/oapp-macros/src/util.rs +103 -0
  169. package/contracts/oapp-macros/tests/test_macros.rs +522 -0
  170. package/contracts/oapps/Cargo.toml +12 -0
  171. package/contracts/oapps/counter/Cargo.toml +24 -0
  172. package/contracts/oapps/counter/integration_tests/mod.rs +3 -0
  173. package/contracts/oapps/counter/integration_tests/setup.rs +201 -0
  174. package/contracts/oapps/counter/integration_tests/test_with_sml.rs +166 -0
  175. package/contracts/oapps/counter/integration_tests/utils.rs +144 -0
  176. package/contracts/oapps/counter/src/codec.rs +63 -0
  177. package/contracts/oapps/counter/src/counter.rs +235 -0
  178. package/contracts/oapps/counter/src/errors.rs +9 -0
  179. package/contracts/oapps/counter/src/lib.rs +16 -0
  180. package/contracts/oapps/counter/src/options.rs +30 -0
  181. package/contracts/oapps/counter/src/storage.rs +33 -0
  182. package/contracts/oapps/counter/src/tests/mod.rs +37 -0
  183. package/contracts/oapps/counter/src/tests/test_codec.rs +64 -0
  184. package/contracts/oapps/counter/src/tests/test_counter.rs +390 -0
  185. package/contracts/oapps/counter/src/u256_ext.rs +21 -0
  186. package/contracts/oapps/lib.rs +2 -0
  187. package/contracts/oapps/oapp/Cargo.toml +21 -0
  188. package/contracts/oapps/oapp/src/errors.rs +9 -0
  189. package/contracts/oapps/oapp/src/lib.rs +10 -0
  190. package/contracts/oapps/oapp/src/oapp_core.rs +92 -0
  191. package/contracts/oapps/oapp/src/oapp_options_type3.rs +89 -0
  192. package/contracts/oapps/oapp/src/oapp_receiver.rs +72 -0
  193. package/contracts/oapps/oapp/src/oapp_sender.rs +66 -0
  194. package/contracts/oapps/oapp/src/tests/mod.rs +4 -0
  195. package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +162 -0
  196. package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +180 -0
  197. package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +157 -0
  198. package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +283 -0
  199. package/contracts/utils/Cargo.toml +21 -0
  200. package/contracts/utils/src/buffer_reader.rs +143 -0
  201. package/contracts/utils/src/buffer_writer.rs +117 -0
  202. package/contracts/utils/src/bytes_ext.rs +19 -0
  203. package/contracts/utils/src/errors.rs +30 -0
  204. package/contracts/utils/src/lib.rs +15 -0
  205. package/contracts/utils/src/option_ext.rs +38 -0
  206. package/contracts/utils/src/ownable.rs +88 -0
  207. package/contracts/utils/src/testing_utils.rs +100 -0
  208. package/contracts/utils/src/tests/buffer_reader.rs +1006 -0
  209. package/contracts/utils/src/tests/buffer_writer.rs +330 -0
  210. package/contracts/utils/src/tests/bytes_ext.rs +77 -0
  211. package/contracts/utils/src/tests/mod.rs +4 -0
  212. package/contracts/utils/src/tests/ownable.rs +149 -0
  213. package/contracts/utils/src/ttl.rs +164 -0
  214. package/contracts/workers/Cargo.toml +13 -0
  215. package/contracts/workers/executor/Cargo.toml +26 -0
  216. package/contracts/workers/executor/src/events.rs +22 -0
  217. package/contracts/workers/executor/src/executor.rs +347 -0
  218. package/contracts/workers/executor/src/interfaces/executor.rs +40 -0
  219. package/contracts/workers/executor/src/interfaces/mod.rs +5 -0
  220. package/contracts/workers/executor/src/interfaces/types.rs +51 -0
  221. package/contracts/workers/executor/src/lib.rs +10 -0
  222. package/contracts/workers/executor/src/storage.rs +23 -0
  223. package/contracts/workers/lib.rs +2 -0
  224. package/contracts/workers/worker-common/Cargo.toml +18 -0
  225. package/contracts/workers/worker-common/src/constants.rs +17 -0
  226. package/contracts/workers/worker-common/src/errors.rs +6 -0
  227. package/contracts/workers/worker-common/src/events.rs +34 -0
  228. package/contracts/workers/worker-common/src/interfaces/executor_fee_lib.rs +35 -0
  229. package/contracts/workers/worker-common/src/interfaces/mod.rs +7 -0
  230. package/contracts/workers/worker-common/src/interfaces/price_feed.rs +40 -0
  231. package/contracts/workers/worker-common/src/interfaces/worker.rs +60 -0
  232. package/contracts/workers/worker-common/src/lib.rs +19 -0
  233. package/contracts/workers/worker-common/src/storage.rs +32 -0
  234. package/contracts/workers/worker-common/src/worker_common.rs +166 -0
  235. package/package.json +25 -0
  236. package/rust-toolchain.toml +4 -0
  237. package/rustfmt.toml +17 -0
  238. package/sdk/.turbo/turbo-build.log +4 -0
  239. package/sdk/dist/generated/bml.d.ts +452 -0
  240. package/sdk/dist/generated/bml.js +72 -0
  241. package/sdk/dist/generated/counter.d.ts +824 -0
  242. package/sdk/dist/generated/counter.js +125 -0
  243. package/sdk/dist/generated/endpoint.d.ts +1676 -0
  244. package/sdk/dist/generated/endpoint.js +216 -0
  245. package/sdk/dist/generated/sml.d.ts +810 -0
  246. package/sdk/dist/generated/sml.js +132 -0
  247. package/sdk/dist/generated/uln302.d.ts +1227 -0
  248. package/sdk/dist/generated/uln302.js +185 -0
  249. package/sdk/dist/index.d.ts +5 -0
  250. package/sdk/dist/index.js +5 -0
  251. package/sdk/node_modules/.bin/tsc +21 -0
  252. package/sdk/node_modules/.bin/tsserver +21 -0
  253. package/sdk/node_modules/.bin/vitest +21 -0
  254. package/sdk/node_modules/.bin/zx +21 -0
  255. package/sdk/package.json +40 -0
  256. package/sdk/src/index.ts +5 -0
  257. package/sdk/test/index.test.ts +271 -0
  258. package/sdk/test/suites/constants.ts +13 -0
  259. package/sdk/test/suites/deploy.ts +277 -0
  260. package/sdk/test/suites/localnet.ts +42 -0
  261. package/sdk/test/suites/scan.ts +189 -0
  262. package/sdk/tsconfig.json +106 -0
  263. package/tools/ts-bindings-gen/Cargo.toml +14 -0
  264. package/tools/ts-bindings-gen/src/main.rs +147 -0
  265. package/turbo.json +12 -0
@@ -0,0 +1,76 @@
1
+ #[contractimpl]
2
+ impl IMessagingComposer for EndpointV2 {
3
+ /// Sends a composed message from an OApp to a composer.
4
+ ///
5
+ /// The composer MUST assert the sender because anyone can send compose msg with this function.
6
+ /// With the same GUID, the OApp can send compose to multiple composers at the same time.
7
+ fn send_compose(env: &Env, from: &Address, to: &Address, guid: &BytesN<32>, index: u32, message: &Bytes) {
8
+ from.require_auth();
9
+ assert_with_error!(env, index <= MAX_COMPOSE_INDEX, EndpointError::InvalidIndex);
10
+
11
+ let compose_queue = Self::compose_queue(env, from, to, guid, index);
12
+ assert_with_error!(env, compose_queue.is_none(), EndpointError::ComposeExists);
13
+
14
+ let message_hash = keccak256(env, message);
15
+ EndpointStorage::set_compose_queue(env, from, to, guid, index, &message_hash);
16
+ ComposeSent { from: from.clone(), to: to.clone(), guid: guid.clone(), index, message: message.clone() }
17
+ .publish(env);
18
+ }
19
+
20
+ /// Clears a composed message by the composer.
21
+ ///
22
+ /// This is a PULL mode versus the PUSH mode of `lz_compose`.
23
+ fn clear_compose(env: &Env, composer: &Address, from: &Address, guid: &BytesN<32>, index: u32, message: &Bytes) {
24
+ composer.require_auth();
25
+ assert_with_error!(env, index <= MAX_COMPOSE_INDEX, EndpointError::InvalidIndex);
26
+
27
+ let expected_hash = Self::compose_queue(env, from, composer, guid, index);
28
+ let actual_hash = keccak256(env, message);
29
+ assert_with_error!(env, expected_hash == Some(actual_hash), EndpointError::ComposeNotFound);
30
+
31
+ let received_hash = BytesN::from_array(env, &RECEIVED_MESSAGE_HASH_BYTES);
32
+ EndpointStorage::set_compose_queue(env, from, composer, guid, index, &received_hash);
33
+
34
+ ComposeDelivered { from: from.clone(), to: composer.clone(), guid: guid.clone(), index }.publish(env);
35
+ }
36
+
37
+ /// Emits an alert event when `lz_compose` execution fails.
38
+ ///
39
+ /// Called by the executor to notify about failed compose message delivery attempts.
40
+ fn lz_compose_alert(
41
+ env: &Env,
42
+ executor: &Address,
43
+ from: &Address,
44
+ to: &Address,
45
+ guid: &BytesN<32>,
46
+ index: u32,
47
+ gas: i128,
48
+ value: i128,
49
+ message: &Bytes,
50
+ extra_data: &Bytes,
51
+ reason: &Bytes,
52
+ ) {
53
+ executor.require_auth();
54
+ assert_with_error!(env, index <= MAX_COMPOSE_INDEX, EndpointError::InvalidIndex);
55
+ LzComposeAlert {
56
+ executor: executor.clone(),
57
+ from: from.clone(),
58
+ to: to.clone(),
59
+ guid: guid.clone(),
60
+ index,
61
+ gas,
62
+ value,
63
+ message: message.clone(),
64
+ extra_data: extra_data.clone(),
65
+ reason: reason.clone(),
66
+ }
67
+ .publish(env);
68
+ }
69
+
70
+ // === View Functions ===
71
+
72
+ /// Returns the stored hash for a composed message, or `None` if not queued.
73
+ fn compose_queue(env: &Env, from: &Address, to: &Address, guid: &BytesN<32>, index: u32) -> Option<BytesN<32>> {
74
+ EndpointStorage::compose_queue(env, from, to, guid, index)
75
+ }
76
+ }
@@ -0,0 +1,78 @@
1
+ use crate::Timeout;
2
+ use common_macros::storage;
3
+ use soroban_sdk::{Address, BytesN};
4
+ use utils::ttl::DefaultTtlConfigProvider;
5
+
6
+ #[storage(DefaultTtlConfigProvider)]
7
+ pub enum EndpointStorage {
8
+ /// The ZRO token address
9
+ #[instance(Address)]
10
+ ZRO,
11
+
12
+ /// The delegate address for an OApp
13
+ #[persistent(Address)]
14
+ Delegate { oapp: Address },
15
+
16
+ /// === Messaging Channel ===
17
+
18
+ /// The lazy inbound nonce for a receiver
19
+ #[persistent(u64)]
20
+ #[default(0)]
21
+ LazyInboundNonce { receiver: Address, src_eid: u32, sender: BytesN<32> },
22
+
23
+ /// The inbound payload hash for a receiver
24
+ #[persistent(BytesN<32>)]
25
+ #[no_auto_ttl_extension]
26
+ InboundPayloadHash { receiver: Address, src_eid: u32, sender: BytesN<32>, nonce: u64 },
27
+
28
+ /// The outbound nonce for a sender
29
+ #[persistent(u64)]
30
+ #[default(0)]
31
+ OutboundNonce { sender: Address, dst_eid: u32, receiver: BytesN<32> },
32
+
33
+ /// === Message Lib Manager ===
34
+
35
+ /// The number of registered libraries
36
+ #[instance(u32)]
37
+ #[default(0)]
38
+ RegisteredLibraryCount,
39
+
40
+ /// The mapping of library to index
41
+ #[persistent(u32)]
42
+ LibraryToIndex { lib: Address },
43
+
44
+ /// The mapping of index to library
45
+ #[persistent(Address)]
46
+ IndexToLibrary { index: u32 },
47
+
48
+ /// The default send library for a destination endpoint
49
+ #[persistent(Address)]
50
+ DefaultSendLibrary { dst_eid: u32 },
51
+
52
+ /// The default receive library for a source endpoint
53
+ #[persistent(Address)]
54
+ DefaultReceiveLibrary { src_eid: u32 },
55
+
56
+ /// The default receive library grace period for a source endpoint
57
+ #[persistent(Timeout)]
58
+ DefaultReceiveLibraryTimeout { src_eid: u32 },
59
+
60
+ /// The custom send library for a sender and destination endpoint
61
+ #[persistent(Address)]
62
+ SendLibrary { sender: Address, dst_eid: u32 },
63
+
64
+ /// The custom receive library for a receiver and source endpoint
65
+ #[persistent(Address)]
66
+ ReceiveLibrary { receiver: Address, src_eid: u32 },
67
+
68
+ /// The custom receive library grace period for a receiver and source endpoint
69
+ #[persistent(Timeout)]
70
+ ReceiveLibraryTimeout { receiver: Address, src_eid: u32 },
71
+
72
+ /// === Messaging Composer ===
73
+
74
+ /// The compose queue for a sender and receiver
75
+ #[persistent(BytesN<32>)]
76
+ #[no_auto_ttl_extension]
77
+ ComposeQueue { from: Address, to: Address, guid: BytesN<32>, index: u32 },
78
+ }
@@ -0,0 +1,131 @@
1
+ use crate::{
2
+ endpoint_v2::{EndpointV2, EndpointV2Client},
3
+ tests::mock::{
4
+ MockMessageLib, MockMessageLibClient, MockReceiveLib, MockReceiveLibClient, MockSendLib, MockSendLibClient,
5
+ },
6
+ MessageLibType,
7
+ };
8
+ use soroban_sdk::{
9
+ testutils::{Address as _, MockAuth, MockAuthInvoke},
10
+ token::StellarAssetClient,
11
+ Address, Env, IntoVal, Val, Vec,
12
+ };
13
+
14
+ pub struct TestSetup<'a> {
15
+ pub eid: u32,
16
+ pub endpoint_client: EndpointV2Client<'a>,
17
+ pub env: Env,
18
+ pub owner: Address,
19
+ pub contract_id: Address,
20
+ pub native_token_client: StellarAssetClient<'a>,
21
+ pub zro_token_client: StellarAssetClient<'a>,
22
+ }
23
+
24
+ pub fn setup<'a>() -> TestSetup<'a> {
25
+ let env = Env::default();
26
+
27
+ let owner = Address::generate(&env);
28
+
29
+ // Deploy native token contract
30
+ let native_token = env.register_stellar_asset_contract_v2(owner.clone());
31
+ let native_token_address = native_token.address();
32
+ let native_token_client = StellarAssetClient::new(&env, &native_token_address);
33
+
34
+ // Deploy ZRO token
35
+ let zro_token = env.register_stellar_asset_contract_v2(owner.clone());
36
+ let zro_token_address = zro_token.address();
37
+ let zro_token_client = StellarAssetClient::new(&env, &zro_token_address);
38
+
39
+ // Deploy the endpoint contract
40
+ let contract_id = env.register(EndpointV2, (&owner,));
41
+ let client = EndpointV2Client::new(&env, &contract_id);
42
+ let eid = client.eid();
43
+
44
+ TestSetup { eid, endpoint_client: client, env, owner, contract_id, native_token_client, zro_token_client }
45
+ }
46
+
47
+ impl<'a> TestSetup<'a> {
48
+ /// Helper function to mint native tokens with proper authorization
49
+ pub fn mint_native(&self, to: &Address, amount: i128) {
50
+ self.env.mock_auths(&[MockAuth {
51
+ address: &self.owner,
52
+ invoke: &MockAuthInvoke {
53
+ contract: &self.native_token_client.address,
54
+ fn_name: "mint",
55
+ args: (to, amount).into_val(&self.env),
56
+ sub_invokes: &[],
57
+ },
58
+ }]);
59
+ self.native_token_client.mint(to, &amount);
60
+ }
61
+
62
+ /// Helper function to mint ZRO tokens with proper authorization
63
+ pub fn mint_zro(&self, to: &Address, amount: i128) {
64
+ self.env.mock_auths(&[MockAuth {
65
+ address: &self.owner,
66
+ invoke: &MockAuthInvoke {
67
+ contract: &self.zro_token_client.address,
68
+ fn_name: "mint",
69
+ args: (to, amount).into_val(&self.env),
70
+ sub_invokes: &[],
71
+ },
72
+ }]);
73
+ self.zro_token_client.mint(to, &amount);
74
+ }
75
+
76
+ // Helper to mock owner auth for common operations
77
+ pub fn mock_owner_auth<T: IntoVal<Env, Vec<Val>>>(&self, fn_name: &str, args: T) {
78
+ self.env.mock_auths(&[MockAuth {
79
+ address: &self.owner,
80
+ invoke: &MockAuthInvoke {
81
+ contract: &self.contract_id,
82
+ fn_name,
83
+ args: args.into_val(&self.env),
84
+ sub_invokes: &[],
85
+ },
86
+ }]);
87
+ }
88
+
89
+ // Helper to mock auth for any address
90
+ pub fn mock_auth<T: IntoVal<Env, Vec<Val>>>(&self, address: &Address, fn_name: &str, args: T) {
91
+ self.env.mock_auths(&[MockAuth {
92
+ address,
93
+ invoke: &MockAuthInvoke {
94
+ contract: &self.contract_id,
95
+ fn_name,
96
+ args: args.into_val(&self.env),
97
+ sub_invokes: &[],
98
+ },
99
+ }]);
100
+ }
101
+
102
+ // Helper function to create and setup a mock message library
103
+ pub fn setup_mock_message_lib(&self, lib_type: MessageLibType, supported_eids: Vec<u32>) -> Address {
104
+ let lib = self.env.register(MockMessageLib, ());
105
+ let lib_client = MockMessageLibClient::new(&self.env, &lib);
106
+ lib_client.setup(&lib_type, &supported_eids);
107
+ lib
108
+ }
109
+
110
+ // Helper function to create and setup a mock send library
111
+ pub fn setup_mock_send_lib(
112
+ &self,
113
+ supported_eids: Vec<u32>,
114
+ native_fee: i128,
115
+ zro_fee: i128,
116
+ fee_recipient: Address,
117
+ ) -> Address {
118
+ let lib = self.env.register(MockSendLib, ());
119
+ let lib_client = MockSendLibClient::new(&self.env, &lib);
120
+ lib_client.setup(&supported_eids, &native_fee, &zro_fee, &fee_recipient);
121
+ lib
122
+ }
123
+
124
+ // Helper function to create and setup a mock receive library
125
+ pub fn setup_mock_receive_lib(&self, supported_eids: Vec<u32>) -> Address {
126
+ let lib = self.env.register(MockReceiveLib, ());
127
+ let lib_client = MockReceiveLibClient::new(&self.env, &lib);
128
+ lib_client.setup(&supported_eids);
129
+ lib
130
+ }
131
+ }
@@ -0,0 +1,237 @@
1
+ use crate::{
2
+ events::PacketDelivered,
3
+ storage,
4
+ tests::{endpoint_setup::setup, mock::MockReceiver},
5
+ util::{build_payload, keccak256},
6
+ Origin,
7
+ };
8
+ use soroban_sdk::{
9
+ testutils::{MockAuth, MockAuthInvoke},
10
+ vec, Bytes, BytesN, IntoVal,
11
+ };
12
+ use utils::testing_utils::assert_event;
13
+
14
+ #[test]
15
+ fn test_clear_success() {
16
+ let context = setup();
17
+ let env = &context.env;
18
+ let endpoint_client = &context.endpoint_client;
19
+
20
+ let src_eid = 2u32;
21
+ let sender = BytesN::from_array(env, &[1u8; 32]);
22
+ let receiver = env.register(MockReceiver, ());
23
+ let nonce = 1u64;
24
+
25
+ // Setup receive library
26
+ let receive_lib = context.setup_mock_receive_lib(vec![env, src_eid]);
27
+ context.mock_owner_auth("register_library", (&receive_lib,));
28
+ endpoint_client.register_library(&receive_lib);
29
+ context.mock_owner_auth("set_default_receive_library", (&src_eid, &receive_lib, &0u64));
30
+ endpoint_client.set_default_receive_library(&src_eid, &receive_lib, &0);
31
+
32
+ // Create message and payload
33
+ let message = Bytes::from_array(env, &[1, 2, 3, 4]);
34
+ let guid = BytesN::from_array(env, &[5u8; 32]);
35
+ let payload = build_payload(env, &guid, &message);
36
+ let payload_hash = keccak256(env, &payload);
37
+
38
+ let origin = Origin { src_eid, sender: sender.clone(), nonce };
39
+
40
+ // First verify the packet
41
+ env.mock_auths(&[MockAuth {
42
+ address: &receive_lib,
43
+ invoke: &MockAuthInvoke {
44
+ contract: &endpoint_client.address,
45
+ fn_name: "verify",
46
+ args: (&receive_lib, &origin, &receiver, &payload_hash).into_val(env),
47
+ sub_invokes: &[],
48
+ },
49
+ }]);
50
+ endpoint_client.verify(&receive_lib, &origin, &receiver, &payload_hash);
51
+
52
+ // Verify payload hash exists before clear
53
+ let hash_before_clear = env.as_contract(&endpoint_client.address, || {
54
+ storage::EndpointStorage::inbound_payload_hash(env, &receiver, src_eid, &sender, nonce)
55
+ });
56
+ assert_eq!(hash_before_clear, Some(payload_hash.clone()), "Payload hash should exist before clear");
57
+
58
+ // Verify initial lazy inbound nonce
59
+ let initial_lazy_nonce = env.as_contract(&endpoint_client.address, || {
60
+ storage::EndpointStorage::lazy_inbound_nonce(env, &receiver, src_eid, &sender)
61
+ });
62
+ assert_eq!(initial_lazy_nonce, 0, "Initial lazy inbound nonce should be 0");
63
+
64
+ // Now clear the payload
65
+ env.mock_auths(&[MockAuth {
66
+ address: &receiver,
67
+ invoke: &MockAuthInvoke {
68
+ contract: &endpoint_client.address,
69
+ fn_name: "clear",
70
+ args: (&receiver, &origin, &receiver, &guid, &message).into_val(env),
71
+ sub_invokes: &[],
72
+ },
73
+ }]);
74
+ endpoint_client.clear(&receiver, &origin, &receiver, &guid, &message);
75
+
76
+ // Verify PacketDelivered event was published
77
+ assert_event(env, &endpoint_client.address, PacketDelivered { origin: origin.clone(), receiver: receiver.clone() });
78
+
79
+ // Verify payload hash was removed via public interface
80
+ let stored_hash = endpoint_client.inbound_payload_hash(&receiver, &src_eid, &sender, &nonce);
81
+ assert_eq!(stored_hash, None);
82
+
83
+ // Assert storage change directly - payload hash removed
84
+ let stored_hash_direct = env.as_contract(&endpoint_client.address, || {
85
+ storage::EndpointStorage::inbound_payload_hash(env, &receiver, src_eid, &sender, nonce)
86
+ });
87
+ assert_eq!(stored_hash_direct, None, "Storage should have payload hash removed");
88
+
89
+ // Verify lazy inbound nonce was updated via public interface
90
+ let lazy_nonce = endpoint_client.lazy_inbound_nonce(&receiver, &src_eid, &sender);
91
+ assert_eq!(lazy_nonce, nonce);
92
+
93
+ // Assert storage change directly - lazy inbound nonce updated
94
+ let stored_lazy_nonce = env.as_contract(&endpoint_client.address, || {
95
+ storage::EndpointStorage::lazy_inbound_nonce(env, &receiver, src_eid, &sender)
96
+ });
97
+ assert_eq!(stored_lazy_nonce, nonce, "Storage should contain updated lazy inbound nonce");
98
+ }
99
+
100
+ #[test]
101
+ fn test_clear_updates_lazy_nonce() {
102
+ let context = setup();
103
+ let env = &context.env;
104
+ let endpoint_client = &context.endpoint_client;
105
+
106
+ let src_eid = 2u32;
107
+ let sender = BytesN::from_array(env, &[1u8; 32]);
108
+ let receiver = env.register(MockReceiver, ());
109
+ let nonce = 1u64;
110
+
111
+ // Setup receive library
112
+ let receive_lib = context.setup_mock_receive_lib(vec![env, src_eid]);
113
+ context.mock_owner_auth("register_library", (&receive_lib,));
114
+ endpoint_client.register_library(&receive_lib);
115
+ context.mock_owner_auth("set_default_receive_library", (&src_eid, &receive_lib, &0u64));
116
+ endpoint_client.set_default_receive_library(&src_eid, &receive_lib, &0);
117
+
118
+ // Create message and payload
119
+ let message = Bytes::from_array(env, &[1, 2, 3, 4]);
120
+ let guid = BytesN::from_array(env, &[5u8; 32]);
121
+ let payload = build_payload(env, &guid, &message);
122
+ let payload_hash = keccak256(env, &payload);
123
+
124
+ let origin = Origin { src_eid, sender: sender.clone(), nonce };
125
+
126
+ // First verify the packet
127
+ env.mock_auths(&[MockAuth {
128
+ address: &receive_lib,
129
+ invoke: &MockAuthInvoke {
130
+ contract: &endpoint_client.address,
131
+ fn_name: "verify",
132
+ args: (&receive_lib, &origin, &receiver, &payload_hash).into_val(env),
133
+ sub_invokes: &[],
134
+ },
135
+ }]);
136
+ endpoint_client.verify(&receive_lib, &origin, &receiver, &payload_hash);
137
+
138
+ // Check initial lazy nonce
139
+ let initial_lazy_nonce = endpoint_client.lazy_inbound_nonce(&receiver, &src_eid, &sender);
140
+ assert_eq!(initial_lazy_nonce, 0);
141
+
142
+ // Clear the payload
143
+ env.mock_auths(&[MockAuth {
144
+ address: &receiver,
145
+ invoke: &MockAuthInvoke {
146
+ contract: &endpoint_client.address,
147
+ fn_name: "clear",
148
+ args: (&receiver, &origin, &receiver, &guid, &message).into_val(env),
149
+ sub_invokes: &[],
150
+ },
151
+ }]);
152
+ endpoint_client.clear(&receiver, &origin, &receiver, &guid, &message);
153
+
154
+ // Verify lazy inbound nonce was updated
155
+ let lazy_nonce = endpoint_client.lazy_inbound_nonce(&receiver, &src_eid, &sender);
156
+ assert_eq!(lazy_nonce, nonce);
157
+ }
158
+
159
+ #[test]
160
+ fn test_clear_sequential_nonces() {
161
+ let context = setup();
162
+ let env = &context.env;
163
+ let endpoint_client = &context.endpoint_client;
164
+
165
+ let src_eid = 2u32;
166
+ let sender = BytesN::from_array(env, &[1u8; 32]);
167
+ let receiver = env.register(MockReceiver, ());
168
+
169
+ // Setup receive library
170
+ let receive_lib = context.setup_mock_receive_lib(vec![env, src_eid]);
171
+ context.mock_owner_auth("register_library", (&receive_lib,));
172
+ endpoint_client.register_library(&receive_lib);
173
+ context.mock_owner_auth("set_default_receive_library", (&src_eid, &receive_lib, &0u64));
174
+ endpoint_client.set_default_receive_library(&src_eid, &receive_lib, &0);
175
+
176
+ // Verify and clear nonce 1
177
+ let message1 = Bytes::from_array(env, &[1, 2, 3]);
178
+ let guid1 = BytesN::from_array(env, &[1u8; 32]);
179
+ let payload1 = build_payload(env, &guid1, &message1);
180
+ let payload_hash1 = keccak256(env, &payload1);
181
+ let origin1 = Origin { src_eid, sender: sender.clone(), nonce: 1 };
182
+
183
+ env.mock_auths(&[MockAuth {
184
+ address: &receive_lib,
185
+ invoke: &MockAuthInvoke {
186
+ contract: &endpoint_client.address,
187
+ fn_name: "verify",
188
+ args: (&receive_lib, &origin1, &receiver, &payload_hash1).into_val(env),
189
+ sub_invokes: &[],
190
+ },
191
+ }]);
192
+ endpoint_client.verify(&receive_lib, &origin1, &receiver, &payload_hash1);
193
+
194
+ env.mock_auths(&[MockAuth {
195
+ address: &receiver,
196
+ invoke: &MockAuthInvoke {
197
+ contract: &endpoint_client.address,
198
+ fn_name: "clear",
199
+ args: (&receiver, &origin1, &receiver, &guid1, &message1).into_val(env),
200
+ sub_invokes: &[],
201
+ },
202
+ }]);
203
+ endpoint_client.clear(&receiver, &origin1, &receiver, &guid1, &message1);
204
+
205
+ // Verify and clear nonce 2
206
+ let message2 = Bytes::from_array(env, &[4, 5, 6]);
207
+ let guid2 = BytesN::from_array(env, &[2u8; 32]);
208
+ let payload2 = build_payload(env, &guid2, &message2);
209
+ let payload_hash2 = keccak256(env, &payload2);
210
+ let origin2 = Origin { src_eid, sender: sender.clone(), nonce: 2 };
211
+
212
+ env.mock_auths(&[MockAuth {
213
+ address: &receive_lib,
214
+ invoke: &MockAuthInvoke {
215
+ contract: &endpoint_client.address,
216
+ fn_name: "verify",
217
+ args: (&receive_lib, &origin2, &receiver, &payload_hash2).into_val(env),
218
+ sub_invokes: &[],
219
+ },
220
+ }]);
221
+ endpoint_client.verify(&receive_lib, &origin2, &receiver, &payload_hash2);
222
+
223
+ env.mock_auths(&[MockAuth {
224
+ address: &receiver,
225
+ invoke: &MockAuthInvoke {
226
+ contract: &endpoint_client.address,
227
+ fn_name: "clear",
228
+ args: (&receiver, &origin2, &receiver, &guid2, &message2).into_val(env),
229
+ sub_invokes: &[],
230
+ },
231
+ }]);
232
+ endpoint_client.clear(&receiver, &origin2, &receiver, &guid2, &message2);
233
+
234
+ // Verify lazy inbound nonce was updated to 2
235
+ let lazy_nonce = endpoint_client.lazy_inbound_nonce(&receiver, &src_eid, &sender);
236
+ assert_eq!(lazy_nonce, 2);
237
+ }
@@ -0,0 +1,42 @@
1
+ use crate::tests::endpoint_setup::setup;
2
+ use soroban_sdk::{
3
+ testutils::{Address as _, MockAuth, MockAuthInvoke},
4
+ Address, IntoVal,
5
+ };
6
+
7
+ #[test]
8
+ fn test_delegate_when_not_set() {
9
+ let context = setup();
10
+ let env = &context.env;
11
+ let endpoint_client = &context.endpoint_client;
12
+
13
+ let oapp = Address::generate(env);
14
+
15
+ let actual_delegate = endpoint_client.delegate(&oapp);
16
+ assert_eq!(actual_delegate, None, "Delegate should not be set");
17
+ }
18
+
19
+ #[test]
20
+ fn test_delegate_when_set() {
21
+ let context = setup();
22
+ let env = &context.env;
23
+ let endpoint_client = &context.endpoint_client;
24
+
25
+ let oapp = Address::generate(env);
26
+ let delegate = Address::generate(env);
27
+
28
+ let delegate_option = Some(delegate.clone());
29
+ env.mock_auths(&[MockAuth {
30
+ address: &oapp,
31
+ invoke: &MockAuthInvoke {
32
+ contract: &endpoint_client.address,
33
+ fn_name: "set_delegate",
34
+ args: (&oapp, &delegate_option).into_val(env),
35
+ sub_invokes: &[],
36
+ },
37
+ }]);
38
+ endpoint_client.set_delegate(&oapp, &delegate_option);
39
+
40
+ let actual_delegate = endpoint_client.delegate(&oapp);
41
+ assert_eq!(actual_delegate, Some(delegate), "Delegate should be set");
42
+ }
@@ -0,0 +1,76 @@
1
+ use crate::{
2
+ tests::{
3
+ endpoint_setup::setup,
4
+ mock::{MockReceiver, MockReceiverReject},
5
+ },
6
+ Origin,
7
+ };
8
+ use soroban_sdk::BytesN;
9
+
10
+ #[test]
11
+ fn test_initializable_with_receiver_allowing_init() {
12
+ let context = setup();
13
+ let endpoint_client = &context.endpoint_client;
14
+
15
+ // Deploy mock receiver that allows initialization
16
+ let receiver = context.env.register(MockReceiver, ());
17
+ let src_eid = 2;
18
+ let sender = BytesN::from_array(&context.env, &[1u8; 32]);
19
+ let origin = Origin { src_eid, sender, nonce: 1 };
20
+
21
+ // For a new path (lazy nonce is 0), should depend on receiver contract
22
+ // MockReceiver allows initialization, so this should return true
23
+ let result = endpoint_client.initializable(&origin, &receiver);
24
+ assert!(result);
25
+ }
26
+
27
+ #[test]
28
+ fn test_initializable_with_receiver_rejecting_init() {
29
+ let context = setup();
30
+ let endpoint_client = &context.endpoint_client;
31
+
32
+ // Deploy mock receiver that rejects initialization
33
+ let receiver = context.env.register(MockReceiverReject, ());
34
+ let src_eid = 2;
35
+ let sender = BytesN::from_array(&context.env, &[1u8; 32]);
36
+ let origin = Origin { src_eid, sender, nonce: 1 };
37
+
38
+ // For a new path (lazy nonce is 0), should depend on receiver contract
39
+ // MockReceiverReject rejects initialization, so this should return false
40
+ let result = endpoint_client.initializable(&origin, &receiver);
41
+ assert!(!result);
42
+ }
43
+
44
+ #[test]
45
+ fn test_initializable_with_established_path() {
46
+ let context = setup();
47
+ let env = &context.env;
48
+ let endpoint_client = &context.endpoint_client;
49
+
50
+ // Deploy mock receiver that rejects initialization
51
+ let receiver = env.register(MockReceiverReject, ());
52
+ let src_eid = 2;
53
+ let sender = BytesN::from_array(env, &[1u8; 32]);
54
+
55
+ // First establish the path by skipping nonce 1
56
+ let _origin = Origin { src_eid, sender: sender.clone(), nonce: 1 };
57
+
58
+ // Set up auth for skip (receiver must authorize)
59
+ use soroban_sdk::{testutils::MockAuth, testutils::MockAuthInvoke, IntoVal};
60
+ env.mock_auths(&[MockAuth {
61
+ address: &receiver,
62
+ invoke: &MockAuthInvoke {
63
+ contract: &endpoint_client.address,
64
+ fn_name: "skip",
65
+ args: (&receiver, &receiver, &src_eid, &sender, &1u64).into_val(env),
66
+ sub_invokes: &[],
67
+ },
68
+ }]);
69
+ endpoint_client.skip(&receiver, &receiver, &src_eid, &sender, &1);
70
+
71
+ // Now the path is established (lazy_nonce > 0), should return true regardless of receiver
72
+ let origin2 = Origin { src_eid, sender, nonce: 2 };
73
+ let result = endpoint_client.initializable(&origin2, &receiver);
74
+ assert!(result);
75
+ }
76
+