This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
XCM docs and tests #2948
Merged
Merged
XCM docs and tests #2948
Changes from 15 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
03d1470
WIP
kianenigma 96d021d
Merge branch 'master' of github.com:paritytech/polkadot into kiz-alex…
kianenigma 59de11d
add tests and docs for DoubleEncoded
apopiak 71c9b5b
reformat parent_count
apopiak bbec29d
add test for match_and_split
apopiak b96f898
fix append_with docs and add tests
apopiak 1b3bcc5
move Parachain enum variant to tuple
apopiak 5b59ee6
Fix stuff
kianenigma bda5c91
Merge branch 'kiz-alex-test-xcm' of github.com:paritytech/polkadot in…
kianenigma 928c20d
add to append test
apopiak 1c3b644
simplify match
kianenigma 3490809
Merge branch 'kiz-alex-test-xcm' of github.com:paritytech/polkadot in…
kianenigma f74a298
formatting
apopiak c951986
format and extend doc comments (including examples)
apopiak 253f6ee
Merge branch 'kiz-alex-test-xcm' of github.com:paritytech/polkadot in…
apopiak b128b22
fix typo
apopiak 2700952
add some doc comments
apopiak e7bf1c2
Merge branch 'kiz-alex-test-xcm' of github.com:paritytech/polkadot in…
apopiak a0c2c99
add test for location inverter
apopiak 169fdba
Add more tests/docs
kianenigma b5b3e70
Merge branch 'kiz-alex-test-xcm' of github.com:paritytech/polkadot in…
kianenigma 058648b
Fix build
kianenigma d1918b6
matches fungibles
kianenigma df78d38
currency adapter.
kianenigma c5198c9
add more tests for location inverter
apopiak 0118bc3
Merge branch 'kiz-alex-test-xcm' of github.com:paritytech/polkadot in…
apopiak 4645f31
extract max length magic number into constant
apopiak 7790e5d
adapters.
kianenigma 20fe978
Merge branch 'kiz-alex-test-xcm' of github.com:paritytech/polkadot in…
kianenigma 4590856
Master.into()
kianenigma b98a29c
Apply suggestions from code review
kianenigma 1a3d428
Master.into()
kianenigma dd2e85c
Merge branch 'master' of github.com:paritytech/polkadot into kiz-alex…
kianenigma 192c2f5
Final touches.
kianenigma 692baf4
Merge branch 'master' of github.com:paritytech/polkadot into kiz-alex…
kianenigma ac47999
Repot and fixes
kianenigma 09f9118
Remove last todo
kianenigma 37921ed
Apply suggestions from code review
kianenigma d12b36f
Update xcm/xcm-builder/src/barriers.rs
kianenigma db134b8
Update xcm/xcm-builder/src/barriers.rs
kianenigma e5a1b67
Update xcm/xcm-builder/src/currency_adapter.rs
kianenigma f4bf121
Update xcm/xcm-builder/src/filter_asset_location.rs
kianenigma a7af09b
Update xcm/xcm-builder/src/matches_fungible.rs
kianenigma 91ecc09
Update xcm/xcm-executor/src/traits/conversion.rs
kianenigma 291ab3b
Update xcm/xcm-executor/src/traits/conversion.rs
kianenigma 73cba92
Update xcm/xcm-executor/src/traits/transact_asset.rs
kianenigma c57e637
Update xcm/xcm-executor/src/traits/should_execute.rs
kianenigma 55473a3
Master.into()
kianenigma 8aa0aa0
Merge branch 'kiz-alex-test-xcm' of github.com:paritytech/polkadot in…
kianenigma a52ac13
Merge branch 'master' into kiz-alex-test-xcm
shawntabrizi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,35 +61,34 @@ pub enum AssetInstance { | |
/// ### Abstract identifiers | ||
/// | ||
/// Abstract identifiers are absolute identifiers that represent a notional asset which can exist within multiple | ||
/// consensus systems. These tend to be simpler to deal with since their broad meaning is unchanged regardless stay | ||
/// of the consensus system in which it is interpreted. | ||
/// consensus systems. These tend to be simpler to deal with since their broad meaning is unchanged regardless stay of | ||
/// the consensus system in which it is interpreted. | ||
/// | ||
/// However, in the attempt to provide uniformity across consensus systems, they may conflate different instantiations | ||
/// of some notional asset (e.g. the reserve asset and a local reserve-backed derivative of it) under the same name, | ||
/// leading to confusion. It also implies that one notional asset is accounted for locally in only one way. This may | ||
/// not be the case, e.g. where there are multiple bridge instances each providing a bridged "BTC" token yet none | ||
/// being fungible between the others. | ||
/// leading to confusion. It also implies that one notional asset is accounted for locally in only one way. This may not | ||
/// be the case, e.g. where there are multiple bridge instances each providing a bridged "BTC" token yet none being | ||
/// fungible between the others. | ||
/// | ||
/// Since they are meant to be absolute and universal, a global registry is needed to ensure that name collisions | ||
/// do not occur. | ||
/// Since they are meant to be absolute and universal, a global registry is needed to ensure that name collisions do not | ||
/// occur. | ||
/// | ||
/// An abstract identifier is represented as a simple variable-size byte string. As of writing, no global registry | ||
/// exists and no proposals have been put forth for asset labeling. | ||
/// | ||
/// ### Concrete identifiers | ||
/// | ||
/// Concrete identifiers are *relative identifiers* that specifically identify a single asset through its location in | ||
/// a consensus system relative to the context interpreting. Use of a `MultiLocation` ensures that similar but non | ||
/// fungible variants of the same underlying asset can be properly distinguished, and obviates the need for any kind | ||
/// of central registry. | ||
/// Concrete identifiers are *relative identifiers* that specifically identify a single asset through its location in a | ||
/// consensus system relative to the context interpreting. Use of a `MultiLocation` ensures that similar but non | ||
/// fungible variants of the same underlying asset can be properly distinguished, and obviates the need for any kind of | ||
/// central registry. | ||
/// | ||
/// The limitation is that the asset identifier cannot be trivially copied between consensus | ||
/// systems and must instead be "re-anchored" whenever being moved to a new consensus system, using the two systems' | ||
/// relative paths. | ||
/// The limitation is that the asset identifier cannot be trivially copied between consensus systems and must instead be | ||
/// "re-anchored" whenever being moved to a new consensus system, using the two systems' relative paths. | ||
/// | ||
/// Throughout XCM, messages are authored such that *when interpreted from the receiver's point of view* they will | ||
/// have the desired meaning/effect. This means that relative paths should always by constructed to be read from the | ||
/// point of view of the receiving system, *which may be have a completely different meaning in the authoring system*. | ||
/// Throughout XCM, messages are authored such that *when interpreted from the receiver's point of view* they will have | ||
/// the desired meaning/effect. This means that relative paths should always by constructed to be read from the point of | ||
/// view of the receiving system, *which may be have a completely different meaning in the authoring system*. | ||
/// | ||
/// Concrete identifiers are the preferred way of identifying an asset since they are entirely unambiguous. | ||
/// | ||
|
@@ -99,8 +98,8 @@ pub enum AssetInstance { | |
/// | ||
/// - `<chain>/PalletInstance(<id>)` for a Frame chain with a single-asset pallet instance (such as an instance of the | ||
/// Balances pallet). | ||
/// - `<chain>/PalletInstance(<id>)/GeneralIndex(<index>)` for a Frame chain with an indexed multi-asset pallet | ||
/// instance (such as an instance of the Assets pallet). | ||
/// - `<chain>/PalletInstance(<id>)/GeneralIndex(<index>)` for a Frame chain with an indexed multi-asset pallet instance | ||
/// (such as an instance of the Assets pallet). | ||
/// - `<chain>/AccountId32` for an ERC-20-style single-asset smart-contract on a Frame-based contracts chain. | ||
/// - `<chain>/AccountKey20` for an ERC-20-style single-asset smart-contract on an Ethereum-like chain. | ||
/// | ||
|
@@ -147,6 +146,9 @@ pub enum MultiAsset { | |
} | ||
|
||
impl MultiAsset { | ||
/// Returns `true` if the `MultiAsset` is a wildcard and can refer to classes of assets, instead of just one. | ||
/// | ||
/// Typically can also be inferred by the name staring with `All`. | ||
apopiak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub fn is_wildcard(&self) -> bool { | ||
match self { | ||
MultiAsset::None | ||
|
@@ -178,6 +180,7 @@ impl MultiAsset { | |
} | ||
} | ||
|
||
// TODO: `All` is both fungible and non-fungible, and I think it should be none. | ||
kianenigma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fn is_fungible(&self) -> bool { | ||
match self { | ||
MultiAsset::All | ||
|
@@ -209,7 +212,6 @@ impl MultiAsset { | |
fn is_concrete_fungible(&self, id: &MultiLocation) -> bool { | ||
match self { | ||
MultiAsset::AllFungible => true, | ||
|
||
MultiAsset::AllConcreteFungible { id: i } | ||
| MultiAsset::ConcreteFungible { id: i, .. } | ||
=> i == id, | ||
|
@@ -250,8 +252,13 @@ impl MultiAsset { | |
|
||
fn is_all(&self) -> bool { matches!(self, MultiAsset::All) } | ||
|
||
/// Returns true if `self` is a super-set of the given `inner`. | ||
/// | ||
/// Typically, any wildcard is never contained in anything else, and a wildcard can contain any other non-wildcard. | ||
/// For more details, see the implementation and tests. | ||
pub fn contains(&self, inner: &MultiAsset) -> bool { | ||
use MultiAsset::*; | ||
|
||
// Inner cannot be wild | ||
if inner.is_wildcard() { return false } | ||
// Everything contains nothing. | ||
|
@@ -273,15 +280,14 @@ impl MultiAsset { | |
AllConcreteNonFungible { class } => inner.is_concrete_non_fungible(class), | ||
AllAbstractNonFungible { class } => inner.is_abstract_non_fungible(class), | ||
|
||
// TODO: should it not be `if i == id && amount >= a`? for self to contain `inner`, self should contain | ||
// larger quantities than inner. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gavofyork am I wrong? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're not wrong. i'd hope there's a test which picks that up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there are tests for this now, but I aligned them with the wrong logic. will fix both code and tests. |
||
ConcreteFungible { id, amount } | ||
=> matches!(inner, ConcreteFungible { id: i , amount: a } if i == id && a >= amount), | ||
AbstractFungible { id, amount } | ||
=> matches!(inner, AbstractFungible { id: i , amount: a } if i == id && a >= amount), | ||
ConcreteNonFungible { class, instance } | ||
=> matches!(inner, ConcreteNonFungible { class: i , instance: a } if i == class && a == instance), | ||
AbstractNonFungible { class, instance } | ||
=> matches!(inner, AbstractNonFungible { class: i , instance: a } if i == class && a == instance), | ||
|
||
ConcreteNonFungible { .. } => self == inner, | ||
AbstractNonFungible { .. } => self == inner, | ||
_ => false, | ||
} | ||
} | ||
|
@@ -313,3 +319,60 @@ impl TryFrom<VersionedMultiAsset> for MultiAsset { | |
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn contains_works() { | ||
use alloc::vec; | ||
use MultiAsset::*; | ||
// trivial case: all contains any non-wildcard. | ||
assert!(All.contains(&None)); | ||
assert!(All.contains(&AbstractFungible { id: alloc::vec![99u8], amount: 1 })); | ||
|
||
// trivial case: none contains nothing, except itself. | ||
assert!(None.contains(&None)); | ||
assert!(!None.contains(&AllFungible)); | ||
assert!(!None.contains(&All)); | ||
|
||
// A bit more sneaky: Nothing can contain wildcard, even All ir the thing itself. | ||
assert!(!All.contains(&All)); | ||
assert!(!All.contains(&AllFungible)); | ||
assert!(!AllFungible.contains(&AllFungible)); | ||
assert!(!AllNonFungible.contains(&AllNonFungible)); | ||
|
||
// For fungibles, containing is basically equality, or equal with higher amount. | ||
assert!( | ||
!AbstractFungible { id: vec![99u8], amount: 9 } | ||
.contains(&AbstractFungible { id: vec![98u8], amount: 99 }) | ||
); | ||
assert!( | ||
AbstractFungible { id: vec![99u8], amount: 9 } | ||
.contains(&AbstractFungible { id: vec![99u8], amount: 99 }) | ||
); | ||
assert!( | ||
AbstractFungible { id: vec![99u8], amount: 9 } | ||
.contains(&AbstractFungible { id: vec![99u8], amount: 9 }) | ||
); | ||
assert!( | ||
!AbstractFungible { id: vec![99u8], amount: 9 } | ||
.contains(&AbstractFungible { id: vec![99u8], amount: 1 }) | ||
); | ||
|
||
// For non-fungibles, containing is equality. | ||
assert!( | ||
!AbstractNonFungible {class: vec![99u8], instance: AssetInstance::Index { id: 9 } } | ||
.contains(&AbstractNonFungible { class: vec![98u8], instance: AssetInstance::Index { id: 9 } }) | ||
); | ||
assert!( | ||
!AbstractNonFungible { class: vec![99u8], instance: AssetInstance::Index { id: 8 } } | ||
.contains(&AbstractNonFungible { class: vec![99u8], instance: AssetInstance::Index { id: 9 } }) | ||
); | ||
assert!( | ||
AbstractNonFungible { class: vec![99u8], instance: AssetInstance::Index { id: 9 } } | ||
.contains(&AbstractNonFungible { class: vec![99u8], instance: AssetInstance::Index { id: 9 } }) | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to prevent myself from doing so many of these and reverted most 🙈 but FYI this is only properly rewrapping the doc to 120 chars.