Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- 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)

## Version 5.0.0-rc

Expand Down
15 changes: 12 additions & 3 deletions integration-tests/erc721/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,8 @@ mod erc721 {
/// the message's sender.
fn approve_for(&mut self, to: &AccountId, id: TokenId) -> Result<(), Error> {
let caller = self.env().caller();
let owner = self.owner_of(id);
if !(owner == Some(caller)
|| self.approved_for_all(owner.expect("Error with AccountId"), caller))
let owner = self.owner_of(id).ok_or(Error::TokenNotFound)?;
if !(owner == caller || self.approved_for_all(owner, caller))
{
return Err(Error::NotAllowed)
};
Expand Down Expand Up @@ -560,6 +559,16 @@ mod erc721 {
assert!(!erc721.is_approved_for_all(accounts.alice, accounts.bob));
}

#[ink::test]
fn approve_nonexistent_token_should_fail() {
let accounts =
ink::env::test::default_accounts::<ink::env::DefaultEnvironment>();
// Create a new contract instance.
let mut erc721 = Erc721::new();
// Approve transfer of nonexistent token id 1
assert_eq!(erc721.approve(accounts.bob, 1), Err(Error::TokenNotFound));
}

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