From 7c33ea49a4bdcde55295ff8b38b67b9caca441c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orkun=20K=C3=BCl=C3=A7e?= Date: Mon, 31 Jan 2022 09:56:33 +0300 Subject: [PATCH] Approval query returns positive for Owner (#47) * Owner is returned in approval * Add test --- contracts/cw721-base/src/contract_tests.rs | 20 ++++++++++++++++++++ contracts/cw721-base/src/query.rs | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/contracts/cw721-base/src/contract_tests.rs b/contracts/cw721-base/src/contract_tests.rs index fc64c10b2..2b840249c 100644 --- a/contracts/cw721-base/src/contract_tests.rs +++ b/contracts/cw721-base/src/contract_tests.rs @@ -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"), diff --git a/contracts/cw721-base/src/query.rs b/contracts/cw721-base/src/query.rs index 130897d08..885afcd21 100644 --- a/contracts/cw721-base/src/query.rs +++ b/contracts/cw721-base/src/query.rs @@ -90,6 +90,16 @@ where include_expired: bool, ) -> StdResult { 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()