Skip to content

Commit

Permalink
Approval query returns positive for Owner (#47)
Browse files Browse the repository at this point in the history
* Owner is returned in approval

* Add test
  • Loading branch information
orkunkl authored Jan 31, 2022
1 parent dab3e6c commit 7c33ea4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions contracts/cw721-base/src/contract_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,26 @@ fn approving_revoking() {
.execute(deps.as_mut(), mock_env(), minter, mint_msg)
.unwrap();

// token owner shows in approval query
let res = contract
.approval(
deps.as_ref(),
mock_env(),
token_id.clone(),
String::from("demeter"),
false,
)
.unwrap();
assert_eq!(
res,
ApprovalResponse {
approval: Approval {
spender: String::from("demeter"),
expires: Expiration::Never {}
}
}
);

// Give random transferring power
let approve_msg = ExecuteMsg::Approve {
spender: String::from("random"),
Expand Down
10 changes: 10 additions & 0 deletions contracts/cw721-base/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ where
include_expired: bool,
) -> StdResult<ApprovalResponse> {
let token = self.tokens.load(deps.storage, &token_id)?;

// token owner has absolute approval
if token.owner == spender {
let approval = cw721::Approval {
spender: token.owner.to_string(),
expires: Expiration::Never {},
};
return Ok(ApprovalResponse { approval });
}

let filtered: Vec<_> = token
.approvals
.into_iter()
Expand Down

0 comments on commit 7c33ea4

Please sign in to comment.