Skip to content

Commit dc5b6c2

Browse files
committed
chore: cleanup
1 parent 0659805 commit dc5b6c2

3 files changed

Lines changed: 49 additions & 57 deletions

File tree

contract/contracts/creator-deposits/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ impl CreatorDeposits {
8383
env.storage()
8484
.instance()
8585
.set(&DataKey::CanonicalToken, &canonical_token);
86+
87+
env.events()
88+
.publish((Symbol::new(&env, TOPIC_INITIALIZED),), ());
8689
}
8790

8891
pub fn deposit(env: Env, creator: Address, token: Address, amount: i128) {
@@ -296,7 +299,7 @@ mod test {
296299

297300
#[test]
298301
fn test_invalid_bps_init_reverts() {
299-
let (env, admin, treasury, _, _) = setup();
302+
let (env, admin, treasury, _, token) = setup();
300303
let contract_id = env.register_contract(None, CreatorDeposits);
301304
let client = CreatorDepositsClient::new(&env, &contract_id);
302305

contract/contracts/creator-deposits/src/property_tests.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ mod props {
4949

5050
let contract_id = env.register_contract(None, CreatorDeposits);
5151
let client = CreatorDepositsClient::new(env, &contract_id);
52-
client.init(&admin, &fee_bps, &treasury);
52+
client.init(&admin, &fee_bps, &treasury, &token_id);
5353
(client, admin, token_client, sac)
5454
}
5555

@@ -220,7 +220,10 @@ mod props {
220220
let contract_id = env.register_contract(None, CreatorDeposits);
221221
let client = CreatorDepositsClient::new(&env, &contract_id);
222222

223-
let result = client.try_init(&admin, &fee_bps, &treasury);
223+
let token_id = env
224+
.register_stellar_asset_contract_v2(Address::generate(&env))
225+
.address();
226+
let result = client.try_init(&admin, &fee_bps, &treasury, &token_id);
224227
prop_assert_eq!(
225228
result,
226229
Err(Ok(SorobanError::from_contract_error(Error::InvalidFeeBps as u32))),

contract/contracts/test-consumer/src/lib.rs

Lines changed: 40 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![no_std]
22
use myfans_lib::{ContentType, MyfansError, SubscriptionStatus};
3-
use soroban_sdk::{contract, contractimpl, Address, Env, Symbol};
3+
use soroban_sdk::{contract, contractimpl, symbol_short, Address, Env, Symbol};
44

55
/// Data keys for contract storage
66
#[derive(Clone, Copy)]
@@ -12,12 +12,11 @@ pub enum DataKey {
1212
impl DataKey {
1313
pub fn to_symbol(&self) -> Symbol {
1414
match self {
15-
DataKey::Admin => Symbol::short("admin"),
16-
DataKey::Paused => Symbol::short("paused"),
15+
DataKey::Admin => symbol_short!("admin"),
16+
DataKey::Paused => symbol_short!("paused"),
1717
}
1818
}
1919
}
20-
use soroban_sdk::{contract, contractimpl, Env, Symbol};
2120

2221
#[contract]
2322
pub struct TestConsumer;
@@ -91,7 +90,7 @@ impl TestConsumer {
9190
pub fn is_active(env: Env, status: SubscriptionStatus) -> bool {
9291
let active = status == SubscriptionStatus::Active;
9392
env.events()
94-
.publish((Symbol::new(&env, "test_consumer:is_active"),), active);
93+
.publish((Symbol::new(&env, "tc_is_active"),), active);
9594
active
9695
}
9796

@@ -100,23 +99,23 @@ impl TestConsumer {
10099
pub fn error_code(env: Env, err: MyfansError) -> u32 {
101100
let code = err as u32;
102101
env.events()
103-
.publish((Symbol::new(&env, "test_consumer:error_code"),), code);
102+
.publish((Symbol::new(&env, "tc_error_code"),), code);
104103
code
105104
}
106105

107106
/// Returns the numeric discriminant of a `ContentType` variant.
108107
pub fn content_code(env: Env, ct: ContentType) -> u32 {
109108
let code = ct as u32;
110109
env.events()
111-
.publish((Symbol::new(&env, "test_consumer:content_code"),), code);
110+
.publish((Symbol::new(&env, "tc_content_code"),), code);
112111
code
113112
}
114113
}
115114

116115
#[cfg(test)]
117116
mod test {
118117
use super::*;
119-
use soroban_sdk::{Address, Env};
118+
use soroban_sdk::{testutils::Address as _, Address, Env};
120119

121120
// ── Unauthorized Caller Tests (Admin-Protected Functions) ────────────
122121

@@ -131,16 +130,13 @@ mod test {
131130
let admin = Address::generate(&env);
132131

133132
// Initialize
134-
let result = client.initialize(&admin);
135-
assert_eq!(result, Ok(()));
133+
client.initialize(&admin);
136134

137135
// Admin should be able to set paused
138-
let result = client.set_paused(&true);
139-
assert_eq!(result, Ok(()));
136+
client.set_paused(&true);
140137

141138
// Verify paused is set
142-
let is_paused = client.is_paused();
143-
assert_eq!(is_paused, Ok(true));
139+
assert!(client.is_paused());
144140
}
145141

146142
#[test]
@@ -152,24 +148,18 @@ mod test {
152148
let client = TestConsumerClient::new(&env, &id);
153149

154150
let admin = Address::generate(&env);
155-
let unauthorized = Address::generate(&env);
156151

157152
// Initialize with admin
158-
let result = client.initialize(&admin);
159-
assert_eq!(result, Ok(()));
153+
client.initialize(&admin);
160154

161-
// Unauthorized caller tries to set paused
155+
// Clear auths so admin.require_auth() fails
156+
env.set_auths(&[]);
162157
let result = client.try_set_paused(&true);
163-
assert_eq!(
164-
result,
165-
Err(Ok(soroban_sdk::Error::from_contract_error(
166-
MyfansError::NotAuthorized as u32
167-
)))
168-
);
169-
170-
// Paused should still be false
171-
let is_paused = client.is_paused();
172-
assert_eq!(is_paused, Ok(false));
158+
assert!(result.is_err(), "set_paused must fail without admin auth");
159+
160+
// Re-auth to read state
161+
env.mock_all_auths();
162+
assert!(!client.is_paused());
173163
}
174164

175165
#[test]
@@ -183,24 +173,17 @@ mod test {
183173
let admin = Address::generate(&env);
184174

185175
// Initialize with admin
186-
let result = client.initialize(&admin);
187-
assert_eq!(result, Ok(()));
176+
client.initialize(&admin);
188177

189-
// Multiple unauthorized callers should all be rejected
178+
// Multiple attempts without auth must all be rejected
190179
for _ in 0..3 {
191-
let unauthorized = Address::generate(&env);
180+
env.set_auths(&[]);
192181
let result = client.try_set_paused(&true);
193-
assert_eq!(
194-
result,
195-
Err(Ok(soroban_sdk::Error::from_contract_error(
196-
MyfansError::NotAuthorized as u32
197-
)))
198-
);
182+
assert!(result.is_err(), "set_paused must fail without admin auth");
199183
}
200184

201-
// Paused should still be false
202-
let is_paused = client.is_paused();
203-
assert_eq!(is_paused, Ok(false));
185+
env.mock_all_auths();
186+
assert!(!client.is_paused());
204187
}
205188

206189
#[test]
@@ -214,23 +197,19 @@ mod test {
214197
let admin = Address::generate(&env);
215198

216199
// Initialize with admin
217-
let result = client.initialize(&admin);
218-
assert_eq!(result, Ok(()));
200+
client.initialize(&admin);
219201

220202
// Admin sets paused to true
221-
let result = client.set_paused(&true);
222-
assert_eq!(result, Ok(()));
223-
assert_eq!(client.is_paused(), Ok(true));
203+
client.set_paused(&true);
204+
assert!(client.is_paused());
224205

225206
// Admin sets paused to false
226-
let result = client.set_paused(&false);
227-
assert_eq!(result, Ok(()));
228-
assert_eq!(client.is_paused(), Ok(false));
207+
client.set_paused(&false);
208+
assert!(!client.is_paused());
229209

230210
// Admin sets paused to true again
231-
let result = client.set_paused(&true);
232-
assert_eq!(result, Ok(()));
233-
assert_eq!(client.is_paused(), Ok(true));
211+
client.set_paused(&true);
212+
assert!(client.is_paused());
234213
}
235214

236215
// ── SubscriptionStatus ────────────────────────────────────────────────
@@ -304,6 +283,7 @@ mod test {
304283
&String::from_str(env, "MFAN"),
305284
&7,
306285
&0,
286+
&admin,
307287
);
308288
(client, admin)
309289
}
@@ -433,6 +413,7 @@ mod test {
433413
&String::from_str(env, "MFAN"),
434414
&7,
435415
&0,
416+
&admin,
436417
);
437418
(client, admin)
438419
}
@@ -607,6 +588,7 @@ mod test {
607588
&String::from_str(env, "MFAN"),
608589
&7,
609590
&0,
591+
&admin,
610592
);
611593
(client, admin)
612594
}
@@ -959,6 +941,7 @@ mod test {
959941
&String::from_str(env, "MFAN"),
960942
&7,
961943
&0,
944+
&admin,
962945
);
963946
(client, admin)
964947
}
@@ -1545,7 +1528,10 @@ mod test {
15451528
mod earnings_integration {
15461529
use earnings::{Earnings, EarningsClient};
15471530
use proptest::proptest;
1548-
use soroban_sdk::{testutils::Address as _, Address, Env, Error as SorobanError};
1531+
use soroban_sdk::{
1532+
testutils::{Address as _, Ledger},
1533+
Address, Env, Error as SorobanError,
1534+
};
15491535

15501536
fn setup(env: &Env) -> (EarningsClient<'_>, Address, Address) {
15511537
env.mock_all_auths();
@@ -1749,7 +1735,7 @@ mod test {
17491735

17501736
// Advance the ledger (simulates time passing).
17511737
env.ledger().with_mut(|ledger| {
1752-
ledger.sequence = ledger.sequence.saturating_add(100);
1738+
ledger.sequence_number = ledger.sequence_number.saturating_add(100);
17531739
});
17541740

17551741
// ── Restore and verify snapshot consistency ──

0 commit comments

Comments
 (0)