@layerzerolabs/protocol-stellar-v2 0.2.40 → 0.2.43
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 +312 -397
- package/.turbo/turbo-lint.log +185 -245
- package/.turbo/turbo-test.log +1846 -1942
- package/Cargo.lock +22 -127
- package/Cargo.toml +4 -6
- package/contracts/common-macros/src/lib.rs +38 -15
- package/contracts/common-macros/src/lz_contract.rs +12 -21
- package/contracts/common-macros/src/tests/lz_contract.rs +17 -8
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__lz_contract__snapshot_generated_lz_contract_code.snap +20 -0
- package/contracts/common-macros/src/upgradeable.rs +37 -30
- package/contracts/endpoint-v2/src/endpoint_v2.rs +4 -3
- package/contracts/endpoint-v2/src/errors.rs +2 -2
- package/contracts/endpoint-v2/src/messaging_channel.rs +11 -0
- package/contracts/endpoint-v2/src/messaging_composer.rs +1 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/clear.rs +12 -25
- package/contracts/endpoint-v2/src/tests/endpoint_v2/initializable.rs +4 -4
- package/contracts/endpoint-v2/src/tests/endpoint_v2/verifiable.rs +50 -10
- package/contracts/endpoint-v2/src/tests/endpoint_v2/verify.rs +6 -35
- package/contracts/endpoint-v2/src/tests/messaging_channel/burn.rs +2 -2
- package/contracts/endpoint-v2/src/tests/messaging_channel/clear_payload.rs +50 -1
- package/contracts/endpoint-v2/src/tests/messaging_channel/inbound.rs +78 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/insert_and_drain_pending_nonces.rs +272 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/mod.rs +1 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/nilify.rs +10 -5
- package/contracts/endpoint-v2/src/tests/messaging_channel/skip.rs +30 -0
- package/contracts/macro-integration-tests/tests/runtime/oapp/mod.rs +25 -6
- package/contracts/macro-integration-tests/tests/runtime/oapp/oapp_core.rs +13 -11
- package/contracts/macro-integration-tests/tests/runtime/oapp/options_type3.rs +13 -10
- package/contracts/macro-integration-tests/tests/runtime/oapp/receiver.rs +15 -11
- package/contracts/macro-integration-tests/tests/runtime/oapp/sender.rs +5 -3
- package/contracts/macro-integration-tests/tests/runtime/ownable/mod.rs +1 -1
- package/contracts/macro-integration-tests/tests/runtime/ownable/two_step_transfer.rs +14 -12
- package/contracts/macro-integration-tests/tests/runtime/upgradeable/migrate_guard_and_state.rs +3 -9
- package/contracts/macro-integration-tests/tests/ui/lz_contract/fail/upgradeable_invalid_inner_option.stderr +24 -1
- package/contracts/macro-integration-tests/tests/ui/lz_contract/fail/upgradeable_missing_internal.stderr +3 -3
- package/contracts/macro-integration-tests/tests/ui/lz_contract/pass/upgradeable_rbac.rs +44 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/missing_auth_trait.rs +28 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/missing_auth_trait.stderr +397 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/missing_lz_receive_internal.rs +1 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/missing_lz_receive_internal.stderr +10 -10
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/custom_all.rs +4 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/custom_single_trait.rs +7 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/minimal_contract.rs +5 -4
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/struct_with_fields.rs +2 -0
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/basic.rs +1 -1
- package/contracts/macro-integration-tests/tests/ui/upgradeable/fail/attr_args.stderr +1 -1
- package/contracts/macro-integration-tests/tests/ui/upgradeable/fail/missing_auth_trait.stderr +2 -2
- package/contracts/macro-integration-tests/tests/ui/upgradeable/fail/missing_upgradeable_internal.stderr +2 -2
- package/contracts/macro-integration-tests/tests/ui/upgradeable/pass/rbac.rs +44 -0
- package/contracts/oapps/counter/integration_tests/utils.rs +5 -3
- package/contracts/oapps/counter/src/counter.rs +4 -3
- package/contracts/oapps/counter/src/tests/mod.rs +16 -1
- package/contracts/oapps/counter/src/tests/test_counter.rs +5 -2
- package/contracts/oapps/oapp/src/oapp_core.rs +22 -8
- package/contracts/oapps/oapp/src/oapp_options_type3.rs +7 -5
- package/contracts/oapps/oapp/src/tests/mod.rs +21 -0
- package/contracts/oapps/oapp/src/tests/oapp_core.rs +14 -11
- package/contracts/oapps/oapp/src/tests/oapp_options_type3.rs +17 -10
- package/contracts/oapps/oapp/src/tests/oapp_receiver.rs +6 -3
- package/contracts/oapps/oapp/src/tests/oapp_sender.rs +5 -3
- package/contracts/oapps/oapp/src/tests/test_macros.rs +25 -0
- package/contracts/oapps/oapp-macros/src/generators.rs +12 -9
- package/contracts/oapps/oapp-macros/src/lib.rs +1 -1
- package/contracts/oapps/oapp-macros/src/tests/snapshots/oapp_macros__tests__oapp__snapshot_generate_oapp.snap +15 -7
- package/contracts/oapps/oft/integration-tests/setup.rs +22 -4
- package/contracts/oapps/oft/integration-tests/utils.rs +94 -13
- package/contracts/oapps/oft/src/extensions/oft_fee.rs +23 -10
- package/contracts/oapps/oft/src/extensions/pausable.rs +31 -10
- package/contracts/oapps/oft/src/extensions/rate_limiter.rs +9 -4
- package/contracts/oapps/oft/src/oft.rs +3 -3
- package/contracts/oapps/oft/src/tests/extensions/oft_fee.rs +39 -27
- package/contracts/oapps/oft/src/tests/extensions/pausable.rs +38 -24
- package/contracts/oapps/oft/src/tests/extensions/rate_limiter.rs +87 -69
- package/contracts/oapps/oft/src/tests/oft_types/lock_unlock.rs +1 -0
- package/contracts/oapps/oft-core/integration-tests/setup.rs +28 -3
- package/contracts/oapps/oft-core/src/oft_core.rs +11 -6
- package/contracts/oapps/oft-core/src/tests/test_msg_inspector.rs +20 -20
- package/contracts/oapps/oft-core/src/tests/test_utils.rs +33 -3
- package/contracts/upgrader/src/lib.rs +67 -30
- package/contracts/upgrader/src/tests/test_data/test_upgradeable_contract3.wasm +0 -0
- package/contracts/upgrader/src/tests/test_data/test_upgradeable_contract4.wasm +0 -0
- package/contracts/upgrader/src/tests/test_upgrader.rs +50 -4
- package/contracts/utils/src/ownable.rs +16 -5
- package/contracts/utils/src/tests/ownable.rs +39 -39
- package/contracts/utils/src/upgradeable.rs +60 -17
- package/docs/oapp-guide.md +18 -13
- package/package.json +5 -5
- package/sdk/.turbo/turbo-test.log +359 -348
- package/sdk/dist/generated/bml.d.ts +4 -4
- package/sdk/dist/generated/bml.js +6 -6
- package/sdk/dist/generated/counter.d.ts +269 -123
- package/sdk/dist/generated/counter.js +45 -25
- package/sdk/dist/generated/dvn.d.ts +4 -6
- package/sdk/dist/generated/dvn.js +8 -8
- package/sdk/dist/generated/dvn_fee_lib.d.ts +8 -10
- package/sdk/dist/generated/dvn_fee_lib.js +8 -8
- package/sdk/dist/generated/endpoint.d.ts +9 -9
- package/sdk/dist/generated/endpoint.js +9 -9
- package/sdk/dist/generated/executor.d.ts +9 -11
- package/sdk/dist/generated/executor.js +11 -11
- package/sdk/dist/generated/executor_fee_lib.d.ts +9 -11
- package/sdk/dist/generated/executor_fee_lib.js +11 -11
- package/sdk/dist/generated/executor_helper.d.ts +4 -4
- package/sdk/dist/generated/executor_helper.js +6 -6
- package/sdk/dist/generated/layerzero_view.d.ts +9 -11
- package/sdk/dist/generated/layerzero_view.js +11 -11
- package/sdk/dist/generated/oft.d.ts +323 -156
- package/sdk/dist/generated/oft.js +65 -43
- package/sdk/dist/generated/price_feed.d.ts +8 -10
- package/sdk/dist/generated/price_feed.js +8 -8
- package/sdk/dist/generated/sac_manager.d.ts +8 -8
- package/sdk/dist/generated/sac_manager.js +6 -6
- package/sdk/dist/generated/sml.d.ts +9 -9
- package/sdk/dist/generated/sml.js +9 -9
- package/sdk/dist/generated/treasury.d.ts +9 -9
- package/sdk/dist/generated/treasury.js +9 -9
- package/sdk/dist/generated/uln302.d.ts +9 -9
- package/sdk/dist/generated/uln302.js +9 -9
- package/sdk/dist/generated/upgrader.d.ts +25 -16
- package/sdk/dist/generated/upgrader.js +5 -5
- package/sdk/package.json +1 -1
- package/sdk/test/counter-sml.test.ts +20 -0
- package/sdk/test/counter-uln.test.ts +20 -0
- package/sdk/test/oft-sml.test.ts +22 -0
- package/sdk/test/upgrader.test.ts +1 -0
- package/ts-bindings-gen.toml +67 -0
- package/turbo.json +1 -8
- package/tools/ts-bindings-gen/Cargo.toml +0 -16
- package/tools/ts-bindings-gen/src/main.rs +0 -214
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
extern crate std;
|
|
2
2
|
|
|
3
3
|
use crate::extensions::oft_fee::{OFTFee, OFTFeeError, OFTFeeInternal};
|
|
4
|
+
use crate::extensions::oft_fee::FEE_ADMIN_ROLE;
|
|
4
5
|
use soroban_sdk::{
|
|
5
6
|
contract, contractimpl,
|
|
6
7
|
testutils::{Address as _, MockAuth, MockAuthInvoke},
|
|
7
8
|
token::{StellarAssetClient, TokenClient},
|
|
8
|
-
Address, Env, IntoVal,
|
|
9
|
+
Address, Env, IntoVal, Symbol,
|
|
9
10
|
};
|
|
10
11
|
use utils::auth::Auth;
|
|
12
|
+
use utils::rbac::{grant_role_no_auth, RoleBasedAccessControl};
|
|
11
13
|
|
|
12
14
|
// ============================================================================
|
|
13
15
|
// Test Contract
|
|
@@ -27,8 +29,17 @@ impl OFTFeeInternal for FeeTestContract {}
|
|
|
27
29
|
#[contractimpl(contracttrait)]
|
|
28
30
|
impl OFTFee for FeeTestContract {}
|
|
29
31
|
|
|
32
|
+
#[contractimpl(contracttrait)]
|
|
33
|
+
impl RoleBasedAccessControl for FeeTestContract {}
|
|
34
|
+
|
|
30
35
|
#[contractimpl]
|
|
31
36
|
impl FeeTestContract {
|
|
37
|
+
/// Test-only: grants FEE_ADMIN_ROLE to the contract.
|
|
38
|
+
pub fn init_roles(env: Env) {
|
|
39
|
+
let contract_id = env.current_contract_address();
|
|
40
|
+
grant_role_no_auth(&env, &contract_id, &Symbol::new(&env, FEE_ADMIN_ROLE), &contract_id);
|
|
41
|
+
}
|
|
42
|
+
|
|
32
43
|
pub fn fee_view(env: Env, dst_eid: u32, amount_ld: i128) -> i128 {
|
|
33
44
|
<Self as OFTFeeInternal>::__fee_view(&env, dst_eid, amount_ld)
|
|
34
45
|
}
|
|
@@ -59,6 +70,7 @@ fn setup() -> TestSetup {
|
|
|
59
70
|
|
|
60
71
|
let contract_id = env.register(FeeTestContract, ());
|
|
61
72
|
let client = FeeTestContractClient::new(&env, &contract_id);
|
|
73
|
+
client.init_roles();
|
|
62
74
|
|
|
63
75
|
let token_admin = Address::generate(&env);
|
|
64
76
|
let sac = env.register_stellar_asset_contract_v2(token_admin.clone());
|
|
@@ -94,9 +106,9 @@ fn test_fee_deposit_address_returns_none_when_unset() {
|
|
|
94
106
|
|
|
95
107
|
#[test]
|
|
96
108
|
fn test_fee_view_nonzero_fee_errors_when_deposit_address_unset() {
|
|
97
|
-
let TestSetup { client, .. } = setup();
|
|
109
|
+
let TestSetup { client, contract_id, .. } = setup();
|
|
98
110
|
|
|
99
|
-
client.set_default_fee_bps(&Some(100u32));
|
|
111
|
+
client.set_default_fee_bps(&Some(100u32), &contract_id);
|
|
100
112
|
|
|
101
113
|
let res = client.try_fee_view(&7u32, &1_000_000i128);
|
|
102
114
|
assert_eq!(res.err().unwrap().ok().unwrap(), OFTFeeError::InvalidFeeDepositAddress.into());
|
|
@@ -108,29 +120,29 @@ fn test_fee_view_nonzero_fee_errors_when_deposit_address_unset() {
|
|
|
108
120
|
|
|
109
121
|
#[test]
|
|
110
122
|
fn test_set_default_fee_bps_rejects_invalid_value() {
|
|
111
|
-
let TestSetup { client, .. } = setup();
|
|
123
|
+
let TestSetup { client, contract_id, .. } = setup();
|
|
112
124
|
|
|
113
125
|
// Zero is not a valid default fee (use None to remove instead)
|
|
114
|
-
let res = client.try_set_default_fee_bps(&Some(0u32));
|
|
126
|
+
let res = client.try_set_default_fee_bps(&Some(0u32), &contract_id);
|
|
115
127
|
assert_eq!(res.err().unwrap().ok().unwrap(), OFTFeeError::InvalidFeeBps.into());
|
|
116
128
|
|
|
117
129
|
// Exceeds maximum
|
|
118
|
-
let res = client.try_set_default_fee_bps(&Some(10_001u32));
|
|
130
|
+
let res = client.try_set_default_fee_bps(&Some(10_001u32), &contract_id);
|
|
119
131
|
assert_eq!(res.err().unwrap().ok().unwrap(), OFTFeeError::InvalidFeeBps.into());
|
|
120
132
|
}
|
|
121
133
|
|
|
122
134
|
#[test]
|
|
123
135
|
fn test_set_default_fee_bps_rejects_same_value() {
|
|
124
|
-
let TestSetup { client, .. } = setup();
|
|
136
|
+
let TestSetup { client, contract_id, .. } = setup();
|
|
125
137
|
|
|
126
138
|
// None when already None (not set)
|
|
127
139
|
let none: Option<u32> = None;
|
|
128
|
-
let res = client.try_set_default_fee_bps(&none);
|
|
140
|
+
let res = client.try_set_default_fee_bps(&none, &contract_id);
|
|
129
141
|
assert_eq!(res.err().unwrap().ok().unwrap(), OFTFeeError::SameValue.into());
|
|
130
142
|
|
|
131
143
|
// Same value when already set
|
|
132
|
-
client.set_default_fee_bps(&Some(123u32));
|
|
133
|
-
let res2 = client.try_set_default_fee_bps(&Some(123u32));
|
|
144
|
+
client.set_default_fee_bps(&Some(123u32), &contract_id);
|
|
145
|
+
let res2 = client.try_set_default_fee_bps(&Some(123u32), &contract_id);
|
|
134
146
|
assert_eq!(res2.err().unwrap().ok().unwrap(), OFTFeeError::SameValue.into());
|
|
135
147
|
}
|
|
136
148
|
|
|
@@ -140,27 +152,27 @@ fn test_set_default_fee_bps_rejects_same_value() {
|
|
|
140
152
|
|
|
141
153
|
#[test]
|
|
142
154
|
fn test_set_fee_bps_rejects_invalid_and_same_value() {
|
|
143
|
-
let TestSetup { client, .. } = setup();
|
|
155
|
+
let TestSetup { client, contract_id, .. } = setup();
|
|
144
156
|
let dst_eid = 101u32;
|
|
145
157
|
|
|
146
|
-
let res = client.try_set_fee_bps(&dst_eid, &None);
|
|
158
|
+
let res = client.try_set_fee_bps(&dst_eid, &None, &contract_id);
|
|
147
159
|
assert_eq!(res.err().unwrap().ok().unwrap(), OFTFeeError::SameValue.into());
|
|
148
160
|
|
|
149
|
-
let res2 = client.try_set_fee_bps(&dst_eid, &Some(10_001u32));
|
|
161
|
+
let res2 = client.try_set_fee_bps(&dst_eid, &Some(10_001u32), &contract_id);
|
|
150
162
|
assert_eq!(res2.err().unwrap().ok().unwrap(), OFTFeeError::InvalidFeeBps.into());
|
|
151
163
|
}
|
|
152
164
|
|
|
153
165
|
#[test]
|
|
154
166
|
fn test_set_fee_bps_set_and_remove() {
|
|
155
|
-
let TestSetup { client, .. } = setup();
|
|
167
|
+
let TestSetup { client, contract_id, .. } = setup();
|
|
156
168
|
let dst_eid = 101u32;
|
|
157
169
|
|
|
158
|
-
client.set_fee_bps(&dst_eid, &Some(200u32));
|
|
170
|
+
client.set_fee_bps(&dst_eid, &Some(200u32), &contract_id);
|
|
159
171
|
assert_eq!(client.fee_bps(&dst_eid), Some(200u32));
|
|
160
172
|
assert_eq!(client.effective_fee_bps(&dst_eid), 200u32);
|
|
161
173
|
|
|
162
|
-
client.set_default_fee_bps(&Some(111u32));
|
|
163
|
-
client.set_fee_bps(&dst_eid, &None);
|
|
174
|
+
client.set_default_fee_bps(&Some(111u32), &contract_id);
|
|
175
|
+
client.set_fee_bps(&dst_eid, &None, &contract_id);
|
|
164
176
|
assert_eq!(client.fee_bps(&dst_eid), None);
|
|
165
177
|
assert_eq!(client.effective_fee_bps(&dst_eid), 111u32);
|
|
166
178
|
}
|
|
@@ -195,19 +207,19 @@ fn test_charge_fee_errors_without_deposit_address() {
|
|
|
195
207
|
|
|
196
208
|
#[test]
|
|
197
209
|
fn test_set_fee_deposit_address_same_value() {
|
|
198
|
-
let TestSetup { client, fee_deposit, .. } = setup();
|
|
210
|
+
let TestSetup { client, contract_id, fee_deposit, .. } = setup();
|
|
199
211
|
|
|
200
212
|
let fee_deposit_opt = Some(fee_deposit);
|
|
201
|
-
client.set_fee_deposit_address(&fee_deposit_opt);
|
|
202
|
-
let res = client.try_set_fee_deposit_address(&fee_deposit_opt);
|
|
213
|
+
client.set_fee_deposit_address(&fee_deposit_opt, &contract_id);
|
|
214
|
+
let res = client.try_set_fee_deposit_address(&fee_deposit_opt, &contract_id);
|
|
203
215
|
assert_eq!(res.err().unwrap().ok().unwrap(), OFTFeeError::SameValue.into());
|
|
204
216
|
}
|
|
205
217
|
|
|
206
218
|
#[test]
|
|
207
219
|
fn test_charge_fee_zero_amount_no_transfer() {
|
|
208
|
-
let TestSetup { env, client, token, from, fee_deposit, .. } = setup();
|
|
220
|
+
let TestSetup { env, client, contract_id, token, from, fee_deposit, .. } = setup();
|
|
209
221
|
|
|
210
|
-
client.set_fee_deposit_address(&Some(fee_deposit.clone()));
|
|
222
|
+
client.set_fee_deposit_address(&Some(fee_deposit.clone()), &contract_id);
|
|
211
223
|
|
|
212
224
|
let token_client = TokenClient::new(&env, &token);
|
|
213
225
|
let from_before = token_client.balance(&from);
|
|
@@ -222,9 +234,9 @@ fn test_charge_fee_zero_amount_no_transfer() {
|
|
|
222
234
|
|
|
223
235
|
#[test]
|
|
224
236
|
fn test_charge_fee_transfers() {
|
|
225
|
-
let TestSetup { env, client, token, from, fee_deposit, .. } = setup();
|
|
237
|
+
let TestSetup { env, client, contract_id, token, from, fee_deposit, .. } = setup();
|
|
226
238
|
|
|
227
|
-
client.set_fee_deposit_address(&Some(fee_deposit.clone()));
|
|
239
|
+
client.set_fee_deposit_address(&Some(fee_deposit.clone()), &contract_id);
|
|
228
240
|
|
|
229
241
|
let token_client = TokenClient::new(&env, &token);
|
|
230
242
|
let from_before = token_client.balance(&from);
|
|
@@ -238,10 +250,10 @@ fn test_charge_fee_transfers() {
|
|
|
238
250
|
|
|
239
251
|
#[test]
|
|
240
252
|
fn test_fee_view_computes_correct_fee() {
|
|
241
|
-
let TestSetup { client, fee_deposit, .. } = setup();
|
|
253
|
+
let TestSetup { client, contract_id, fee_deposit, .. } = setup();
|
|
242
254
|
|
|
243
|
-
client.set_fee_deposit_address(&Some(fee_deposit));
|
|
244
|
-
client.set_default_fee_bps(&Some(100u32)); // 1%
|
|
255
|
+
client.set_fee_deposit_address(&Some(fee_deposit), &contract_id);
|
|
256
|
+
client.set_default_fee_bps(&Some(100u32), &contract_id); // 1%
|
|
245
257
|
|
|
246
258
|
let fee = client.fee_view(&999u32, &10_000i128);
|
|
247
259
|
assert_eq!(fee, 100); // 1% of 10,000
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
extern crate std;
|
|
2
2
|
|
|
3
3
|
use crate::extensions::pausable::{OFTPausable, OFTPausableError, OFTPausableInternal};
|
|
4
|
-
use
|
|
4
|
+
use crate::extensions::pausable::{PAUSER_ROLE, UNPAUSER_ROLE};
|
|
5
|
+
use soroban_sdk::{contract, contractimpl, Address, Env, Symbol};
|
|
6
|
+
use utils::rbac::{grant_role_no_auth, RoleBasedAccessControl};
|
|
5
7
|
use utils::auth::Auth;
|
|
6
8
|
|
|
7
9
|
// ============================================================================
|
|
@@ -22,8 +24,18 @@ impl OFTPausableInternal for PausableTestContract {}
|
|
|
22
24
|
#[contractimpl(contracttrait)]
|
|
23
25
|
impl OFTPausable for PausableTestContract {}
|
|
24
26
|
|
|
27
|
+
#[contractimpl(contracttrait)]
|
|
28
|
+
impl RoleBasedAccessControl for PausableTestContract {}
|
|
29
|
+
|
|
25
30
|
#[contractimpl]
|
|
26
31
|
impl PausableTestContract {
|
|
32
|
+
/// Test-only: grants PAUSER_ROLE and UNPAUSER_ROLE to the contract.
|
|
33
|
+
pub fn init_roles(env: Env) {
|
|
34
|
+
let contract_id = env.current_contract_address();
|
|
35
|
+
grant_role_no_auth(&env, &contract_id, &Symbol::new(&env, PAUSER_ROLE), &contract_id);
|
|
36
|
+
grant_role_no_auth(&env, &contract_id, &Symbol::new(&env, UNPAUSER_ROLE), &contract_id);
|
|
37
|
+
}
|
|
38
|
+
|
|
27
39
|
pub fn assert_not_paused(env: Env) {
|
|
28
40
|
<Self as OFTPausableInternal>::__assert_not_paused(&env)
|
|
29
41
|
}
|
|
@@ -35,6 +47,7 @@ impl PausableTestContract {
|
|
|
35
47
|
|
|
36
48
|
struct TestSetup {
|
|
37
49
|
client: PausableTestContractClient<'static>,
|
|
50
|
+
contract_id: Address,
|
|
38
51
|
}
|
|
39
52
|
|
|
40
53
|
fn setup() -> TestSetup {
|
|
@@ -43,7 +56,8 @@ fn setup() -> TestSetup {
|
|
|
43
56
|
|
|
44
57
|
let contract_id = env.register(PausableTestContract, ());
|
|
45
58
|
let client = PausableTestContractClient::new(&env, &contract_id);
|
|
46
|
-
|
|
59
|
+
client.init_roles();
|
|
60
|
+
TestSetup { client, contract_id }
|
|
47
61
|
}
|
|
48
62
|
|
|
49
63
|
// ============================================================================
|
|
@@ -58,45 +72,45 @@ fn test_initial_state_is_not_paused() {
|
|
|
58
72
|
}
|
|
59
73
|
|
|
60
74
|
// ============================================================================
|
|
61
|
-
//
|
|
75
|
+
// Pause/Unpause Tests
|
|
62
76
|
// ============================================================================
|
|
63
77
|
|
|
64
78
|
#[test]
|
|
65
|
-
fn
|
|
66
|
-
let TestSetup { client, .. } = setup();
|
|
79
|
+
fn test_pause_sets_paused() {
|
|
80
|
+
let TestSetup { client, contract_id, .. } = setup();
|
|
67
81
|
|
|
68
|
-
client.
|
|
82
|
+
client.pause(&contract_id);
|
|
69
83
|
assert!(client.is_paused());
|
|
70
84
|
}
|
|
71
85
|
|
|
72
86
|
#[test]
|
|
73
|
-
fn
|
|
74
|
-
let TestSetup { client, .. } = setup();
|
|
87
|
+
fn test_unpause_after_pausing() {
|
|
88
|
+
let TestSetup { client, contract_id, .. } = setup();
|
|
75
89
|
|
|
76
|
-
client.
|
|
90
|
+
client.pause(&contract_id);
|
|
77
91
|
assert!(client.is_paused());
|
|
78
92
|
|
|
79
|
-
client.
|
|
93
|
+
client.unpause(&contract_id);
|
|
80
94
|
assert!(!client.is_paused());
|
|
81
95
|
}
|
|
82
96
|
|
|
83
97
|
#[test]
|
|
84
|
-
fn
|
|
85
|
-
let TestSetup { client, .. } = setup();
|
|
98
|
+
fn test_unpause_unchanged_when_unpaused() {
|
|
99
|
+
let TestSetup { client, contract_id, .. } = setup();
|
|
86
100
|
|
|
87
|
-
// Initially not paused,
|
|
88
|
-
let res = client.
|
|
101
|
+
// Initially not paused, unpause should fail
|
|
102
|
+
let res = client.try_unpause(&contract_id);
|
|
89
103
|
assert_eq!(res.err().unwrap().ok().unwrap(), OFTPausableError::PauseStatusUnchanged.into());
|
|
90
104
|
}
|
|
91
105
|
|
|
92
106
|
#[test]
|
|
93
|
-
fn
|
|
94
|
-
let TestSetup { client, .. } = setup();
|
|
107
|
+
fn test_pause_unchanged_when_paused() {
|
|
108
|
+
let TestSetup { client, contract_id, .. } = setup();
|
|
95
109
|
|
|
96
|
-
client.
|
|
110
|
+
client.pause(&contract_id);
|
|
97
111
|
|
|
98
|
-
// Already paused,
|
|
99
|
-
let res = client.
|
|
112
|
+
// Already paused, pause again should fail
|
|
113
|
+
let res = client.try_pause(&contract_id);
|
|
100
114
|
assert_eq!(res.err().unwrap().ok().unwrap(), OFTPausableError::PauseStatusUnchanged.into());
|
|
101
115
|
}
|
|
102
116
|
|
|
@@ -114,9 +128,9 @@ fn test_assert_not_paused_succeeds_when_not_paused() {
|
|
|
114
128
|
|
|
115
129
|
#[test]
|
|
116
130
|
fn test_assert_not_paused_fails_when_paused() {
|
|
117
|
-
let TestSetup { client, .. } = setup();
|
|
131
|
+
let TestSetup { client, contract_id, .. } = setup();
|
|
118
132
|
|
|
119
|
-
client.
|
|
133
|
+
client.pause(&contract_id);
|
|
120
134
|
|
|
121
135
|
let res = client.try_assert_not_paused();
|
|
122
136
|
assert_eq!(res.err().unwrap().ok().unwrap(), OFTPausableError::Paused.into());
|
|
@@ -128,14 +142,14 @@ fn test_assert_not_paused_fails_when_paused() {
|
|
|
128
142
|
|
|
129
143
|
#[test]
|
|
130
144
|
fn test_pause_unpause_toggle_multiple_times() {
|
|
131
|
-
let TestSetup { client, .. } = setup();
|
|
145
|
+
let TestSetup { client, contract_id, .. } = setup();
|
|
132
146
|
|
|
133
147
|
// Toggle multiple times
|
|
134
148
|
for _ in 0..3 {
|
|
135
149
|
assert!(!client.is_paused());
|
|
136
|
-
client.
|
|
150
|
+
client.pause(&contract_id);
|
|
137
151
|
assert!(client.is_paused());
|
|
138
|
-
client.
|
|
152
|
+
client.unpause(&contract_id);
|
|
139
153
|
}
|
|
140
154
|
assert!(!client.is_paused());
|
|
141
155
|
}
|