@layerzerolabs/protocol-stellar-v2 0.2.29 → 0.2.30

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 (205) hide show
  1. package/.turbo/turbo-build.log +371 -321
  2. package/.turbo/turbo-lint.log +211 -202
  3. package/.turbo/turbo-test.log +1766 -1673
  4. package/Cargo.lock +11 -1
  5. package/contracts/common-macros/src/lib.rs +0 -2
  6. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__upgradeable__snapshot_generated_upgradeable_code.snap +1 -0
  7. package/contracts/endpoint-v2/src/messaging_channel.rs +32 -3
  8. package/contracts/endpoint-v2/src/tests/endpoint_setup.rs +1 -1
  9. package/contracts/endpoint-v2/src/tests/messaging_channel/clear_payload.rs +1 -1
  10. package/contracts/endpoint-v2/src/tests/messaging_channel/inbound.rs +6 -6
  11. package/contracts/endpoint-v2/src/tests/messaging_channel/inbound_payload_hash.rs +1 -1
  12. package/contracts/endpoint-v2/src/tests/messaging_channel/outbound.rs +16 -10
  13. package/contracts/macro-integration-tests/tests/runtime/oapp/options_type3.rs +10 -10
  14. package/contracts/macro-integration-tests/tests/runtime/oapp/receiver.rs +3 -3
  15. package/contracts/macro-integration-tests/tests/runtime/oapp/sender.rs +4 -3
  16. package/contracts/macro-integration-tests/tests/runtime/upgradeable/migrate_guard_and_state.rs +1 -57
  17. package/contracts/macro-integration-tests/tests/ui/lz_contract/fail/upgradeable_missing_internal.stderr +0 -30
  18. package/contracts/macro-integration-tests/tests/ui/oapp/fail/custom_wrong_value.stderr +5 -3
  19. package/contracts/macro-integration-tests/tests/ui/oapp/fail/non_struct_input.stderr +6 -4
  20. package/contracts/macro-integration-tests/tests/ui/oapp/fail/unknown_custom_option.stderr +5 -3
  21. package/contracts/macro-integration-tests/tests/ui/oapp/fail/wrong_key.stderr +5 -3
  22. package/contracts/macro-integration-tests/tests/ui/upgradeable/fail/missing_auth_trait.stderr +0 -30
  23. package/contracts/macro-integration-tests/tests/ui/upgradeable/fail/missing_upgradeable_internal.stderr +0 -30
  24. package/contracts/macro-integration-tests/tests/ui/upgradeable/pass/basic.rs +0 -2
  25. package/contracts/macro-integration-tests/tests/ui/upgradeable/pass/multisig_contract.rs +0 -2
  26. package/contracts/macro-integration-tests/tests/ui/upgradeable/pass/no_migration.rs +0 -2
  27. package/contracts/macro-integration-tests/tests/ui/upgradeable/pass/no_user_contractimpl.rs +1 -3
  28. package/contracts/message-libs/message-lib-common/src/packet_codec_v1.rs +3 -6
  29. package/contracts/message-libs/message-lib-common/src/tests/worker_options/extract_type_3_options.rs +10 -0
  30. package/contracts/message-libs/message-lib-common/src/worker_options.rs +6 -2
  31. package/contracts/message-libs/treasury/src/interfaces/zro_fee_lib.rs +3 -3
  32. package/contracts/message-libs/treasury/src/lib.rs +2 -1
  33. package/contracts/message-libs/treasury/src/tests/setup.rs +1 -1
  34. package/contracts/message-libs/treasury/src/treasury.rs +5 -2
  35. package/contracts/message-libs/uln-302/src/errors.rs +2 -0
  36. package/contracts/message-libs/uln-302/src/events.rs +3 -3
  37. package/contracts/message-libs/uln-302/src/interfaces/receive_uln.rs +8 -0
  38. package/contracts/message-libs/uln-302/src/lib.rs +2 -1
  39. package/contracts/message-libs/uln-302/src/receive_uln.rs +16 -13
  40. package/contracts/message-libs/uln-302/src/send_uln.rs +51 -24
  41. package/contracts/message-libs/uln-302/src/storage.rs +2 -2
  42. package/contracts/message-libs/uln-302/src/tests/receive_uln302/effective_receive_uln_config.rs +45 -1
  43. package/contracts/message-libs/uln-302/src/tests/receive_uln302/verifiable.rs +63 -0
  44. package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_executor_config.rs +47 -2
  45. package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_send_uln_config.rs +50 -1
  46. package/contracts/message-libs/uln-302/src/uln302.rs +0 -8
  47. package/contracts/oapps/counter/Cargo.toml +4 -4
  48. package/contracts/oapps/counter/integration_tests/setup_uln.rs +22 -2
  49. package/contracts/oapps/counter/src/counter.rs +8 -8
  50. package/contracts/oapps/oapp/src/interfaces/oapp_msg_inspector.rs +33 -10
  51. package/contracts/oapps/oapp/src/lib.rs +6 -2
  52. package/contracts/oapps/oapp/src/oapp_core.rs +49 -24
  53. package/contracts/oapps/oapp/src/oapp_options_type3.rs +21 -14
  54. package/contracts/oapps/oapp/src/oapp_receiver.rs +17 -16
  55. package/contracts/oapps/oapp/src/oapp_sender.rs +66 -15
  56. package/contracts/oapps/oapp/src/tests/oapp_core.rs +5 -5
  57. package/contracts/oapps/oapp/src/tests/oapp_options_type3.rs +18 -18
  58. package/contracts/oapps/oapp/src/tests/oapp_receiver.rs +4 -4
  59. package/contracts/oapps/oapp/src/tests/oapp_sender.rs +3 -3
  60. package/contracts/oapps/oapp-macros/Cargo.toml +0 -1
  61. package/contracts/oapps/oapp-macros/src/generators.rs +87 -46
  62. package/contracts/oapps/oapp-macros/src/lib.rs +3 -61
  63. package/contracts/oapps/oapp-macros/src/tests/oapp.rs +9 -23
  64. package/contracts/oapps/oapp-macros/src/tests/parse_custom_impls.rs +15 -11
  65. package/contracts/oapps/oft/Cargo.toml +1 -1
  66. package/contracts/oapps/oft/integration-tests/extensions/test_oft_fee.rs +3 -3
  67. package/contracts/oapps/oft/integration-tests/extensions/test_pausable.rs +4 -4
  68. package/contracts/oapps/oft/integration-tests/extensions/test_rate_limiter.rs +144 -8
  69. package/contracts/oapps/oft/integration-tests/setup.rs +4 -2
  70. package/contracts/oapps/oft/integration-tests/utils.rs +25 -11
  71. package/contracts/oapps/oft/src/extensions/oft_fee.rs +65 -63
  72. package/contracts/oapps/oft/src/extensions/pausable.rs +2 -3
  73. package/contracts/oapps/oft/src/extensions/rate_limiter.rs +22 -5
  74. package/contracts/oapps/oft/src/interfaces/mint_burnable.rs +18 -0
  75. package/contracts/oapps/oft/src/interfaces/mod.rs +3 -0
  76. package/contracts/oapps/oft/src/lib.rs +4 -2
  77. package/contracts/oapps/oft/src/oft.rs +35 -36
  78. package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +13 -9
  79. package/contracts/oapps/oft/src/oft_types/mint_burn.rs +14 -9
  80. package/contracts/oapps/oft/src/oft_types/mod.rs +14 -12
  81. package/contracts/oapps/oft/src/tests/extensions/oft_fee.rs +28 -20
  82. package/contracts/oapps/oft/src/tests/extensions/rate_limiter.rs +136 -2
  83. package/contracts/oapps/oft/src/tests/oft_types/lock_unlock.rs +12 -8
  84. package/contracts/oapps/oft-core/integration-tests/setup.rs +8 -9
  85. package/contracts/oapps/oft-core/integration-tests/test_with_sml.rs +7 -6
  86. package/contracts/oapps/oft-core/integration-tests/utils.rs +5 -4
  87. package/contracts/oapps/oft-core/src/codec/oft_compose_msg_codec.rs +2 -2
  88. package/contracts/oapps/oft-core/src/codec/oft_msg_codec.rs +33 -37
  89. package/contracts/oapps/oft-core/src/errors.rs +2 -1
  90. package/contracts/oapps/oft-core/src/events.rs +6 -0
  91. package/contracts/oapps/oft-core/src/lib.rs +8 -4
  92. package/contracts/oapps/oft-core/src/oft_core.rs +205 -148
  93. package/contracts/oapps/oft-core/src/storage.rs +4 -2
  94. package/contracts/oapps/oft-core/src/tests/test_decimals.rs +2 -2
  95. package/contracts/oapps/oft-core/src/tests/test_lz_receive.rs +6 -6
  96. package/contracts/oapps/oft-core/src/tests/test_msg_inspector.rs +7 -6
  97. package/contracts/oapps/oft-core/src/tests/test_oft_msg_codec.rs +11 -82
  98. package/contracts/oapps/oft-core/src/tests/test_quote_oft.rs +13 -13
  99. package/contracts/oapps/oft-core/src/tests/test_quote_send.rs +1 -1
  100. package/contracts/oapps/oft-core/src/tests/test_resolve_address.rs +2 -2
  101. package/contracts/oapps/oft-core/src/tests/test_send.rs +22 -22
  102. package/contracts/oapps/oft-core/src/tests/test_utils.rs +20 -22
  103. package/contracts/oapps/oft-core/src/utils.rs +12 -8
  104. package/contracts/sac-manager/Cargo.toml +25 -0
  105. package/contracts/sac-manager/src/errors.rs +18 -0
  106. package/contracts/sac-manager/src/extensions/mod.rs +6 -0
  107. package/contracts/sac-manager/src/extensions/redistribution.rs +109 -0
  108. package/contracts/sac-manager/src/extensions/supply_control/mod.rs +488 -0
  109. package/contracts/sac-manager/src/extensions/supply_control/rate_limit.rs +126 -0
  110. package/contracts/sac-manager/src/interfaces/mod.rs +3 -0
  111. package/contracts/sac-manager/src/interfaces/sac_manager.rs +52 -0
  112. package/contracts/sac-manager/src/lib.rs +23 -0
  113. package/contracts/sac-manager/src/sac_manager.rs +193 -0
  114. package/contracts/sac-manager/src/storage.rs +20 -0
  115. package/contracts/sac-manager/src/tests/mod.rs +14 -0
  116. package/contracts/sac-manager/src/tests/redistribution/mod.rs +1 -0
  117. package/contracts/sac-manager/src/tests/redistribution/redistribute_funds.rs +82 -0
  118. package/contracts/sac-manager/src/tests/sac_manager/admin_mint.rs +206 -0
  119. package/contracts/sac-manager/src/tests/sac_manager/burn.rs +215 -0
  120. package/contracts/sac-manager/src/tests/sac_manager/clawback.rs +209 -0
  121. package/contracts/sac-manager/src/tests/sac_manager/mint.rs +252 -0
  122. package/contracts/sac-manager/src/tests/sac_manager/mod.rs +9 -0
  123. package/contracts/sac-manager/src/tests/sac_manager/set_admin.rs +36 -0
  124. package/contracts/sac-manager/src/tests/sac_manager/set_authorized.rs +43 -0
  125. package/contracts/sac-manager/src/tests/sac_manager/set_oft_address.rs +47 -0
  126. package/contracts/sac-manager/src/tests/sac_manager/test_helper.rs +75 -0
  127. package/contracts/sac-manager/src/tests/sac_manager/view_functions.rs +60 -0
  128. package/contracts/sac-manager/src/tests/supply_control/enumerable_set.rs +256 -0
  129. package/contracts/sac-manager/src/tests/supply_control/mod.rs +8 -0
  130. package/contracts/sac-manager/src/tests/supply_control/refill.rs +90 -0
  131. package/contracts/sac-manager/src/tests/supply_control/set_mint_whitelist.rs +245 -0
  132. package/contracts/sac-manager/src/tests/supply_control/set_supply_controller.rs +267 -0
  133. package/contracts/sac-manager/src/tests/supply_control/set_supply_controller_manager.rs +122 -0
  134. package/contracts/sac-manager/src/tests/supply_control/test_helper.rs +38 -0
  135. package/contracts/sac-manager/src/tests/supply_control/update_allow_any_mint_burn.rs +114 -0
  136. package/contracts/sac-manager/src/tests/supply_control/update_limit_config.rs +257 -0
  137. package/contracts/sac-manager/src/tests/test_helper.rs +190 -0
  138. package/contracts/upgrader/src/lib.rs +2 -1
  139. package/contracts/utils/src/errors.rs +0 -1
  140. package/contracts/utils/src/tests/upgradeable.rs +0 -66
  141. package/contracts/utils/src/upgradeable.rs +0 -18
  142. package/contracts/workers/dvn/src/dvn.rs +2 -2
  143. package/contracts/workers/dvn/src/interfaces/dvn.rs +2 -2
  144. package/contracts/workers/dvn/src/lib.rs +2 -1
  145. package/contracts/workers/dvn-fee-lib/src/lib.rs +3 -1
  146. package/contracts/workers/executor/src/auth.rs +42 -26
  147. package/contracts/workers/executor/src/executor.rs +28 -3
  148. package/contracts/workers/executor/src/lib.rs +4 -2
  149. package/contracts/workers/executor/src/storage.rs +21 -1
  150. package/contracts/workers/executor/src/tests/auth.rs +64 -20
  151. package/contracts/workers/executor/src/tests/executor.rs +1 -1
  152. package/contracts/workers/executor/src/tests/setup.rs +18 -0
  153. package/contracts/workers/executor-fee-lib/src/lib.rs +4 -1
  154. package/contracts/workers/executor-helper/src/executor_helper.rs +24 -10
  155. package/contracts/workers/executor-helper/src/tests/setup.rs +147 -34
  156. package/contracts/workers/price-feed/src/lib.rs +3 -1
  157. package/contracts/workers/worker/src/lib.rs +2 -1
  158. package/contracts/workers/worker/src/worker.rs +31 -17
  159. package/docs/oapp-guide.md +17 -8
  160. package/docs/oft-guide.md +3 -3
  161. package/package.json +3 -3
  162. package/sdk/.turbo/turbo-test.log +512 -351
  163. package/sdk/dist/generated/bml.d.ts +3 -9
  164. package/sdk/dist/generated/bml.js +6 -7
  165. package/sdk/dist/generated/counter.d.ts +22 -28
  166. package/sdk/dist/generated/counter.js +11 -12
  167. package/sdk/dist/generated/dvn.d.ts +36 -54
  168. package/sdk/dist/generated/dvn.js +10 -15
  169. package/sdk/dist/generated/dvn_fee_lib.d.ts +3 -21
  170. package/sdk/dist/generated/dvn_fee_lib.js +6 -11
  171. package/sdk/dist/generated/endpoint.d.ts +3 -9
  172. package/sdk/dist/generated/endpoint.js +6 -7
  173. package/sdk/dist/generated/executor.d.ts +80 -54
  174. package/sdk/dist/generated/executor.js +16 -16
  175. package/sdk/dist/generated/executor_fee_lib.d.ts +3 -21
  176. package/sdk/dist/generated/executor_fee_lib.js +6 -11
  177. package/sdk/dist/generated/executor_helper.d.ts +36 -42
  178. package/sdk/dist/generated/executor_helper.js +9 -10
  179. package/sdk/dist/generated/layerzero_view.d.ts +20 -32
  180. package/sdk/dist/generated/layerzero_view.js +25 -26
  181. package/sdk/dist/generated/oft.d.ts +147 -79
  182. package/sdk/dist/generated/oft.js +47 -54
  183. package/sdk/dist/generated/price_feed.d.ts +20 -38
  184. package/sdk/dist/generated/price_feed.js +15 -20
  185. package/sdk/dist/generated/sac_manager.d.ts +1309 -0
  186. package/sdk/dist/generated/sac_manager.js +484 -0
  187. package/sdk/dist/generated/sml.d.ts +3 -9
  188. package/sdk/dist/generated/sml.js +6 -7
  189. package/sdk/dist/generated/treasury.d.ts +3 -9
  190. package/sdk/dist/generated/treasury.js +8 -9
  191. package/sdk/dist/generated/uln302.d.ts +20 -20
  192. package/sdk/dist/generated/uln302.js +25 -22
  193. package/sdk/dist/generated/upgrader.d.ts +3 -9
  194. package/sdk/dist/generated/upgrader.js +6 -7
  195. package/sdk/dist/index.d.ts +1 -0
  196. package/sdk/dist/index.js +1 -0
  197. package/sdk/package.json +1 -1
  198. package/sdk/src/index.ts +1 -0
  199. package/sdk/test/oft-sml.test.ts +7 -5
  200. package/sdk/test/sac-manager-redistribution.test.ts +578 -0
  201. package/sdk/test/suites/globalSetup.ts +11 -6
  202. package/sdk/test/test_data/test_upgradeable_dvn.wasm +0 -0
  203. package/sdk/test/upgrader.test.ts +75 -202
  204. package/sdk/test/utils.ts +40 -0
  205. package/tools/ts-bindings-gen/src/main.rs +1 -0
@@ -0,0 +1,252 @@
1
+ //! Mint (MintBurnable) Integration Tests
2
+
3
+ use super::test_helper::{mock_set_authorized_auth, mock_set_mint_whitelist_auth, mock_set_supply_controller_auth};
4
+ use crate::errors::SacManagerError;
5
+ use crate::extensions::redistribution::RedistributeFunds;
6
+ use crate::extensions::supply_control::{LimitConfig, SupplyControlError, SupplyControllerConfig};
7
+ use crate::tests::test_helper::{mock_oft_mint_auth, TestSetup};
8
+ use soroban_sdk::{testutils::IssuerFlags, Vec};
9
+ use utils::testing_utils::assert_contains_event;
10
+
11
+ // =========================================================================
12
+ // Mint Tests (without Supply Control) — OFT calls mint
13
+ // =========================================================================
14
+
15
+ #[test]
16
+ fn test_mint_by_oft() {
17
+ let setup = TestSetup::new().with_manager_as_sac_admin().build();
18
+ let recipient = setup.generate_address();
19
+
20
+ // Supply control is disabled by default
21
+ assert!(!setup.sac_manager_client.supply_control_enabled());
22
+
23
+ // OFT can mint when supply control is disabled (no SupplyIncreased event emitted)
24
+ mock_oft_mint_auth(&setup, &recipient, 1000_i128);
25
+ setup.sac_manager_client.mint(&recipient, &1000);
26
+ assert_eq!(setup.sac_client.balance(&recipient), 1000);
27
+ }
28
+
29
+ #[test]
30
+ fn test_oft_mint_redistributes_when_recipient_blacklisted() {
31
+ let setup = TestSetup::new().with_manager_as_sac_admin().with_redistribution_enabled().build();
32
+ let blacklisted_recipient = setup.generate_address();
33
+
34
+ // Enable issuer flags required for blacklist behavior in SAC tests.
35
+ setup.sac_contract.issuer().set_flag(IssuerFlags::RevocableFlag);
36
+ setup.sac_contract.issuer().set_flag(IssuerFlags::ClawbackEnabledFlag);
37
+
38
+ mock_set_authorized_auth(&setup, &blacklisted_recipient, false);
39
+ setup.sac_manager_client.set_authorized(&blacklisted_recipient, &false);
40
+ assert!(!setup.sac_client.authorized(&blacklisted_recipient));
41
+
42
+ let owner_balance_before = setup.sac_client.balance(&setup.owner);
43
+ let blacklisted_balance_before = setup.sac_client.balance(&blacklisted_recipient);
44
+
45
+ mock_oft_mint_auth(&setup, &blacklisted_recipient, 700_i128);
46
+ setup.sac_manager_client.mint(&blacklisted_recipient, &700);
47
+
48
+ // No SupplyIncreased when supply control is off; only RedistributeFunds is emitted.
49
+ let expected = RedistributeFunds { user: blacklisted_recipient.clone(), amount: 700 };
50
+ assert_contains_event(&setup.env, &setup.sac_manager, expected);
51
+
52
+ assert_eq!(setup.sac_client.balance(&blacklisted_recipient), blacklisted_balance_before);
53
+ assert_eq!(setup.sac_client.balance(&setup.owner), owner_balance_before + 700);
54
+ }
55
+
56
+ #[test]
57
+ fn test_mint_fails_when_oft_not_set() {
58
+ let setup = TestSetup::new().without_oft().build();
59
+ let recipient = setup.generate_address();
60
+
61
+ let result = setup.sac_manager_client.try_mint(&recipient, &1000);
62
+ assert_eq!(result.err().unwrap().unwrap(), SacManagerError::OftAddressNotSet.into());
63
+ }
64
+
65
+ // =========================================================================
66
+ // Mint Tests (with Supply Control)
67
+ // =========================================================================
68
+
69
+ #[test]
70
+ fn test_mint_within_rate_limit() {
71
+ let setup = TestSetup::new().with_manager_as_sac_admin().with_supply_control_enabled().build();
72
+ let recipient = setup.generate_address();
73
+
74
+ // Add the OFT as a supply controller
75
+ let config = SupplyControllerConfig {
76
+ limit_config: LimitConfig { limit_capacity: 1_000, refill_per_second: 10 },
77
+ allow_any_mint_burn: true,
78
+ whitelist_addresses: Vec::new(&setup.env),
79
+ };
80
+ mock_set_supply_controller_auth(&setup, &setup.sc_manager, &setup.oft, &Some(config.clone()));
81
+ setup.sac_manager_client.set_supply_controller(&setup.sc_manager, &setup.oft, &Some(config.clone()));
82
+
83
+ // Mint within limit should succeed
84
+ mock_oft_mint_auth(&setup, &recipient, 500_i128);
85
+ setup.sac_manager_client.mint(&recipient, &500);
86
+ assert_eq!(setup.sac_client.balance(&recipient), 500);
87
+ assert_eq!(setup.sac_manager_client.get_remaining_mint_amount(&setup.oft), 500);
88
+ }
89
+
90
+ #[test]
91
+ fn test_mint_to_whitelisted_address() {
92
+ let setup = TestSetup::new().with_manager_as_sac_admin().with_supply_control_enabled().build();
93
+ let whitelisted = setup.generate_address();
94
+
95
+ // Add OFT as controller with whitelist (NOT allow_any_mint_burn)
96
+ let config = SupplyControllerConfig {
97
+ limit_config: LimitConfig { limit_capacity: 1_000, refill_per_second: 0 },
98
+ allow_any_mint_burn: false,
99
+ whitelist_addresses: Vec::new(&setup.env),
100
+ };
101
+ mock_set_supply_controller_auth(&setup, &setup.sc_manager, &setup.oft, &Some(config.clone()));
102
+ setup.sac_manager_client.set_supply_controller(&setup.sc_manager, &setup.oft, &Some(config.clone()));
103
+
104
+ // Add whitelisted address to the whitelist
105
+ mock_set_mint_whitelist_auth(&setup, &setup.sc_manager, &setup.oft, &whitelisted, true);
106
+ setup.sac_manager_client.set_mint_whitelist(&setup.sc_manager, &setup.oft, &whitelisted, &true);
107
+
108
+ // Mint to whitelisted address should succeed
109
+ mock_oft_mint_auth(&setup, &whitelisted, 500_i128);
110
+ setup.sac_manager_client.mint(&whitelisted, &500);
111
+ assert_eq!(setup.sac_client.balance(&whitelisted), 500);
112
+ }
113
+
114
+ // =========================================================================
115
+ // Mint Error Cases (Supply Control)
116
+ // =========================================================================
117
+
118
+ #[test]
119
+ fn test_mint_exceeds_rate_limit() {
120
+ let setup = TestSetup::new().with_manager_as_sac_admin().with_supply_control_enabled().build();
121
+ let recipient = setup.generate_address();
122
+
123
+ let config = SupplyControllerConfig {
124
+ limit_config: LimitConfig { limit_capacity: 100, refill_per_second: 1 },
125
+ allow_any_mint_burn: true,
126
+ whitelist_addresses: Vec::new(&setup.env),
127
+ };
128
+ mock_set_supply_controller_auth(&setup, &setup.sc_manager, &setup.oft, &Some(config.clone()));
129
+ setup.sac_manager_client.set_supply_controller(&setup.sc_manager, &setup.oft, &Some(config.clone()));
130
+
131
+ // Try to mint more than limit - should fail
132
+ mock_oft_mint_auth(&setup, &recipient, 200_i128);
133
+ let result = setup.sac_manager_client.try_mint(&recipient, &200);
134
+ assert_eq!(result.err().unwrap().unwrap(), SupplyControlError::RateLimitExceeded.into());
135
+ }
136
+
137
+ #[test]
138
+ fn test_mint_failure_does_not_change_remaining_amount() {
139
+ let setup = TestSetup::new().with_manager_as_sac_admin().with_supply_control_enabled().build();
140
+ let recipient = setup.generate_address();
141
+
142
+ let config = SupplyControllerConfig {
143
+ limit_config: LimitConfig { limit_capacity: 100, refill_per_second: 1 },
144
+ allow_any_mint_burn: true,
145
+ whitelist_addresses: Vec::new(&setup.env),
146
+ };
147
+ mock_set_supply_controller_auth(&setup, &setup.sc_manager, &setup.oft, &Some(config.clone()));
148
+ setup.sac_manager_client.set_supply_controller(&setup.sc_manager, &setup.oft, &Some(config.clone()));
149
+
150
+ let remaining_before = setup.sac_manager_client.get_remaining_mint_amount(&setup.oft);
151
+ mock_oft_mint_auth(&setup, &recipient, 200_i128);
152
+ let result = setup.sac_manager_client.try_mint(&recipient, &200);
153
+ let remaining_after = setup.sac_manager_client.get_remaining_mint_amount(&setup.oft);
154
+
155
+ assert_eq!(result.err().unwrap().unwrap(), SupplyControlError::RateLimitExceeded.into());
156
+ assert_eq!(remaining_after, remaining_before);
157
+ }
158
+
159
+ #[test]
160
+ fn test_mint_to_non_whitelisted_fails() {
161
+ let setup = TestSetup::new().with_manager_as_sac_admin().with_supply_control_enabled().build();
162
+ let whitelisted = setup.generate_address();
163
+ let not_whitelisted = setup.generate_address();
164
+
165
+ let config = SupplyControllerConfig {
166
+ limit_config: LimitConfig { limit_capacity: 1_000, refill_per_second: 0 },
167
+ allow_any_mint_burn: false,
168
+ whitelist_addresses: Vec::new(&setup.env),
169
+ };
170
+ mock_set_supply_controller_auth(&setup, &setup.sc_manager, &setup.oft, &Some(config.clone()));
171
+ setup.sac_manager_client.set_supply_controller(&setup.sc_manager, &setup.oft, &Some(config.clone()));
172
+
173
+ // Add whitelisted address (not_whitelisted is NOT added)
174
+ mock_set_mint_whitelist_auth(&setup, &setup.sc_manager, &setup.oft, &whitelisted, true);
175
+ setup.sac_manager_client.set_mint_whitelist(&setup.sc_manager, &setup.oft, &whitelisted, &true);
176
+
177
+ // Mint to non-whitelisted address should fail
178
+ mock_oft_mint_auth(&setup, &not_whitelisted, 500_i128);
179
+ let result = setup.sac_manager_client.try_mint(&not_whitelisted, &500);
180
+ assert_eq!(result.err().unwrap().unwrap(), SupplyControlError::CannotMintToAddress.into());
181
+ }
182
+
183
+ #[test]
184
+ fn test_mint_fails_when_oft_not_supply_controller() {
185
+ let setup = TestSetup::new().with_manager_as_sac_admin().with_supply_control_enabled().build();
186
+ let recipient = setup.generate_address();
187
+
188
+ // OFT is NOT added as supply controller — should fail
189
+ mock_oft_mint_auth(&setup, &recipient, 500_i128);
190
+ let result = setup.sac_manager_client.try_mint(&recipient, &500);
191
+ assert_eq!(result.err().unwrap().unwrap(), SupplyControlError::NotFound.into());
192
+
193
+ // Non-controller should report zero remaining mint amount.
194
+ assert_eq!(setup.sac_manager_client.get_remaining_mint_amount(&recipient), 0);
195
+ }
196
+
197
+ // =========================================================================
198
+ // get_remaining_mint_amount Tests
199
+ // =========================================================================
200
+
201
+ #[test]
202
+ fn test_unlimited_rate_limit() {
203
+ let setup = TestSetup::new().with_manager_as_sac_admin().build();
204
+
205
+ // refill_per_second == 0 means unlimited
206
+ let config = SupplyControllerConfig {
207
+ limit_config: LimitConfig { limit_capacity: 1_000, refill_per_second: 0 },
208
+ allow_any_mint_burn: true,
209
+ whitelist_addresses: Vec::new(&setup.env),
210
+ };
211
+ mock_set_supply_controller_auth(&setup, &setup.sc_manager, &setup.oft, &Some(config.clone()));
212
+ setup.sac_manager_client.set_supply_controller(&setup.sc_manager, &setup.oft, &Some(config.clone()));
213
+
214
+ let remaining = setup.sac_manager_client.get_remaining_mint_amount(&setup.oft);
215
+ assert_eq!(remaining, i128::MAX);
216
+ }
217
+
218
+ #[test]
219
+ fn test_mint_exact_capacity_then_next_fails() {
220
+ let setup = TestSetup::new().with_manager_as_sac_admin().with_supply_control_enabled().build();
221
+ let recipient = setup.generate_address();
222
+
223
+ let config = SupplyControllerConfig {
224
+ limit_config: LimitConfig { limit_capacity: 1_000, refill_per_second: 1 },
225
+ allow_any_mint_burn: true,
226
+ whitelist_addresses: Vec::new(&setup.env),
227
+ };
228
+ mock_set_supply_controller_auth(&setup, &setup.sc_manager, &setup.oft, &Some(config.clone()));
229
+ setup.sac_manager_client.set_supply_controller(&setup.sc_manager, &setup.oft, &Some(config.clone()));
230
+
231
+ mock_oft_mint_auth(&setup, &recipient, 1000_i128);
232
+ setup.sac_manager_client.mint(&recipient, &1000);
233
+ assert_eq!(setup.sac_manager_client.get_remaining_mint_amount(&setup.oft), 0);
234
+
235
+ mock_oft_mint_auth(&setup, &recipient, 1_i128);
236
+ let result = setup.sac_manager_client.try_mint(&recipient, &1);
237
+ assert_eq!(result.err().unwrap().unwrap(), SupplyControlError::RateLimitExceeded.into());
238
+ }
239
+
240
+ // =========================================================================
241
+ // Mint Auth Tests
242
+ // =========================================================================
243
+
244
+ #[test]
245
+ #[should_panic(expected = "Error(Auth, InvalidAction)")]
246
+ fn test_mint_fails_without_oft_auth() {
247
+ // No mock_all_auths — the OFT address won't be authorized
248
+ let setup = TestSetup::new().with_manager_as_sac_admin().build();
249
+ let recipient = setup.generate_address();
250
+
251
+ setup.sac_manager_client.mint(&recipient, &1000);
252
+ }
@@ -0,0 +1,9 @@
1
+ mod clawback;
2
+ mod admin_mint;
3
+ mod burn;
4
+ mod mint;
5
+ mod set_admin;
6
+ mod set_authorized;
7
+ mod set_oft_address;
8
+ mod test_helper;
9
+ mod view_functions;
@@ -0,0 +1,36 @@
1
+ //! release_sac_admin Integration Tests
2
+
3
+ use super::test_helper::mock_release_sac_admin_auth;
4
+ use crate::tests::test_helper::TestSetup;
5
+
6
+ // =========================================================================
7
+ // release_sac_admin Tests
8
+ // =========================================================================
9
+
10
+ #[test]
11
+ fn test_release_sac_admin() {
12
+ let setup = TestSetup::new().with_manager_as_sac_admin().build();
13
+ let new_admin = setup.generate_address();
14
+
15
+ // Current SAC admin is the manager (configured by test setup).
16
+ assert_eq!(setup.sac_client.admin(), setup.sac_manager);
17
+
18
+ // Owner can change SAC admin
19
+ mock_release_sac_admin_auth(&setup, &new_admin);
20
+ setup.sac_manager_client.release_sac_admin(&new_admin);
21
+ assert_eq!(setup.sac_client.admin(), new_admin);
22
+ }
23
+
24
+ // =========================================================================
25
+ // release_sac_admin Auth Tests
26
+ // =========================================================================
27
+
28
+ #[test]
29
+ #[should_panic(expected = "Error(Auth, InvalidAction)")]
30
+ fn test_release_sac_admin_without_auth() {
31
+ let setup = TestSetup::new().build();
32
+ let new_admin = setup.generate_address();
33
+
34
+ // Should panic because owner doesn't authorize the call
35
+ setup.sac_manager_client.release_sac_admin(&new_admin);
36
+ }
@@ -0,0 +1,43 @@
1
+ //! set_authorized Integration Tests
2
+ //!
3
+ //! Requires revocable issuer flag on the SAC before authorization can be changed.
4
+
5
+ use super::test_helper::mock_set_authorized_auth;
6
+ use crate::tests::test_helper::TestSetup;
7
+ use soroban_sdk::testutils::IssuerFlags;
8
+
9
+ // =========================================================================
10
+ // set_authorized Tests
11
+ // =========================================================================
12
+
13
+ #[test]
14
+ fn test_set_authorized_by_owner() {
15
+ let setup = TestSetup::new().with_manager_as_sac_admin().build();
16
+ let user = setup.generate_address();
17
+
18
+ // Enable issuer flag required by SAC for set_authorized.
19
+ setup.sac_contract.issuer().set_flag(IssuerFlags::RevocableFlag);
20
+ assert!(setup.sac_client.authorized(&user));
21
+
22
+ mock_set_authorized_auth(&setup, &user, false);
23
+ setup.sac_manager_client.set_authorized(&user, &false);
24
+ assert!(!setup.sac_client.authorized(&user));
25
+
26
+ mock_set_authorized_auth(&setup, &user, true);
27
+ setup.sac_manager_client.set_authorized(&user, &true);
28
+ assert!(setup.sac_client.authorized(&user));
29
+ }
30
+
31
+ // =========================================================================
32
+ // set_authorized Auth Tests
33
+ // =========================================================================
34
+
35
+ #[test]
36
+ #[should_panic(expected = "Error(Auth, InvalidAction)")]
37
+ fn test_set_authorized_without_auth() {
38
+ let setup = TestSetup::new().build();
39
+ let user = setup.generate_address();
40
+
41
+ // Should panic because owner doesn't authorize the call
42
+ setup.sac_manager_client.set_authorized(&user, &false);
43
+ }
@@ -0,0 +1,47 @@
1
+ //! set_oft_address Integration Tests
2
+
3
+ use super::test_helper::mock_set_oft_address_auth;
4
+ use crate::errors::SacManagerError;
5
+ use crate::tests::test_helper::TestSetup;
6
+
7
+ // =========================================================================
8
+ // set_oft_address Error Cases
9
+ // =========================================================================
10
+
11
+ #[test]
12
+ fn test_set_oft_address_by_owner_when_not_set() {
13
+ let setup = TestSetup::new().without_oft().build();
14
+ let new_oft = setup.generate_address();
15
+
16
+ let initial = setup.sac_manager_client.try_oft_address();
17
+ assert_eq!(initial.err().unwrap().unwrap(), SacManagerError::OftAddressNotSet.into());
18
+
19
+ mock_set_oft_address_auth(&setup, &new_oft);
20
+ setup.sac_manager_client.set_oft_address(&new_oft);
21
+ assert_eq!(setup.sac_manager_client.oft_address(), new_oft);
22
+ }
23
+
24
+ #[test]
25
+ fn test_set_oft_address_fails_if_same_value() {
26
+ let setup = TestSetup::new().build();
27
+
28
+ // Setting the same OFT address should fail with SameValue
29
+ mock_set_oft_address_auth(&setup, &setup.oft);
30
+ let result = setup.sac_manager_client.try_set_oft_address(&setup.oft);
31
+ assert_eq!(result.err().unwrap().unwrap(), SacManagerError::SameValue.into());
32
+ }
33
+
34
+ // =========================================================================
35
+ // set_oft_address Auth Tests
36
+ // =========================================================================
37
+
38
+ #[test]
39
+ #[should_panic(expected = "Error(Auth, InvalidAction)")]
40
+ fn test_set_oft_address_without_auth() {
41
+ // Build without mock_all_auths and without setting OFT (to test auth, not the once-only check)
42
+ let setup = TestSetup::new().without_oft().build();
43
+ let new_oft = setup.generate_address();
44
+
45
+ // Should panic because owner doesn't authorize the call
46
+ setup.sac_manager_client.set_oft_address(&new_oft);
47
+ }
@@ -0,0 +1,75 @@
1
+ use crate::tests::test_helper::{mock_auth, TestSetup};
2
+ use soroban_sdk::{
3
+ testutils::{MockAuth, MockAuthInvoke},
4
+ Address, IntoVal,
5
+ };
6
+
7
+ pub use crate::tests::test_helper::mock_set_supply_controller_auth;
8
+
9
+ pub fn mock_set_mint_whitelist_auth(
10
+ setup: &TestSetup,
11
+ sender: &Address,
12
+ controller: &Address,
13
+ mint_addr: &Address,
14
+ active: bool,
15
+ ) {
16
+ mock_auth(&setup.env, &setup.sac_manager, sender, "set_mint_whitelist", (sender, controller, mint_addr, active));
17
+ }
18
+
19
+ pub fn mock_authorized_mint_auth(setup: &TestSetup, sender: &Address, recipient: &Address, amount: i128) {
20
+ mock_auth(&setup.env, &setup.sac_manager, sender, "authorized_mint", (sender, recipient, amount));
21
+ }
22
+
23
+ pub fn mock_clawback_auth(setup: &TestSetup, sender: &Address, from: &Address, amount: i128) {
24
+ mock_auth(&setup.env, &setup.sac_manager, sender, "clawback", (sender, from, amount));
25
+ }
26
+
27
+ pub fn mock_burn_auth(setup: &TestSetup, from: &Address, amount: i128) {
28
+ let sac_burn_sub_invoke = MockAuthInvoke {
29
+ contract: &setup.sac,
30
+ fn_name: "burn",
31
+ args: (from, amount).into_val(&setup.env),
32
+ sub_invokes: &[],
33
+ };
34
+
35
+ let from_sub_invokes = [sac_burn_sub_invoke];
36
+
37
+ setup.env.mock_auths(&[
38
+ // `from` authorizes sac_manager.burn → nested sac.burn(from, amount)
39
+ MockAuth {
40
+ address: from,
41
+ invoke: &MockAuthInvoke {
42
+ contract: &setup.sac_manager,
43
+ fn_name: "burn",
44
+ args: (from, amount).into_val(&setup.env),
45
+ sub_invokes: &from_sub_invokes,
46
+ },
47
+ },
48
+ // OFT also authorizes sac_manager.burn (no sub-invokes needed)
49
+ MockAuth {
50
+ address: &setup.oft,
51
+ invoke: &MockAuthInvoke {
52
+ contract: &setup.sac_manager,
53
+ fn_name: "burn",
54
+ args: (from, amount).into_val(&setup.env),
55
+ sub_invokes: &[],
56
+ },
57
+ },
58
+ ]);
59
+ }
60
+
61
+ pub fn mock_set_authorized_auth(setup: &TestSetup, user: &Address, authorize: bool) {
62
+ mock_auth(&setup.env, &setup.sac_manager, &setup.owner, "set_authorized", (user, authorize));
63
+ }
64
+
65
+ pub fn mock_release_sac_admin_auth(setup: &TestSetup, new_admin: &Address) {
66
+ mock_auth(&setup.env, &setup.sac_manager, &setup.owner, "release_sac_admin", (new_admin,));
67
+ }
68
+
69
+ pub fn mock_set_oft_address_auth(setup: &TestSetup, new_oft: &Address) {
70
+ mock_auth(&setup.env, &setup.sac_manager, &setup.owner, "set_oft_address", (new_oft,));
71
+ }
72
+
73
+ pub fn mock_sac_owner_mint_auth(setup: &TestSetup, recipient: &Address, amount: i128) {
74
+ mock_auth(&setup.env, &setup.sac, &setup.owner, "mint", (recipient, amount));
75
+ }
@@ -0,0 +1,60 @@
1
+ //! View Functions Integration Tests
2
+
3
+ use crate::errors::SacManagerError;
4
+ use crate::tests::test_helper::TestSetup;
5
+
6
+ // =========================================================================
7
+ // Core View Functions
8
+ // =========================================================================
9
+
10
+ #[test]
11
+ fn test_underlying_sac() {
12
+ let setup = TestSetup::new().build();
13
+ assert_eq!(setup.sac_manager_client.underlying_sac(), setup.sac);
14
+ }
15
+
16
+ #[test]
17
+ fn test_oft_address() {
18
+ let setup = TestSetup::new().build();
19
+ assert_eq!(setup.sac_manager_client.oft_address(), setup.oft);
20
+ }
21
+
22
+ #[test]
23
+ fn test_oft_address_fails_when_not_set() {
24
+ let setup = TestSetup::new().without_oft().build();
25
+
26
+ let result = setup.sac_manager_client.try_oft_address();
27
+ assert_eq!(result.err().unwrap().unwrap(), SacManagerError::OftAddressNotSet.into());
28
+ }
29
+
30
+ // =========================================================================
31
+ // Redistribution Settings
32
+ // =========================================================================
33
+
34
+ #[test]
35
+ fn test_redistribution_disabled_by_default() {
36
+ let setup = TestSetup::new().build();
37
+ assert!(!setup.sac_manager_client.redistribution_enabled());
38
+ }
39
+
40
+ #[test]
41
+ fn test_redistribution_enabled_at_construction() {
42
+ let setup: TestSetup<'_> = TestSetup::new().with_redistribution_enabled().build();
43
+ assert!(setup.sac_manager_client.redistribution_enabled());
44
+ }
45
+
46
+ // =========================================================================
47
+ // Supply Control Settings
48
+ // =========================================================================
49
+
50
+ #[test]
51
+ fn test_supply_control_disabled_by_default() {
52
+ let setup = TestSetup::new().build();
53
+ assert!(!setup.sac_manager_client.supply_control_enabled());
54
+ }
55
+
56
+ #[test]
57
+ fn test_supply_control_enabled_at_construction() {
58
+ let setup = TestSetup::new().with_supply_control_enabled().build();
59
+ assert!(setup.sac_manager_client.supply_control_enabled());
60
+ }