difftreelog
Fixes for nesting and permissions tests
in: master
3 files changed
tests/src/nesting/nest.test.tsdiffbeforeafterboth--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -10,7 +10,7 @@
enablePublicMintingExpectSuccess,
getTokenOwner,
getTopmostTokenOwner,
- setCollectionPermissionsExceptSuccess,
+ setCollectionPermissionsExpectSuccess,
transferExpectFailure,
transferExpectSuccess,
transferFromExpectSuccess,
@@ -31,7 +31,7 @@
it('Performs the full suite: bundles a token, transfers, and allows to unnest', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
+ await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
// Create a nested token
@@ -63,7 +63,7 @@
it('NFT: allows an Owner to nest/unnest their token', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
+ await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
// Create a nested token
@@ -82,7 +82,7 @@
it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});
+ await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
// Create a nested token
@@ -103,7 +103,7 @@
it('Fungible: allows an Owner to nest/unnest their token', async () => {
await usingApi(async api => {
const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});
+ await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});
const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});
const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
@@ -130,7 +130,7 @@
const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted: [collectionFT]}});
+ await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted: [collectionFT]}});
// Create a nested token
await expect(executeTransaction(api, alice, api.tx.unique.createItem(
@@ -150,7 +150,7 @@
it('ReFungible: allows an Owner to nest/unnest their token', async () => {
await usingApi(async api => {
const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});
+ await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});
const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});
const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
@@ -177,7 +177,7 @@
const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});
+ await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});
// Create a nested token
await expect(executeTransaction(api, alice, api.tx.unique.createItem(
@@ -204,7 +204,7 @@
it('Disallows excessive token nesting', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
+ await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
const maxNestingLevel = 5;
@@ -238,7 +238,7 @@
it('NFT: disallows to nest token if nesting is disabled', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Disabled'});
+ await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Disabled'});
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
// Try to create a nested token
@@ -260,7 +260,7 @@
it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
+ await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
await addToAllowListExpectSuccess(alice, collection, bob.address);
await enableAllowListExpectSuccess(alice, collection);
@@ -286,7 +286,7 @@
it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});
+ await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});
await addToAllowListExpectSuccess(alice, collection, bob.address);
await enableAllowListExpectSuccess(alice, collection);
@@ -312,7 +312,7 @@
it('NFT: disallows to nest token in an unlisted collection', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[]}});
+ await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[]}});
// Create a token to attempt to be nested into
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
@@ -336,7 +336,7 @@
it('Fungible: disallows to nest token if nesting is disabled', async () => {
await usingApi(async api => {
const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Disabled'});
+ await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});
const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
@@ -364,7 +364,7 @@
it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {
await usingApi(async api => {
const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});
+ await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});
await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
await enableAllowListExpectSuccess(alice, collectionNFT);
@@ -401,7 +401,7 @@
const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionFT]}});
+ await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionFT]}});
// Try to create a nested token in the wrong collection
await expect(executeTransaction(api, alice, api.tx.unique.createItem(
@@ -419,7 +419,7 @@
it('Fungible: disallows to nest token in an unlisted collection', async () => {
await usingApi(async api => {
const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});
+ await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});
// Create a token to attempt to be nested into
const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
@@ -445,7 +445,7 @@
it('ReFungible: disallows to nest token if nesting is disabled', async () => {
await usingApi(async api => {
const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Disabled'});
+ await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});
const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
@@ -475,7 +475,7 @@
it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {
await usingApi(async api => {
const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});
+ await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});
await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
await enableAllowListExpectSuccess(alice, collectionNFT);
@@ -512,7 +512,7 @@
const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});
+ await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});
// Try to create a nested token in the wrong collection
await expect(executeTransaction(api, alice, api.tx.unique.createItem(
@@ -530,7 +530,7 @@
it('ReFungible: disallows to nest token to an unlisted collection', async () => {
await usingApi(async api => {
const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});
+ await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});
// Create a token to attempt to be nested into
const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
tests/src/nesting/unnest.test.tsdiffbeforeafterboth1import {expect} from 'chai';2import {tokenIdToAddress} from '../eth/util/helpers';3import privateKey from '../substrate/privateKey';4import usingApi, {executeTransaction} from '../substrate/substrate-api';5import {6 createCollectionExpectSuccess,7 createItemExpectSuccess,8 getBalance,9 getTokenOwner,10 normalizeAccountId,11 setCollectionPermissionsExceptSuccess,12 transferExpectSuccess,13 transferFromExpectSuccess,14} from '../util/helpers';15import {IKeyringPair} from '@polkadot/types/types';1617let alice: IKeyringPair;18let bob: IKeyringPair;1920describe('Integration Test: Unnesting', () => {21 before(async () => {22 await usingApi(async () => {23 alice = privateKey('//Alice');24 bob = privateKey('//Bob');25 });26 });2728 it('NFT: allows the owner to successfully unnest a token', async () => {29 await usingApi(async api => {30 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});31 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});32 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');33 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};3435 // Create a nested token36 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', targetAddress);3738 // Unnest39 await expect(executeTransaction(40 api,41 alice,42 api.tx.unique.transferFrom(normalizeAccountId(targetAddress), normalizeAccountId(alice), collection, nestedToken, 1),43 ), 'while unnesting').to.not.be.rejected;44 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});4546 // Nest and burn47 await transferExpectSuccess(collection, nestedToken, alice, targetAddress);48 await expect(executeTransaction(49 api,50 alice,51 api.tx.unique.burnFrom(collection, normalizeAccountId(targetAddress), nestedToken, 1),52 ), 'while burning').to.not.be.rejected;53 await expect(getTokenOwner(api, collection, nestedToken)).to.be.rejected;54 });55 });5657 it('Fungible: allows the owner to successfully unnest a token', async () => {58 await usingApi(async api => {59 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});60 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});61 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');62 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};6364 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});65 const nestedToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');6667 // Nest and unnest68 await transferExpectSuccess(collectionFT, nestedToken, alice, targetAddress, 1, 'Fungible');69 await transferFromExpectSuccess(collectionFT, nestedToken, alice, targetAddress, alice, 1, 'Fungible');7071 // Nest and burn72 await transferExpectSuccess(collectionFT, nestedToken, alice, targetAddress, 1, 'Fungible');73 const balanceBefore = await getBalance(api, collectionFT, normalizeAccountId(targetAddress), nestedToken);74 await expect(executeTransaction(75 api,76 alice,77 api.tx.unique.burnFrom(collectionFT, normalizeAccountId(targetAddress), nestedToken, 1),78 ), 'while burning').to.not.be.rejected;79 const balanceAfter = await getBalance(api, collectionFT, normalizeAccountId(targetAddress), nestedToken);80 expect(balanceAfter + BigInt(1)).to.be.equal(balanceBefore);81 });82 });8384 it('ReFungible: allows the owner to successfully unnest a token', async () => {85 await usingApi(async api => {86 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});87 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});88 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');89 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};9091 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});92 const nestedToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');9394 // Nest and unnest95 await transferExpectSuccess(collectionRFT, nestedToken, alice, targetAddress, 1, 'ReFungible');96 await transferFromExpectSuccess(collectionRFT, nestedToken, alice, targetAddress, alice, 1, 'ReFungible');9798 // Nest and burn99 await transferExpectSuccess(collectionRFT, nestedToken, alice, targetAddress, 1, 'ReFungible');100 await expect(executeTransaction(101 api,102 alice,103 api.tx.unique.burnFrom(collectionRFT, normalizeAccountId(targetAddress), nestedToken, 1),104 ), 'while burning').to.not.be.rejected;105 const balance = await getBalance(api, collectionRFT, normalizeAccountId(targetAddress), nestedToken);106 expect(balance).to.be.equal(0n);107 });108 });109});110111describe('Negative Test: Unnesting', () => {112 before(async () => {113 await usingApi(async () => {114 alice = privateKey('//Alice');115 bob = privateKey('//Bob');116 });117 });118119 it('Disallows a non-owner to unnest/burn a token', async () => {120 await usingApi(async api => {121 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});122 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});123 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');124 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};125126 // Create a nested token127 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', targetAddress);128129 // Try to unnest130 await expect(executeTransaction(131 api,132 bob,133 api.tx.unique.transferFrom(normalizeAccountId(targetAddress), normalizeAccountId(bob), collection, nestedToken, 1),134 ), 'while unnesting').to.be.rejectedWith(/^common\.ApprovedValueTooLow$/);135 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});136137 // Try to burn138 await expect(executeTransaction(139 api,140 bob,141 api.tx.unique.burnFrom(collection, normalizeAccountId(bob.address), nestedToken, 1),142 ), 'while burning').to.not.be.rejectedWith(/^common\.ApprovedValueTooLow$/);143 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});144 });145 });146147 // todo another test for creating excessive depth matryoshka with Ethereum?148149 // Recursive nesting150 it('Prevents Ouroboros creation', async () => {151 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});152 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});153 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');154155 // Create a nested token ouroboros156 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});157 expect(transferExpectSuccess(collection, targetToken, alice, {Ethereum: tokenIdToAddress(collection, nestedToken)})).to.be.rejectedWith(/^structure\.OuroborosDetected$/);158 });159});1import {expect} from 'chai';2import {tokenIdToAddress} from '../eth/util/helpers';3import privateKey from '../substrate/privateKey';4import usingApi, {executeTransaction} from '../substrate/substrate-api';5import {6 createCollectionExpectSuccess,7 createItemExpectSuccess,8 getBalance,9 getTokenOwner,10 normalizeAccountId,11 setCollectionPermissionsExpectSuccess,12 transferExpectSuccess,13 transferFromExpectSuccess,14} from '../util/helpers';15import {IKeyringPair} from '@polkadot/types/types';1617let alice: IKeyringPair;18let bob: IKeyringPair;1920describe('Integration Test: Unnesting', () => {21 before(async () => {22 await usingApi(async () => {23 alice = privateKey('//Alice');24 bob = privateKey('//Bob');25 });26 });2728 it('NFT: allows the owner to successfully unnest a token', async () => {29 await usingApi(async api => {30 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});31 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});32 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');33 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};3435 // Create a nested token36 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', targetAddress);3738 // Unnest39 await expect(executeTransaction(40 api,41 alice,42 api.tx.unique.transferFrom(normalizeAccountId(targetAddress), normalizeAccountId(alice), collection, nestedToken, 1),43 ), 'while unnesting').to.not.be.rejected;44 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});4546 // Nest and burn47 await transferExpectSuccess(collection, nestedToken, alice, targetAddress);48 await expect(executeTransaction(49 api,50 alice,51 api.tx.unique.burnFrom(collection, normalizeAccountId(targetAddress), nestedToken, 1),52 ), 'while burning').to.not.be.rejected;53 await expect(getTokenOwner(api, collection, nestedToken)).to.be.rejected;54 });55 });5657 it('Fungible: allows the owner to successfully unnest a token', async () => {58 await usingApi(async api => {59 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});60 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});61 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');62 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};6364 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});65 const nestedToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');6667 // Nest and unnest68 await transferExpectSuccess(collectionFT, nestedToken, alice, targetAddress, 1, 'Fungible');69 await transferFromExpectSuccess(collectionFT, nestedToken, alice, targetAddress, alice, 1, 'Fungible');7071 // Nest and burn72 await transferExpectSuccess(collectionFT, nestedToken, alice, targetAddress, 1, 'Fungible');73 const balanceBefore = await getBalance(api, collectionFT, normalizeAccountId(targetAddress), nestedToken);74 await expect(executeTransaction(75 api,76 alice,77 api.tx.unique.burnFrom(collectionFT, normalizeAccountId(targetAddress), nestedToken, 1),78 ), 'while burning').to.not.be.rejected;79 const balanceAfter = await getBalance(api, collectionFT, normalizeAccountId(targetAddress), nestedToken);80 expect(balanceAfter + BigInt(1)).to.be.equal(balanceBefore);81 });82 });8384 it('ReFungible: allows the owner to successfully unnest a token', async () => {85 await usingApi(async api => {86 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});87 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});88 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');89 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};9091 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});92 const nestedToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');9394 // Nest and unnest95 await transferExpectSuccess(collectionRFT, nestedToken, alice, targetAddress, 1, 'ReFungible');96 await transferFromExpectSuccess(collectionRFT, nestedToken, alice, targetAddress, alice, 1, 'ReFungible');9798 // Nest and burn99 await transferExpectSuccess(collectionRFT, nestedToken, alice, targetAddress, 1, 'ReFungible');100 await expect(executeTransaction(101 api,102 alice,103 api.tx.unique.burnFrom(collectionRFT, normalizeAccountId(targetAddress), nestedToken, 1),104 ), 'while burning').to.not.be.rejected;105 const balance = await getBalance(api, collectionRFT, normalizeAccountId(targetAddress), nestedToken);106 expect(balance).to.be.equal(0n);107 });108 });109});110111describe('Negative Test: Unnesting', () => {112 before(async () => {113 await usingApi(async () => {114 alice = privateKey('//Alice');115 bob = privateKey('//Bob');116 });117 });118119 it('Disallows a non-owner to unnest/burn a token', async () => {120 await usingApi(async api => {121 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});122 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});123 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');124 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};125126 // Create a nested token127 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', targetAddress);128129 // Try to unnest130 await expect(executeTransaction(131 api,132 bob,133 api.tx.unique.transferFrom(normalizeAccountId(targetAddress), normalizeAccountId(bob), collection, nestedToken, 1),134 ), 'while unnesting').to.be.rejectedWith(/^common\.ApprovedValueTooLow$/);135 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});136137 // Try to burn138 await expect(executeTransaction(139 api,140 bob,141 api.tx.unique.burnFrom(collection, normalizeAccountId(bob.address), nestedToken, 1),142 ), 'while burning').to.not.be.rejectedWith(/^common\.ApprovedValueTooLow$/);143 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});144 });145 });146147 // todo another test for creating excessive depth matryoshka with Ethereum?148149 // Recursive nesting150 it('Prevents Ouroboros creation', async () => {151 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});152 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});153 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');154155 // Create a nested token ouroboros156 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});157 expect(transferExpectSuccess(collection, targetToken, alice, {Ethereum: tokenIdToAddress(collection, nestedToken)})).to.be.rejectedWith(/^structure\.OuroborosDetected$/);158 });159});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -554,7 +554,7 @@
});
}
-export const setCollectionPermissionsExceptSuccess = async (sender: IKeyringPair, collectionId: number, permissions: {mintMode?: boolean, access?: 'Normal' | 'AllowList', nesting?: 'Disabled' | 'Owner' | {OwnerRestricted: number[]}}) => {
+export const setCollectionPermissionsExpectSuccess = async (sender: IKeyringPair, collectionId: number, permissions: {mintMode?: boolean, access?: 'Normal' | 'AllowList', nesting?: 'Disabled' | 'Owner' | {OwnerRestricted: number[]}}) => {
await usingApi(async(api) => {
const tx = api.tx.unique.setCollectionPermissions(collectionId, permissions);
const events = await submitTransactionAsync(sender, tx);
@@ -1298,7 +1298,7 @@
await usingApi(async (api) => {
// Run the transaction
- const tx = api.tx.unique.setPublicAccessMode(collectionId, accessMode);
+ const tx = api.tx.unique.setCollectionPermissions(collectionId, {access: accessMode});
const events = await submitTransactionAsync(sender, tx);
const result = getGenericResult(events);
@@ -1319,7 +1319,7 @@
await usingApi(async (api) => {
// Run the transaction
- const tx = api.tx.unique.setPublicAccessMode(collectionId, accessMode);
+ const tx = api.tx.unique.setCollectionPermissions(collectionId, {access: accessMode});
const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
const result = getGenericResult(events);
@@ -1345,7 +1345,7 @@
await usingApi(async (api) => {
// Run the transaction
- const tx = api.tx.unique.setMintPermission(collectionId, enabled);
+ const tx = api.tx.unique.setCollectionPermissions(collectionId, {mintMode: enabled});
const events = await submitTransactionAsync(sender, tx);
const result = getGenericResult(events);
expect(result.success).to.be.true;