Skip to content

Commit

Permalink
feat: fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshvarma committed Feb 7, 2024
1 parent 709390f commit 0452862
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 67 deletions.
8 changes: 4 additions & 4 deletions tests/integration/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
pub use frame_support::{
assert_noop, assert_ok,
traits::{GenesisBuild, OnFinalize, OnIdle, OnInitialize},
traits::{OnFinalize, OnIdle, OnInitialize},
weights::Weight,
};
pub use pallet_evm::AddressMapping;
Expand Down Expand Up @@ -181,8 +181,8 @@ impl ExtBuilder {
}

pub fn build(self) -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
let mut t = frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.unwrap();

pallet_balances::GenesisConfig::<Runtime> {
Expand All @@ -193,7 +193,7 @@ impl ExtBuilder {

#[cfg(any(feature = "shibuya"))]
// Needed to trigger initial inflation config setting.
<pallet_inflation::GenesisConfig as GenesisBuild<Runtime>>::assimilate_storage(
<pallet_inflation::GenesisConfig<Runtime> as BuildStorage>::assimilate_storage(
&pallet_inflation::GenesisConfig::default(),
&mut t,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/src/xvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ fn wasm_call_via_xvm_fails_if_storage_deposit_limit_exhausted() {
reason: FailureReason::Error(FailureError::VmError(data)),
..
}) => {
let error_string = "WASM call error: Module(ModuleError { index: 70, error: [22, 0, 0, 0], message: Some(\"StorageDepositLimitExhausted\") })";
let error_string = "WASM call error: Module(ModuleError { index: 70, error: [23, 0, 0, 0], message: Some(\"StorageDepositLimitExhausted\") })";
assert_eq!(data, error_string.as_bytes());
},
_ => panic!("unexpected wasm call result"),
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
// You should have received a copy of the GNU General Public License
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

use frame_support::{traits::Currency, weights::Weight};
use frame_support::{traits::fungible::Inspect, weights::Weight};
use pallet_contracts_primitives::{Code, ReturnFlags};
use parity_scale_codec::Decode;
use sp_runtime::traits::Hash;

type ContractBalanceOf<T> = <<T as pallet_contracts::Config>::Currency as Currency<
type ContractBalanceOf<T> = <<T as pallet_contracts::Config>::Currency as Inspect<
<T as frame_system::Config>::AccountId,
>>::Balance;

Expand Down
21 changes: 11 additions & 10 deletions tests/xcm-simulator/src/mocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ pub(crate) mod relay_chain;

use frame_support::traits::{Currency, IsType, OnFinalize, OnInitialize};
use sp_runtime::traits::{Bounded, StaticLookup};
use sp_runtime::DispatchResult;
use sp_runtime::{BuildStorage, DispatchResult};
use xcm::latest::prelude::*;
use xcm_executor::traits::Convert;
use xcm_executor::traits::ConvertLocation;
use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt};

pub const ALICE: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0xFAu8; 32]);
pub const BOB: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0xFBu8; 32]);
pub const INITIAL_BALANCE: u128 = 1_000_000_000_000_000_000_000_000;
pub const ONE: u128 = 1_000_000_000_000_000_000;
pub const DAPP_STAKER_REWARD_PER_BLOCK: parachain::Balance = 1_000;
pub const DAPP_STAKER_DEV_PER_BLOCK: parachain::Balance = 250;

Expand Down Expand Up @@ -82,19 +83,19 @@ pub type ParachainXtokens = orml_xtokens::Pallet<parachain::Runtime>;

pub fn parent_account_id() -> parachain::AccountId {
let location = (Parent,);
parachain::LocationToAccountId::convert(location.into()).unwrap()
parachain::LocationToAccountId::convert_location(&location.into()).unwrap()
}

/// Derive parachain sovereign account on relay chain, from parachain Id
pub fn child_para_account_id(para: u32) -> relay_chain::AccountId {
let location = (Parachain(para),);
relay_chain::LocationToAccountId::convert(location.into()).unwrap()
relay_chain::LocationToAccountId::convert_location(&location.into()).unwrap()
}

/// Derive parachain sovereign account on a sibling parachain, from parachain Id
pub fn sibling_para_account_id(para: u32) -> parachain::AccountId {
let location = (Parent, X1(Parachain(para)));
parachain::LocationToAccountId::convert(location.into()).unwrap()
parachain::LocationToAccountId::convert_location(&location.into()).unwrap()
}

/// Derive parachain's account's account on a sibling parachain
Expand All @@ -111,15 +112,15 @@ pub fn sibling_para_account_account_id(
id: who.into(),
},
);
parachain::LocationToAccountId::convert(location.into()).unwrap()
parachain::LocationToAccountId::convert_location(&location.into()).unwrap()
}

/// Prepare parachain test externality
pub fn para_ext(para_id: u32) -> sp_io::TestExternalities {
use parachain::{MsgQueue, Runtime, System};

let mut t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
let mut t = frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.unwrap();

pallet_balances::GenesisConfig::<Runtime> {
Expand Down Expand Up @@ -150,8 +151,8 @@ pub fn para_ext(para_id: u32) -> sp_io::TestExternalities {
pub fn relay_ext() -> sp_io::TestExternalities {
use relay_chain::{Runtime, System};

let mut t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
let mut t = frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.unwrap();

pallet_balances::GenesisConfig::<Runtime> {
Expand Down
65 changes: 32 additions & 33 deletions tests/xcm-simulator/src/mocks/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ use frame_system::{
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{AccountIdConversion, Convert, Get, IdentityLookup},
traits::{AccountIdConversion, Convert, Get, IdentityLookup, MaybeEquivalence},
AccountId32, Perbill, RuntimeDebug,
};
use sp_std::marker::PhantomData;
Expand All @@ -60,10 +59,7 @@ use xcm_builder::{
use orml_traits::location::{RelativeReserveProvider, Reserve};
use orml_xcm_support::DisabledParachainFee;

use xcm_executor::{
traits::{Convert as XcmConvert, JustTry},
XcmExecutor,
};
use xcm_executor::{traits::JustTry, XcmExecutor};

use astar_primitives::xcm::{
AssetLocationIdConverter, FixedRateOfForeignAsset, ReserveAssetFilter, XcmFungibleFeeHandler,
Expand All @@ -84,13 +80,12 @@ parameter_types! {
impl frame_system::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Nonce = u64;
type Block = Block;
type Hash = H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type BlockWeights = ();
Expand Down Expand Up @@ -124,9 +119,9 @@ impl pallet_balances::Config for Runtime {
type WeightInfo = ();
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ConstU32<0>;
type RuntimeHoldReason = RuntimeHoldReason;
type FreezeIdentifier = RuntimeFreezeReason;
type MaxHolds = ConstU32<1>;
type MaxFreezes = ConstU32<0>;
}

Expand Down Expand Up @@ -213,6 +208,8 @@ parameter_types! {
pub const DepositPerItem: Balance = MILLISDN / 1_000_000;
pub const DepositPerByte: Balance = MILLISDN / 1_000_000;
pub const DefaultDepositLimit: Balance = 1000 * MILLISDN;
pub const MaxDelegateDependencies: u32 = 32;
pub const CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(30);
pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();
}

Expand Down Expand Up @@ -240,6 +237,7 @@ impl pallet_contracts::Config for Runtime {
type Currency = Balances;
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type RuntimeHoldReason = RuntimeHoldReason;
/// The safest default is to allow no calls at all.
///
/// Runtimes should whitelist dispatchables that are allowed to be called from contracts
Expand All @@ -261,6 +259,11 @@ impl pallet_contracts::Config for Runtime {
type MaxStorageKeyLen = ConstU32<128>;
type UnsafeUnstableInterface = ConstBool<true>;
type MaxDebugBufferLen = ConstU32<{ 2 * 1024 * 1024 }>;
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
type MaxDelegateDependencies = MaxDelegateDependencies;
type Migrations = ();
type Debug = ();
type Environment = ();
}

pub struct BurnFees;
Expand Down Expand Up @@ -553,6 +556,7 @@ impl xcm_executor::Config for XcmConfig {
type UniversalAliases = Nothing;
type CallDispatcher = RuntimeCall;
type SafeCallFilter = Everything;
type Aliasers = Nothing;
}

impl mock_msg_queue::Config for Runtime {
Expand Down Expand Up @@ -626,7 +630,7 @@ parameter_types! {
pub struct AssetIdConvert;
impl Convert<AssetId, Option<MultiLocation>> for AssetIdConvert {
fn convert(asset_id: AssetId) -> Option<MultiLocation> {
ShidenAssetLocationIdConverter::reverse_ref(&asset_id).ok()
ShidenAssetLocationIdConverter::convert_back(&asset_id)
}
}

Expand Down Expand Up @@ -665,28 +669,23 @@ impl orml_xtokens::Config for Runtime {
type ReserveProvider = AbsoluteAndRelativeReserveProvider<ShidenLocationAbsolute>;
}

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

construct_runtime!(
pub struct Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
MsgQueue: mock_msg_queue::{Pallet, Storage, Event<T>},
PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin},
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>},
XcAssetConfig: pallet_xc_asset_config::{Pallet, Call, Storage, Event<T>},
CumulusXcm: cumulus_pallet_xcm::{Pallet, Event<T>, Origin},
DappsStaking: pallet_dapps_staking::{Pallet, Call, Event<T>},
Proxy: pallet_proxy::{Pallet, Call, Event<T>},
Utility: pallet_utility::{Pallet, Call, Event},
Randomness: pallet_insecure_randomness_collective_flip::{Pallet, Storage},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
Contracts: pallet_contracts::{Pallet, Call, Storage, Event<T>},
Xtokens: orml_xtokens::{Pallet, Storage, Call, Event<T>},
pub struct Runtime {
System: frame_system,
Balances: pallet_balances,
MsgQueue: mock_msg_queue,
PolkadotXcm: pallet_xcm,
Assets: pallet_assets,
XcAssetConfig: pallet_xc_asset_config,
CumulusXcm: cumulus_pallet_xcm,
DappsStaking: pallet_dapps_staking,
Proxy: pallet_proxy,
Utility: pallet_utility,
Randomness: pallet_insecure_randomness_collective_flip,
Timestamp: pallet_timestamp,
Contracts: pallet_contracts,
Xtokens: orml_xtokens,
}
);
28 changes: 12 additions & 16 deletions tests/xcm-simulator/src/mocks/relay_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use frame_support::{
};
use frame_system::EnsureRoot;
use sp_core::H256;
use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32};
use sp_runtime::{traits::IdentityLookup, AccountId32};

use polkadot_parachain::primitives::Id as ParaId;
use polkadot_runtime_parachains::{
Expand All @@ -50,13 +50,12 @@ parameter_types! {
impl frame_system::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Nonce = u64;
type Block = Block;
type Hash = H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type BlockWeights = ();
Expand Down Expand Up @@ -90,7 +89,7 @@ impl pallet_balances::Config for Runtime {
type WeightInfo = ();
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
type HoldIdentifier = ();
type RuntimeHoldReason = RuntimeHoldReason;
type FreezeIdentifier = ();
type MaxHolds = ConstU32<0>;
type MaxFreezes = ConstU32<0>;
Expand Down Expand Up @@ -158,6 +157,7 @@ impl xcm_executor::Config for XcmConfig {
type UniversalAliases = Nothing;
type CallDispatcher = RuntimeCall;
type SafeCallFilter = Everything;
type Aliasers = Nothing;
}

pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, KusamaNetwork>;
Expand Down Expand Up @@ -205,7 +205,6 @@ parameter_types! {

impl origin::Config for Runtime {}

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

parameter_types! {
Expand Down Expand Up @@ -246,18 +245,15 @@ impl pallet_message_queue::Config for Runtime {
type MessageProcessor = MessageProcessor;
type QueueChangeHandler = ();
type WeightInfo = ();
type QueuePausedQuery = ();
}

construct_runtime!(
pub struct Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
ParasOrigin: origin::{Pallet, Origin},
XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin},
MessageQueue: pallet_message_queue::{Pallet, Event<T>},
pub struct Runtime {
System: frame_system,
Balances: pallet_balances,
ParasOrigin: origin,
XcmPallet: pallet_xcm,
MessageQueue: pallet_message_queue,
}
);
3 changes: 2 additions & 1 deletion tests/xcm-simulator/src/tests/experimental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use frame_support::{assert_ok, weights::Weight};
use parity_scale_codec::Encode;
use sp_runtime::traits::Bounded;
use xcm::{prelude::*, v3::Response};
use xcm_executor::traits::QueryHandler;
use xcm_simulator::TestExt;

const GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000, 3 * 1024 * 1024);
Expand Down Expand Up @@ -279,7 +280,7 @@ fn test_async_xcm_contract_call_no_ce() {
ALICE.into(),
0,
GAS_LIMIT,
None,
Some(ONE * 100),
[CONSTRUCTOR_SELECTOR.to_vec(), 1.encode()].concat(),
);

Expand Down

0 comments on commit 0452862

Please sign in to comment.