Skip to content

Commit

Permalink
Refactor NFT contract ownership management and update constructor ini…
Browse files Browse the repository at this point in the history
…tialization
  • Loading branch information
Ben-Rey committed Dec 5, 2024
1 parent d08698b commit 78a3a82
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 142 deletions.
5 changes: 3 additions & 2 deletions smart-contracts/assembly/contracts/NFT/NFT-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ import {
_update,
_transferFrom,
} from './NFT-internals';
import { setOwner, onlyOwner } from '../utils/ownership';
import { onlyOwner } from '../utils/ownership';

import { Context, isDeployingContract } from '@massalabs/massa-as-sdk';
import { _setOwner } from '../utils/ownership-internal';

/**
* @param binaryArgs - serialized strings representing the name and the symbol of the NFT
Expand All @@ -52,7 +53,7 @@ export function constructor(binaryArgs: StaticArray<u8>): void {
.nextString()
.expect('symbol argument is missing or invalid');
_constructor(name, symbol);
setOwner(new Args().add(Context.caller().toString()).serialize());
_setOwner(Context.caller().toString());
}

export function name(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {

import {
Args,
NoArg,
byteToBool,
bytesToString,
bytesToU256,
stringToBytes,
} from '@massalabs/as-types';
import { u256 } from 'as-bignum/assembly';
import {
Expand Down Expand Up @@ -54,14 +56,14 @@ beforeEach(() => {
resetStorage();
switchUser(contractOwner);
setDeployContext(contractOwner);
constructor(new Args().add(NFTName).add(NFTSymbol).serialize());
constructor(NoArg.serialize());
});

describe('NFT Enumerable Contract', () => {
describe('Initialization', () => {
it('should return correct name and symbol', () => {
expect(name()).toBe(NFTName);
expect(symbol()).toBe(NFTSymbol);
expect(name()).toStrictEqual(stringToBytes(NFTName));
expect(symbol()).toStrictEqual(stringToBytes(NFTSymbol));
});
it('should return correct contract owner', () => {
expect(bytesToString(ownerAddress([]))).toBe(contractOwner);
Expand Down
137 changes: 0 additions & 137 deletions smart-contracts/assembly/contracts/NFT/y.ts

This file was deleted.

0 comments on commit 78a3a82

Please sign in to comment.