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
4 changes: 4 additions & 0 deletions contracts/pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,13 @@ impl NodusAmm {
to: Address,
amount_0_out: i128,
amount_1_out: i128,
deadline: u64,
) -> Result<(), Error> {
require_initialized(&env)?;
require_not_paused(&env)?;
if env.ledger().timestamp() > deadline {
return Err(Error::Expired);
}
lock(&env)?;
env.storage()
.instance()
Expand Down
17 changes: 13 additions & 4 deletions contracts/pool/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ mod integration {
let (env, contract, _, _) = setup_initialized();
let client = NodusAmmClient::new(&env, &contract);
let to = Address::generate(&env);
assert!(client.try_swap(&to, &100, &0).is_err());
assert!(client.try_swap(&to, &100, &0, &u64::MAX).is_err());
}

#[test]
fn swap_zero_output_rejected() {
let (env, contract, _, _) = setup_initialized();
let client = NodusAmmClient::new(&env, &contract);
let to = Address::generate(&env);
assert!(client.try_swap(&to, &0, &0).is_err());
assert!(client.try_swap(&to, &0, &0, &u64::MAX).is_err());
}

#[test]
Expand All @@ -57,6 +57,15 @@ mod integration {
.is_err());
}

#[test]
fn expired_swap_rejected() {
let (env, contract, _, _) = setup_initialized();
let client = NodusAmmClient::new(&env, &contract);
env.ledger().set_timestamp(5_000);
let to = Address::generate(&env);
assert!(client.try_swap(&to, &100, &0, &1_000).is_err());
}

#[test]
fn not_initialized_token_query_fails() {
let env = Env::default();
Expand Down Expand Up @@ -123,7 +132,7 @@ mod integration {
client.pause(&admin);
let to = Address::generate(&env);
assert_eq!(
client.try_swap(&to, &100, &0),
client.try_swap(&to, &100, &0, &u64::MAX),
Err(Ok(nodus_protocol_amm::Error::ContractPaused))
);
}
Expand Down Expand Up @@ -196,7 +205,7 @@ mod integration {
let to = Address::generate(&env);
// No longer blocked by pause; fails for the ordinary reason (no reserves) instead.
assert_eq!(
client.try_swap(&to, &100, &0),
client.try_swap(&to, &100, &0, &u64::MAX),
Err(Ok(nodus_protocol_amm::Error::InsufficientLiquidity))
);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/pool/tests/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ mod soroban_contract_tests {
let (env, contract) = setup();
let client = NodusAmmClient::new(&env, &contract);
let to = Address::generate(&env);
assert!(client.try_swap(&to, &100, &0).is_err());
assert!(client.try_swap(&to, &100, &0, &u64::MAX).is_err());
}

#[test]
Expand Down
Loading