From c232173f563f4f83d284175ecb457eded1bc2c81 Mon Sep 17 00:00:00 2001 From: Jake Hartnell Date: Mon, 11 Sep 2023 18:12:44 -0700 Subject: [PATCH] Tests for renouncing ownership --- .../tests/cases/contract_owner.rs | 70 ++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/contracts/external/cw-tokenfactory-issuer/tests/cases/contract_owner.rs b/contracts/external/cw-tokenfactory-issuer/tests/cases/contract_owner.rs index 4066e0f57..04cbc431b 100644 --- a/contracts/external/cw-tokenfactory-issuer/tests/cases/contract_owner.rs +++ b/contracts/external/cw-tokenfactory-issuer/tests/cases/contract_owner.rs @@ -1,5 +1,5 @@ -use cosmwasm_std::Addr; -use cw_tokenfactory_issuer::ContractError; +use cosmwasm_std::{Addr, Uint128}; +use cw_tokenfactory_issuer::{msg::ExecuteMsg, ContractError}; use osmosis_test_tube::Account; use crate::test_env::{TestEnv, TokenfactoryIssuer}; @@ -52,3 +52,69 @@ fn change_owner_by_non_owner_should_fail() { )) ); } + +#[test] +fn renounce_ownership() { + let env = TestEnv::default(); + let owner = &env.test_accs[0]; + let non_owner = &env.test_accs[1]; + let hook = &env.test_accs[1]; + + assert_eq!( + Some(Addr::unchecked(owner.address())), + env.cw_tokenfactory_issuer.query_owner().unwrap().owner, + ); + + // Renounce ownership + env.cw_tokenfactory_issuer + .execute( + &ExecuteMsg::UpdateOwnership(cw_ownable::Action::RenounceOwnership), + &[], + owner, + ) + .unwrap(); + + assert_eq!( + env.cw_tokenfactory_issuer.query_owner().unwrap().owner, + None, + ); + + // Cannot perform actions that require ownership + assert_eq!( + env.cw_tokenfactory_issuer + .set_minter(&non_owner.address(), 10000, owner) + .unwrap_err(), + TokenfactoryIssuer::execute_error(ContractError::Ownership( + cw_ownable::OwnershipError::NoOwner + )) + ); + assert_eq!( + env.cw_tokenfactory_issuer + .set_burner(&non_owner.address(), 10000, owner) + .unwrap_err(), + TokenfactoryIssuer::execute_error(ContractError::Ownership( + cw_ownable::OwnershipError::NoOwner + )) + ); + assert_eq!( + env.cw_tokenfactory_issuer + .force_transfer( + non_owner, + Uint128::new(10000), + owner.address(), + non_owner.address(), + ) + .unwrap_err(), + TokenfactoryIssuer::execute_error(ContractError::Ownership( + cw_ownable::OwnershipError::NoOwner + )) + ); + assert_eq!( + env.cw_tokenfactory_issuer + .set_before_send_hook(hook.address(), owner) + .unwrap(), + TokenfactoryIssuer::execute_error(ContractError::Ownership( + cw_ownable::OwnershipError::NoOwner + )) + ); +}