Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create xcm emulator tests for People-Rococo #2373

Merged
merged 106 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
9de660b
create initial structure
0xmovses Nov 16, 2023
0f3d4a1
Update cumulus/parachains/integration-tests/emulated/chains/parachain…
0xmovses Nov 20, 2023
71eafe0
updates
0xmovses Nov 20, 2023
92d9d63
parachain set identity
0xmovses Nov 20, 2023
1908d75
assert has_idenity
0xmovses Nov 20, 2023
7d20153
reap identity
0xmovses Nov 20, 2023
dffefa1
updates xcm tests
0xmovses Nov 20, 2023
cebde91
assert deposit amount non zero
0xmovses Nov 20, 2023
84e6ed5
set identity zero deposit
0xmovses Nov 21, 2023
a762093
add test args
0xmovses Nov 21, 2023
2a970c2
".git/.scripts/commands/fmt/fmt.sh"
Nov 21, 2023
aeec8ef
Update cumulus/parachains/integration-tests/emulated/tests/people/peo…
0xmovses Nov 22, 2023
319b3ae
address petrowski feedback
0xmovses Nov 22, 2023
13d9d18
assert on subs_of
0xmovses Nov 22, 2023
b92de0a
add asserts on parachain
0xmovses Nov 22, 2023
6275090
check unreserved amount
0xmovses Nov 22, 2023
9072f05
add xcm feature, cleanup
0xmovses Nov 22, 2023
10da8af
remove redundant comment
0xmovses Nov 22, 2023
b5e4b3e
".git/.scripts/commands/fmt/fmt.sh"
Nov 22, 2023
65da33e
Update cumulus/parachains/integration-tests/emulated/tests/people/peo…
0xmovses Nov 22, 2023
386744f
Update cumulus/parachains/integration-tests/emulated/tests/people/peo…
0xmovses Nov 22, 2023
a6312db
Update cumulus/parachains/integration-tests/emulated/tests/people/peo…
0xmovses Nov 22, 2023
5e3e9a3
Update substrate/frame/identity/src/lib.rs
0xmovses Nov 22, 2023
e8e88d1
Update substrate/frame/identity/src/lib.rs
0xmovses Nov 22, 2023
41b3564
Update polkadot/runtime/rococo/src/lib.rs
0xmovses Nov 22, 2023
21ce617
Update polkadot/runtime/rococo/src/lib.rs
0xmovses Nov 22, 2023
1e2ab6d
add some printlns
0xmovses Nov 22, 2023
98cb721
assert parachain processes msg queue
0xmovses Nov 22, 2023
7670e4d
Update substrate/frame/identity/src/lib.rs
0xmovses Nov 22, 2023
e90f351
assert additional events
0xmovses Nov 22, 2023
9fbc89e
assert on inner enum vals
0xmovses Nov 23, 2023
72b38e2
".git/.scripts/commands/fmt/fmt.sh"
Nov 23, 2023
0d1c309
fmt
0xmovses Nov 23, 2023
7b35c9f
fmt
0xmovses Nov 23, 2023
472d203
assert IdentityMigrator events
0xmovses Nov 24, 2023
342454e
Update cumulus/parachains/integration-tests/emulated/tests/people/peo…
0xmovses Nov 24, 2023
1bca9e7
Update cumulus/parachains/integration-tests/emulated/chains/parachain…
0xmovses Nov 24, 2023
c29d8f7
Update cumulus/parachains/integration-tests/emulated/tests/people/peo…
0xmovses Nov 24, 2023
11d0a6a
version 0 cargo.lock
0xmovses Nov 24, 2023
880f611
Add filter, update weights
0xmovses Nov 27, 2023
3b3454c
update amounts and weights, all tests passing
0xmovses Nov 27, 2023
6d868e1
Update cumulus/parachains/integration-tests/emulated/chains/parachain…
0xmovses Nov 28, 2023
ee8d510
Update cumulus/parachains/integration-tests/emulated/tests/people/peo…
0xmovses Nov 28, 2023
8f54f7b
Update cumulus/parachains/integration-tests/emulated/tests/people/peo…
0xmovses Nov 28, 2023
b4e826e
updates
0xmovses Nov 28, 2023
12840ef
address pr feedback
0xmovses Nov 28, 2023
7ccfff3
add type aliases
0xmovses Nov 28, 2023
301fffe
fix conflicts
0xmovses Nov 28, 2023
dd8441f
".git/.scripts/commands/fmt/fmt.sh"
Nov 28, 2023
b313e18
typo
0xmovses Nov 28, 2023
8e9b251
clippy
0xmovses Nov 28, 2023
5ae4cd8
atleast an ED
0xmovses Nov 28, 2023
da2f38e
assert equality on exact
0xmovses Nov 28, 2023
4fc3e01
".git/.scripts/commands/fmt/fmt.sh"
Nov 28, 2023
f575356
create identities
0xmovses Nov 29, 2023
3902107
generalise asserts
0xmovses Nov 29, 2023
bc6a03e
check many instances
0xmovses Nov 29, 2023
58f8e77
Update cumulus/parachains/integration-tests/emulated/tests/people/peo…
0xmovses Nov 29, 2023
8abca7c
add comment
0xmovses Nov 29, 2023
0e2ddc1
add petrowski cases
0xmovses Nov 29, 2023
512e3a1
updates cleanup
0xmovses Nov 29, 2023
3985fab
reduce code duplication
0xmovses Nov 30, 2023
239e297
Merge branch 'joe-people-chain' into 0xmovses-people-xcm-tests
0xmovses Nov 30, 2023
3d262dd
use calc_remote_deposit
0xmovses Nov 30, 2023
348b9c4
assert and calculate on remote deposit
0xmovses Nov 30, 2023
872e454
remove redundant comment
0xmovses Nov 30, 2023
363ad04
clean
0xmovses Nov 30, 2023
c394638
Update cumulus/parachains/integration-tests/emulated/tests/people/peo…
0xmovses Dec 1, 2023
dbcd0bb
updates
0xmovses Dec 1, 2023
0c51fc4
Revert "updates"
0xmovses Dec 1, 2023
51a21a7
add Subs cases, refactor, petrowski feedback
0xmovses Dec 1, 2023
c2ca2ab
cleanup
0xmovses Dec 1, 2023
97a59fc
integrate seadanda feedback and further refactors
0xmovses Dec 1, 2023
9bcaffb
improve Identity::new
0xmovses Dec 1, 2023
0877093
Update cumulus/parachains/integration-tests/emulated/tests/people/peo…
0xmovses Dec 1, 2023
5c4fa6a
integrate petrowski feedback
0xmovses Dec 1, 2023
d73f6fe
call n times for with n new accounts
0xmovses Dec 1, 2023
83a5e70
create set_subs, update assertions
0xmovses Dec 1, 2023
8d23635
update comment
0xmovses Dec 1, 2023
5861ab5
total_deposit from subs variant
0xmovses Dec 1, 2023
5ba20bd
fix conflict
0xmovses Dec 1, 2023
0a44a21
small cleanups
0xmovses Dec 1, 2023
c5f065f
remove unneeded match
0xmovses Dec 1, 2023
37845fe
add all 12 cases
0xmovses Dec 1, 2023
dca8618
use default
0xmovses Dec 1, 2023
72829cb
generalise calc deposit
0xmovses Dec 2, 2023
e3a9f45
Tweaks to emulator People testing (#2595)
0xmovses Dec 4, 2023
6b015f9
integrate aguirre feedback
0xmovses Dec 4, 2023
bc86d0d
typo
0xmovses Dec 4, 2023
84fa2b1
improve doc comment
0xmovses Dec 4, 2023
ee7c5a9
Update cumulus/parachains/integration-tests/emulated/common/src/lib.rs
0xmovses Dec 4, 2023
342165f
Update cumulus/parachains/integration-tests/emulated/common/src/lib.rs
0xmovses Dec 4, 2023
cb3f892
impl relay para methods for TestArgs
0xmovses Dec 4, 2023
5582178
refactors
0xmovses Dec 4, 2023
dca66bf
Update cumulus/parachains/integration-tests/emulated/tests/people/peo…
0xmovses Dec 4, 2023
860c647
Update cumulus/parachains/integration-tests/emulated/tests/people/peo…
0xmovses Dec 4, 2023
76f4400
Update cumulus/parachains/integration-tests/emulated/tests/people/peo…
0xmovses Dec 4, 2023
149cae4
Update cumulus/parachains/integration-tests/emulated/common/src/impls.rs
0xmovses Dec 4, 2023
bc66fcd
Update substrate/frame/identity/src/lib.rs
0xmovses Dec 4, 2023
4a9cb21
integrate seadanda feedback, remove unused
0xmovses Dec 4, 2023
b2dddf8
update feature name
0xmovses Dec 4, 2023
bd4183d
".git/.scripts/commands/fmt/fmt.sh"
Dec 4, 2023
8083b9e
wrong method name
0xmovses Dec 4, 2023
3d9d09f
Apply suggestions from code review
joepetrowski Dec 5, 2023
1d7d1dd
Merge branch 'joe-people-chain' into 0xmovses-people-xcm-tests
joepetrowski Dec 5, 2023
b33d317
Update cumulus/xcm/xcm-emulator/src/lib.rs
joepetrowski Dec 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions cumulus/parachains/integration-tests/emulated/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,43 +86,6 @@ pub fn get_host_config() -> HostConfiguration<BlockNumber> {
}
}

/// Returns a [`TestArgs`] instance to be used for the Relay Chain across integration tests
pub fn relay_test_args(
dest: MultiLocation,
beneficiary_id: AccountId32,
amount: Balance,
) -> TestArgs {
TestArgs {
dest,
beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(),
amount,
assets: (Here, amount).into(),
asset_id: None,
fee_asset_item: 0,
weight_limit: WeightLimit::Unlimited,
}
}

/// Returns a [`TestArgs`] instance to be used by parachains across integration tests
pub fn para_test_args(
dest: MultiLocation,
beneficiary_id: AccountId32,
amount: Balance,
assets: MultiAssets,
asset_id: Option<u32>,
fee_asset_item: u32,
) -> TestArgs {
TestArgs {
dest,
beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(),
amount,
assets,
asset_id,
fee_asset_item,
weight_limit: WeightLimit::Unlimited,
}
}

/// Helper function used in tests to build the genesis storage using given RuntimeGenesisConfig and
/// code Used in `legacy_vs_json_check` submods to verify storage building with JSON patch against
/// building with RuntimeGenesisConfig struct.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use crate::*;
use asset_hub_rococo_runtime::xcm_config::XcmConfig as AssetHubRococoXcmConfig;
use emulated_integration_tests_common::{para_test_args, relay_test_args};
use penpal_runtime::xcm_config::XcmConfig as PenpalRococoXcmConfig;
use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig;

Expand Down Expand Up @@ -276,7 +275,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() {
let test_args = TestContext {
sender: RococoSender::get(),
receiver: PenpalAReceiver::get(),
args: relay_test_args(destination, beneficiary_id, amount_to_send),
args: TestArgs::new_relay(destination, beneficiary_id, amount_to_send),
};

let mut test = RelayToParaTest::new(test_args);
Expand Down Expand Up @@ -320,7 +319,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() {
let test_args = TestContext {
sender: AssetHubRococoSender::get(),
receiver: PenpalAReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = SystemParaToParaTest::new(test_args);
Expand Down Expand Up @@ -364,7 +363,7 @@ fn reserve_transfer_native_asset_from_para_to_system_para() {
let test_args = TestContext {
sender: PenpalASender::get(),
receiver: AssetHubRococoReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = ParaToSystemParaTest::new(test_args);
Expand Down Expand Up @@ -444,7 +443,7 @@ fn reserve_transfer_assets_from_system_para_to_para() {
let para_test_args = TestContext {
sender: AssetHubRococoSender::get(),
receiver: PenpalAReceiver::get(),
args: para_test_args(
args: TestArgs::new_para(
destination,
beneficiary_id,
asset_amount_to_send,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// Copyright (C) Parity Technologies (UK) Lt,
0xmovses marked this conversation as resolved.
Show resolved Hide resolved
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -15,7 +15,6 @@

use crate::*;
use asset_hub_rococo_runtime::xcm_config::XcmConfig as AssetHubRococoXcmConfig;
use emulated_integration_tests_common::{para_test_args, relay_test_args};
use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig;

fn relay_origin_assertions(t: RelayToSystemParaTest) {
Expand Down Expand Up @@ -163,7 +162,7 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() {
let test_args = TestContext {
sender: RococoSender::get(),
receiver: AssetHubRococoReceiver::get(),
args: relay_test_args(dest, beneficiary_id, amount_to_send),
args: TestArgs::new_relay(dest, beneficiary_id, amount_to_send),
};

let mut test = RelayToSystemParaTest::new(test_args);
Expand Down Expand Up @@ -207,7 +206,7 @@ fn limited_teleport_native_assets_back_from_system_para_to_relay_works() {
let test_args = TestContext {
sender: AssetHubRococoSender::get(),
receiver: RococoReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = SystemParaToRelayTest::new(test_args);
Expand Down Expand Up @@ -248,7 +247,7 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() {
let test_args = TestContext {
sender: AssetHubRococoSender::get(),
receiver: RococoReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = SystemParaToRelayTest::new(test_args);
Expand Down Expand Up @@ -286,7 +285,7 @@ fn teleport_native_assets_from_relay_to_system_para_works() {
let test_args = TestContext {
sender: RococoSender::get(),
receiver: AssetHubRococoReceiver::get(),
args: relay_test_args(dest, beneficiary_id, amount_to_send),
args: TestArgs::new_relay(dest, beneficiary_id, amount_to_send),
};

let mut test = RelayToSystemParaTest::new(test_args);
Expand Down Expand Up @@ -330,7 +329,7 @@ fn teleport_native_assets_back_from_system_para_to_relay_works() {
let test_args = TestContext {
sender: AssetHubRococoSender::get(),
receiver: RococoReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = SystemParaToRelayTest::new(test_args);
Expand Down Expand Up @@ -371,7 +370,7 @@ fn teleport_native_assets_from_system_para_to_relay_fails() {
let test_args = TestContext {
sender: AssetHubRococoSender::get(),
receiver: RococoReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = SystemParaToRelayTest::new(test_args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use crate::*;
use asset_hub_westend_runtime::xcm_config::XcmConfig as AssetHubWestendXcmConfig;
use emulated_integration_tests_common::{para_test_args, relay_test_args};
use penpal_runtime::xcm_config::XcmConfig as PenpalWestendXcmConfig;
use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig;

Expand Down Expand Up @@ -275,7 +274,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() {
let test_args = TestContext {
sender: WestendSender::get(),
receiver: PenpalBReceiver::get(),
args: relay_test_args(destination, beneficiary_id, amount_to_send),
args: TestArgs::new_relay(destination, beneficiary_id, amount_to_send),
};

let mut test = RelayToParaTest::new(test_args);
Expand Down Expand Up @@ -319,7 +318,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() {
let test_args = TestContext {
sender: AssetHubWestendSender::get(),
receiver: PenpalBReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_parachain(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = SystemParaToParaTest::new(test_args);
Expand Down Expand Up @@ -363,7 +362,7 @@ fn reserve_transfer_native_asset_from_para_to_system_para() {
let test_args = TestContext {
sender: PenpalBSender::get(),
receiver: AssetHubWestendReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = ParaToSystemParaTest::new(test_args);
Expand Down Expand Up @@ -444,7 +443,7 @@ fn reserve_transfer_assets_from_system_para_to_para() {
let para_test_args = TestContext {
sender: AssetHubWestendSender::get(),
receiver: PenpalBReceiver::get(),
args: para_test_args(
args: TestArgs::new_para(
destination,
beneficiary_id,
asset_amount_to_send,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use crate::*;
use asset_hub_westend_runtime::xcm_config::XcmConfig as AssetHubWestendXcmConfig;
use emulated_integration_tests_common::{para_test_args, relay_test_args};
use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig;

fn relay_origin_assertions(t: RelayToSystemParaTest) {
Expand Down Expand Up @@ -163,7 +162,7 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() {
let test_args = TestContext {
sender: WestendSender::get(),
receiver: beneficiary.clone(),
args: relay_test_args(dest, beneficiary, amount_to_send),
args: TestArgs::new_relay(dest, beneficiary, amount_to_send),
};

let mut test = RelayToSystemParaTest::new(test_args);
Expand Down Expand Up @@ -207,7 +206,7 @@ fn limited_teleport_native_assets_back_from_system_para_to_relay_works() {
let test_args = TestContext {
sender: AssetHubWestendSender::get(),
receiver: WestendReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = SystemParaToRelayTest::new(test_args);
Expand Down Expand Up @@ -248,7 +247,7 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() {
let test_args = TestContext {
sender: AssetHubWestendSender::get(),
receiver: WestendReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = SystemParaToRelayTest::new(test_args);
Expand Down Expand Up @@ -286,7 +285,7 @@ fn teleport_native_assets_from_relay_to_system_para_works() {
let test_args = TestContext {
sender: WestendSender::get(),
receiver: beneficiary.clone(),
args: relay_test_args(dest, beneficiary, amount_to_send),
args: TestArgs::new_relay(dest, beneficiary, amount_to_send),
};

let mut test = RelayToSystemParaTest::new(test_args);
Expand Down Expand Up @@ -330,7 +329,7 @@ fn teleport_native_assets_back_from_system_para_to_relay_works() {
let test_args = TestContext {
sender: AssetHubWestendSender::get(),
receiver: WestendReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = SystemParaToRelayTest::new(test_args);
Expand Down Expand Up @@ -371,7 +370,7 @@ fn teleport_native_assets_from_system_para_to_relay_fails() {
let test_args = TestContext {
sender: AssetHubWestendSender::get(),
receiver: WestendReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = SystemParaToRelayTest::new(test_args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ impl IdentityOn<'_> {
///
/// `account_from_u32(5)` will return an `AccountId32` with the bytes
/// `[0, 5, 0, 0, 0, 0, 0, 0, 0, 5 ... ]`
///
/// **Note**
///
/// This is only used for testing and is not intended for production use.
fn account_from_u32(id: u32) -> AccountId32 {
let mut buffer = [255u8; 32];
let id_bytes = id.to_le_bytes();
Expand Down Expand Up @@ -198,9 +194,9 @@ fn set_id_relay(id: &Identity) -> Balance {
Subs::Zero => {},
0xmovses marked this conversation as resolved.
Show resolved Hide resolved
Subs::Many(n) => {
let mut subs = Vec::with_capacity(n.try_into().unwrap());
for ii in 0..n {
for i in 0..n {
subs.push((
account_from_u32(ii),
AccountId32::from(i),
Data::Raw(b"name".to_vec().try_into().unwrap()),
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// limitations under the License.

use crate::*;
use emulated_integration_tests_common::{para_test_args, relay_test_args};
use people_rococo_runtime::xcm_config::XcmConfig as PeopleRococoXcmConfig;
use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig;

Expand Down Expand Up @@ -142,7 +141,7 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() {
let test_args = TestContext {
sender: RococoSender::get(),
receiver: PeopleRococoReceiver::get(),
args: relay_test_args(dest, beneficiary_id, amount_to_send),
args: TestArgs::new_relay(dest, beneficiary_id, amount_to_send),
};

let mut test = RelayToSystemParaTest::new(test_args);
Expand Down Expand Up @@ -188,7 +187,7 @@ fn limited_teleport_native_assets_back_from_system_para_to_relay_works() {
let test_args = TestContext {
sender: PeopleRococoSender::get(),
receiver: RococoReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = SystemParaToRelayTest::new(test_args);
Expand Down Expand Up @@ -232,7 +231,7 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() {
let test_args = TestContext {
sender: PeopleRococoSender::get(),
receiver: RococoReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = SystemParaToRelayTest::new(test_args);
Expand Down
6 changes: 5 additions & 1 deletion cumulus/xcm/xcm-emulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,7 @@ pub struct TestArgs {
}

impl TestArgs {
/// Returns a [`TestArgs`] instance to be used for the Relay Chain across integration tests
joepetrowski marked this conversation as resolved.
Show resolved Hide resolved
pub fn new_relay(dest: MultiLocation, beneficiary_id: AccountId32, amount: Balance) -> Self {
Self {
dest,
Expand All @@ -1448,11 +1449,14 @@ impl TestArgs {
}
}

pub fn new_parachain(
/// Returns a [`TestArgs`] instance to be used by parachains across integration tests
joepetrowski marked this conversation as resolved.
Show resolved Hide resolved
pub fn new_para(
dest: MultiLocation,
beneficiary_id: AccountId32,
amount: Balance,
assets: MultiAssets,
asset_id: Option<u32>,
fee_asset_item: u32,
) -> Self {
Self {
dest,
Expand Down
22 changes: 22 additions & 0 deletions substrate/primitives/core/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,28 @@ impl From<[u8; 32]> for AccountId32 {
}
}

/// Generate an `AccountId32` from a `u32`.
/// This creates a 32-byte array, initially filled with `255`, and then repeatedly fills it
/// with the 4-byte little-endian representation of the `u32` value, until the array is full.
///
/// **Example**:
///
/// `account_from_u32(5)` will return an `AccountId32` with the bytes
/// `[0, 5, 0, 0, 0, 0, 0, 0, 0, 5 ... ]`
impl From<u32> for AccountId32 {
fn from(id: u32) -> Self {
let mut buffer = [255u8; 32];
let id_bytes = id.to_le_bytes();
let id_size = id_bytes.len();
for i in 0..buffer.len() / id_size {
let start = i * id_size;
let end = start + id_size;
buffer[start..end].clone_from_slice(&id_bytes[..]);
}
Self::new(buffer)
}
}

impl<'a> TryFrom<&'a [u8]> for AccountId32 {
type Error = ();
fn try_from(x: &'a [u8]) -> Result<AccountId32, ()> {
Expand Down