From 84f326092afa341fd1828b6e3aec4c54a7c25351 Mon Sep 17 00:00:00 2001 From: Chevdor Date: Mon, 30 May 2022 12:06:37 +0200 Subject: [PATCH] Allow user overriding the Parachain Pallet Id fix #45 --- README.md | 16 ++++++----- README_src.adoc | 2 ++ .../Cargo.toml | 2 +- .../src/lib.rs | 28 +++++++++++++++++-- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a322835..e747698 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ MacOS Homebrew users can use: ### Command: --help - subwasm 0.17.0 + subwasm 0.17.1 chevdor :Wilfried Kopp :Wilfried Kopp :Wilfried Kopp :Wilfried Kopp :Wilfried Kopp :Wilfried Kopp :Wilfried Kopp CalllHash { } pub fn get_parachainsystem_authorize_upgrade(wasm_blob: &[u8]) -> CalllHash { + let s = env::var(PARACHAIN_PALLET_ID_ENV).unwrap_or_else(|_| String::from("0x01")).replace("0x", ""); + let decoded = <[u8; 1]>::from_hex(s).expect("Decoding failed"); + let parachain_pallet_id = *decoded.first().expect("Failure while fecthing the Parachain Pallet ID"); + let prefix_parachainsystem_authorize_upgrade: Prefix = (parachain_pallet_id, 0x03); let code_hash = BlakeTwo256::hash(wasm_blob); - get_call_hash(PREFIX_PARACHAINSYSTEM_AUTHORIZE_UPGRADE, code_hash.as_bytes()) + get_call_hash(prefix_parachainsystem_authorize_upgrade, code_hash.as_bytes()) } fn get_call_hash(prefix: Prefix, wasm_blob: &[u8]) -> CalllHash { @@ -72,8 +78,9 @@ fn get_call_hash(prefix: Prefix, wasm_blob: &[u8]) -> CalllHash { } #[cfg(test)] -mod tests { +mod prop_hash_tests { use super::*; + use std::env; #[test] fn test_proposal_hash() { @@ -99,6 +106,7 @@ mod tests { #[test] fn test_parachain_upgrade() { + env::set_var(PARACHAIN_PALLET_ID_ENV, "0x01"); assert_eq!( get_parachainsystem_authorize_upgrade(&[ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x97, 0x03, 0x39, 0x60, 0x03, 0x7f, 0x7f @@ -110,6 +118,20 @@ mod tests { ); } + #[test] + fn test_custom_parachain_upgrade() { + env::set_var(PARACHAIN_PALLET_ID_ENV, "0x32"); + assert_eq!( + get_parachainsystem_authorize_upgrade(&[ + 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x97, 0x03, 0x39, 0x60, 0x03, 0x7f, 0x7f + ]), + [ + 29, 53, 127, 234, 110, 75, 67, 238, 243, 171, 65, 93, 187, 246, 0, 84, 166, 88, 161, 205, 95, 62, 135, + 99, 121, 139, 154, 39, 207, 121, 98, 87 + ] + ); + } + #[test] fn test_hash_length() { assert_eq!(32, get_proposal_hash(&[0]).len());