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

Location conversion tests for relay and parachains #487

Merged
merged 18 commits into from
Nov 28, 2024

Conversation

x3c41a
Copy link
Contributor

@x3c41a x3c41a commented Oct 17, 2024

Added location convertion tests.
Polkadot sdk PR
Fixes #488

@x3c41a x3c41a marked this pull request as draft October 17, 2024 17:03
@x3c41a x3c41a marked this pull request as ready for review October 17, 2024 20:36
@x3c41a x3c41a marked this pull request as draft October 17, 2024 20:36
@x3c41a x3c41a changed the title Loc conv test Location conversion tests for relay and parachains Oct 18, 2024
@x3c41a x3c41a marked this pull request as ready for review October 18, 2024 09:47
Copy link
Contributor

@acatangiu acatangiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversions are the same for all system parachains, so this test could be a macro to dedup the code, but I don't know where we would put that macro or if it's worth the effort. I'm fine with the duplicated code too.

Please see the other comments.

Comment on lines 35 to 118
// DescribeTerminus
TestCase {
description: "DescribeTerminus Parent",
location: Location::new(1, Here),
expected_account_id_str: "5GyWtDJP7qaipWRGr4KJ6VUDxRXf4jDnPW6KPTeCekHfqZkD",
},
TestCase {
description: "DescribeTerminus Sibling",
location: Location::new(1, [Parachain(1111)]),
expected_account_id_str: "5EC5GfEFm9XEBYjXzxb1VseMHsG2VhPeGTGWF9H8tYZnGsSk",
},
// DescribePalletTerminal
TestCase {
description: "DescribePalletTerminal Parent",
location: Location::new(1, [PalletInstance(50)]),
expected_account_id_str: "5CnwemvaAXkWFVwibiCvf2EjqwiqBi29S5cLLydZLEaEw6jZ",
},
TestCase {
description: "DescribePalletTerminal Sibling",
location: Location::new(1, [Parachain(1111), PalletInstance(50)]),
expected_account_id_str: "5GFBgPjpEQPdaxEnFirUoa51u5erVx84twYxJVuBRAT2UP2g",
},
// DescribeAccountId32Terminal
TestCase {
description: "DescribeAccountId32Terminal Parent",
location: Location::new(
1,
[AccountId32 { network: None, id: AccountId::from(ALICE).into() }],
),
expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4",
},
TestCase {
description: "DescribeAccountId32Terminal Sibling",
location: Location::new(
1,
[
Parachain(1111),
Junction::AccountId32 { network: None, id: AccountId::from(ALICE).into() },
],
),
expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg",
},
// DescribeAccountKey20Terminal
TestCase {
description: "DescribeAccountKey20Terminal Parent",
location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]),
expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg",
},
TestCase {
description: "DescribeAccountKey20Terminal Sibling",
location: Location::new(
1,
[Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }],
),
expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg",
},
// DescribeTreasuryVoiceTerminal
TestCase {
description: "DescribeTreasuryVoiceTerminal Parent",
location: Location::new(1, [Plurality { id: BodyId::Treasury, part: BodyPart::Voice }]),
expected_account_id_str: "5CUjnE2vgcUCuhxPwFoQ5r7p1DkhujgvMNDHaF2bLqRp4D5F",
},
TestCase {
description: "DescribeTreasuryVoiceTerminal Sibling",
location: Location::new(
1,
[Parachain(1111), Plurality { id: BodyId::Treasury, part: BodyPart::Voice }],
),
expected_account_id_str: "5G6TDwaVgbWmhqRUKjBhRRnH4ry9L9cjRymUEmiRsLbSE4gB",
},
// DescribeBodyTerminal
TestCase {
description: "DescribeBodyTerminal Parent",
location: Location::new(1, [Plurality { id: BodyId::Unit, part: BodyPart::Voice }]),
expected_account_id_str: "5EBRMTBkDisEXsaN283SRbzx9Xf2PXwUxxFCJohSGo4jYe6B",
},
TestCase {
description: "DescribeBodyTerminal Sibling",
location: Location::new(
1,
[Parachain(1111), Plurality { id: BodyId::Unit, part: BodyPart::Voice }],
),
expected_account_id_str: "5DBoExvojy8tYnHgLL97phNH975CyT45PWTZEeGoBZfAyRMH",
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parent and Sibling (parachain) locations do not make sense for a Relay chain.

All of these should be replaced with Child (parachain) locations.
(DescribeTerminus Child, DescribePalletTerminal Child, etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 35 to 118
// DescribeTerminus
TestCase {
description: "DescribeTerminus Parent",
location: Location::new(1, Here),
expected_account_id_str: "5GyWtDJP7qaipWRGr4KJ6VUDxRXf4jDnPW6KPTeCekHfqZkD",
},
TestCase {
description: "DescribeTerminus Sibling",
location: Location::new(1, [Parachain(1111)]),
expected_account_id_str: "5EC5GfEFm9XEBYjXzxb1VseMHsG2VhPeGTGWF9H8tYZnGsSk",
},
// DescribePalletTerminal
TestCase {
description: "DescribePalletTerminal Parent",
location: Location::new(1, [PalletInstance(50)]),
expected_account_id_str: "5CnwemvaAXkWFVwibiCvf2EjqwiqBi29S5cLLydZLEaEw6jZ",
},
TestCase {
description: "DescribePalletTerminal Sibling",
location: Location::new(1, [Parachain(1111), PalletInstance(50)]),
expected_account_id_str: "5GFBgPjpEQPdaxEnFirUoa51u5erVx84twYxJVuBRAT2UP2g",
},
// DescribeAccountId32Terminal
TestCase {
description: "DescribeAccountId32Terminal Parent",
location: Location::new(
1,
[AccountId32 { network: None, id: AccountId::from(ALICE).into() }],
),
expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4",
},
TestCase {
description: "DescribeAccountId32Terminal Sibling",
location: Location::new(
1,
[
Parachain(1111),
Junction::AccountId32 { network: None, id: AccountId::from(ALICE).into() },
],
),
expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg",
},
// DescribeAccountKey20Terminal
TestCase {
description: "DescribeAccountKey20Terminal Parent",
location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]),
expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg",
},
TestCase {
description: "DescribeAccountKey20Terminal Sibling",
location: Location::new(
1,
[Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }],
),
expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg",
},
// DescribeTreasuryVoiceTerminal
TestCase {
description: "DescribeTreasuryVoiceTerminal Parent",
location: Location::new(1, [Plurality { id: BodyId::Treasury, part: BodyPart::Voice }]),
expected_account_id_str: "5CUjnE2vgcUCuhxPwFoQ5r7p1DkhujgvMNDHaF2bLqRp4D5F",
},
TestCase {
description: "DescribeTreasuryVoiceTerminal Sibling",
location: Location::new(
1,
[Parachain(1111), Plurality { id: BodyId::Treasury, part: BodyPart::Voice }],
),
expected_account_id_str: "5G6TDwaVgbWmhqRUKjBhRRnH4ry9L9cjRymUEmiRsLbSE4gB",
},
// DescribeBodyTerminal
TestCase {
description: "DescribeBodyTerminal Parent",
location: Location::new(1, [Plurality { id: BodyId::Unit, part: BodyPart::Voice }]),
expected_account_id_str: "5EBRMTBkDisEXsaN283SRbzx9Xf2PXwUxxFCJohSGo4jYe6B",
},
TestCase {
description: "DescribeBodyTerminal Sibling",
location: Location::new(
1,
[Parachain(1111), Plurality { id: BodyId::Unit, part: BodyPart::Voice }],
),
expected_account_id_str: "5DBoExvojy8tYnHgLL97phNH975CyT45PWTZEeGoBZfAyRMH",
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parent and Sibling (parachain) locations do not make sense for a Relay chain.

All of these should be replaced with Child (parachain) locations.
(DescribeTerminus Child, DescribePalletTerminal Child, etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// DescribeAccountKey20Terminal
TestCase {
description: "DescribeAccountKey20Terminal Parent",
location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for these AccountKey20s:

Suggested change
location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]),
location: Location::new(1, [bob_20.clone()]),

with

let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }

(notice I also suggested using non-zero keys)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☑️
Out of curiosity, what edge-case you want to avoid by eliminating zero keys?

@x3c41a
Copy link
Contributor Author

x3c41a commented Oct 23, 2024

bot fmt

@x3c41a
Copy link
Contributor Author

x3c41a commented Oct 23, 2024

The conversions are the same for all system parachains, so this test could be a macro to dedup the code, but I don't know where we would put that macro or if it's worth the effort. I'm fine with the duplicated code too.

Please see the other comments.

I don't feel like writing macros just yet, still want to get used to Rust.

@x3c41a x3c41a requested a review from acatangiu October 23, 2024 11:11
@x3c41a x3c41a marked this pull request as draft October 23, 2024 11:37
@x3c41a x3c41a marked this pull request as ready for review October 23, 2024 15:06
Copy link

Review required! Latest push from author must always be reviewed

CHANGELOG.md Outdated Show resolved Hide resolved
expected_account_id_str: &'static str,
}

let test_cases = vec![
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the test-cases not defined in a shared crate? They seem to be copy&pasted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a subtle difference among these tests -- DescribeAccountId32Terminal is different in many of the cases.

If I were to refactor the tests I'd rather rewrite those into macros, as Adrian suggested a few comments before. I'll leave it as a follow-up for myself once I fully onboard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you're talking about people folder specifically, though I would not do it for a single folder...

@x3c41a x3c41a requested a review from ggwpez November 25, 2024 15:25
@ggwpez
Copy link
Member

ggwpez commented Nov 28, 2024

/merge

@fellowship-merge-bot fellowship-merge-bot bot enabled auto-merge (squash) November 28, 2024 13:37
@fellowship-merge-bot
Copy link
Contributor

Enabled auto-merge in Pull Request

Available commands
  • /merge: Enables auto-merge for Pull Request
  • /merge cancel: Cancels auto-merge for Pull Request
  • /merge help: Shows this menu

For more information see the documentation

@fellowship-merge-bot fellowship-merge-bot bot merged commit db4bb53 into polkadot-fellows:main Nov 28, 2024
49 of 50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate foreign locations to local accounts converter when upgrading polkadot-sdk to a newer version
5 participants