diff --git a/Cargo.lock b/Cargo.lock index 1cf7244ab..899d3b64f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6725,6 +6725,7 @@ dependencies = [ "clap", "env_logger 0.11.3", "hex", + "hex-literal", "jsonrpsee", "partner-chains-cardano-offchain", "serde", diff --git a/toolkit/cli/smart-contracts-commands/Cargo.toml b/toolkit/cli/smart-contracts-commands/Cargo.toml index 314e1b439..ad7054e44 100644 --- a/toolkit/cli/smart-contracts-commands/Cargo.toml +++ b/toolkit/cli/smart-contracts-commands/Cargo.toml @@ -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 } diff --git a/toolkit/cli/smart-contracts-commands/src/lib.rs b/toolkit/cli/smart-contracts-commands/src/lib.rs index 0cd28074b..94d25d745 100644 --- a/toolkit/cli/smart-contracts-commands/src/lib.rs +++ b/toolkit/cli/smart-contracts-commands/src/lib.rs @@ -62,6 +62,7 @@ pub(crate) fn read_private_key_from_file(path: &str) -> CmdResult CmdResult { + 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::>()[..] { @@ -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(), + ), + } + } +}