git.delta.rocks / unique-network / refs/commits / 39dc916474d4

difftreelog

tests: fix tests for optional collections

Yaroslav Bolyukin2021-03-22parent: #6a8b360.patch.diff
in: master

10 files changed

modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -32,6 +32,7 @@
     "testRemoveFromWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromWhiteList.test.ts",
     "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
     "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
+    "testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",
     "testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",
     "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",
     "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",
@@ -44,6 +45,7 @@
     "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",
     "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",
     "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",
+    "testRemoveFromContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromContractWhiteList.test.ts",
     "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",
     "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",
     "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",
modifiedtests/src/approve.test.tsdiffbeforeafterboth
--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -123,9 +123,6 @@
     // nft
     const nftCollectionId = await createCollectionExpectSuccess();
     await approveExpectFail(nftCollectionId, 2, Alice, Bob);
-    // fungible
-    const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
-    await approveExpectFail(fungibleCollectionId, 2, Alice, Bob);
     // reFungible
     const reFungibleCollectionId =
       await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -46,8 +46,7 @@
       // tslint:disable-next-line:no-unused-expression
       expect(result.success).to.be.true;
       // tslint:disable-next-line:no-unused-expression
-      expect(item).to.be.not.null;
-      expect(item.Owner).to.be.equal(nullPublicKey);
+      expect(item).to.be.null;
     });
 
   });
@@ -88,8 +87,7 @@
       
       // What to expect
       expect(result.success).to.be.true;
-      expect(balance).to.be.not.null;
-      expect(balance.Owner.length).to.be.equal(0);
+      expect(balance).to.be.null;
     });
 
   });
modifiedtests/src/contracts.test.tsdiffbeforeafterboth
--- a/tests/src/contracts.test.ts
+++ b/tests/src/contracts.test.ts
@@ -63,13 +63,13 @@
       const collectionId = await createCollectionExpectSuccess();
       const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
       const [contract, deployer] = await deployTransferContract(api);
-      const tokenBefore: any = await api.query.nft.nftItemList(collectionId, tokenId);
+      const tokenBefore: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
       
       // Transfer
       const transferTx = contract.tx.transfer(value, gasLimit, bob.address, collectionId, tokenId, 1);
       const events = await submitTransactionAsync(alice, transferTx);
       const result = getGenericResult(events);
-      const tokenAfter: any = await api.query.nft.nftItemList(collectionId, tokenId);
+      const tokenAfter: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
 
       // tslint:disable-next-line:no-unused-expression
       expect(result.success).to.be.true;
modifiedtests/src/createMultipleItems.test.tsdiffbeforeafterboth
--- a/tests/src/createMultipleItems.test.ts
+++ b/tests/src/createMultipleItems.test.ts
@@ -38,9 +38,9 @@
       await submitTransactionAsync(Alice, createMultipleItemsTx);
       const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
       expect(itemsListIndexAfter.toNumber()).to.be.equal(3);
-      const token1Data = await api.query.nft.nftItemList(collectionId, 1) as unknown as ITokenDataType;
-      const token2Data = await api.query.nft.nftItemList(collectionId, 2) as unknown as ITokenDataType;
-      const token3Data = await api.query.nft.nftItemList(collectionId, 3) as unknown as ITokenDataType;
+      const token1Data = (await api.query.nft.nftItemList(collectionId, 1)).toJSON() as unknown as ITokenDataType;
+      const token2Data = (await api.query.nft.nftItemList(collectionId, 2)).toJSON() as unknown as ITokenDataType;
+      const token3Data = (await api.query.nft.nftItemList(collectionId, 3)).toJSON() as unknown as ITokenDataType;
 
       expect(token1Data.Owner.toString()).to.be.equal(Alice.address);
       expect(token2Data.Owner.toString()).to.be.equal(Alice.address);
@@ -72,9 +72,9 @@
       await submitTransactionAsync(Alice, createMultipleItemsTx);
       const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
       expect(itemsListIndexAfter.toNumber()).to.be.equal(3);
-      const token1Data = await api.query.nft.reFungibleItemList(collectionId, 1) as unknown as IReFungibleTokenDataType;
-      const token2Data = await api.query.nft.reFungibleItemList(collectionId, 2) as unknown as IReFungibleTokenDataType;
-      const token3Data = await api.query.nft.reFungibleItemList(collectionId, 3) as unknown as IReFungibleTokenDataType;
+      const token1Data = (await api.query.nft.reFungibleItemList(collectionId, 1) as any).unwrap() as unknown as IReFungibleTokenDataType;
+      const token2Data = (await api.query.nft.reFungibleItemList(collectionId, 2) as any).unwrap() as unknown as IReFungibleTokenDataType;
+      const token3Data = (await api.query.nft.reFungibleItemList(collectionId, 3) as any).unwrap() as unknown as IReFungibleTokenDataType;
 
       expect(token1Data.Owner[0].Owner.toString()).to.be.equal(Alice.address);
       expect(token1Data.Owner[0].Fraction.toNumber()).to.be.equal(1);
modifiedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
--- a/tests/src/removeCollectionAdmin.test.ts
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -36,6 +36,19 @@
       expect(adminListAfterRemoveAdmin).not.to.be.contains(Bob.address);
     });
   });
+
+  it('Remove admin from collection that has no admins', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const Alice = privateKey('//Alice');
+      const collectionId = await createCollectionExpectSuccess();
+
+      const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));
+      expect(adminListBeforeAddAdmin).to.have.lengthOf(0);
+
+      const tx = api.tx.nft.removeCollectionAdmin(collectionId, Alice.address);
+      await submitTransactionAsync(Alice, tx);
+    });
+  });
 });
 
 describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {
@@ -68,19 +81,6 @@
 
       // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
       await createCollectionExpectSuccess();
-    });
-  });
-
-  it('Remove admin from collection that has no admins', async () => {
-    await usingApi(async (api: ApiPromise) => {
-      const Alice = privateKey('//Alice');
-      const collectionId = await createCollectionExpectSuccess();
-
-      const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));
-      expect(adminListBeforeAddAdmin).to.have.lengthOf(0);
-
-      const tx = api.tx.nft.removeCollectionAdmin(collectionId, Alice.address);
-      await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
     });
   });
 });
modifiedtests/src/removeFromContractWhiteList.test.tsdiffbeforeafterboth
--- a/tests/src/removeFromContractWhiteList.test.ts
+++ b/tests/src/removeFromContractWhiteList.test.ts
@@ -13,8 +13,10 @@
 describe('Integration Test removeFromContractWhiteList', () => {
     let bob: IKeyringPair;
 
-    before(() => {
-        bob = privateKey('//Bob');
+    before(async () => {
+        await usingApi(async () => {
+            bob = privateKey('//Bob');
+        });
     });
 
     it('user is no longer whitelisted after removal', async () => {
@@ -56,9 +58,11 @@
     let alice: IKeyringPair;
     let bob: IKeyringPair;
 
-    before(() => {
-        alice = privateKey('//Alice');
-        bob = privateKey('//Bob');
+    before(async () => {
+        await usingApi(async () => {
+            alice = privateKey('//Alice');
+            bob = privateKey('//Bob');
+        });
     });
 
     it('fails when called with non-contract address', async () => {
modifiedtests/src/setVariableMetaData.test.tsdiffbeforeafterboth
--- a/tests/src/setVariableMetaData.test.ts
+++ b/tests/src/setVariableMetaData.test.ts
@@ -41,7 +41,7 @@
 
   it('verify data was set', async () => {
     await usingApi(async api => {
-      const item: any = await api.query.nft.nftItemList(collectionId, tokenId);
+      const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
 
       expect(Array.from(item.VariableData)).to.deep.equal(Array.from(data));
     });
modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -237,7 +237,7 @@
       const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
       const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
       await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);
-      await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
+      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
       await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);
           
     });
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
599 // tslint:disable-next-line:no-unused-expression599 // tslint:disable-next-line:no-unused-expression
600 expect(result.success).to.be.true;600 expect(result.success).to.be.true;
601 // tslint:disable-next-line:no-unused-expression601 // tslint:disable-next-line:no-unused-expression
602 expect(item).to.be.not.null;602 expect(item).to.be.null;
603 expect(item.Owner).to.be.equal(nullPublicKey);
604 });603 });
605}604}
606605
641 // tslint:disable-next-line:no-unused-expression640 // tslint:disable-next-line:no-unused-expression
642 expect(result.success).to.be.true;641 expect(result.success).to.be.true;
643 if (type === 'NFT') {642 if (type === 'NFT') {
644 const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;643 const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap() as ITokenDataType;
645 expect(nftItemData.Owner.toString()).to.be.equal(accountTo.address);644 expect(nftItemData.Owner.toString()).to.be.equal(accountTo.address);
646 }645 }
647 if (type === 'Fungible') {646 if (type === 'Fungible') {
648 const balanceAfter = await api.query.nft.balance(collectionId, accountTo.address) as unknown as BN;647 const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, accountTo.address) as any).Value as unknown as BN;
649 expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());648 expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());
650 }649 }
651 if (type === 'ReFungible') {650 if (type === 'ReFungible') {
652 const nftItemData =651 const nftItemData =
653 await api.query.nft.reFungibleItemList(collectionId, tokenId) as unknown as IReFungibleTokenDataType;652 (await api.query.nft.reFungibleItemList(collectionId, tokenId) as any).unwrap() as IReFungibleTokenDataType;
654 expect(nftItemData.Owner[0].Owner.toString()).to.be.equal(accountTo.address);653 expect(nftItemData.Owner[0].Owner.toString()).to.be.equal(accountTo.address);
655 expect(nftItemData.Owner[0].Fraction.toNumber()).to.be.equal(value);654 expect(nftItemData.Owner[0].Fraction.toNumber()).to.be.equal(value);
656 }655 }
697 expect(result.recipient).to.be.equal(recipient.address);696 expect(result.recipient).to.be.equal(recipient.address);
698 expect(result.value.toString()).to.be.equal(value.toString());697 expect(result.value.toString()).to.be.equal(value.toString());
699 if (type === 'NFT') {698 if (type === 'NFT') {
700 const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;699 const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;
701 expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);700 expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);
702 }701 }
703 if (type === 'Fungible') {702 if (type === 'Fungible') {
704 const balanceAfter = await api.query.nft.balance(collectionId, recipient.address) as unknown as BN;703 const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, recipient.address) as any).Value as unknown as BN;
705 expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());704 expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());
706 }705 }
707 if (type === 'ReFungible') {706 if (type === 'ReFungible') {
708 const nftItemData =707 const nftItemData =
709 await api.query.nft.reFungibleItemList(collectionId, tokenId) as unknown as IReFungibleTokenDataType;708 (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON() as unknown as IReFungibleTokenDataType;
710 expect(nftItemData.Owner[0].Owner.toString()).to.be.equal(recipient.address);709 expect(nftItemData.Owner[0].Owner.toString()).to.be.equal(recipient.address);
711 expect(nftItemData.Owner[0].Fraction.toNumber()).to.be.equal(value);710 expect(nftItemData.Owner[0].Fraction.toString()).to.be.equal(value.toString());
712 }711 }
713 });712 });
714}713}