Skip to content

Commit 688969e

Browse files
authored
Merge pull request #426 from emarc99/fix/transfer_admin_validation_bug
Fix: Admin Transfer Validation & Test Stability
2 parents dba14f4 + 05797b8 commit 688969e

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

stellar-contracts/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub enum Error {
4040
NoPendingAdmin = 203,
4141
InvalidRecipient = 204,
4242
NotOperator = 205,
43+
SameAdmin = 207,
4344
OperatorCapReached = 206,
4445

4546
// --- 300 series: Constraints & Limits ---
@@ -1174,6 +1175,9 @@ impl FiatBridge {
11741175
.get(&DataKey::Admin)
11751176
.ok_or(Error::NotInitialized)?;
11761177
admin.require_auth();
1178+
if new_admin == admin {
1179+
return Err(Error::SameAdmin);
1180+
}
11771181
env.storage()
11781182
.instance()
11791183
.set(&DataKey::PendingAdmin, &new_admin);

stellar-contracts/src/test.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,21 @@ fn test_transfer_admin() {
328328
assert_eq!(bridge.get_admin(), new_admin);
329329
}
330330

331+
#[test]
332+
fn test_transfer_admin_to_self_fails() {
333+
let env = Env::default();
334+
env.mock_all_auths();
335+
336+
let (_, bridge, admin, _, _, _) = setup_bridge(&env, 100);
337+
338+
// Attempting to transfer to self should fail with InvalidRecipient
339+
let result = bridge.try_transfer_admin(&admin);
340+
assert_eq!(result, Err(Ok(Error::SameAdmin)));
341+
342+
// Admin should remain the same
343+
assert_eq!(bridge.get_admin(), admin);
344+
}
345+
331346
#[test]
332347
fn test_set_limit() {
333348
let env = Env::default();
@@ -3061,6 +3076,8 @@ fn test_withdraw_to_self_address_rejected() {
30613076
bridge.deposit(&user, &500, &token_addr, &Bytes::new(&env), &0, &0, &None);
30623077

30633078
// Attempt to withdraw to the contract's own address — should be rejected
3079+
// Order: caller, to, amount, token
3080+
30643081
let result = bridge.try_withdraw(&admin, &contract_id, &100, &token_addr);
30653082
assert_eq!(result, Err(Ok(Error::InvalidRecipient)));
30663083

@@ -3181,3 +3198,4 @@ fn test_set_min_deposit_admin_only() {
31813198
let result = bridge.try_set_min_deposit(&0);
31823199
assert_eq!(result, Err(Ok(Error::BelowMinimum)));
31833200
}
3201+

0 commit comments

Comments
 (0)