From 4d04f30b0345eac09445f1520e4abbe7d7883316 Mon Sep 17 00:00:00 2001 From: he1pa <18012015693@163.com> Date: Mon, 5 Feb 2024 16:29:39 +0800 Subject: [PATCH] fmt code --- ir_cli/src/abi/mod.rs | 4 +- ir_cli/src/tests/e2e/continue.rs | 7 ++-- ir_cli/src/tests/e2e/match.rs | 2 +- ir_cli/src/tests/e2e/mod.rs | 2 +- ir_cli/src/vm/mod.rs | 65 ++++++++++++++++---------------- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/ir_cli/src/abi/mod.rs b/ir_cli/src/abi/mod.rs index c8a7270..6217c6f 100644 --- a/ir_cli/src/abi/mod.rs +++ b/ir_cli/src/abi/mod.rs @@ -458,9 +458,7 @@ fn input_type_to_abi_param(input_type_name: &str, param_str: &str) -> Result { - return Err(format!( - "not supported input param type {inner_type_name}" - )); + return Err(format!("not supported input param type {inner_type_name}")); } } } else { diff --git a/ir_cli/src/tests/e2e/continue.rs b/ir_cli/src/tests/e2e/continue.rs index a6ecb03..43bba02 100644 --- a/ir_cli/src/tests/e2e/continue.rs +++ b/ir_cli/src/tests/e2e/continue.rs @@ -9,8 +9,9 @@ use smart_ir::encoding::datastream::ParamType; #[test] fn test_simple_contract_with_continue() { - let mut runtime_and_abi = build_mock_runtime( - r#"module_name = "continueTest" + let mut runtime_and_abi = + build_mock_runtime( + r#"module_name = "continueTest" contract continueTest { state { } @@ -48,7 +49,7 @@ fn test_simple_contract_with_continue() { meta !6 = !{11: u32, 11: u32, "test.sonar": str, } meta !7 = !{14: u32, 14: u32, "test.sonar": str, } "#, - ); + ); let mut runtime = runtime_and_abi.0; let abi = runtime_and_abi.1; // ABI diff --git a/ir_cli/src/tests/e2e/match.rs b/ir_cli/src/tests/e2e/match.rs index 786007a..d4fc1f5 100644 --- a/ir_cli/src/tests/e2e/match.rs +++ b/ir_cli/src/tests/e2e/match.rs @@ -46,5 +46,5 @@ fn test_match() { let mut bytes = vec![0_u8]; bytes.append(&mut ABIParam::I32(3).as_bytes()); - assert_eq!(runtime.call("match", &bytes), [0,3]); + assert_eq!(runtime.call("match", &bytes), [0, 3]); } diff --git a/ir_cli/src/tests/e2e/mod.rs b/ir_cli/src/tests/e2e/mod.rs index f1c6922..b05280c 100644 --- a/ir_cli/src/tests/e2e/mod.rs +++ b/ir_cli/src/tests/e2e/mod.rs @@ -25,7 +25,7 @@ mod r#for; mod func; mod r#if; mod map; +mod r#match; mod math; mod parampack; mod select; -mod r#match; diff --git a/ir_cli/src/vm/mod.rs b/ir_cli/src/vm/mod.rs index b20e219..edbded4 100644 --- a/ir_cli/src/vm/mod.rs +++ b/ir_cli/src/vm/mod.rs @@ -36,9 +36,8 @@ use smart_ir::ir_codegen::common::global::set_extend_context; use smart_ir::ir_config::IROptions; use smart_ir::runtime::vm::*; -pub static WASM_IR: [&[u8]; 1] = [include_bytes!( - "../../../smart_ir/src/runtime/stdlib/wasm/storage_t.bc" -)]; +pub static WASM_IR: [&[u8]; 1] = + [include_bytes!("../../../smart_ir/src/runtime/stdlib/wasm/storage_t.bc")]; pub static INIT_EXTEND_CONTEXT_ONCE: Once = Once::new(); @@ -150,10 +149,11 @@ impl Externals for MockRuntime { let value_ptr: u32 = args.nth_checked(5)?; println!("GET SHARED STORAGE KEYS: {keys:?}"); - let value = match self.store.get(&keys) { - Some(v) => v.clone(), - None => vec![0], - }; + let value = + match self.store.get(&keys) { + Some(v) => v.clone(), + None => vec![0], + }; println!("GET SHARED STORAGE VALUE {value:?}"); self.codec.push(value.clone()); self.vm @@ -172,10 +172,11 @@ impl Externals for MockRuntime { Some(HostAPI::ReadObjectLength) => { let keys = self.build_keys(&args, "GET STORAGE LENGTH".to_string())?; println!("GET SHARED STORAGE KEYS: {keys:?}"); - let length = match self.store.get(&keys) { - Some(v) => v.len() as i32, - None => -1, - }; + let length = + match self.store.get(&keys) { + Some(v) => v.len() as i32, + None => -1, + }; println!("GET PRIVATE STORAGE LENGTH: {length:?}"); Ok(Some(RuntimeValue::I32(length))) } @@ -194,12 +195,12 @@ impl Externals for MockRuntime { Ok(None) } - Some(HostAPI::GetCallGasLeft) => Ok(Some(RuntimeValue::I64( - self.vm.context.call_gas_left as i64, - ))), - Some(HostAPI::GetCallGasLimit) => Ok(Some(RuntimeValue::I64( - self.vm.context.call_gas_limit as i64, - ))), + Some(HostAPI::GetCallGasLeft) => { + Ok(Some(RuntimeValue::I64(self.vm.context.call_gas_left as i64))) + } + Some(HostAPI::GetCallGasLimit) => { + Ok(Some(RuntimeValue::I64(self.vm.context.call_gas_limit as i64))) + } Some(HostAPI::GetOpContractLength) => { Ok(Some(RuntimeValue::I32(self.vm.op_addr.len() as i32))) } @@ -245,12 +246,12 @@ impl Externals for MockRuntime { Ok(None) } - Some(HostAPI::GetBlockNumber) => Ok(Some(RuntimeValue::I64( - self.vm.context.block_number.try_into().unwrap(), - ))), - Some(HostAPI::GetBlockTimestamp) => Ok(Some(RuntimeValue::I64( - self.vm.context.block_timestamp.try_into().unwrap(), - ))), + Some(HostAPI::GetBlockNumber) => { + Ok(Some(RuntimeValue::I64(self.vm.context.block_number.try_into().unwrap()))) + } + Some(HostAPI::GetBlockTimestamp) => { + Ok(Some(RuntimeValue::I64(self.vm.context.block_timestamp.try_into().unwrap()))) + } Some(HostAPI::GetBlockRandomSeed) => { let data: u32 = args.nth_checked(0)?; @@ -261,15 +262,15 @@ impl Externals for MockRuntime { Ok(None) } - Some(HostAPI::GetTxTimestamp) => Ok(Some(RuntimeValue::I64( - self.vm.context.timestamp.try_into().unwrap(), - ))), - Some(HostAPI::GetTxNonce) => Ok(Some(RuntimeValue::I64( - self.vm.context.nonce.try_into().unwrap(), - ))), - Some(HostAPI::GetTxIndex) => Ok(Some(RuntimeValue::I32( - self.vm.context.index.try_into().unwrap(), - ))), + Some(HostAPI::GetTxTimestamp) => { + Ok(Some(RuntimeValue::I64(self.vm.context.timestamp.try_into().unwrap()))) + } + Some(HostAPI::GetTxNonce) => { + Ok(Some(RuntimeValue::I64(self.vm.context.nonce.try_into().unwrap()))) + } + Some(HostAPI::GetTxIndex) => { + Ok(Some(RuntimeValue::I32(self.vm.context.index.try_into().unwrap()))) + } Some(HostAPI::GetTxHash) => { let dest = args.nth_checked::(0)?; self.vm