mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 00:37:57 +00:00
Add function for embedding the runtime version in a wasm blob (#9277)
* Add function for embedding the runtime version in a wasm blob This function can be used to add the custom section to a wasm blob with the runtime version in it. * Review nitpick
This commit is contained in:
@@ -46,6 +46,7 @@ substrate-test-runtime = { version = "2.0.0", path = "../../test-utils/runtime"
|
||||
sp-state-machine = { version = "0.9.0", path = "../../primitives/state-machine" }
|
||||
sp-runtime = { version = "3.0.0", path = "../../primitives/runtime" }
|
||||
sp-tracing = { version = "3.0.0", path = "../../primitives/tracing" }
|
||||
sp-maybe-compressed-blob = { version = "3.0.0", path = "../../primitives/maybe-compressed-blob" }
|
||||
sc-tracing = { version = "3.0.0", path = "../tracing" }
|
||||
tracing = "0.1.25"
|
||||
tracing-subscriber = "0.2.18"
|
||||
|
||||
@@ -526,4 +526,35 @@ mod tests {
|
||||
let version = decode_version(&old_runtime_version.encode()).unwrap();
|
||||
assert_eq!(3, version.transaction_version);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn embed_runtime_version_works() {
|
||||
let wasm = sp_maybe_compressed_blob::decompress(
|
||||
substrate_test_runtime::wasm_binary_unwrap(),
|
||||
sp_maybe_compressed_blob::CODE_BLOB_BOMB_LIMIT,
|
||||
).expect("Decompressing works");
|
||||
|
||||
let runtime_version = RuntimeVersion {
|
||||
spec_name: "test_replace".into(),
|
||||
impl_name: "test_replace".into(),
|
||||
authoring_version: 100,
|
||||
spec_version: 100,
|
||||
impl_version: 100,
|
||||
apis: sp_api::create_apis_vec!([(<dyn Core::<Block>>::ID, 3)]),
|
||||
transaction_version: 100,
|
||||
};
|
||||
|
||||
let embedded = sp_version::embed::embed_runtime_version(
|
||||
&wasm,
|
||||
runtime_version.clone(),
|
||||
).expect("Embedding works");
|
||||
|
||||
let blob = RuntimeBlob::new(&embedded).expect("Embedded blob is valid");
|
||||
let read_version = read_embedded_version(&blob)
|
||||
.ok()
|
||||
.flatten()
|
||||
.expect("Reading embedded version works");
|
||||
|
||||
assert_eq!(runtime_version, read_version);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user