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

ERC-721: Clear approval in burn() #2099

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix the `StorageVec` type by excluding the `len_cached` field from its type info - [#2052](https://github.com/paritytech/ink/pull/2052)
- Fix panic in `approve_for` in the ERC-721 example - [#2092](https://github.com/paritytech/ink/pull/2092)
- ERC-721: `transfer_token_from` now ensures the token owner is correct - [#2093](https://github.com/paritytech/ink/pull/2093)
- ERC-721: `burn()` clears token approval - [#2099](https://github.com/paritytech/ink/pull/2099)

## Version 5.0.0-rc

Expand Down
26 changes: 26 additions & 0 deletions integration-tests/erc721/lib.rs
Expand Up @@ -226,6 +226,7 @@ mod erc721 {
.ok_or(Error::CannotFetchValue)?;
owned_tokens_count.insert(caller, &count);
token_owner.remove(id);
self.clear_approval(id);

self.env().emit_event(Transfer {
from: Some(caller),
Expand Down Expand Up @@ -635,6 +636,31 @@ mod erc721 {
assert_eq!(erc721.burn(1), Err(Error::NotOwner));
}

#[ink::test]
fn burn_clears_approval() {
let accounts =
ink::env::test::default_accounts::<ink::env::DefaultEnvironment>();
// Create a new contract instance.
let mut erc721 = Erc721::new();
// Create token Id 1 for Alice
assert_eq!(erc721.mint(1), Ok(()));
// Alice gives approval to Bob to transfer token Id 1
assert_eq!(erc721.approve(accounts.bob, 1), Ok(()));
// Alice burns token
assert_eq!(erc721.burn(1), Ok(()));
// Set caller to Frank
set_caller(accounts.frank);
// Frank mints token Id 1
assert_eq!(erc721.mint(1), Ok(()));
// Set caller to Bob
set_caller(accounts.bob);
// Bob tries to transfer token Id 1 from Frank to himself
assert_eq!(
erc721.transfer_from(accounts.frank, accounts.bob, 1),
Err(Error::NotApproved)
);
}

#[ink::test]
fn transfer_from_fails_not_owner() {
let accounts =
Expand Down