Skip to content
Open
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
1 change: 1 addition & 0 deletions contracts/sorosave/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ pub enum ContractError {
InsufficientMembers = 16,
RoundNotComplete = 17,
GroupCompleted = 18,
InvalidToken = 19,
}
6 changes: 6 additions & 0 deletions contracts/sorosave/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ pub fn create_group(
return Err(ContractError::InsufficientMembers);
}

// Validate token contract exists by calling symbol()
let token_client = soroban_sdk::token::Client::new(env, &token);
if token_client.try_symbol().is_err() {
return Err(ContractError::InvalidToken);
}

let group_id = storage::get_group_counter(env) + 1;
storage::set_group_counter(env, group_id);

Expand Down
56 changes: 56 additions & 0 deletions contracts/sorosave/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,59 @@ fn test_set_group_admin() {
let group = client.get_group(&group_id);
assert_eq!(group.admin, new_admin);
}

#[test]
fn test_valid_token_contract() {
let (env, admin, client, token) = setup_env();

// Create group with valid token (should succeed)
let group_id = client.create_group(
&admin,
&String::from_str(&env, "Valid Token Group"),
&token,
&1_000_000,
&86400,
&5,
);

let group = client.get_group(&group_id);
assert_eq!(group.token, token);
}

#[test]
#[should_panic(expected = "InvalidToken")]
fn test_invalid_token_contract() {
let (env, admin, client, _token) = setup_env();

// Use a random address that's not a token contract
let invalid_token = Address::generate(&env);

// Try to create group with invalid token (should fail)
client.create_group(
&admin,
&String::from_str(&env, "Invalid Token Group"),
&invalid_token,
&1_000_000,
&86400,
&5,
);
}

#[test]
#[should_panic(expected = "InvalidToken")]
fn test_non_existent_token_contract() {
let (env, admin, client, _token) = setup_env();

// Use the contract's own address (not a token)
let non_token = client.address.clone();

// Try to create group with non-token contract (should fail)
client.create_group(
&admin,
&String::from_str(&env, "Non-Token Group"),
&non_token,
&1_000_000,
&86400,
&5,
);
}