difftreelog
CreateItem* tests fixes
in: master
4 files changed
tests/src/createItem.test.tsdiffbeforeafterboth23 createItemExpectSuccess,23 createItemExpectSuccess,24 addCollectionAdminExpectSuccess,24 addCollectionAdminExpectSuccess,25 createCollectionWithPropsExpectSuccess,25 createCollectionWithPropsExpectSuccess,26 createItemWithPropsExpectSuccess,26} from './util/helpers';27} from './util/helpers';272828const expect = chai.expect;29const expect = chai.expect;29let alice: IKeyringPair;30let alice: IKeyringPair;30let bob: IKeyringPair;31let bob: IKeyringPair;313232describe('integration test: ext. createItem():', () => {33describe('integration test: ext. ():', () => {33 before(async () => {34 before(async () => {34 await usingApi(async () => {35 await usingApi(async () => {35 const keyring = new Keyring({type: 'sr25519'});36 const keyring = new Keyring({type: 'sr25519'});75 it('Set property Admin', async () => {76 it('Set property Admin', async () => {76 const createMode = 'NFT';77 const createMode = 'NFT';77 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 78 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 78 properties: [{key: 'key1', value: 'val1'}], 79 propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: false}]});79 propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});80 80 81 await createItemExpectSuccess(alice, newCollectionID, createMode);81 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'k', value: 't2'}]);82 });82 });838384 it('Set property AdminConst', async () => {84 it('Set property AdminConst', async () => {85 const createMode = 'NFT';85 const createMode = 'NFT';86 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 86 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 87 properties: [{key: 'key1', value: 'val1'}], 88 propPerm: [{key: 'key1', mutable: false, collectionAdmin: true, tokenOwner: false}]});87 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});89 88 90 await createItemExpectSuccess(alice, newCollectionID, createMode);89 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);91 });90 });929193 it('Set property itemOwnerOrAdmin', async () => {92 it('Set property itemOwnerOrAdmin', async () => {94 const createMode = 'NFT';93 const createMode = 'NFT';95 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 94 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},96 properties: [{key: 'key1', value: 'val1'}], 97 propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: true}]});95 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});98 96 99 await createItemExpectSuccess(alice, newCollectionID, createMode);97 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);100 });98 });101});99});102100129 await usingApi(async api => {127 await usingApi(async api => {130 const createMode = 'NFT';128 const createMode = 'NFT';131 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 129 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 132 propPerm: [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});130 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});133131134 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');132 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');135 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);133 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);144142145 it('User doesnt have editing rights', async () => {143 it('User doesnt have editing rights', async () => {146 await usingApi(async api => {144 await usingApi(async api => {147 const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});145 const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});148 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');146 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');149147150 await expect(executeTransaction(148 await expect(executeTransaction(tests/src/createMultipleItems.test.tsdiffbeforeafterboth--- a/tests/src/createMultipleItems.test.ts
+++ b/tests/src/createMultipleItems.test.ts
@@ -34,6 +34,7 @@
getCreatedCollectionCount,
createCollectionWithPropsExpectSuccess,
getCreateItemsResult,
+ createMultipleItemsWithPropsExpectSuccess
} from './util/helpers';
chai.use(chaiAsPromised);
@@ -133,25 +134,18 @@
it('Create 0x31, 0x32, 0x33 items in active NFT with property Admin', async () => {
await usingApi(async (api: ApiPromise) => {
- const collectionId = await createCollectionExpectSuccess();
+ const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});
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'}},
- {Nft: {const_data: '0x32'}},
- {Nft: {const_data: '0x33'}}];
- const createMultipleItemsTx = api.tx.unique
- .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
- await submitTransactionAsync(alice, createMultipleItemsTx);
+ const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v1'}]}},
+ {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'v2'}]}},
+ {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'v3'}]}}];
+
+ await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);
const itemsListIndexAfter = await getLastTokenId(api, collectionId);
expect(itemsListIndexAfter).to.be.equal(3);
-
- await expect(executeTransaction(
- api,
- alice,
- api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]),
- )).to.not.be.rejected;
expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));
expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));
@@ -165,26 +159,20 @@
it('Create 0x31, 0x32, 0x33 items in active NFT with property AdminConst', async () => {
await usingApi(async (api: ApiPromise) => {
- const collectionId = await createCollectionExpectSuccess();
+ const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});
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'}},
- {Nft: {const_data: '0x32'}},
- {Nft: {const_data: '0x33'}}];
- const createMultipleItemsTx = api.tx.unique
- .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
- await submitTransactionAsync(alice, createMultipleItemsTx);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v1'}]}},
+ {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'v2'}]}},
+ {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'v3'}]}}];
+
+ await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);
const itemsListIndexAfter = await getLastTokenId(api, collectionId);
expect(itemsListIndexAfter).to.be.equal(3);
- await expect(executeTransaction(
- api,
- alice,
- api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]),
- )).to.not.be.rejected;
-
expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));
expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));
expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));
@@ -197,25 +185,18 @@
it('Create 0x31, 0x32, 0x33 items in active NFT with property itemOwnerOrAdmin', async () => {
await usingApi(async (api: ApiPromise) => {
- const collectionId = await createCollectionExpectSuccess();
+ const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});
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'}},
- {Nft: {const_data: '0x32'}},
- {Nft: {const_data: '0x33'}}];
- const createMultipleItemsTx = api.tx.unique
- .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
- await submitTransactionAsync(alice, createMultipleItemsTx);
+ const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v1'}]}},
+ {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'v2'}]}},
+ {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'v3'}]}}];
+
+ await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);
const itemsListIndexAfter = await getLastTokenId(api, collectionId);
expect(itemsListIndexAfter).to.be.equal(3);
-
- await expect(executeTransaction(
- api,
- alice,
- api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]),
- )).to.not.be.rejected;
expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));
expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));
@@ -451,7 +432,7 @@
it('No editing rights', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],
- propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});
+ propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
@@ -479,7 +460,7 @@
it('User doesnt have editing rights', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],
- propPerm: [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});
+ propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
@@ -530,7 +511,7 @@
it('Adding more than 64 prps', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],
- propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: false}]});
+ propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
@@ -565,7 +546,7 @@
it('Trying to add bigger property than allowed', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],
- propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});
+ propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
const args = [{Nft: {const_data: '0x31'}},
tests/src/createMultipleItemsEx.test.tsdiffbeforeafterboth--- a/tests/src/createMultipleItemsEx.test.ts
+++ b/tests/src/createMultipleItemsEx.test.ts
@@ -48,8 +48,8 @@
});
});
- it('createMultipleItemsEx with property Admin', async () => {
- const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ it.only('createMultipleItemsEx with property Admin', async () => {
+ const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
@@ -57,33 +57,30 @@
const data = [
{
owner: {substrate: alice.address},
- constData: '0x0000',
+ constData: '0x1111',
+ properties: [{key: 'k', value: 'v1'}],
}, {
owner: {substrate: bob.address},
constData: '0x2222',
+ properties: [{key: 'k', value: 'v2'}],
}, {
owner: {substrate: charlie.address},
constData: '0x4444',
+ properties: [{key: 'k', value: 'v3'}],
},
];
-
- await expect(executeTransaction(
- api,
- alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]),
- )).to.not.be.rejected;
await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {
NFT: data,
}));
- const tokens = await api.query.nonfungible.tokenData.entries(collection);
- const json = tokens.map(([, token]) => token.toJSON());
- expect(json).to.be.deep.equal(data);
+ for (let i = 1; i < 4; i++) {
+ expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;
+ }
});
});
it('createMultipleItemsEx with property AdminConst', async () => {
- const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
@@ -92,33 +89,29 @@
{
owner: {substrate: alice.address},
constData: '0x0000',
+ properties: [{key: 'k', value: 'v1'}],
}, {
owner: {substrate: bob.address},
constData: '0x2222',
+ properties: [{key: 'k', value: 'v2'}],
}, {
owner: {substrate: charlie.address},
constData: '0x4444',
+ properties: [{key: 'k', value: 'v3'}],
},
];
- await expect(executeTransaction(
- api,
- alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]),
- )).to.not.be.rejected;
await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {
NFT: data,
}));
-
-
- const tokens = await api.query.nonfungible.tokenData.entries(collection);
- const json = tokens.map(([, token]) => token.toJSON());
- expect(json).to.be.deep.equal(data);
+ for (let i = 1; i < 4; i++) {
+ expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;
+ }
});
});
it('createMultipleItemsEx with property itemOwnerOrAdmin', async () => {
- const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}]});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
@@ -127,34 +120,30 @@
{
owner: {substrate: alice.address},
constData: '0x0000',
+ properties: [{key: 'k', value: 'v1'}],
}, {
owner: {substrate: bob.address},
constData: '0x2222',
+ properties: [{key: 'k', value: 'v2'}],
}, {
owner: {substrate: charlie.address},
constData: '0x4444',
+ properties: [{key: 'k', value: 'v3'}],
},
];
- await expect(executeTransaction(
- api,
- alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]),
- )).to.not.be.rejected;
await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {
NFT: data,
}));
-
-
- const tokens = await api.query.nonfungible.tokenData.entries(collection);
- const json = tokens.map(([, token]) => token.toJSON());
- expect(json).to.be.deep.equal(data);
+ for (let i = 1; i < 4; i++) {
+ expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;
+ }
});
});
it('No editing rights', async () => {
const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],
- propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});
+ propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
@@ -188,7 +177,7 @@
it('User doesnt have editing rights', async () => {
const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],
- propPerm: [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});
+ propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -27,7 +27,7 @@
import privateKey from '../substrate/privateKey';
import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';
import {hexToStr, strToUTF16, utf16ToStr} from './util';
-import {UpDataStructsRpcCollection} from '@polkadot/types/lookup';
+import {UpDataStructsRpcCollection, UpDataStructsCreateItemData} from '@polkadot/types/lookup';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -295,13 +295,17 @@
value: any,
};
-type PropertyPermission = {
- key: any,
+type Permission = {
mutable: boolean;
collectionAdmin: boolean;
tokenOwner: boolean;
}
+type PropertyPermission = {
+ key: any;
+ permission: Permission;
+}
+
export type CreateCollectionParams = {
mode: CollectionMode,
name: string,
@@ -1123,6 +1127,65 @@
});
}
+export async function createMultipleItemsWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, itemsData: any, owner: CrossAccountId | string = sender.address) {
+ await usingApi(async (api) => {
+ const to = normalizeAccountId(owner);
+ const tx = api.tx.unique.createMultipleItems(collectionId, to, itemsData);
+
+ const events = await submitTransactionAsync(sender, tx);
+ const result = getCreateItemsResult(events);
+
+ for (let res of result) {
+ expect(await api.rpc.unique.tokenProperties(collectionId, res.itemId)).not.to.be.empty;
+ }
+ });
+}
+
+export async function createItemWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, props: Array<Property>, owner: CrossAccountId | string = sender.address) {
+ let newItemId = 0;
+ await usingApi(async (api) => {
+ const to = normalizeAccountId(owner);
+ const itemCountBefore = await getLastTokenId(api, collectionId);
+ const itemBalanceBefore = await getBalance(api, collectionId, to, newItemId);
+
+ let tx;
+ if (createMode === 'Fungible') {
+ const createData = {fungible: {value: 10}};
+ tx = api.tx.unique.createItem(collectionId, to, createData as any);
+ } else if (createMode === 'ReFungible') {
+ const createData = {refungible: {const_data: [], pieces: 100}};
+ tx = api.tx.unique.createItem(collectionId, to, createData as any);
+ } else {
+ const data = api.createType('UpDataStructsCreateItemData', { NFT: { constData: 'test', properties: props}});
+ tx = api.tx.unique.createItem(collectionId, to, data as UpDataStructsCreateItemData);
+ }
+
+ const events = await submitTransactionAsync(sender, tx);
+ const result = getCreateItemResult(events);
+
+ const itemCountAfter = await getLastTokenId(api, collectionId);
+ const itemBalanceAfter = await getBalance(api, collectionId, to, newItemId);
+
+ if (createMode === 'NFT') {
+ expect(await api.rpc.unique.tokenProperties(collectionId, result.itemId)).not.to.be.empty;
+ }
+
+ // What to expect
+ // tslint:disable-next-line:no-unused-expression
+ expect(result.success).to.be.true;
+ if (createMode === 'Fungible') {
+ expect(itemBalanceAfter - itemBalanceBefore).to.be.equal(10n);
+ } else {
+ expect(itemCountAfter).to.be.equal(itemCountBefore + 1);
+ }
+ expect(collectionId).to.be.equal(result.collectionId);
+ expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());
+ expect(to).to.be.deep.equal(result.recipient);
+ newItemId = result.itemId;
+ });
+ return newItemId;
+}
+
export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {
let newItemId = 0;
await usingApi(async (api) => {