From a0b2dceb0cdefb7ce6935a52620a8c139b43d4c4 Mon Sep 17 00:00:00 2001 From: Zack Grannan Date: Fri, 15 Nov 2024 09:49:23 -0800 Subject: [PATCH] ERC-721: Clear approval in `burn()` (#2099) * ERC-721: Clear approval in burn() * ERC-721: add changelog entry --- CHANGELOG.md | 1 + integration-tests/public/erc721/lib.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9571f37470..00048420213 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/integration-tests/public/erc721/lib.rs b/integration-tests/public/erc721/lib.rs index 637836f934f..5b2cbafd944 100644 --- a/integration-tests/public/erc721/lib.rs +++ b/integration-tests/public/erc721/lib.rs @@ -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), @@ -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::(); + // 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 =