diff --git a/src/functions.rs b/src/functions.rs index 364a3e7..a0e641a 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -10,6 +10,6 @@ pub(crate) fn get_proposal_bytes(proposal: String) -> Vec { } else { // This is a file path let contents = fs::read_to_string(proposal).expect("Should give a valid file path"); - hex::decode(contents.as_str().trim_start_matches("0x").trim()).expect("Valid proposal") + hex::decode(contents.as_str().trim().trim_start_matches("0x")).expect("Valid proposal") } } diff --git a/src/tests.rs b/src/tests.rs index 27c25a3..d55e1f5 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -158,6 +158,7 @@ fn upgrade_args_for_only_relay() -> UpgradeArgs { coretime: None, filename: None, additional: None, + no_runtime_checks: false, } } @@ -175,6 +176,7 @@ fn upgrade_args_for_only_asset_hub() -> UpgradeArgs { coretime: None, filename: None, additional: None, + no_runtime_checks: false, } } @@ -192,6 +194,7 @@ fn upgrade_args_for_all() -> UpgradeArgs { coretime: None, filename: None, additional: None, + no_runtime_checks: false, } } @@ -210,6 +213,7 @@ fn upgrade_args_with_additional() -> UpgradeArgs { filename: None, // `system.remark("test")` on Polkadot Asset Hub additional: Some(String::from("0x00001074657374")), + no_runtime_checks: false, } } @@ -242,6 +246,18 @@ fn call_info_from_bytes_works() { assert_eq!(proposal_call_info.hash, &bad_verification[..]); } +#[test] +fn get_proposal_bytes_trims_file_contents() { + let path = std::env::temp_dir() + .join(format!("opengov-cli-proposal-{}-trim-test.call", std::process::id())); + std::fs::write(&path, "\n 0x00001074657374\n").expect("write proposal file"); + + let proposal_bytes = get_proposal_bytes(path.to_string_lossy().into_owned()); + std::fs::remove_file(&path).ok(); + + assert_eq!(proposal_bytes, hex::decode("00001074657374").expect("hex")); +} + #[test] fn call_info_from_runtime_call_works() { let remark_to_verify = PolkadotRuntimeCall::System(PolkadotRelaySystemCall::remark {