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
--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -120,56 +120,6 @@
     expect(await sponsorCollection.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.createNFTCollection(owner, 'Limits', 'absolutely anything', 'FLO');
-    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, 'nft', 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';
@@ -285,25 +235,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.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
-    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', 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}) => {
modifiedtests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth
152 expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));152 expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));
153 });153 });
154
155 itEth('Set limits', async ({helper}) => {
156 const owner = await helper.eth.createAccountWithBalance(donor);
157 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'INSI');
158 const limits = {
159 accountTokenOwnershipLimit: 1000,
160 sponsoredDataSize: 1024,
161 sponsoredDataRateLimit: 30,
162 tokenLimit: 1000000,
163 sponsorTransferTimeout: 6,
164 sponsorApproveTimeout: 6,
165 ownerCanTransfer: 0,
166 ownerCanDestroy: 0,
167 transfersEnabled: 0,
168 };
169
170 const expectedLimits = {
171 accountTokenOwnershipLimit: 1000,
172 sponsoredDataSize: 1024,
173 sponsoredDataRateLimit: 30,
174 tokenLimit: 1000000,
175 sponsorTransferTimeout: 6,
176 sponsorApproveTimeout: 6,
177 ownerCanTransfer: false,
178 ownerCanDestroy: false,
179 transfersEnabled: false,
180 };
181
182 const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
183 await collection.methods.setCollectionLimit('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();
184 await collection.methods.setCollectionLimit('sponsoredDataSize', limits.sponsoredDataSize).send();
185 await collection.methods.setCollectionLimit('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();
186 await collection.methods.setCollectionLimit('tokenLimit', limits.tokenLimit).send();
187 await collection.methods.setCollectionLimit('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();
188 await collection.methods.setCollectionLimit('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();
189 await collection.methods.setCollectionLimit('ownerCanTransfer', limits.ownerCanTransfer).send();
190 await collection.methods.setCollectionLimit('ownerCanDestroy', limits.ownerCanDestroy).send();
191 await collection.methods.setCollectionLimit('transfersEnabled', limits.transfersEnabled).send();
192
193 const data = (await helper.rft.getData(collectionId))!;
194 expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(expectedLimits.accountTokenOwnershipLimit);
195 expect(data.raw.limits.sponsoredDataSize).to.be.eq(expectedLimits.sponsoredDataSize);
196 expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(expectedLimits.sponsoredDataRateLimit);
197 expect(data.raw.limits.tokenLimit).to.be.eq(expectedLimits.tokenLimit);
198 expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(expectedLimits.sponsorTransferTimeout);
199 expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(expectedLimits.sponsorApproveTimeout);
200 expect(data.raw.limits.ownerCanTransfer).to.be.eq(expectedLimits.ownerCanTransfer);
201 expect(data.raw.limits.ownerCanDestroy).to.be.eq(expectedLimits.ownerCanDestroy);
202 expect(data.raw.limits.transfersEnabled).to.be.eq(expectedLimits.transfersEnabled);
203 });
204154
205 itEth('Collection address exist', async ({helper}) => {155 itEth('Collection address exist', async ({helper}) => {
206 const owner = await helper.eth.createAccountWithBalance(donor);156 const owner = await helper.eth.createAccountWithBalance(donor);
319 }269 }
320 });270 });
321271
322 itEth('(!negative test!) Set limits', async ({helper}) => {
323 const invalidLimits = {
324 accountTokenOwnershipLimit: BigInt(Number.MAX_SAFE_INTEGER),
325 transfersEnabled: 3,
326 };
327
328 const owner = await helper.eth.createAccountWithBalance(donor);
329 const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'ISNI');
330 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
331
332 await expect(collectionEvm.methods
333 .setCollectionLimit(Object.keys(invalidLimits)[0], invalidLimits.accountTokenOwnershipLimit)
334 .call()).to.be.rejectedWith(`can't convert value to u32 "${invalidLimits.accountTokenOwnershipLimit}"`);
335
336 await expect(collectionEvm.methods
337 .setCollectionLimit(Object.keys(invalidLimits)[1], invalidLimits.transfersEnabled)
338 .call()).to.be.rejectedWith(`can't convert value to boolean "${invalidLimits.transfersEnabled}"`);
339 });
340
341 itEth('destroyCollection', async ({helper}) => {272 itEth('destroyCollection', async ({helper}) => {
342 const owner = await helper.eth.createAccountWithBalance(donor);273 const owner = await helper.eth.createAccountWithBalance(donor);