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
--- a/tests/src/setConstOnChainSchema.test.ts
+++ b/tests/src/setConstOnChainSchema.test.ts
@@ -30,8 +30,7 @@
     alice = keyring.addFromUri('//Alice');
     bob = keyring.addFromUri('//Bob');
     shema = '0x31';
-    largeShema = new Array(4097).fill(0xff);
-
+    largeShema = new Array(1024 * 1024 + 10).fill(0xff);
   });
 });
 describe('Integration Test ext. setConstOnChainSchema()', () => {
@@ -88,7 +87,7 @@
     });
   });
 
-  it('Set invalid data in schema (size too large:> 1024b)', async () => {
+  it('Set invalid data in schema (size too large:> 1MB)', async () => {
     await usingApi(async (api) => {
       const collectionId = await createCollectionExpectSuccess();
       const setShema = api.tx.unique.setConstOnChainSchema(collectionId, largeShema);
modifiedtests/src/setOffchainSchema.test.tsdiffbeforeafterboth
before · tests/src/setOffchainSchema.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 {IKeyringPair} from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import usingApi from './substrate/substrate-api';11import {12  createCollectionExpectSuccess,13  destroyCollectionExpectSuccess,14  findNotExistingCollection,15  queryCollectionExpectSuccess,16  setOffchainSchemaExpectFailure,17  setOffchainSchemaExpectSuccess,18  addCollectionAdminExpectSuccess,19} from './util/helpers';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324const DATA = [1, 2, 3, 4];2526describe('Integration Test setOffchainSchema', () => {27  let alice: IKeyringPair;28  let bob: IKeyringPair;2930  before(async () => {31    await usingApi(async () => {32      alice = privateKey('//Alice');33      bob = privateKey('//Bob');34    });35  });3637  it('execute setOffchainSchema, verify data was set', async () => {38    await usingApi(async api => {39      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});40      await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);41      const collection = await queryCollectionExpectSuccess(api, collectionId);4243      expect('0x' + Buffer.from(collection.offchainSchema).toString('hex')).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));44    });45  });4647  it('execute setOffchainSchema (collection admin), verify data was set', async () => {48    await usingApi(async api => {49      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});50      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);51      await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);52      const collection = await queryCollectionExpectSuccess(api, collectionId);5354      expect('0x' + Buffer.from(collection.offchainSchema).toString('hex')).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));55    });56  });57});5859describe('Negative Integration Test setOffchainSchema', () => {60  let alice: IKeyringPair;61  let bob: IKeyringPair;6263  let validCollectionId: number;6465  before(async () => {66    await usingApi(async () => {67      alice = privateKey('//Alice');68      bob = privateKey('//Bob');6970      validCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});71    });72  });7374  it('fails on not existing collection id', async () => {75    const nonExistingCollectionId = await usingApi(findNotExistingCollection);7677    await setOffchainSchemaExpectFailure(alice, nonExistingCollectionId, DATA);78  });7980  it('fails on destroyed collection id', async () => {81    const destroyedCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});82    await destroyCollectionExpectSuccess(destroyedCollectionId);8384    await setOffchainSchemaExpectFailure(alice, destroyedCollectionId, DATA);85  });8687  it('fails on too long data', async () => {88    const tooLongData = new Array(4097).fill(0xff);8990    await setOffchainSchemaExpectFailure(alice, validCollectionId, tooLongData);91  });9293  it('fails on execution by non-owner', async () => {94    await setOffchainSchemaExpectFailure(bob, validCollectionId, DATA);95  });96});
after · tests/src/setOffchainSchema.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 {IKeyringPair} from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import usingApi from './substrate/substrate-api';11import {12  createCollectionExpectSuccess,13  destroyCollectionExpectSuccess,14  findNotExistingCollection,15  queryCollectionExpectSuccess,16  setOffchainSchemaExpectFailure,17  setOffchainSchemaExpectSuccess,18  addCollectionAdminExpectSuccess,19} from './util/helpers';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324const DATA = [1, 2, 3, 4];2526describe('Integration Test setOffchainSchema', () => {27  let alice: IKeyringPair;28  let bob: IKeyringPair;2930  before(async () => {31    await usingApi(async () => {32      alice = privateKey('//Alice');33      bob = privateKey('//Bob');34    });35  });3637  it('execute setOffchainSchema, verify data was set', async () => {38    await usingApi(async api => {39      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});40      await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);41      const collection = await queryCollectionExpectSuccess(api, collectionId);4243      expect('0x' + Buffer.from(collection.offchainSchema).toString('hex')).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));44    });45  });4647  it('execute setOffchainSchema (collection admin), verify data was set', async () => {48    await usingApi(async api => {49      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});50      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);51      await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);52      const collection = await queryCollectionExpectSuccess(api, collectionId);5354      expect('0x' + Buffer.from(collection.offchainSchema).toString('hex')).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));55    });56  });57});5859describe('Negative Integration Test setOffchainSchema', () => {60  let alice: IKeyringPair;61  let bob: IKeyringPair;6263  let validCollectionId: number;6465  before(async () => {66    await usingApi(async () => {67      alice = privateKey('//Alice');68      bob = privateKey('//Bob');6970      validCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});71    });72  });7374  it('fails on not existing collection id', async () => {75    const nonExistingCollectionId = await usingApi(findNotExistingCollection);7677    await setOffchainSchemaExpectFailure(alice, nonExistingCollectionId, DATA);78  });7980  it('fails on destroyed collection id', async () => {81    const destroyedCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});82    await destroyCollectionExpectSuccess(destroyedCollectionId);8384    await setOffchainSchemaExpectFailure(alice, destroyedCollectionId, DATA);85  });8687  it.only('fails on too long data', async () => {88    const tooLongData = new Array(8 * 1024 + 10).fill(0xff);8990    await setOffchainSchemaExpectFailure(alice, validCollectionId, tooLongData);91  });9293  it('fails on execution by non-owner', async () => {94    await setOffchainSchemaExpectFailure(bob, validCollectionId, DATA);95  });96});
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);