difftreelog
Quick fix for nesting tests
in: master
5 files changed
tests/src/nesting/graphs.test.tsdiffbeforeafterboth1import {ApiPromise} from '@polkadot/api';2import {IKeyringPair} from '@polkadot/types/types';3import {expect} from 'chai';4import {tokenIdToCross} from '../eth/util/helpers';5import privateKey from '../substrate/privateKey';6import usingApi, {executeTransaction} from '../substrate/substrate-api';7import {getCreateCollectionResult, transferExpectSuccess} from '../util/helpers';89/**10 * ```dot11 * 4 -> 3 -> 2 -> 112 * 7 -> 6 -> 5 -> 213 * 8 -> 514 * ```15 */16async function buildComplexObjectGraph(api: ApiPromise, sender: IKeyringPair): Promise<number> {17 const events = await executeTransaction(api, sender, api.tx.unique.createCollectionEx({mode: 'NFT', limits: {nestingRule: 'Owner'}}));18 const {collectionId} = getCreateCollectionResult(events);1920 await executeTransaction(api, sender, api.tx.unique.createMultipleItemsEx(collectionId, {NFT: Array(8).fill({owner: {Substrate: sender.address}})}));2122 await transferExpectSuccess(collectionId, 8, sender, tokenIdToCross(collectionId, 5));2324 await transferExpectSuccess(collectionId, 7, sender, tokenIdToCross(collectionId, 6));25 await transferExpectSuccess(collectionId, 6, sender, tokenIdToCross(collectionId, 5));26 await transferExpectSuccess(collectionId, 5, sender, tokenIdToCross(collectionId, 2));2728 await transferExpectSuccess(collectionId, 4, sender, tokenIdToCross(collectionId, 3));29 await transferExpectSuccess(collectionId, 3, sender, tokenIdToCross(collectionId, 2));30 await transferExpectSuccess(collectionId, 2, sender, tokenIdToCross(collectionId, 1));3132 return collectionId;33}3435describe('Graphs', () => {36 it('Ouroboros can\'t be created in a complex graph', async () => {37 await usingApi(async api => {38 const alice = privateKey('//Alice');39 const collection = await buildComplexObjectGraph(api, alice);4041 // to self42 await expect(43 executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 1), collection, 1, 1)),44 'first transaction', 45 ).to.be.rejectedWith(/structure\.OuroborosDetected/);46 // to nested part of graph47 await expect(48 executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 5), collection, 1, 1)),49 'second transaction',50 ).to.be.rejectedWith(/structure\.OuroborosDetected/);51 await expect(52 executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 8), collection, 2, 1)),53 'third transaction',54 ).to.be.rejectedWith(/structure\.OuroborosDetected/);55 });56 });57});tests/src/nesting/nest.test.tsdiffbeforeafterboth--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -8,11 +8,11 @@
createItemExpectSuccess,
enableAllowListExpectSuccess,
enablePublicMintingExpectSuccess,
- getTokenOwner,
+ getTokenOwner,
getTopmostTokenOwner,
- setCollectionLimitsExpectSuccess,
- transferExpectFailure,
- transferExpectSuccess,
+ setCollectionPermissionsExceptSuccess,
+ transferExpectFailure,
+ transferExpectSuccess,
transferFromExpectSuccess,
} from '../util/helpers';
import {IKeyringPair} from '@polkadot/types/types';
@@ -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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+ await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+ await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});
+ await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
+ await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionFT]}});
+ await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
+ await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionRFT]}});
+ await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+ await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
// Create a nested-token matryoshka
@@ -226,7 +226,7 @@
it('NFT: disallows to nest token if nesting is disabled', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Disabled'});
+ await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Disabled'});
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
// Try to create a nested token
@@ -248,7 +248,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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+ await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
await addToAllowListExpectSuccess(alice, collection, bob.address);
await enableAllowListExpectSuccess(alice, collection);
@@ -274,7 +274,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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});
+ await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});
await addToAllowListExpectSuccess(alice, collection, bob.address);
await enableAllowListExpectSuccess(alice, collection);
@@ -300,7 +300,7 @@
it('NFT: disallows to nest token in an unlisted collection', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[]}});
+ await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[]}});
// Create a token to attempt to be nested into
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
@@ -324,7 +324,7 @@
it('Fungible: disallows to nest token if nesting is disabled', async () => {
await usingApi(async api => {
const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Disabled'});
+ await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Disabled'});
const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
@@ -352,7 +352,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 setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
+ await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});
await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
await enableAllowListExpectSuccess(alice, collectionNFT);
@@ -389,7 +389,7 @@
const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionFT]}});
+ await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionFT]}});
// Try to create a nested token in the wrong collection
await expect(executeTransaction(api, alice, api.tx.unique.createItem(
@@ -407,7 +407,7 @@
it('Fungible: disallows to nest token in an unlisted collection', async () => {
await usingApi(async api => {
const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}});
+ await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});
// Create a token to attempt to be nested into
const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
@@ -433,7 +433,7 @@
it('ReFungible: disallows to nest token if nesting is disabled', async () => {
await usingApi(async api => {
const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Disabled'});
+ await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Disabled'});
const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
@@ -463,7 +463,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 setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
+ await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});
await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
await enableAllowListExpectSuccess(alice, collectionNFT);
@@ -500,7 +500,7 @@
const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionRFT]}});
+ await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});
// Try to create a nested token in the wrong collection
await expect(executeTransaction(api, alice, api.tx.unique.createItem(
@@ -518,7 +518,7 @@
it('ReFungible: disallows to nest token to an unlisted collection', async () => {
await usingApi(async api => {
const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}});
+ await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});
// Create a token to attempt to be nested into
const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
tests/src/nesting/rules-smoke.test.tsdiffbeforeafterboth--- a/tests/src/nesting/rules-smoke.test.ts
+++ b/tests/src/nesting/rules-smoke.test.ts
@@ -14,8 +14,8 @@
const bob = privateKey('//Bob');
const events = await executeTransaction(api, alice, api.tx.unique.createCollectionEx({
mode: 'NFT',
- limits: {
- nestingRule: {OwnerRestricted: []},
+ permissions: {
+ nesting: {OwnerRestricted: []},
},
}));
const collection = getCreateCollectionResult(events).collectionId;
@@ -39,7 +39,7 @@
it('called for nonfungible', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await expect(executeTransaction(api, alice, api.tx.unique.createItem(collection, nestTarget, {NFT: {ConstData: []}})))
+ await expect(executeTransaction(api, alice, api.tx.unique.createItem(collection, nestTarget, {NFT: {properties: []}})))
.to.be.rejectedWith(/^common\.SourceCollectionIsNotAllowedToNest$/);
const token = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
@@ -51,7 +51,7 @@
it('called for refungible', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- await expect(executeTransaction(api, alice, api.tx.unique.createItem(collection, nestTarget, {ReFungible: {ConstData: []}})))
+ await expect(executeTransaction(api, alice, api.tx.unique.createItem(collection, nestTarget, {ReFungible: {}})))
.to.be.rejectedWith(/^common\.SourceCollectionIsNotAllowedToNest$/);
const token = await createItemExpectSuccess(alice, collection, 'ReFungible', {Substrate: alice.address});
tests/src/nesting/unnest.test.tsdiffbeforeafterboth--- a/tests/src/nesting/unnest.test.ts
+++ b/tests/src/nesting/unnest.test.ts
@@ -8,7 +8,7 @@
getBalance,
getTokenOwner,
normalizeAccountId,
- setCollectionLimitsExpectSuccess,
+ setCollectionPermissionsExceptSuccess,
transferExpectSuccess,
transferFromExpectSuccess,
} from '../util/helpers';
@@ -28,7 +28,7 @@
it('NFT: allows the owner to successfully unnest a token', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+ await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
@@ -57,7 +57,7 @@
it('Fungible: allows the owner to successfully unnest a token', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+ await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
@@ -84,7 +84,7 @@
it('ReFungible: allows the owner to successfully unnest a token', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+ await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
@@ -119,7 +119,7 @@
it('Disallows a non-owner to unnest/burn a token', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+ await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
@@ -149,7 +149,7 @@
// Recursive nesting
it('Prevents Ouroboros creation', async () => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+ await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
// Create a nested token ouroboros
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -325,7 +325,7 @@
};
export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {
- const {name, description, mode, tokenPrefix, schemaVersion} = {...defaultCreateCollectionParams, ...params};
+ const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};
let collectionId = 0;
await usingApi(async (api) => {
@@ -348,8 +348,7 @@
name: strToUTF16(name),
description: strToUTF16(description),
tokenPrefix: strToUTF16(tokenPrefix),
- mode: modeprm as any,
- schemaVersion: schemaVersion,
+ mode: modeprm as any
});
const events = await submitTransactionAsync(alicePrivateKey, tx);
const result = getCreateCollectionResult(events);
@@ -555,6 +554,16 @@
});
}
+export const setCollectionPermissionsExceptSuccess = 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);
+ const result = getGenericResult(events);
+
+ expect(result.success).to.be.true;
+ });
+}
+
export async function setCollectionLimitsExpectFailure(sender: IKeyringPair, collectionId: number, limits: any) {
await usingApi(async (api) => {
const tx = api.tx.unique.setCollectionLimits(collectionId, limits);
@@ -1299,7 +1308,7 @@
// What to expect
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
- expect(collection.access.toHuman()).to.be.equal(accessMode);
+ expect(collection.permissions.access.toHuman()).to.be.equal(accessMode);
});
}
@@ -1344,7 +1353,7 @@
// Get the collection
const collection = await queryCollectionExpectSuccess(api, collectionId);
- expect(collection.mintMode.toHuman()).to.be.equal(enabled);
+ expect(collection.permissions.mintMode.toHuman()).to.be.equal(enabled);
});
}