From c129ab4cb300564ef920016fe3f4906de9b09b75 Mon Sep 17 00:00:00 2001 From: parazyd Date: Tue, 30 May 2023 11:38:18 +0200 Subject: [PATCH] runtime: Add sanity_check function for checking WASM bincode. --- src/runtime/vm_runtime.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/runtime/vm_runtime.rs b/src/runtime/vm_runtime.rs index cde42af5d..83e4412c1 100644 --- a/src/runtime/vm_runtime.rs +++ b/src/runtime/vm_runtime.rs @@ -61,7 +61,7 @@ pub enum ContractSection { } impl ContractSection { - pub fn name(&self) -> &str { + pub const fn name(&self) -> &str { match self { Self::Deploy => "__initialize", Self::Exec => "__entrypoint", @@ -299,6 +299,19 @@ impl Runtime { Ok(Self { instance, store, ctx }) } + /// Perform a sanity check of the WASM bincode + pub fn sanity_check(&self) -> Result<()> { + debug!(target: "runtime::vm_runtime", "Performing sanity check on wasm bincode"); + + // Check that we have all the necessary symbols; + let _ = self.instance.exports.get_function(ContractSection::Deploy.name())?; + let _ = self.instance.exports.get_function(ContractSection::Exec.name())?; + let _ = self.instance.exports.get_function(ContractSection::Update.name())?; + let _ = self.instance.exports.get_function(ContractSection::Metadata.name())?; + + Ok(()) + } + fn call(&mut self, section: ContractSection, payload: &[u8]) -> Result> { debug!(target: "runtime::vm_runtime", "Calling {} method", section.name()); @@ -445,7 +458,7 @@ impl Runtime { fn print_logs(&self) { let logs = self.ctx.as_ref(&self.store).logs.borrow(); for msg in logs.iter() { - debug!(target: "runtime::vm_runtime", "Contract log: {}", msg); + info!(target: "runtime::vm_runtime", "[WASM] Contract log: {}", msg); } }