Skip to content

Commit

Permalink
Marketplace: added test for start_time in past and expired status error
Browse files Browse the repository at this point in the history
  • Loading branch information
joemonem committed Mar 14, 2024
1 parent 07dde2b commit 5dbf5b0
Showing 1 changed file with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,40 @@ fn test_execute_buy_works() {
let _res = execute(deps.as_mut(), env, info, msg).unwrap();
}

#[test]
fn test_start_sale_in_past() {
let mut deps = mock_dependencies_custom(&[]);
let env = mock_env();

let _res = init(deps.as_mut(), None);

let current_time = env.block.time.nanos() / MILLISECONDS_TO_NANOSECONDS_RATIO;
let hook_msg = Cw721HookMsg::StartSale {
coin_denom: "uusd".to_string(),
price: Uint128::new(100),
// Set start time to one second in the past
start_time: Some(env.block.time.minus_seconds(1).seconds()),
duration: Some(360),
};
let msg = ExecuteMsg::ReceiveNft(Cw721ReceiveMsg {
sender: MOCK_TOKEN_OWNER.to_owned(),
token_id: MOCK_UNCLAIMED_TOKEN.to_owned(),
msg: encode_binary(&hook_msg).unwrap(),
});
let env = mock_env();

let info = mock_info(MOCK_TOKEN_ADDR, &[]);
let err = execute(deps.as_mut(), env.clone(), info, msg).unwrap_err();

assert_eq!(
err,
ContractError::StartTimeInThePast {
current_time,
current_block: env.block.height
}
)
}

#[test]
fn test_execute_buy_future_start() {
let mut deps = mock_dependencies_custom(&[]);
Expand Down Expand Up @@ -377,6 +411,32 @@ fn test_execute_buy_sale_expired() {
assert_eq!(err, ContractError::SaleExpired {})
}

#[test]
fn test_execute_buy_sale_expired_from_the_start() {
let mut deps = mock_dependencies_custom(&[]);
let env = mock_env();

let _res = init(deps.as_mut(), None);

start_sale_future_start_with_duration(deps.as_mut(), mock_env());

let msg = ExecuteMsg::Buy {
token_id: MOCK_UNCLAIMED_TOKEN.to_owned(),
token_address: MOCK_TOKEN_ADDR.to_string(),
};

let info = mock_info("someone", &coins(100, "uusd".to_string()));
// Set status as expired
let mut state = TOKEN_SALE_STATE.load(deps.as_mut().storage, 1).unwrap();
state.status = Status::Expired;
TOKEN_SALE_STATE
.save(deps.as_mut().storage, 1, &state)
.unwrap();

let err = execute(deps.as_mut(), env, info, msg).unwrap_err();
assert_eq!(err, ContractError::SaleExpired {})
}

#[test]
fn test_execute_update_sale_unauthorized() {
let mut deps = mock_dependencies_custom(&[]);
Expand Down

0 comments on commit 5dbf5b0

Please sign in to comment.