difftreelog
Combine refungible tests
in: master
9 files changed
tests/src/burnItem.test.tsdiffbeforeafterboth--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -45,32 +45,6 @@
await collection.burnTokens(alice, 1n);
expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);
});
-
- itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
- const collection = await helper.rft.mintCollection(alice);
- const token = await collection.mintToken(alice, 100n);
-
- await token.burn(alice, 90n);
- expect(await token.getBalance({Substrate: alice.address})).to.eq(10n);
-
- await token.burn(alice, 10n);
- expect(await token.getBalance({Substrate: alice.address})).to.eq(0n);
- });
-
- itSub.ifWithPallets('Burn owned portion of item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
- const collection = await helper.rft.mintCollection(alice);
- const token = await collection.mintToken(alice, 100n);
-
- await token.transfer(alice, {Substrate: bob.address}, 1n);
-
- expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);
- expect(await token.getBalance({Substrate: bob.address})).to.eq(1n);
-
- await token.burn(bob, 1n);
-
- expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);
- expect(await token.getBalance({Substrate: bob.address})).to.eq(0n);
- });
});
describe('integration test: ext. burnItem() with admin permissions:', () => {
@@ -104,16 +78,6 @@
await collection.burnTokensFrom(bob, {Substrate: alice.address}, 1n);
expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);
});
-
- itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
- const collection = await helper.rft.mintCollection(alice);
- await collection.setLimits(alice, {ownerCanTransfer: true});
- await collection.addAdmin(alice, {Substrate: bob.address});
- const token = await collection.mintToken(alice, 100n);
-
- await token.burnFrom(bob, {Substrate: alice.address}, 100n);
- expect(await token.doesExist()).to.be.false;
- });
});
describe('Negative integration test: ext. burnItem():', () => {
@@ -138,31 +102,6 @@
const token = await collection.mintToken(alice);
await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');
- });
-
- itSub.ifWithPallets('RFT: cannot burn non-owned token pieces', [Pallets.ReFungible], async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice);
- const aliceToken = await collection.mintToken(alice, 10n, {Substrate: alice.address});
- const bobToken = await collection.mintToken(alice, 10n, {Substrate: bob.address});
-
- // 1. Cannot burn non-owned token:
- await expect(bobToken.burn(alice, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
- await expect(bobToken.burn(alice, 5n)).to.be.rejectedWith('common.TokenValueTooLow');
- // 2. Cannot burn non-existing token:
- await expect(helper.rft.burnToken(alice, 99999, 10)).to.be.rejectedWith('common.CollectionNotFound');
- await expect(helper.rft.burnToken(alice, collection.collectionId, 99999)).to.be.rejectedWith('common.TokenValueTooLow');
- // 3. Can burn zero amount of owned tokens (EIP-20)
- await aliceToken.burn(alice, 0n);
-
- // 4. Storage is not corrupted:
- expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
- expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
-
- // 4.1 Tokens can be transfered:
- await aliceToken.transfer(alice, {Substrate: bob.address}, 10n);
- await bobToken.transfer(bob, {Substrate: alice.address}, 10n);
- expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
- expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
});
itSub('Transfer a burned token', async ({helper}) => {
tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -43,7 +43,7 @@
expect(events).to.be.deep.equal([
{
- address: COLLECTION_HELPER,
+ address: '0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F',
event: 'CollectionCreated',
args: {
owner: owner,
tests/src/nesting/nest.test.tsdiffbeforeafterboth--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import {expect, itSub, Pallets, usingPlaygrounds} from '../util';
+import {expect, itSub, usingPlaygrounds} from '../util';
describe('Integration Test: Composite nesting tests', () => {
let alice: IKeyringPair;
@@ -287,54 +287,7 @@
await collectionFT.mint(charlie, 5n);
await collectionFT.transfer(charlie, targetToken.nestingAccount(), 2n);
expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);
- });
-
- // ---------- Re-Fungible ----------
-
- itSub.ifWithPallets('ReFungible: allows an Owner to nest/unnest their token', [Pallets.ReFungible], async ({helper}) => {
- const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});
- const collectionRFT = await helper.rft.mintCollection(alice);
- const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
-
- await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
- await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
-
- await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});
- await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});
- await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());
-
- // Create an immediately nested token
- const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());
- expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
-
- // Create a token to be nested and nest
- const newToken = await collectionRFT.mintToken(charlie, 5n);
- await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);
- expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);
});
-
- itSub.ifWithPallets('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {
- const collectionNFT = await helper.nft.mintCollection(alice);
- const collectionRFT = await helper.rft.mintCollection(alice);
- const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
-
- await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionRFT.collectionId]}});
- await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
- await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
-
- await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});
- await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});
- await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());
-
- // Create an immediately nested token
- const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());
- expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
-
- // Create a token to be nested and nest
- const newToken = await collectionRFT.mintToken(charlie, 5n);
- await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);
- expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);
- });
});
describe('Negative Test: Nesting', () => {
@@ -579,89 +532,5 @@
expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);
- });
-
- // ---------- Re-Fungible ----------
-
- itSub.ifWithPallets('ReFungible: disallows to nest token if nesting is disabled', [Pallets.ReFungible], async ({helper}) => {
- const collectionNFT = await helper.nft.mintCollection(alice);
- const collectionRFT = await helper.rft.mintCollection(alice);
- const targetToken = await collectionNFT.mintToken(alice);
-
- // Try to create an immediately nested token
- await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
- .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
-
- // Try to create a token to be nested and nest
- const token = await collectionRFT.mintToken(alice, 5n);
- await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
- .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
- });
-
- itSub.ifWithPallets('ReFungible: disallows a non-Owner to nest someone else\'s token', [Pallets.ReFungible], async ({helper}) => {
- const collectionNFT = await helper.nft.mintCollection(alice);
- const collectionRFT = await helper.rft.mintCollection(alice);
- const targetToken = await collectionNFT.mintToken(alice);
-
- await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});
- await collectionNFT.addToAllowList(alice, {Substrate: bob.address});
- await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
-
- // Try to create a token to be nested and nest
- const newToken = await collectionRFT.mintToken(alice);
- await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);
-
- expect(await targetToken.getChildren()).to.be.length(0);
- expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);
-
- // Nest some tokens as Alice into Bob's token
- await newToken.transfer(alice, targetToken.nestingAccount());
-
- // Try to pull it out
- await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))
- .to.be.rejectedWith(/common\.ApprovedValueTooLow/);
- expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
- });
-
- itSub.ifWithPallets('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {
- const collectionNFT = await helper.nft.mintCollection(alice);
- const collectionRFT = await helper.rft.mintCollection(alice);
- const targetToken = await collectionNFT.mintToken(alice);
-
- await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: [collectionRFT.collectionId]}});
- await collectionNFT.addToAllowList(alice, {Substrate: bob.address});
- await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
-
- // Try to create a token to be nested and nest
- const newToken = await collectionRFT.mintToken(alice);
- await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);
-
- expect(await targetToken.getChildren()).to.be.length(0);
- expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);
-
- // Nest some tokens as Alice into Bob's token
- await newToken.transfer(alice, targetToken.nestingAccount());
-
- // Try to pull it out
- await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))
- .to.be.rejectedWith(/common\.ApprovedValueTooLow/);
- expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
- });
-
- itSub.ifWithPallets('ReFungible: disallows to nest token to an unlisted collection', [Pallets.ReFungible], async ({helper}) => {
- const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true, restricted: []}}});
- const collectionRFT = await helper.rft.mintCollection(alice);
- const targetToken = await collectionNFT.mintToken(alice);
-
- // Try to create an immediately nested token
- await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
- .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
-
- // Try to create a token to be nested and nest
- const token = await collectionRFT.mintToken(alice, 5n);
- await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
- .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
});
});
tests/src/nesting/unnest.test.tsdiffbeforeafterboth--- a/tests/src/nesting/unnest.test.ts
+++ b/tests/src/nesting/unnest.test.ts
@@ -63,26 +63,6 @@
expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
expect(await targetToken.getChildren()).to.be.length(0);
});
-
- itSub.ifWithPallets('ReFungible: allows the owner to successfully unnest a token', [Pallets.ReFungible], async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
- const targetToken = await collection.mintToken(alice);
-
- const collectionRFT = await helper.rft.mintCollection(alice);
-
- // Nest and unnest
- const token = await collectionRFT.mintToken(alice, 10n, targetToken.nestingAccount());
- await expect(token.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 9n), 'while unnesting').to.be.fulfilled;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(9n);
- expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
-
- // Nest and burn
- await token.transfer(alice, targetToken.nestingAccount(), 5n);
- await expect(token.burnFrom(alice, targetToken.nestingAccount(), 6n), 'while burning').to.be.fulfilled;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(4n);
- expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
- expect(await targetToken.getChildren()).to.be.length(0);
- });
});
describe('Negative Test: Unnesting', () => {
tests/src/refungible.test.tsdiffbeforeafterboth--- a/tests/src/refungible.test.ts
+++ b/tests/src/refungible.test.ts
@@ -88,20 +88,6 @@
expect((await token.getTop10Owners()).length).to.be.equal(10);
});
- itSub('Transfer token pieces', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
-
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
- expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
-
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
- expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
-
- await expect(token.transfer(alice, {Substrate: bob.address}, 41n))
- .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
- });
-
itSub('Create multiple tokens', async ({helper}) => {
const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
// TODO: fix mintMultipleTokens
@@ -118,56 +104,8 @@
const lastTokenId = await collection.getLastTokenId();
expect(lastTokenId).to.be.equal(3);
expect(await collection.getTokenBalance(lastTokenId, {Substrate: alice.address})).to.be.equal(100n);
- });
-
- itSub('Burn some pieces', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
- expect(await token.burn(alice, 99n)).to.be.true;
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);
});
- itSub('Burn all pieces', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
-
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
-
- expect(await token.burn(alice, 100n)).to.be.true;
- expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
- });
-
- itSub('Burn some pieces for multiple users', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
-
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
-
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
- expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
-
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
- expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
-
- expect(await token.burn(alice, 40n)).to.be.true;
-
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
-
- expect(await token.burn(bob, 59n)).to.be.true;
-
- expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
-
- expect(await token.burn(bob, 1n)).to.be.true;
-
- expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
- });
-
itSub('Set allowance for token', async ({helper}) => {
const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
const token = await collection.mintToken(alice, 100n);
@@ -183,68 +121,6 @@
expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);
});
- itSub('Repartition', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
-
- expect(await token.repartition(alice, 200n)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);
- expect(await token.getTotalPieces()).to.be.equal(200n);
-
- expect(await token.transfer(alice, {Substrate: bob.address}, 110n)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);
- expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);
-
- await expect(token.repartition(alice, 80n))
- .to.eventually.be.rejectedWith(/refungible\.RepartitionWhileNotOwningAllPieces/);
-
- expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
- expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);
-
- expect(await token.repartition(bob, 150n)).to.be.true;
- await expect(token.transfer(bob, {Substrate: alice.address}, 160n))
- .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
- });
-
- itSub('Repartition with increased amount', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
- await token.repartition(alice, 200n);
- const chainEvents = helper.chainLog.slice(-1)[0].events;
- const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemCreated');
- expect(event).to.deep.include({
- section: 'common',
- method: 'ItemCreated',
- index: [66, 2],
- data: [
- collection.collectionId,
- token.tokenId,
- {substrate: alice.address},
- 100n,
- ],
- });
- });
-
- itSub('Repartition with decreased amount', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
- await token.repartition(alice, 50n);
- const chainEvents = helper.chainLog.slice(-1)[0].events;
- const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemDestroyed');
- expect(event).to.deep.include({
- section: 'common',
- method: 'ItemDestroyed',
- index: [66, 3],
- data: [
- collection.collectionId,
- token.tokenId,
- {substrate: alice.address},
- 50n,
- ],
- });
- });
-
itSub('Create new collection with properties', async ({helper}) => {
const properties = [{key: 'key1', value: 'val1'}];
const tokenPropertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];
@@ -252,46 +128,5 @@
const info = await collection.getData();
expect(info?.raw.properties).to.be.deep.equal(properties);
expect(info?.raw.tokenPropertyPermissions).to.be.deep.equal(tokenPropertyPermissions);
- });
-});
-
-describe('Refungible negative tests', () => {
- let donor: IKeyringPair;
- let alice: IKeyringPair;
- let bob: IKeyringPair;
- let charlie: IKeyringPair;
-
- before(async function() {
- await usingPlaygrounds(async (helper, privateKey) => {
- requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
-
- donor = await privateKey({filename: __filename});
- [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
- });
- });
-
- itSub('Cannot transfer incorrect amount of token pieces', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const tokenAlice = await collection.mintToken(alice, 10n, {Substrate: alice.address});
- const tokenBob = await collection.mintToken(alice, 10n, {Substrate: bob.address});
-
- // 1. Alice cannot transfer Bob's token:
- await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
- await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
- await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejectedWith('common.TokenValueTooLow');
- await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');
-
- // 2. Alice cannot transfer non-existing token:
- await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
- await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
-
- // 3. Zero transfer allowed (EIP-20):
- await tokenAlice.transfer(alice, {Substrate: charlie.address}, 0n);
-
- expect(await tokenAlice.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
- expect(await tokenBob.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
- expect(await tokenAlice.getBalance({Substrate: alice.address})).to.eq(10n);
- expect(await tokenBob.getBalance({Substrate: bob.address})).to.eq(10n);
- expect(await tokenBob.getBalance({Substrate: charlie.address})).to.eq(0n);
});
});
tests/src/sub/refungible/burn.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/sub/refungible/burn.test.ts
@@ -0,0 +1,127 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '../../util';
+
+describe('Refungible: burn', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+ donor = await privateKey({filename: __filename});
+ [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);
+ });
+ });
+
+ itSub('can burn some pieces', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
+ await token.burn(alice, 99n);
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);
+ });
+
+ itSub('can burn all pieces', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
+
+ await token.burn(alice, 100n);
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
+ });
+
+ itSub('burn pieces for multiple users', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+
+ await token.transfer(alice, {Substrate: bob.address}, 60n);
+
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
+ expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
+
+ await token.burn(alice, 40n);
+
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
+
+ await token.burn(bob, 59n);
+
+ expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+
+ await token.burn(bob, 1n);
+
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
+ });
+
+ itSub('burn pieces by admin', async function({helper}) {
+ const collection = await helper.rft.mintCollection(alice);
+ await collection.setLimits(alice, {ownerCanTransfer: true});
+ await collection.addAdmin(alice, {Substrate: bob.address});
+ const token = await collection.mintToken(alice, 100n);
+
+ await token.burnFrom(bob, {Substrate: alice.address}, 100n);
+ expect(await token.doesExist()).to.be.false;
+ });
+});
+
+describe('Refungible: burn negative tests', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+ donor = await privateKey({filename: __filename});
+ [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
+ });
+ });
+
+ itSub('cannot burn non-owned token pieces', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice);
+ const aliceToken = await collection.mintToken(alice, 10n, {Substrate: alice.address});
+ const bobToken = await collection.mintToken(alice, 10n, {Substrate: bob.address});
+
+ // 1. Cannot burn non-owned token:
+ await expect(bobToken.burn(alice, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+ await expect(bobToken.burn(alice, 5n)).to.be.rejectedWith('common.TokenValueTooLow');
+ // 2. Cannot burn non-existing token:
+ await expect(helper.rft.burnToken(alice, 99999, 10)).to.be.rejectedWith('common.CollectionNotFound');
+ await expect(helper.rft.burnToken(alice, collection.collectionId, 99999)).to.be.rejectedWith('common.TokenValueTooLow');
+ // 3. Can burn zero amount of owned tokens (EIP-20)
+ await aliceToken.burn(alice, 0n);
+
+ // 4. Storage is not corrupted:
+ expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+ expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+
+ // 4.1 Tokens can be transfered:
+ await aliceToken.transfer(alice, {Substrate: bob.address}, 10n);
+ await bobToken.transfer(bob, {Substrate: alice.address}, 10n);
+ expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+ expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+ });
+});
tests/src/sub/refungible/nesting.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/sub/refungible/nesting.test.ts
@@ -0,0 +1,175 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from '../../util';
+
+describe('Refungible nesting', () => {
+ let alice: IKeyringPair;
+ let charlie: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+ const donor = await privateKey({filename: __filename});
+ [alice, charlie] = await helper.arrange.createAccounts([50n, 10n], donor);
+ });
+ });
+
+ [
+ {restrictedMode: true},
+ {restrictedMode: false},
+ ].map(testCase => {
+ itSub(`Owner can nest their token${testCase.restrictedMode ? ': Restricted mode' : ''}`, async ({helper}) => {
+ const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
+
+ await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionRFT.collectionId] : null}});
+ await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
+ await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
+
+ await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});
+ await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});
+ await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());
+
+ // Create an immediately nested token
+ const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());
+ expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
+
+ // Create a token to be nested and nest
+ const newToken = await collectionRFT.mintToken(charlie, 5n);
+ await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);
+ expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);
+ expect(await newToken.getBalance({Substrate: charlie.address})).to.be.equal(3n);
+ });
+ });
+
+ itSub('owner can unnest nested token', async ({helper}) => {
+ const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
+ const targetToken = await collection.mintToken(alice);
+
+ // Owner mints nested RFT token:
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const token = await collectionRFT.mintToken(alice, 10n, targetToken.nestingAccount());
+
+ // 1.1 Owner can partially unnest token pieces with transferFrom:
+ await token.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 9n);
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(9n);
+ expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
+
+ // 1.2 Owner can unnest all pieces:
+ await token.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 1n);
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(10n);
+ expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
+ });
+
+ itSub('owner can burn nested token', async ({helper}) => {
+ const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
+ const targetToken = await collection.mintToken(alice);
+
+ // Owner mints nested RFT token:
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const token = await collectionRFT.mintToken(alice, 10n, targetToken.nestingAccount());
+
+ // 1.1 Owner can partially burnFrom nested pieces:
+ await token.burnFrom(alice, targetToken.nestingAccount(), 6n);
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
+ expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(4n);
+ expect(await targetToken.getChildren()).to.has.length(1);
+
+ // 1.1 Owner can burnFrom all nested pieces:
+ await token.burnFrom(alice, targetToken.nestingAccount(), 4n);
+ expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
+ expect(await targetToken.getChildren()).to.has.length(0);
+ expect(await token.doesExist()).to.be.false;
+ });
+});
+
+describe('Refungible nesting negative tests', () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+ const donor = await privateKey({filename: __filename});
+ [alice, bob] = await helper.arrange.createAccounts([100n, 50n], donor);
+ });
+ });
+
+ itSub('cannot nest token if nesting is disabled', async ({helper}) => {
+ const collectionNFT = await helper.nft.mintCollection(alice);
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const targetToken = await collectionNFT.mintToken(alice);
+
+ // Try to create an immediately nested token
+ await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
+ .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
+
+ // Try to create a token to be nested and nest
+ const token = await collectionRFT.mintToken(alice, 5n);
+ await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
+ .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
+ });
+
+ [
+ {restrictedMode: true},
+ {restrictedMode: false},
+ ].map(testCase => {
+ itSub(`non-Owner cannot nest someone else's token${testCase.restrictedMode ? ': Restricted mode' : ''}`, async ({helper}) => {
+ const collectionNFT = await helper.nft.mintCollection(alice);
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const targetToken = await collectionNFT.mintToken(alice);
+
+ await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionRFT.collectionId] : null}});
+ await collectionNFT.addToAllowList(alice, {Substrate: bob.address});
+ await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
+
+ // Try to create a token to be nested and nest
+ const newToken = await collectionRFT.mintToken(alice);
+ await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);
+
+ expect(await targetToken.getChildren()).to.be.length(0);
+ expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);
+
+ // Nest some tokens as Alice into Bob's token
+ await newToken.transfer(alice, targetToken.nestingAccount());
+
+ // Try to pull it out
+ await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))
+ .to.be.rejectedWith(/common\.ApprovedValueTooLow/);
+ expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
+ });
+ });
+
+ itSub('ReFungible: disallows to nest token to an unlisted collection', async ({helper}) => {
+ const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true, restricted: []}}});
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const targetToken = await collectionNFT.mintToken(alice);
+
+ // Try to create an immediately nested token
+ await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
+ .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
+
+ // Try to create a token to be nested and nest
+ const token = await collectionRFT.mintToken(alice, 5n);
+ await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
+ .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
+ });
+});
tests/src/sub/refungible/repartition.test.tsdiffbeforeafterbothno changes
tests/src/sub/refungible/transfer.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/sub/refungible/transfer.test.ts
@@ -0,0 +1,73 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '../../util';
+
+describe('Refungible transfer tests', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+ donor = await privateKey({filename: __filename});
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ });
+ });
+
+ itSub('Can transfer token pieces', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+
+ expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
+ // 1. Can transfer less or equal than have:
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
+ expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
+ });
+
+ itSub('Cannot transfer incorrect amount of token pieces', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const tokenAlice = await collection.mintToken(alice, 10n, {Substrate: alice.address});
+ const tokenBob = await collection.mintToken(alice, 10n, {Substrate: bob.address});
+
+ // 1. Alice cannot transfer Bob's token:
+ await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+ await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
+ await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejectedWith('common.TokenValueTooLow');
+ await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');
+
+ // 2. Alice cannot transfer non-existing token:
+ await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+ await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
+
+ // 3. Cannot transfer more than have:
+ await expect(tokenAlice.transfer(alice, {Substrate: bob.address}, 11n))
+ .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
+
+ // 4. Zero transfer allowed (EIP-20):
+ await tokenAlice.transfer(alice, {Substrate: charlie.address}, 0n);
+
+ expect(await tokenAlice.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+ expect(await tokenBob.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+ expect(await tokenAlice.getBalance({Substrate: alice.address})).to.eq(10n);
+ expect(await tokenBob.getBalance({Substrate: bob.address})).to.eq(10n);
+ expect(await tokenBob.getBalance({Substrate: charlie.address})).to.eq(0n);
+ });
+});
\ No newline at end of file