Co #10719: Use into_account_truncating (#4947)

* Use into_account_truncating

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* more truncating

* more truncating

* more

* clean up parachain primitives

* more truncating

* update lockfile for {"substrate"}

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: parity-processbot <>
This commit is contained in:
Oliver Tale-Yazdi
2022-05-17 23:53:14 +02:00
committed by GitHub
parent 2907a7aeae
commit 157b5186ba
15 changed files with 279 additions and 236 deletions
+172 -172
View File
File diff suppressed because it is too large Load Diff
@@ -23,7 +23,7 @@ pub mod crowdloan_index_migration {
// The old way we generated fund accounts. // The old way we generated fund accounts.
fn old_fund_account_id<T: Config>(index: ParaId) -> T::AccountId { fn old_fund_account_id<T: Config>(index: ParaId) -> T::AccountId {
T::PalletId::get().into_sub_account(index) T::PalletId::get().into_sub_account_truncating(index)
} }
pub fn pre_migrate<T: Config>() -> Result<(), &'static str> { pub fn pre_migrate<T: Config>() -> Result<(), &'static str> {
+1 -1
View File
@@ -661,7 +661,7 @@ impl<T: Config> Pallet<T> {
/// This actually does computation. If you need to keep using it, then make sure you cache the /// This actually does computation. If you need to keep using it, then make sure you cache the
/// value and only call this once. /// value and only call this once.
pub fn fund_account_id(index: FundIndex) -> T::AccountId { pub fn fund_account_id(index: FundIndex) -> T::AccountId {
T::PalletId::get().into_sub_account(index) T::PalletId::get().into_sub_account_truncating(index)
} }
pub fn id_from_index(index: FundIndex) -> child::ChildInfo { pub fn id_from_index(index: FundIndex) -> child::ChildInfo {
@@ -24,7 +24,7 @@ pub mod slots_crowdloan_index_migration {
// The old way we generated fund accounts. // The old way we generated fund accounts.
fn old_fund_account_id<T: Config + crowdloan::Config>(index: ParaId) -> T::AccountId { fn old_fund_account_id<T: Config + crowdloan::Config>(index: ParaId) -> T::AccountId {
<T as crowdloan::Config>::PalletId::get().into_sub_account(index) <T as crowdloan::Config>::PalletId::get().into_sub_account_truncating(index)
} }
pub fn pre_migrate<T: Config + crowdloan::Config>() -> Result<(), &'static str> { pub fn pre_migrate<T: Config + crowdloan::Config>() -> Result<(), &'static str> {
+7 -7
View File
@@ -687,7 +687,7 @@ impl<T: Config> Pallet<T> {
// Return the deposit of the sender, but only if it is not the para being offboarded. // Return the deposit of the sender, but only if it is not the para being offboarded.
if !outgoing.contains(&req_id.sender) { if !outgoing.contains(&req_id.sender) {
T::Currency::unreserve( T::Currency::unreserve(
&req_id.sender.into_account(), &req_id.sender.into_account_truncating(),
req_data.sender_deposit.unique_saturated_into(), req_data.sender_deposit.unique_saturated_into(),
); );
} }
@@ -700,7 +700,7 @@ impl<T: Config> Pallet<T> {
if req_data.confirmed { if req_data.confirmed {
if !outgoing.contains(&req_id.recipient) { if !outgoing.contains(&req_id.recipient) {
T::Currency::unreserve( T::Currency::unreserve(
&req_id.recipient.into_account(), &req_id.recipient.into_account_truncating(),
config.hrmp_recipient_deposit.unique_saturated_into(), config.hrmp_recipient_deposit.unique_saturated_into(),
); );
} }
@@ -817,11 +817,11 @@ impl<T: Config> Pallet<T> {
<Self as Store>::HrmpChannels::take(channel_id) <Self as Store>::HrmpChannels::take(channel_id)
{ {
T::Currency::unreserve( T::Currency::unreserve(
&channel_id.sender.into_account(), &channel_id.sender.into_account_truncating(),
sender_deposit.unique_saturated_into(), sender_deposit.unique_saturated_into(),
); );
T::Currency::unreserve( T::Currency::unreserve(
&channel_id.recipient.into_account(), &channel_id.recipient.into_account_truncating(),
recipient_deposit.unique_saturated_into(), recipient_deposit.unique_saturated_into(),
); );
} }
@@ -1137,7 +1137,7 @@ impl<T: Config> Pallet<T> {
); );
T::Currency::reserve( T::Currency::reserve(
&origin.into_account(), &origin.into_account_truncating(),
config.hrmp_sender_deposit.unique_saturated_into(), config.hrmp_sender_deposit.unique_saturated_into(),
)?; )?;
@@ -1210,7 +1210,7 @@ impl<T: Config> Pallet<T> {
); );
T::Currency::reserve( T::Currency::reserve(
&origin.into_account(), &origin.into_account_truncating(),
config.hrmp_recipient_deposit.unique_saturated_into(), config.hrmp_recipient_deposit.unique_saturated_into(),
)?; )?;
@@ -1264,7 +1264,7 @@ impl<T: Config> Pallet<T> {
// Unreserve the sender's deposit. The recipient could not have left their deposit because // Unreserve the sender's deposit. The recipient could not have left their deposit because
// we ensured that the request is not confirmed. // we ensured that the request is not confirmed.
T::Currency::unreserve( T::Currency::unreserve(
&channel_id.sender.into_account(), &channel_id.sender.into_account_truncating(),
open_channel_req.sender_deposit.unique_saturated_into(), open_channel_req.sender_deposit.unique_saturated_into(),
); );
@@ -36,7 +36,7 @@ fn register_parachain_with_balance<T: Config>(id: ParaId, balance: BalanceOf<T>)
validation_code: vec![1].into(), validation_code: vec![1].into(),
}, },
); );
T::Currency::make_free_balance_be(&id.into_account(), balance); T::Currency::make_free_balance_be(&id.into_account_truncating(), balance);
} }
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) { fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
@@ -201,7 +201,7 @@ frame_benchmarking::benchmarks! {
let para: ParaId = 1u32.into(); let para: ParaId = 1u32.into();
let para_origin: crate::Origin = 1u32.into(); let para_origin: crate::Origin = 1u32.into();
register_parachain_with_balance::<T>(para, deposit); register_parachain_with_balance::<T>(para, deposit);
T::Currency::make_free_balance_be(&para.into_account(), deposit * 256u32.into()); T::Currency::make_free_balance_be(&para.into_account_truncating(), deposit * 256u32.into());
for ingress_para_id in 0..i { for ingress_para_id in 0..i {
// establish ingress channels to `para`. // establish ingress channels to `para`.
+32 -14
View File
@@ -135,7 +135,7 @@ fn register_parachain_with_balance(id: ParaId, balance: Balance) {
validation_code: vec![1].into(), validation_code: vec![1].into(),
}, },
)); ));
<Test as Config>::Currency::make_free_balance_be(&id.into_account(), balance); <Test as Config>::Currency::make_free_balance_be(&id.into_account_truncating(), balance);
} }
fn register_parachain(id: ParaId) { fn register_parachain(id: ParaId) {
@@ -490,15 +490,21 @@ fn refund_deposit_on_normal_closure() {
run_to_block(5, Some(vec![4, 5])); run_to_block(5, Some(vec![4, 5]));
Hrmp::init_open_channel(para_a, para_b, 2, 8).unwrap(); Hrmp::init_open_channel(para_a, para_b, 2, 8).unwrap();
Hrmp::accept_open_channel(para_b, para_a).unwrap(); Hrmp::accept_open_channel(para_b, para_a).unwrap();
assert_eq!(<Test as Config>::Currency::free_balance(&para_a.into_account()), 80); assert_eq!(<Test as Config>::Currency::free_balance(&para_a.into_account_truncating()), 80);
assert_eq!(<Test as Config>::Currency::free_balance(&para_b.into_account()), 95); assert_eq!(<Test as Config>::Currency::free_balance(&para_b.into_account_truncating()), 95);
run_to_block(8, Some(vec![8])); run_to_block(8, Some(vec![8]));
// Now, we close the channel and wait until the next session. // Now, we close the channel and wait until the next session.
Hrmp::close_channel(para_b, HrmpChannelId { sender: para_a, recipient: para_b }).unwrap(); Hrmp::close_channel(para_b, HrmpChannelId { sender: para_a, recipient: para_b }).unwrap();
run_to_block(10, Some(vec![10])); run_to_block(10, Some(vec![10]));
assert_eq!(<Test as Config>::Currency::free_balance(&para_a.into_account()), 100); assert_eq!(
assert_eq!(<Test as Config>::Currency::free_balance(&para_b.into_account()), 110); <Test as Config>::Currency::free_balance(&para_a.into_account_truncating()),
100
);
assert_eq!(
<Test as Config>::Currency::free_balance(&para_b.into_account_truncating()),
110
);
}); });
} }
@@ -517,8 +523,8 @@ fn refund_deposit_on_offboarding() {
run_to_block(5, Some(vec![4, 5])); run_to_block(5, Some(vec![4, 5]));
Hrmp::init_open_channel(para_a, para_b, 2, 8).unwrap(); Hrmp::init_open_channel(para_a, para_b, 2, 8).unwrap();
Hrmp::accept_open_channel(para_b, para_a).unwrap(); Hrmp::accept_open_channel(para_b, para_a).unwrap();
assert_eq!(<Test as Config>::Currency::free_balance(&para_a.into_account()), 80); assert_eq!(<Test as Config>::Currency::free_balance(&para_a.into_account_truncating()), 80);
assert_eq!(<Test as Config>::Currency::free_balance(&para_b.into_account()), 95); assert_eq!(<Test as Config>::Currency::free_balance(&para_b.into_account_truncating()), 95);
run_to_block(8, Some(vec![8])); run_to_block(8, Some(vec![8]));
assert!(channel_exists(para_a, para_b)); assert!(channel_exists(para_a, para_b));
@@ -531,8 +537,14 @@ fn refund_deposit_on_offboarding() {
assert!(!channel_exists(para_a, para_b)); assert!(!channel_exists(para_a, para_b));
Hrmp::assert_storage_consistency_exhaustive(); Hrmp::assert_storage_consistency_exhaustive();
assert_eq!(<Test as Config>::Currency::free_balance(&para_a.into_account()), 100); assert_eq!(
assert_eq!(<Test as Config>::Currency::free_balance(&para_b.into_account()), 110); <Test as Config>::Currency::free_balance(&para_a.into_account_truncating()),
100
);
assert_eq!(
<Test as Config>::Currency::free_balance(&para_b.into_account_truncating()),
110
);
}); });
} }
@@ -552,7 +564,7 @@ fn no_dangling_open_requests() {
// Start opening a channel a->b // Start opening a channel a->b
Hrmp::init_open_channel(para_a, para_b, 2, 8).unwrap(); Hrmp::init_open_channel(para_a, para_b, 2, 8).unwrap();
assert_eq!(<Test as Config>::Currency::free_balance(&para_a.into_account()), 80); assert_eq!(<Test as Config>::Currency::free_balance(&para_a.into_account_truncating()), 80);
// Then deregister one parachain, but don't wait two sessions until it takes effect. // Then deregister one parachain, but don't wait two sessions until it takes effect.
// Instead, `para_b` will confirm the request, which will take place the same time // Instead, `para_b` will confirm the request, which will take place the same time
@@ -560,12 +572,15 @@ fn no_dangling_open_requests() {
deregister_parachain(para_a); deregister_parachain(para_a);
run_to_block(9, Some(vec![9])); run_to_block(9, Some(vec![9]));
Hrmp::accept_open_channel(para_b, para_a).unwrap(); Hrmp::accept_open_channel(para_b, para_a).unwrap();
assert_eq!(<Test as Config>::Currency::free_balance(&para_b.into_account()), 95); assert_eq!(<Test as Config>::Currency::free_balance(&para_b.into_account_truncating()), 95);
assert!(!channel_exists(para_a, para_b)); assert!(!channel_exists(para_a, para_b));
run_to_block(10, Some(vec![10])); run_to_block(10, Some(vec![10]));
// The outcome we expect is `para_b` should receive the refund. // The outcome we expect is `para_b` should receive the refund.
assert_eq!(<Test as Config>::Currency::free_balance(&para_b.into_account()), 110); assert_eq!(
<Test as Config>::Currency::free_balance(&para_b.into_account_truncating()),
110
);
assert!(!channel_exists(para_a, para_b)); assert!(!channel_exists(para_a, para_b));
Hrmp::assert_storage_consistency_exhaustive(); Hrmp::assert_storage_consistency_exhaustive();
}); });
@@ -587,12 +602,15 @@ fn cancel_pending_open_channel_request() {
// Start opening a channel a->b // Start opening a channel a->b
Hrmp::init_open_channel(para_a, para_b, 2, 8).unwrap(); Hrmp::init_open_channel(para_a, para_b, 2, 8).unwrap();
assert_eq!(<Test as Config>::Currency::free_balance(&para_a.into_account()), 80); assert_eq!(<Test as Config>::Currency::free_balance(&para_a.into_account_truncating()), 80);
// Cancel opening the channel // Cancel opening the channel
Hrmp::cancel_open_request(para_a, HrmpChannelId { sender: para_a, recipient: para_b }) Hrmp::cancel_open_request(para_a, HrmpChannelId { sender: para_a, recipient: para_b })
.unwrap(); .unwrap();
assert_eq!(<Test as Config>::Currency::free_balance(&para_a.into_account()), 100); assert_eq!(
<Test as Config>::Currency::free_balance(&para_a.into_account_truncating()),
100
);
run_to_block(10, Some(vec![10])); run_to_block(10, Some(vec![10]));
assert!(!channel_exists(para_a, para_b)); assert!(!channel_exists(para_a, para_b));
+4 -1
View File
@@ -40,4 +40,7 @@ std = [
"xcm/std", "xcm/std",
"xcm-executor/std", "xcm-executor/std",
] ]
runtime-benchmarks = [] runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
]
+1 -1
View File
@@ -1074,7 +1074,7 @@ pub mod pallet {
pub fn check_account() -> T::AccountId { pub fn check_account() -> T::AccountId {
const ID: PalletId = PalletId(*b"py/xcmch"); const ID: PalletId = PalletId(*b"py/xcmch");
AccountIdConversion::<T::AccountId>::into_account(&ID) AccountIdConversion::<T::AccountId>::into_account_truncating(&ID)
} }
fn do_new_query( fn do_new_query(
+47 -25
View File
@@ -36,8 +36,10 @@ const SEND_AMOUNT: u128 = 10;
#[test] #[test]
fn report_outcome_notify_works() { fn report_outcome_notify_works() {
let balances = let balances = vec![
vec![(ALICE, INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account(), INITIAL_BALANCE)]; (ALICE, INITIAL_BALANCE),
(ParaId::from(PARA_ID).into_account_truncating(), INITIAL_BALANCE),
];
let sender = AccountId32 { network: AnyNetwork::get(), id: ALICE.into() }.into(); let sender = AccountId32 { network: AnyNetwork::get(), id: ALICE.into() }.into();
let mut message = Xcm(vec![TransferAsset { let mut message = Xcm(vec![TransferAsset {
assets: (Here, SEND_AMOUNT).into(), assets: (Here, SEND_AMOUNT).into(),
@@ -96,8 +98,10 @@ fn report_outcome_notify_works() {
#[test] #[test]
fn report_outcome_works() { fn report_outcome_works() {
let balances = let balances = vec![
vec![(ALICE, INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account(), INITIAL_BALANCE)]; (ALICE, INITIAL_BALANCE),
(ParaId::from(PARA_ID).into_account_truncating(), INITIAL_BALANCE),
];
let sender = AccountId32 { network: AnyNetwork::get(), id: ALICE.into() }.into(); let sender = AccountId32 { network: AnyNetwork::get(), id: ALICE.into() }.into();
let mut message = Xcm(vec![TransferAsset { let mut message = Xcm(vec![TransferAsset {
assets: (Here, SEND_AMOUNT).into(), assets: (Here, SEND_AMOUNT).into(),
@@ -148,8 +152,10 @@ fn report_outcome_works() {
/// Asserts that the expected message is sent and the event is emitted /// Asserts that the expected message is sent and the event is emitted
#[test] #[test]
fn send_works() { fn send_works() {
let balances = let balances = vec![
vec![(ALICE, INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account(), INITIAL_BALANCE)]; (ALICE, INITIAL_BALANCE),
(ParaId::from(PARA_ID).into_account_truncating(), INITIAL_BALANCE),
];
new_test_ext_with_balances(balances).execute_with(|| { new_test_ext_with_balances(balances).execute_with(|| {
let sender: MultiLocation = let sender: MultiLocation =
AccountId32 { network: AnyNetwork::get(), id: ALICE.into() }.into(); AccountId32 { network: AnyNetwork::get(), id: ALICE.into() }.into();
@@ -185,8 +191,10 @@ fn send_works() {
/// Asserts that `send` fails with `Error::SendFailure` /// Asserts that `send` fails with `Error::SendFailure`
#[test] #[test]
fn send_fails_when_xcm_router_blocks() { fn send_fails_when_xcm_router_blocks() {
let balances = let balances = vec![
vec![(ALICE, INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account(), INITIAL_BALANCE)]; (ALICE, INITIAL_BALANCE),
(ParaId::from(PARA_ID).into_account_truncating(), INITIAL_BALANCE),
];
new_test_ext_with_balances(balances).execute_with(|| { new_test_ext_with_balances(balances).execute_with(|| {
let sender: MultiLocation = let sender: MultiLocation =
Junction::AccountId32 { network: AnyNetwork::get(), id: ALICE.into() }.into(); Junction::AccountId32 { network: AnyNetwork::get(), id: ALICE.into() }.into();
@@ -212,8 +220,10 @@ fn send_fails_when_xcm_router_blocks() {
/// local effects. /// local effects.
#[test] #[test]
fn teleport_assets_works() { fn teleport_assets_works() {
let balances = let balances = vec![
vec![(ALICE, INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account(), INITIAL_BALANCE)]; (ALICE, INITIAL_BALANCE),
(ParaId::from(PARA_ID).into_account_truncating(), INITIAL_BALANCE),
];
new_test_ext_with_balances(balances).execute_with(|| { new_test_ext_with_balances(balances).execute_with(|| {
let weight = 2 * BaseXcmWeight::get(); let weight = 2 * BaseXcmWeight::get();
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE); assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE);
@@ -253,8 +263,10 @@ fn teleport_assets_works() {
/// local effects. /// local effects.
#[test] #[test]
fn limmited_teleport_assets_works() { fn limmited_teleport_assets_works() {
let balances = let balances = vec![
vec![(ALICE, INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account(), INITIAL_BALANCE)]; (ALICE, INITIAL_BALANCE),
(ParaId::from(PARA_ID).into_account_truncating(), INITIAL_BALANCE),
];
new_test_ext_with_balances(balances).execute_with(|| { new_test_ext_with_balances(balances).execute_with(|| {
let weight = 2 * BaseXcmWeight::get(); let weight = 2 * BaseXcmWeight::get();
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE); assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE);
@@ -295,8 +307,10 @@ fn limmited_teleport_assets_works() {
/// local effects. /// local effects.
#[test] #[test]
fn unlimmited_teleport_assets_works() { fn unlimmited_teleport_assets_works() {
let balances = let balances = vec![
vec![(ALICE, INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account(), INITIAL_BALANCE)]; (ALICE, INITIAL_BALANCE),
(ParaId::from(PARA_ID).into_account_truncating(), INITIAL_BALANCE),
];
new_test_ext_with_balances(balances).execute_with(|| { new_test_ext_with_balances(balances).execute_with(|| {
let weight = 2 * BaseXcmWeight::get(); let weight = 2 * BaseXcmWeight::get();
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE); assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE);
@@ -335,8 +349,10 @@ fn unlimmited_teleport_assets_works() {
/// is increased. Verifies the correct message is sent and event is emitted. /// is increased. Verifies the correct message is sent and event is emitted.
#[test] #[test]
fn reserve_transfer_assets_works() { fn reserve_transfer_assets_works() {
let balances = let balances = vec![
vec![(ALICE, INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account(), INITIAL_BALANCE)]; (ALICE, INITIAL_BALANCE),
(ParaId::from(PARA_ID).into_account_truncating(), INITIAL_BALANCE),
];
new_test_ext_with_balances(balances).execute_with(|| { new_test_ext_with_balances(balances).execute_with(|| {
let weight = BaseXcmWeight::get(); let weight = BaseXcmWeight::get();
let dest: MultiLocation = let dest: MultiLocation =
@@ -352,7 +368,7 @@ fn reserve_transfer_assets_works() {
// Alice spent amount // Alice spent amount
assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE - SEND_AMOUNT); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE - SEND_AMOUNT);
// Destination account (parachain account) has amount // Destination account (parachain account) has amount
let para_acc: AccountId = ParaId::from(PARA_ID).into_account(); let para_acc: AccountId = ParaId::from(PARA_ID).into_account_truncating();
assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE + SEND_AMOUNT); assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE + SEND_AMOUNT);
assert_eq!( assert_eq!(
sent_xcm(), sent_xcm(),
@@ -381,8 +397,10 @@ fn reserve_transfer_assets_works() {
/// is increased. Verifies the correct message is sent and event is emitted. /// is increased. Verifies the correct message is sent and event is emitted.
#[test] #[test]
fn limited_reserve_transfer_assets_works() { fn limited_reserve_transfer_assets_works() {
let balances = let balances = vec![
vec![(ALICE, INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account(), INITIAL_BALANCE)]; (ALICE, INITIAL_BALANCE),
(ParaId::from(PARA_ID).into_account_truncating(), INITIAL_BALANCE),
];
new_test_ext_with_balances(balances).execute_with(|| { new_test_ext_with_balances(balances).execute_with(|| {
let weight = BaseXcmWeight::get(); let weight = BaseXcmWeight::get();
let dest: MultiLocation = let dest: MultiLocation =
@@ -399,7 +417,7 @@ fn limited_reserve_transfer_assets_works() {
// Alice spent amount // Alice spent amount
assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE - SEND_AMOUNT); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE - SEND_AMOUNT);
// Destination account (parachain account) has amount // Destination account (parachain account) has amount
let para_acc: AccountId = ParaId::from(PARA_ID).into_account(); let para_acc: AccountId = ParaId::from(PARA_ID).into_account_truncating();
assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE + SEND_AMOUNT); assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE + SEND_AMOUNT);
assert_eq!( assert_eq!(
sent_xcm(), sent_xcm(),
@@ -428,8 +446,10 @@ fn limited_reserve_transfer_assets_works() {
/// is increased. Verifies the correct message is sent and event is emitted. /// is increased. Verifies the correct message is sent and event is emitted.
#[test] #[test]
fn unlimited_reserve_transfer_assets_works() { fn unlimited_reserve_transfer_assets_works() {
let balances = let balances = vec![
vec![(ALICE, INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account(), INITIAL_BALANCE)]; (ALICE, INITIAL_BALANCE),
(ParaId::from(PARA_ID).into_account_truncating(), INITIAL_BALANCE),
];
new_test_ext_with_balances(balances).execute_with(|| { new_test_ext_with_balances(balances).execute_with(|| {
let weight = BaseXcmWeight::get(); let weight = BaseXcmWeight::get();
let dest: MultiLocation = let dest: MultiLocation =
@@ -446,7 +466,7 @@ fn unlimited_reserve_transfer_assets_works() {
// Alice spent amount // Alice spent amount
assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE - SEND_AMOUNT); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE - SEND_AMOUNT);
// Destination account (parachain account) has amount // Destination account (parachain account) has amount
let para_acc: AccountId = ParaId::from(PARA_ID).into_account(); let para_acc: AccountId = ParaId::from(PARA_ID).into_account_truncating();
assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE + SEND_AMOUNT); assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE + SEND_AMOUNT);
assert_eq!( assert_eq!(
sent_xcm(), sent_xcm(),
@@ -473,8 +493,10 @@ fn unlimited_reserve_transfer_assets_works() {
/// is increased. Verifies the expected event is emitted. /// is increased. Verifies the expected event is emitted.
#[test] #[test]
fn execute_withdraw_to_deposit_works() { fn execute_withdraw_to_deposit_works() {
let balances = let balances = vec![
vec![(ALICE, INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account(), INITIAL_BALANCE)]; (ALICE, INITIAL_BALANCE),
(ParaId::from(PARA_ID).into_account_truncating(), INITIAL_BALANCE),
];
new_test_ext_with_balances(balances).execute_with(|| { new_test_ext_with_balances(balances).execute_with(|| {
let weight = 3 * BaseXcmWeight::get(); let weight = 3 * BaseXcmWeight::get();
let dest: MultiLocation = let dest: MultiLocation =
@@ -60,7 +60,7 @@ impl From<Error> for XcmError {
/// /// Our relay chain's location. /// /// Our relay chain's location.
/// parameter_types! { /// parameter_types! {
/// pub RelayChain: MultiLocation = Parent.into(); /// pub RelayChain: MultiLocation = Parent.into();
/// pub CheckingAccount: AccountId = PalletId(*b"checking").into_account(); /// pub CheckingAccount: AccountId = PalletId(*b"checking").into_account_truncating();
/// } /// }
/// ///
/// /// Some items that implement `Convert<MultiLocation, AccountId>`. Can be more, but for now we just assume we accept /// /// Some items that implement `Convert<MultiLocation, AccountId>`. Can be more, but for now we just assume we accept
@@ -70,7 +70,7 @@ impl<ParaId: From<u32> + Into<u32> + AccountIdConversion<AccountId>, AccountId:
fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<AccountId, ()> { fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<AccountId, ()> {
match location.borrow() { match location.borrow() {
MultiLocation { parents: 0, interior: X1(Parachain(id)) } => MultiLocation { parents: 0, interior: X1(Parachain(id)) } =>
Ok(ParaId::from(*id).into_account()), Ok(ParaId::from(*id).into_account_truncating()),
_ => Err(()), _ => Err(()),
} }
} }
@@ -91,7 +91,7 @@ impl<ParaId: From<u32> + Into<u32> + AccountIdConversion<AccountId>, AccountId:
fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<AccountId, ()> { fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<AccountId, ()> {
match location.borrow() { match location.borrow() {
MultiLocation { parents: 1, interior: X1(Parachain(id)) } => MultiLocation { parents: 1, interior: X1(Parachain(id)) } =>
Ok(ParaId::from(*id).into_account()), Ok(ParaId::from(*id).into_account_truncating()),
_ => Err(()), _ => Err(()),
} }
} }
+6 -6
View File
@@ -41,7 +41,7 @@ fn buy_execution<C>() -> Instruction<C> {
/// Asserts that the parachain accounts are updated as expected. /// Asserts that the parachain accounts are updated as expected.
#[test] #[test]
fn withdraw_and_deposit_works() { fn withdraw_and_deposit_works() {
let para_acc: AccountId = ParaId::from(PARA_ID).into_account(); let para_acc: AccountId = ParaId::from(PARA_ID).into_account_truncating();
let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)]; let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)];
kusama_like_with_balances(balances).execute_with(|| { kusama_like_with_balances(balances).execute_with(|| {
let other_para_id = 3000; let other_para_id = 3000;
@@ -61,7 +61,7 @@ fn withdraw_and_deposit_works() {
weight, weight,
); );
assert_eq!(r, Outcome::Complete(weight)); assert_eq!(r, Outcome::Complete(weight));
let other_para_acc: AccountId = ParaId::from(other_para_id).into_account(); let other_para_acc: AccountId = ParaId::from(other_para_id).into_account_truncating();
assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE - amount); assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE - amount);
assert_eq!(Balances::free_balance(other_para_acc), amount); assert_eq!(Balances::free_balance(other_para_acc), amount);
}); });
@@ -108,7 +108,7 @@ fn transfer_asset_works() {
#[test] #[test]
fn query_holding_works() { fn query_holding_works() {
use xcm::opaque::latest::prelude::*; use xcm::opaque::latest::prelude::*;
let para_acc: AccountId = ParaId::from(PARA_ID).into_account(); let para_acc: AccountId = ParaId::from(PARA_ID).into_account_truncating();
let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)]; let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)];
kusama_like_with_balances(balances).execute_with(|| { kusama_like_with_balances(balances).execute_with(|| {
let other_para_id = 3000; let other_para_id = 3000;
@@ -169,7 +169,7 @@ fn query_holding_works() {
weight, weight,
); );
assert_eq!(r, Outcome::Complete(weight)); assert_eq!(r, Outcome::Complete(weight));
let other_para_acc: AccountId = ParaId::from(other_para_id).into_account(); let other_para_acc: AccountId = ParaId::from(other_para_id).into_account_truncating();
assert_eq!(Balances::free_balance(other_para_acc), amount); assert_eq!(Balances::free_balance(other_para_acc), amount);
assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE - 2 * amount); assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE - 2 * amount);
assert_eq!( assert_eq!(
@@ -197,7 +197,7 @@ fn query_holding_works() {
#[test] #[test]
fn teleport_to_statemine_works() { fn teleport_to_statemine_works() {
use xcm::opaque::latest::prelude::*; use xcm::opaque::latest::prelude::*;
let para_acc: AccountId = ParaId::from(PARA_ID).into_account(); let para_acc: AccountId = ParaId::from(PARA_ID).into_account_truncating();
let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)]; let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)];
kusama_like_with_balances(balances).execute_with(|| { kusama_like_with_balances(balances).execute_with(|| {
let statemine_id = 1000; let statemine_id = 1000;
@@ -287,7 +287,7 @@ fn teleport_to_statemine_works() {
#[test] #[test]
fn reserve_based_transfer_works() { fn reserve_based_transfer_works() {
use xcm::opaque::latest::prelude::*; use xcm::opaque::latest::prelude::*;
let para_acc: AccountId = ParaId::from(PARA_ID).into_account(); let para_acc: AccountId = ParaId::from(PARA_ID).into_account_truncating();
let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)]; let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)];
kusama_like_with_balances(balances).execute_with(|| { kusama_like_with_balances(balances).execute_with(|| {
let other_para_id = 3000; let other_para_id = 3000;
@@ -61,7 +61,7 @@ decl_test_network! {
} }
pub fn para_account_id(id: u32) -> relay_chain::AccountId { pub fn para_account_id(id: u32) -> relay_chain::AccountId {
ParaId::from(id).into_account() ParaId::from(id).into_account_truncating()
} }
pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { pub fn para_ext(para_id: u32) -> sp_io::TestExternalities {
@@ -65,7 +65,7 @@ decl_test_network! {
} }
pub fn para_account_id(id: u32) -> relay_chain::AccountId { pub fn para_account_id(id: u32) -> relay_chain::AccountId {
ParaId::from(id).into_account() ParaId::from(id).into_account_truncating()
} }
pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { pub fn para_ext(para_id: u32) -> sp_io::TestExternalities {