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
12 changes: 6 additions & 6 deletions contract/contracts/access-control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ impl AccessControl {
/// * `admin` - The address to be appointed as the initial super admin.
///
/// # Errors
/// * Panics with `"AlreadyInitialized"` if the contract has already been initialized.
/// * Panics with `"AlreadyInitializedOrConfigNotSet"` if the contract has already been initialized.
pub fn init(env: Env, admin: Address) {
if env.storage().instance().has(&DataKey::Admin) {
soroban_sdk::panic_with_error!(&env, PrediFiError::AlreadyInitialized);
soroban_sdk::panic_with_error!(&env, PrediFiError::AlreadyInitializedOrConfigNotSet);
}
env.storage().instance().set(&DataKey::Admin, &admin);
// Also grant the Admin role to the admin address.
Expand Down Expand Up @@ -126,7 +126,7 @@ impl AccessControl {
///
/// # Errors
/// * `Unauthorized` - If the caller is not the super admin.
/// * `RoleNotFound` - If the user doesn't have the specified role.
/// * `InsufficientPermissions` - If the user doesn't have the specified role.
pub fn revoke_role(
env: Env,
admin_caller: Address,
Expand All @@ -145,7 +145,7 @@ impl AccessControl {
.persistent()
.has(&DataKey::Role(user.clone(), role.clone()))
{
return Err(PrediFiError::RoleNotFound);
return Err(PrediFiError::InsufficientPermissions);
}

env.storage()
Expand Down Expand Up @@ -178,7 +178,7 @@ impl AccessControl {
///
/// # Errors
/// * `Unauthorized` - If the caller is not the super admin.
/// * `RoleNotFound` - If the `from` address doesn't have the specified role.
/// * `InsufficientPermissions` - If the `from` address doesn't have the specified role.
pub fn transfer_role(
env: Env,
admin_caller: Address,
Expand All @@ -198,7 +198,7 @@ impl AccessControl {
.persistent()
.has(&DataKey::Role(from.clone(), role.clone()))
{
return Err(PrediFiError::RoleNotFound);
return Err(PrediFiError::InsufficientPermissions);
}

env.storage()
Expand Down
40 changes: 26 additions & 14 deletions contract/contracts/predifi-contract/src/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

use super::*;
use crate::test_utils::TokenTestContext;
use soroban_sdk::{testutils::Address as _, Address, Env};
use soroban_sdk::{
testutils::{Address as _, Ledger},
Address, Env,
};

mod dummy_access_control {
use soroban_sdk::{contract, contractimpl, Address, Env, Symbol};
Expand All @@ -27,7 +30,9 @@ mod dummy_access_control {
const ROLE_ADMIN: u32 = 0;
const ROLE_OPERATOR: u32 = 1;

fn setup_integration(env: &Env) -> (
fn setup_integration(
env: &Env,
) -> (
PredifiContractClient<'static>,
TokenTestContext,
Address, // Admin
Expand Down Expand Up @@ -79,7 +84,8 @@ fn test_full_market_lifecycle() {
// Total stake = 100 + 200 + 300 = 600
assert_eq!(token_ctx.token.balance(&client.address), 600);

// 3. Resolve Pool
// 3. Resolve Pool (advance time past end_time=1000)
env.ledger().with_mut(|li| li.timestamp = 1001);
client.resolve_pool(&operator, &pool_id, &1u32); // Outcome 1 wins

// 4. Claim Winnings
Expand Down Expand Up @@ -110,13 +116,16 @@ fn test_multi_user_betting_and_balance_verification() {
let (client, token_ctx, _admin, operator, _treasury) = setup_integration(&env);

// 5 users
let users: soroban_sdk::Vec<Address> = soroban_sdk::Vec::from_array(&env, [
Address::generate(&env),
Address::generate(&env),
Address::generate(&env),
Address::generate(&env),
Address::generate(&env),
]);
let users: soroban_sdk::Vec<Address> = soroban_sdk::Vec::from_array(
&env,
[
Address::generate(&env),
Address::generate(&env),
Address::generate(&env),
Address::generate(&env),
Address::generate(&env),
],
);

for user in users.iter() {
token_ctx.mint(&user, 5000);
Expand All @@ -131,7 +140,7 @@ fn test_multi_user_betting_and_balance_verification() {
// U3: 1500 on 3
// U4: 500 on 1
// Total 1: 1500, Total 2: 1000, Total 3: 1500. Total Stake: 4000.

client.place_prediction(&users.get(0).unwrap(), &pool_id, &500, &1);
client.place_prediction(&users.get(1).unwrap(), &pool_id, &1000, &2);
client.place_prediction(&users.get(2).unwrap(), &pool_id, &500, &1);
Expand All @@ -140,7 +149,8 @@ fn test_multi_user_betting_and_balance_verification() {

assert_eq!(token_ctx.token.balance(&client.address), 4000);

// Resolve to Outcome 3
// Resolve to Outcome 3 (advance time past end_time=2000)
env.ledger().with_mut(|li| li.timestamp = 2001);
client.resolve_pool(&operator, &pool_id, &3u32);

// Winner: U3
Expand Down Expand Up @@ -179,16 +189,18 @@ fn test_market_resolution_multiple_winners() {
// U2: 300 on 1
// U3: 500 on 2
// Total 1: 500, Total 2: 500. Total Stake: 1000.

client.place_prediction(&user1, &pool_id, &200, &1);
client.place_prediction(&user2, &pool_id, &300, &1);
client.place_prediction(&user3, &pool_id, &500, &2);

// Advance time past end_time=1500, then resolve
env.ledger().with_mut(|li| li.timestamp = 1501);
client.resolve_pool(&operator, &pool_id, &1u32); // Outcome 1 wins

// U1 Winnings: (200 / 500) * 1000 = 400
// U2 Winnings: (300 / 500) * 1000 = 600

let w1 = client.claim_winnings(&user1, &pool_id);
let w2 = client.claim_winnings(&user2, &pool_id);

Expand Down
Loading