difftreelog
CreateItem* tests fixes
in: master
4 files changed
tests/src/createItem.test.tsdiffbeforeafterboth--- a/tests/src/createItem.test.ts
+++ b/tests/src/createItem.test.ts
@@ -23,13 +23,14 @@
createItemExpectSuccess,
addCollectionAdminExpectSuccess,
createCollectionWithPropsExpectSuccess,
+ createItemWithPropsExpectSuccess,
} from './util/helpers';
const expect = chai.expect;
let alice: IKeyringPair;
let bob: IKeyringPair;
-describe('integration test: ext. createItem():', () => {
+describe('integration test: ext. ():', () => {
before(async () => {
await usingApi(async () => {
const keyring = new Keyring({type: 'sr25519'});
@@ -75,28 +76,25 @@
it('Set property Admin', async () => {
const createMode = 'NFT';
const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},
- properties: [{key: 'key1', value: 'val1'}],
- propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: false}]});
+ propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});
- await createItemExpectSuccess(alice, newCollectionID, createMode);
+ await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'k', value: 't2'}]);
});
it('Set property AdminConst', async () => {
const createMode = 'NFT';
const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},
- properties: [{key: 'key1', value: 'val1'}],
- propPerm: [{key: 'key1', mutable: false, collectionAdmin: true, tokenOwner: false}]});
+ propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});
- await createItemExpectSuccess(alice, newCollectionID, createMode);
+ await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);
});
it('Set property itemOwnerOrAdmin', async () => {
const createMode = 'NFT';
- const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},
- properties: [{key: 'key1', value: 'val1'}],
- propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: true}]});
+ const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},
+ propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});
- await createItemExpectSuccess(alice, newCollectionID, createMode);
+ await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);
});
});
@@ -129,7 +127,7 @@
await usingApi(async api => {
const createMode = 'NFT';
const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},
- propPerm: [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});
+ propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});
const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');
await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);
@@ -144,7 +142,7 @@
it('User doesnt have editing rights', async () => {
await usingApi(async api => {
- const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});
+ const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});
const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');
await expect(executeTransaction(
tests/src/createMultipleItems.test.tsdiffbeforeafterboth34 getCreatedCollectionCount,34 getCreatedCollectionCount,35 createCollectionWithPropsExpectSuccess,35 createCollectionWithPropsExpectSuccess,36 getCreateItemsResult,36 getCreateItemsResult,37 createMultipleItemsWithPropsExpectSuccess37} from './util/helpers';38} from './util/helpers';383939chai.use(chaiAsPromised);40chai.use(chaiAsPromised);133134134 it('Create 0x31, 0x32, 0x33 items in active NFT with property Admin', async () => {135 it('Create 0x31, 0x32, 0x33 items in active NFT with property Admin', async () => {135 await usingApi(async (api: ApiPromise) => {136 await usingApi(async (api: ApiPromise) => {136 const collectionId = await createCollectionExpectSuccess();137 const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});137 const itemsListIndexBefore = await getLastTokenId(api, collectionId);138 const itemsListIndexBefore = await getLastTokenId(api, collectionId);138 expect(itemsListIndexBefore).to.be.equal(0);139 expect(itemsListIndexBefore).to.be.equal(0);139 const alice = privateKey('//Alice');140 const alice = privateKey('//Alice');140 const bob = privateKey('//Bob');141 const bob = privateKey('//Bob');141 const args = [{Nft: {const_data: '0x31'}},142 const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v1'}]}},142 {Nft: {const_data: '0x32'}},143 {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'v2'}]}},143 {Nft: {const_data: '0x33'}}];144 {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'v3'}]}}];144 const createMultipleItemsTx = api.tx.unique145145 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);146 await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);146 await submitTransactionAsync(alice, createMultipleItemsTx);147 const itemsListIndexAfter = await getLastTokenId(api, collectionId);147 const itemsListIndexAfter = await getLastTokenId(api, collectionId);148 expect(itemsListIndexAfter).to.be.equal(3);148 expect(itemsListIndexAfter).to.be.equal(3);149150 await expect(executeTransaction(151 api,152 alice,153 api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]),154 )).to.not.be.rejected;155149156 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));150 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));157 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));151 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));165159166 it('Create 0x31, 0x32, 0x33 items in active NFT with property AdminConst', async () => {160 it('Create 0x31, 0x32, 0x33 items in active NFT with property AdminConst', async () => {167 await usingApi(async (api: ApiPromise) => {161 await usingApi(async (api: ApiPromise) => {168 const collectionId = await createCollectionExpectSuccess();162 const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});169 const itemsListIndexBefore = await getLastTokenId(api, collectionId);163 const itemsListIndexBefore = await getLastTokenId(api, collectionId);170 expect(itemsListIndexBefore).to.be.equal(0);164 expect(itemsListIndexBefore).to.be.equal(0);171 const alice = privateKey('//Alice');165 const alice = privateKey('//Alice');172 const bob = privateKey('//Bob');166 const bob = privateKey('//Bob');167 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);173 const args = [{Nft: {const_data: '0x31'}},168 const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v1'}]}},174 {Nft: {const_data: '0x32'}},169 {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'v2'}]}},175 {Nft: {const_data: '0x33'}}];170 {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'v3'}]}}];176 const createMultipleItemsTx = api.tx.unique171177 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);172 await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);178 await submitTransactionAsync(alice, createMultipleItemsTx);179 const itemsListIndexAfter = await getLastTokenId(api, collectionId);173 const itemsListIndexAfter = await getLastTokenId(api, collectionId);180 expect(itemsListIndexAfter).to.be.equal(3);174 expect(itemsListIndexAfter).to.be.equal(3);181182 await expect(executeTransaction(183 api,184 alice,185 api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]),186 )).to.not.be.rejected;187175188 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));176 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));189 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));177 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));197185198 it('Create 0x31, 0x32, 0x33 items in active NFT with property itemOwnerOrAdmin', async () => {186 it('Create 0x31, 0x32, 0x33 items in active NFT with property itemOwnerOrAdmin', async () => {199 await usingApi(async (api: ApiPromise) => {187 await usingApi(async (api: ApiPromise) => {200 const collectionId = await createCollectionExpectSuccess();188 const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});201 const itemsListIndexBefore = await getLastTokenId(api, collectionId);189 const itemsListIndexBefore = await getLastTokenId(api, collectionId);202 expect(itemsListIndexBefore).to.be.equal(0);190 expect(itemsListIndexBefore).to.be.equal(0);203 const alice = privateKey('//Alice');191 const alice = privateKey('//Alice');204 const bob = privateKey('//Bob');192 const bob = privateKey('//Bob');205 const args = [{Nft: {const_data: '0x31'}},193 const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v1'}]}},206 {Nft: {const_data: '0x32'}},194 {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'v2'}]}},207 {Nft: {const_data: '0x33'}}];195 {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'v3'}]}}];208 const createMultipleItemsTx = api.tx.unique196209 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);197 await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);210 await submitTransactionAsync(alice, createMultipleItemsTx);211 const itemsListIndexAfter = await getLastTokenId(api, collectionId);198 const itemsListIndexAfter = await getLastTokenId(api, collectionId);212 expect(itemsListIndexAfter).to.be.equal(3);199 expect(itemsListIndexAfter).to.be.equal(3);213214 await expect(executeTransaction(215 api,216 alice,217 api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]),218 )).to.not.be.rejected;219200220 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));201 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));221 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));202 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));451 it('No editing rights', async () => {432 it('No editing rights', async () => {452 await usingApi(async (api: ApiPromise) => {433 await usingApi(async (api: ApiPromise) => {453 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],434 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],454 propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});435 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});455 const itemsListIndexBefore = await getLastTokenId(api, collectionId);436 const itemsListIndexBefore = await getLastTokenId(api, collectionId);456 expect(itemsListIndexBefore).to.be.equal(0);437 expect(itemsListIndexBefore).to.be.equal(0);457 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);438 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);479 it('User doesnt have editing rights', async () => {460 it('User doesnt have editing rights', async () => {480 await usingApi(async (api: ApiPromise) => {461 await usingApi(async (api: ApiPromise) => {481 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],462 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],482 propPerm: [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});463 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});483 const itemsListIndexBefore = await getLastTokenId(api, collectionId);464 const itemsListIndexBefore = await getLastTokenId(api, collectionId);484 expect(itemsListIndexBefore).to.be.equal(0);465 expect(itemsListIndexBefore).to.be.equal(0);485 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);466 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);530 it('Adding more than 64 prps', async () => {511 it('Adding more than 64 prps', async () => {531 await usingApi(async (api: ApiPromise) => {512 await usingApi(async (api: ApiPromise) => {532 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],513 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],533 propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: false}]});514 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});534 const itemsListIndexBefore = await getLastTokenId(api, collectionId);515 const itemsListIndexBefore = await getLastTokenId(api, collectionId);535 expect(itemsListIndexBefore).to.be.equal(0);516 expect(itemsListIndexBefore).to.be.equal(0);536 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);517 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);565 it('Trying to add bigger property than allowed', async () => {546 it('Trying to add bigger property than allowed', async () => {566 await usingApi(async (api: ApiPromise) => {547 await usingApi(async (api: ApiPromise) => {567 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],548 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],568 propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});549 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});569 const itemsListIndexBefore = await getLastTokenId(api, collectionId);550 const itemsListIndexBefore = await getLastTokenId(api, collectionId);570 expect(itemsListIndexBefore).to.be.equal(0);551 expect(itemsListIndexBefore).to.be.equal(0);571 const args = [{Nft: {const_data: '0x31'}},552 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) => {