Skip to content

Commit

Permalink
test(lockup): add test for edge case of withdrawal at exact maturity
Browse files Browse the repository at this point in the history
  • Loading branch information
Unique-Divine committed Sep 25, 2024
1 parent a7f7135 commit 7d6e277
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions contracts/lockup/src/contract_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,42 @@ fn test_lock_state() -> TestResult {

Ok(())
}

#[test]
fn test_withdraw_at_exact_maturity() -> TestResult {
let (mut deps, mut env, _info) = setup_contract()?;

// Create and initiate unlock for a lock
let info = mock_info(USER, &coins(100, DENOM));
let msg = ExecuteMsg::Lock { blocks: 100 };
let _ = execute(deps.as_mut(), env.clone(), info, msg)?;

let msg = ExecuteMsg::InitiateUnlock { id: 1 };
let info = mock_info(USER, &[]);
let _ = execute(deps.as_mut(), env.clone(), info, msg)?;

// Fast forward to exact maturity
env.block.height += 100;

// Attempt to withdraw at exact maturity
let msg = ExecuteMsg::WithdrawFunds { id: 1 };
let info = mock_info(USER, &[]);
let res = execute(deps.as_mut(), env.clone(), info, msg)?;

// Check that withdrawal was successful
assert_eq!(1, res.messages.len());
assert_eq!(
res.messages[0],
SubMsg::new(BankMsg::Send {
to_address: USER.to_string(),
amount: vec![Coin::new(100u128, DENOM)]
})
);

// Query the lock to ensure it's marked as withdrawn
let locks = locks();
let lock = locks.load(&deps.storage, 1)?;
assert!(lock.funds_withdrawn);

Ok(())
}

0 comments on commit 7d6e277

Please sign in to comment.