Skip to content

Commit

Permalink
add enumerable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjah committed Dec 6, 2024
1 parent 634813c commit 8386b95
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 64 deletions.
30 changes: 30 additions & 0 deletions smart-contract/assembly/__tests__/dns.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Args,
boolToByte,
bytesToU256,
nativeTypeArrayToBytes,
stringToBytes,
u256ToBytes,
} from '@massalabs/as-types';
Expand Down Expand Up @@ -37,8 +38,11 @@ import {
mockBalance,
mockTransferredCoins,
resetStorage,
getKeys,
} from '@massalabs/massa-as-sdk';
import { u256 } from 'as-bignum/assembly';
// eslint-disable-next-line max-len
import { OWNED_TOKENS_KEY } from '@massalabs/sc-standards/assembly/contracts/MRC721/enumerable/MRC721Enumerable-internals';

const defaultOwner = 'AU12UBnqTHDQALpocVBnkPNy7y5CndUJQTLutaVDDFgMJcq5kQiKq';
const owner = 'AU122Em8qkqegdLb1eyH8rdkSCNEf7RZLeTJve4Q2inRPGiTJ2xNv';
Expand Down Expand Up @@ -76,7 +80,18 @@ describe('Test DNS allocation', () => {
args.add(domain);
args.add(target);

// check no tokens are owned by defaultOwner
let keys = getKeys(OWNED_TOKENS_KEY.concat(stringToBytes(defaultOwner)));
expect(keys.length).toStrictEqual(0);

expect(dnsAlloc(args.serialize())).toStrictEqual(u256ToBytes(u256.Zero));

// check owned
const filter = OWNED_TOKENS_KEY.concat(stringToBytes(defaultOwner));
keys = getKeys(filter);
expect(keys.length).toStrictEqual(1);
const tokenId = nativeTypeArrayToBytes(keys[0].slice(filter.length));
expect(tokenId).toStrictEqual(u256ToBytes(u256.Zero));
});
test('Testing multiple alloc', () => {
let argsCost = new Args();
Expand All @@ -88,13 +103,28 @@ describe('Test DNS allocation', () => {
args.add(domain);
args.add(target);
expect(dnsAlloc(args.serialize())).toStrictEqual(u256ToBytes(u256.Zero));

// check owned
let filter = OWNED_TOKENS_KEY.concat(stringToBytes(owner));
let keys = getKeys(filter);
expect(keys.length).toStrictEqual(1);
const tokenId1 = nativeTypeArrayToBytes(keys[0].slice(filter.length));
expect(tokenId1).toStrictEqual(u256ToBytes(u256.Zero));

mockBalance(owner, transferredAmount);
mockTransferredCoins(transferredAmount);
mockBalance(scAddress, transferredAmount);
let args2 = new Args();
args2.add('test29087890');
args2.add(target);
expect(dnsAlloc(args2.serialize())).toStrictEqual(u256ToBytes(u256.One));

// check owned
filter = OWNED_TOKENS_KEY.concat(stringToBytes(owner));
keys = getKeys(filter);
expect(keys.length).toStrictEqual(2);
const tokenId2 = nativeTypeArrayToBytes(keys[1].slice(filter.length));
expect(tokenId2).toStrictEqual(u256ToBytes(u256.One));
});
throws('No funds sent', () => {
let args = new Args();
Expand Down
Loading

0 comments on commit 8386b95

Please sign in to comment.