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.tsdiffbeforeafterboth1import {expect} from 'chai';2import privateKey from '../substrate/privateKey';3import {submitTransactionAsync} from '../substrate/substrate-api';4import {createEthAccountWithBalance, deployCollector, GAS_ARGS, itWeb3, subToEth, transferBalanceToEth} from './util/helpers';5import {evmToAddress} from '@polkadot/util-crypto';6import {getGenericResult} from '../util/helpers';7import {getBalanceSingle, transferBalanceExpectSuccess} from '../substrate/get-balance';89describe('EVM payable contracts', () => {10 itWeb3('Evm contract can receive wei from eth account', async ({api, web3}) => {11 const deployer = await createEthAccountWithBalance(api, web3);12 const contract = await deployCollector(web3, deployer);1314 await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: '10000', ...GAS_ARGS});1516 expect(await contract.methods.getCollected().call()).to.be.equal('10000');17 });1819 itWeb3('Evm contract can receive wei from substrate account', async ({api, web3}) => {20 const deployer = await createEthAccountWithBalance(api, web3);21 const contract = await deployCollector(web3, deployer);22 const alice = privateKey('//Alice');2324 // Transaction fee/value will be payed from subToEth(sender) evm balance,25 // which is backed by evmToAddress(subToEth(sender)) substrate balance26 await transferBalanceToEth(api, alice, subToEth(alice.address));2728 {29 const tx = api.tx.evm.call(30 subToEth(alice.address),31 contract.options.address,32 contract.methods.giveMoney().encodeABI(),33 '10000',34 GAS_ARGS.gas,35 await web3.eth.getGasPrice(),36 null,37 );38 const events = await submitTransactionAsync(alice, tx);39 const result = getGenericResult(events);40 expect(result.success).to.be.true;41 }4243 expect(await contract.methods.getCollected().call()).to.be.equal('10000');44 });4546 // We can't handle sending balance to backing storage of evm balance, because evmToAddress operation is irreversible47 itWeb3('Wei sent directly to backing storage of evm contract balance is unaccounted', async({api, web3}) => {48 const deployer = await createEthAccountWithBalance(api, web3);49 const contract = await deployCollector(web3, deployer);50 const alice = privateKey('//Alice');5152 await transferBalanceExpectSuccess(api, alice, evmToAddress(contract.options.address), '10000');5354 expect(await contract.methods.getUnaccounted().call()).to.be.equal('10000');55 });5657 itWeb3('Balance can be retrieved from evm contract', async({api, web3}) => {58 const FEE_BALANCE = 10n ** 18n;59 const CONTRACT_BALANCE = 10n ** 14n;6061 const deployer = await createEthAccountWithBalance(api, web3);62 const contract = await deployCollector(web3, deployer);63 const alice = privateKey('//Alice');6465 await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: CONTRACT_BALANCE.toString(), ...GAS_ARGS});6667 const receiver = privateKey(`//Receiver${Date.now()}`);6869 // First receive balance on eth balance of bob70 {71 const ethReceiver = subToEth(receiver.address);72 expect(await web3.eth.getBalance(ethReceiver)).to.be.equal('0');73 await contract.methods.withdraw(ethReceiver).send({from: deployer});74 expect(await web3.eth.getBalance(ethReceiver)).to.be.equal(CONTRACT_BALANCE.toString());75 }7677 // Some balance is required to pay fee for evm.withdraw call78 await transferBalanceExpectSuccess(api, alice, receiver.address, FEE_BALANCE.toString());7980 // Withdraw balance from eth to substrate81 {82 const initialReceiverBalance = await getBalanceSingle(api, receiver.address);83 const tx = api.tx.evm.withdraw(84 subToEth(receiver.address),85 CONTRACT_BALANCE.toString(),86 );87 const events = await submitTransactionAsync(receiver, tx);88 const result = getGenericResult(events);89 expect(result.success).to.be.true;90 const finalReceiverBalance = await getBalanceSingle(api, receiver.address);9192 expect(finalReceiverBalance > initialReceiverBalance).to.be.true;93 }94 });95});1import {expect} from 'chai';2import privateKey from '../substrate/privateKey';3import {submitTransactionAsync} from '../substrate/substrate-api';4import {createEthAccountWithBalance, deployCollector, GAS_ARGS, itWeb3, subToEth, transferBalanceToEth} from './util/helpers';5import {evmToAddress} from '@polkadot/util-crypto';6import {getGenericResult, UNIQUE} from '../util/helpers';7import {getBalanceSingle, transferBalanceExpectSuccess} from '../substrate/get-balance';89describe('EVM payable contracts', () => {10 itWeb3('Evm contract can receive wei from eth account', async ({api, web3}) => {11 const deployer = await createEthAccountWithBalance(api, web3);12 const contract = await deployCollector(web3, deployer);1314 await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: '10000', ...GAS_ARGS});1516 expect(await contract.methods.getCollected().call()).to.be.equal('10000');17 });1819 itWeb3('Evm contract can receive wei from substrate account', async ({api, web3}) => {20 const deployer = await createEthAccountWithBalance(api, web3);21 const contract = await deployCollector(web3, deployer);22 const alice = privateKey('//Alice');2324 // Transaction fee/value will be payed from subToEth(sender) evm balance,25 // which is backed by evmToAddress(subToEth(sender)) substrate balance26 await transferBalanceToEth(api, alice, subToEth(alice.address));2728 {29 const tx = api.tx.evm.call(30 subToEth(alice.address),31 contract.options.address,32 contract.methods.giveMoney().encodeABI(),33 '10000',34 GAS_ARGS.gas,35 await web3.eth.getGasPrice(),36 null,37 );38 const events = await submitTransactionAsync(alice, tx);39 const result = getGenericResult(events);40 expect(result.success).to.be.true;41 }4243 expect(await contract.methods.getCollected().call()).to.be.equal('10000');44 });4546 // We can't handle sending balance to backing storage of evm balance, because evmToAddress operation is irreversible47 itWeb3('Wei sent directly to backing storage of evm contract balance is unaccounted', async({api, web3}) => {48 const deployer = await createEthAccountWithBalance(api, web3);49 const contract = await deployCollector(web3, deployer);50 const alice = privateKey('//Alice');5152 await transferBalanceExpectSuccess(api, alice, evmToAddress(contract.options.address), '10000');5354 expect(await contract.methods.getUnaccounted().call()).to.be.equal('10000');55 });5657 itWeb3('Balance can be retrieved from evm contract', async({api, web3}) => {58 const FEE_BALANCE = 1000n * UNIQUE;59 const CONTRACT_BALANCE = 1n * UNIQUE;6061 const deployer = await createEthAccountWithBalance(api, web3);62 const contract = await deployCollector(web3, deployer);63 const alice = privateKey('//Alice');6465 await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: CONTRACT_BALANCE.toString(), ...GAS_ARGS});6667 const receiver = privateKey(`//Receiver${Date.now()}`);6869 // First receive balance on eth balance of bob70 {71 const ethReceiver = subToEth(receiver.address);72 expect(await web3.eth.getBalance(ethReceiver)).to.be.equal('0');73 await contract.methods.withdraw(ethReceiver).send({from: deployer});74 expect(await web3.eth.getBalance(ethReceiver)).to.be.equal(CONTRACT_BALANCE.toString());75 }7677 // Some balance is required to pay fee for evm.withdraw call78 await transferBalanceExpectSuccess(api, alice, receiver.address, FEE_BALANCE.toString());7980 // Withdraw balance from eth to substrate81 {82 const initialReceiverBalance = await getBalanceSingle(api, receiver.address);83 const tx = api.tx.evm.withdraw(84 subToEth(receiver.address),85 CONTRACT_BALANCE.toString(),86 );87 const events = await submitTransactionAsync(receiver, tx);88 const result = getGenericResult(events);89 expect(result.success).to.be.true;90 const finalReceiverBalance = await getBalanceSingle(api, receiver.address);9192 expect(finalReceiverBalance > initialReceiverBalance).to.be.true;93 }94 });95});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.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);