Skip to content

Inconsistency in XCM Versioned* try_as implementation #8185

@bkontur

Description

@bkontur

A conversion with TryInto works between different VersionedLocation version and xcm::v*::Location, but TryAs works only with the same version.

Other words, I can try_into convert VersionedLocation::V4 to v4::Location or v3::Location or v5::Location, but I can try_as convert VersionedLocation::V4 only to v4::Location and nothing else.

Solution

Behavior should be aligned or we just remove TryAs.

Demo

#[test]
fn test_try_as() {
	let versioned_location_v4 = VersionedLocation::V4(v4::Location::parent());

	// TryInto:
	// Works
	assert!(TryInto::<v4::Location>::try_into(versioned_location_v4.clone()).is_ok());
	assert!(TryInto::<v3::Location>::try_into(versioned_location_v4.clone()).is_ok());
	assert!(TryInto::<v5::Location>::try_into(versioned_location_v4.clone()).is_ok());

	// TryAs:
	// Works
	assert!(versioned_location_v4.try_as::<v4::Location>().is_ok());
	// Fails - should work also!!!
	assert!(versioned_location_v4.try_as::<v3::Location>().is_err());
	assert!(versioned_location_v4.try_as::<v5::Location>().is_err());
}

Metadata

Metadata

Labels

T6-XCMThis PR/Issue is related to XCM.

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions