Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Aug 7, 2023
1 parent e8953df commit 387c630
Show file tree
Hide file tree
Showing 34 changed files with 199 additions and 256 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ check-tests: githooks
SKIP_WASM_BUILD= cargo check --features with-all-runtime --tests --all

.PHONY: check-all
check-all: check-runtimes check-benchmarks check-integration-tests
check-all: check-runtimes check-benchmarks check-tests check-integration-tests

.PHONY: check-runtimes
check-runtimes:
Expand Down
2 changes: 1 addition & 1 deletion evm-tests
18 changes: 6 additions & 12 deletions modules/aggregated-dex/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,10 @@ use frame_system::EnsureSignedBy;
use orml_tokens::ConvertBalance;
pub use orml_traits::{parameter_type_with_key, MultiCurrency};
use primitives::{Amount, TokenSymbol, TradingPair};
use sp_runtime::{
testing::{Header, H256},
traits::IdentityLookup,
AccountId32, ArithmeticError, FixedPointNumber,
};
use sp_runtime::{testing::H256, traits::IdentityLookup, AccountId32, ArithmeticError, BuildStorage, FixedPointNumber};
pub use support::{ExchangeRate, RebasedStableAsset};

pub type AccountId = AccountId32;
pub type BlockNumber = u64;

mod aggregated_dex {
pub use super::super::*;
Expand Down Expand Up @@ -205,16 +200,15 @@ impl Config for Runtime {
pub type StableAssetWrapper =
RebasedStableAsset<StableAsset, ConvertBalanceHoma, RebasedStableAssetErrorConvertor<Runtime>>;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;

frame_support::construct_runtime!(
pub enum Runtime {
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
AggregatedDex: aggregated_dex::{Pallet, Call, Storage},
Dex: module_dex::{Pallet, Call, Storage, Config<T>, Event<T>},
Tokens: orml_tokens::{Pallet, Storage, Event<T>, Config<T>},
StableAsset: nutsfinance_stable_asset::{Pallet, Call, Storage, Event<T>},
System: frame_system,
AggregatedDex: aggregated_dex,
Dex: module_dex,
Tokens: orml_tokens,
StableAsset: nutsfinance_stable_asset,
}
);

Expand Down
18 changes: 8 additions & 10 deletions modules/asset-registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

use crate as asset_registry;
use frame_support::{
assert_ok, construct_runtime, ord_parameter_types,
pallet_prelude::GenesisBuild,
parameter_types,
assert_ok, construct_runtime, ord_parameter_types, parameter_types,
traits::{ConstU128, ConstU32, ConstU64, Everything},
};
use frame_system::EnsureSignedBy;
Expand All @@ -33,6 +31,7 @@ use primitives::{
evm::convert_decimals_to_evm, evm::EvmAddress, AccountId, Balance, CurrencyId, ReserveIdentifier, TokenSymbol,
};
use sp_core::{H160, H256, U256};
use sp_runtime::BuildStorage;
use std::str::FromStr;

impl frame_system::Config for Runtime {
Expand All @@ -44,7 +43,7 @@ impl frame_system::Config for Runtime {
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = sp_runtime::testing::Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type BlockWeights = ();
Expand Down Expand Up @@ -138,16 +137,15 @@ impl asset_registry::Config for Runtime {
type WeightInfo = ();
}

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;

construct_runtime!(
pub enum Runtime {
System: frame_system::{Pallet, Call, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
AssetRegistry: asset_registry::{Pallet, Call, Event<T>, Storage},
EVM: module_evm::{Pallet, Config<T>, Call, Storage, Event<T>},
EVMBridge: module_evm_bridge::{Pallet},
System: frame_system,
Balances: pallet_balances,
AssetRegistry: asset_registry,
EVM: module_evm,
EVMBridge: module_evm_bridge,
}
);

Expand Down
13 changes: 7 additions & 6 deletions modules/auction-manager/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use sp_core::H256;
use sp_runtime::{
testing::{Header, TestXt},
traits::{AccountIdConversion, IdentityLookup, One as OneT},
BuildStorage,
};
use sp_std::cell::RefCell;
pub use support::Price;
Expand Down Expand Up @@ -220,12 +221,12 @@ pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<u32, Runti

construct_runtime!(
pub enum Runtime {
System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
AuctionManagerModule: auction_manager::{Pallet, Storage, Call, Event<T>, ValidateUnsigned},
Tokens: orml_tokens::{Pallet, Storage, Event<T>, Config<T>},
AuctionModule: orml_auction::{Pallet, Storage, Call, Event<T>},
CDPTreasuryModule: cdp_treasury::{Pallet, Storage, Call, Event<T>},
DEXModule: module_dex::{Pallet, Storage, Call, Event<T>, Config<T>},
System: frame_system,
AuctionManagerModule: auction_manager,
Tokens: orml_tokens,
AuctionModule: orml_auction,
CDPTreasuryModule: cdp_treasury,
DEXModule: module_dex,
}
);

Expand Down
24 changes: 12 additions & 12 deletions modules/cdp-engine/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ use orml_traits::parameter_type_with_key;
use primitives::{DexShare, Moment, TokenSymbol, TradingPair};
use sp_core::{crypto::AccountId32, H256};
use sp_runtime::{
testing::{Header, TestXt},
testing::TestXt,
traits::{AccountIdConversion, IdentityLookup, One as OneT},
BuildStorage,
};
use sp_std::{cell::RefCell, str::FromStr};
use support::mocks::MockStableAsset;
Expand Down Expand Up @@ -407,21 +408,20 @@ impl Config for Runtime {
type WeightInfo = ();
}

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;

construct_runtime!(
pub enum Runtime {
System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
CDPEngineModule: cdp_engine::{Pallet, Storage, Call, Event<T>, Config, ValidateUnsigned},
CDPTreasuryModule: cdp_treasury::{Pallet, Storage, Call, Config, Event<T>},
Currencies: orml_currencies::{Pallet, Call},
Tokens: orml_tokens::{Pallet, Storage, Event<T>, Config<T>},
LoansModule: loans::{Pallet, Storage, Call, Event<T>},
PalletBalances: pallet_balances::{Pallet, Call, Storage, Event<T>},
DEXModule: dex::{Pallet, Storage, Call, Event<T>, Config<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
EvmAccounts: evm_accounts::{Pallet, Call, Storage, Event<T>},
System: frame_system,
CDPEngineModule: cdp_engine,
CDPTreasuryModule: cdp_treasury,
Currencies: orml_currencies,
Tokens: orml_tokens,
LoansModule: loans,
PalletBalances: pallet_balances,
DEXModule: dex,
Timestamp: pallet_timestamp,
EvmAccounts: evm_accounts,
}
);

Expand Down
42 changes: 17 additions & 25 deletions modules/cdp-treasury/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use nutsfinance_stable_asset::{
use orml_traits::parameter_type_with_key;
use primitives::{DexShare, TokenSymbol, TradingPair};
use sp_core::H256;
use sp_runtime::{testing::Header, traits::IdentityLookup};
use sp_runtime::{traits::IdentityLookup, BuildStorage};
use sp_std::cell::RefCell;
use support::SpecificJointsSwap;

Expand Down Expand Up @@ -222,17 +222,16 @@ impl Config for Runtime {
type StableAsset = MockStableAsset;
}

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;

construct_runtime!(
pub enum Runtime {
System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
CDPTreasuryModule: cdp_treasury::{Pallet, Storage, Call, Config, Event<T>},
Currencies: orml_currencies::{Pallet, Call},
Tokens: orml_tokens::{Pallet, Storage, Event<T>, Config<T>},
PalletBalances: pallet_balances::{Pallet, Call, Storage, Event<T>},
DEXModule: module_dex::{Pallet, Storage, Call, Event<T>, Config<T>},
System: frame_system,
CDPTreasuryModule: cdp_treasury,
Currencies: orml_currencies,
Tokens: orml_tokens,
PalletBalances: pallet_balances,
DEXModule: module_dex,
}
);

Expand Down Expand Up @@ -298,8 +297,7 @@ impl StableAsset for MockStableAsset {

fn pool(
_id: StableAssetPoolId,
) -> Option<StableAssetPoolInfo<Self::AssetId, Self::Balance, Self::Balance, Self::AccountId, BlockNumberFor<Self>>>
{
) -> Option<StableAssetPoolInfo<Self::AssetId, Self::Balance, Self::Balance, Self::AccountId, Self::BlockNumber>> {
Some(StableAssetPoolInfo {
pool_asset: CurrencyId::StableAssetPoolToken(0),
assets: vec![CurrencyId::ForeignAsset(255), CurrencyId::Token(TokenSymbol::DOT)],
Expand Down Expand Up @@ -392,7 +390,7 @@ impl StableAsset for MockStableAsset {
Self::Balance,
Self::Balance,
Self::AccountId,
BlockNumberFor<Self>,
Self::BlockNumber,
>,
) -> DispatchResult {
unimplemented!()
Expand All @@ -405,7 +403,7 @@ impl StableAsset for MockStableAsset {
Self::Balance,
Self::Balance,
Self::AccountId,
BlockNumberFor<Self>,
Self::BlockNumber,
>,
) -> DispatchResult {
unimplemented!()
Expand All @@ -418,17 +416,13 @@ impl StableAsset for MockStableAsset {
Self::Balance,
Self::Balance,
Self::AccountId,
BlockNumberFor<Self>,
Self::BlockNumber,
>,
) -> DispatchResult {
unimplemented!()
}

fn modify_a(
_pool_id: StableAssetPoolId,
_a: Self::Balance,
_future_a_block: BlockNumberFor<Self>,
) -> DispatchResult {
fn modify_a(_pool_id: StableAssetPoolId, _a: Self::Balance, _future_a_block: Self::BlockNumber) -> DispatchResult {
unimplemented!()
}

Expand All @@ -438,10 +432,9 @@ impl StableAsset for MockStableAsset {
Self::Balance,
Self::Balance,
Self::AccountId,
BlockNumberFor<Self>,
Self::BlockNumber,
>,
) -> Option<StableAssetPoolInfo<Self::AssetId, Self::Balance, Self::Balance, Self::AccountId, BlockNumberFor<Self>>>
{
) -> Option<StableAssetPoolInfo<Self::AssetId, Self::Balance, Self::Balance, Self::AccountId, Self::BlockNumber>> {
Some(StableAssetPoolInfo {
pool_asset: CurrencyId::StableAssetPoolToken(0),
assets: vec![CurrencyId::ForeignAsset(255), CurrencyId::Token(TokenSymbol::DOT)],
Expand All @@ -468,10 +461,9 @@ impl StableAsset for MockStableAsset {
Self::Balance,
Self::Balance,
Self::AccountId,
BlockNumberFor<Self>,
Self::BlockNumber,
>,
) -> Option<StableAssetPoolInfo<Self::AssetId, Self::Balance, Self::Balance, Self::AccountId, BlockNumberFor<Self>>>
{
) -> Option<StableAssetPoolInfo<Self::AssetId, Self::Balance, Self::Balance, Self::AccountId, Self::BlockNumber>> {
Some(StableAssetPoolInfo {
pool_asset: CurrencyId::StableAssetPoolToken(0),
assets: vec![CurrencyId::ForeignAsset(255), CurrencyId::Token(TokenSymbol::DOT)],
Expand All @@ -498,7 +490,7 @@ impl StableAsset for MockStableAsset {
Self::Balance,
Self::Balance,
Self::AccountId,
BlockNumberFor<Self>,
Self::BlockNumber,
>,
_amount_bal: Self::Balance,
) -> Option<RedeemProportionResult<Self::Balance>> {
Expand Down
25 changes: 11 additions & 14 deletions modules/collator-selection/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,30 @@ use super::*;
use crate as collator_selection;
use frame_support::{
ord_parameter_types, parameter_types,
traits::{ConstU16, ConstU32, ConstU64, Everything, FindAuthor, GenesisBuild},
traits::{ConstU16, ConstU32, ConstU64, Everything, FindAuthor},
PalletId,
};
use frame_system::EnsureSignedBy;
use primitives::ReserveIdentifier;
use sp_core::H256;
use sp_runtime::{
testing::{Header, UintAuthorityId},
testing::UintAuthorityId,
traits::{BlakeTwo256, ConstBool, IdentityLookup, OpaqueKeys},
Permill, RuntimeAppPublic,
BuildStorage, Permill, RuntimeAppPublic,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test {
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
Aura: pallet_aura::{Pallet, Storage, Config<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
CollatorSelection: collator_selection::{Pallet, Call, Storage, Event<T>},
Authorship: pallet_authorship::{Pallet, Storage},
System: frame_system,
Timestamp: pallet_timestamp,
Session: pallet_session,
Aura: pallet_aura,
Balances: pallet_balances,
CollatorSelection: collator_selection,
Authorship: pallet_authorship,
}
);

Expand Down Expand Up @@ -191,9 +190,7 @@ impl Config for Test {

pub fn new_test_ext() -> sp_io::TestExternalities {
sp_tracing::try_init_simple();
let mut t = frame_system::GenesisConfig::<Runtime>::default()
.build_storage::<Test>()
.unwrap();
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let invulnerables = vec![1, 2];
let keys = invulnerables
.iter()
Expand Down
8 changes: 3 additions & 5 deletions modules/collator-selection/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ use crate::{mock::*, Error, NonCandidates, RESERVE_ID};
use frame_support::{
assert_noop, assert_ok,
storage::bounded_btree_set::BoundedBTreeSet,
traits::{ConstU32, Currency, GenesisBuild, NamedReservableCurrency, OnInitialize},
traits::{ConstU32, Currency, NamedReservableCurrency, OnInitialize},
};
use pallet_balances::Error as BalancesError;
use sp_runtime::{testing::UintAuthorityId, traits::BadOrigin};
use sp_runtime::{testing::UintAuthorityId, traits::BadOrigin, BuildStorage};

type Collators = BoundedBTreeSet<u64, ConstU32<4>>;

Expand Down Expand Up @@ -574,9 +574,7 @@ fn exceeding_max_invulnerables_should_fail() {
#[should_panic = "duplicate invulnerables in genesis."]
fn cannot_set_genesis_value_twice() {
sp_tracing::try_init_simple();
let mut t = frame_system::GenesisConfig::<Runtime>::default()
.build_storage::<Test>()
.unwrap();
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let invulnerables = vec![1, 1];

let collator_selection = collator_selection::GenesisConfig::<Test> {
Expand Down
11 changes: 4 additions & 7 deletions modules/dex-oracle/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ use frame_system::EnsureSignedBy;
use primitives::{DexShare, Moment, TokenSymbol};
use sp_core::{H160, H256};
use sp_runtime::{
testing::Header,
traits::{IdentityLookup, Zero},
DispatchError,
BuildStorage, DispatchError,
};
use sp_std::cell::RefCell;
use support::SwapLimit;

pub type AccountId = u128;
pub type BlockNumber = u64;

pub const ACA: CurrencyId = CurrencyId::Token(TokenSymbol::ACA);
pub const AUSD: CurrencyId = CurrencyId::Token(TokenSymbol::AUSD);
Expand Down Expand Up @@ -177,14 +175,13 @@ impl Config for Runtime {
type WeightInfo = ();
}

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;

construct_runtime!(
pub enum Runtime {
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
DexOracle: dex_oracle::{Pallet, Call, Storage},
System: frame_system,
Timestamp: pallet_timestamp,
DexOracle: dex_oracle,
}
);

Expand Down
Loading

0 comments on commit 387c630

Please sign in to comment.