Skip to content

Commit

Permalink
fix: allow keys with 0x prefix in register command
Browse files Browse the repository at this point in the history
  • Loading branch information
LGLO authored Dec 11, 2024
1 parent aacddc0 commit 923c9ac
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
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(),
),
}
}
}

0 comments on commit 923c9ac

Please sign in to comment.