git.delta.rocks / unique-network / refs/commits / 5056401c7dcb

difftreelog

fix PR

Trubnikov Sergey2022-12-13parent: #7b1642b.patch.diff
in: master

2 files changed

modifiedtests/src/eth/events.test.tsdiffbeforeafterboth
--- a/tests/src/eth/events.test.ts
+++ b/tests/src/eth/events.test.ts
@@ -17,8 +17,9 @@
 import {expect} from 'chai';
 import {IKeyringPair} from '@polkadot/types/types';
 import {EthUniqueHelper, itEth, usingEthPlaygrounds} from './util';
-import {TCollectionMode} from '../util/playgrounds/types';
+import {IEvent, TCollectionMode} from '../util/playgrounds/types';
 import {Pallets, requirePalletsOrSkip} from '../util';
+import {NormalizedEvent} from './util/playgrounds/types';
 
 let donor: IKeyringPair;
   
@@ -28,6 +29,11 @@
   });
 });
 
+function clearEvents(ethEvents: NormalizedEvent[], subEvents: IEvent[]) {
+  ethEvents.splice(0);
+  subEvents.splice(0);
+}
+
 async function testCollectionCreatedAndDestroy(helper: EthUniqueHelper, mode: TCollectionMode) {
   const owner = await helper.eth.createAccountWithBalance(donor);
   const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionCreated', 'CollectionDestroyed']}]);
@@ -44,8 +50,7 @@
       },
     ]);
     expect(subEvents).to.be.like([{method: 'CollectionCreated'}]);
-    ethEvents.pop();
-    subEvents.pop();
+    clearEvents(ethEvents, subEvents);
   }
   {
     const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
@@ -69,12 +74,12 @@
   const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
   const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
     
+  const ethEvents: any = [];
+  collectionHelper.events.allEvents((_: any, event: any) => {
+    ethEvents.push(event);
+  });
   const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPropertySet', 'CollectionPropertyDeleted']}]);
   {
-    const ethEvents: any = [];
-    collectionHelper.events.allEvents((_: any, event: any) => {
-      ethEvents.push(event);
-    });
     await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner});
     await helper.wait.newBlocks(1);
     expect(ethEvents).to.be.like([
@@ -86,13 +91,9 @@
       },
     ]);
     expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]);
-    subEvents.pop();
+    clearEvents(ethEvents, subEvents);
   }
   {
-    const ethEvents: any = [];
-    collectionHelper.events.allEvents((_: any, event: any) => {
-      ethEvents.push(event);
-    });
     await collection.methods.deleteCollectionProperties(['A']).send({from:owner});
     await helper.wait.newBlocks(1);
     expect(ethEvents).to.be.like([
@@ -113,14 +114,14 @@
   const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
   const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
   const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
-  const eethEvents: any = [];
+  const ethEvents: any = [];
   collectionHelper.events.allEvents((_: any, event: any) => {
-    eethEvents.push(event);
+    ethEvents.push(event);
   });
   const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['PropertyPermissionSet']}]);
   await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner});
   await helper.wait.newBlocks(1);
-  expect(eethEvents).to.be.like([
+  expect(ethEvents).to.be.like([
     {
       event: 'CollectionChanged',
       returnValues: {
@@ -156,8 +157,7 @@
       },
     ]);
     expect(subEvents).to.be.like([{method: 'AllowListAddressAdded'}]);
-    ethEvents.pop();
-    subEvents.pop();
+    clearEvents(ethEvents, subEvents);
   }
   {
     await collection.methods.removeFromCollectionAllowListCross(user).send({from: owner});
@@ -176,7 +176,7 @@
   unsubscribe();
 }
 
-async function testCollectionAdminAddedAndCollectionAdminRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {
+async function testCollectionAdminAddedAndRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {
   const owner = await helper.eth.createAccountWithBalance(donor);
   const user = helper.ethCrossAccount.createAccount();
   const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
@@ -199,8 +199,7 @@
       },
     ]);
     expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]);
-    ethEvents.pop();
-    subEvents.pop();
+    clearEvents(ethEvents, subEvents);
   }
   {
     await collection.methods.removeCollectionAdminCross(user).send({from: owner});
@@ -293,8 +292,7 @@
       },
     ]);
     expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);
-    ethEvents.pop();
-    subEvents.pop();
+    clearEvents(ethEvents, subEvents);
   }
   {
     await collection.methods.setCollectionAccess(1).send({from: owner});
@@ -312,7 +310,7 @@
   unsubscribe();
 }
 
-async function testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {
+async function testCollectionSponsorSetAndConfirmedAndThenRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {
   const owner = await helper.eth.createAccountWithBalance(donor);
   const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor);
   const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
@@ -337,8 +335,7 @@
       },
     ]);
     expect(subEvents).to.be.like([{method: 'CollectionSponsorSet'}]);
-    ethEvents.pop();
-    subEvents.pop();
+    clearEvents(ethEvents, subEvents);
   }
   {
     await collection.methods.confirmCollectionSponsorship().send({from: sponsor.eth});
@@ -352,8 +349,7 @@
       },
     ]);
     expect(subEvents).to.be.like([{method: 'SponsorshipConfirmed'}]);
-    ethEvents.pop();
-    subEvents.pop();
+    clearEvents(ethEvents, subEvents);
   }
   {
     await collection.methods.removeCollectionSponsor().send({from: owner});
@@ -371,7 +367,7 @@
   unsubscribe();
 }
 
-async function testTokenPropertySetAndTokenPropertyDeleted(helper: EthUniqueHelper, mode: TCollectionMode) {
+async function testTokenPropertySetAndDeleted(helper: EthUniqueHelper, mode: TCollectionMode) {
   const owner = await helper.eth.createAccountWithBalance(donor);
   const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
   const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
@@ -398,8 +394,7 @@
       },
     ]);
     expect(subEvents).to.be.like([{method: 'TokenPropertySet'}]);
-    ethEvents.pop();
-    subEvents.pop();
+    clearEvents(ethEvents, subEvents);
   }
   {
     await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});
@@ -417,7 +412,7 @@
   unsubscribe();
 }
 
-describe('[FT] Sync sub & eth events', () => {
+describe.only('[FT] Sync sub & eth events', () => {
   const mode: TCollectionMode = 'ft';
 
   itEth('CollectionCreated and CollectionDestroyed events', async ({helper}) => {
@@ -433,7 +428,7 @@
   });
     
   itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {
-    await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode);
+    await testCollectionAdminAddedAndRemoved(helper, mode);
   });
     
   itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {
@@ -449,11 +444,11 @@
   });
 
   itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {
-    await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode);
+    await testCollectionSponsorSetAndConfirmedAndThenRemoved(helper, mode);
   });
 });
 
-describe('[NFT] Sync sub & eth events', () => {
+describe.only('[NFT] Sync sub & eth events', () => {
   const mode: TCollectionMode = 'nft';
 
   itEth('CollectionCreated and CollectionDestroyed events', async ({helper}) => {
@@ -473,7 +468,7 @@
   });
     
   itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {
-    await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode);
+    await testCollectionAdminAddedAndRemoved(helper, mode);
   });
     
   itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {
@@ -489,15 +484,15 @@
   });
 
   itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {
-    await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode);
+    await testCollectionSponsorSetAndConfirmedAndThenRemoved(helper, mode);
   });
      
   itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {
-    await testTokenPropertySetAndTokenPropertyDeleted(helper, mode);
+    await testTokenPropertySetAndDeleted(helper, mode);
   });
 });
 
-describe('[RFT] Sync sub & eth events', () => {
+describe.only('[RFT] Sync sub & eth events', () => {
   const mode: TCollectionMode = 'rft';
 
   before(async function() {
@@ -524,7 +519,7 @@
   });
     
   itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {
-    await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode);
+    await testCollectionAdminAddedAndRemoved(helper, mode);
   });
     
   itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {
@@ -540,10 +535,10 @@
   });
 
   itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {
-    await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode);
+    await testCollectionSponsorSetAndConfirmedAndThenRemoved(helper, mode);
   });
      
   itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {
-    await testTokenPropertySetAndTokenPropertyDeleted(helper, mode);
+    await testTokenPropertySetAndDeleted(helper, mode);
   });
 });
modifiedtests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth
70 await expect(collection.removeSponsor(alice)).to.not.be.rejected;70 await expect(collection.removeSponsor(alice)).to.not.be.rejected;
71 });71 });
7272
73 itSub('Remove sponsor for a collection with collection admin permissions', async ({helper}) => {73 itSub('Remove a sponsor from a collection with collection admin permissions', async ({helper}) => {
74 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-1', tokenPrefix: 'RCS'});74 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-1', tokenPrefix: 'RCS'});
75 await collection.setSponsor(alice, bob.address);75 await collection.setSponsor(alice, bob.address);
76 await collection.addAdmin(alice, {Substrate: charlie.address});76 await collection.addAdmin(alice, {Substrate: charlie.address});