git.delta.rocks / unique-network / refs/commits / b80b794104f8

difftreelog

CreateItem* tests fixes

kryadinskii2022-05-19parent: #69adc40.patch.diff
in: master

4 files changed

modifiedtests/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(
modifiedtests/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'}},
modifiedtests/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');
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
27import privateKey from '../substrate/privateKey';27import privateKey from '../substrate/privateKey';
28import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';28import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';
29import {hexToStr, strToUTF16, utf16ToStr} from './util';29import {hexToStr, strToUTF16, utf16ToStr} from './util';
30import {UpDataStructsRpcCollection} from '@polkadot/types/lookup';30import {UpDataStructsRpcCollection, UpDataStructsCreateItemData} from '@polkadot/types/lookup';
3131
32chai.use(chaiAsPromised);32chai.use(chaiAsPromised);
33const expect = chai.expect;33const expect = chai.expect;
295 value: any,295 value: any,
296};296};
297297
298type PropertyPermission = {298type Permission = {
299 key: any,
300 mutable: boolean;299 mutable: boolean;
301 collectionAdmin: boolean;300 collectionAdmin: boolean;
302 tokenOwner: boolean;301 tokenOwner: boolean;
303}302}
303
304type PropertyPermission = {
305 key: any;
306 permission: Permission;
307}
304308
305export type CreateCollectionParams = {309export type CreateCollectionParams = {
306 mode: CollectionMode,310 mode: CollectionMode,
1123 });1127 });
1124}1128}
1129
1130export async function createMultipleItemsWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, itemsData: any, owner: CrossAccountId | string = sender.address) {
1131 await usingApi(async (api) => {
1132 const to = normalizeAccountId(owner);
1133 const tx = api.tx.unique.createMultipleItems(collectionId, to, itemsData);
1134
1135 const events = await submitTransactionAsync(sender, tx);
1136 const result = getCreateItemsResult(events);
1137
1138 for (let res of result) {
1139 expect(await api.rpc.unique.tokenProperties(collectionId, res.itemId)).not.to.be.empty;
1140 }
1141 });
1142}
1143
1144export async function createItemWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, props: Array<Property>, owner: CrossAccountId | string = sender.address) {
1145 let newItemId = 0;
1146 await usingApi(async (api) => {
1147 const to = normalizeAccountId(owner);
1148 const itemCountBefore = await getLastTokenId(api, collectionId);
1149 const itemBalanceBefore = await getBalance(api, collectionId, to, newItemId);
1150
1151 let tx;
1152 if (createMode === 'Fungible') {
1153 const createData = {fungible: {value: 10}};
1154 tx = api.tx.unique.createItem(collectionId, to, createData as any);
1155 } else if (createMode === 'ReFungible') {
1156 const createData = {refungible: {const_data: [], pieces: 100}};
1157 tx = api.tx.unique.createItem(collectionId, to, createData as any);
1158 } else {
1159 const data = api.createType('UpDataStructsCreateItemData', { NFT: { constData: 'test', properties: props}});
1160 tx = api.tx.unique.createItem(collectionId, to, data as UpDataStructsCreateItemData);
1161 }
1162
1163 const events = await submitTransactionAsync(sender, tx);
1164 const result = getCreateItemResult(events);
1165
1166 const itemCountAfter = await getLastTokenId(api, collectionId);
1167 const itemBalanceAfter = await getBalance(api, collectionId, to, newItemId);
1168
1169 if (createMode === 'NFT') {
1170 expect(await api.rpc.unique.tokenProperties(collectionId, result.itemId)).not.to.be.empty;
1171 }
1172
1173 // What to expect
1174 // tslint:disable-next-line:no-unused-expression
1175 expect(result.success).to.be.true;
1176 if (createMode === 'Fungible') {
1177 expect(itemBalanceAfter - itemBalanceBefore).to.be.equal(10n);
1178 } else {
1179 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);
1180 }
1181 expect(collectionId).to.be.equal(result.collectionId);
1182 expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());
1183 expect(to).to.be.deep.equal(result.recipient);
1184 newItemId = result.itemId;
1185 });
1186 return newItemId;
1187}
11251188
1126export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {1189export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {
1127 let newItemId = 0;1190 let newItemId = 0;