difftreelog
test(structure) extra nesting + properties refactoring
in: master
7 files changed
tests/src/createItem.test.tsdiffbeforeafterboth--- a/tests/src/createItem.test.ts
+++ b/tests/src/createItem.test.ts
@@ -144,7 +144,6 @@
it('User doesnt have editing rights', async () => {
await usingApi(async api => {
- const createMode = 'NFT';
const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});
const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');
tests/src/createMultipleItems.test.tsdiffbeforeafterboth--- a/tests/src/createMultipleItems.test.ts
+++ b/tests/src/createMultipleItems.test.ts
@@ -146,7 +146,6 @@
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},
{Nft: {const_data: '0x32', variable_data: '0x32'}},
{Nft: {const_data: '0x33', variable_data: '0x33'}}];
@@ -182,7 +181,6 @@
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},
{Nft: {const_data: '0x32', variable_data: '0x32'}},
{Nft: {const_data: '0x33', variable_data: '0x33'}}];
@@ -218,7 +216,6 @@
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},
{Nft: {const_data: '0x32', variable_data: '0x32'}},
{Nft: {const_data: '0x33', variable_data: '0x33'}}];
tests/src/nesting/migration-check.test.tsdiffbeforeafterboth--- a/tests/src/nesting/migration-check.test.ts
+++ b/tests/src/nesting/migration-check.test.ts
@@ -8,8 +8,8 @@
// Used for polkadot-launch signalling
import find from 'find-process';
-// todo skip
-describe('Migration testing for pallet-common', () => {
+// todo un-skip for migrations
+describe.skip('Migration testing for pallet-common', () => {
let alice: IKeyringPair;
before(async() => {
@@ -63,16 +63,33 @@
});
// And wait for the parachain upgrade
- while (newVersion == oldVersion! && connectionFailCounter < 2) {
- try {
- await usingApi(async api => {
- await waitNewBlocks(api);
- newVersion = (api.consts.system.version.toJSON() as any).specVersion;
- });
- } catch (_) {
- connectionFailCounter++;
- console.log(`Still waiting for the parachain upgrade from ${oldVersion!}...`);
- await new Promise(resolve => setTimeout(resolve, 12000));
+ {
+ // Catch warnings like 'RPC methods not decorated' and keep the 'waiting' message in front
+ const stdlog = console.warn.bind(console);
+ let warnCount = 0;
+ console.warn = function(...args){
+ if (arguments.length <= 2 || !args[2].includes('RPC methods not decorated')) {
+ warnCount++;
+ stdlog.apply(console, args as any);
+ }
+ };
+
+ let oldWarnCount = 0;
+ while (newVersion == oldVersion! && connectionFailCounter < 2) {
+ try {
+ await usingApi(async api => {
+ await waitNewBlocks(api);
+ newVersion = (api.consts.system.version.toJSON() as any).specVersion;
+ if (warnCount > oldWarnCount) {
+ console.log(`Still waiting for the parachain upgrade from ${oldVersion!}...`);
+ oldWarnCount = warnCount;
+ }
+ await new Promise(resolve => setTimeout(resolve, 6000));
+ });
+ } catch (_) {
+ connectionFailCounter++;
+ await new Promise(resolve => setTimeout(resolve, 12000));
+ }
}
}
tests/src/nesting/nest.test.tsdiffbeforeafterboth--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -9,8 +9,7 @@
enableAllowListExpectSuccess,
enablePublicMintingExpectSuccess,
getTokenOwner,
- getTopmostTokenOwner,
- normalizeAccountId,
+ getTopmostTokenOwner,
setCollectionLimitsExpectSuccess,
transferExpectFailure,
transferExpectSuccess,
@@ -23,7 +22,7 @@
describe('Integration Test: Nesting', () => {
before(async () => {
- await usingApi(async api => {
+ await usingApi(async () => {
alice = privateKey('//Alice');
bob = privateKey('//Bob');
});
@@ -196,7 +195,7 @@
describe('Negative Test: Nesting', async() => {
before(async () => {
- await usingApi(async api => {
+ await usingApi(async () => {
alice = privateKey('//Alice');
bob = privateKey('//Bob');
});
@@ -212,14 +211,11 @@
const nestedToken1 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});
const nestedToken2 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, nestedToken1)});
// The nesting depth is limited by 2
- await expect(executeTransaction(
- api, alice,
- api.tx.unique.createItem(
- collection,
- {Ethereum: tokenIdToAddress(collection, nestedToken2)},
+ await expect(executeTransaction(api, alice, api.tx.unique.createItem(
+ collection,
+ {Ethereum: tokenIdToAddress(collection, nestedToken2)},
{nft: {const_data: [], variable_data: []}} as any,
- ),
- ), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/); // OuroborosDetected?
+ )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);
expect(await getTopmostTokenOwner(api, collection, nestedToken2)).to.be.deep.equal({Substrate: alice.address});
});
@@ -234,24 +230,16 @@
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
// Try to create a nested token
- await expect(executeTransaction(
- api, alice,
- api.tx.unique.createItem(
- collection,
- {Ethereum: tokenIdToAddress(collection, targetToken)},
+ await expect(executeTransaction(api, alice, api.tx.unique.createItem(
+ collection,
+ {Ethereum: tokenIdToAddress(collection, targetToken)},
{nft: {const_data: [], variable_data: []}} as any,
- ),
- ), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);
+ )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);
// Create a token to be nested
const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
// Try to nest
- await expect(executeTransaction(
- api, alice,
- api.tx.unique.transfer(
- normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,
- ),
- ), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/); // todo to.be.rejected for all
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);
expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
});
@@ -270,23 +258,15 @@
const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');
// Try to create a nested token in the wrong collection
- await expect(executeTransaction(
- api, alice,
- api.tx.unique.createItem(
- collection,
- {Ethereum: tokenIdToAddress(collection, targetToken)},
+ await expect(executeTransaction(api, alice, api.tx.unique.createItem(
+ collection,
+ {Ethereum: tokenIdToAddress(collection, targetToken)},
{nft: {const_data: [], variable_data: []}} as any,
- ),
- ), 'while creating nested token').to.be.rejectedWith(/structure\.DepthLimit/); // todo NestingIsDisabled?
+ )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);
// Try to create and nest a token in the wrong collection
const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
- await expect(executeTransaction(
- api, alice,
- api.tx.unique.transfer(
- normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,
- ),
- ), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);
expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
});
});
@@ -304,23 +284,15 @@
const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');
// Try to create a nested token in the wrong collection
- await expect(executeTransaction(
- api, alice,
- api.tx.unique.createItem(
- collection,
- {Ethereum: tokenIdToAddress(collection, targetToken)},
+ await expect(executeTransaction(api, alice, api.tx.unique.createItem(
+ collection,
+ {Ethereum: tokenIdToAddress(collection, targetToken)},
{nft: {const_data: [], variable_data: []}} as any,
- ),
- ), 'while creating nested token').to.be.rejectedWith(/structure\.DepthLimit/);
+ )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);
// Try to create and nest a token in the wrong collection
const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
- await expect(executeTransaction(
- api, alice,
- api.tx.unique.transfer(
- normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,
- ),
- ), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);
expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
});
});
@@ -334,23 +306,15 @@
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
// Try to create a nested token in the wrong collection
- await expect(executeTransaction(
- api, alice,
- api.tx.unique.createItem(
- collection,
- {Ethereum: tokenIdToAddress(collection, targetToken)},
+ await expect(executeTransaction(api, alice, api.tx.unique.createItem(
+ collection,
+ {Ethereum: tokenIdToAddress(collection, targetToken)},
{nft: {const_data: [], variable_data: []}} as any,
- ),
- ), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
+ )), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
// Try to create and nest a token in the wrong collection
const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
- await expect(executeTransaction(
- api, alice,
- api.tx.unique.transfer(
- normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,
- ),
- ), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
});
});
@@ -367,24 +331,21 @@
const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
// Try to create a nested token
- await expect(executeTransaction(
- api, alice,
- api.tx.unique.createItem(
- collectionFT,
- targetAddress,
- {Fungible: {Value: 10}},
- )
- ), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);
-
+ await expect(executeTransaction(api, alice, api.tx.unique.createItem(
+ collectionFT,
+ targetAddress,
+ {Fungible: {Value: 10}},
+ )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);
+
// Create a token to be nested
const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
// Try to nest
- await expect(executeTransaction(
- api, alice,
- api.tx.unique.transfer(
- normalizeAccountId({Ethereum: tokenIdToAddress(collectionFT, targetToken)}), collectionFT, newToken, 1,
- ),
- ), 'while nesting new token').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);
+
+ // Create another token to be nested
+ const newToken2 = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
+ // Try to nest inside a fungible token
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionFT, newToken)}, collectionFT, newToken2, 1)), 'while nesting new token inside fungible').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);
});
});
@@ -404,31 +365,21 @@
const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
// Try to create a nested token in the wrong collection
- await expect(executeTransaction(
- api, alice,
- api.tx.unique.createItem(
- collectionFT,
- targetAddress,
- {Fungible: {Value: 10}},
- )
- ), 'while creating nested token').to.be.rejectedWith(/structure\.DepthLimit/);
+ await expect(executeTransaction(api, alice, api.tx.unique.createItem(
+ collectionFT,
+ targetAddress,
+ {Fungible: {Value: 10}},
+ )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);
// Try to create and nest a token in the wrong collection
const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
- await expect(executeTransaction(
- api, alice,
- api.tx.unique.transfer(
- normalizeAccountId({Ethereum: tokenIdToAddress(collectionFT, targetToken)}), collectionFT, newToken, 1,
- ),
- ), 'while nesting new token').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);
});
});
it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {
await usingApi(async api => {
const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionNFT]}}); // todo clear redundant restrictions?
-
await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
await enableAllowListExpectSuccess(alice, collectionNFT);
await enablePublicMintingExpectSuccess(alice, collectionNFT);
@@ -438,17 +389,18 @@
const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+ await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionFT]}});
// Try to create a nested token in the wrong collection
await expect(executeTransaction(api, alice, api.tx.unique.createItem(
collectionFT,
targetAddress,
{Fungible: {Value: 10}},
- ))).to.be.rejected;
+ )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);
// Try to create and nest a token in the wrong collection
const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
- await transferExpectFailure(collectionFT, newToken, alice, targetAddress, 1);
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);
});
});
@@ -468,11 +420,11 @@
collectionFT,
targetAddress,
{Fungible: {Value: 10}},
- ))).to.be.rejected;
+ )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
// Try to create and nest a token in the wrong collection
const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
- await transferExpectFailure(collectionFT, newToken, alice, targetAddress, 1);
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
});
});
@@ -492,12 +444,19 @@
collectionRFT,
targetAddress,
{ReFungible: {const_data: [], pieces: 100}},
- ))).to.be.rejectedWith(/^common\.NestingIsDisabled$/);
+ )), 'while creating a nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);
// Create a token to be nested
const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');
// Try to nest
await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);
+ // Try to nest
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);
+
+ // Create another token to be nested
+ const newToken2 = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');
+ // Try to nest inside a fungible token
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionRFT, newToken)}, collectionRFT, newToken2, 1)), 'while nesting new token inside refungible').to.be.rejectedWith(/refungible\.RefungibleDisallowsNesting/);
});
});
@@ -521,19 +480,17 @@
collectionRFT,
targetAddress,
{ReFungible: {const_data: [], pieces: 100}},
- ))).to.be.rejected;
+ )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);
// Try to create and nest a token in the wrong collection
const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');
- await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);
});
});
it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {
await usingApi(async api => {
const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionNFT]}});
-
await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
await enableAllowListExpectSuccess(alice, collectionNFT);
await enablePublicMintingExpectSuccess(alice, collectionNFT);
@@ -543,17 +500,18 @@
const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionRFT]}});
// Try to create a nested token in the wrong collection
await expect(executeTransaction(api, alice, api.tx.unique.createItem(
collectionRFT,
targetAddress,
{ReFungible: {const_data: [], pieces: 100}},
- ))).to.be.rejected;
+ )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);
// Try to create and nest a token in the wrong collection
const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');
- await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);
});
});
@@ -573,11 +531,11 @@
collectionRFT,
targetAddress,
{ReFungible: {const_data: [], pieces: 100}},
- ))).to.be.rejected;
+ )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
// Try to create and nest a token in the wrong collection
const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');
- await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
});
});
});
tests/src/nesting/properties.test.tsdiffbeforeafterboth--- a/tests/src/nesting/properties.test.ts
+++ b/tests/src/nesting/properties.test.ts
@@ -18,7 +18,7 @@
describe('Integration Test: Collection Properties', () => {
before(async () => {
- await usingApi(async api => {
+ await usingApi(async () => {
alice = privateKey('//Alice');
bob = privateKey('//Bob');
});
@@ -113,7 +113,7 @@
describe('Negative Integration Test: Collection Properties', () => {
before(async () => {
- await usingApi(async api => {
+ await usingApi(async () => {
alice = privateKey('//Alice');
bob = privateKey('//Bob');
});
@@ -213,13 +213,13 @@
api,
alice,
api.tx.unique.setCollectionProperties(collection, [{key: '', value: 'nothing must not exist'}]),
- ), `on rejecting an unnamed property`).to.be.rejectedWith(/common\.EmptyPropertyKey/);
+ ), 'on rejecting an unnamed property').to.be.rejectedWith(/common\.EmptyPropertyKey/);
await expect(executeTransaction(
api,
alice,
api.tx.unique.setCollectionProperties(collection, [
- {key: 'CRISPR-Cas9', value: 'rewriting nature!'}
+ {key: 'CRISPR-Cas9', value: 'rewriting nature!'},
]),
), 'on setting the correctly-but-still-badly-named property').to.not.be.rejected;
@@ -245,7 +245,7 @@
describe('Integration Test: Access Rights to Token Properties', () => {
before(async () => {
- await usingApi(async api => {
+ await usingApi(async () => {
alice = privateKey('//Alice');
bob = privateKey('//Bob');
});
@@ -311,7 +311,7 @@
describe('Negative Integration Test: Access Rights to Token Properties', () => {
before(async () => {
- await usingApi(async api => {
+ await usingApi(async () => {
alice = privateKey('//Alice');
bob = privateKey('//Bob');
});
@@ -400,7 +400,7 @@
api,
alice,
api.tx.unique.setPropertyPermissions(collection, [{key: '', permission: {}}]),
- ), `on rejecting an unnamed property`).to.be.rejectedWith(/common\.EmptyPropertyKey/);
+ ), 'on rejecting an unnamed property').to.be.rejectedWith(/common\.EmptyPropertyKey/);
const correctKey = '--0x03116e387820CA05'; // PolkadotJS would parse this as an already encoded hex-string
await expect(executeTransaction(
@@ -429,7 +429,7 @@
let permissions: {permission: any, signers: IKeyringPair[]}[];
before(async () => {
- await usingApi(async api => {
+ await usingApi(async () => {
alice = privateKey('//Alice');
bob = privateKey('//Bob');
charlie = privateKey('//Charlie');
@@ -446,10 +446,12 @@
});
beforeEach(async () => {
- collection = await createCollectionExpectSuccess();
- token = await createItemExpectSuccess(alice, collection, 'NFT');
- await addCollectionAdminExpectSuccess(alice, collection, bob.address);
- await transferExpectSuccess(collection, token, alice, charlie);
+ await usingApi(async () => {
+ collection = await createCollectionExpectSuccess();
+ token = await createItemExpectSuccess(alice, collection, 'NFT');
+ await addCollectionAdminExpectSuccess(alice, collection, bob.address);
+ await transferExpectSuccess(collection, token, alice, charlie);
+ });
});
it('Reads yet empty properties of a token', async () => {
@@ -592,7 +594,7 @@
let constitution: {permission: any, signers: IKeyringPair[], sinner: IKeyringPair}[];
before(async () => {
- await usingApi(async api => {
+ await usingApi(async () => {
alice = privateKey('//Alice');
bob = privateKey('//Bob');
charlie = privateKey('//Charlie');
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 createItemExpectFailure,8 createItemExpectSuccess,9 getBalance,10 getTokenOwner,11 getTopmostTokenOwner,12 normalizeAccountId,13 setCollectionLimitsExpectSuccess,14 transferExpectSuccess,15 transferFromExpectSuccess,16} from '../util/helpers';17import {IKeyringPair} from '@polkadot/types/types';1819let alice: IKeyringPair;20let bob: IKeyringPair;2122describe('Integration Test: Unnesting', () => {23 before(async () => {24 await usingApi(async api => {25 alice = privateKey('//Alice');26 bob = privateKey('//Bob');27 });28 });2930 it('NFT: allows the owner to successfully unnest a token', async () => {31 await usingApi(async api => {32 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});33 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});34 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');35 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};3637 // Create a nested token38 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', targetAddress);3940 // Unnest41 await expect(executeTransaction(42 api,43 alice,44 api.tx.unique.transferFrom(normalizeAccountId(targetAddress), normalizeAccountId(alice), collection, nestedToken, 1),45 ), 'while unnesting').to.not.be.rejected;46 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});4748 // Nest and burn49 await transferExpectSuccess(collection, nestedToken, alice, targetAddress);50 await expect(executeTransaction(51 api,52 alice,53 api.tx.unique.burnFrom(collection, normalizeAccountId(targetAddress), nestedToken, 1),54 ), 'while burning').to.not.be.rejected;55 await expect(getTokenOwner(api, collection, nestedToken)).to.be.rejected;56 });57 });5859 it('Fungible: allows the owner to successfully unnest a token', async () => {60 await usingApi(async api => {61 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});62 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});63 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');64 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};6566 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});67 const nestedToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');6869 // Nest and unnest70 await transferExpectSuccess(collectionFT, nestedToken, alice, targetAddress, 1, 'Fungible');71 await transferFromExpectSuccess(collectionFT, nestedToken, alice, targetAddress, alice, 1, 'Fungible');7273 // Nest and burn74 await transferExpectSuccess(collectionFT, nestedToken, alice, targetAddress, 1, 'Fungible');75 const balanceBefore = await getBalance(api, collectionFT, normalizeAccountId(targetAddress), nestedToken);76 await expect(executeTransaction(77 api,78 alice,79 api.tx.unique.burnFrom(collectionFT, normalizeAccountId(targetAddress), nestedToken, 1),80 ), 'while burning').to.not.be.rejected;81 const balanceAfter = await getBalance(api, collectionFT, normalizeAccountId(targetAddress), nestedToken);82 expect(balanceAfter + BigInt(1)).to.be.equal(balanceBefore);83 });84 });8586 it('ReFungible: allows the owner to successfully unnest a token', async () => {87 await usingApi(async api => {88 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});89 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});90 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');91 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};9293 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});94 const nestedToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');9596 // Nest and unnest97 await transferExpectSuccess(collectionRFT, nestedToken, alice, targetAddress, 1, 'ReFungible');98 await transferFromExpectSuccess(collectionRFT, nestedToken, alice, targetAddress, alice, 1, 'ReFungible');99100 // Nest and burn101 await transferExpectSuccess(collectionRFT, nestedToken, alice, targetAddress, 1, 'ReFungible');102 await expect(executeTransaction(103 api,104 alice,105 api.tx.unique.burnFrom(collectionRFT, normalizeAccountId(targetAddress), nestedToken, 1),106 ), 'while burning').to.not.be.rejected;107 const balance = await getBalance(api, collectionRFT, normalizeAccountId(targetAddress), nestedToken);108 expect(balance).to.be.equal(0n);109 });110 });111});112113describe('Negative Test: Unnesting', () => {114 before(async () => {115 await usingApi(async api => {116 alice = privateKey('//Alice');117 bob = privateKey('//Bob');118 });119 });120121 it('Disallows a non-owner to unnest/burn a token', async () => {122 await usingApi(async api => {123 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});124 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});125 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');126 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};127128 // Create a nested token129 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', targetAddress);130131 // Try to unnest132 await expect(executeTransaction(133 api,134 bob,135 api.tx.unique.transferFrom(normalizeAccountId(targetAddress), normalizeAccountId(bob), collection, nestedToken, 1),136 ), 'while unnesting').to.be.rejectedWith(/^structure\.DepthLimit$/); // todo ApprovedValueTooLow?137 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});138139 // Try to burn140 await expect(executeTransaction(141 api,142 bob,143 api.tx.unique.burnFrom(collection, normalizeAccountId(bob.address), nestedToken, 1),144 ), 'while burning').to.not.be.rejectedWith(/^common\.ApprovedValueTooLow$/);145 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});146 });147 });148149 // todo another test for creating excessive depth matryoshka with Ethereum?150151 // Recursive nesting152 it('Prevents Ouroboros creation', async () => {153 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});154 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});155 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');156157 // Create a nested token ouroboros158 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});159 expect(transferExpectSuccess(collection, targetToken, alice, {Ethereum: tokenIdToAddress(collection, nestedToken)})).to.be.rejectedWith(/^structure\.OuroborosDetected$/);160 });161});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 setCollectionLimitsExpectSuccess,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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: '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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: '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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: '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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: '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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: '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
@@ -427,7 +427,6 @@
export async function createCollectionWithPropsExpectFailure(params: Partial<CreateCollectionParams> = {}) {
const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};
- const collectionId = 0;
await usingApi(async (api) => {
// Get number of collections before the transaction
const collectionCountBefore = await getCreatedCollectionCount(api);