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

difftreelog

Merge pull request #258 from UniqueNetwork/fix/unit_tests

kozyrevdev2021-12-03parents: #12f45ba #7bc9172.patch.diff
in: master
Unit tests fixed

6 files changed

modifiedpallets/unique/src/mock.rsdiffbeforeafterboth
--- a/pallets/unique/src/mock.rs
+++ b/pallets/unique/src/mock.rs
@@ -193,6 +193,7 @@
 }
 
 impl pallet_template::Config for Test {
+	type Event = ();
 	type WeightInfo = ();
 }
 
modifiedpallets/unique/src/tests.rsdiffbeforeafterboth
--- a/pallets/unique/src/tests.rs
+++ b/pallets/unique/src/tests.rs
@@ -2259,7 +2259,7 @@
 	new_test_ext().execute_with(|| {
 		let origin1 = Origin::signed(1);
 
-		for i in 1..COLLECTION_NUMBER_LIMIT {
+		for i in 1..=COLLECTION_NUMBER_LIMIT {
 			create_test_collection(&CollectionMode::NFT, CollectionId(i));
 		}
 
modifiedtests/src/eth/payable.test.tsdiffbeforeafterboth
--- a/tests/src/eth/payable.test.ts
+++ b/tests/src/eth/payable.test.ts
@@ -3,7 +3,7 @@
 import {submitTransactionAsync} from '../substrate/substrate-api';
 import {createEthAccountWithBalance, deployCollector, GAS_ARGS, itWeb3, subToEth, transferBalanceToEth} from './util/helpers';
 import {evmToAddress} from '@polkadot/util-crypto';
-import {getGenericResult} from '../util/helpers';
+import {getGenericResult, UNIQUE} from '../util/helpers';
 import {getBalanceSingle, transferBalanceExpectSuccess} from '../substrate/get-balance';
 
 describe('EVM payable contracts', () => {
@@ -55,8 +55,8 @@
   });
 
   itWeb3('Balance can be retrieved from evm contract', async({api, web3}) => {
-    const FEE_BALANCE = 10n ** 18n;
-    const CONTRACT_BALANCE = 10n ** 14n;
+    const FEE_BALANCE = 1000n * UNIQUE;
+    const CONTRACT_BALANCE = 1n * UNIQUE;
 
     const deployer = await createEthAccountWithBalance(api, web3);
     const contract = await deployCollector(web3, deployer);
modifiedtests/src/setConstOnChainSchema.test.tsdiffbeforeafterboth
before · tests/src/setConstOnChainSchema.test.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import {Keyring} from '@polkadot/api';7import {IKeyringPair} from '@polkadot/types/types';8import chai from 'chai';9import chaiAsPromised from 'chai-as-promised';10import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';11import {12  createCollectionExpectSuccess,13  destroyCollectionExpectSuccess,14  addCollectionAdminExpectSuccess,15  queryCollectionExpectSuccess,16  getCreatedCollectionCount,17} from './util/helpers';1819chai.use(chaiAsPromised);20const expect = chai.expect;2122let alice: IKeyringPair;23let bob: IKeyringPair;24let shema: any;25let largeShema: any;2627before(async () => {28  await usingApi(async () => {29    const keyring = new Keyring({type: 'sr25519'});30    alice = keyring.addFromUri('//Alice');31    bob = keyring.addFromUri('//Bob');32    shema = '0x31';33    largeShema = new Array(4097).fill(0xff);3435  });36});37describe('Integration Test ext. setConstOnChainSchema()', () => {3839  it('Run extrinsic with parameters of the collection id, set the scheme', async () => {40    await usingApi(async (api) => {41      const collectionId = await createCollectionExpectSuccess();42      const collection = await queryCollectionExpectSuccess(api, collectionId);43      expect(collection.owner.toString()).to.be.eq(alice.address);44      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);45      await submitTransactionAsync(alice, setShema);46    });47  });4849  it('Collection admin can set the scheme', async () => {50    await usingApi(async (api) => {51      const collectionId = await createCollectionExpectSuccess();52      const collection = await queryCollectionExpectSuccess(api, collectionId);53      expect(collection.owner.toString()).to.be.eq(alice.address);54      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);55      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);56      await submitTransactionAsync(bob, setShema);57    });58  });5960  it('Checking collection data using the ConstOnChainSchema parameter', async () => {61    await usingApi(async (api) => {62      const collectionId = await createCollectionExpectSuccess();63      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);64      await submitTransactionAsync(alice, setShema);65      const collection = await queryCollectionExpectSuccess(api, collectionId);66      expect(collection.constOnChainSchema.toString()).to.be.eq(shema);67    });68  });69});7071describe('Negative Integration Test ext. setConstOnChainSchema()', () => {7273  it('Set a non-existent collection', async () => {74    await usingApi(async (api) => {75      // tslint:disable-next-line: radix76      const collectionId = await getCreatedCollectionCount(api) + 1;77      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);78      await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;79    });80  });8182  it('Set a previously deleted collection', async () => {83    await usingApi(async (api) => {84      const collectionId = await createCollectionExpectSuccess();85      await destroyCollectionExpectSuccess(collectionId);86      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);87      await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;88    });89  });9091  it('Set invalid data in schema (size too large:> 1024b)', async () => {92    await usingApi(async (api) => {93      const collectionId = await createCollectionExpectSuccess();94      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, largeShema);95      await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;96    });97  });9899  it('Execute method not on behalf of the collection owner', async () => {100    await usingApi(async (api) => {101      const collectionId = await createCollectionExpectSuccess();102      const collection = await queryCollectionExpectSuccess(api, collectionId);103      expect(collection.owner.toString()).to.be.eq(alice.address);104      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);105      await expect(submitTransactionExpectFailAsync(bob, setShema)).to.be.rejected;106    });107  });108109});
after · tests/src/setConstOnChainSchema.test.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import {Keyring} from '@polkadot/api';7import {IKeyringPair} from '@polkadot/types/types';8import chai from 'chai';9import chaiAsPromised from 'chai-as-promised';10import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';11import {12  createCollectionExpectSuccess,13  destroyCollectionExpectSuccess,14  addCollectionAdminExpectSuccess,15  queryCollectionExpectSuccess,16  getCreatedCollectionCount,17} from './util/helpers';1819chai.use(chaiAsPromised);20const expect = chai.expect;2122let alice: IKeyringPair;23let bob: IKeyringPair;24let shema: any;25let largeShema: any;2627before(async () => {28  await usingApi(async () => {29    const keyring = new Keyring({type: 'sr25519'});30    alice = keyring.addFromUri('//Alice');31    bob = keyring.addFromUri('//Bob');32    shema = '0x31';33    largeShema = new Array(1024 * 1024 + 10).fill(0xff);34  });35});36describe('Integration Test ext. setConstOnChainSchema()', () => {3738  it('Run extrinsic with parameters of the collection id, set the scheme', async () => {39    await usingApi(async (api) => {40      const collectionId = await createCollectionExpectSuccess();41      const collection = await queryCollectionExpectSuccess(api, collectionId);42      expect(collection.owner.toString()).to.be.eq(alice.address);43      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);44      await submitTransactionAsync(alice, setShema);45    });46  });4748  it('Collection admin can set the scheme', async () => {49    await usingApi(async (api) => {50      const collectionId = await createCollectionExpectSuccess();51      const collection = await queryCollectionExpectSuccess(api, collectionId);52      expect(collection.owner.toString()).to.be.eq(alice.address);53      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);54      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);55      await submitTransactionAsync(bob, setShema);56    });57  });5859  it('Checking collection data using the ConstOnChainSchema parameter', async () => {60    await usingApi(async (api) => {61      const collectionId = await createCollectionExpectSuccess();62      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);63      await submitTransactionAsync(alice, setShema);64      const collection = await queryCollectionExpectSuccess(api, collectionId);65      expect(collection.constOnChainSchema.toString()).to.be.eq(shema);66    });67  });68});6970describe('Negative Integration Test ext. setConstOnChainSchema()', () => {7172  it('Set a non-existent collection', async () => {73    await usingApi(async (api) => {74      // tslint:disable-next-line: radix75      const collectionId = await getCreatedCollectionCount(api) + 1;76      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);77      await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;78    });79  });8081  it('Set a previously deleted collection', async () => {82    await usingApi(async (api) => {83      const collectionId = await createCollectionExpectSuccess();84      await destroyCollectionExpectSuccess(collectionId);85      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);86      await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;87    });88  });8990  it('Set invalid data in schema (size too large:> 1MB)', async () => {91    await usingApi(async (api) => {92      const collectionId = await createCollectionExpectSuccess();93      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, largeShema);94      await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;95    });96  });9798  it('Execute method not on behalf of the collection owner', async () => {99    await usingApi(async (api) => {100      const collectionId = await createCollectionExpectSuccess();101      const collection = await queryCollectionExpectSuccess(api, collectionId);102      expect(collection.owner.toString()).to.be.eq(alice.address);103      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);104      await expect(submitTransactionExpectFailAsync(bob, setShema)).to.be.rejected;105    });106  });107108});
modifiedtests/src/setOffchainSchema.test.tsdiffbeforeafterboth
--- a/tests/src/setOffchainSchema.test.ts
+++ b/tests/src/setOffchainSchema.test.ts
@@ -84,8 +84,8 @@
     await setOffchainSchemaExpectFailure(alice, destroyedCollectionId, DATA);
   });
 
-  it('fails on too long data', async () => {
-    const tooLongData = new Array(4097).fill(0xff);
+  it.only('fails on too long data', async () => {
+    const tooLongData = new Array(8 * 1024 + 10).fill(0xff);
 
     await setOffchainSchemaExpectFailure(alice, validCollectionId, tooLongData);
   });
modifiedtests/src/setVariableOnChainSchema.test.tsdiffbeforeafterboth
--- a/tests/src/setVariableOnChainSchema.test.ts
+++ b/tests/src/setVariableOnChainSchema.test.ts
@@ -30,7 +30,7 @@
     alice = keyring.addFromUri('//Alice');
     bob = keyring.addFromUri('//Bob');
     schema = '0x31';
-    largeSchema = new Array(4097).fill(0xff);
+    largeSchema = new Array(8 * 1024 + 10).fill(0xff);
 
   });
 });
@@ -104,7 +104,7 @@
     });
   });
 
-  it('Set invalid data in schema (size too large:> 1024b)', async () => {
+  it('Set invalid data in schema (size too large:> 8kB)', async () => {
     await usingApi(async (api) => {
       const collectionId = await createCollectionExpectSuccess();
       const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, largeSchema);