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

fix: parse keys with 0x prefix #322

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions toolkit/cli/smart-contracts-commands/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ tokio = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
cardano-serialization-lib = { workspace = true }

[dev-dependencies]
hex-literal = { workspace = true }
36 changes: 36 additions & 0 deletions toolkit/cli/smart-contracts-commands/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub(crate) fn read_private_key_from_file(path: &str) -> CmdResult<MainchainPriva
pub(crate) fn parse_partnerchain_public_keys(
partner_chain_public_keys: &str,
) -> CmdResult<PermissionedCandidateData> {
let partner_chain_public_keys = partner_chain_public_keys.replace("0x", "");
if let [sidechain_pub_key, aura_pub_key, grandpa_pub_key] =
partner_chain_public_keys.split(":").collect::<Vec<_>>()[..]
{
Expand All @@ -86,3 +87,38 @@ fn payment_signing_key_to_mainchain_address_hash(
.try_into()
.map(MainchainAddressHash)?)
}

#[cfg(test)]
mod test {
use crate::parse_partnerchain_public_keys;
use hex_literal::hex;
use sidechain_domain::{
AuraPublicKey, GrandpaPublicKey, PermissionedCandidateData, SidechainPublicKey,
};

#[test]
fn parse_partnerchain_public_keys_with_0x_prefix() {
let input = "039799ff93d184146deacaa455dade51b13ed16f23cdad11d1ad6af20103391180:e85534c93315d60f808568d1dce5cb9e8ba6ed0b204209c5cc8f3bec56c10b73:cdf3e5b33f53c8b541bbaea383225c45654f24de38c585725f3cff25b2802f55";
assert_eq!(parse_partnerchain_public_keys(input).unwrap(), expected_public_keys())
}

#[test]
fn parse_partnerchain_public_keys_without_0x_prefix() {
let input = "0x039799ff93d184146deacaa455dade51b13ed16f23cdad11d1ad6af20103391180:0xe85534c93315d60f808568d1dce5cb9e8ba6ed0b204209c5cc8f3bec56c10b73:0xcdf3e5b33f53c8b541bbaea383225c45654f24de38c585725f3cff25b2802f55";
assert_eq!(parse_partnerchain_public_keys(input).unwrap(), expected_public_keys())
}

fn expected_public_keys() -> PermissionedCandidateData {
PermissionedCandidateData {
sidechain_public_key: SidechainPublicKey(
hex!("039799ff93d184146deacaa455dade51b13ed16f23cdad11d1ad6af20103391180").to_vec(),
),
aura_public_key: AuraPublicKey(
hex!("e85534c93315d60f808568d1dce5cb9e8ba6ed0b204209c5cc8f3bec56c10b73").to_vec(),
),
grandpa_public_key: GrandpaPublicKey(
hex!("cdf3e5b33f53c8b541bbaea383225c45654f24de38c585725f3cff25b2802f55").to_vec(),
),
}
}
}
Loading