Skip to content
Open
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
46 changes: 44 additions & 2 deletions contracts/predinex/src/protocol_fee_tests.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![cfg(test)]
use super::*;
use soroban_sdk::{
testutils::{Address as _, Ledger},
Address, Env, String,
testutils::{Address as _, Events, Ledger},
vec, Address, Env, IntoVal, String, Symbol,
};

fn setup_contract() -> (Env, PredinexContractClient<'static>, Address, Address) {
Expand All @@ -18,8 +18,24 @@
client.initialize(&token_id.address(), &token_admin, &token_admin);

(env, client, token_admin, token_id.address())
}

Check warning on line 21 in contracts/predinex/src/protocol_fee_tests.rs

View workflow job for this annotation

GitHub Actions / Contract Checks

Diff in /home/runner/work/predinex-stellar/predinex-stellar/contracts/predinex/src/protocol_fee_tests.rs

/// Like `setup_contract` but returns the contract_id for event assertion.
fn setup_contract_for_events() -> (Env, PredinexContractClient<'static>, Address, Address, Address) {
let env = Env::default();
env.mock_all_auths();

let contract_id = env.register(PredinexContract, ());
let client: PredinexContractClient<'static> = PredinexContractClient::new(&env, &contract_id);

let token_admin = Address::generate(&env);
let token_id = env.register_stellar_asset_contract_v2(token_admin.clone());

client.initialize(&token_id.address(), &token_admin, &token_admin);

(env, client, contract_id, token_admin, token_id.address())
}

#[test]
fn test_get_protocol_fee_returns_default() {
let (_env, client, _, _) = setup_contract();
Expand Down Expand Up @@ -99,3 +115,29 @@

assert_eq!(pool_id, 1);
}

/// `set_protocol_fee` emits a single `protocol_fee_set` event carrying the new
/// fee and `event_version` in its topic tuple, consistent with all other events.
#[test]
fn test_set_protocol_fee_emits_event_with_version() {
let (env, client, cid, admin, _) = setup_contract_for_events();

client.set_protocol_fee(&admin, &500);

let events = env.events().all();
assert_eq!(
events,
vec![
&env,
(
cid,
(
Symbol::new(&env, "protocol_fee_set"),
Symbol::new(&env, EVENT_SCHEMA_VERSION),
)
.into_val(&env),
(admin, 200u32, 500u32).into_val(&env),
),
]
);
}
Loading