Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: execute remove tokens #25

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ members = [
[workspace.package]
description = "Alliance NFT Collection dropped to the Game of Alliance players"
authors = ["Terra Money <[email protected]>"]
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"
Expand Down
24 changes: 24 additions & 0 deletions contracts/alliance-nft-minter/src/contract/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<Response, ContractError> {
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
Expand Down
68 changes: 68 additions & 0 deletions contracts/alliance-nft-minter/src/tests/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
);
}
1 change: 1 addition & 0 deletions packages/alliance-nft-packages/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pub struct AllianceRedelegateMsg {
pub enum ExecuteMinterMsg {
AppendNftMetadata(HashMap<String, MinterExtension>),
Mint {},
RemoveToken(String),
SendToDao(i16),
ChangeDaoTreasuryAddress(String),
ChangeOwner(String),
Expand Down
1 change: 0 additions & 1 deletion packages/alliance-nft-packages/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ impl From<QueryCollectionMsg> for CW721QueryMsg<Empty> {
},
QueryCollectionMsg::AllOperators {
owner,
/// unset or false will filter out expired items, you must set to true to see them
include_expired,
start_after,
limit,
Expand Down