From 609f299b52ae9b349f6175b2e642653ace7f62fc Mon Sep 17 00:00:00 2001 From: Senji888 <44082144+Ben-Rey@users.noreply.github.com> Date: Thu, 2 Nov 2023 10:39:54 +0100 Subject: [PATCH] Transform u256 to u64 in NFT --- .../assembly/contracts/NFT/NFT-internals.ts | 61 ++++++++-------- smart-contracts/assembly/contracts/NFT/NFT.ts | 62 ++++++++-------- .../assembly/contracts/NFT/NFTWrapper.ts | 27 ++++--- .../contracts/NFT/__tests__/NFT.spec.ts | 71 ++++++++++--------- .../contracts/NFT/__tests__/wrapper.spec.ts | 12 ++-- 5 files changed, 119 insertions(+), 114 deletions(-) diff --git a/smart-contracts/assembly/contracts/NFT/NFT-internals.ts b/smart-contracts/assembly/contracts/NFT/NFT-internals.ts index 4f871d94..ec77edc3 100644 --- a/smart-contracts/assembly/contracts/NFT/NFT-internals.ts +++ b/smart-contracts/assembly/contracts/NFT/NFT-internals.ts @@ -1,6 +1,6 @@ -import { stringToBytes, bytesToU256, u256ToBytes } from '@massalabs/as-types'; -import { Storage, Context } from '@massalabs/massa-as-sdk'; -import { u256 } from 'as-bignum/assembly'; +import { stringToBytes, bytesToU64, u64ToBytes } from '@massalabs/as-types'; +import { Storage, Context, validateAddress } from '@massalabs/massa-as-sdk'; + import { approvedForAllTokenKey, approvedTokenKey, @@ -14,9 +14,9 @@ import { * Increment the NFT counter */ export function _increment(): void { - const currentID = bytesToU256(Storage.get(counterKey)); - const newID = u256.add(currentID, u256.fromU32(1)); - Storage.set(counterKey, u256ToBytes(newID)); + const currentID = bytesToU64(Storage.get(counterKey)); + const newID = currentID + 1; + Storage.set(counterKey, u64ToBytes(newID)); } export function _updateBalanceOf(address: string, increment: boolean): void { @@ -24,21 +24,21 @@ export function _updateBalanceOf(address: string, increment: boolean): void { const number = increment ? 1 : -1; if (Storage.has(balanceKey)) { - const balance = bytesToU256(Storage.get(balanceKey)); - const newBalance = u256.add(balance, u256.fromI32(number)); - Storage.set(balanceKey, u256ToBytes(newBalance)); + const balance = bytesToU64(Storage.get(balanceKey)); + const newBalance = balance + number; + Storage.set(balanceKey, u64ToBytes(newBalance)); } else { assert(number == 1, 'Balance cannot be negative'); - Storage.set(balanceKey, u256ToBytes(new u256(1))); + Storage.set(balanceKey, u64ToBytes(1)); } } -export function _getBalanceOf(address: string): u256 { +export function _getBalanceOf(address: string): u64 { const balanceKey = stringToBytes('balanceOf_' + address); - if (!Storage.has(balanceKey)) return new u256(0); + if (!Storage.has(balanceKey)) return 0; - return bytesToU256(Storage.get(balanceKey)); + return bytesToU64(Storage.get(balanceKey)); } /** @@ -52,10 +52,10 @@ export function _onlyOwner(): bool { * @param tokenId - the tokenID * @returns true if the caller is token's owner */ -export function _isTokenOwner(address: string, tokenId: u256): bool { +export function _isTokenOwner(address: string, tokenId: u64): bool { // as we need to compare two byteArrays, we need to compare the pointers // we transform our byte array to their pointers and we compare them - const left = nft1_ownerOf(u256ToBytes(tokenId)); + const left = nft1_ownerOf(u64ToBytes(tokenId)); return ( memory.compare( changetype(left), @@ -69,16 +69,16 @@ export function _isTokenOwner(address: string, tokenId: u256): bool { * @param tokenId - the tokenID * @returns true if the token is minted */ -export function _onlyMinted(tokenId: u256): bool { +export function _onlyMinted(tokenId: u64): bool { return Storage.has(ownerTokenKey + tokenId.toString()); } /** * Internal function returning the currentSupply - * @returns u256 + * @returns u64 */ -export function _currentSupply(): u256 { - return bytesToU256(Storage.get(counterKey)); +export function _currentSupply(): u64 { + return bytesToU64(Storage.get(counterKey)); } // ==================================================== // @@ -89,7 +89,7 @@ export function _transfer( caller: string, owner: string, recipient: string, - tokenId: u256, + tokenId: u64, ): void { assertIsMinted(tokenId); assertIsOwner(owner, tokenId); @@ -115,7 +115,7 @@ export function _transfer( * @param tokenId - The token ID to approve */ export function _approve( - tokenId: u256, + tokenId: u64, owner: string, spenderAddress: string, ): void { @@ -131,20 +131,19 @@ export function _approve( * Removes the approval of the token * @param tokenId - the tokenID */ -function _removeApproval(id: u256): void { - const key = approvedTokenKey + id.toString(); +function _removeApproval(tokenId: u64): void { + const key = approvedTokenKey + tokenId.toString(); Storage.set(key, ''); } -export function _getApproved(tokenId: u256): string { +export function _getApproved(tokenId: u64): string { const key = approvedTokenKey + tokenId.toString(); - if (!Storage.has(key)) return ''; return Storage.get(key); } -export function _isApproved(address: string, tokenId: u256): bool { +export function _isApproved(address: string, tokenId: u64): bool { if (address.length === 0) return false; const approvedAddress = _getApproved(tokenId); return approvedAddress === address; @@ -176,18 +175,18 @@ export function _isApprovedForAll(owner: string, operator: string): bool { // ==== General Assertions ==== // // ==================================================== // -export function assertIsMinted(tokenId: u256): void { +export function assertIsMinted(tokenId: u64): void { assert(_onlyMinted(tokenId), `Token ${tokenId.toString()} is not minted`); } -export function assertIsOwner(address: string, tokenId: u256): void { +export function assertIsOwner(address: string, tokenId: u64): void { assert( _isTokenOwner(address, tokenId), `${address} is not the owner of ${tokenId.toString()}`, ); } -function assertIsApproved(owner: string, caller: string, tokenId: u256): void { +function assertIsApproved(owner: string, caller: string, tokenId: u64): void { assert( _isApproved(caller, tokenId) || _isApprovedForAll(owner, caller) || @@ -203,6 +202,10 @@ export function assertNotSelfTransfer(owner: string, recipient: string): void { ); } +export function assertAddressIsValid(address: string): void { + assert(validateAddress(address), 'Address is not valid'); +} + // ==================================================== // // ==== EVENTS ==== // // ==================================================== // diff --git a/smart-contracts/assembly/contracts/NFT/NFT.ts b/smart-contracts/assembly/contracts/NFT/NFT.ts index 5a42d4ba..b69a0e14 100644 --- a/smart-contracts/assembly/contracts/NFT/NFT.ts +++ b/smart-contracts/assembly/contracts/NFT/NFT.ts @@ -8,11 +8,10 @@ import { import { Args, stringToBytes, - bytesToU256, - u256ToBytes, + bytesToU64, u32ToBytes, + u64ToBytes, } from '@massalabs/as-types'; -import { u256 } from 'as-bignum/assembly'; import { assertIsMinted, _onlyOwner, @@ -38,7 +37,7 @@ export const counterKey = stringToBytes('Counter'); export const ownerTokenKey = 'ownerOf_'; export const approvedTokenKey = 'approved_'; export const approvedForAllTokenKey = 'approvedForAll_'; -export const initCounter = new u256(0); +export const initCounter = 0; /** * Initialize all the properties of the NFT (contract Owner, counter to 0...) @@ -59,13 +58,13 @@ export const initCounter = new u256(0); * new Args() * .add(NFTName) * .add(NFTSymbol) - * .add(u256(NFTtotalSupply)) + * .add(NFTtotalSupply) * .add(NFTBaseURI) * .serialize(), * ); * ``` * - * @param binaryArgs - arguments serialized with `Args` containing the name, the symbol, the totalSupply as u256, + * @param binaryArgs - arguments serialized with `Args` containing the name, the symbol, the totalSupply as u64, * the baseURI */ export function constructor(binaryArgs: StaticArray): void { @@ -79,7 +78,7 @@ export function constructor(binaryArgs: StaticArray): void { .nextString() .expect('symbol argument is missing or invalid'); const totalSupply = args - .nextU256() + .nextU64() .expect('totalSupply argument is missing or invalid'); const baseURI = args .nextString() @@ -87,10 +86,10 @@ export function constructor(binaryArgs: StaticArray): void { Storage.set(nameKey, name); Storage.set(symbolKey, symbol); - Storage.set(totalSupplyKey, u256ToBytes(totalSupply)); + Storage.set(totalSupplyKey, u64ToBytes(totalSupply)); Storage.set(baseURIKey, baseURI); Storage.set(ownerKey, Context.caller().toString()); - Storage.set(counterKey, u256ToBytes(initCounter)); + Storage.set(counterKey, u64ToBytes(initCounter)); } /** @@ -136,16 +135,18 @@ export function nft1_symbol( /** * Returns the token URI (external link written in NFT where pictures or others are stored) - * @param binaryArgs - u256 serialized tokenID with `Args` + * @param binaryArgs - u64 serialized tokenID with `Args` */ export function nft1_tokenURI(binaryArgs: StaticArray): StaticArray { const args = new Args(binaryArgs); const tokenId = args - .nextU256() + .nextU64() .expect('token id argument is missing or invalid') .toString(); - if (Storage.has(tokenURIKey + tokenId)) { - return stringToBytes(Storage.get(tokenURIKey + tokenId)); + + const key = tokenURIKey + tokenId; + if (Storage.has(key)) { + return stringToBytes(Storage.get(key)); } else { return stringToBytes(Storage.get(baseURIKey) + tokenId); } @@ -154,15 +155,17 @@ export function nft1_tokenURI(binaryArgs: StaticArray): StaticArray { /** * Set a token URI (external link written in NFT where pictures or others are stored). * If not set the tokenURI will be the baseURI + tokenId - * @param binaryArgs - u256 serialized tokenID with `Args` + URI string + * @param binaryArgs - u64 serialized tokenID with `Args` + URI string */ export function nft1_setTokenURI(binaryArgs: StaticArray): void { const args = new Args(binaryArgs); const tokenId = args - .nextU256() + .nextU64() .expect('token id argument is missing or invalid'); + assertIsMinted(tokenId); assertIsOwner(Context.caller().toString(), tokenId); + Storage.set( tokenURIKey + tokenId.toString(), args.nextString().expect('tokenURI argument is missing or invalid'), @@ -182,7 +185,7 @@ export function nft1_baseURI( /** * Returns the max supply possible * @param _ - unused see https://github.com/massalabs/massa-sc-std/issues/18 - * @returns the u256 max supply + * @returns the u64 max supply */ export function nft1_totalSupply( _: StaticArray = new StaticArray(0), @@ -193,7 +196,7 @@ export function nft1_totalSupply( /** * Return the current supply. * @param _ - unused see https://github.com/massalabs/massa-sc-std/issues/18 - * @returns the u256 current counter + * @returns the u64 current counter */ export function nft1_currentSupply( _: StaticArray = new StaticArray(0), @@ -203,13 +206,13 @@ export function nft1_currentSupply( /** * Return the tokenId's owner - * @param _args - tokenId serialized with `Args` as u256 + * @param _args - tokenId serialized with `Args` as u64 * @returns serialized Address as string */ export function nft1_ownerOf(_args: StaticArray): StaticArray { const args = new Args(_args); const tokenId = args - .nextU256() + .nextU64() .expect('tokenId argument is missing or invalid'); assertIsMinted(tokenId); @@ -222,7 +225,7 @@ export function nft1_ownerOf(_args: StaticArray): StaticArray { /** * Return the balance of the address * @param _args - Address serialized with `Args` - * @returns the balance as u256 + * @returns the balance as u64 * @throws if the address is invalid */ export function nft1_balanceOf(_args: StaticArray): StaticArray { @@ -231,7 +234,7 @@ export function nft1_balanceOf(_args: StaticArray): StaticArray { .nextString() .expect('address argument is missing or invalid'); - return u256ToBytes(_getBalanceOf(address)); + return u64ToBytes(_getBalanceOf(address)); } // ==================================================== // @@ -245,7 +248,7 @@ export function nft1_balanceOf(_args: StaticArray): StaticArray { */ export function nft1_mint(_args: StaticArray): void { assert( - bytesToU256(Storage.get(totalSupplyKey)) > _currentSupply(), + bytesToU64(Storage.get(totalSupplyKey)) > _currentSupply(), 'Max supply reached', ); @@ -255,7 +258,6 @@ export function nft1_mint(_args: StaticArray): void { .nextString() .expect('mintAddress argument is missing or invalid'); - // TODO: Check Address validity _increment(); const tokenToMint = _currentSupply().toString(); @@ -266,7 +268,7 @@ export function nft1_mint(_args: StaticArray): void { _updateBalanceOf(mintAddress, true); - generateEvent(createEvent('Mint', [tokenToMint, mintAddress])); + generateEvent(createEvent('Mint', [mintAddress])); } // ==================================================== // @@ -279,7 +281,7 @@ export function nft1_mint(_args: StaticArray): void { * @param binaryArgs - arguments serialized with `Args` containing the following data in this order : * - the owner's account (address) * - the recipient's account (address) - * - the tokenID (u256). + * - the tokenID (u64). * @throws if the token is not minted or if the caller is not allowed to transfer the token */ export function nft1_transferFrom(binaryArgs: StaticArray): void { @@ -292,7 +294,7 @@ export function nft1_transferFrom(binaryArgs: StaticArray): void { .nextString() .expect('toAddress argument is missing or invalid'); const tokenId = args - .nextU256() + .nextU64() .expect('tokenId argument is missing or invalid'); _transfer(caller, owner, recipient, tokenId); @@ -311,7 +313,7 @@ export function nft1_transferFrom(binaryArgs: StaticArray): void { * @param binaryArgs - arguments serialized with `Args` containing the following data in this order: * - the owner's - owner address * - the spenderAddress - spender address - * - the tokenID (u256) + * - the tokenID (U64) */ export function nft1_approve(binaryArgs: StaticArray): void { const args = new Args(binaryArgs); @@ -319,7 +321,7 @@ export function nft1_approve(binaryArgs: StaticArray): void { const callerAddress = Context.caller().toString(); const tokenId = args - .nextU256() + .nextU64() .expect('tokenId argument is missing or invalid'); const toAddress = new Address( @@ -341,13 +343,13 @@ export function nft1_approve(binaryArgs: StaticArray): void { * Return if the address is approved to transfer the tokenId * @param binaryArgs - arguments serialized with `Args` containing the following data in this order : * - the address (string) - * - the tokenID (u256) + * - the tokenID (U64) * @returns true if the address is approved to transfer the tokenId, false otherwise */ export function nft1_getApproved(binaryArgs: StaticArray): StaticArray { const args = new Args(binaryArgs); const tokenId = args - .nextU256() + .nextU64() .expect('tokenId argument is missing or invalid'); return stringToBytes(_getApproved(tokenId)); diff --git a/smart-contracts/assembly/contracts/NFT/NFTWrapper.ts b/smart-contracts/assembly/contracts/NFT/NFTWrapper.ts index 88f917a9..1a3b892b 100644 --- a/smart-contracts/assembly/contracts/NFT/NFTWrapper.ts +++ b/smart-contracts/assembly/contracts/NFT/NFTWrapper.ts @@ -3,10 +3,9 @@ import { Args, NoArg, bytesToString, - bytesToU256, + bytesToU64, bytesToU32, } from '@massalabs/as-types'; -import { u256 } from 'as-bignum/assembly'; /** * The Massa's standard NFT implementation wrapper. @@ -55,7 +54,7 @@ export class NFT1Wrapper { * Returns the token URI (external link written in NFT where pictures or others are stored) * @param tokenId - Token ID */ - tokenURI(tokenId: u256): string { + tokenURI(tokenId: u64): string { return bytesToString( call( this._origin, @@ -70,7 +69,7 @@ export class NFT1Wrapper { * Set a token URI (external link written in NFT where pictures or others are stored). * If not set the tokenURI will be the baseURI + tokenId */ - setTokenURI(tokenId: u256, tokenURI: string): void { + setTokenURI(tokenId: u64, tokenURI: string): void { call( this._origin, 'nft1_setTokenURI', @@ -91,8 +90,8 @@ export class NFT1Wrapper { /** * Returns the max supply */ - totalSupply(): u256 { - return bytesToU256( + totalSupply(): u64 { + return bytesToU64( call(this._origin, 'nft1_totalSupply', NoArg, Context.transferredCoins()), ); } @@ -100,8 +99,8 @@ export class NFT1Wrapper { /** * Returns the current counter, if 10 NFT minted, returns 10. */ - currentSupply(): u256 { - return bytesToU256( + currentSupply(): u64 { + return bytesToU64( call( this._origin, 'nft1_currentSupply', @@ -115,7 +114,7 @@ export class NFT1Wrapper { * Returns the owner of a tokenID * @param tokenId - Token ID */ - ownerOf(tokenId: u256): Address { + ownerOf(tokenId: u64): Address { return new Address( bytesToString( call( @@ -132,8 +131,8 @@ export class NFT1Wrapper { * Returns the balance of an address * @param address - address to check */ - balanceOf(address: string): u256 { - return bytesToU256( + balanceOf(address: string): u64 { + return bytesToU64( call( this._origin, 'nft1_balanceOf', @@ -168,7 +167,7 @@ export class NFT1Wrapper { * @remarks caller must be an approved address * */ - transferFrom(owner: string, recipient: string, tokenId: u256): void { + transferFrom(owner: string, recipient: string, tokenId: u64): void { call( this._origin, 'nft1_transferFrom', @@ -184,7 +183,7 @@ export class NFT1Wrapper { * @param address - address to approve * */ - approve(tokenId: u256, address: string): void { + approve(tokenId: u64, address: string): void { call( this._origin, 'nft1_approve', @@ -201,7 +200,7 @@ export class NFT1Wrapper { * @returns the approved address if there is one else '' * */ - getApproved(tokenId: u256): string { + getApproved(tokenId: u64): string { return bytesToString( call( this._origin, diff --git a/smart-contracts/assembly/contracts/NFT/__tests__/NFT.spec.ts b/smart-contracts/assembly/contracts/NFT/__tests__/NFT.spec.ts index 952ee62f..567389b6 100644 --- a/smart-contracts/assembly/contracts/NFT/__tests__/NFT.spec.ts +++ b/smart-contracts/assembly/contracts/NFT/__tests__/NFT.spec.ts @@ -7,10 +7,10 @@ import { Args, bytesToString, stringToBytes, - bytesToU256, - u256ToBytes, + bytesToU64, bytesToI32, bytesToU32, + u64ToBytes, } from '@massalabs/as-types'; import { constructor, @@ -31,14 +31,13 @@ import { nft1_setApprovalForAll, nft1_isApprovedForAll, } from '../NFT'; -import { u256 } from 'as-bignum/assembly'; const callerAddress = 'A12UBnqTHDQALpocVBnkPNy7y5CndUJQTLutaVDDFgMJcq5kQiKq'; const NFTName = 'MASSA_NFT'; const NFTSymbol = 'NFT'; const NFTBaseURI = 'my.massa/'; -const NFTtotalSupply: u256 = new u256(5); +const NFTtotalSupply: u64 = 5; describe('NFT contract', () => { beforeAll(() => { @@ -55,7 +54,7 @@ describe('NFT contract', () => { }); test('initialized', () => { - expect(bytesToU256(Storage.get(counterKey))).toBe(initCounter); + expect(bytesToU64(Storage.get(counterKey))).toBe(initCounter); }); test('get name', () => { @@ -65,42 +64,42 @@ describe('NFT contract', () => { expect(bytesToString(nft1_symbol())).toBe(NFTSymbol); }); test('totalSupply call', () => { - expect(bytesToU256(nft1_totalSupply())).toBe(NFTtotalSupply); + expect(bytesToU64(nft1_totalSupply())).toBe(NFTtotalSupply); }); test('get baseURI', () => { expect(bytesToString(nft1_baseURI())).toBe(NFTBaseURI); }); test('get current supply', () => { - expect(bytesToU256(nft1_currentSupply())).toBe(new u256(0)); + expect(bytesToU64(nft1_currentSupply())).toBe(0); }); test('get tokenURI', () => { - const tokenID = new u256(1); + const tokenID = 1; expect( - bytesToString(nft1_tokenURI(new Args().add(tokenID).serialize())), + bytesToString(nft1_tokenURI(new Args().add(tokenID).serialize())), ).toBe('my.massa/1'); }); test('set URI', () => { const newURI = 'my.newMassaURI/'; - const tokenID = new u256(1); + const tokenID = 1; nft1_setURI(new Args().add(newURI).serialize()); expect( - bytesToString(nft1_tokenURI(new Args().add(tokenID).serialize())), + bytesToString(nft1_tokenURI(new Args().add(tokenID).serialize())), ).toBe('my.newMassaURI/1'); }); test('mint call, ownerOf and currentSupply call', () => { - expect(bytesToU256(nft1_currentSupply())).toBe(u256.Zero); - for (let i: u64 = 0; i < NFTtotalSupply.toU64(); i++) { + expect(bytesToU64(nft1_currentSupply())).toBe(0); + for (let i: u64 = 0; i < NFTtotalSupply; i++) { nft1_mint(new Args().add(callerAddress).serialize()); } - expect(Storage.get(counterKey)).toStrictEqual(u256ToBytes(NFTtotalSupply)); - expect(bytesToU256(nft1_currentSupply())).toBe(NFTtotalSupply); - expect( - nft1_ownerOf(new Args().add(u256.fromU64(2)).serialize()), - ).toStrictEqual(stringToBytes(callerAddress)); + expect(Storage.get(counterKey)).toStrictEqual(u64ToBytes(NFTtotalSupply)); + expect(bytesToU64(nft1_currentSupply())).toBe(NFTtotalSupply); + expect(nft1_ownerOf(new Args().add(2).serialize())).toStrictEqual( + stringToBytes(callerAddress), + ); }); throws('we have reach max supply', () => { @@ -108,11 +107,11 @@ describe('NFT contract', () => { }); test('current supply call', () => { - expect(bytesToU256(nft1_currentSupply())).toBe(NFTtotalSupply); + expect(bytesToU64(nft1_currentSupply())).toBe(NFTtotalSupply); }); test('approval', () => { - const tokenId = new u256(1); + const tokenId = 1; let address = '2x'; approveAddress(tokenId, address); @@ -143,12 +142,12 @@ describe('NFT contract', () => { ).toBe(1); nft1_transferFrom( - new Args().add(callerAddress).add(recipient).add(new u256(1)).serialize(), + new Args().add(callerAddress).add(recipient).add(1).serialize(), ); - expect( - nft1_ownerOf(new Args().add(u256.fromU64(1)).serialize()), - ).toStrictEqual(stringToBytes(recipient)); + expect(nft1_ownerOf(new Args().add(1).serialize())).toStrictEqual( + stringToBytes(recipient), + ); expect( bytesToI32( @@ -160,7 +159,7 @@ describe('NFT contract', () => { }); test('transferFrom', () => { - const tokenId = new u256(3); + const tokenId = 3; let address = '2x'; let recipient = '3x'; @@ -171,32 +170,34 @@ describe('NFT contract', () => { expect(approvedAddress).toStrictEqual(address); nft1_transferFrom( - new Args().add(callerAddress).add(recipient).add(tokenId).serialize(), + new Args() + .add(callerAddress) + .add(recipient) + .add(tokenId) + .serialize(), ); expect(isAllowanceCleared(tokenId)).toBeTruthy(); - expect(nft1_ownerOf(u256ToBytes(tokenId))).toStrictEqual( + expect(nft1_ownerOf(u64ToBytes(tokenId))).toStrictEqual( stringToBytes(recipient), ); }); throws('transferFrom fail if not allowed', () => { - const tokenId = new u256(4); + const tokenId = 4; expect(getAllowedAddress(tokenId)).toStrictEqual(''); - expect(nft1_ownerOf(u256ToBytes(tokenId))).toStrictEqual( + expect(nft1_ownerOf(u64ToBytes(tokenId))).toStrictEqual( stringToBytes(callerAddress), ); - nft1_transferFrom( - new Args().add('2x').add('3x').add(new u256(4)).serialize(), - ); + nft1_transferFrom(new Args().add('2x').add('3x').add(4).serialize()); }); }); -function isAllowanceCleared(tokenId: u256): boolean { +function isAllowanceCleared(tokenId: u64): boolean { return getAllowedAddress(tokenId).length === 0; } -function getAllowedAddress(tokenId: u256): string { +function getAllowedAddress(tokenId: u64): string { const allowedAddress = bytesToString( nft1_getApproved(new Args().add(tokenId).serialize()), ); @@ -204,7 +205,7 @@ function getAllowedAddress(tokenId: u256): string { return allowedAddress; } -function approveAddress(tokenId: u256, address: string): void { +function approveAddress(tokenId: u64, address: string): void { const args = new Args().add(tokenId).add(address).serialize(); nft1_approve(args); } diff --git a/smart-contracts/assembly/contracts/NFT/__tests__/wrapper.spec.ts b/smart-contracts/assembly/contracts/NFT/__tests__/wrapper.spec.ts index 806882cf..8d0b612b 100644 --- a/smart-contracts/assembly/contracts/NFT/__tests__/wrapper.spec.ts +++ b/smart-contracts/assembly/contracts/NFT/__tests__/wrapper.spec.ts @@ -1,7 +1,7 @@ import { u256 } from 'as-bignum/assembly'; import { Address, mockScCall } from '@massalabs/massa-as-sdk'; import { NFT1Wrapper } from '../NFTWrapper'; -import { stringToBytes, u256ToBytes } from '@massalabs/as-types'; +import { stringToBytes, u64ToBytes } from '@massalabs/as-types'; describe('NFT wrapper', () => { test('demonstrative test', () => { @@ -19,18 +19,18 @@ describe('NFT wrapper', () => { mockScCall(stringToBytes('test.massa/')); NFT.baseURI(); mockScCall(stringToBytes('test.massa/2')); - NFT.tokenURI(u256.fromU64(2)); - mockScCall(u256ToBytes(u256.fromU64(3))); + NFT.tokenURI(2); + mockScCall(u64ToBytes(3)); NFT.totalSupply(); for (let i = 0; i < 3; i++) { mockScCall(stringToBytes('toto')); NFT.mint(myAddress.toString()); } - mockScCall(u256ToBytes(u256.fromU64(3))); + mockScCall(u64ToBytes(3)); NFT.currentSupply(); mockScCall(stringToBytes(myAddress.toString())); - NFT.ownerOf(u256.fromU64(1)); + NFT.ownerOf(1); mockScCall(stringToBytes(myAddress.toString())); - NFT.ownerOf(u256.fromU64(2)); + NFT.ownerOf(2); }); });