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

difftreelog

Combine evm collection limits tests

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

4 files changed

addedtests/src/eth/collectionLimits.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/eth/collectionLimits.test.ts
@@ -0,0 +1,99 @@
+import {IKeyringPair} from '@polkadot/types/types';
+import {expect, itEth, usingEthPlaygrounds} from './util';
+
+
+describe('Can set collection limits', () => {
+  let donor: IKeyringPair;
+
+  before(async () => {
+    await usingEthPlaygrounds(async (_helper, privateKey) => {
+      donor = await privateKey({filename: __filename});
+    });
+  });
+
+  [
+    {case: 'nft' as const, method: 'createNFTCollection' as const},
+    {case: 'rft' as const, method: 'createRFTCollection' as const},
+    {case: 'ft' as const, method: 'createFTCollection' as const},
+  ].map(testCase =>
+    itEth(`for ${testCase.case}`, async ({helper}) => {
+      const owner = await helper.eth.createAccountWithBalance(donor);
+      const {collectionId, collectionAddress} = await helper.eth.createCollecion(testCase.method, owner, 'Limits', 'absolutely anything', 'FLO', 18);
+      const limits = {
+        accountTokenOwnershipLimit: 1000,
+        sponsoredDataSize: 1024,
+        sponsoredDataRateLimit: 30,
+        tokenLimit: 1000000,
+        sponsorTransferTimeout: 6,
+        sponsorApproveTimeout: 6,
+        ownerCanTransfer: 1,
+        ownerCanDestroy: 0,
+        transfersEnabled: 0,
+      };
+      
+      const expectedLimits = {
+        accountTokenOwnershipLimit: 1000,
+        sponsoredDataSize: 1024,
+        sponsoredDataRateLimit: {blocks: 30},
+        tokenLimit: 1000000,
+        sponsorTransferTimeout: 6,
+        sponsorApproveTimeout: 6,
+        ownerCanTransfer: true,
+        ownerCanDestroy: false,
+        transfersEnabled: false,
+      };
+     
+      const collection = helper.ethNativeContract.collection(collectionAddress, testCase.case, owner);
+      await collection.methods.setCollectionLimit('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();
+      await collection.methods.setCollectionLimit('sponsoredDataSize', limits.sponsoredDataSize).send();
+      await collection.methods.setCollectionLimit('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();
+      await collection.methods.setCollectionLimit('tokenLimit', limits.tokenLimit).send();
+      await collection.methods.setCollectionLimit('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();
+      await collection.methods.setCollectionLimit('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();
+      await collection.methods.setCollectionLimit('ownerCanTransfer', limits.ownerCanTransfer).send();
+      await collection.methods.setCollectionLimit('ownerCanDestroy', limits.ownerCanDestroy).send();
+      await collection.methods.setCollectionLimit('transfersEnabled', limits.transfersEnabled).send();
+      
+      const data = (await helper.rft.getData(collectionId))!;
+      expect(data.raw.limits).to.deep.eq(expectedLimits);
+      expect(await helper.collection.getEffectiveLimits(collectionId)).to.deep.eq(expectedLimits);
+    }));
+});
+
+describe('Cannot set invalid collection limits', () => {
+  let donor: IKeyringPair;
+
+  before(async () => {
+    await usingEthPlaygrounds(async (_helper, privateKey) => {
+      donor = await privateKey({filename: __filename});
+    });
+  });
+
+  [
+    {case: 'nft' as const, method: 'createNFTCollection' as const},
+    {case: 'rft' as const, method: 'createRFTCollection' as const},
+    {case: 'ft' as const, method: 'createFTCollection' as const},
+  ].map(testCase =>
+    itEth(`for ${testCase.case}`, async ({helper}) => {
+      const invalidLimits = {
+        accountTokenOwnershipLimit: BigInt(Number.MAX_SAFE_INTEGER),
+        transfersEnabled: 3,
+      };
+
+      const owner = await helper.eth.createAccountWithBalance(donor);
+      const {collectionAddress} = await helper.eth.createCollecion(testCase.method, owner, 'Limits', 'absolutely anything', 'ISNI', 18);
+      const collectionEvm = helper.ethNativeContract.collection(collectionAddress, testCase.case, owner);
+      await expect(collectionEvm.methods
+        .setCollectionLimit('badLimit', '1')
+        .call()).to.be.rejectedWith('unknown limit "badLimit"');
+      
+      await expect(collectionEvm.methods
+        .setCollectionLimit(Object.keys(invalidLimits)[0], invalidLimits.accountTokenOwnershipLimit)
+        .call()).to.be.rejectedWith(`can't convert value to u32 "${invalidLimits.accountTokenOwnershipLimit}"`);
+      
+      await expect(collectionEvm.methods
+        .setCollectionLimit(Object.keys(invalidLimits)[1], invalidLimits.transfersEnabled)
+        .call()).to.be.rejectedWith(`can't convert value to boolean "${invalidLimits.transfersEnabled}"`);
+    }));
+});
+  
\ No newline at end of file
modifiedtests/src/eth/createFTCollection.test.tsdiffbeforeafterboth
--- a/tests/src/eth/createFTCollection.test.ts
+++ b/tests/src/eth/createFTCollection.test.ts
@@ -79,56 +79,6 @@
     expect(await collection.methods.description().call()).to.deep.equal(description);
   });
 
-  itEth('Set limits', async ({helper}) => {
-    const owner = await helper.eth.createAccountWithBalance(donor);
-    const {collectionId, collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Limits', DECIMALS, 'absolutely anything', 'INSI');
-    const limits = {
-      accountTokenOwnershipLimit: 1000,
-      sponsoredDataSize: 1024,
-      sponsoredDataRateLimit: 30,
-      tokenLimit: 1000000,
-      sponsorTransferTimeout: 6,
-      sponsorApproveTimeout: 6,
-      ownerCanTransfer: 0,
-      ownerCanDestroy: 0,
-      transfersEnabled: 0,
-    };
-    
-    const expectedLimits = {
-      accountTokenOwnershipLimit: 1000,
-      sponsoredDataSize: 1024,
-      sponsoredDataRateLimit: 30,
-      tokenLimit: 1000000,
-      sponsorTransferTimeout: 6,
-      sponsorApproveTimeout: 6,
-      ownerCanTransfer: false,
-      ownerCanDestroy: false,
-      transfersEnabled: false,
-    };
-   
-    const collection = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
-    await collection.methods.setCollectionLimit('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();
-    await collection.methods.setCollectionLimit('sponsoredDataSize', limits.sponsoredDataSize).send();
-    await collection.methods.setCollectionLimit('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();
-    await collection.methods.setCollectionLimit('tokenLimit', limits.tokenLimit).send();
-    await collection.methods.setCollectionLimit('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();
-    await collection.methods.setCollectionLimit('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();
-    await collection.methods.setCollectionLimit('ownerCanTransfer', limits.ownerCanTransfer).send();
-    await collection.methods.setCollectionLimit('ownerCanDestroy', limits.ownerCanDestroy).send();
-    await collection.methods.setCollectionLimit('transfersEnabled', limits.transfersEnabled).send();
-    
-    const data = (await helper.rft.getData(collectionId))!;
-    expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(expectedLimits.accountTokenOwnershipLimit);
-    expect(data.raw.limits.sponsoredDataSize).to.be.eq(expectedLimits.sponsoredDataSize);
-    expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(expectedLimits.sponsoredDataRateLimit);
-    expect(data.raw.limits.tokenLimit).to.be.eq(expectedLimits.tokenLimit);
-    expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(expectedLimits.sponsorTransferTimeout);
-    expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(expectedLimits.sponsorApproveTimeout);
-    expect(data.raw.limits.ownerCanTransfer).to.be.eq(expectedLimits.ownerCanTransfer);
-    expect(data.raw.limits.ownerCanDestroy).to.be.eq(expectedLimits.ownerCanDestroy);
-    expect(data.raw.limits.transfersEnabled).to.be.eq(expectedLimits.transfersEnabled);
-  });
-
   itEth('Collection address exist', async ({helper}) => {
     const owner = await helper.eth.createAccountWithBalance(donor);
     const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';
@@ -274,31 +224,5 @@
         .setCollectionLimit('account_token_ownership_limit', '1000')
         .call()).to.be.rejectedWith(EXPECTED_ERROR);
     }
-  });
-
-  itEth('(!negative test!) Set limits', async ({helper}) => {
-
-    const invalidLimits = {
-      accountTokenOwnershipLimit: BigInt(Number.MAX_SAFE_INTEGER),
-      transfersEnabled: 3,
-    };
-
-    const owner = await helper.eth.createAccountWithBalance(donor);
-    const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Limits', DECIMALS, 'absolutely anything', 'ISNI');
-    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
-    await expect(collectionEvm.methods
-      .setCollectionLimit('badLimit', '1')
-      .call()).to.be.rejectedWith('unknown limit "badLimit"');
-    
-    await expect(collectionEvm.methods
-      .setCollectionLimit(Object.keys(invalidLimits)[0], invalidLimits.accountTokenOwnershipLimit)
-      .call()).to.be.rejectedWith(`can't convert value to u32 "${invalidLimits.accountTokenOwnershipLimit}"`);
-    
-    await expect(collectionEvm.methods
-      .setCollectionLimit(Object.keys(invalidLimits)[1], invalidLimits.transfersEnabled)
-      .call()).to.be.rejectedWith(`can't convert value to boolean "${invalidLimits.transfersEnabled}"`);
-  });
-
-   
-    
+  });    
 });
modifiedtests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth
120 expect(await sponsorCollection.methods.description().call()).to.deep.equal(description);120 expect(await sponsorCollection.methods.description().call()).to.deep.equal(description);
121 });121 });
122
123 itEth('Set limits', async ({helper}) => {
124 const owner = await helper.eth.createAccountWithBalance(donor);
125 const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'FLO');
126 const limits = {
127 accountTokenOwnershipLimit: 1000,
128 sponsoredDataSize: 1024,
129 sponsoredDataRateLimit: 30,
130 tokenLimit: 1000000,
131 sponsorTransferTimeout: 6,
132 sponsorApproveTimeout: 6,
133 ownerCanTransfer: 0,
134 ownerCanDestroy: 0,
135 transfersEnabled: 0,
136 };
137
138 const expectedLimits = {
139 accountTokenOwnershipLimit: 1000,
140 sponsoredDataSize: 1024,
141 sponsoredDataRateLimit: 30,
142 tokenLimit: 1000000,
143 sponsorTransferTimeout: 6,
144 sponsorApproveTimeout: 6,
145 ownerCanTransfer: false,
146 ownerCanDestroy: false,
147 transfersEnabled: false,
148 };
149
150 const collection = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
151 await collection.methods.setCollectionLimit('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();
152 await collection.methods.setCollectionLimit('sponsoredDataSize', limits.sponsoredDataSize).send();
153 await collection.methods.setCollectionLimit('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();
154 await collection.methods.setCollectionLimit('tokenLimit', limits.tokenLimit).send();
155 await collection.methods.setCollectionLimit('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();
156 await collection.methods.setCollectionLimit('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();
157 await collection.methods.setCollectionLimit('ownerCanTransfer', limits.ownerCanTransfer).send();
158 await collection.methods.setCollectionLimit('ownerCanDestroy', limits.ownerCanDestroy).send();
159 await collection.methods.setCollectionLimit('transfersEnabled', limits.transfersEnabled).send();
160
161 const data = (await helper.rft.getData(collectionId))!;
162 expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(expectedLimits.accountTokenOwnershipLimit);
163 expect(data.raw.limits.sponsoredDataSize).to.be.eq(expectedLimits.sponsoredDataSize);
164 expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(expectedLimits.sponsoredDataRateLimit);
165 expect(data.raw.limits.tokenLimit).to.be.eq(expectedLimits.tokenLimit);
166 expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(expectedLimits.sponsorTransferTimeout);
167 expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(expectedLimits.sponsorApproveTimeout);
168 expect(data.raw.limits.ownerCanTransfer).to.be.eq(expectedLimits.ownerCanTransfer);
169 expect(data.raw.limits.ownerCanDestroy).to.be.eq(expectedLimits.ownerCanDestroy);
170 expect(data.raw.limits.transfersEnabled).to.be.eq(expectedLimits.transfersEnabled);
171 });
172122
173 itEth('Collection address exist', async ({helper}) => {123 itEth('Collection address exist', async ({helper}) => {
174 const owner = await helper.eth.createAccountWithBalance(donor);124 const owner = await helper.eth.createAccountWithBalance(donor);
287 }237 }
288 });238 });
289
290 itEth('(!negative test!) Set limits', async ({helper}) => {
291 const invalidLimits = {
292 accountTokenOwnershipLimit: BigInt(Number.MAX_SAFE_INTEGER),
293 transfersEnabled: 3,
294 };
295
296 const owner = await helper.eth.createAccountWithBalance(donor);
297 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
298 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
299
300 await expect(collectionEvm.methods
301 .setCollectionLimit(Object.keys(invalidLimits)[0], invalidLimits.accountTokenOwnershipLimit)
302 .call()).to.be.rejectedWith(`can't convert value to u32 "${invalidLimits.accountTokenOwnershipLimit}"`);
303
304 await expect(collectionEvm.methods
305 .setCollectionLimit(Object.keys(invalidLimits)[1], invalidLimits.transfersEnabled)
306 .call()).to.be.rejectedWith(`can't convert value to boolean "${invalidLimits.transfersEnabled}"`);
307 });
308239
309 itEth('destroyCollection', async ({helper}) => {240 itEth('destroyCollection', async ({helper}) => {
310 const owner = await helper.eth.createAccountWithBalance(donor);241 const owner = await helper.eth.createAccountWithBalance(donor);
modifiedtests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth
--- a/tests/src/eth/createRFTCollection.test.ts
+++ b/tests/src/eth/createRFTCollection.test.ts
@@ -152,56 +152,6 @@
     expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));
   });
 
-  itEth('Set limits', async ({helper}) => {
-    const owner = await helper.eth.createAccountWithBalance(donor);
-    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'INSI');
-    const limits = {
-      accountTokenOwnershipLimit: 1000,
-      sponsoredDataSize: 1024,
-      sponsoredDataRateLimit: 30,
-      tokenLimit: 1000000,
-      sponsorTransferTimeout: 6,
-      sponsorApproveTimeout: 6,
-      ownerCanTransfer: 0,
-      ownerCanDestroy: 0,
-      transfersEnabled: 0,
-    };
-    
-    const expectedLimits = {
-      accountTokenOwnershipLimit: 1000,
-      sponsoredDataSize: 1024,
-      sponsoredDataRateLimit: 30,
-      tokenLimit: 1000000,
-      sponsorTransferTimeout: 6,
-      sponsorApproveTimeout: 6,
-      ownerCanTransfer: false,
-      ownerCanDestroy: false,
-      transfersEnabled: false,
-    };
-    
-    const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
-    await collection.methods.setCollectionLimit('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();
-    await collection.methods.setCollectionLimit('sponsoredDataSize', limits.sponsoredDataSize).send();
-    await collection.methods.setCollectionLimit('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();
-    await collection.methods.setCollectionLimit('tokenLimit', limits.tokenLimit).send();
-    await collection.methods.setCollectionLimit('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();
-    await collection.methods.setCollectionLimit('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();
-    await collection.methods.setCollectionLimit('ownerCanTransfer', limits.ownerCanTransfer).send();
-    await collection.methods.setCollectionLimit('ownerCanDestroy', limits.ownerCanDestroy).send();
-    await collection.methods.setCollectionLimit('transfersEnabled', limits.transfersEnabled).send();
-    
-    const data = (await helper.rft.getData(collectionId))!;
-    expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(expectedLimits.accountTokenOwnershipLimit);
-    expect(data.raw.limits.sponsoredDataSize).to.be.eq(expectedLimits.sponsoredDataSize);
-    expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(expectedLimits.sponsoredDataRateLimit);
-    expect(data.raw.limits.tokenLimit).to.be.eq(expectedLimits.tokenLimit);
-    expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(expectedLimits.sponsorTransferTimeout);
-    expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(expectedLimits.sponsorApproveTimeout);
-    expect(data.raw.limits.ownerCanTransfer).to.be.eq(expectedLimits.ownerCanTransfer);
-    expect(data.raw.limits.ownerCanDestroy).to.be.eq(expectedLimits.ownerCanDestroy);
-    expect(data.raw.limits.transfersEnabled).to.be.eq(expectedLimits.transfersEnabled);
-  });
-
   itEth('Collection address exist', async ({helper}) => {
     const owner = await helper.eth.createAccountWithBalance(donor);
     const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';
@@ -317,25 +267,6 @@
         .setCollectionLimit('account_token_ownership_limit', '1000')
         .call()).to.be.rejectedWith(EXPECTED_ERROR);
     }
-  });
-
-  itEth('(!negative test!) Set limits', async ({helper}) => {
-    const invalidLimits = {
-      accountTokenOwnershipLimit: BigInt(Number.MAX_SAFE_INTEGER),
-      transfersEnabled: 3,
-    };
-
-    const owner = await helper.eth.createAccountWithBalance(donor);
-    const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'ISNI');
-    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
-    
-    await expect(collectionEvm.methods
-      .setCollectionLimit(Object.keys(invalidLimits)[0], invalidLimits.accountTokenOwnershipLimit)
-      .call()).to.be.rejectedWith(`can't convert value to u32 "${invalidLimits.accountTokenOwnershipLimit}"`);
-    
-    await expect(collectionEvm.methods
-      .setCollectionLimit(Object.keys(invalidLimits)[1], invalidLimits.transfersEnabled)
-      .call()).to.be.rejectedWith(`can't convert value to boolean "${invalidLimits.transfersEnabled}"`);
   });
   
   itEth('destroyCollection', async ({helper}) => {