difftreelog
Merge pull request #258 from UniqueNetwork/fix/unit_tests
in: master
Unit tests fixed
6 files changed
pallets/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 = ();
}
pallets/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));
}
tests/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);
tests/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);
tests/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);
});
tests/src/setVariableOnChainSchema.test.tsdiffbeforeafterboth1//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 schema: any;25let largeSchema: 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 schema = '0x31';33 largeSchema = new Array(4097).fill(0xff);3435 });36});37describe('Integration Test ext. setVariableOnChainSchema()', () => {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 setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);45 await submitTransactionAsync(alice, setSchema);46 });47 });4849 it('Checking collection data using the setVariableOnChainSchema parameter', async () => {50 await usingApi(async (api) => {51 const collectionId = await createCollectionExpectSuccess();52 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);53 await submitTransactionAsync(alice, setSchema);54 const collection = await queryCollectionExpectSuccess(api, collectionId);55 expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);5657 });58 });59});6061describe('Integration Test ext. collection admin setVariableOnChainSchema()', () => {6263 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {64 await usingApi(async (api) => {65 const collectionId = await createCollectionExpectSuccess();66 const collection = await queryCollectionExpectSuccess(api, collectionId);67 expect(collection.owner.toString()).to.be.eq(alice.address);68 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);69 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);70 await submitTransactionAsync(bob, setSchema);71 });72 });7374 it('Checking collection data using the setVariableOnChainSchema parameter', async () => {75 await usingApi(async (api) => {76 const collectionId = await createCollectionExpectSuccess();77 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);78 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);79 await submitTransactionAsync(bob, setSchema);80 const collection = await queryCollectionExpectSuccess(api, collectionId);81 expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);8283 });84 });85});8687describe('Negative Integration Test ext. setVariableOnChainSchema()', () => {8889 it('Set a non-existent collection', async () => {90 await usingApi(async (api) => {91 // tslint:disable-next-line: radix92 const collectionId = await getCreatedCollectionCount(api) + 1;93 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);94 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;95 });96 });9798 it('Set a previously deleted collection', async () => {99 await usingApi(async (api) => {100 const collectionId = await createCollectionExpectSuccess();101 await destroyCollectionExpectSuccess(collectionId);102 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);103 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;104 });105 });106107 it('Set invalid data in schema (size too large:> 1024b)', async () => {108 await usingApi(async (api) => {109 const collectionId = await createCollectionExpectSuccess();110 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, largeSchema);111 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;112 });113 });114115 it('Execute method not on behalf of the collection owner', async () => {116 await usingApi(async (api) => {117 const collectionId = await createCollectionExpectSuccess();118 const collection = await queryCollectionExpectSuccess(api, collectionId);119 expect(collection.owner.toString()).to.be.eq(alice.address);120 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);121 await expect(submitTransactionExpectFailAsync(bob, setSchema)).to.be.rejected;122 });123 });124125});