From 4c285c2c04479299a6bb8078c027c20dbac3dcc3 Mon Sep 17 00:00:00 2001 From: leoloco Date: Mon, 6 May 2024 16:30:53 +0200 Subject: [PATCH 1/2] Fixed return type --- smart-contracts/assembly/contracts/NFT/NFT-example.ts | 8 ++++---- smart-contracts/assembly/contracts/NFT/NFT-internals.ts | 8 ++++++++ .../assembly/contracts/NFT/__tests__/NFT-example.spec.ts | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/smart-contracts/assembly/contracts/NFT/NFT-example.ts b/smart-contracts/assembly/contracts/NFT/NFT-example.ts index d4ea73a..c44d5cf 100644 --- a/smart-contracts/assembly/contracts/NFT/NFT-example.ts +++ b/smart-contracts/assembly/contracts/NFT/NFT-example.ts @@ -55,12 +55,12 @@ export function constructor(binaryArgs: StaticArray): void { setOwner(new Args().add(Context.caller().toString()).serialize()); } -export function name(): string { - return _name(); +export function name(): StaticArray { + return stringToBytes(_name()); } -export function symbol(): string { - return _symbol(); +export function symbol(): StaticArray { + return stringToBytes(_symbol()); } /** diff --git a/smart-contracts/assembly/contracts/NFT/NFT-internals.ts b/smart-contracts/assembly/contracts/NFT/NFT-internals.ts index 8d068df..a3c7bd6 100644 --- a/smart-contracts/assembly/contracts/NFT/NFT-internals.ts +++ b/smart-contracts/assembly/contracts/NFT/NFT-internals.ts @@ -280,6 +280,14 @@ export function _transferFrom(from: string, to: string, tokenId: u256): void { _update(to, tokenId, from); } +export function _transfer(to: string, tokenId: u256): void { + assert(Storage.has(ownerKey(tokenId)), 'Nonexistent token'); + const from = Context.caller().toString(); + assert(_ownerOf(tokenId) == from, 'Unauthorized caller'); + assert(to != '', 'Unauthorized to'); + _update(to, tokenId, from); +} + /** * TOD0: Implement the safeTransferFrom function. * To do so you need to verify that the recipient is a contract and supports the ERC721Receiver interface. diff --git a/smart-contracts/assembly/contracts/NFT/__tests__/NFT-example.spec.ts b/smart-contracts/assembly/contracts/NFT/__tests__/NFT-example.spec.ts index b1ed479..c2e20b3 100644 --- a/smart-contracts/assembly/contracts/NFT/__tests__/NFT-example.spec.ts +++ b/smart-contracts/assembly/contracts/NFT/__tests__/NFT-example.spec.ts @@ -50,10 +50,10 @@ beforeEach(() => { describe('Initialization', () => { test('get name', () => { - expect(name()).toBe(NFTName); + expect(bytesToString(name())).toStrictEqual(NFTName); }); test('get symbol', () => { - expect(symbol()).toBe(NFTSymbol); + expect(bytesToString(symbol())).toStrictEqual(NFTSymbol); }); test('get owner', () => { expect(bytesToString(ownerAddress([]))).toBe(contractOwner); From 395b37f21f601e54f9c689506f2bd5941f759f01 Mon Sep 17 00:00:00 2001 From: leoloco Date: Mon, 6 May 2024 16:33:22 +0200 Subject: [PATCH 2/2] Removed transfer function --- smart-contracts/assembly/contracts/NFT/NFT-internals.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/smart-contracts/assembly/contracts/NFT/NFT-internals.ts b/smart-contracts/assembly/contracts/NFT/NFT-internals.ts index a3c7bd6..8d068df 100644 --- a/smart-contracts/assembly/contracts/NFT/NFT-internals.ts +++ b/smart-contracts/assembly/contracts/NFT/NFT-internals.ts @@ -280,14 +280,6 @@ export function _transferFrom(from: string, to: string, tokenId: u256): void { _update(to, tokenId, from); } -export function _transfer(to: string, tokenId: u256): void { - assert(Storage.has(ownerKey(tokenId)), 'Nonexistent token'); - const from = Context.caller().toString(); - assert(_ownerOf(tokenId) == from, 'Unauthorized caller'); - assert(to != '', 'Unauthorized to'); - _update(to, tokenId, from); -} - /** * TOD0: Implement the safeTransferFrom function. * To do so you need to verify that the recipient is a contract and supports the ERC721Receiver interface.