Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add starts_with to v0 and v1 MultiLocation #6311

Merged
merged 3 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
add tests
  • Loading branch information
joepetrowski committed Nov 19, 2022
commit 4ce52fe438f94c7d879988e2be1903d649a11c7c
18 changes: 18 additions & 0 deletions xcm/src/v0/multi_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,24 @@ mod tests {
assert_eq!(m.match_and_split(&m), None);
}

#[test]
fn starts_with_works() {
let full = X3(Parent, Parachain(1000), AccountIndex64 { network: Any, index: 23 });
let identity = full.clone();
let prefix = X2(Parent, Parachain(1000));
let wrong_parachain = X2(Parent, Parachain(1001));
let wrong_account = X3(Parent, Parachain(1000), AccountIndex64 { network: Any, index: 24 });
let no_parents = X1(Parachain(1000));
let too_many_parents = X3(Parent, Parent, Parachain(1000));

assert!(full.starts_with(&identity));
assert!(full.starts_with(&prefix));
assert!(!full.starts_with(&wrong_parachain));
assert!(!full.starts_with(&wrong_account));
assert!(!full.starts_with(&no_parents));
assert!(!full.starts_with(&too_many_parents));
}

#[test]
fn append_with_works() {
let acc = AccountIndex64 { network: Any, index: 23 };
Expand Down
18 changes: 18 additions & 0 deletions xcm/src/v1/multilocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,24 @@ mod tests {
assert_eq!(m.match_and_split(&m), None);
}

#[test]
fn starts_with_works() {
let full: MultiLocation = (Parent, Parachain(1000), AccountId32 { network: Any, id: [0; 32] }).into();
let identity: MultiLocation = full.clone();
let prefix: MultiLocation = (Parent, Parachain(1000)).into();
let wrong_parachain: MultiLocation = (Parent, Parachain(1001)).into();
let wrong_account: MultiLocation = (Parent, Parachain(1000), AccountId32 { network: Any, id: [1; 32] }).into();
let no_parents: MultiLocation = (Parachain(1000)).into();
let too_many_parents: MultiLocation = (Parent, Parent, Parachain(1000)).into();

assert!(full.starts_with(&identity));
assert!(full.starts_with(&prefix));
assert!(!full.starts_with(&wrong_parachain));
assert!(!full.starts_with(&wrong_account));
assert!(!full.starts_with(&no_parents));
assert!(!full.starts_with(&too_many_parents));
}

#[test]
fn append_with_works() {
let acc = AccountIndex64 { network: Any, index: 23 };
Expand Down