Skip to content

Commit

Permalink
test: account token ownership transfer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksandre committed Jun 25, 2024
1 parent 79f3d06 commit 16b3e62
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions js-packages/tests/limits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from '@u

describe('Number of tokens per address (NFT)', () => {
let alice: IKeyringPair;
let bob: IKeyringPair;

before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
const donor = await privateKey({url: import.meta.url});
[alice] = await helper.arrange.createAccounts([10n], donor);
[alice, bob] = await helper.arrange.createAccounts([10n, 0n], donor);
});
});

Expand Down Expand Up @@ -51,17 +52,40 @@ describe('Number of tokens per address (NFT)', () => {
await collection.burnToken(alice, 1);
await expect(collection.burn(alice)).to.be.not.rejected;
});

itSub('Can transfer tokens to address equal to accountTokenOwnershipLimit', async ({helper}) => {
const collection = await helper.nft.mintCollection(alice, {});
await collection.setLimits(alice, {accountTokenOwnershipLimit: 1});

// Limit 1 - can transfer #1 token
const tkn1 = await collection.mintToken(alice);
await collection.transferToken(alice, tkn1.tokenId, {Substrate: bob.address});

// Limit 1 - cannot transfer #2 token
const tkn2 = await collection.mintToken(alice);
await expect(collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);

// Increase limit to 2
// Now can transfer token #2
await collection.setLimits(alice, {accountTokenOwnershipLimit: 2});
await collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address});

// But cannot transfer token #3
const tkn3 = await collection.mintToken(alice);
await expect(collection.transferToken(alice, tkn3.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);
});
});

describe('Number of tokens per address (ReFungible)', () => {
let alice: IKeyringPair;
let bob: IKeyringPair;

before(async function() {
await usingPlaygrounds(async (helper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);

const donor = await privateKey({url: import.meta.url});
[alice] = await helper.arrange.createAccounts([10n], donor);
[alice, bob] = await helper.arrange.createAccounts([10n, 0n], donor);
});
});

Expand Down Expand Up @@ -89,6 +113,28 @@ describe('Number of tokens per address (ReFungible)', () => {
await collection.burnToken(alice, 1);
await expect(collection.burn(alice)).to.be.not.rejected;
});

itSub('Can transfer tokens to address equal to accountTokenOwnershipLimit', async ({helper}) => {
const collection = await helper.rft.mintCollection(alice, {});
await collection.setLimits(alice, {accountTokenOwnershipLimit: 1});

// Limit 1 - can transfer #1 token
const tkn1 = await collection.mintToken(alice);
await collection.transferToken(alice, tkn1.tokenId, {Substrate: bob.address});

// Limit 1 - cannot transfer #2 token
const tkn2 = await collection.mintToken(alice);
await expect(collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);

// Increase limit to 2
// Now can transfer token #2
await collection.setLimits(alice, {accountTokenOwnershipLimit: 2});
await collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address});

// But cannot transfer token #3
const tkn3 = await collection.mintToken(alice);
await expect(collection.transferToken(alice, tkn3.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);
});
});

// todo:playgrounds skipped ~ postponed
Expand Down

0 comments on commit 16b3e62

Please sign in to comment.