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.tsdiffbeforeafterboth17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';19import chaiAsPromised from 'chai-as-promised';20import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';20import {usingPlaygrounds} from './util/playgrounds';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';412142chai.use(chaiAsPromised);22chai.use(chaiAsPromised);43const expect = chai.expect;23const expect = chai.expect;442425let donor: IKeyringPair;2627before(async () => {28 await usingPlaygrounds(async (_, privateKey) => {29 donor = privateKey('//Alice');30 });31});3245let alice: IKeyringPair;33let alice: IKeyringPair;46let bob: IKeyringPair;34let bob: IKeyringPair;47let charlie: IKeyringPair;35let charlie: IKeyringPair;483649describe('Integration Test ext. Allow list tests', () => {37describe('Integration Test ext. Allow list tests', () => {503851 before(async () => {39 before(async () => {52 await usingApi(async (api, privateKeyWrapper) => {40 await usingPlaygrounds(async (helper) => {53 alice = privateKeyWrapper('//Alice');41 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);54 bob = privateKeyWrapper('//Bob');55 charlie = privateKeyWrapper('//Charlie');56 });42 });57 });43 });584459 it('Owner can add address to allow list', async () => {45 it('Owner can add address to allow list', async () => {60 const collectionId = await createCollectionExpectSuccess();46 await usingPlaygrounds(async (helper) => {47 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});61 await addToAllowListExpectSuccess(alice, collectionId, bob.address);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 });62 });52 });635364 it('Admin can add address to allow list', async () => {54 it('Admin can add address to allow list', async () => {65 const collectionId = await createCollectionExpectSuccess();55 await usingPlaygrounds(async (helper) => {56 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});66 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);57 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});5867 await addToAllowListExpectSuccess(bob, collectionId, charlie.address);59 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 });68 });63 });696470 it('Non-privileged user cannot add address to allow list', async () => {65 it('Non-privileged user cannot add address to allow list', async () => {71 const collectionId = await createCollectionExpectSuccess();66 await usingPlaygrounds(async (helper) => {67 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});72 await addToAllowListExpectFail(bob, collectionId, charlie.address);68 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});69 await expect(addToAllowListTx()).to.be.rejected;70 });73 });71 });747275 it('Nobody can add address to allow list of non-existing collection', async () => {73 it('Nobody can add address to allow list of non-existing collection', async () => {76 const collectionId = (1<<32) - 1;74 const collectionId = (1<<32) - 1;77 await addToAllowListExpectFail(alice, collectionId, bob.address);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 });78 });79 });798080 it('Nobody can add address to allow list of destroyed collection', async () => {81 it('Nobody can add address to allow list of destroyed collection', async () => {81 const collectionId = await createCollectionExpectSuccess();82 await usingPlaygrounds(async (helper) => {83 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});82 await destroyCollectionExpectSuccess(collectionId, '//Alice');84 await helper.collection.burn(alice, collectionId);83 await addToAllowListExpectFail(alice, collectionId, bob.address);85 const addToAllowListTx = async () => helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});86 await expect(addToAllowListTx()).to.be.rejected;87 });84 });88 });858986 it('If address is already added to allow list, nothing happens', async () => {90 it('If address is already added to allow list, nothing happens', async () => {87 const collectionId = await createCollectionExpectSuccess();91 await usingPlaygrounds(async (helper) => {92 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});88 await addToAllowListExpectSuccess(alice, collectionId, bob.address);93 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});89 await addToAllowListAgainExpectSuccess(alice, collectionId, 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 });90 });98 });919992 it('Owner can remove address from allow list', async () => {100 it('Owner can remove address from allow list', async () => {93 const collectionId = await createCollectionExpectSuccess();101 await usingPlaygrounds(async (helper) => {102 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});94 await addToAllowListExpectSuccess(alice, collectionId, bob.address);103 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});10495 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob));105 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 });96 });111 });9711298 it('Admin can remove address from allow list', async () => {113 it('Admin can remove address from allow list', async () => {99 const collectionId = await createCollectionExpectSuccess();114 await usingPlaygrounds(async (helper) => {115 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});100 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);116 await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address});101 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);117 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});102 await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie));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 });103 });124 });104125105 it('Non-privileged user cannot remove address from allow list', async () => {126 it('Non-privileged user cannot remove address from allow list', async () => {106 const collectionId = await createCollectionExpectSuccess();127 await usingPlaygrounds(async (helper) => {128 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});107 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);129 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});108 await removeFromAllowListExpectFailure(bob, collectionId, normalizeAccountId(charlie));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 });109 });136 });110137111 it('Nobody can remove address from allow list of non-existing collection', async () => {138 it('Nobody can remove address from allow list of non-existing collection', async () => {112 const collectionId = (1<<32) - 1;139 const collectionId = (1<<32) - 1;113 await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));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 });114 });144 });115145116 it('Nobody can remove address from allow list of deleted collection', async () => {146 it('Nobody can remove address from allow list of deleted collection', async () => {117 const collectionId = await createCollectionExpectSuccess();147 await usingPlaygrounds(async (helper) => {148 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});118 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);149 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});119 await destroyCollectionExpectSuccess(collectionId, '//Alice');150 await helper.collection.burn(alice, collectionId);120 await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));151 const removeTx = async () => helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});152153 await expect(removeTx()).to.be.rejected;154 });121 });155 });122156123 it('If address is already removed from allow list, nothing happens', async () => {157 it('If address is already removed from allow list, nothing happens', async () => {124 const collectionId = await createCollectionExpectSuccess();158 await usingPlaygrounds(async (helper) => {159 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});125 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);160 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});126 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));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});164127 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));165 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 });128 });170 });129171130 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 () => {172 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();173 await usingPlaygrounds(async (helper) => {174 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});132 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);175 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});133 await enableAllowListExpectSuccess(alice, collectionId);176 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});134 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);177 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});135178136 await transferExpectFailure(179 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});137 collectionId,138 itemId,139 alice,140 charlie,141 1,180 await expect(transferResult()).to.be.rejected;142 );181 });143 });182 });144183145 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 () => {184 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();185 await usingPlaygrounds(async (helper) => {186 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});147 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);187 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});148 await enableAllowListExpectSuccess(alice, collectionId);188 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});149 await addToAllowListExpectSuccess(alice, collectionId, alice.address);189 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});150 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);190 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});151 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);191 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});152 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));192 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});153193154 await transferExpectFailure(194 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});155 collectionId,156 itemId,157 alice,158 charlie,159 1,195 await expect(transferResult()).to.be.rejected;160 );196 });161 });197 });162198163 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 () => {199 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();200 await usingPlaygrounds(async (helper) => {201 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});165 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);202 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});166 await enableAllowListExpectSuccess(alice, collectionId);203 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});167 await addToAllowListExpectSuccess(alice, collectionId, alice.address);204 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});168205169 await transferExpectFailure(206 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});170 collectionId,171 itemId,172 alice,173 charlie,174 1,207 await expect(transferResult()).to.be.rejected;175 );208 });176 });209 });177210178 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 () => {211 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();212 await usingPlaygrounds(async (helper) => {180 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);213 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});181 await enableAllowListExpectSuccess(alice, collectionId);214 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});182 await addToAllowListExpectSuccess(alice, collectionId, alice.address);183 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);215 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});184 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);216 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});185 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));217 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});186218187 await transferExpectFailure(219 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});188 collectionId,220 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});221189 itemId,222 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});190 alice,191 charlie,192 1,223 await expect(transferResult()).to.be.rejected;193 );224 });194 });225 });195226196 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 () => {227 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();228 await usingPlaygrounds(async (helper) => {198 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);229 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});199 await enableAllowListExpectSuccess(alice, collectionId);230 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});200201 await usingApi(async (api) => {202 const tx = api.tx.unique.burnItem(collectionId, itemId, /*normalizeAccountId(Alice.address),*/ 11);231 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});203 const badTransaction = async function () {232 const burnTx = async () => helper.nft.burnToken(bob, collectionId, tokenId);204 await submitTransactionExpectFailAsync(alice, tx);205 };206 await expect(badTransaction()).to.be.rejected;233 await expect(burnTx()).to.be.rejected;207 });234 });208 });235 });209236210 it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {237 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();238 await usingPlaygrounds(async (helper) => {239 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});212 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);240 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});213 await enableAllowListExpectSuccess(alice, collectionId);241 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});214 await approveExpectFail(collectionId, itemId, alice, bob);242 const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});243 await expect(approveTx()).to.be.rejected;244 });215 });245 });216246217 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => {247 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();248 await usingPlaygrounds(async (helper) => {249 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});219 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);250 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});220 await enableAllowListExpectSuccess(alice, collectionId);251 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});221 await addToAllowListExpectSuccess(alice, collectionId, alice.address);252 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});222 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);253 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});223 await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');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 });224 });258 });225259226 it('If Public Access mode is set to AllowList, tokens can be transferred to a alowlisted address with transferFrom.', async () => {260 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transferFrom.', async () => {227 const collectionId = await createCollectionExpectSuccess();261 await usingPlaygrounds(async (helper) => {262 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});228 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);263 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});229 await enableAllowListExpectSuccess(alice, collectionId);264 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});230 await addToAllowListExpectSuccess(alice, collectionId, alice.address);265 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});231 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);266 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});232 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);267 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});268233 await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');269 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 });234 });273 });235274236 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {275 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();276 await usingPlaygrounds(async (helper) => {277 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});238 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);278 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});239 await enableAllowListExpectSuccess(alice, collectionId);279 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});240 await addToAllowListExpectSuccess(alice, collectionId, alice.address);280 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});241 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);281 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});282242 await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');283 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 });243 });287 });244288245 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {289 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();290 await usingPlaygrounds(async (helper) => {291 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});247 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);292 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});248 await enableAllowListExpectSuccess(alice, collectionId);293 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});249 await addToAllowListExpectSuccess(alice, collectionId, alice.address);294 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});250 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);295 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});251 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);296 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});297252 await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');298 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 });253 });302 });254303255 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {304 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();305 await usingPlaygrounds(async (helper) => {306 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});257 await enableAllowListExpectSuccess(alice, collectionId);307 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});258 await setMintPermissionExpectSuccess(alice, collectionId, false);308 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});259 await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);309 const token = await helper.nft.getToken(collectionId, tokenId);310 expect(token).to.be.not.null;311 });260 });312 });261313262 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {314 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();315 await usingPlaygrounds(async (helper) => {316 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});264 await enableAllowListExpectSuccess(alice, collectionId);317 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});265 await setMintPermissionExpectSuccess(alice, collectionId, false);318 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});266 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);319 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});267 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);320 const token = await helper.nft.getToken(collectionId, tokenId);321 expect(token).to.be.not.null;322 });268 });323 });269324270 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 () => {325 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();326 await usingPlaygrounds(async (helper) => {272 await enableAllowListExpectSuccess(alice, collectionId);327 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});273 await setMintPermissionExpectSuccess(alice, collectionId, false);328 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});274 await addToAllowListExpectSuccess(alice, collectionId, bob.address);329 await helper.collection.addToAllowList(alice, collectionId, {Substrate: bob.address});275 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);330 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});331 await expect(mintTokenTx()).to.be.rejected;332 });276 });333 });277334278 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 () => {335 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();336 await usingPlaygrounds(async (helper) => {280 await enableAllowListExpectSuccess(alice, collectionId);337 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});281 await setMintPermissionExpectSuccess(alice, collectionId, false);338 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});282 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);339 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});340 await expect(mintTokenTx()).to.be.rejected;341 });283 });342 });284343285 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {344 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();345 await usingPlaygrounds(async (helper) => {346 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});287 await enableAllowListExpectSuccess(alice, collectionId);347 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});288 await setMintPermissionExpectSuccess(alice, collectionId, true);348 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});289 await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);349 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);350 expect(owner.Substrate).to.be.equal(alice.address);351 });290 });352 });291353292 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {354 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();355 await usingPlaygrounds(async (helper) => {356 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});294 await enableAllowListExpectSuccess(alice, collectionId);357 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});295 await setMintPermissionExpectSuccess(alice, collectionId, true);358 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});296 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);359 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});297 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);360 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);361 expect(owner.Substrate).to.be.equal(bob.address);362 });298 });363 });299364300 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 () => {365 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();366 await usingPlaygrounds(async (helper) => {302 await enableAllowListExpectSuccess(alice, collectionId);367 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});303 await setMintPermissionExpectSuccess(alice, collectionId, true);368 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});304 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);369 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});370 await expect(mintTokenTx()).to.be.rejected;371 });305 });372 });306373307 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 () => {374 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();375 await usingPlaygrounds(async (helper) => {376 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});309 await enableAllowListExpectSuccess(alice, collectionId);377 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});310 await setMintPermissionExpectSuccess(alice, collectionId, true);378 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});311 await addToAllowListExpectSuccess(alice, collectionId, bob.address);379 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});312 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);380 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);381 expect(owner.Substrate).to.be.equal(bob.address);382 });313 });383 });314});384});315385tests/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);
- }
+ }
}