diff --git a/asset-registry/Cargo.toml b/asset-registry/Cargo.toml index 4970ad8d3..11c3c9128 100644 --- a/asset-registry/Cargo.toml +++ b/asset-registry/Cargo.toml @@ -13,10 +13,10 @@ serde = { version = "1.0.136", optional = true } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] } # substrate -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } # polkadot pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.31" } @@ -29,9 +29,9 @@ orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = fa [dev-dependencies] # substrate -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } # cumulus cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.31" } @@ -47,30 +47,37 @@ xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "rele # orml orml-tokens = { path = "../tokens" } -orml-xtokens = { path = "../xtokens" } orml-xcm = { path = "../xcm" } orml-xcm-support = { path = "../xcm-support", default-features = false } +orml-xtokens = { path = "../xtokens" } [features] default = ["std"] std = [ "serde", + "codec/std", - "scale-info/std", - "sp-runtime/std", - "sp-std/std", "frame-support/std", "frame-system/std", "orml-traits/std", "pallet-xcm/std", - "xcm/std", + "scale-info/std", + "sp-runtime/std", + "sp-std/std", "xcm-builder/std", "xcm-executor/std", + "xcm/std", ] runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", + "pallet-xcm/try-runtime", ] -try-runtime = ["frame-support/try-runtime"] diff --git a/asset-registry/src/tests.rs b/asset-registry/src/tests.rs index 0ef593428..f204c8c31 100644 --- a/asset-registry/src/tests.rs +++ b/asset-registry/src/tests.rs @@ -118,7 +118,7 @@ fn send_self_parachain_asset_to_sibling() { ) .into() ), - 40, + WeightLimit::Unlimited, )); assert_eq!(ParaTokens::free_balance(CurrencyId::RegisteredAsset(1), &ALICE), 500); @@ -204,7 +204,7 @@ fn send_sibling_asset_to_non_reserve_sibling() { ) .into() ), - 40 + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::RegisteredAsset(1), &ALICE), 500); }); @@ -302,7 +302,7 @@ fn test_fixed_rate_asset_trader() { ) .into() ), - 40, + WeightLimit::Unlimited, )); }); @@ -353,7 +353,7 @@ fn test_fixed_rate_asset_trader() { ) .into() ), - 40, + WeightLimit::Unlimited, )); }); diff --git a/auction/Cargo.toml b/auction/Cargo.toml index 004c5c905..404d0f5e1 100644 --- a/auction/Cargo.toml +++ b/auction/Cargo.toml @@ -8,14 +8,14 @@ authors = ["Acala Developers"] edition = "2021" [dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } @@ -27,12 +27,16 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0 default = ["std"] std = [ "serde", + "codec/std", - "scale-info/std", - "sp-runtime/std", - "sp-std/std", "frame-support/std", "frame-system/std", "orml-traits/std", + "scale-info/std", + "sp-runtime/std", + "sp-std/std", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", +] \ No newline at end of file diff --git a/authority/Cargo.toml b/authority/Cargo.toml index e0468a06b..0f831f2b1 100644 --- a/authority/Cargo.toml +++ b/authority/Cargo.toml @@ -8,36 +8,42 @@ authors = ["Acala Developers"] edition = "2021" [dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.145", optional = true } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } -pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } +pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } [features] default = ["std"] std = [ "serde", + "codec/std", + "frame-support/std", + "frame-system/std", "scale-info/std", + "sp-core/std", + "sp-io/std", "sp-runtime/std", "sp-std/std", - "sp-io/std", - "frame-support/std", - "frame-system/std", ] runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", ] -try-runtime = ["frame-support/try-runtime"] diff --git a/authority/src/lib.rs b/authority/src/lib.rs index cc49a9074..93a30dac6 100644 --- a/authority/src/lib.rs +++ b/authority/src/lib.rs @@ -11,6 +11,13 @@ //! Two functionalities are provided by this module: //! - schedule a dispatchable //! - dispatch method with on behalf of other origins +//! +//! NOTE: +//! +//! In order to derive a feasible max encoded len for `DelayedOrigin`, it is +//! assumed that there are no nested `DelayedOrigin` in `OriginCaller`. +//! In practice, this means there should not be nested `schedule_dispatch`. +//! Otherwise the proof size estimation may not be accurate. #![cfg_attr(not(feature = "std"), no_std)] // Disable the following three lints since they originate from an external macro @@ -32,6 +39,7 @@ use frame_support::{ }; use frame_system::{pallet_prelude::*, EnsureRoot, EnsureSigned}; use scale_info::TypeInfo; +use sp_core::defer; use sp_runtime::{ traits::{CheckedSub, Dispatchable, Hash, Saturating}, ArithmeticError, DispatchError, DispatchResult, Either, RuntimeDebug, @@ -45,12 +53,64 @@ mod weights; pub use weights::WeightInfo; /// A delayed origin. Can only be dispatched via `dispatch_as` with a delay. -#[derive(PartialEq, Eq, Clone, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)] +#[derive(PartialEq, Eq, Clone, RuntimeDebug, Encode, Decode, TypeInfo)] pub struct DelayedOrigin { /// Number of blocks that this call have been delayed. - pub delay: BlockNumber, + pub(crate) delay: BlockNumber, /// The initial origin. - pub origin: Box, + pub(crate) origin: Box, +} + +#[cfg(feature = "std")] +mod helper { + use std::cell::RefCell; + + thread_local! { + static NESTED_MAX_ENCODED_LEN: RefCell = RefCell::new(false); + } + + pub fn set_nested_max_encoded_len(val: bool) { + NESTED_MAX_ENCODED_LEN.with(|v| *v.borrow_mut() = val); + } + + pub fn nested_max_encoded_len() -> bool { + NESTED_MAX_ENCODED_LEN.with(|v| *v.borrow()) + } +} + +#[cfg(not(feature = "std"))] +mod helper { + static mut NESTED_MAX_ENCODED_LEN: bool = false; + + pub fn set_nested_max_encoded_len(val: bool) { + unsafe { + NESTED_MAX_ENCODED_LEN = val; + } + } + + pub fn nested_max_encoded_len() -> bool { + unsafe { NESTED_MAX_ENCODED_LEN } + } +} + +// Manual implementation to break recursive calls of `MaxEncodedLen` as the +// implementation of `PalletsOrigin::max_encoded_len` will also call +// `MaxEncodedLen` on `DelayedOrigin`. This is only safe if there are no nested +// `DelayedOrigin`. It is only possible to construct a `DelayedOrigin` via +// `schedule_dispatch` which is a protected call only accessible via governance. +impl MaxEncodedLen + for DelayedOrigin +{ + fn max_encoded_len() -> usize { + if helper::nested_max_encoded_len() { + return 0; + } + + helper::set_nested_max_encoded_len(true); + defer!(helper::set_nested_max_encoded_len(false)); + + BlockNumber::max_encoded_len() + PalletsOrigin::max_encoded_len() + } } /// Ensure the origin have a minimum amount of delay. @@ -99,10 +159,10 @@ pub trait AuthorityConfig { new_delay: BlockNumber, ) -> DispatchResult; /// Check if the `origin` is allow to delay a scheduled task that - /// initially created by `inital_origin`. + /// initially created by `initial_origin`. fn check_delay_schedule(origin: Origin, initial_origin: &PalletsOrigin) -> DispatchResult; /// Check if the `origin` is allow to cancel a scheduled task that - /// initially created by `inital_origin`. + /// initially created by `initial_origin`. fn check_cancel_schedule(origin: Origin, initial_origin: &PalletsOrigin) -> DispatchResult; } @@ -396,12 +456,12 @@ pub mod module { #[pallet::weight(T::WeightInfo::remove_authorized_call())] pub fn remove_authorized_call(origin: OriginFor, hash: T::Hash) -> DispatchResult { - let root_or_sigend = + let root_or_signed = EitherOfDiverse::, EnsureSigned>::ensure_origin(origin)?; SavedCalls::::try_mutate_exists(hash, |maybe_call| { let (_, maybe_caller) = maybe_call.take().ok_or(Error::::CallNotAuthorized)?; - match root_or_sigend { + match root_or_signed { Either::Left(_) => {} // root, do nothing Either::Right(who) => { // signed, ensure it's the caller diff --git a/authority/src/tests.rs b/authority/src/tests.rs index f44c2a840..c4bd784d6 100644 --- a/authority/src/tests.rs +++ b/authority/src/tests.rs @@ -3,6 +3,7 @@ #![cfg(test)] use super::*; +use codec::MaxEncodedLen; use frame_support::{ assert_noop, assert_ok, dispatch::DispatchErrorWithPostInfo, @@ -691,3 +692,9 @@ fn trigger_old_call_should_be_free_and_operational() { ); }); } + +#[test] +fn origin_max_encoded_len_works() { + assert_eq!(DelayedOrigin::::max_encoded_len(), 22); + assert_eq!(OriginCaller::max_encoded_len(), 27); +} diff --git a/benchmarking/Cargo.toml b/benchmarking/Cargo.toml index c0e50e798..a7fc2e3fc 100644 --- a/benchmarking/Cargo.toml +++ b/benchmarking/Cargo.toml @@ -8,20 +8,20 @@ authors = ["Laminar Developers "] edition = "2021" [dependencies] -serde = { version = "1.0.136", optional = true } -paste = "1.0.7" codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } -scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } log = { version = "0.4.17", default-features = false } +paste = "1.0.7" +scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +serde = { version = "1.0.136", optional = true } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } sp-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-runtime-interface = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-runtime-interface = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } sp-storage = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } [dev-dependencies] hex-literal = "0.3.4" @@ -32,13 +32,16 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "polk default = [ "std" ] std = [ "serde", + "codec/std", + "frame-benchmarking/std", + "frame-support/std", + "log/std", "scale-info/std", + "sp-api/std", + "sp-io/std", "sp-runtime-interface/std", "sp-runtime/std", - "sp-api/std", "sp-std/std", - "frame-support/std", - "frame-benchmarking/std", - "log/std", + "sp-storage/std", ] diff --git a/currencies/Cargo.toml b/currencies/Cargo.toml index 68cdf1ee9..2c54199e8 100644 --- a/currencies/Cargo.toml +++ b/currencies/Cargo.toml @@ -8,22 +8,22 @@ authors = ["Laminar Developers "] edition = "2021" [dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } orml-utilities = { path = "../utilities", version = "0.4.1-dev", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } orml_tokens = { package = "orml-tokens", path = "../tokens", version = "0.4.1-dev" } @@ -31,14 +31,18 @@ orml_tokens = { package = "orml-tokens", path = "../tokens", version = "0.4.1-de default = ["std"] std = [ "serde", + "codec/std", - "scale-info/std", - "sp-runtime/std", - "sp-std/std", - "sp-io/std", "frame-support/std", "frame-system/std", "orml-traits/std", "orml-utilities/std", + "scale-info/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", ] -try-runtime = ["frame-support/try-runtime"] diff --git a/gradually-update/Cargo.toml b/gradually-update/Cargo.toml index 93591c3e8..45829b0c9 100644 --- a/gradually-update/Cargo.toml +++ b/gradually-update/Cargo.toml @@ -8,28 +8,32 @@ authors = ["Laminar Developers "] edition = "2021" [dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } [features] default = ["std"] std = [ "serde", + "codec/std", - "scale-info/std", "frame-support/std", "frame-system/std", - "sp-io/std", - "sp-std/std", + "scale-info/std", "sp-core/std", + "sp-io/std", "sp-runtime/std", + "sp-std/std", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", ] -try-runtime = ["frame-support/try-runtime"] diff --git a/nft/Cargo.toml b/nft/Cargo.toml index 8b408a4b6..43d6000cc 100644 --- a/nft/Cargo.toml +++ b/nft/Cargo.toml @@ -8,28 +8,32 @@ authors = ["Acala Developers"] edition = "2021" [dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } [features] default = ["std"] std = [ "serde", + "codec/std", - "scale-info/std", - "sp-std/std", - "sp-runtime/std", "frame-support/std", "frame-system/std", + "scale-info/std", + "sp-runtime/std", + "sp-std/std", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", +] \ No newline at end of file diff --git a/oracle/Cargo.toml b/oracle/Cargo.toml index a5c51f564..68836ecd0 100644 --- a/oracle/Cargo.toml +++ b/oracle/Cargo.toml @@ -8,16 +8,16 @@ authors = ["Laminar Developers "] edition = "2021" [dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } sp-application-crypto = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } orml-utilities = { path = "../utilities", version = "0.4.1-dev", default-features = false } @@ -29,15 +29,19 @@ sp-core = { git = "https://github.com/paritytech/substrate", default-features = default = ["std"] std = [ "serde", + "codec/std", + "frame-support/std", + "frame-system/std", + "orml-traits/std", + "orml-utilities/std", "scale-info/std", "sp-application-crypto/std", "sp-io/std", "sp-runtime/std", "sp-std/std", - "frame-support/std", - "frame-system/std", - "orml-traits/std", - "orml-utilities/std", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", +] diff --git a/payments/Cargo.toml b/payments/Cargo.toml index 81044bc0a..6218a3dfc 100644 --- a/payments/Cargo.toml +++ b/payments/Cargo.toml @@ -10,7 +10,7 @@ description = "Allows users to post escrow payment on-chain" readme = "README.md" [dependencies] -parity-scale-codec = { version = "3.1.5", default-features = false, features = ["max-encoded-len"] } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } @@ -32,13 +32,17 @@ orml-tokens = { path = "../tokens", version = "0.4.1-dev", default-features = fa [features] default = ['std'] std = [ - 'parity-scale-codec/std', + 'codec/std', 'frame-support/std', 'frame-system/std', 'log/std', + 'orml-tokens/std', + 'orml-traits/std', + 'scale-info/std', 'sp-runtime/std', 'sp-std/std', - 'scale-info/std', - 'orml-traits/std', - 'orml-tokens/std' ] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", +] \ No newline at end of file diff --git a/payments/src/types.rs b/payments/src/types.rs index a4e5058d4..acb694db2 100644 --- a/payments/src/types.rs +++ b/payments/src/types.rs @@ -1,6 +1,6 @@ #![allow(unused_qualifications)] use crate::{pallet, AssetIdOf, BalanceOf}; -use parity_scale_codec::{Decode, Encode, HasCompact, MaxEncodedLen}; +use codec::{Decode, Encode, HasCompact, MaxEncodedLen}; use scale_info::TypeInfo; use sp_runtime::{DispatchResult, Percent}; diff --git a/rewards/Cargo.toml b/rewards/Cargo.toml index 27e15bb17..b54b2c2d4 100644 --- a/rewards/Cargo.toml +++ b/rewards/Cargo.toml @@ -8,16 +8,16 @@ authors = ["Acala Developers"] edition = "2021" [dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } @@ -28,14 +28,18 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot- default = ["std"] std = [ "serde", + "codec/std", - "scale-info/std", - "sp-runtime/std", - "sp-io/std", - "sp-std/std", - "sp-core/std", "frame-support/std", "frame-system/std", "orml-traits/std", + "scale-info/std", + "sp-core/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", +] \ No newline at end of file diff --git a/rewards/src/lib.rs b/rewards/src/lib.rs index 0ef94ade5..f395f9506 100644 --- a/rewards/src/lib.rs +++ b/rewards/src/lib.rs @@ -274,22 +274,24 @@ impl Pallet { return; } - PoolInfos::::mutate(pool, |pool_info| { - let total_shares = U256::from(pool_info.total_shares.to_owned().saturated_into::()); - pool_info.rewards.iter_mut().for_each( - |(reward_currency, (total_reward, total_withdrawn_reward))| { - Self::claim_one( - withdrawn_rewards, - *reward_currency, - share.to_owned(), - total_reward.to_owned(), - total_shares, - total_withdrawn_reward, - who, - pool, - ); - }, - ); + PoolInfos::::mutate_exists(pool, |maybe_pool_info| { + if let Some(pool_info) = maybe_pool_info { + let total_shares = U256::from(pool_info.total_shares.to_owned().saturated_into::()); + pool_info.rewards.iter_mut().for_each( + |(reward_currency, (total_reward, total_withdrawn_reward))| { + Self::claim_one( + withdrawn_rewards, + *reward_currency, + share.to_owned(), + total_reward.to_owned(), + total_shares, + total_withdrawn_reward, + who, + pool, + ); + }, + ); + } }); } }); diff --git a/rewards/src/tests.rs b/rewards/src/tests.rs index f0c05bd25..fb80a28bb 100644 --- a/rewards/src/tests.rs +++ b/rewards/src/tests.rs @@ -121,6 +121,32 @@ fn claim_rewards_should_not_create_empty_records() { SharesAndWithdrawnRewards::::contains_key(&DOT_POOL, &ALICE), false ); + + PoolInfos::::mutate(DOT_POOL, |pool_info| { + pool_info.rewards.insert(NATIVE_COIN, (10_000, 0)); + }); + RewardsModule::add_share(&ALICE, &DOT_POOL, 100); + assert_eq!( + RewardsModule::pool_infos(DOT_POOL), + PoolInfo { + total_shares: 100, + rewards: vec![(NATIVE_COIN, (10_000, 0))].into_iter().collect() + } + ); + assert_eq!( + RewardsModule::shares_and_withdrawn_rewards(DOT_POOL, ALICE), + (100, vec![(NATIVE_COIN, 0)].into_iter().collect()) + ); + + PoolInfos::::remove(DOT_POOL); + assert_eq!(PoolInfos::::contains_key(DOT_POOL), false); + + RewardsModule::claim_rewards(&ALICE, &DOT_POOL); + assert_eq!(PoolInfos::::contains_key(&DOT_POOL), false); + assert_eq!( + RewardsModule::shares_and_withdrawn_rewards(DOT_POOL, ALICE), + (100, vec![(NATIVE_COIN, 0)].into_iter().collect()) + ); }) } diff --git a/tokens/Cargo.toml b/tokens/Cargo.toml index e6573be1f..b69d4a4e0 100644 --- a/tokens/Cargo.toml +++ b/tokens/Cargo.toml @@ -8,37 +8,42 @@ authors = ["Laminar Developers "] edition = "2021" [dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } -pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } pallet-elections-phragmen = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } +pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } [features] default = ["std"] std = [ "serde", + "codec/std", - "scale-info/std", - "sp-runtime/std", - "sp-std/std", "frame-support/std", "frame-system/std", "orml-traits/std", + "scale-info/std", + "sp-runtime/std", + "sp-std/std", ] runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", +] \ No newline at end of file diff --git a/traits/src/xcm_transfer.rs b/traits/src/xcm_transfer.rs index 797f2c50d..cd671f5e6 100644 --- a/traits/src/xcm_transfer.rs +++ b/traits/src/xcm_transfer.rs @@ -1,5 +1,5 @@ use frame_support::dispatch::DispatchResult; -use xcm::latest::{prelude::*, Weight}; +use xcm::latest::prelude::*; /// Abstraction over cross-chain token transfers. pub trait XcmTransfer { @@ -9,7 +9,7 @@ pub trait XcmTransfer { currency_id: CurrencyId, amount: Balance, dest: MultiLocation, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult; /// Transfer `MultiAsset` @@ -17,6 +17,6 @@ pub trait XcmTransfer { who: AccountId, asset: MultiAsset, dest: MultiLocation, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult; } diff --git a/unknown-tokens/Cargo.toml b/unknown-tokens/Cargo.toml index 07c8a610e..2fc720c5f 100644 --- a/unknown-tokens/Cargo.toml +++ b/unknown-tokens/Cargo.toml @@ -8,33 +8,37 @@ authors = ["Acala Developers"] edition = "2021" [dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.31" } orml-xcm-support = { path = "../xcm-support", default-features = false } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } [features] default = ["std"] std = [ "serde", + "codec/std", - "scale-info/std", - "sp-std/std", "frame-support/std", "frame-system/std", - "xcm/std", "orml-xcm-support/std", + "scale-info/std", + "sp-std/std", + "xcm/std", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", +] \ No newline at end of file diff --git a/vesting/Cargo.toml b/vesting/Cargo.toml index f406347ee..9cbf09fe5 100644 --- a/vesting/Cargo.toml +++ b/vesting/Cargo.toml @@ -8,34 +8,39 @@ authors = ["Laminar Developers "] edition = "2021" [dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } [features] default = ["std"] std = [ "serde", + "codec/std", + "frame-support/std", + "frame-system/std", "scale-info/std", + "sp-io/std", "sp-runtime/std", "sp-std/std", - "sp-io/std", - "frame-support/std", - "frame-system/std", ] runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", +] \ No newline at end of file diff --git a/xcm-support/Cargo.toml b/xcm-support/Cargo.toml index d3e1e0b51..460b49d71 100644 --- a/xcm-support/Cargo.toml +++ b/xcm-support/Cargo.toml @@ -10,9 +10,9 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.31" } xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.31" } @@ -22,10 +22,11 @@ orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = fa [features] default = ["std"] std = [ - "sp-std/std", - "sp-runtime/std", + "codec/std", "frame-support/std", - "xcm/std", - "xcm-executor/std", "orml-traits/std", + "sp-runtime/std", + "sp-std/std", + "xcm-executor/std", + "xcm/std", ] diff --git a/xcm/Cargo.toml b/xcm/Cargo.toml index 6b75f3cee..a72393624 100644 --- a/xcm/Cargo.toml +++ b/xcm/Cargo.toml @@ -11,12 +11,12 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.31" } pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.31" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.31" } [dev-dependencies] xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.31" } @@ -25,11 +25,15 @@ xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "rele default = ["std"] std = [ "codec/std", - "scale-info/std", - "sp-std/std", "frame-support/std", "frame-system/std", - "xcm/std", "pallet-xcm/std", + "scale-info/std", + "sp-std/std", + "xcm/std", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", + "pallet-xcm/try-runtime", +] \ No newline at end of file diff --git a/xtokens/Cargo.toml b/xtokens/Cargo.toml index 78e660234..6d7c8c143 100644 --- a/xtokens/Cargo.toml +++ b/xtokens/Cargo.toml @@ -8,16 +8,16 @@ authors = ["Acala Developers"] edition = "2021" [dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } # substrate -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.31" } # cumulus cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", default-features = false , branch = "polkadot-v0.9.31" } @@ -28,19 +28,19 @@ xcm = { git = "https://github.com/paritytech/polkadot", default-features = false xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.31" } # orml -orml-xcm-support = { path = "../xcm-support", default-features = false } orml-traits = { path = "../traits", default-features = false} +orml-xcm-support = { path = "../xcm-support", default-features = false } [dev-dependencies] # substrate -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" } # cumulus -cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.31" } cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.31" } -cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.31" } cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.31" } +cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.31" } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.31" } parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.31" } # polkadot @@ -57,21 +57,31 @@ orml-xcm = { path = "../xcm" } default = ["std"] std = [ "serde", + "codec/std", + "cumulus-primitives-core/std", + "frame-support/std", + "frame-system/std", + "orml-traits/std", + "orml-xcm-support/std", + "pallet-xcm/std", "scale-info/std", + "sp-io/std", "sp-runtime/std", "sp-std/std", - "sp-io/std", - "frame-support/std", - "frame-system/std", - "cumulus-primitives-core/std", - "xcm/std", "xcm-executor/std", - "orml-xcm-support/std", - "orml-traits/std", + "xcm/std", ] runtime-benchmarks = [ + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", + "pallet-xcm/try-runtime", +] \ No newline at end of file diff --git a/xtokens/src/lib.rs b/xtokens/src/lib.rs index 027ad6215..89ad16bff 100644 --- a/xtokens/src/lib.rs +++ b/xtokens/src/lib.rs @@ -189,9 +189,9 @@ pub mod module { impl Pallet { /// Transfer native currencies. /// - /// `dest_weight` is the weight for XCM execution on the dest chain, and - /// it would be charged from the transferred assets. If set below - /// requirements, the execution may fail and assets wouldn't be + /// `dest_weight_limit` is the weight for XCM execution on the dest + /// chain, and it would be charged from the transferred assets. If set + /// below requirements, the execution may fail and assets wouldn't be /// received. /// /// It's a no-op if any error on local XCM execution or message sending. @@ -205,18 +205,18 @@ pub mod module { currency_id: T::CurrencyId, amount: T::Balance, dest: Box, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult { let who = ensure_signed(origin)?; let dest: MultiLocation = (*dest).try_into().map_err(|()| Error::::BadVersion)?; - Self::do_transfer(who, currency_id, amount, dest, dest_weight) + Self::do_transfer(who, currency_id, amount, dest, dest_weight_limit) } /// Transfer `MultiAsset`. /// - /// `dest_weight` is the weight for XCM execution on the dest chain, and - /// it would be charged from the transferred assets. If set below - /// requirements, the execution may fail and assets wouldn't be + /// `dest_weight_limit` is the weight for XCM execution on the dest + /// chain, and it would be charged from the transferred assets. If set + /// below requirements, the execution may fail and assets wouldn't be /// received. /// /// It's a no-op if any error on local XCM execution or message sending. @@ -229,20 +229,20 @@ pub mod module { origin: OriginFor, asset: Box, dest: Box, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult { let who = ensure_signed(origin)?; let asset: MultiAsset = (*asset).try_into().map_err(|()| Error::::BadVersion)?; let dest: MultiLocation = (*dest).try_into().map_err(|()| Error::::BadVersion)?; - Self::do_transfer_multiasset(who, asset, dest, dest_weight) + Self::do_transfer_multiasset(who, asset, dest, dest_weight_limit) } /// Transfer native currencies specifying the fee and amount as /// separate. /// - /// `dest_weight` is the weight for XCM execution on the dest chain, and - /// it would be charged from the transferred assets. If set below - /// requirements, the execution may fail and assets wouldn't be + /// `dest_weight_limit` is the weight for XCM execution on the dest + /// chain, and it would be charged from the transferred assets. If set + /// below requirements, the execution may fail and assets wouldn't be /// received. /// /// `fee` is the amount to be spent to pay for execution in destination @@ -265,19 +265,19 @@ pub mod module { amount: T::Balance, fee: T::Balance, dest: Box, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult { let who = ensure_signed(origin)?; let dest: MultiLocation = (*dest).try_into().map_err(|()| Error::::BadVersion)?; - Self::do_transfer_with_fee(who, currency_id, amount, fee, dest, dest_weight) + Self::do_transfer_with_fee(who, currency_id, amount, fee, dest, dest_weight_limit) } /// Transfer `MultiAsset` specifying the fee and amount as separate. /// - /// `dest_weight` is the weight for XCM execution on the dest chain, and - /// it would be charged from the transferred assets. If set below - /// requirements, the execution may fail and assets wouldn't be + /// `dest_weight_limit` is the weight for XCM execution on the dest + /// chain, and it would be charged from the transferred assets. If set + /// below requirements, the execution may fail and assets wouldn't be /// received. /// /// `fee` is the multiasset to be spent to pay for execution in @@ -300,21 +300,21 @@ pub mod module { asset: Box, fee: Box, dest: Box, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult { let who = ensure_signed(origin)?; let asset: MultiAsset = (*asset).try_into().map_err(|()| Error::::BadVersion)?; let fee: MultiAsset = (*fee).try_into().map_err(|()| Error::::BadVersion)?; let dest: MultiLocation = (*dest).try_into().map_err(|()| Error::::BadVersion)?; - Self::do_transfer_multiasset_with_fee(who, asset, fee, dest, dest_weight) + Self::do_transfer_multiasset_with_fee(who, asset, fee, dest, dest_weight_limit) } /// Transfer several currencies specifying the item to be used as fee /// - /// `dest_weight` is the weight for XCM execution on the dest chain, and - /// it would be charged from the transferred assets. If set below - /// requirements, the execution may fail and assets wouldn't be + /// `dest_weight_limit` is the weight for XCM execution on the dest + /// chain, and it would be charged from the transferred assets. If set + /// below requirements, the execution may fail and assets wouldn't be /// received. /// /// `fee_item` is index of the currencies tuple that we want to use for @@ -331,19 +331,19 @@ pub mod module { currencies: Vec<(T::CurrencyId, T::Balance)>, fee_item: u32, dest: Box, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult { let who = ensure_signed(origin)?; let dest: MultiLocation = (*dest).try_into().map_err(|()| Error::::BadVersion)?; - Self::do_transfer_multicurrencies(who, currencies, fee_item, dest, dest_weight) + Self::do_transfer_multicurrencies(who, currencies, fee_item, dest, dest_weight_limit) } /// Transfer several `MultiAsset` specifying the item to be used as fee /// - /// `dest_weight` is the weight for XCM execution on the dest chain, and - /// it would be charged from the transferred assets. If set below - /// requirements, the execution may fail and assets wouldn't be + /// `dest_weight_limit` is the weight for XCM execution on the dest + /// chain, and it would be charged from the transferred assets. If set + /// below requirements, the execution may fail and assets wouldn't be /// received. /// /// `fee_item` is index of the MultiAssets that we want to use for @@ -360,7 +360,7 @@ pub mod module { assets: Box, fee_item: u32, dest: Box, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult { let who = ensure_signed(origin)?; let assets: MultiAssets = (*assets).try_into().map_err(|()| Error::::BadVersion)?; @@ -369,7 +369,7 @@ pub mod module { // We first grab the fee let fee: &MultiAsset = assets.get(fee_item as usize).ok_or(Error::::AssetIndexNonExistent)?; - Self::do_transfer_multiassets(who, assets.clone(), fee.clone(), dest, dest_weight) + Self::do_transfer_multiassets(who, assets.clone(), fee.clone(), dest, dest_weight_limit) } } @@ -379,7 +379,7 @@ pub mod module { currency_id: T::CurrencyId, amount: T::Balance, dest: MultiLocation, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult { let location: MultiLocation = T::CurrencyIdConvert::convert(currency_id).ok_or(Error::::NotCrossChainTransferableCurrency)?; @@ -391,7 +391,7 @@ pub mod module { ); let asset: MultiAsset = (location, amount.into()).into(); - Self::do_transfer_multiassets(who, vec![asset.clone()].into(), asset, dest, dest_weight) + Self::do_transfer_multiassets(who, vec![asset.clone()].into(), asset, dest, dest_weight_limit) } fn do_transfer_with_fee( @@ -400,7 +400,7 @@ pub mod module { amount: T::Balance, fee: T::Balance, dest: MultiLocation, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult { let location: MultiLocation = T::CurrencyIdConvert::convert(currency_id).ok_or(Error::::NotCrossChainTransferableCurrency)?; @@ -420,16 +420,16 @@ pub mod module { assets.push(asset); assets.push(fee_asset.clone()); - Self::do_transfer_multiassets(who, assets, fee_asset, dest, dest_weight) + Self::do_transfer_multiassets(who, assets, fee_asset, dest, dest_weight_limit) } fn do_transfer_multiasset( who: T::AccountId, asset: MultiAsset, dest: MultiLocation, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult { - Self::do_transfer_multiassets(who, vec![asset.clone()].into(), asset, dest, dest_weight) + Self::do_transfer_multiassets(who, vec![asset.clone()].into(), asset, dest, dest_weight_limit) } fn do_transfer_multiasset_with_fee( @@ -437,14 +437,14 @@ pub mod module { asset: MultiAsset, fee: MultiAsset, dest: MultiLocation, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult { // Push contains saturated addition, so we should be able to use it safely let mut assets = MultiAssets::new(); assets.push(asset); assets.push(fee.clone()); - Self::do_transfer_multiassets(who, assets, fee, dest, dest_weight)?; + Self::do_transfer_multiassets(who, assets, fee, dest, dest_weight_limit)?; Ok(()) } @@ -454,7 +454,7 @@ pub mod module { currencies: Vec<(T::CurrencyId, T::Balance)>, fee_item: u32, dest: MultiLocation, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult { ensure!( currencies.len() <= T::MaxAssetsForTransfer::get(), @@ -488,7 +488,7 @@ pub mod module { let fee: MultiAsset = (fee_location, (*fee_amount).into()).into(); - Self::do_transfer_multiassets(who, assets, fee, dest, dest_weight) + Self::do_transfer_multiassets(who, assets, fee, dest, dest_weight_limit) } fn do_transfer_multiassets( @@ -496,7 +496,7 @@ pub mod module { assets: MultiAssets, fee: MultiAsset, dest: MultiLocation, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult { ensure!( assets.len() <= T::MaxAssetsForTransfer::get(), @@ -576,7 +576,7 @@ pub mod module { fee_reserve, &dest, Some(override_recipient), - dest_weight, + dest_weight_limit.clone(), true, )?; @@ -588,7 +588,7 @@ pub mod module { non_fee_reserve, &dest, None, - dest_weight, + dest_weight_limit, false, )?; } else { @@ -599,7 +599,7 @@ pub mod module { non_fee_reserve, &dest, None, - dest_weight, + dest_weight_limit, false, )?; } @@ -623,7 +623,7 @@ pub mod module { reserve: Option, dest: &MultiLocation, maybe_recipient_override: Option, - dest_weight: Weight, + dest_weight_limit: WeightLimit, use_teleport: bool, ) -> DispatchResult { let (transfer_kind, dest, reserve, recipient) = Self::transfer_kind(reserve, dest)?; @@ -633,11 +633,17 @@ pub mod module { }; let mut msg = match transfer_kind { - SelfReserveAsset => Self::transfer_self_reserve_asset(assets, fee, dest, recipient, dest_weight)?, - ToReserve => Self::transfer_to_reserve(assets, fee, dest, recipient, dest_weight)?, - ToNonReserve => { - Self::transfer_to_non_reserve(assets, fee, reserve, dest, recipient, dest_weight, use_teleport)? - } + SelfReserveAsset => Self::transfer_self_reserve_asset(assets, fee, dest, recipient, dest_weight_limit)?, + ToReserve => Self::transfer_to_reserve(assets, fee, dest, recipient, dest_weight_limit)?, + ToNonReserve => Self::transfer_to_non_reserve( + assets, + fee, + reserve, + dest, + recipient, + dest_weight_limit, + use_teleport, + )?, }; let weight = T::Weigher::weight(&mut msg).map_err(|()| Error::::UnweighableMessage)?; @@ -656,13 +662,13 @@ pub mod module { fee: MultiAsset, dest: MultiLocation, recipient: MultiLocation, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> Result, DispatchError> { Ok(Xcm(vec![TransferReserveAsset { assets: assets.clone(), dest: dest.clone(), xcm: Xcm(vec![ - Self::buy_execution(fee, &dest, dest_weight)?, + Self::buy_execution(fee, &dest, dest_weight_limit)?, Self::deposit_asset(recipient, assets.len() as u32), ]), }])) @@ -673,7 +679,7 @@ pub mod module { fee: MultiAsset, reserve: MultiLocation, recipient: MultiLocation, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> Result, DispatchError> { Ok(Xcm(vec![ WithdrawAsset(assets.clone()), @@ -681,7 +687,7 @@ pub mod module { assets: All.into(), reserve: reserve.clone(), xcm: Xcm(vec![ - Self::buy_execution(fee, &reserve, dest_weight)?, + Self::buy_execution(fee, &reserve, dest_weight_limit)?, Self::deposit_asset(recipient, assets.len() as u32), ]), }, @@ -694,7 +700,7 @@ pub mod module { reserve: MultiLocation, dest: MultiLocation, recipient: MultiLocation, - dest_weight: Weight, + dest_weight_limit: WeightLimit, use_teleport: bool, ) -> Result, DispatchError> { let mut reanchored_dest = dest.clone(); @@ -717,13 +723,13 @@ pub mod module { assets: All.into(), reserve: reserve.clone(), xcm: Xcm(vec![ - Self::buy_execution(half(&fee), &reserve, dest_weight)?, + Self::buy_execution(half(&fee), &reserve, dest_weight_limit.clone())?, DepositReserveAsset { assets: All.into(), max_assets: assets.len() as u32, dest: reanchored_dest, xcm: Xcm(vec![ - Self::buy_execution(half(&fee), &dest, dest_weight)?, + Self::buy_execution(half(&fee), &dest, dest_weight_limit)?, Self::deposit_asset(recipient, assets.len() as u32), ]), }, @@ -737,12 +743,12 @@ pub mod module { assets: All.into(), reserve: reserve.clone(), xcm: Xcm(vec![ - Self::buy_execution(half(&fee), &reserve, dest_weight)?, + Self::buy_execution(half(&fee), &reserve, dest_weight_limit.clone())?, InitiateTeleport { assets: All.into(), dest: reanchored_dest, xcm: Xcm(vec![ - Self::buy_execution(half(&fee), &dest, dest_weight)?, + Self::buy_execution(half(&fee), &dest, dest_weight_limit)?, Self::deposit_asset(recipient, assets.len() as u32), ]), }, @@ -763,16 +769,14 @@ pub mod module { fn buy_execution( asset: MultiAsset, at: &MultiLocation, - weight: Weight, + weight_limit: WeightLimit, ) -> Result, DispatchError> { let ancestry = T::LocationInverter::ancestry(); let fees = asset .reanchored(at, &ancestry) .map_err(|_| Error::::CannotReanchor)?; - Ok(BuyExecution { - fees, - weight_limit: WeightLimit::Limited(weight), - }) + + Ok(BuyExecution { fees, weight_limit }) } /// Ensure has the `dest` has chain part and recipient part. @@ -931,9 +935,9 @@ pub mod module { currency_id: T::CurrencyId, amount: T::Balance, dest: MultiLocation, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult { - Self::do_transfer(who, currency_id, amount, dest, dest_weight) + Self::do_transfer(who, currency_id, amount, dest, dest_weight_limit) } #[require_transactional] @@ -941,9 +945,9 @@ pub mod module { who: T::AccountId, asset: MultiAsset, dest: MultiLocation, - dest_weight: Weight, + dest_weight_limit: WeightLimit, ) -> DispatchResult { - Self::do_transfer_multiasset(who, asset, dest, dest_weight) + Self::do_transfer_multiasset(who, asset, dest, dest_weight_limit) } } } diff --git a/xtokens/src/tests.rs b/xtokens/src/tests.rs index d1f368ef5..79ef3c0b7 100644 --- a/xtokens/src/tests.rs +++ b/xtokens/src/tests.rs @@ -71,7 +71,7 @@ fn send_relay_chain_asset_to_relay_chain() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::R, &ALICE), 500); }); @@ -106,7 +106,7 @@ fn send_relay_chain_asset_to_relay_chain_with_fee() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::R, &ALICE), 500); }); @@ -140,7 +140,7 @@ fn cannot_lost_fund_on_send_failed() { ) .into() ), - 40, + WeightLimit::Unlimited ), Error::::XcmExecutionFailed ); @@ -175,7 +175,7 @@ fn send_relay_chain_asset_to_sibling() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::R, &ALICE), 500); }); @@ -217,7 +217,7 @@ fn send_relay_chain_asset_to_sibling_with_fee() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::R, &ALICE), 500); }); @@ -264,7 +264,7 @@ fn send_sibling_asset_to_reserve_sibling() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::B, &ALICE), 500); @@ -289,7 +289,7 @@ fn send_sibling_asset_to_reserve_sibling() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::A, &BOB), 500); }); @@ -329,7 +329,7 @@ fn send_sibling_asset_to_reserve_sibling_with_fee() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::B, &ALICE), 500); @@ -372,7 +372,7 @@ fn send_sibling_asset_to_reserve_sibling_with_distinct_fee() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::B, &ALICE), 550); @@ -418,7 +418,7 @@ fn send_sibling_asset_to_reserve_sibling_with_distinct_fee_index_works() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::B, &ALICE), 550); @@ -464,7 +464,7 @@ fn send_sibling_asset_to_non_reserve_sibling() { ) .into() ), - 40 + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::B, &ALICE), 500); }); @@ -511,7 +511,7 @@ fn send_sibling_asset_to_non_reserve_sibling_with_fee() { ) .into() ), - 40 + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::B, &ALICE), 500); }); @@ -553,7 +553,7 @@ fn send_self_parachain_asset_to_sibling() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::A, &ALICE), 500); @@ -590,7 +590,7 @@ fn send_self_parachain_asset_to_sibling_with_fee() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::A, &ALICE), 500); @@ -628,7 +628,7 @@ fn send_self_parachain_asset_to_sibling_with_distinct_fee() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::A, &ALICE), 550); @@ -681,7 +681,7 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_works() { ) .into() ), - weight as u64, + WeightLimit::Limited(weight as u64), )); assert_eq!(550, ParaTokens::free_balance(CurrencyId::C, &ALICE)); assert_eq!(1000 - fee_amount, ParaTokens::free_balance(CurrencyId::R, &ALICE)); @@ -741,7 +741,7 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_works_with_relative_s ) .into() ), - weight as u64, + WeightLimit::Limited(weight as u64), )); assert_eq!(550, ParaRelativeTokens::free_balance(CurrencyId::C, &ALICE)); assert_eq!( @@ -804,7 +804,7 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_not_enough() { ) .into() ), - weight as u64, + WeightLimit::Limited(weight as u64), )); assert_eq!(550, ParaTokens::free_balance(CurrencyId::C, &ALICE)); assert_eq!(1000 - fee_amount, ParaTokens::free_balance(CurrencyId::R, &ALICE)); @@ -850,7 +850,7 @@ fn transfer_asset_with_relay_fee_failed() { ) .into() ), - 40, + WeightLimit::Unlimited ), Error::::InvalidAsset ); @@ -874,7 +874,7 @@ fn transfer_asset_with_relay_fee_failed() { ) .into() ), - 40, + WeightLimit::Unlimited ), Error::::InvalidAsset ); @@ -899,7 +899,7 @@ fn transfer_asset_with_relay_fee_failed() { ) .into() ), - 40, + WeightLimit::Unlimited ), Error::::FeeNotEnough ); @@ -923,7 +923,7 @@ fn transfer_asset_with_relay_fee_failed() { ) .into() ), - 40, + WeightLimit::Unlimited ), Error::::MinXcmFeeNotDefined ); @@ -950,7 +950,7 @@ fn transfer_no_reserve_assets_fails() { ) .into() ), - 50, + WeightLimit::Unlimited ), Error::::AssetHasNoReserve ); @@ -979,7 +979,7 @@ fn transfer_to_self_chain_fails() { ) .into() ), - 50, + WeightLimit::Unlimited ), Error::::NotCrossChainTransfer ); @@ -1005,7 +1005,7 @@ fn transfer_to_invalid_dest_fails() { ) .into() ), - 50, + WeightLimit::Unlimited ), Error::::InvalidDest ); @@ -1137,7 +1137,7 @@ fn send_with_zero_fee_should_yield_an_error() { ) .into() ), - 40, + WeightLimit::Unlimited ), Error::::ZeroFee ); @@ -1171,7 +1171,7 @@ fn send_with_insufficient_fee_traps_assets() { ) .into() ), - 40, + WeightLimit::Unlimited )); }); @@ -1214,7 +1214,7 @@ fn send_with_fee_should_handle_overflow() { ) .into() ), - 40, + WeightLimit::Unlimited ), Error::::XcmExecutionFailed ); @@ -1264,7 +1264,7 @@ fn specifying_more_than_assets_limit_should_error() { ) .into() ), - 40, + WeightLimit::Unlimited ), Error::::TooManyAssetsBeingSent ); @@ -1305,7 +1305,7 @@ fn sending_non_fee_assets_with_different_reserve_should_fail() { ) .into() ), - 40, + WeightLimit::Unlimited ), Error::::DistinctReserveForAssetAndFee ); @@ -1341,7 +1341,7 @@ fn specifying_a_non_existent_asset_index_should_fail() { ) .into() ), - 40, + WeightLimit::Unlimited ), Error::::AssetIndexNonExistent ); @@ -1369,7 +1369,7 @@ fn send_with_zero_amount() { ) .into() ), - 40, + WeightLimit::Unlimited ), Error::::ZeroAmount ); @@ -1390,7 +1390,7 @@ fn send_with_zero_amount() { ) .into() ), - 40, + WeightLimit::Unlimited ), Error::::ZeroAmount ); @@ -1423,7 +1423,7 @@ fn send_self_parachain_asset_to_sibling_relative_parachain() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaRelativeTokens::free_balance(CurrencyId::D, &ALICE), 500); @@ -1468,7 +1468,7 @@ fn send_sibling_asset_to_reserve_sibling_with_relative_view() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::D, &ALICE), 500); @@ -1496,7 +1496,7 @@ fn send_sibling_asset_to_reserve_sibling_with_relative_view() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaRelativeTokens::free_balance(CurrencyId::A, &BOB), 500); }); @@ -1537,7 +1537,7 @@ fn send_relative_view_sibling_asset_to_non_reserve_sibling() { ) .into() ), - 40 + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::D, &ALICE), 500); }); @@ -1585,7 +1585,7 @@ fn send_relay_chain_asset_to_relative_view_sibling() { ) .into() ), - 40, + WeightLimit::Unlimited )); assert_eq!(ParaTokens::free_balance(CurrencyId::R, &ALICE), 500); }); @@ -1623,7 +1623,7 @@ fn unsupported_multilocation_should_be_filtered() { ) .into() ), - 40, + WeightLimit::Unlimited ), Error::::NotSupportedMultiLocation ); @@ -1644,9 +1644,82 @@ fn unsupported_multilocation_should_be_filtered() { ) .into() ), - 40, + WeightLimit::Unlimited ), Error::::NotSupportedMultiLocation ); }); } + +#[test] +fn send_with_sufficient_weight_limit() { + TestNet::reset(); + + ParaA::execute_with(|| { + assert_ok!(ParaTokens::deposit(CurrencyId::A, &ALICE, 1_000)); + + assert_ok!(ParaXTokens::transfer( + Some(ALICE).into(), + CurrencyId::A, + 500, + Box::new( + MultiLocation::new( + 1, + X2( + Parachain(2), + Junction::AccountId32 { + network: NetworkId::Any, + id: BOB.into(), + } + ) + ) + .into() + ), + WeightLimit::Limited(40), + )); + + assert_eq!(ParaTokens::free_balance(CurrencyId::A, &ALICE), 500); + assert_eq!(ParaTokens::free_balance(CurrencyId::A, &sibling_b_account()), 500); + }); + + ParaB::execute_with(|| { + assert_eq!(ParaTokens::free_balance(CurrencyId::A, &BOB), 460); + }); +} + +#[test] +fn send_with_insufficient_weight_limit() { + TestNet::reset(); + + ParaA::execute_with(|| { + assert_ok!(ParaTokens::deposit(CurrencyId::A, &ALICE, 1_000)); + + assert_ok!(ParaXTokens::transfer( + Some(ALICE).into(), + CurrencyId::A, + 500, + Box::new( + MultiLocation::new( + 1, + X2( + Parachain(2), + Junction::AccountId32 { + network: NetworkId::Any, + id: BOB.into(), + } + ) + ) + .into() + ), + WeightLimit::Limited(1), + )); + + assert_eq!(ParaTokens::free_balance(CurrencyId::A, &ALICE), 500); + assert_eq!(ParaTokens::free_balance(CurrencyId::A, &sibling_b_account()), 500); + }); + + ParaB::execute_with(|| { + // no funds should arrive - message will have failed + assert_eq!(ParaTokens::free_balance(CurrencyId::A, &BOB), 0); + }); +}