Skip to content

Commit a2d2caa

Browse files
Merge pull request #170 from JayWebtech/contract_issues
issue fixes
2 parents ee9271d + 4b02b7d commit a2d2caa

47 files changed

Lines changed: 13572 additions & 498 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

contracts/src/fuzz.rs

Lines changed: 101 additions & 113 deletions
Large diffs are not rendered by default.

contracts/src/lib.rs

Lines changed: 365 additions & 237 deletions
Large diffs are not rendered by default.

contracts/src/tests.rs

Lines changed: 184 additions & 81 deletions
Large diffs are not rendered by default.

contracts/src/token.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use soroban_sdk::{
77
enum DataKey {
88
CertificateContract,
99
Balance(Address, u32),
10+
MintPaused,
1011
}
1112

1213
#[contracterror]
@@ -15,6 +16,7 @@ pub enum TokenError {
1516
AlreadyInitialized = 1,
1617
NotAuthorized = 2,
1718
InvalidAmount = 3,
19+
ContractPaused = 4,
1820
}
1921

2022
#[contract]
@@ -31,12 +33,46 @@ impl RsTokenContract {
3133
env.storage()
3234
.instance()
3335
.set(&DataKey::CertificateContract, &certificate_contract);
36+
env.storage()
37+
.instance()
38+
.set(&DataKey::MintPaused, &false);
39+
}
40+
41+
fn require_mint_not_paused(env: &Env) {
42+
let paused: bool = env
43+
.storage()
44+
.instance()
45+
.get(&DataKey::MintPaused)
46+
.unwrap_or(false);
47+
if paused {
48+
panic_with_error!(env, TokenError::ContractPaused);
49+
}
50+
}
51+
52+
/// Only the certificate contract may pause minting (invoked when the cert contract pauses).
53+
pub fn set_mint_pause(env: Env, caller: Address, paused: bool) {
54+
caller.require_auth();
55+
56+
let certificate_contract: Address = env
57+
.storage()
58+
.instance()
59+
.get(&DataKey::CertificateContract)
60+
.unwrap();
61+
62+
if caller != certificate_contract {
63+
panic_with_error!(&env, TokenError::NotAuthorized);
64+
}
65+
66+
env.storage()
67+
.instance()
68+
.set(&DataKey::MintPaused, &paused);
3469
}
3570

3671
/// Mints non-transferable RS-Tokens to a student for a specific token ID.
3772
/// Only the configured certificate contract address may call this.
3873
pub fn mint(env: Env, caller: Address, student: Address, token_id: u32, amount: i128) {
3974
caller.require_auth();
75+
Self::require_mint_not_paused(&env);
4076

4177
let certificate_contract: Address = env
4278
.storage()
@@ -136,6 +172,23 @@ mod tests {
136172
client.mint(&unauthorized, &student, &1, &10);
137173
}
138174

175+
#[test]
176+
#[should_panic]
177+
fn rejects_mint_when_paused() {
178+
let env = Env::default();
179+
env.mock_all_auths();
180+
181+
let contract_id = env.register(RsTokenContract, ());
182+
let client = RsTokenContractClient::new(&env, &contract_id);
183+
184+
let certificate_contract = Address::generate(&env);
185+
let student = Address::generate(&env);
186+
187+
client.init(&certificate_contract);
188+
client.set_mint_pause(&certificate_contract, &true);
189+
client.mint(&certificate_contract, &student, &1, &10);
190+
}
191+
139192
#[test]
140193
fn mints_different_token_ids_for_same_student() {
141194
let env = Env::default();

0 commit comments

Comments
 (0)