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
before · pallets/unique/src/mock.rs
1#![allow(clippy::from_over_into)]23use crate as pallet_template;4use sp_core::{H160, H256};5use frame_support::{parameter_types, traits::Everything, weights::IdentityFee};6use sp_runtime::{7	traits::{BlakeTwo256, IdentityLookup},8	testing::Header,9};10use pallet_transaction_payment::{CurrencyAdapter};11use frame_system as system;12use pallet_evm::AddressMapping;13use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};14use codec::{Encode, Decode};15use scale_info::TypeInfo;1617type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;18type Block = frame_system::mocking::MockBlock<Test>;1920// Configure a mock runtime to test the pallet.21frame_support::construct_runtime!(22	pub enum Test where23		Block = Block,24		NodeBlock = Block,25		UncheckedExtrinsic = UncheckedExtrinsic,26	{27		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},28		TemplateModule: pallet_template::{Pallet, Call, Storage},29		Balances: pallet_balances::{Pallet, Call, Storage},30		Common: pallet_common::{Pallet, Storage, Event<T>},31		Fungible: pallet_fungible::{Pallet, Storage},32		Refungible: pallet_refungible::{Pallet, Storage},33		Nonfungible: pallet_nonfungible::{Pallet, Storage},34	}35);3637parameter_types! {38	pub const BlockHashCount: u64 = 250;39	pub const SS58Prefix: u8 = 42;40}4142impl system::Config for Test {43	type BaseCallFilter = Everything;44	type BlockWeights = ();45	type BlockLength = ();46	type DbWeight = ();47	type Origin = Origin;48	type Call = Call;49	type Index = u64;50	type BlockNumber = u64;51	type Hash = H256;52	type Hashing = BlakeTwo256;53	type AccountId = u64;54	type Lookup = IdentityLookup<Self::AccountId>;55	type Header = Header;56	type Event = ();57	type BlockHashCount = BlockHashCount;58	type Version = ();59	type PalletInfo = PalletInfo;60	type AccountData = pallet_balances::AccountData<u64>;61	type OnNewAccount = ();62	type OnKilledAccount = ();63	type SystemWeightInfo = ();64	type SS58Prefix = SS58Prefix;65	type OnSetCode = ();66}6768parameter_types! {69	pub const ExistentialDeposit: u64 = 1;70	pub const MaxLocks: u32 = 50;71}72//frame_system::Module<Test>;73impl pallet_balances::Config for Test {74	type AccountStore = System;75	type Balance = u64;76	type DustRemoval = ();77	type Event = ();78	type ExistentialDeposit = ExistentialDeposit;79	type WeightInfo = ();80	type MaxLocks = MaxLocks;81	type MaxReserves = ();82	type ReserveIdentifier = [u8; 8];83}8485parameter_types! {86	pub const TransactionByteFee: u64 = 1;87	pub const OperationalFeeMultiplier: u8 = 5;88}8990impl pallet_transaction_payment::Config for Test {91	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;92	type TransactionByteFee = TransactionByteFee;93	type WeightToFee = IdentityFee<u64>;94	type FeeMultiplierUpdate = ();95	type OperationalFeeMultiplier = OperationalFeeMultiplier;96}9798parameter_types! {99	pub const MinimumPeriod: u64 = 1;100}101impl pallet_timestamp::Config for Test {102	type Moment = u64;103	type OnTimestampSet = ();104	type MinimumPeriod = MinimumPeriod;105	type WeightInfo = ();106}107108parameter_types! {109	pub const CollectionCreationPrice: u32 = 0;110	pub TreasuryAccountId: u64 = 1234;111	pub EthereumChainId: u32 = 1111;112}113114pub struct TestEvmAddressMapping;115impl AddressMapping<u64> for TestEvmAddressMapping {116	fn into_account_id(_addr: sp_core::H160) -> u64 {117		unimplemented!()118	}119}120121pub struct TestEvmBackwardsAddressMapping;122impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {123	fn from_account_id(_account_id: u64) -> sp_core::H160 {124		unimplemented!()125	}126}127128#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]129pub struct TestCrossAccountId(u64, sp_core::H160);130impl CrossAccountId<u64> for TestCrossAccountId {131	fn as_sub(&self) -> &u64 {132		&self.0133	}134	fn as_eth(&self) -> &sp_core::H160 {135		&self.1136	}137	fn from_sub(sub: u64) -> Self {138		let mut eth = [0; 20];139		eth[12..20].copy_from_slice(&sub.to_be_bytes());140		Self(sub, sp_core::H160(eth))141	}142	fn from_eth(eth: sp_core::H160) -> Self {143		let mut sub_raw = [0; 8];144		sub_raw.copy_from_slice(&eth.0[0..8]);145		let sub = u64::from_be_bytes(sub_raw);146		Self(sub, eth)147	}148	fn conv_eq(&self, other: &Self) -> bool {149		self.as_sub() == other.as_sub()150	}151}152153impl Default for TestCrossAccountId {154	fn default() -> Self {155		Self::from_sub(0)156	}157}158159pub struct TestEtheremTransactionSender;160impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {161	fn submit_logs_transaction(162		_source: H160,163		_tx: pallet_ethereum::Transaction,164		_logs: Vec<pallet_ethereum::Log>,165	) {166	}167}168169impl pallet_evm_coder_substrate::Config for Test {170	type EthereumTransactionSender = TestEtheremTransactionSender;171	type GasWeightMapping = ();172}173174impl pallet_common::Config for Test {175	type Event = ();176	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;177	type EvmAddressMapping = TestEvmAddressMapping;178	type CrossAccountId = TestCrossAccountId;179180	type Currency = Balances;181	type CollectionCreationPrice = CollectionCreationPrice;182	type TreasuryAccountId = TreasuryAccountId;183}184185impl pallet_fungible::Config for Test {186	type WeightInfo = ();187}188impl pallet_refungible::Config for Test {189	type WeightInfo = ();190}191impl pallet_nonfungible::Config for Test {192	type WeightInfo = ();193}194195impl pallet_template::Config for Test {196	type WeightInfo = ();197}198199// Build genesis storage according to the mock runtime.200pub fn new_test_ext() -> sp_io::TestExternalities {201	system::GenesisConfig::default()202		.build_storage::<Test>()203		.unwrap()204		.into()205}
after · pallets/unique/src/mock.rs
1#![allow(clippy::from_over_into)]23use crate as pallet_template;4use sp_core::{H160, H256};5use frame_support::{parameter_types, traits::Everything, weights::IdentityFee};6use sp_runtime::{7	traits::{BlakeTwo256, IdentityLookup},8	testing::Header,9};10use pallet_transaction_payment::{CurrencyAdapter};11use frame_system as system;12use pallet_evm::AddressMapping;13use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};14use codec::{Encode, Decode};15use scale_info::TypeInfo;1617type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;18type Block = frame_system::mocking::MockBlock<Test>;1920// Configure a mock runtime to test the pallet.21frame_support::construct_runtime!(22	pub enum Test where23		Block = Block,24		NodeBlock = Block,25		UncheckedExtrinsic = UncheckedExtrinsic,26	{27		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},28		TemplateModule: pallet_template::{Pallet, Call, Storage},29		Balances: pallet_balances::{Pallet, Call, Storage},30		Common: pallet_common::{Pallet, Storage, Event<T>},31		Fungible: pallet_fungible::{Pallet, Storage},32		Refungible: pallet_refungible::{Pallet, Storage},33		Nonfungible: pallet_nonfungible::{Pallet, Storage},34	}35);3637parameter_types! {38	pub const BlockHashCount: u64 = 250;39	pub const SS58Prefix: u8 = 42;40}4142impl system::Config for Test {43	type BaseCallFilter = Everything;44	type BlockWeights = ();45	type BlockLength = ();46	type DbWeight = ();47	type Origin = Origin;48	type Call = Call;49	type Index = u64;50	type BlockNumber = u64;51	type Hash = H256;52	type Hashing = BlakeTwo256;53	type AccountId = u64;54	type Lookup = IdentityLookup<Self::AccountId>;55	type Header = Header;56	type Event = ();57	type BlockHashCount = BlockHashCount;58	type Version = ();59	type PalletInfo = PalletInfo;60	type AccountData = pallet_balances::AccountData<u64>;61	type OnNewAccount = ();62	type OnKilledAccount = ();63	type SystemWeightInfo = ();64	type SS58Prefix = SS58Prefix;65	type OnSetCode = ();66}6768parameter_types! {69	pub const ExistentialDeposit: u64 = 1;70	pub const MaxLocks: u32 = 50;71}72//frame_system::Module<Test>;73impl pallet_balances::Config for Test {74	type AccountStore = System;75	type Balance = u64;76	type DustRemoval = ();77	type Event = ();78	type ExistentialDeposit = ExistentialDeposit;79	type WeightInfo = ();80	type MaxLocks = MaxLocks;81	type MaxReserves = ();82	type ReserveIdentifier = [u8; 8];83}8485parameter_types! {86	pub const TransactionByteFee: u64 = 1;87	pub const OperationalFeeMultiplier: u8 = 5;88}8990impl pallet_transaction_payment::Config for Test {91	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;92	type TransactionByteFee = TransactionByteFee;93	type WeightToFee = IdentityFee<u64>;94	type FeeMultiplierUpdate = ();95	type OperationalFeeMultiplier = OperationalFeeMultiplier;96}9798parameter_types! {99	pub const MinimumPeriod: u64 = 1;100}101impl pallet_timestamp::Config for Test {102	type Moment = u64;103	type OnTimestampSet = ();104	type MinimumPeriod = MinimumPeriod;105	type WeightInfo = ();106}107108parameter_types! {109	pub const CollectionCreationPrice: u32 = 0;110	pub TreasuryAccountId: u64 = 1234;111	pub EthereumChainId: u32 = 1111;112}113114pub struct TestEvmAddressMapping;115impl AddressMapping<u64> for TestEvmAddressMapping {116	fn into_account_id(_addr: sp_core::H160) -> u64 {117		unimplemented!()118	}119}120121pub struct TestEvmBackwardsAddressMapping;122impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {123	fn from_account_id(_account_id: u64) -> sp_core::H160 {124		unimplemented!()125	}126}127128#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]129pub struct TestCrossAccountId(u64, sp_core::H160);130impl CrossAccountId<u64> for TestCrossAccountId {131	fn as_sub(&self) -> &u64 {132		&self.0133	}134	fn as_eth(&self) -> &sp_core::H160 {135		&self.1136	}137	fn from_sub(sub: u64) -> Self {138		let mut eth = [0; 20];139		eth[12..20].copy_from_slice(&sub.to_be_bytes());140		Self(sub, sp_core::H160(eth))141	}142	fn from_eth(eth: sp_core::H160) -> Self {143		let mut sub_raw = [0; 8];144		sub_raw.copy_from_slice(&eth.0[0..8]);145		let sub = u64::from_be_bytes(sub_raw);146		Self(sub, eth)147	}148	fn conv_eq(&self, other: &Self) -> bool {149		self.as_sub() == other.as_sub()150	}151}152153impl Default for TestCrossAccountId {154	fn default() -> Self {155		Self::from_sub(0)156	}157}158159pub struct TestEtheremTransactionSender;160impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {161	fn submit_logs_transaction(162		_source: H160,163		_tx: pallet_ethereum::Transaction,164		_logs: Vec<pallet_ethereum::Log>,165	) {166	}167}168169impl pallet_evm_coder_substrate::Config for Test {170	type EthereumTransactionSender = TestEtheremTransactionSender;171	type GasWeightMapping = ();172}173174impl pallet_common::Config for Test {175	type Event = ();176	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;177	type EvmAddressMapping = TestEvmAddressMapping;178	type CrossAccountId = TestCrossAccountId;179180	type Currency = Balances;181	type CollectionCreationPrice = CollectionCreationPrice;182	type TreasuryAccountId = TreasuryAccountId;183}184185impl pallet_fungible::Config for Test {186	type WeightInfo = ();187}188impl pallet_refungible::Config for Test {189	type WeightInfo = ();190}191impl pallet_nonfungible::Config for Test {192	type WeightInfo = ();193}194195impl pallet_template::Config for Test {196	type Event = ();197	type WeightInfo = ();198}199200// Build genesis storage according to the mock runtime.201pub fn new_test_ext() -> sp_io::TestExternalities {202	system::GenesisConfig::default()203		.build_storage::<Test>()204		.unwrap()205		.into()206}
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
--- 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);