@layerzerolabs/protocol-stellar-v2 0.2.33 → 0.2.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +377 -392
- package/.turbo/turbo-lint.log +209 -207
- package/.turbo/turbo-test.log +1687 -1753
- package/contracts/oapps/oft/integration-tests/extensions/test_oft_fee.rs +5 -11
- package/contracts/oapps/oft/integration-tests/extensions/test_pausable.rs +7 -14
- package/contracts/oapps/oft/integration-tests/extensions/test_rate_limiter.rs +11 -22
- package/contracts/oapps/oft/integration-tests/setup.rs +59 -7
- package/contracts/oapps/oft/integration-tests/utils.rs +28 -2
- package/contracts/oapps/oft/src/interfaces/mintable.rs +14 -0
- package/contracts/oapps/oft/src/interfaces/mod.rs +2 -2
- package/contracts/oapps/oft/src/oft.rs +3 -3
- package/contracts/oapps/oft/src/oft_types/mint_burn.rs +8 -8
- package/contracts/oapps/oft/src/oft_types/mod.rs +3 -4
- package/contracts/oapps/oft/src/tests/extensions/rate_limiter.rs +7 -5
- package/contracts/oapps/sac-manager/src/errors.rs +14 -0
- package/contracts/{sac-manager → oapps/sac-manager}/src/lib.rs +0 -4
- package/contracts/oapps/sac-manager/src/sac_manager.rs +115 -0
- package/contracts/oapps/sac-manager/src/storage.rs +20 -0
- package/contracts/{sac-manager → oapps/sac-manager}/src/tests/mod.rs +0 -4
- package/contracts/oapps/sac-manager/src/tests/sac_manager/clawback.rs +86 -0
- package/contracts/oapps/sac-manager/src/tests/sac_manager/mint.rs +58 -0
- package/contracts/{sac-manager → oapps/sac-manager}/src/tests/sac_manager/mod.rs +1 -3
- package/contracts/oapps/sac-manager/src/tests/sac_manager/set_minter.rs +69 -0
- package/contracts/oapps/sac-manager/src/tests/sac_manager/test_helper.rs +18 -0
- package/contracts/oapps/sac-manager/src/tests/sac_manager/view_functions.rs +28 -0
- package/contracts/{sac-manager → oapps/sac-manager}/src/tests/test_helper.rs +16 -59
- package/package.json +8 -3
- package/sdk/.turbo/turbo-test.log +373 -374
- package/sdk/dist/generated/oft.d.ts +3 -3
- package/sdk/dist/generated/oft.js +4 -4
- package/sdk/dist/generated/sac_manager.d.ts +26 -318
- package/sdk/dist/generated/sac_manager.js +23 -129
- package/sdk/package.json +6 -1
- package/sdk/test/oft-sml.test.ts +72 -36
- package/sdk/test/sac-manager-redistribution.test.ts +38 -182
- package/contracts/oapps/oft/src/interfaces/mint_burnable.rs +0 -18
- package/contracts/sac-manager/src/errors.rs +0 -18
- package/contracts/sac-manager/src/extensions/mod.rs +0 -6
- package/contracts/sac-manager/src/extensions/redistribution.rs +0 -109
- package/contracts/sac-manager/src/extensions/supply_control/mod.rs +0 -488
- package/contracts/sac-manager/src/extensions/supply_control/rate_limit.rs +0 -126
- package/contracts/sac-manager/src/interfaces/mod.rs +0 -3
- package/contracts/sac-manager/src/interfaces/sac_manager.rs +0 -52
- package/contracts/sac-manager/src/sac_manager.rs +0 -193
- package/contracts/sac-manager/src/storage.rs +0 -20
- package/contracts/sac-manager/src/tests/redistribution/mod.rs +0 -1
- package/contracts/sac-manager/src/tests/redistribution/redistribute_funds.rs +0 -82
- package/contracts/sac-manager/src/tests/sac_manager/admin_mint.rs +0 -206
- package/contracts/sac-manager/src/tests/sac_manager/burn.rs +0 -215
- package/contracts/sac-manager/src/tests/sac_manager/clawback.rs +0 -209
- package/contracts/sac-manager/src/tests/sac_manager/mint.rs +0 -252
- package/contracts/sac-manager/src/tests/sac_manager/set_oft_address.rs +0 -47
- package/contracts/sac-manager/src/tests/sac_manager/test_helper.rs +0 -75
- package/contracts/sac-manager/src/tests/sac_manager/view_functions.rs +0 -60
- package/contracts/sac-manager/src/tests/supply_control/enumerable_set.rs +0 -256
- package/contracts/sac-manager/src/tests/supply_control/mod.rs +0 -8
- package/contracts/sac-manager/src/tests/supply_control/refill.rs +0 -90
- package/contracts/sac-manager/src/tests/supply_control/set_mint_whitelist.rs +0 -245
- package/contracts/sac-manager/src/tests/supply_control/set_supply_controller.rs +0 -267
- package/contracts/sac-manager/src/tests/supply_control/set_supply_controller_manager.rs +0 -122
- package/contracts/sac-manager/src/tests/supply_control/test_helper.rs +0 -38
- package/contracts/sac-manager/src/tests/supply_control/update_allow_any_mint_burn.rs +0 -114
- package/contracts/sac-manager/src/tests/supply_control/update_limit_config.rs +0 -257
- /package/contracts/{sac-manager → oapps/sac-manager}/Cargo.toml +0 -0
- /package/contracts/{sac-manager → oapps/sac-manager}/src/tests/sac_manager/set_admin.rs +0 -0
- /package/contracts/{sac-manager → oapps/sac-manager}/src/tests/sac_manager/set_authorized.rs +0 -0
|
@@ -1,252 +0,0 @@
|
|
|
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, ¬_whitelisted, 500_i128);
|
|
179
|
-
let result = setup.sac_manager_client.try_mint(¬_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
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
//! Supply Controller Add/Remove & Enumeration Edge-Case Tests
|
|
2
|
-
//!
|
|
3
|
-
//! Focuses on add/remove controller mechanics, re-adding after
|
|
4
|
-
//! removal, removing all controllers, and verifying initial rate-limit state.
|
|
5
|
-
|
|
6
|
-
use super::test_helper::mock_set_supply_controller_auth;
|
|
7
|
-
use crate::extensions::supply_control::{LimitConfig, SupplyControlClient, SupplyControlError, SupplyControllerConfig};
|
|
8
|
-
use crate::tests::test_helper::TestSetup;
|
|
9
|
-
use soroban_sdk::{Env, Vec};
|
|
10
|
-
|
|
11
|
-
// =========================================================================
|
|
12
|
-
// Helpers
|
|
13
|
-
// =========================================================================
|
|
14
|
-
|
|
15
|
-
fn default_config(env: &Env) -> SupplyControllerConfig {
|
|
16
|
-
SupplyControllerConfig {
|
|
17
|
-
limit_config: LimitConfig { limit_capacity: 1_000, refill_per_second: 10 },
|
|
18
|
-
allow_any_mint_burn: true,
|
|
19
|
-
whitelist_addresses: Vec::new(env),
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
fn add(setup: &TestSetup, sc_client: &SupplyControlClient, controller: &soroban_sdk::Address) {
|
|
24
|
-
let config = default_config(&setup.env);
|
|
25
|
-
mock_set_supply_controller_auth(setup, &setup.sc_manager, controller, &Some(config.clone()));
|
|
26
|
-
sc_client.set_supply_controller(&setup.sc_manager, controller, &Some(config));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
fn remove(setup: &TestSetup, sc_client: &SupplyControlClient, controller: &soroban_sdk::Address) {
|
|
30
|
-
mock_set_supply_controller_auth(setup, &setup.sc_manager, controller, &None);
|
|
31
|
-
sc_client.set_supply_controller(&setup.sc_manager, controller, &None);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// =========================================================================
|
|
35
|
-
// Initial Rate-Limit State
|
|
36
|
-
// =========================================================================
|
|
37
|
-
|
|
38
|
-
#[test]
|
|
39
|
-
fn test_add_supply_controller_initial_rate_limit_state() {
|
|
40
|
-
let setup = TestSetup::new().with_manager_as_sac_admin().build();
|
|
41
|
-
let controller = setup.generate_address();
|
|
42
|
-
let sc_client = SupplyControlClient::new(&setup.env, &setup.sac_manager);
|
|
43
|
-
|
|
44
|
-
let config = SupplyControllerConfig {
|
|
45
|
-
limit_config: LimitConfig { limit_capacity: 5_000, refill_per_second: 50 },
|
|
46
|
-
allow_any_mint_burn: false,
|
|
47
|
-
whitelist_addresses: Vec::new(&setup.env),
|
|
48
|
-
};
|
|
49
|
-
mock_set_supply_controller_auth(&setup, &setup.sc_manager, &controller, &Some(config.clone()));
|
|
50
|
-
sc_client.set_supply_controller(&setup.sc_manager, &controller, &Some(config.clone()));
|
|
51
|
-
|
|
52
|
-
// remaining_mint_amount should equal limit_capacity at t=0
|
|
53
|
-
let remaining = sc_client.get_remaining_mint_amount(&controller);
|
|
54
|
-
assert_eq!(remaining, 5_000);
|
|
55
|
-
|
|
56
|
-
// Config should match what we set
|
|
57
|
-
let stored = sc_client.get_supply_controller_config(&controller).unwrap();
|
|
58
|
-
assert_eq!(stored.limit_config.limit_capacity, 5_000);
|
|
59
|
-
assert_eq!(stored.limit_config.refill_per_second, 50);
|
|
60
|
-
assert_eq!(stored.allow_any_mint_burn, false);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// =========================================================================
|
|
64
|
-
// Re-add After Removal
|
|
65
|
-
// =========================================================================
|
|
66
|
-
|
|
67
|
-
#[test]
|
|
68
|
-
fn test_readd_supply_controller_after_removal() {
|
|
69
|
-
let setup = TestSetup::new().with_manager_as_sac_admin().build();
|
|
70
|
-
let controller = setup.generate_address();
|
|
71
|
-
let sc_client = SupplyControlClient::new(&setup.env, &setup.sac_manager);
|
|
72
|
-
|
|
73
|
-
// Add, remove, then add again — should succeed
|
|
74
|
-
add(&setup, &sc_client, &controller);
|
|
75
|
-
assert!(sc_client.get_supply_controller_config(&controller).is_some());
|
|
76
|
-
|
|
77
|
-
remove(&setup, &sc_client, &controller);
|
|
78
|
-
assert!(sc_client.get_supply_controller_config(&controller).is_none());
|
|
79
|
-
|
|
80
|
-
add(&setup, &sc_client, &controller);
|
|
81
|
-
assert!(sc_client.get_supply_controller_config(&controller).is_some());
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// =========================================================================
|
|
85
|
-
// Remove From Middle / First / Last
|
|
86
|
-
// =========================================================================
|
|
87
|
-
|
|
88
|
-
#[test]
|
|
89
|
-
fn test_remove_middle_controller() {
|
|
90
|
-
let setup = TestSetup::new().with_manager_as_sac_admin().build();
|
|
91
|
-
let sc_client = SupplyControlClient::new(&setup.env, &setup.sac_manager);
|
|
92
|
-
|
|
93
|
-
let c1 = setup.generate_address();
|
|
94
|
-
let c2 = setup.generate_address();
|
|
95
|
-
let c3 = setup.generate_address();
|
|
96
|
-
|
|
97
|
-
add(&setup, &sc_client, &c1);
|
|
98
|
-
add(&setup, &sc_client, &c2);
|
|
99
|
-
add(&setup, &sc_client, &c3);
|
|
100
|
-
|
|
101
|
-
// Remove the middle controller (c2).
|
|
102
|
-
remove(&setup, &sc_client, &c2);
|
|
103
|
-
|
|
104
|
-
let controllers = sc_client.get_supply_controllers();
|
|
105
|
-
assert_eq!(controllers.len(), 2);
|
|
106
|
-
assert!(controllers.contains(&c1));
|
|
107
|
-
assert!(controllers.contains(&c3));
|
|
108
|
-
assert!(!controllers.contains(&c2));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
#[test]
|
|
112
|
-
fn test_remove_first_controller() {
|
|
113
|
-
let setup = TestSetup::new().with_manager_as_sac_admin().build();
|
|
114
|
-
let sc_client = SupplyControlClient::new(&setup.env, &setup.sac_manager);
|
|
115
|
-
|
|
116
|
-
let c1 = setup.generate_address();
|
|
117
|
-
let c2 = setup.generate_address();
|
|
118
|
-
let c3 = setup.generate_address();
|
|
119
|
-
|
|
120
|
-
add(&setup, &sc_client, &c1);
|
|
121
|
-
add(&setup, &sc_client, &c2);
|
|
122
|
-
add(&setup, &sc_client, &c3);
|
|
123
|
-
|
|
124
|
-
// Remove first controller (c1).
|
|
125
|
-
remove(&setup, &sc_client, &c1);
|
|
126
|
-
|
|
127
|
-
let controllers = sc_client.get_supply_controllers();
|
|
128
|
-
assert_eq!(controllers.len(), 2);
|
|
129
|
-
assert!(controllers.contains(&c2));
|
|
130
|
-
assert!(controllers.contains(&c3));
|
|
131
|
-
assert!(!controllers.contains(&c1));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
#[test]
|
|
135
|
-
fn test_remove_last_controller() {
|
|
136
|
-
let setup = TestSetup::new().with_manager_as_sac_admin().build();
|
|
137
|
-
let sc_client = SupplyControlClient::new(&setup.env, &setup.sac_manager);
|
|
138
|
-
|
|
139
|
-
let c1 = setup.generate_address();
|
|
140
|
-
let c2 = setup.generate_address();
|
|
141
|
-
let c3 = setup.generate_address();
|
|
142
|
-
|
|
143
|
-
add(&setup, &sc_client, &c1);
|
|
144
|
-
add(&setup, &sc_client, &c2);
|
|
145
|
-
add(&setup, &sc_client, &c3);
|
|
146
|
-
|
|
147
|
-
// Remove last controller.
|
|
148
|
-
remove(&setup, &sc_client, &c3);
|
|
149
|
-
|
|
150
|
-
let controllers = sc_client.get_supply_controllers();
|
|
151
|
-
assert_eq!(controllers.len(), 2);
|
|
152
|
-
assert!(controllers.contains(&c1));
|
|
153
|
-
assert!(controllers.contains(&c2));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// =========================================================================
|
|
157
|
-
// Remove All Controllers
|
|
158
|
-
// =========================================================================
|
|
159
|
-
|
|
160
|
-
#[test]
|
|
161
|
-
fn test_remove_all_controllers() {
|
|
162
|
-
let setup = TestSetup::new().with_manager_as_sac_admin().build();
|
|
163
|
-
let sc_client = SupplyControlClient::new(&setup.env, &setup.sac_manager);
|
|
164
|
-
|
|
165
|
-
let c1 = setup.generate_address();
|
|
166
|
-
let c2 = setup.generate_address();
|
|
167
|
-
|
|
168
|
-
add(&setup, &sc_client, &c1);
|
|
169
|
-
add(&setup, &sc_client, &c2);
|
|
170
|
-
|
|
171
|
-
remove(&setup, &sc_client, &c1);
|
|
172
|
-
remove(&setup, &sc_client, &c2);
|
|
173
|
-
|
|
174
|
-
let controllers = sc_client.get_supply_controllers();
|
|
175
|
-
assert_eq!(controllers.len(), 0);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
#[test]
|
|
179
|
-
fn test_remove_single_controller() {
|
|
180
|
-
let setup = TestSetup::new().with_manager_as_sac_admin().build();
|
|
181
|
-
let sc_client = SupplyControlClient::new(&setup.env, &setup.sac_manager);
|
|
182
|
-
|
|
183
|
-
let c1 = setup.generate_address();
|
|
184
|
-
add(&setup, &sc_client, &c1);
|
|
185
|
-
|
|
186
|
-
remove(&setup, &sc_client, &c1);
|
|
187
|
-
|
|
188
|
-
let controllers = sc_client.get_supply_controllers();
|
|
189
|
-
assert_eq!(controllers.len(), 0);
|
|
190
|
-
assert!(sc_client.get_supply_controller_config(&c1).is_none());
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// =========================================================================
|
|
194
|
-
// Get All Controllers
|
|
195
|
-
// =========================================================================
|
|
196
|
-
|
|
197
|
-
#[test]
|
|
198
|
-
fn test_get_supply_controllers_empty() {
|
|
199
|
-
let setup = TestSetup::new().with_manager_as_sac_admin().build();
|
|
200
|
-
let sc_client = SupplyControlClient::new(&setup.env, &setup.sac_manager);
|
|
201
|
-
|
|
202
|
-
let controllers = sc_client.get_supply_controllers();
|
|
203
|
-
assert_eq!(controllers.len(), 0);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// =========================================================================
|
|
207
|
-
// Multiple Add/Remove Cycles
|
|
208
|
-
// =========================================================================
|
|
209
|
-
|
|
210
|
-
#[test]
|
|
211
|
-
fn test_multiple_add_remove_cycles() {
|
|
212
|
-
let setup = TestSetup::new().with_manager_as_sac_admin().build();
|
|
213
|
-
let sc_client = SupplyControlClient::new(&setup.env, &setup.sac_manager);
|
|
214
|
-
|
|
215
|
-
let c1 = setup.generate_address();
|
|
216
|
-
let c2 = setup.generate_address();
|
|
217
|
-
let c3 = setup.generate_address();
|
|
218
|
-
|
|
219
|
-
// Add all three
|
|
220
|
-
add(&setup, &sc_client, &c1);
|
|
221
|
-
add(&setup, &sc_client, &c2);
|
|
222
|
-
add(&setup, &sc_client, &c3);
|
|
223
|
-
|
|
224
|
-
// Remove middle, then re-add it
|
|
225
|
-
remove(&setup, &sc_client, &c2);
|
|
226
|
-
add(&setup, &sc_client, &c2);
|
|
227
|
-
|
|
228
|
-
let controllers = sc_client.get_supply_controllers();
|
|
229
|
-
assert_eq!(controllers.len(), 3);
|
|
230
|
-
assert!(controllers.contains(&c1));
|
|
231
|
-
assert!(controllers.contains(&c2));
|
|
232
|
-
assert!(controllers.contains(&c3));
|
|
233
|
-
|
|
234
|
-
// Remove first two, verify only c3 remains
|
|
235
|
-
remove(&setup, &sc_client, &c1);
|
|
236
|
-
remove(&setup, &sc_client, &c2);
|
|
237
|
-
|
|
238
|
-
let controllers = sc_client.get_supply_controllers();
|
|
239
|
-
assert_eq!(controllers.len(), 1);
|
|
240
|
-
assert!(controllers.contains(&c3));
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
#[test]
|
|
244
|
-
fn test_remove_already_removed_fails() {
|
|
245
|
-
let setup = TestSetup::new().with_manager_as_sac_admin().build();
|
|
246
|
-
let sc_client = SupplyControlClient::new(&setup.env, &setup.sac_manager);
|
|
247
|
-
|
|
248
|
-
let c1 = setup.generate_address();
|
|
249
|
-
add(&setup, &sc_client, &c1);
|
|
250
|
-
remove(&setup, &sc_client, &c1);
|
|
251
|
-
|
|
252
|
-
// Removing again should fail with NotFound
|
|
253
|
-
mock_set_supply_controller_auth(&setup, &setup.sc_manager, &c1, &None);
|
|
254
|
-
let result = sc_client.try_set_supply_controller(&setup.sc_manager, &c1, &None);
|
|
255
|
-
assert_eq!(result.err().unwrap().unwrap(), SupplyControlError::NotFound.into());
|
|
256
|
-
}
|