git.delta.rocks / unique-network / refs/commits / 6da085670d5d

difftreelog

Skip rft tests

Max Andreev2022-12-07parent: #c19d240.patch.diff
in: master

2 files changed

modifiedtests/src/eth/collectionLimits.test.tsdiffbeforeafterboth
1import {IKeyringPair} from '@polkadot/types/types';1import {IKeyringPair} from '@polkadot/types/types';
2import {Pallets} from '../util';
2import {expect, itEth, usingEthPlaygrounds} from './util';3import {expect, itEth, usingEthPlaygrounds} from './util';
34
45
1314
14 [15 [
15 {case: 'nft' as const, method: 'createNFTCollection' as const},16 {case: 'nft' as const, method: 'createNFTCollection' as const},
16 {case: 'rft' as const, method: 'createRFTCollection' as const},17 {case: 'rft' as const, method: 'createRFTCollection' as const, requiredPallets: [Pallets.ReFungible]},
17 {case: 'ft' as const, method: 'createFTCollection' as const},18 {case: 'ft' as const, method: 'createFTCollection' as const},
18 ].map(testCase =>19 ].map(testCase =>
19 itEth(`for ${testCase.case}`, async ({helper}) => {20 itEth.ifWithPallets(`for ${testCase.case}`, testCase.requiredPallets || [], async ({helper}) => {
20 const owner = await helper.eth.createAccountWithBalance(donor);21 const owner = await helper.eth.createAccountWithBalance(donor);
21 const {collectionId, collectionAddress} = await helper.eth.createCollecion(testCase.method, owner, 'Limits', 'absolutely anything', 'FLO', 18);22 const {collectionId, collectionAddress} = await helper.eth.createCollecion(testCase.method, owner, 'Limits', 'absolutely anything', 'FLO', 18);
22 const limits = {23 const limits = {
7172
72 [73 [
73 {case: 'nft' as const, method: 'createNFTCollection' as const},74 {case: 'nft' as const, method: 'createNFTCollection' as const},
74 {case: 'rft' as const, method: 'createRFTCollection' as const},75 {case: 'rft' as const, method: 'createRFTCollection' as const, requiredPallets: [Pallets.ReFungible]},
75 {case: 'ft' as const, method: 'createFTCollection' as const},76 {case: 'ft' as const, method: 'createFTCollection' as const},
76 ].map(testCase =>77 ].map(testCase =>
77 itEth(`for ${testCase.case}`, async ({helper}) => {78 itEth.ifWithPallets(`for ${testCase.case}`, testCase.requiredPallets || [], async ({helper}) => {
78 const invalidLimits = {79 const invalidLimits = {
79 accountTokenOwnershipLimit: BigInt(Number.MAX_SAFE_INTEGER),80 accountTokenOwnershipLimit: BigInt(Number.MAX_SAFE_INTEGER),
80 transfersEnabled: 3,81 transfersEnabled: 3,
modifiedtests/src/eth/collectionProperties.test.tsdiffbeforeafterboth
--- a/tests/src/eth/collectionProperties.test.ts
+++ b/tests/src/eth/collectionProperties.test.ts
@@ -18,7 +18,6 @@
 import {Pallets} from '../util';
 import {IProperty, ITokenPropertyPermission} from '../util/playgrounds/types';
 import {IKeyringPair} from '@polkadot/types/types';
-import {TCollectionMode} from '../util/playgrounds/types';
 
 describe('EVM collection properties', () => {
   let donor: IKeyringPair;
@@ -133,86 +132,82 @@
       donor = await privateKey({filename: __filename});
     });
   });
-
-  const checkERC721Metadata = async (helper: EthUniqueHelper, mode: 'nft' | 'rft') => {
-    const caller = await helper.eth.createAccountWithBalance(donor);
-    const bruh = await helper.eth.createAccountWithBalance(donor);
-
-    const BASE_URI = 'base/';
-    const SUFFIX = 'suffix1';
-    const URI = 'uri1';
-
-    const collectionHelpers = helper.ethNativeContract.collectionHelpers(caller);
-    const creatorMethod = mode === 'rft' ? 'createRFTCollection' : 'createNFTCollection';
-
-    const {collectionId, collectionAddress} = await helper.eth[creatorMethod](caller, 'n', 'd', 'p');
-    const bruhCross = helper.ethCrossAccount.fromAddress(bruh);
-
-    const contract = helper.ethNativeContract.collectionById(collectionId, mode, caller);
-    await contract.methods.addCollectionAdminCross(bruhCross).send(); // to check that admin will work too
 
-    const collection1 = helper.nft.getCollectionObject(collectionId);
-    const data1 = await collection1.getData();
-    expect(data1?.raw.flags.erc721metadata).to.be.false;
-    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;
-
-    await collectionHelpers.methods.makeCollectionERC721MetadataCompatible(collectionAddress, BASE_URI)
-      .send({from: bruh});
-
-    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;
-
-    const collection2 = helper.nft.getCollectionObject(collectionId);
-    const data2 = await collection2.getData();
-    expect(data2?.raw.flags.erc721metadata).to.be.true;
-
-    const propertyPermissions = data2?.raw.tokenPropertyPermissions;
-    expect(propertyPermissions?.length).to.equal(2);
-
-    expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => {
-      return tpp.key === 'URI' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner;
-    })).to.be.not.null;
-
-    expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => {
-      return tpp.key === 'URISuffix' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner;
-    })).to.be.not.null;
-
-    expect(data2?.raw.properties?.find((property: IProperty) => {
-      return property.key === 'baseURI' && property.value === BASE_URI;
-    })).to.be.not.null;
-
-    const token1Result = await contract.methods.mint(bruh).send();
-    const tokenId1 = token1Result.events.Transfer.returnValues.tokenId;
-
-    expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI);
-
-    await contract.methods.setProperties(tokenId1, [{key: 'URISuffix', value: Buffer.from(SUFFIX)}]).send();
-    expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI + SUFFIX);
-
-    await contract.methods.setProperties(tokenId1, [{key: 'URI', value: Buffer.from(URI)}]).send();
-    expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(URI);
-
-    await contract.methods.deleteProperties(tokenId1, ['URI']).send();
-    expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI + SUFFIX);
-
-    const token2Result = await contract.methods.mintWithTokenURI(bruh, URI).send();
-    const tokenId2 = token2Result.events.Transfer.returnValues.tokenId;
-
-    expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(URI);
-
-    await contract.methods.deleteProperties(tokenId2, ['URI']).send();
-    expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI);
-
-    await contract.methods.setProperties(tokenId2, [{key: 'URISuffix', value: Buffer.from(SUFFIX)}]).send();
-    expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI + SUFFIX);
-  };
-
-  itEth('ERC721Metadata property can be set for NFT collection', async({helper}) => {
-    await checkERC721Metadata(helper, 'nft');
-  });
-
-  itEth.ifWithPallets('ERC721Metadata property can be set for RFT collection', [Pallets.ReFungible], async({helper}) => {
-    await checkERC721Metadata(helper, 'rft');
-  });
+  [
+    {case: 'nft' as const},
+    {case: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+  ].map(testCase => 
+    itEth.ifWithPallets(`ERC721Metadata property can be set for ${testCase.case} collection`, testCase.requiredPallets || [], async ({helper}) => {
+      const caller = await helper.eth.createAccountWithBalance(donor);
+      const bruh = await helper.eth.createAccountWithBalance(donor);
+  
+      const BASE_URI = 'base/';
+      const SUFFIX = 'suffix1';
+      const URI = 'uri1';
+  
+      const collectionHelpers = helper.ethNativeContract.collectionHelpers(caller);
+      const creatorMethod = testCase.case === 'rft' ? 'createRFTCollection' : 'createNFTCollection';
+  
+      const {collectionId, collectionAddress} = await helper.eth[creatorMethod](caller, 'n', 'd', 'p');
+      const bruhCross = helper.ethCrossAccount.fromAddress(bruh);
+  
+      const contract = helper.ethNativeContract.collectionById(collectionId, testCase.case, caller);
+      await contract.methods.addCollectionAdminCross(bruhCross).send(); // to check that admin will work too
+  
+      const collection1 = helper.nft.getCollectionObject(collectionId);
+      const data1 = await collection1.getData();
+      expect(data1?.raw.flags.erc721metadata).to.be.false;
+      expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;
+  
+      await collectionHelpers.methods.makeCollectionERC721MetadataCompatible(collectionAddress, BASE_URI)
+        .send({from: bruh});
+  
+      expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;
+  
+      const collection2 = helper.nft.getCollectionObject(collectionId);
+      const data2 = await collection2.getData();
+      expect(data2?.raw.flags.erc721metadata).to.be.true;
+  
+      const propertyPermissions = data2?.raw.tokenPropertyPermissions;
+      expect(propertyPermissions?.length).to.equal(2);
+  
+      expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => {
+        return tpp.key === 'URI' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner;
+      })).to.be.not.null;
+  
+      expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => {
+        return tpp.key === 'URISuffix' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner;
+      })).to.be.not.null;
+  
+      expect(data2?.raw.properties?.find((property: IProperty) => {
+        return property.key === 'baseURI' && property.value === BASE_URI;
+      })).to.be.not.null;
+  
+      const token1Result = await contract.methods.mint(bruh).send();
+      const tokenId1 = token1Result.events.Transfer.returnValues.tokenId;
+  
+      expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI);
+  
+      await contract.methods.setProperties(tokenId1, [{key: 'URISuffix', value: Buffer.from(SUFFIX)}]).send();
+      expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI + SUFFIX);
+  
+      await contract.methods.setProperties(tokenId1, [{key: 'URI', value: Buffer.from(URI)}]).send();
+      expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(URI);
+  
+      await contract.methods.deleteProperties(tokenId1, ['URI']).send();
+      expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI + SUFFIX);
+  
+      const token2Result = await contract.methods.mintWithTokenURI(bruh, URI).send();
+      const tokenId2 = token2Result.events.Transfer.returnValues.tokenId;
+  
+      expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(URI);
+  
+      await contract.methods.deleteProperties(tokenId2, ['URI']).send();
+      expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI);
+  
+      await contract.methods.setProperties(tokenId2, [{key: 'URISuffix', value: Buffer.from(SUFFIX)}]).send();
+      expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI + SUFFIX);
+    }));
 });
 
 describe('EVM collection property', () => {
@@ -224,81 +219,70 @@
     });
   });
 
-  async function testSetReadProperties(helper: EthUniqueHelper, mode: TCollectionMode) {
-    const collection = await helper[mode].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});
-
-    const sender = await helper.eth.createAccountWithBalance(donor, 100n);
-    await collection.addAdmin(donor, {Ethereum: sender});
+  [
+    {case: 'nft' as const},
+    {case: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+    {case: 'ft' as const},
+  ].map(testCase => 
+    itEth.ifWithPallets(`can set/read properties ${testCase.case}`, testCase.requiredPallets || [], async ({helper}) => {
+      const collection = await helper[testCase.case].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});
 
-    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
-    const contract = helper.ethNativeContract.collection(collectionAddress, mode, sender);
-
-    const keys = ['key0', 'key1'];
-
-    const writeProperties = [
-      helper.ethProperty.property(keys[0], 'value0'),
-      helper.ethProperty.property(keys[1], 'value1'),
-    ];
-
-    await contract.methods.setCollectionProperties(writeProperties).send();
-    const readProperties = await contract.methods.collectionProperties([keys[0], keys[1]]).call();
-    expect(readProperties).to.be.like(writeProperties);
-  }
-
-  itEth('Set/read properties ft', async ({helper}) => {
-    await testSetReadProperties(helper, 'ft');
-  });
-  itEth.ifWithPallets('Set/read properties rft', [Pallets.ReFungible], async ({helper}) => {
-    await testSetReadProperties(helper, 'rft');
-  });
-  itEth('Set/read properties nft', async ({helper}) => {
-    await testSetReadProperties(helper, 'nft');
-  });
-
-  async function testDeleteProperties(helper: EthUniqueHelper, mode: TCollectionMode) {
-    const collection = await helper[mode].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});
-
-    const sender = await helper.eth.createAccountWithBalance(donor, 100n);
-    await collection.addAdmin(donor, {Ethereum: sender});
-
-    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
-    const contract = helper.ethNativeContract.collection(collectionAddress, mode, sender);
-
-    const keys = ['key0', 'key1', 'key2', 'key3'];
-
-    {
+      const sender = await helper.eth.createAccountWithBalance(donor, 100n);
+      await collection.addAdmin(donor, {Ethereum: sender});
+  
+      const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+      const contract = helper.ethNativeContract.collection(collectionAddress, testCase.case, sender);
+  
+      const keys = ['key0', 'key1'];
+  
       const writeProperties = [
         helper.ethProperty.property(keys[0], 'value0'),
         helper.ethProperty.property(keys[1], 'value1'),
-        helper.ethProperty.property(keys[2], 'value2'),
-        helper.ethProperty.property(keys[3], 'value3'),
       ];
-
+  
       await contract.methods.setCollectionProperties(writeProperties).send();
-      const readProperties = await contract.methods.collectionProperties([keys[0], keys[1], keys[2], keys[3]]).call();
+      const readProperties = await contract.methods.collectionProperties([keys[0], keys[1]]).call();
       expect(readProperties).to.be.like(writeProperties);
-    }
+    }));
 
-    {
-      const expectProperties = [
-        helper.ethProperty.property(keys[0], 'value0'),
-        helper.ethProperty.property(keys[1], 'value1'),
-      ];
+  [
+    {case: 'nft' as const},
+    {case: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+    {case: 'ft' as const},
+  ].map(testCase => 
+    itEth.ifWithPallets(`can delete properties ${testCase.case}`, testCase.requiredPallets || [], async ({helper}) => {
+      const collection = await helper[testCase.case].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});
 
-      await contract.methods.deleteCollectionProperties([keys[2], keys[3]]).send();
-      const readProperties = await contract.methods.collectionProperties([]).call();
-      expect(readProperties).to.be.like(expectProperties);
-    }
-  }
+      const sender = await helper.eth.createAccountWithBalance(donor, 100n);
+      await collection.addAdmin(donor, {Ethereum: sender});
   
-  itEth('Delete properties ft', async ({helper}) => {
-    await testDeleteProperties(helper, 'ft');
-  });
-  itEth.ifWithPallets('Delete properties rft', [Pallets.ReFungible], async ({helper}) => {
-    await testDeleteProperties(helper, 'rft');
-  });
-  itEth('Delete properties nft', async ({helper}) => {
-    await testDeleteProperties(helper, 'nft');
-  });
-    
+      const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+      const contract = helper.ethNativeContract.collection(collectionAddress, testCase.case, sender);
+  
+      const keys = ['key0', 'key1', 'key2', 'key3'];
+  
+      {
+        const writeProperties = [
+          helper.ethProperty.property(keys[0], 'value0'),
+          helper.ethProperty.property(keys[1], 'value1'),
+          helper.ethProperty.property(keys[2], 'value2'),
+          helper.ethProperty.property(keys[3], 'value3'),
+        ];
+  
+        await contract.methods.setCollectionProperties(writeProperties).send();
+        const readProperties = await contract.methods.collectionProperties([keys[0], keys[1], keys[2], keys[3]]).call();
+        expect(readProperties).to.be.like(writeProperties);
+      }
+  
+      {
+        const expectProperties = [
+          helper.ethProperty.property(keys[0], 'value0'),
+          helper.ethProperty.property(keys[1], 'value1'),
+        ];
+  
+        await contract.methods.deleteCollectionProperties([keys[2], keys[3]]).send();
+        const readProperties = await contract.methods.collectionProperties([]).call();
+        expect(readProperties).to.be.like(expectProperties);
+      }
+    }));
 });