difftreelog
Add regungible burn test and fix fungible zero transfer test
in: master
2 files changed
tests/src/burnItem.test.tsdiffbeforeafterboth--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -140,6 +140,31 @@
await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');
});
+ itSub('RFT: 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}]);
+ });
+
itSub('Transfer a burned token', async ({helper}) => {
const collection = await helper.nft.mintCollection(alice);
const token = await collection.mintToken(alice);
tests/src/fungible.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect, requirePalletsOrSkip, Pallets} from './util';1920const U128_MAX = (1n << 128n) - 1n;2122describe('integration test: Fungible functionality:', () => {23 let donor: IKeyringPair;24 let alice: IKeyringPair;25 let bob: IKeyringPair;2627 before(async () => {28 await usingPlaygrounds(async (helper, privateKey) => {29 donor = await privateKey({filename: __filename});30 [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);31 });32 });3334 itSub('Create fungible collection and token', async ({helper}) => {35 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'trest'});36 const defaultTokenId = await collection.getLastTokenId();37 expect(defaultTokenId).to.be.equal(0);3839 await collection.mint(alice, U128_MAX);40 const aliceBalance = await collection.getBalance({Substrate: alice.address});41 const itemCountAfter = await collection.getLastTokenId();4243 expect(itemCountAfter).to.be.equal(defaultTokenId);44 expect(aliceBalance).to.be.equal(U128_MAX);45 });46 47 itSub('RPC method tokenOnewrs for fungible collection and token', async ({helper}) => {48 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};49 const facelessCrowd = (await helper.arrange.createAccounts(Array(7).fill(0n), donor)).map(keyring => {return {Substrate: keyring.address};});5051 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});5253 await collection.mint(alice, U128_MAX);5455 await collection.transfer(alice, {Substrate: bob.address}, 1000n);56 await collection.transfer(alice, ethAcc, 900n);57 58 for (let i = 0; i < 7; i++) {59 await collection.transfer(alice, facelessCrowd[i], 1n);60 } 6162 const owners = await collection.getTop10Owners();6364 // What to expect65 expect(owners).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);66 expect(owners.length).to.be.equal(10);67 68 const [eleven] = await helper.arrange.createAccounts([0n], donor);69 expect(await collection.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;70 expect((await collection.getTop10Owners()).length).to.be.equal(10);71 });72 73 itSub('Transfer token', async ({helper}) => {74 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};75 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});76 await collection.mint(alice, 500n);7778 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);79 expect(await collection.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;80 expect(await collection.transfer(alice, ethAcc, 140n)).to.be.true;8182 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(300n);83 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(60n);84 expect(await collection.getBalance(ethAcc)).to.be.equal(140n);8586 await expect(collection.transfer(alice, {Substrate: bob.address}, 350n)).to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);87 });8889 itSub('Tokens multiple creation', async ({helper}) => {90 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});9192 await collection.mintWithOneOwner(alice, [93 {value: 500n},94 {value: 400n},95 {value: 300n},96 ]);9798 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1200n);99 });100101 itSub('Burn some tokens ', async ({helper}) => {102 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});103 await collection.mint(alice, 500n);104105 expect(await collection.doesTokenExist(0)).to.be.true;106 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);107 expect(await collection.burnTokens(alice, 499n)).to.be.true;108 expect(await collection.doesTokenExist(0)).to.be.true;109 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);110 });111 112 itSub('Burn all tokens ', async ({helper}) => {113 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});114 await collection.mint(alice, 500n);115116 expect(await collection.doesTokenExist(0)).to.be.true;117 expect(await collection.burnTokens(alice, 500n)).to.be.true;118 expect(await collection.doesTokenExist(0)).to.be.true;119120 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(0n);121 expect(await collection.getTotalPieces()).to.be.equal(0n);122 });123124 itSub('Set allowance for token', async ({helper}) => {125 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});126 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};127 await collection.mint(alice, 100n);128129 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(100n);130 131 expect(await collection.approveTokens(alice, {Substrate: bob.address}, 60n)).to.be.true;132 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(60n);133 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(0n);134135 expect(await collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: bob.address}, 20n)).to.be.true;136 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(80n);137 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(20n);138 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);139140 await collection.burnTokensFrom(bob, {Substrate: alice.address}, 10n);141142 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(70n);143 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(30n);144 expect(await collection.transferFrom(bob, {Substrate: alice.address}, ethAcc, 10n)).to.be.true;145 expect(await collection.getBalance(ethAcc)).to.be.equal(10n);146 });147});148149describe('Fungible negative tests', () => {150 let donor: IKeyringPair;151 let alice: IKeyringPair;152 let bob: IKeyringPair;153 let charlie: IKeyringPair;154155 before(async function() {156 await usingPlaygrounds(async (helper, privateKey) => {157 requirePalletsOrSkip(this, helper, [Pallets.Fungible]);158159 donor = await privateKey({filename: __filename});160 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);161 });162 });163164 itSub('Cannot transfer incorrect amount of tokens', async ({helper}) => {165 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});166 const nonExistingCollection = helper.ft.getCollectionObject(99999);167 await collection.mint(alice, 10n, {Substrate: bob.address});168169 // 1. Alice cannot transfer Bob's token:170 await expect(collection.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');171 await expect(collection.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');172 await expect(collection.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejectedWith('common.TokenValueTooLow');173 await expect(collection.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');174 175 // 2. Alice cannot transfer non-existing token:176 await expect(nonExistingCollection.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.CollectionNotFound');177 await expect(nonExistingCollection.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.CollectionNotFound');178179 // 3. Zero transfer allowed (EIP-20):180 await collection.transfer(bob, {Substrate: charlie.address}, 0n);181182 expect(await collection.getBalance({Substrate: alice.address})).to.eq(0n);183 expect(await collection.getBalance({Substrate: bob.address})).to.eq(10n);184 expect(await collection.getBalance({Substrate: charlie.address})).to.eq(0n);185 });186});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect, requirePalletsOrSkip, Pallets} from './util';1920const U128_MAX = (1n << 128n) - 1n;2122describe('integration test: Fungible functionality:', () => {23 let donor: IKeyringPair;24 let alice: IKeyringPair;25 let bob: IKeyringPair;2627 before(async () => {28 await usingPlaygrounds(async (helper, privateKey) => {29 donor = await privateKey({filename: __filename});30 [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);31 });32 });3334 itSub('Create fungible collection and token', async ({helper}) => {35 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'trest'});36 const defaultTokenId = await collection.getLastTokenId();37 expect(defaultTokenId).to.be.equal(0);3839 await collection.mint(alice, U128_MAX);40 const aliceBalance = await collection.getBalance({Substrate: alice.address});41 const itemCountAfter = await collection.getLastTokenId();4243 expect(itemCountAfter).to.be.equal(defaultTokenId);44 expect(aliceBalance).to.be.equal(U128_MAX);45 });46 47 itSub('RPC method tokenOnewrs for fungible collection and token', async ({helper}) => {48 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};49 const facelessCrowd = (await helper.arrange.createAccounts(Array(7).fill(0n), donor)).map(keyring => {return {Substrate: keyring.address};});5051 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});5253 await collection.mint(alice, U128_MAX);5455 await collection.transfer(alice, {Substrate: bob.address}, 1000n);56 await collection.transfer(alice, ethAcc, 900n);57 58 for (let i = 0; i < 7; i++) {59 await collection.transfer(alice, facelessCrowd[i], 1n);60 } 6162 const owners = await collection.getTop10Owners();6364 // What to expect65 expect(owners).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);66 expect(owners.length).to.be.equal(10);67 68 const [eleven] = await helper.arrange.createAccounts([0n], donor);69 expect(await collection.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;70 expect((await collection.getTop10Owners()).length).to.be.equal(10);71 });72 73 itSub('Transfer token', async ({helper}) => {74 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};75 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});76 await collection.mint(alice, 500n);7778 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);79 expect(await collection.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;80 expect(await collection.transfer(alice, ethAcc, 140n)).to.be.true;8182 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(300n);83 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(60n);84 expect(await collection.getBalance(ethAcc)).to.be.equal(140n);8586 await expect(collection.transfer(alice, {Substrate: bob.address}, 350n)).to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);87 });8889 itSub('Tokens multiple creation', async ({helper}) => {90 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});9192 await collection.mintWithOneOwner(alice, [93 {value: 500n},94 {value: 400n},95 {value: 300n},96 ]);9798 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1200n);99 });100101 itSub('Burn some tokens ', async ({helper}) => {102 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});103 await collection.mint(alice, 500n);104105 expect(await collection.doesTokenExist(0)).to.be.true;106 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);107 expect(await collection.burnTokens(alice, 499n)).to.be.true;108 expect(await collection.doesTokenExist(0)).to.be.true;109 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);110 });111 112 itSub('Burn all tokens ', async ({helper}) => {113 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});114 await collection.mint(alice, 500n);115116 expect(await collection.doesTokenExist(0)).to.be.true;117 expect(await collection.burnTokens(alice, 500n)).to.be.true;118 expect(await collection.doesTokenExist(0)).to.be.true;119120 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(0n);121 expect(await collection.getTotalPieces()).to.be.equal(0n);122 });123124 itSub('Set allowance for token', async ({helper}) => {125 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});126 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};127 await collection.mint(alice, 100n);128129 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(100n);130 131 expect(await collection.approveTokens(alice, {Substrate: bob.address}, 60n)).to.be.true;132 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(60n);133 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(0n);134135 expect(await collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: bob.address}, 20n)).to.be.true;136 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(80n);137 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(20n);138 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);139140 await collection.burnTokensFrom(bob, {Substrate: alice.address}, 10n);141142 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(70n);143 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(30n);144 expect(await collection.transferFrom(bob, {Substrate: alice.address}, ethAcc, 10n)).to.be.true;145 expect(await collection.getBalance(ethAcc)).to.be.equal(10n);146 });147});148149describe('Fungible negative tests', () => {150 let donor: IKeyringPair;151 let alice: IKeyringPair;152 let bob: IKeyringPair;153 let charlie: IKeyringPair;154155 before(async function() {156 await usingPlaygrounds(async (helper, privateKey) => {157 requirePalletsOrSkip(this, helper, [Pallets.Fungible]);158159 donor = await privateKey({filename: __filename});160 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);161 });162 });163164 itSub('Cannot transfer incorrect amount of tokens', async ({helper}) => {165 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});166 const nonExistingCollection = helper.ft.getCollectionObject(99999);167 await collection.mint(alice, 10n, {Substrate: bob.address});168169 // 1. Alice cannot transfer more than 0 tokens if balance low:170 await expect(collection.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');171 await expect(collection.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');172 173 // 2. Alice cannot transfer non-existing token:174 await expect(nonExistingCollection.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.CollectionNotFound');175 await expect(nonExistingCollection.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.CollectionNotFound');176 177 // 3. Zero transfer allowed (EIP-20):178 await collection.transfer(bob, {Substrate: charlie.address}, 0n);179 // 3.1 even if the balance = 0180 await collection.transfer(alice, {Substrate: charlie.address}, 0n);181182 expect(await collection.getBalance({Substrate: alice.address})).to.eq(0n);183 expect(await collection.getBalance({Substrate: bob.address})).to.eq(10n);184 expect(await collection.getBalance({Substrate: charlie.address})).to.eq(0n);185 });186});