difftreelog
Merge pull request #567 from UniqueNetwork/test/playground-migration
in: master
Test/playground migration
5 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -49,6 +49,7 @@
"testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",
"testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",
"testRemoveFromAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromAllowList.test.ts",
+ "testAllowLists": "mocha --timeout 9999999 -r ts-node/register ./**/allowLists.test.ts",
"testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
"testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",
"testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",
tests/src/adminTransferAndBurn.test.tsdiffbeforeafterboth--- a/tests/src/adminTransferAndBurn.test.ts
+++ b/tests/src/adminTransferAndBurn.test.ts
@@ -17,56 +17,63 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import {default as usingApi} from './substrate/substrate-api';
-import {
- createCollectionExpectSuccess,
- createItemExpectSuccess,
- transferExpectFailure,
- transferFromExpectSuccess,
- burnItemExpectFailure,
- burnFromExpectSuccess,
- setCollectionLimitsExpectSuccess,
-} from './util/helpers';
+import {usingPlaygrounds} from './util/playgrounds';
chai.use(chaiAsPromised);
const expect = chai.expect;
+let donor: IKeyringPair;
+
+before(async () => {
+ await usingPlaygrounds(async (_, privateKey) => {
+ donor = privateKey('//Alice');
+ });
+});
+
describe('Integration Test: ownerCanTransfer allows admins to use only transferFrom/burnFrom:', () => {
let alice: IKeyringPair;
let bob: IKeyringPair;
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- charlie = privateKeyWrapper('//Charlie');
+ await usingPlaygrounds(async (helper) => {
+ [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);
});
});
it('admin transfers other user\'s token', async () => {
- await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess();
- await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
-
- const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', {Substrate: bob.address});
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});
+ await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});
+ const limits = await helper.collection.getEffectiveLimits(collectionId);
+ expect(limits.ownerCanTransfer).to.be.true;
- await transferExpectFailure(collectionId, tokenId, alice, charlie);
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
+ const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
+ await expect(transferResult()).to.be.rejected;
- await transferFromExpectSuccess(collectionId, tokenId, alice, bob, charlie, 1);
+ await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address});
+ const newTokenOwner = await helper.nft.getTokenOwner(collectionId, tokenId);
+ expect(newTokenOwner.Substrate).to.be.equal(charlie.address);
});
});
it('admin burns other user\'s token', async () => {
- await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess();
- await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});
+
+ await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});
+ const limits = await helper.collection.getEffectiveLimits(collectionId);
+ expect(limits.ownerCanTransfer).to.be.true;
- const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', {Substrate: bob.address});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
+ const burnTxFailed = async () => helper.nft.burnToken(alice, collectionId, tokenId);
- await burnItemExpectFailure(alice, collectionId, tokenId);
+ await expect(burnTxFailed()).to.be.rejected;
- await burnFromExpectSuccess(alice, bob, collectionId, tokenId);
+ await helper.nft.burnToken(bob, collectionId, tokenId);
+ const token = await helper.nft.getToken(collectionId, tokenId);
+ expect(token).to.be.null;
});
});
});
tests/src/allowLists.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 chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';21import {22 addToAllowListExpectSuccess,23 createCollectionExpectSuccess,24 createItemExpectSuccess,25 destroyCollectionExpectSuccess,26 enableAllowListExpectSuccess,27 normalizeAccountId,28 addCollectionAdminExpectSuccess,29 addToAllowListExpectFail,30 removeFromAllowListExpectSuccess,31 removeFromAllowListExpectFailure,32 addToAllowListAgainExpectSuccess,33 transferExpectFailure,34 approveExpectSuccess,35 approveExpectFail,36 transferExpectSuccess,37 transferFromExpectSuccess,38 setMintPermissionExpectSuccess,39 createItemExpectFailure,40} from './util/helpers';4142chai.use(chaiAsPromised);43const expect = chai.expect;4445let alice: IKeyringPair;46let bob: IKeyringPair;47let charlie: IKeyringPair;4849describe('Integration Test ext. Allow list tests', () => {5051 before(async () => {52 await usingApi(async (api, privateKeyWrapper) => {53 alice = privateKeyWrapper('//Alice');54 bob = privateKeyWrapper('//Bob');55 charlie = privateKeyWrapper('//Charlie');56 });57 });5859 it('Owner can add address to allow list', async () => {60 const collectionId = await createCollectionExpectSuccess();61 await addToAllowListExpectSuccess(alice, collectionId, bob.address);62 });6364 it('Admin can add address to allow list', async () => {65 const collectionId = await createCollectionExpectSuccess();66 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);67 await addToAllowListExpectSuccess(bob, collectionId, charlie.address);68 });6970 it('Non-privileged user cannot add address to allow list', async () => {71 const collectionId = await createCollectionExpectSuccess();72 await addToAllowListExpectFail(bob, collectionId, charlie.address);73 });7475 it('Nobody can add address to allow list of non-existing collection', async () => {76 const collectionId = (1<<32) - 1;77 await addToAllowListExpectFail(alice, collectionId, bob.address);78 });7980 it('Nobody can add address to allow list of destroyed collection', async () => {81 const collectionId = await createCollectionExpectSuccess();82 await destroyCollectionExpectSuccess(collectionId, '//Alice');83 await addToAllowListExpectFail(alice, collectionId, bob.address);84 });8586 it('If address is already added to allow list, nothing happens', async () => {87 const collectionId = await createCollectionExpectSuccess();88 await addToAllowListExpectSuccess(alice, collectionId, bob.address);89 await addToAllowListAgainExpectSuccess(alice, collectionId, bob.address);90 });9192 it('Owner can remove address from allow list', async () => {93 const collectionId = await createCollectionExpectSuccess();94 await addToAllowListExpectSuccess(alice, collectionId, bob.address);95 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob));96 });9798 it('Admin can remove address from allow list', async () => {99 const collectionId = await createCollectionExpectSuccess();100 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);101 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);102 await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie));103 });104105 it('Non-privileged user cannot remove address from allow list', async () => {106 const collectionId = await createCollectionExpectSuccess();107 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);108 await removeFromAllowListExpectFailure(bob, collectionId, normalizeAccountId(charlie));109 });110111 it('Nobody can remove address from allow list of non-existing collection', async () => {112 const collectionId = (1<<32) - 1;113 await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));114 });115116 it('Nobody can remove address from allow list of deleted collection', async () => {117 const collectionId = await createCollectionExpectSuccess();118 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);119 await destroyCollectionExpectSuccess(collectionId, '//Alice');120 await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));121 });122123 it('If address is already removed from allow list, nothing happens', async () => {124 const collectionId = await createCollectionExpectSuccess();125 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);126 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));127 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));128 });129130 it('If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom. Test1', async () => {131 const collectionId = await createCollectionExpectSuccess();132 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);133 await enableAllowListExpectSuccess(alice, collectionId);134 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);135136 await transferExpectFailure(137 collectionId,138 itemId,139 alice,140 charlie,141 1,142 );143 });144145 it('If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom. Test2', async () => {146 const collectionId = await createCollectionExpectSuccess();147 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);148 await enableAllowListExpectSuccess(alice, collectionId);149 await addToAllowListExpectSuccess(alice, collectionId, alice.address);150 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);151 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);152 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));153154 await transferExpectFailure(155 collectionId,156 itemId,157 alice,158 charlie,159 1,160 );161 });162163 it('If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom. Test1', async () => {164 const collectionId = await createCollectionExpectSuccess();165 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);166 await enableAllowListExpectSuccess(alice, collectionId);167 await addToAllowListExpectSuccess(alice, collectionId, alice.address);168169 await transferExpectFailure(170 collectionId,171 itemId,172 alice,173 charlie,174 1,175 );176 });177178 it('If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom. Test2', async () => {179 const collectionId = await createCollectionExpectSuccess();180 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);181 await enableAllowListExpectSuccess(alice, collectionId);182 await addToAllowListExpectSuccess(alice, collectionId, alice.address);183 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);184 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);185 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));186187 await transferExpectFailure(188 collectionId,189 itemId,190 alice,191 charlie,192 1,193 );194 });195196 it('If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if it owned them before enabling AllowList mode)', async () => {197 const collectionId = await createCollectionExpectSuccess();198 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);199 await enableAllowListExpectSuccess(alice, collectionId);200201 await usingApi(async (api) => {202 const tx = api.tx.unique.burnItem(collectionId, itemId, /*normalizeAccountId(Alice.address),*/ 11);203 const badTransaction = async function () {204 await submitTransactionExpectFailAsync(alice, tx);205 };206 await expect(badTransaction()).to.be.rejected;207 });208 });209210 it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {211 const collectionId = await createCollectionExpectSuccess();212 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);213 await enableAllowListExpectSuccess(alice, collectionId);214 await approveExpectFail(collectionId, itemId, alice, bob);215 });216217 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => {218 const collectionId = await createCollectionExpectSuccess();219 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);220 await enableAllowListExpectSuccess(alice, collectionId);221 await addToAllowListExpectSuccess(alice, collectionId, alice.address);222 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);223 await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');224 });225226 it('If Public Access mode is set to AllowList, tokens can be transferred to a alowlisted address with transferFrom.', async () => {227 const collectionId = await createCollectionExpectSuccess();228 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);229 await enableAllowListExpectSuccess(alice, collectionId);230 await addToAllowListExpectSuccess(alice, collectionId, alice.address);231 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);232 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);233 await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');234 });235236 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {237 const collectionId = await createCollectionExpectSuccess();238 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);239 await enableAllowListExpectSuccess(alice, collectionId);240 await addToAllowListExpectSuccess(alice, collectionId, alice.address);241 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);242 await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');243 });244245 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {246 const collectionId = await createCollectionExpectSuccess();247 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);248 await enableAllowListExpectSuccess(alice, collectionId);249 await addToAllowListExpectSuccess(alice, collectionId, alice.address);250 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);251 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);252 await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');253 });254255 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {256 const collectionId = await createCollectionExpectSuccess();257 await enableAllowListExpectSuccess(alice, collectionId);258 await setMintPermissionExpectSuccess(alice, collectionId, false);259 await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);260 });261262 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {263 const collectionId = await createCollectionExpectSuccess();264 await enableAllowListExpectSuccess(alice, collectionId);265 await setMintPermissionExpectSuccess(alice, collectionId, false);266 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);267 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);268 });269270 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and allow-listed address', async () => {271 const collectionId = await createCollectionExpectSuccess();272 await enableAllowListExpectSuccess(alice, collectionId);273 await setMintPermissionExpectSuccess(alice, collectionId, false);274 await addToAllowListExpectSuccess(alice, collectionId, bob.address);275 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);276 });277278 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-allow listed address', async () => {279 const collectionId = await createCollectionExpectSuccess();280 await enableAllowListExpectSuccess(alice, collectionId);281 await setMintPermissionExpectSuccess(alice, collectionId, false);282 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);283 });284285 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {286 const collectionId = await createCollectionExpectSuccess();287 await enableAllowListExpectSuccess(alice, collectionId);288 await setMintPermissionExpectSuccess(alice, collectionId, true);289 await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);290 });291292 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {293 const collectionId = await createCollectionExpectSuccess();294 await enableAllowListExpectSuccess(alice, collectionId);295 await setMintPermissionExpectSuccess(alice, collectionId, true);296 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);297 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);298 });299300 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-allow listed address', async () => {301 const collectionId = await createCollectionExpectSuccess();302 await enableAllowListExpectSuccess(alice, collectionId);303 await setMintPermissionExpectSuccess(alice, collectionId, true);304 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);305 });306307 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address', async () => {308 const collectionId = await createCollectionExpectSuccess();309 await enableAllowListExpectSuccess(alice, collectionId);310 await setMintPermissionExpectSuccess(alice, collectionId, true);311 await addToAllowListExpectSuccess(alice, collectionId, bob.address);312 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);313 });314});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 chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import {usingPlaygrounds} from './util/playgrounds';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425let donor: IKeyringPair;2627before(async () => {28 await usingPlaygrounds(async (_, privateKey) => {29 donor = privateKey('//Alice');30 });31});3233let alice: IKeyringPair;34let bob: IKeyringPair;35let charlie: IKeyringPair;3637describe('Integration Test ext. Allow list tests', () => {3839 before(async () => {40 await usingPlaygrounds(async (helper) => {41 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);42 });43 });4445 it('Owner can add address to allow list', async () => {46 await usingPlaygrounds(async (helper) => {47 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});48 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});49 const allowList = await helper.nft.getAllowList(collectionId);50 expect(allowList).to.be.deep.contains({Substrate: bob.address});51 });52 });5354 it('Admin can add address to allow list', async () => {55 await usingPlaygrounds(async (helper) => {56 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});57 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});5859 await helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});60 const allowList = await helper.nft.getAllowList(collectionId);61 expect(allowList).to.be.deep.contains({Substrate: charlie.address});62 });63 });6465 it('Non-privileged user cannot add address to allow list', async () => {66 await usingPlaygrounds(async (helper) => {67 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});68 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});69 await expect(addToAllowListTx()).to.be.rejected;70 });71 });7273 it('Nobody can add address to allow list of non-existing collection', async () => {74 const collectionId = (1<<32) - 1;75 await usingPlaygrounds(async (helper) => {76 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});77 await expect(addToAllowListTx()).to.be.rejected;78 });79 });8081 it('Nobody can add address to allow list of destroyed collection', async () => {82 await usingPlaygrounds(async (helper) => {83 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});84 await helper.collection.burn(alice, collectionId);85 const addToAllowListTx = async () => helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});86 await expect(addToAllowListTx()).to.be.rejected;87 });88 });8990 it('If address is already added to allow list, nothing happens', async () => {91 await usingPlaygrounds(async (helper) => {92 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});93 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});94 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});95 const allowList = await helper.nft.getAllowList(collectionId);96 expect(allowList).to.be.deep.contains({Substrate: bob.address});97 });98 });99100 it('Owner can remove address from allow list', async () => {101 await usingPlaygrounds(async (helper) => {102 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});103 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});104105 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});106107 const allowList = await helper.nft.getAllowList(collectionId);108109 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});110 });111 });112113 it('Admin can remove address from allow list', async () => {114 await usingPlaygrounds(async (helper) => {115 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});116 await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address});117 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});118 await helper.collection.removeFromAllowList(charlie, collectionId, {Substrate: bob.address});119120 const allowList = await helper.nft.getAllowList(collectionId);121122 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});123 });124 });125126 it('Non-privileged user cannot remove address from allow list', async () => {127 await usingPlaygrounds(async (helper) => {128 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});129 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});130 const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});131 await expect(removeTx()).to.be.rejected;132 const allowList = await helper.nft.getAllowList(collectionId);133134 expect(allowList).to.be.deep.contains({Substrate: charlie.address});135 });136 });137138 it('Nobody can remove address from allow list of non-existing collection', async () => {139 const collectionId = (1<<32) - 1;140 await usingPlaygrounds(async (helper) => {141 const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});142 await expect(removeTx()).to.be.rejected;143 });144 });145146 it('Nobody can remove address from allow list of deleted collection', async () => {147 await usingPlaygrounds(async (helper) => {148 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});149 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});150 await helper.collection.burn(alice, collectionId);151 const removeTx = async () => helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});152153 await expect(removeTx()).to.be.rejected;154 });155 });156157 it('If address is already removed from allow list, nothing happens', async () => {158 await usingPlaygrounds(async (helper) => {159 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});160 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});161 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});162 const allowListBefore = await helper.nft.getAllowList(collectionId);163 expect(allowListBefore).to.be.not.deep.contains({Substrate: bob.address});164165 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});166167 const allowListAfter = await helper.nft.getAllowList(collectionId);168 expect(allowListAfter).to.be.not.deep.contains({Substrate: bob.address});169 });170 });171172 it('If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom. Test1', async () => {173 await usingPlaygrounds(async (helper) => {174 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});175 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});176 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});177 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});178179 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});180 await expect(transferResult()).to.be.rejected;181 });182 });183184 it('If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom. Test2', async () => {185 await usingPlaygrounds(async (helper) => {186 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});187 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});188 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});189 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});190 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});191 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});192 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});193194 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});195 await expect(transferResult()).to.be.rejected;196 });197 });198199 it('If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom. Test1', async () => {200 await usingPlaygrounds(async (helper) => {201 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});202 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});203 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});204 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});205206 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});207 await expect(transferResult()).to.be.rejected;208 });209 });210211 it('If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom. Test2', async () => {212 await usingPlaygrounds(async (helper) => {213 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});214 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});215 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});216 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});217 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});218219 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});220 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});221222 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});223 await expect(transferResult()).to.be.rejected;224 });225 });226227 it('If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if it owned them before enabling AllowList mode)', async () => {228 await usingPlaygrounds(async (helper) => {229 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});230 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});231 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});232 const burnTx = async () => helper.nft.burnToken(bob, collectionId, tokenId);233 await expect(burnTx()).to.be.rejected;234 });235 });236237 it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {238 await usingPlaygrounds(async (helper) => {239 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});240 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});241 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});242 const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});243 await expect(approveTx()).to.be.rejected;244 });245 });246247 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => {248 await usingPlaygrounds(async (helper) => {249 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});250 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});251 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});252 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});253 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});254 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});255 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);256 expect(owner.Substrate).to.be.equal(charlie.address);257 });258 });259260 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transferFrom.', async () => {261 await usingPlaygrounds(async (helper) => {262 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});263 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});264 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});265 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});266 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});267 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});268269 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});270 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);271 expect(owner.Substrate).to.be.equal(charlie.address);272 });273 });274275 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {276 await usingPlaygrounds(async (helper) => {277 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});278 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});279 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});280 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});281 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});282283 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});284 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);285 expect(owner.Substrate).to.be.equal(charlie.address);286 });287 });288289 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {290 await usingPlaygrounds(async (helper) => {291 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});292 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});293 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});294 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});295 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});296 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});297298 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});299 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);300 expect(owner.Substrate).to.be.equal(charlie.address);301 });302 });303304 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {305 await usingPlaygrounds(async (helper) => {306 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});307 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});308 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});309 const token = await helper.nft.getToken(collectionId, tokenId);310 expect(token).to.be.not.null;311 });312 });313314 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {315 await usingPlaygrounds(async (helper) => {316 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});317 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});318 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});319 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});320 const token = await helper.nft.getToken(collectionId, tokenId);321 expect(token).to.be.not.null;322 });323 });324325 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and allow-listed address', async () => {326 await usingPlaygrounds(async (helper) => {327 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});328 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});329 await helper.collection.addToAllowList(alice, collectionId, {Substrate: bob.address});330 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});331 await expect(mintTokenTx()).to.be.rejected;332 });333 });334335 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-allow listed address', async () => {336 await usingPlaygrounds(async (helper) => {337 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});338 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});339 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});340 await expect(mintTokenTx()).to.be.rejected;341 });342 });343344 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {345 await usingPlaygrounds(async (helper) => {346 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});347 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});348 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});349 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);350 expect(owner.Substrate).to.be.equal(alice.address);351 });352 });353354 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {355 await usingPlaygrounds(async (helper) => {356 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});357 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});358 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});359 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});360 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);361 expect(owner.Substrate).to.be.equal(bob.address);362 });363 });364365 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-allow listed address', async () => {366 await usingPlaygrounds(async (helper) => {367 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});368 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});369 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});370 await expect(mintTokenTx()).to.be.rejected;371 });372 });373374 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address', async () => {375 await usingPlaygrounds(async (helper) => {376 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});377 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});378 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});379 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});380 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);381 expect(owner.Substrate).to.be.equal(bob.address);382 });383 });384});tests/src/approve.test.tsdiffbeforeafterboth--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -15,28 +15,26 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import {ApiPromise} from '@polkadot/api';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import {default as usingApi} from './substrate/substrate-api';
import {
approveExpectFail,
approveExpectSuccess,
createCollectionExpectSuccess,
createItemExpectSuccess,
- destroyCollectionExpectSuccess,
- setCollectionLimitsExpectSuccess,
- transferExpectSuccess,
- addCollectionAdminExpectSuccess,
- adminApproveFromExpectFail,
- getCreatedCollectionCount,
- transferFromExpectSuccess,
- transferFromExpectFail,
- requirePallets,
- Pallets,
} from './util/helpers';
+import {usingPlaygrounds} from './util/playgrounds';
+
+let donor: IKeyringPair;
+
+before(async () => {
+ await usingPlaygrounds(async (_, privateKey) => {
+ donor = privateKey('//Alice');
+ });
+});
chai.use(chaiAsPromised);
+const expect = chai.expect;
describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {
let alice: IKeyringPair;
@@ -44,63 +42,89 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- charlie = privateKeyWrapper('//Charlie');
+ await usingPlaygrounds(async (helper) => {
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
it('[nft] Execute the extrinsic and check approvedList', async () => {
- const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
- await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+ await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
+ expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
+ });
});
it('[fungible] Execute the extrinsic and check approvedList', async () => {
- const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
- await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
+ const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
+ expect(amount).to.be.equal(BigInt(1));
+ });
});
it('[refungible] Execute the extrinsic and check approvedList', async function() {
- await requirePallets(this, [Pallets.ReFungible]);
-
- const reFungibleCollectionId =
- await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
- await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
+ await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
+ const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
+ expect(amount).to.be.equal(BigInt(1));
+ });
});
it('[nft] Remove approval by using 0 amount', async () => {
- const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
- await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 1);
- await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 0);
+ await usingPlaygrounds(async (helper) => {
+ const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const collectionId = collection.collectionId;
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+ await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
+ expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
+ await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0));
+ expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;
+ });
});
it('[fungible] Remove approval by using 0 amount', async () => {
- const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
- await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 1);
- await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 0);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
+ const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
+ expect(amountBefore).to.be.equal(BigInt(1));
+
+ await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
+ const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
+ expect(amountAfter).to.be.equal(BigInt(0));
+ });
});
it('[refungible] Remove approval by using 0 amount', async function() {
- await requirePallets(this, [Pallets.ReFungible]);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
+ await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
+ const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
+ expect(amountBefore).to.be.equal(BigInt(1));
- const reFungibleCollectionId =
- await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
- await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 1);
- await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 0);
+ await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
+ const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
+ expect(amountAfter).to.be.equal(BigInt(0));
+ });
});
it('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
-
- await adminApproveFromExpectFail(collectionId, itemId, alice, bob.address, charlie.address);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
+ const approveTokenTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
+ await expect(approveTokenTx()).to.be.rejected;
+ });
});
});
@@ -110,31 +134,39 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- charlie = privateKeyWrapper('//Charlie');
+ await usingPlaygrounds(async (helper) => {
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
- });
+ });
it('NFT', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
- await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
+ await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
+ expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.true;
+ });
});
it('Fungible up to an approved amount', async () => {
- const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});
- const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', bob.address);
- await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, bob.address, 10n);
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
+ const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address});
+ expect(amount).to.be.equal(BigInt(1));
+ });
});
it('ReFungible up to an approved amount', async function() {
- await requirePallets(this, [Pallets.ReFungible]);
-
- const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});
- const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', bob.address);
- await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});
+ await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);
+ const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address});
+ expect(amount).to.be.equal(BigInt(100n));
+ });
});
});
@@ -144,34 +176,45 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- charlie = privateKeyWrapper('//Charlie');
+ await usingPlaygrounds(async (helper) => {
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
- });
+ });
it('NFT', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
- await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
- await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'NFT');
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
+ await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
+ await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
+ const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
+ expect(owner.Substrate).to.be.equal(alice.address);
+ });
});
it('Fungible up to an approved amount', async () => {
- const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});
- const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', bob.address);
- await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
- await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'Fungible');
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, bob.address, 10n);
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
+ const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
+ await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);
+ const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
+ expect(after - before).to.be.equal(BigInt(1));
+ });
});
it('ReFungible up to an approved amount', async function() {
- await requirePallets(this, [Pallets.ReFungible]);
-
- const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});
- const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', bob.address);
- await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
- await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'ReFungible');
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});
+ await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
+ const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
+ await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);
+ const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
+ expect(after - before).to.be.equal(BigInt(1));
+ });
});
});
@@ -181,37 +224,52 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- charlie = privateKeyWrapper('//Charlie');
+ await usingPlaygrounds(async (helper) => {
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
- });
+ });
it('NFT', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
- await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
- await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'NFT');
- await transferFromExpectFail(collectionId, itemId, charlie, bob, alice, 1);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
+ await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
+ await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
+ const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
+ expect(owner.Substrate).to.be.equal(alice.address);
+ const transferTokenFromTx = async () => helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
+ await expect(transferTokenFromTx()).to.be.rejected;
+ });
});
it('Fungible up to an approved amount', async () => {
- const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});
- const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', bob.address);
- await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
- await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'Fungible');
- await transferFromExpectFail(collectionId, itemId, charlie, bob, alice, 1);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, bob.address, 10n);
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
+ const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
+ await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);
+ const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
+ expect(after - before).to.be.equal(BigInt(1));
+
+ const transferTokenFromTx = async () => helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);
+ await expect(transferTokenFromTx()).to.be.rejected;
+ });
});
it('ReFungible up to an approved amount', async function() {
- await requirePallets(this, [Pallets.ReFungible]);
-
- const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});
- const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', bob.address);
- await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
- await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'ReFungible');
- await transferFromExpectFail(collectionId, itemId, charlie, bob, alice, 1);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});
+ await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);
+ const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
+ await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n);
+ const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
+ expect(after - before).to.be.equal(BigInt(100));
+ const transferTokenFromTx = async () => helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n);
+ await expect(transferTokenFromTx()).to.be.rejected;
+ });
});
});
@@ -222,20 +280,28 @@
let dave: IKeyringPair;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- charlie = privateKeyWrapper('//Charlie');
- dave = privateKeyWrapper('//Dave');
+ await usingPlaygrounds(async (helper) => {
+ [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);
});
- });
+ });
it('If a user B is approved to transfer 10 Fungible tokens from user A, they can transfer 2 tokens to user C, which will result in decreasing approval from 10 to 8. Then user B can transfer 8 tokens to user D.', async () => {
- const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});
- const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', alice.address);
- await approveExpectSuccess(collectionId, itemId, alice, bob.address, 10);
- await transferFromExpectSuccess(collectionId, itemId, bob, alice, charlie, 2, 'Fungible');
- await transferFromExpectSuccess(collectionId, itemId, bob, alice, dave, 8, 'Fungible');
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n);
+
+ const charlieBefore = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});
+ await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address}, 2n);
+ const charlieAfter = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});
+ expect(charlieAfter - charlieBefore).to.be.equal(BigInt(2));
+
+ const daveBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
+ await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: dave.address}, 8n);
+ const daveAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
+ expect(daveAfter - daveBefore).to.be.equal(BigInt(8));
+ });
});
});
@@ -245,38 +311,57 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- charlie = privateKeyWrapper('//Charlie');
+ await usingPlaygrounds(async (helper) => {
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
it('NFT', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT');
- await approveExpectSuccess(collectionId, itemId, alice, bob.address, 1);
- await approveExpectSuccess(collectionId, itemId, alice, bob.address, 0);
- await transferFromExpectFail(collectionId, itemId, bob, bob, charlie, 1);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+ await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
+ expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
+ await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0));
+ expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;
+ const transferTokenFromTx = async () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address});
+ await expect(transferTokenFromTx()).to.be.rejected;
+ });
});
it('Fungible', async () => {
- const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
- await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 1);
- await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 0);
- await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, bob, charlie, 1);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
+ const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
+ expect(amountBefore).to.be.equal(BigInt(1));
+
+ await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
+ const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
+ expect(amountAfter).to.be.equal(BigInt(0));
+
+ const transferTokenFromTx = async () => helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 1n);
+ await expect(transferTokenFromTx()).to.be.rejected;
+ });
});
it('ReFungible', async function() {
- await requirePallets(this, [Pallets.ReFungible]);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
+ await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
+ const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
+ expect(amountBefore).to.be.equal(BigInt(1));
- const reFungibleCollectionId =
- await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
- await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 1);
- await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 0);
- await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, bob, charlie, 1);
+ await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
+ const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
+ expect(amountAfter).to.be.equal(BigInt(0));
+
+ const transferTokenFromTx = async () => helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 100n);
+ await expect(transferTokenFromTx()).to.be.rejected;
+ });
});
});
@@ -286,31 +371,38 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- charlie = privateKeyWrapper('//Charlie');
+ await usingPlaygrounds(async (helper) => {
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
it('1 for NFT', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
- await approveExpectFail(collectionId, itemId, bob, charlie, 2);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
+ const approveTx = async () => helper.signTransaction(bob, helper.api?.tx.unique.approve({Substrate: charlie.address}, collectionId, tokenId, 2));
+ await expect(approveTx()).to.be.rejected;
+ expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;
+ });
});
it('Fungible', async () => {
- const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
- await approveExpectFail(fungibleCollectionId, newFungibleTokenId, bob, charlie, 11);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ const approveTx = async () => helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 11n);
+ await expect(approveTx()).to.be.rejected;
+ });
});
it('ReFungible', async function() {
- await requirePallets(this, [Pallets.ReFungible]);
-
- const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
- await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, charlie, 101);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
+ const approveTx = async () => helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 101n);
+ await expect(approveTx()).to.be.rejected;
+ });
});
});
@@ -321,41 +413,67 @@
let dave: IKeyringPair;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- charlie = privateKeyWrapper('//Charlie');
- dave = privateKeyWrapper('//Dave');
+ await usingPlaygrounds(async (helper) => {
+ [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);
});
- });
+ });
it('NFT', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', charlie.address);
- await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'NFT');
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await transferFromExpectSuccess(collectionId, itemId, bob, dave, alice, 1, 'NFT');
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: charlie.address});
+
+ await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address});
+ const owner1 = await helper.nft.getTokenOwner(collectionId, tokenId);
+ expect(owner1.Substrate).to.be.equal(dave.address);
+
+ await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
+ await helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address});
+ const owner2 = await helper.nft.getTokenOwner(collectionId, tokenId);
+ expect(owner2.Substrate).to.be.equal(alice.address);
+ });
});
it('Fungible up to an approved amount', async () => {
- const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});
- await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
- const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', charlie.address);
- await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'Fungible');
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await transferFromExpectSuccess(collectionId, itemId, bob, dave, alice, 1, 'Fungible');
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});
+ await helper.ft.mintTokens(alice, collectionId, charlie.address, 10n);
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+
+ const daveBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
+ await helper.ft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);
+ const daveBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
+ expect(daveBalanceAfter - daveBalanceBefore).to.be.equal(BigInt(1));
+
+ await helper.collection.addAdmin(alice ,collectionId, {Substrate: bob.address});
+
+ const aliceBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
+ await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);
+ const aliceBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
+ expect(aliceBalanceAfter - aliceBalanceBefore).to.be.equal(BigInt(1));
+ });
});
it('ReFungible up to an approved amount', async function() {
- await requirePallets(this, [Pallets.ReFungible]);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: charlie.address, pieces: 100n});
+
+ const daveBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});
+ await helper.rft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);
+ const daveAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});
+ expect(daveAfter - daveBefore).to.be.equal(BigInt(1));
- const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});
- await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
- const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', charlie.address);
- await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'ReFungible');
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await transferFromExpectSuccess(collectionId, itemId, bob, dave, alice, 1, 'ReFungible');
+ await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
+
+ const aliceBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
+ await helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);
+ const aliceAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
+ expect(aliceAfter - aliceBefore).to.be.equal(BigInt(1));
+ });
});
});
@@ -366,13 +484,10 @@
let dave: IKeyringPair;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- charlie = privateKeyWrapper('//Charlie');
- dave = privateKeyWrapper('//Dave');
+ await usingPlaygrounds(async (helper) => {
+ [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);
});
- });
+ });
it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. Fungible', async () => {
const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});
@@ -417,19 +532,19 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- charlie = privateKeyWrapper('//Charlie');
+ await usingPlaygrounds(async (helper) => {
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
it('can be called by collection admin on non-owned item', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
-
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await adminApproveFromExpectFail(collectionId, itemId, bob, alice.address, charlie.address);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+ await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
+ const approveTx = async () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
+ await expect(approveTx()).to.be.rejected;
+ });
});
});
@@ -439,114 +554,139 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
- bob = privateKeyWrapper('//Bob');
- charlie = privateKeyWrapper('//Charlie');
+ await usingPlaygrounds(async (helper) => {
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
it('[nft] Approve for a collection that does not exist', async () => {
- await usingApi(async (api: ApiPromise) => {
- const nftCollectionCount = await getCreatedCollectionCount(api);
- await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);
+ await usingPlaygrounds(async (helper) => {
+ const collectionId = 1 << 32 - 1;
+ const approveTx = async () => helper.nft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});
+ await expect(approveTx()).to.be.rejected;
});
});
it('[fungible] Approve for a collection that does not exist', async () => {
- await usingApi(async (api: ApiPromise) => {
- const fungibleCollectionCount = await getCreatedCollectionCount(api);
- await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);
+ await usingPlaygrounds(async (helper) => {
+ const collectionId = 1 << 32 - 1;
+ const approveTx = async () => helper.ft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});
+ await expect(approveTx()).to.be.rejected;
});
});
it('[refungible] Approve for a collection that does not exist', async function() {
- await requirePallets(this, [Pallets.ReFungible]);
-
- await usingApi(async (api: ApiPromise) => {
- const reFungibleCollectionCount = await getCreatedCollectionCount(api);
- await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);
+ await usingPlaygrounds(async (helper) => {
+ const collectionId = 1 << 32 - 1;
+ const approveTx = async () => helper.rft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});
+ await expect(approveTx()).to.be.rejected;
});
});
it('[nft] Approve for a collection that was destroyed', async () => {
- const nftCollectionId = await createCollectionExpectSuccess();
- await destroyCollectionExpectSuccess(nftCollectionId);
- await approveExpectFail(nftCollectionId, 1, alice, bob);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ await helper.nft.burn(alice, collectionId);
+ const approveTx = async () => helper.nft.approveToken(alice, collectionId, 1, {Substrate: bob.address});
+ await expect(approveTx()).to.be.rejected;
+ });
});
- it('Approve for a collection that was destroyed', async () => {
- const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- await destroyCollectionExpectSuccess(fungibleCollectionId);
- await approveExpectFail(fungibleCollectionId, 0, alice, bob);
+ it('[fungible] Approve for a collection that was destroyed', async () => {
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ await helper.ft.burn(alice, collectionId);
+ const approveTx = async () => helper.ft.approveToken(alice, collectionId, 1, {Substrate: bob.address});
+ await expect(approveTx()).to.be.rejected;
+ });
});
it('[refungible] Approve for a collection that was destroyed', async function() {
- await requirePallets(this, [Pallets.ReFungible]);
-
- const reFungibleCollectionId =
- await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- await destroyCollectionExpectSuccess(reFungibleCollectionId);
- await approveExpectFail(reFungibleCollectionId, 1, alice, bob);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ await helper.rft.burn(alice, collectionId);
+ const approveTx = async () => helper.rft.approveToken(alice, collectionId, 1, {Substrate: bob.address});
+ await expect(approveTx()).to.be.rejected;
+ });
});
it('[nft] Approve transfer of a token that does not exist', async () => {
- const nftCollectionId = await createCollectionExpectSuccess();
- await approveExpectFail(nftCollectionId, 2, alice, bob);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const approveTx = async () => helper.nft.approveToken(alice, collectionId, 2, {Substrate: bob.address});
+ await expect(approveTx()).to.be.rejected;
+ });
});
it('[refungible] Approve transfer of a token that does not exist', async function() {
- await requirePallets(this, [Pallets.ReFungible]);
-
- const reFungibleCollectionId =
- await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- await approveExpectFail(reFungibleCollectionId, 2, alice, bob);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const approveTx = async () => helper.rft.approveToken(alice, collectionId, 2, {Substrate: bob.address});
+ await expect(approveTx()).to.be.rejected;
+ });
});
it('[nft] Approve using the address that does not own the approved token', async () => {
- const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
- await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+ const approveTx = async () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});
+ await expect(approveTx()).to.be.rejected;
+ });
});
it('[fungible] Approve using the address that does not own the approved token', async () => {
- const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
- await approveExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ const approveTx = async () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});
+ await expect(approveTx()).to.be.rejected;
+ });
});
it('[refungible] Approve using the address that does not own the approved token', async function() {
- await requirePallets(this, [Pallets.ReFungible]);
-
- const reFungibleCollectionId =
- await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
- await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, alice);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
+ const approveTx = async () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});
+ await expect(approveTx()).to.be.rejected;
+ });
});
it('should fail if approved more ReFungibles than owned', async function() {
- await requirePallets(this, [Pallets.ReFungible]);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
+ await helper.rft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 100n);
+ await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 100n);
- const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'ReFungible');
- await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 100, 'ReFungible');
- await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 100);
- await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 101);
+ const approveTx = async () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 101n);
+ await expect(approveTx()).to.be.rejected;
+ });
});
it('should fail if approved more Fungibles than owned', async () => {
- const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'Fungible');
- await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 10, 'Fungible');
- await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 10);
- await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 11);
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+
+ await helper.ft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n);
+ await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 10n);
+ const approveTx = async () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 11n);
+ await expect(approveTx()).to.be.rejected;
+ });
});
it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
- await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: false});
+ await usingPlaygrounds(async (helper) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
+ await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: false});
- await approveExpectFail(collectionId, itemId, alice, charlie);
+ const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
+ await expect(approveTx()).to.be.rejected;
+ });
});
});
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -255,9 +255,9 @@
return network;
}
- static async createConnection(wsEndpoint: string, listeners?: IApiListeners, network?: TUniqueNetworks | null): Promise<{
- api: ApiPromise;
- network: TUniqueNetworks;
+ static async createConnection(wsEndpoint: string, listeners?: IApiListeners, network?: TUniqueNetworks | null): Promise<{
+ api: ApiPromise;
+ network: TUniqueNetworks;
}> {
if(typeof network === 'undefined' || network === null) network = 'opal';
const supportedRPC = {
@@ -444,7 +444,7 @@
if(this.api === null) throw Error('API not initialized');
return this.api.runtimeMetadata.asLatest.pallets.map(m => m.name.toString().toLowerCase());
}
-
+
fetchMissingPalletNames(requiredPallets: string[]): string[] {
const palletNames = this.fetchAllPalletNames();
return requiredPallets.filter(p => !palletNames.includes(p));
@@ -477,7 +477,7 @@
/**
* Get the number of created collections.
- *
+ *
* @returns number of created collections
*/
async getTotalCount(): Promise<number> {
@@ -485,10 +485,10 @@
}
/**
- * Get information about the collection with additional data,
- * including the number of tokens it contains, its administrators,
+ * Get information about the collection with additional data,
+ * including the number of tokens it contains, its administrators,
* the normalized address of the collection's owner, and decoded name and description.
- *
+ *
* @param collectionId ID of collection
* @example await getData(2)
* @returns collection information object
@@ -515,8 +515,8 @@
collectionData[key] = this.helper.util.vec2str(humanCollection[key]);
}
- collectionData.tokensCount = (['RFT', 'NFT'].includes(humanCollection.mode))
- ? await this.helper[humanCollection.mode.toLocaleLowerCase() as 'nft' | 'rft'].getLastTokenId(collectionId)
+ collectionData.tokensCount = (['RFT', 'NFT'].includes(humanCollection.mode))
+ ? await this.helper[humanCollection.mode.toLocaleLowerCase() as 'nft' | 'rft'].getLastTokenId(collectionId)
: 0;
collectionData.admins = await this.getAdmins(collectionId);
@@ -525,7 +525,7 @@
/**
* Get the addresses of the collection's administrators, optionally normalized.
- *
+ *
* @param collectionId ID of collection
* @param normalize whether to normalize the addresses to the default ss58 format
* @example await getAdmins(1)
@@ -539,7 +539,7 @@
return address.Substrate
? {Substrate: this.helper.address.normalizeSubstrate(address.Substrate)}
: address;
- })
+ })
: admins;
}
@@ -557,13 +557,13 @@
return address.Substrate
? {Substrate: this.helper.address.normalizeSubstrate(address.Substrate)}
: address;
- })
+ })
: allowListed;
}
/**
* Get the effective limits of the collection instead of null for default values
- *
+ *
* @param collectionId ID of collection
* @example await getEffectiveLimits(2)
* @returns object of collection limits
@@ -574,7 +574,7 @@
/**
* Burns the collection if the signer has sufficient permissions and collection is empty.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @example await helper.collection.burn(aliceKeyring, 3);
@@ -592,7 +592,7 @@
/**
* Sets the sponsor for the collection (Requires the Substrate address). Needs confirmation by the sponsor.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param sponsorAddress Sponsor substrate address
@@ -611,7 +611,7 @@
/**
* Confirms consent to sponsor the collection on behalf of the signer.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @example confirmSponsorship(aliceKeyring, 10)
@@ -629,7 +629,7 @@
/**
* Removes the sponsor of a collection, regardless if it consented or not.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @example removeSponsor(aliceKeyring, 10)
@@ -647,7 +647,7 @@
/**
* Sets the limits of the collection. At least one limit must be specified for a correct call.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param limits collection limits object
@@ -674,7 +674,7 @@
/**
* Changes the owner of the collection to the new Substrate address.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param ownerAddress substrate address of new owner
@@ -692,8 +692,8 @@
}
/**
- * Adds a collection administrator.
- *
+ * Adds a collection administrator.
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param adminAddressObj Administrator address (substrate or ethereum)
@@ -712,7 +712,7 @@
/**
* Removes a collection administrator.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param adminAddressObj Administrator address (substrate or ethereum)
@@ -730,7 +730,7 @@
}
/**
- * Adds an address to allow list
+ * Adds an address to allow list
* @param signer keyring of signer
* @param collectionId ID of collection
* @param addressObj address to add to the allow list
@@ -747,8 +747,8 @@
}
/**
- * Removes an address from allow list
- *
+ * Removes an address from allow list
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param addressObj address to remove from the allow list
@@ -766,7 +766,7 @@
/**
* Sets onchain permissions for selected collection.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param permissions collection permissions object
@@ -785,7 +785,7 @@
/**
* Enables nesting for selected collection. If `restricted` set, you can nest only tokens from specified collections.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param permissions nesting permissions object
@@ -798,7 +798,7 @@
/**
* Disables nesting for selected collection.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @example disableNesting(aliceKeyring, 10);
@@ -810,7 +810,7 @@
/**
* Sets onchain properties to the collection.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param properties array of property objects
@@ -829,7 +829,7 @@
/**
* Deletes onchain properties from the collection.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param propertyKeys array of property keys to delete
@@ -848,7 +848,7 @@
/**
* Changes the owner of the token.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param tokenId ID of token
@@ -868,9 +868,9 @@
}
/**
- *
- * Change ownership of a token(s) on behalf of the owner.
- *
+ *
+ * Change ownership of a token(s) on behalf of the owner.
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param tokenId ID of token
@@ -890,9 +890,9 @@
}
/**
- *
+ *
* Destroys a concrete instance of NFT/RFT or burns a specified amount of fungible tokens.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param tokenId ID of token
@@ -916,7 +916,7 @@
/**
* Destroys a concrete instance of NFT on behalf of the owner
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param fromAddressObj address on behalf of which the token will be burnt
@@ -937,7 +937,7 @@
/**
* Set, change, or remove approved address to transfer the ownership of the NFT.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param tokenId ID of token
@@ -947,7 +947,7 @@
*/
async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, amount=1n) {
const approveResult = await this.helper.executeExtrinsic(
- signer,
+ signer,
'api.tx.unique.approve', [toAddressObj, collectionId, tokenId, amount],
true, // `Unable to approve token for ${label}`,
);
@@ -957,7 +957,7 @@
/**
* Get the amount of token pieces approved to transfer or burn. Normally 0.
- *
+ *
* @param collectionId ID of collection
* @param tokenId ID of token
* @param toAccountObj address which is approved to use token pieces
@@ -971,7 +971,7 @@
/**
* Get the last created token ID in a collection
- *
+ *
* @param collectionId ID of collection
* @example getLastTokenId(10);
* @returns id of the last created token
@@ -982,7 +982,7 @@
/**
* Check if token exists
- *
+ *
* @param collectionId ID of collection
* @param tokenId ID of token
* @example isTokenExists(10, 20);
@@ -996,7 +996,7 @@
class NFTnRFT extends CollectionGroup {
/**
* Get tokens owned by account
- *
+ *
* @param collectionId ID of collection
* @param addressObj tokens owner
* @example getTokensByAddress(10, {Substrate: "5DyN4Y92vZCjv38fg..."})
@@ -1008,13 +1008,13 @@
/**
* Get token data
- *
+ *
* @param collectionId ID of collection
* @param tokenId ID of token
* @param propertyKeys optionally filter the token properties to only these keys
* @param blockHashAt optionally query the data at some block with this hash
* @example getToken(10, 5);
- * @returns human readable token data
+ * @returns human readable token data
*/
async getToken(collectionId: number, tokenId: number, propertyKeys: string[] = [], blockHashAt?: string): Promise<{
properties: IProperty[];
@@ -1045,7 +1045,7 @@
/**
* Set permissions to change token properties
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param permissions permissions to change a property by the collection owner or admin
@@ -1066,7 +1066,7 @@
/**
* Set token properties
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param tokenId ID of token
@@ -1089,7 +1089,7 @@
* @param signer keyring of signer
* @param collectionId ID of collection
* @param tokenId ID of token
- * @param propertyKeys property keys to be deleted
+ * @param propertyKeys property keys to be deleted
* @example deleteTokenProperties(aliceKeyring, 10, 5, ["gender", "age"])
* @returns ```true``` if extrinsic success, otherwise ```false```
*/
@@ -1105,9 +1105,9 @@
/**
* Mint new collection
- *
+ *
* @param signer keyring of signer
- * @param collectionOptions basic collection options and properties
+ * @param collectionOptions basic collection options and properties
* @param mode NFT or RFT type of a collection
* @example mintCollection(aliceKeyring, {name: 'New', description: "New collection", tokenPrefix: "NEW"}, "NFT")
* @returns object of the created collection
@@ -1189,7 +1189,7 @@
/**
* Changes the owner of the token.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param tokenId ID of token
@@ -1202,9 +1202,9 @@
}
/**
- *
- * Change ownership of a NFT on behalf of the owner.
- *
+ *
+ * Change ownership of a NFT on behalf of the owner.
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param tokenId ID of token
@@ -1221,7 +1221,7 @@
* Recursively find the address that owns the token
* @param collectionId ID of collection
* @param tokenId ID of token
- * @param blockHashAt
+ * @param blockHashAt
* @example getTokenTopmostOwner(10, 5);
* @returns address in CrossAccountId format, e.g. {Substrate: "5DyN4Y92vZCjv38fg..."}
*/
@@ -1246,7 +1246,7 @@
* @param tokenId ID of token
* @param blockHashAt optionally query the data at the block with this hash
* @example getTokenChildren(10, 5);
- * @returns tokens whose depth of nesting is <= 5
+ * @returns tokens whose depth of nesting is <= 5
*/
async getTokenChildren(collectionId: number, tokenId: number, blockHashAt?: string): Promise<IToken[]> {
let children;
@@ -1283,7 +1283,7 @@
* @param signer keyring of signer
* @param tokenObj token to unnest
* @param rootTokenObj parent of a token
- * @param toAddressObj address of a new token owner
+ * @param toAddressObj address of a new token owner
* @example unnestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4}, {Substrate: "5DyN4Y92vZCjv38fg..."});
* @returns ```true``` if extrinsic success, otherwise ```false```
*/
@@ -1300,7 +1300,7 @@
* Mint new collection
* @param signer keyring of signer
* @param collectionOptions Collection options
- * @example
+ * @example
* mintCollection(aliceKeyring, {
* name: 'New',
* description: 'New collection',
@@ -1339,7 +1339,7 @@
* @param signer keyring of signer
* @param collectionId ID of collection
* @param tokens array of tokens with owner and properties
- * @example
+ * @example
* mintMultipleTokens(aliceKeyring, 10, [{
* owner: {Substrate: "5DyN4Y92vZCjv38fg..."},
* properties: [{key: "gender", value: "male"},{key: "age", value: "45"}],
@@ -1390,23 +1390,11 @@
);
const collection = this.getCollectionObject(collectionId);
return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));
- }
-
- /**
- * Destroys a concrete instance of NFT.
- * @param signer keyring of signer
- * @param collectionId ID of collection
- * @param tokenId ID of token
- * @example burnToken(aliceKeyring, 10, 5);
- * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```
- */
- async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number): Promise<{ success: boolean; token: number | null; }> {
- return await super.burnToken(signer, collectionId, tokenId, 1n);
}
/**
* Set, change, or remove approved address to transfer the ownership of the NFT.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param tokenId ID of token
@@ -1443,7 +1431,7 @@
}
/**
- * Get top 10 token owners with the largest number of pieces
+ * Get top 10 token owners with the largest number of pieces
* @param collectionId ID of collection
* @param tokenId ID of token
* @example getTokenTop10Owners(10, 5);
@@ -1480,7 +1468,7 @@
}
/**
- * Change ownership of some pieces of RFT on behalf of the owner.
+ * Change ownership of some pieces of RFT on behalf of the owner.
* @param signer keyring of signer
* @param collectionId ID of collection
* @param tokenId ID of token
@@ -1584,7 +1572,7 @@
/**
* Set, change, or remove approved address to transfer the ownership of the RFT.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param tokenId ID of token
@@ -1645,7 +1633,7 @@
* Mint new fungible collection
* @param signer keyring of signer
* @param collectionOptions Collection options
- * @param decimalPoints number of token decimals
+ * @param decimalPoints number of token decimals
* @example
* mintCollection(aliceKeyring, {
* name: 'New',
@@ -1676,7 +1664,7 @@
* @param owner address owner of new tokens
* @param amount amount of tokens to be meanted
* @example mintTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq"}, 1000n);
- * @returns ```true``` if extrinsic success, otherwise ```false```
+ * @returns ```true``` if extrinsic success, otherwise ```false```
*/
async mintTokens(signer: TSigner, collectionId: number, amount: bigint, owner: ICrossAccountId | string): Promise<boolean> {
const creationResult = await this.helper.executeExtrinsic(
@@ -1697,7 +1685,7 @@
* @param collectionId ID of collection
* @param owner tokens owner
* @param tokens array of tokens with properties and pieces
- * @returns ```true``` if extrinsic success, otherwise ```false```
+ * @returns ```true``` if extrinsic success, otherwise ```false```
*/
async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, tokens: {value: bigint}[], owner: ICrossAccountId): Promise<boolean> {
const rawTokens = [];
@@ -1714,7 +1702,7 @@
}
/**
- * Get the top 10 owners with the largest balance for the Fungible collection
+ * Get the top 10 owners with the largest balance for the Fungible collection
* @param collectionId ID of collection
* @example getTop10Owners(10);
* @returns array of ```ICrossAccountId```
@@ -1741,7 +1729,7 @@
* @param toAddressObj address recipient
* @param amount amount of tokens to be sent
* @example transfer(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);
- * @returns ```true``` if extrinsic success, otherwise ```false```
+ * @returns ```true``` if extrinsic success, otherwise ```false```
*/
async transfer(signer: TSigner, collectionId: number, toAddressObj: ICrossAccountId, amount=1n) {
return await super.transferToken(signer, collectionId, 0, toAddressObj, amount);
@@ -1755,7 +1743,7 @@
* @param toAddressObj address where token to be sent
* @param amount number of tokens to be sent
* @example transferFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, {Substrate: "5DfhbVfww7ThF8q6f3ij..."}, 10000n);
- * @returns ```true``` if extrinsic success, otherwise ```false```
+ * @returns ```true``` if extrinsic success, otherwise ```false```
*/
async transferFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {
return await super.transferTokenFrom(signer, collectionId, 0, fromAddressObj, toAddressObj, amount);
@@ -1767,7 +1755,7 @@
* @param collectionId ID of collection
* @param amount amount of tokens to be destroyed
* @example burnTokens(aliceKeyring, 10, 1000n);
- * @returns ```true``` if extrinsic success, otherwise ```false```
+ * @returns ```true``` if extrinsic success, otherwise ```false```
*/
async burnTokens(signer: IKeyringPair, collectionId: number, amount=1n): Promise<boolean> {
return (await super.burnToken(signer, collectionId, 0, amount)).success;
@@ -1780,7 +1768,7 @@
* @param fromAddressObj address on behalf of which tokens will be burnt
* @param amount amount of tokens to be burnt
* @example burnTokensFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);
- * @returns ```true``` if extrinsic success, otherwise ```false```
+ * @returns ```true``` if extrinsic success, otherwise ```false```
*/
async burnTokensFrom(signer: IKeyringPair, collectionId: number, fromAddressObj: ICrossAccountId, amount=1n): Promise<boolean> {
return await super.burnTokenFrom(signer, collectionId, fromAddressObj, 0, amount);
@@ -1788,8 +1776,8 @@
/**
* Get total collection supply
- * @param collectionId
- * @returns
+ * @param collectionId
+ * @returns
*/
async getTotalPieces(collectionId: number): Promise<bigint> {
return (await this.helper.callRpc('api.rpc.unique.totalPieces', [collectionId, 0])).unwrap().toBigInt();
@@ -1797,13 +1785,13 @@
/**
* Set, change, or remove approved address to transfer tokens.
- *
+ *
* @param signer keyring of signer
* @param collectionId ID of collection
* @param toAddressObj address to be approved
* @param amount amount of tokens to be approved
* @example approveTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n)
- * @returns ```true``` if extrinsic success, otherwise ```false```
+ * @returns ```true``` if extrinsic success, otherwise ```false```
*/
async approveTokens(signer: IKeyringPair, collectionId: number, toAddressObj: ICrossAccountId, amount=1n) {
return super.approveToken(signer, collectionId, 0, toAddressObj, amount);
@@ -1901,7 +1889,7 @@
/**
* Get full substrate balance including free, miscFrozen, feeFrozen, and reserved
* @param address substrate address
- * @returns
+ * @returns
*/
async getSubstrateFull(address: TSubstrateAccount): Promise<ISubstrateBalance> {
const accountInfo = (await this.helper.callRpc('api.query.system.account', [address])).data;
@@ -2022,7 +2010,7 @@
async unstake(signer: TSigner, label?: string): Promise<number> {
if(typeof label === 'undefined') label = `${signer.address}`;
const unstakeResult = await this.helper.executeExtrinsic(
- signer, 'api.tx.appPromotion.unstake',
+ signer, 'api.tx.appPromotion.unstake',
[], true,
);
// TODO extract block number fron events
@@ -2041,7 +2029,7 @@
async getPendingUnstake(address: ICrossAccountId): Promise<bigint> {
return (await this.helper.callRpc('api.rpc.appPromotion.pendingUnstake', [address])).toBigInt();
}
-
+
async getPendingUnstakePerBlock(address: ICrossAccountId): Promise<bigint[][]> {
return (await this.helper.callRpc('api.rpc.appPromotion.pendingUnstakePerBlock', [address])).map(([block, amount]: any[]) => [block.toBigInt(), amount.toBigInt()]);
}
@@ -2067,7 +2055,7 @@
this.rft = new RFTGroup(this);
this.ft = new FTGroup(this);
this.staking = new StakingGroup(this);
- }
+ }
}