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(ADR-006): POAP v2 #195

Merged
merged 40 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b362cad
feat: add new poap-v2 contract
manu0466 Jul 12, 2023
e1a33b6
feat: add messages to update the POAP contract configurations
manu0466 Jul 14, 2023
e037425
feat: add messages to query the POAP contract configurations
manu0466 Jul 14, 2023
2501925
feat: add transferable check to SendNft message
manu0466 Jul 14, 2023
232f7ca
refactor: reordered field of InstantiateMsg
manu0466 Jul 14, 2023
a40568b
fix: build error
manu0466 Jul 14, 2023
b8fb961
fix: check if user can mint
manu0466 Jul 14, 2023
c0cfccf
fix: start mint start time check logic
manu0466 Jul 14, 2023
6887edd
test: add user mint tests
manu0466 Jul 14, 2023
5a496af
test: wrote all execution tests
manu0466 Jul 14, 2023
1c678d0
test: check contract errors
manu0466 Jul 14, 2023
f3bda48
docs: finalized contract documentation
manu0466 Jul 14, 2023
f68cdc2
chore: removed old poap contracts
manu0466 Jul 14, 2023
70e7f91
build: fix build command
manu0466 Jul 14, 2023
dbce992
build: add schema generator
manu0466 Jul 14, 2023
03380a9
build: add cargo alias
manu0466 Jul 14, 2023
5fd6a8b
refactor: moved the code into the poap directory
manu0466 Jul 14, 2023
0aa3426
chore: add README.md with the build instructions
manu0466 Jul 14, 2023
3098401
test: test cw721 base messages
manu0466 Jul 17, 2023
0d9ba25
docs: update message documentation
manu0466 Jul 17, 2023
6c1a962
docs: add contract documentation
manu0466 Jul 17, 2023
236b3aa
build(deps): update cargo.lock
manu0466 Jul 17, 2023
eb2ee0a
build(deps): update cosmwasm, serde and thiserror
manu0466 Jul 17, 2023
c52b286
docs: update AD3-006 Status
manu0466 Jul 17, 2023
1ef1f99
test: fixed failing tests
manu0466 Jul 17, 2023
21c6832
ci: update tarpaulin action
manu0466 Jul 17, 2023
02e2db9
docs: update repo README.md
manu0466 Jul 17, 2023
2f66294
feat: add mint start time and mint end time checks when instantiating…
manu0466 Jul 17, 2023
ac46dfe
chore: bump version to 2.0.0
manu0466 Jul 18, 2023
26063e0
feat: allow the admin to perform the minter operations
manu0466 Jul 18, 2023
034cf97
feat: allow the minter to be optional
manu0466 Jul 18, 2023
e543c83
feat: limit the poap that and user can mint to 1
manu0466 Jul 18, 2023
41d98c7
chore: excluded some functions from the test coverage
manu0466 Jul 18, 2023
04b0547
test: add test to ensure that the instantiate message checks the star…
manu0466 Jul 18, 2023
5133c8a
feat: enforce max one POAP per user
manu0466 Jul 18, 2023
42f4c06
docs: update POAP contract documentation
manu0466 Jul 18, 2023
4c2efd0
chore: fixed typos
RiccardoM Jul 18, 2023
a2d2197
refactor: moved assert_user_dont_own_a_poap into mint_to_user
manu0466 Jul 19, 2023
bad9a0d
chore: fix lint error
manu0466 Jul 19, 2023
93febe0
chore: fix compilation error
manu0466 Jul 19, 2023
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
29 changes: 28 additions & 1 deletion contracts/poap/src/contract_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::ExecuteMsg::{
Approve, ApproveAll, Burn, Mint, MintTo, Revoke, RevokeAll, SendNft, SetMintStartEndTime,
SetMintable, SetTransferable, TransferNft, UpdateMinter,
};
use crate::{ExecuteMsg, Extension, InstantiateMsg, PoapContract};
use crate::{ContractError, ExecuteMsg, Extension, InstantiateMsg, PoapContract};
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{to_binary, Addr, CosmosMsg, Deps, DepsMut, Empty, Env, Timestamp, WasmMsg};
use cw721::{Cw721Query, NftInfoResponse};
Expand Down Expand Up @@ -236,6 +236,33 @@ fn admin_can_mint_if_not_mintable() {
assert_poap_minted(&contract, deps.as_ref(), poap_id, ADMIN.to_string());
}

#[test]
fn user_cant_mint_more_then_1_poap() {
let mut deps = mock_dependencies();
let contract = setup_contract(deps.as_mut(), true, true, None, None);
let poap_id = contract.generate_poap_id(&deps.storage).unwrap();

let _ = contract
.execute(
deps.as_mut(),
mock_env(),
mock_info(USER, &[]),
Mint { extension: None },
)
.unwrap();
assert_poap_minted(&contract, deps.as_ref(), poap_id, USER.to_string());

let err = contract
.execute(
deps.as_mut(),
mock_env(),
mock_info(USER, &[]),
Mint { extension: None },
)
.unwrap_err();
assert_eq!(ContractError::PoapAlreadyMinted {}, err);
}

#[test]
fn user_can_mint_after_start_time() {
let mut deps = mock_dependencies();
Expand Down
3 changes: 3 additions & 0 deletions contracts/poap/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#[error("Mint is not allowed")]
MintDisabled {},

#[error("POAP already minted")]
PoapAlreadyMinted {},

#[error("You don't have the permission to mint")]
MintUnauthorized {},

Expand All @@ -43,14 +46,14 @@
}

impl From<Cw721BaseContractError> for ContractError {
fn from(error: Cw721BaseContractError) -> Self {
match error {
Cw721BaseContractError::Std(e) => ContractError::Std(e),
Cw721BaseContractError::Ownership(e) => ContractError::Ownership(e),
Cw721BaseContractError::Version(e) => ContractError::Version(e),

Check warning on line 53 in contracts/poap/src/error.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/error.rs#L49-L53

Added lines #L49 - L53 were not covered by tests
Cw721BaseContractError::Claimed {} => ContractError::Claimed {},
Cw721BaseContractError::Expired {} => ContractError::Expired {},
Cw721BaseContractError::ApprovalNotFound { spender } => {

Check warning on line 56 in contracts/poap/src/error.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/error.rs#L56

Added line #L56 was not covered by tests
ContractError::ApprovalNotFound { spender }
}
}
Expand Down
12 changes: 12 additions & 0 deletions contracts/poap/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

// Get the minter address or fallback to the sender address.
let minter = msg
.minter

Check warning on line 45 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L45

Added line #L45 was not covered by tests
.map(|minter| deps.api.addr_validate(&minter))
.transpose()?;
self.minter.save(deps.storage, &minter)?;
Expand All @@ -54,7 +54,7 @@
&& msg.mint_end_time.is_some()
&& msg.mint_start_time.unwrap() >= msg.mint_end_time.unwrap()
{
return Err(ContractError::InvalidTimestampValues {});

Check warning on line 57 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L57

Added line #L57 was not covered by tests
}

self.mint_start_time
Expand All @@ -73,31 +73,31 @@
) -> Result<Response<C>, ContractError> {
match msg {
ExecuteMsg::TransferNft {
recipient,
token_id,
} => self.transfer_poap(deps, env, info, recipient, token_id),

Check warning on line 78 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L76-L78

Added lines #L76 - L78 were not covered by tests
ExecuteMsg::SendNft {
contract,
msg,
token_id,
} => self.send_poap(deps, env, info, contract, token_id, msg),

Check warning on line 83 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L80-L83

Added lines #L80 - L83 were not covered by tests
ExecuteMsg::UpdateMinter { minter } => self.update_minter(deps, env, info, minter),
ExecuteMsg::SetMintable { mintable } => self.set_mintable(deps, env, info, mintable),
ExecuteMsg::SetTransferable { transferable } => {
self.set_transferable(deps, env, info, transferable)
}
ExecuteMsg::SetMintStartEndTime {
start_time,
end_time,
} => self.set_mint_start_end_time(deps, env, info, start_time, end_time),

Check warning on line 92 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L90-L92

Added lines #L90 - L92 were not covered by tests
ExecuteMsg::Mint { extension } => self.mint(deps, env, info, extension),
ExecuteMsg::MintTo { extension, users } => {
self.mint_to(deps, env, info, users, extension)
}
_ => self
.cw721_base

Check warning on line 98 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L98

Added line #L98 was not covered by tests
.execute(deps, env, info, msg.into())
.map_err(|e| e.into()),

Check warning on line 100 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L100

Added line #L100 was not covered by tests
}
}
}
Expand All @@ -124,9 +124,9 @@
self.assert_is_transferable(deps.storage)?;

return self
.cw721_base

Check warning on line 127 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L127

Added line #L127 was not covered by tests
.transfer_nft(deps, env, info, recipient, token_id)
.map_err(|e| e.into());

Check warning on line 129 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L129

Added line #L129 was not covered by tests
}

/// Send a POAP to a contract and trigger an action on the contract.
Expand All @@ -146,9 +146,9 @@
self.assert_is_transferable(deps.storage)?;

return self
.cw721_base

Check warning on line 149 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L149

Added line #L149 was not covered by tests
.send_nft(deps, env, info, contract, token_id, msg)
.map_err(|e| e.into());

Check warning on line 151 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L151

Added line #L151 was not covered by tests
}

/// Updates who have the minting permissions, this action can be executed only from
Expand All @@ -166,10 +166,10 @@
self.minter.save(deps.storage, &new_minter)?;

Ok(Response::new()
.add_attribute("action", "update_minter")

Check warning on line 169 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L169

Added line #L169 was not covered by tests
.add_attribute("sender", info.sender)
.add_attribute(
"new_minter",

Check warning on line 172 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L171-L172

Added lines #L171 - L172 were not covered by tests
new_minter.map_or_else(|| "none".to_string(), |minter| minter.to_string()),
))
}
Expand All @@ -188,7 +188,7 @@
self.is_mintable.save(deps.storage, &mintable)?;

Ok(Response::new()
.add_attribute("action", "set_mintable")

Check warning on line 191 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L191

Added line #L191 was not covered by tests
.add_attribute("sender", info.sender)
.add_attribute("mintable", mintable.to_string()))
}
Expand All @@ -207,7 +207,7 @@
self.is_transferable.save(deps.storage, &transferable)?;

Ok(Response::new()
.add_attribute("action", "set_transferable")

Check warning on line 210 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L210

Added line #L210 was not covered by tests
.add_attribute("sender", info.sender)
.add_attribute("transferable", transferable.to_string()))
}
Expand Down Expand Up @@ -239,14 +239,14 @@
self.mint_end_time.save(deps.storage, &end_time)?;

Ok(Response::new()
.add_attribute("action", "set_mint_start_end_time")

Check warning on line 242 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L242

Added line #L242 was not covered by tests
.add_attribute("sender", info.sender)
.add_attribute(
"start_time",

Check warning on line 245 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L244-L245

Added lines #L244 - L245 were not covered by tests
start_time.map_or_else(|| "none".to_string(), |t| t.to_string()),
)
.add_attribute(
"end_time",

Check warning on line 249 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L248-L249

Added lines #L248 - L249 were not covered by tests
end_time.map_or_else(|| "none".to_string(), |t| t.to_string()),
))
}
Expand All @@ -263,7 +263,7 @@
let token_id = self.mint_to_user(deps.storage, &info.sender, extension)?;

Ok(Response::new()
.add_attribute("action", "mint")

Check warning on line 266 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L266

Added line #L266 was not covered by tests
.add_attribute("owner", info.sender)
.add_attribute("token_id", token_id))
}
Expand Down Expand Up @@ -293,7 +293,7 @@
}

Ok(Response::new()
.add_attribute("action", "mint_to")

Check warning on line 296 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L296

Added line #L296 was not covered by tests
.add_attribute("minter", info.sender)
.add_attribute("token_ids", minted_tokens.join(", ")))
}
Expand Down Expand Up @@ -331,9 +331,9 @@
// Generate the token id
let token_id = self.generate_poap_id(storage)?;
self.cw721_base
.tokens

Check warning on line 334 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L334

Added line #L334 was not covered by tests
.update(storage, &token_id, |old| match old {
Some(_) => Err(ContractError::Claimed {}),

Check warning on line 336 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L336

Added line #L336 was not covered by tests
None => Ok(token),
})?;

Expand Down Expand Up @@ -392,6 +392,18 @@
return Err(ContractError::MintDisabled {});
}

// Check if this user have already minted a poap.
manu0466 marked this conversation as resolved.
Show resolved Hide resolved
if !self
.cw721_base
.tokens
.idx
.owner

Check warning on line 400 in contracts/poap/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/poap/src/execute.rs#L397-L400

Added lines #L397 - L400 were not covered by tests
.prefix(user.clone())
.is_empty(storage)
{
return Err(ContractError::PoapAlreadyMinted {});
}

// Check if we have a mint start time
if let Some(start_time) = self.mint_start_time.load(storage)? {
// Check if the event has started.
Expand Down
Loading