Skip to content

Commit

Permalink
ERC-721: Clear approval in burn() (#2099)
Browse files Browse the repository at this point in the history
* ERC-721: Clear approval in burn()

* ERC-721: add changelog entry
  • Loading branch information
zgrannan authored Nov 15, 2024
1 parent 3e3df91 commit a0b2dce
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix outdated docs for `[ink_e2e::test]`[#2162](https://github.com/use-ink/ink/pull/2162)
- [E2E] build contracts before initializing node rpc ‒ [#2168](https://github.com/use-ink/ink/pull/2162)
- [E2E] `set_account_balance` now can't set balance below existential deposit - [#1983](https://github.com/paritytech/ink/pull/1983) (thanks [@0xLucca](https://github.com/0xLucca)!)
- ERC-721: `burn()` clears token approval - [#2099](https://github.com/paritytech/ink/pull/2099)

## Version 5.0.0

Expand Down
26 changes: 26 additions & 0 deletions integration-tests/public/erc721/lib.rs
Original file line number Diff line number Diff line change
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

0 comments on commit a0b2dce

Please sign in to comment.