From 2f6836401b43c8e521fb0130107a573e774709ea Mon Sep 17 00:00:00 2001 From: Joe Monem Date: Thu, 14 Mar 2024 11:05:47 +0200 Subject: [PATCH] Auction: added tests for authorize and deauthorize token contract. +1.75% coverage --- .../andromeda-auction/src/testing/tests.rs | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/contracts/non-fungible-tokens/andromeda-auction/src/testing/tests.rs b/contracts/non-fungible-tokens/andromeda-auction/src/testing/tests.rs index b16c0cc76..81f613c97 100644 --- a/contracts/non-fungible-tokens/andromeda-auction/src/testing/tests.rs +++ b/contracts/non-fungible-tokens/andromeda-auction/src/testing/tests.rs @@ -13,7 +13,8 @@ use andromeda_non_fungible_tokens::{ cw721::ExecuteMsg as Cw721ExecuteMsg, }; use andromeda_std::{ - ado_base::modules::Module, + ado_base::{modules::Module, permissioning::Permission}, + ado_contract::ADOContract, amp::AndrAddr, common::{encode_binary, expiration::MILLISECONDS_TO_NANOSECONDS_RATIO}, error::ContractError, @@ -111,6 +112,66 @@ fn test_auction_instantiate() { assert_eq!(0, res.messages.len()); } +#[test] +fn test_authorize_and_deauthorize_token_contract() { + let mut deps = mock_dependencies_custom(&[]); + let env = mock_env(); + let _res = init(deps.as_mut(), None); + let token_contract = AndrAddr::from_string("adr"); + + let msg = ExecuteMsg::AuthorizeTokenContract { + addr: token_contract.clone(), + expiration: None, + }; + + let info = mock_info("not_owner", &[]); + // Unauthorized + let res = execute(deps.as_mut(), env.clone(), info, msg.clone()); + assert_eq!(ContractError::Unauthorized {}, res.unwrap_err()); + + // Works + let info = mock_info("owner", &[]); + let _res = execute(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); + + let permission = + ADOContract::get_permission(deps.as_mut().storage, "SEND_NFT", token_contract).unwrap(); + let expected_permission = Some(Permission::whitelisted(None)); + assert_eq!(permission, expected_permission); + + // Work with set expiration + let token_contract = AndrAddr::from_string("ada"); + let expiration = Some(Expiration::AtTime(Timestamp::from_nanos(1))); + let msg = ExecuteMsg::AuthorizeTokenContract { + addr: token_contract.clone(), + expiration, + }; + let _res = execute(deps.as_mut(), env.clone(), info, msg).unwrap(); + let permission = + ADOContract::get_permission(deps.as_mut().storage, "SEND_NFT", token_contract).unwrap(); + let expected_permission = Some(Permission::whitelisted(expiration)); + assert_eq!(permission, expected_permission); + + // Deauthorize + let token_contract = AndrAddr::from_string("adr"); + let msg = ExecuteMsg::DeauthorizeTokenContract { + addr: token_contract.clone(), + }; + let info = mock_info("not_owner", &[]); + // Unauthorized + let res = execute(deps.as_mut(), env.clone(), info, msg); + assert_eq!(ContractError::Unauthorized {}, res.unwrap_err()); + + // Works + let msg = ExecuteMsg::DeauthorizeTokenContract { + addr: token_contract.clone(), + }; + let info = mock_info("owner", &[]); + let _res = execute(deps.as_mut(), env.clone(), info, msg).unwrap(); + let permission = + ADOContract::get_permission(deps.as_mut().storage, "SEND_NFT", token_contract).unwrap(); + assert!(permission.is_none()); +} + #[test] fn test_execute_place_bid_non_existing_auction() { let mut deps = mock_dependencies_custom(&[]);