From 13bdcf4e7223f3ba8a20cbc2c3d36f154ab28ab4 Mon Sep 17 00:00:00 2001 From: emidev98 Date: Mon, 11 Dec 2023 20:30:09 +0200 Subject: [PATCH] feat: minter remove token --- Cargo.lock | 6 +- Cargo.toml | 2 +- .../src/contract/execute.rs | 24 +++++++ .../alliance-nft-minter/src/tests/execute.rs | 68 +++++++++++++++++++ packages/alliance-nft-packages/src/execute.rs | 1 + packages/alliance-nft-packages/src/query.rs | 1 - 6 files changed, 97 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1dd2ff0..fe5f974 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,7 +15,7 @@ dependencies = [ [[package]] name = "alliance-nft-collection" -version = "1.0.0" +version = "1.0.1" dependencies = [ "alliance-nft-packages", "cosmwasm-schema", @@ -33,7 +33,7 @@ dependencies = [ [[package]] name = "alliance-nft-minter" -version = "1.0.0" +version = "1.0.1" dependencies = [ "alliance-nft-packages", "cosmwasm-schema", @@ -51,7 +51,7 @@ dependencies = [ [[package]] name = "alliance-nft-packages" -version = "1.0.0" +version = "1.0.1" dependencies = [ "cosmwasm-schema", "cosmwasm-std", diff --git a/Cargo.toml b/Cargo.toml index 2d3d607..98bf24b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ members = [ [workspace.package] description = "Alliance NFT Collection dropped to the Game of Alliance players" authors = ["Terra Money "] -version = "1.0.0" +version = "1.0.1" edition = "2021" license = "GPL-3.0-or-later" repository = "https://github.com/terra-money/alliance-nft-collection" diff --git a/contracts/alliance-nft-minter/src/contract/execute.rs b/contracts/alliance-nft-minter/src/contract/execute.rs index f5cbdbf..176224e 100644 --- a/contracts/alliance-nft-minter/src/contract/execute.rs +++ b/contracts/alliance-nft-minter/src/contract/execute.rs @@ -21,6 +21,7 @@ pub fn execute( try_append_nft_metadata(deps, info, metadata) } ExecuteMinterMsg::Mint {} => try_mint(deps, env, info), + ExecuteMinterMsg::RemoveToken(address) => try_remove_token(deps, info, address), ExecuteMinterMsg::SendToDao(batch) => try_send_to_dao_treasury(deps, env, batch), ExecuteMinterMsg::ChangeDaoTreasuryAddress(address) => { try_change_dao_treasury_address(deps, info, address) @@ -29,6 +30,29 @@ pub fn execute( } } +/// Remove an NFT from the allowed minting list +fn try_remove_token( + deps: DepsMut, + info: MessageInfo, + address: String, +) -> Result { + let cfg = CONFIG.load(deps.storage)?; + cfg.is_authorized_execution(info.sender)?; + + if NFT_METADATA.has(deps.storage, address.clone()) { + NFT_METADATA.remove(deps.storage, address.clone()); + STATS.update(deps.storage, |mut stats| -> Result<_, ContractError> { + stats.available_nfts -= 1; + Ok(stats) + })?; + } + + Ok(Response::new().add_attributes([ + ("method", "try_remove_token"), + ("removed_token", address.as_ref()), + ])) +} + /// Append NFT metadata on chain. /// Execution only allowed when: /// - sender is the owner and diff --git a/contracts/alliance-nft-minter/src/tests/execute.rs b/contracts/alliance-nft-minter/src/tests/execute.rs index 1e8d090..b55f09e 100644 --- a/contracts/alliance-nft-minter/src/tests/execute.rs +++ b/contracts/alliance-nft-minter/src/tests/execute.rs @@ -468,3 +468,71 @@ fn test_try_change_owener() { }) ); } + +#[test] +fn remove_nft_from_mint() { + // Create the env with the contract + let (mut deps, env, _) = intantiate_with_reply(); + + // Execute the message + let _ = append_nft_metadata_execution( + deps.as_mut(), + "creator", + "terra1zdpgj8am5nqqvht927k3etljyl6a52kwqup0je".to_string(), + ); + + + // mint an nft + let res = execute( + deps.as_mut(), + env.clone(), + mock_info("creator", &[]), + ExecuteMinterMsg::RemoveToken(String::from("terra1zdpgj8am5nqqvht927k3etljyl6a52kwqup0je")), + ); + + assert_eq!( + res.unwrap(), + Response::default() + .add_attribute("method", "try_remove_token") + .add_attribute("removed_token", "terra1zdpgj8am5nqqvht927k3etljyl6a52kwqup0je") + ); + + // query to see if stats match + let query_res = query(deps.as_ref(), env, QueryMinterMsg::Stats {}).unwrap(); + assert_eq!( + query_res, + to_binary(&MinterStats { + available_nfts: 0, + minted_nfts: 0, + }) + .unwrap() + ); +} + + +#[test] +fn remove_nft_from_mint_wrong_sender() { + // Create the env with the contract + let (mut deps, env, _) = intantiate_with_reply(); + + // Execute the message + let _ = append_nft_metadata_execution( + deps.as_mut(), + "creator", + "terra1zdpgj8am5nqqvht927k3etljyl6a52kwqup0je".to_string(), + ); + + + // mint an nft + let res = execute( + deps.as_mut(), + env.clone(), + mock_info("creatorw", &[]), + ExecuteMinterMsg::RemoveToken(String::from("terra1zdpgj8am5nqqvht927k3etljyl6a52kwqup0je")), + ); + + assert_eq!( + res.unwrap_err().to_string(), + String::from("Unauthorized execution, sender (creatorw) is not the expected address (creator)") + ); +} \ No newline at end of file diff --git a/packages/alliance-nft-packages/src/execute.rs b/packages/alliance-nft-packages/src/execute.rs index aad0468..9be35d9 100644 --- a/packages/alliance-nft-packages/src/execute.rs +++ b/packages/alliance-nft-packages/src/execute.rs @@ -150,6 +150,7 @@ pub struct AllianceRedelegateMsg { pub enum ExecuteMinterMsg { AppendNftMetadata(HashMap), Mint {}, + RemoveToken(String), SendToDao(i16), ChangeDaoTreasuryAddress(String), ChangeOwner(String), diff --git a/packages/alliance-nft-packages/src/query.rs b/packages/alliance-nft-packages/src/query.rs index 6ad0da2..c046898 100644 --- a/packages/alliance-nft-packages/src/query.rs +++ b/packages/alliance-nft-packages/src/query.rs @@ -160,7 +160,6 @@ impl From for CW721QueryMsg { }, QueryCollectionMsg::AllOperators { owner, - /// unset or false will filter out expired items, you must set to true to see them include_expired, start_after, limit,