From 5dbf5b04266a3855e3b9ee643ff720108f9b0558 Mon Sep 17 00:00:00 2001 From: Joe Monem Date: Thu, 14 Mar 2024 10:46:03 +0200 Subject: [PATCH] Marketplace: added test for start_time in past and expired status error --- .../src/testing/tests.rs | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs b/contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs index 4fdcd6882..cd03d0c84 100644 --- a/contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs +++ b/contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs @@ -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(&[]); @@ -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(&[]);