git.delta.rocks / unique-network / refs/commits / 2849d0e6033f

difftreelog

Add destroyCollection tests

Max Andreev2022-12-03parent: #2293f03.patch.diff
in: master

2 files changed

modifiedtests/src/eth/destroyCollection.test.tsdiffbeforeafterboth
--- a/tests/src/eth/destroyCollection.test.ts
+++ b/tests/src/eth/destroyCollection.test.ts
@@ -15,62 +15,48 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 import {IKeyringPair} from '@polkadot/types/types';
-import {Pallets, requirePalletsOrSkip} from '../util';
+import {Pallets} from '../util';
 import {expect, itEth, usingEthPlaygrounds} from './util';
 
-
-describe('Destroy Collection from EVM', () => {
+describe('Destroy Collection from EVM', function() {
   let donor: IKeyringPair;
+  const testCases = [
+    {method: 'createRFTCollection' as const, params: ['Limits', 'absolutely anything', 'OLF'], requiredPallets: [Pallets.ReFungible]},
+    {method: 'createNFTCollection' as const, params: ['Limits', 'absolutely anything', 'OLF'], requiredPallets: [Pallets.NFT]},
+    {method: 'createFTCollection' as const, params: ['Limits', 'absolutely anything', 'OLF', 18], requiredPallets: [Pallets.Fungible]},
+  ];
 
   before(async function() {
-    await usingEthPlaygrounds(async (helper, privateKey) => {
-      requirePalletsOrSkip(this, helper, [Pallets.ReFungible, Pallets.NFT]);
+    await usingEthPlaygrounds(async (_, privateKey) => {
       donor = await privateKey({filename: __filename});
     });
   });
 
-  
-  itEth('(!negative test!) RFT', async ({helper}) => {
-    const owner = await helper.eth.createAccountWithBalance(donor);
-    const signer = await helper.eth.createAccountWithBalance(donor);
-    
-    const unexistedCollection = helper.ethAddress.fromCollectionId(1000000);
-    
-    const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
-    const collectionHelper = helper.ethNativeContract.collectionHelpers(signer);
-    
-    await expect(collectionHelper.methods
-      .destroyCollection(collectionAddress)
-      .send({from: signer})).to.be.rejected;
-    
-    await expect(collectionHelper.methods
-      .destroyCollection(unexistedCollection)
-      .send({from: signer})).to.be.rejected;
-    
-    expect(await collectionHelper.methods
-      .isCollectionExist(unexistedCollection)
-      .call()).to.be.false;
-  });
-  
-  itEth('(!negative test!) NFT', async ({helper}) => {
-    const owner = await helper.eth.createAccountWithBalance(donor);
-    const signer = await helper.eth.createAccountWithBalance(donor);
-    
-    const unexistedCollection = helper.ethAddress.fromCollectionId(1000000);
-    
-    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
-    const collectionHelper = helper.ethNativeContract.collectionHelpers(signer);
-    
-    await expect(collectionHelper.methods
-      .destroyCollection(collectionAddress)
-      .send({from: signer})).to.be.rejected;
-    
-    await expect(collectionHelper.methods
-      .destroyCollection(unexistedCollection)
-      .send({from: signer})).to.be.rejected;
-    
-    expect(await collectionHelper.methods
-      .isCollectionExist(unexistedCollection)
-      .call()).to.be.false;
-  });
+  testCases.map((testCase) => 
+    itEth.ifWithPallets(`(!negative test!) ${testCase.method}`, testCase.requiredPallets, async ({helper}) => {
+      const owner = await helper.eth.createAccountWithBalance(donor);
+      const signer = await helper.eth.createAccountWithBalance(donor);
+      
+      const unexistedCollection = helper.ethAddress.fromCollectionId(1000000);
+      
+      const collectionHelpers = helper.ethNativeContract.collectionHelpers(signer);
+      const {collectionAddress} = await helper.eth.createCollecion(testCase.method, owner, ...testCase.params as [string, string, string, number?]);
+
+      // cannot burn collec
+      await expect(collectionHelpers.methods
+        .destroyCollection(collectionAddress)
+        .send({from: signer})).to.be.rejected;
+      
+      await expect(collectionHelpers.methods
+        .destroyCollection(unexistedCollection)
+        .send({from: signer})).to.be.rejected;
+      
+      expect(await collectionHelpers.methods
+        .isCollectionExist(unexistedCollection)
+        .call()).to.be.false;
+      
+      expect(await collectionHelpers.methods
+        .isCollectionExist(collectionAddress)
+        .call()).to.be.true;
+    }));
 });
modifiedtests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth
186 return await this.helper.callRpc('api.rpc.eth.call', [{from: signer, to: contractAddress, data: abi}]);186 return await this.helper.callRpc('api.rpc.eth.call', [{from: signer, to: contractAddress, data: abi}]);
187 }187 }
188188
189 async createCollecion(functionName: string, signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {189 async createCollecion(functionName: 'createNFTCollection' | 'createRFTCollection' | 'createFTCollection', signer: string, name: string, description: string, tokenPrefix: string, decimals?: number): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
190 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();190 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
191 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);191 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
192192
193 const functionParams = functionName === 'createFTCollection' ? [name, decimals, description, tokenPrefix] : [name, description, tokenPrefix];
193 const result = await collectionHelper.methods[functionName](name, description, tokenPrefix).send({value: Number(collectionCreationPrice)});194 const result = await collectionHelper.methods[functionName](...functionParams).send({value: Number(collectionCreationPrice)});
194195
195 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);196 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
196 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);197 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
217 return this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix);218 return this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix);
218 }219 }
219220
220 async createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {221 createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {
221 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
222 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
223
224 const result = await collectionHelper.methods.createFTCollection(name, decimals, description, tokenPrefix).send({value: Number(collectionCreationPrice)});222 return this.createCollecion('createFTCollection', signer, name, description, tokenPrefix, decimals);
225 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
226 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
227
228 const events = this.helper.eth.normalizeEvents(result.events);
229
230 return {collectionId, collectionAddress, events};
231 }223 }
232224
233 async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {225 async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {