Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contracts/revenue_pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const ERR_UNAUTHORIZED: &str = "unauthorized: caller is not admin";
const ERR_INSUFFICIENT_BALANCE: &str = "insufficient USDC balance";
const ERR_NOT_INITIALIZED: &str = "revenue pool not initialized";
const ERR_DUPLICATE_RECIPIENT: &str = "duplicate recipient in batch";
const PAUSED_KEY: &str = "paused";
const ERR_PAUSED: &str = "revenue pool paused";
const VERSION_KEY: &str = "version";

pub const DEFAULT_MAX_DISTRIBUTE: i128 = i128::MAX;
Expand Down
40 changes: 40 additions & 0 deletions contracts/revenue_pool/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,46 @@ fn create_usdc<'a>(
assert_eq!(usdc_client.balance(&developer), 400);
}

#[test]
fn pause_blocks_distribute() {
let env = Env::default();
env.mock_all_auths();
let admin = Address::generate(&env);
let developer = Address::generate(&env);
let (pool_addr, client) = create_pool(&env);
let (usdc_address, _, usdc_admin) = create_usdc(&env, &admin);

client.init(&admin, &usdc_address);
fund_pool(&usdc_admin, &pool_addr, 1_000);
assert!(!client.is_paused());
client.pause(&admin);
assert!(client.is_paused());

let result = std::panic::catch_unwind(|| client.distribute(&admin, &developer, &100));
assert!(result.is_err());
}

#[test]
fn unpause_restores_distribute() {
let env = Env::default();
env.mock_all_auths();
let admin = Address::generate(&env);
let developer = Address::generate(&env);
let (pool_addr, client) = create_pool(&env);
let (usdc_address, usdc_client, usdc_admin) = create_usdc(&env, &admin);

client.init(&admin, &usdc_address);
fund_pool(&usdc_admin, &pool_addr, 1_000);
client.pause(&admin);
assert!(client.is_paused());
client.unpause(&admin);
assert!(!client.is_paused());

client.distribute(&admin, &developer, &250);
assert_eq!(usdc_client.balance(&pool_addr), 750);
assert_eq!(usdc_client.balance(&developer), 250);
}

#[test]
#[should_panic(expected = "amount must be positive")]
fn distribute_zero_panics() {
Expand Down
Loading