Jelajahi Sumber

Update seal debug message (#911)

rename seal_println symbol to seal_debug_message

disable print in integration tests for now

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Cyrill Leutwiler 3 tahun lalu
induk
melakukan
d5002dc925

+ 2 - 1
integration/substrate/UniswapV2ERC20.sol

@@ -35,7 +35,8 @@ contract UniswapV2ERC20 is IUniswapV2ERC20 {
     }
 
     function _mint(address to, uint value) internal {
-        print("_mint {} {}".format(to, value));
+        // Disabled for now, see #911
+        // print("_mint {} {}".format(to, value));
         totalSupply = totalSupply.add(value);
         balanceOf[to] = balanceOf[to].add(value);
         emit Transfer(address(0), to, value);

+ 2 - 1
integration/substrate/balances.sol

@@ -14,6 +14,7 @@ contract balances {
 	function pay_me() public payable {
 		uint128 v = msg.value;
 
-		print("Thank you very much for {}".format(v));
+		// Disabled for now, see #911
+		// print("Thank you very much for {}".format(v));
 	}
 }

+ 2 - 1
integration/substrate/issue666.sol

@@ -1,6 +1,7 @@
 contract Flip {
     function flip () pure public {
-	print("flip");
+	// Disabled for now, see #911
+	//print("flip");
     }
 }
 

+ 4 - 4
src/emit/substrate.rs

@@ -89,7 +89,7 @@ impl SubstrateTarget {
             "seal_hash_blake2_128",
             "seal_hash_blake2_256",
             "seal_return",
-            "seal_println",
+            "seal_debug_message",
             "seal_instantiate",
             "seal_call",
             "seal_value_transferred",
@@ -301,8 +301,8 @@ impl SubstrateTarget {
         );
 
         binary.module.add_function(
-            "seal_println",
-            binary.context.void_type().fn_type(
+            "seal_debug_message",
+            binary.context.i32_type().fn_type(
                 &[
                     u8_ptr,  // string_ptr
                     u32_val, // string_len
@@ -3391,7 +3391,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
 
     fn print(&self, binary: &Binary, string_ptr: PointerValue, string_len: IntValue) {
         binary.builder.build_call(
-            binary.module.get_function("seal_println").unwrap(),
+            binary.module.get_function("seal_debug_message").unwrap(),
             &[string_ptr.into(), string_len.into()],
             "",
         );

+ 8 - 8
tests/substrate.rs

@@ -58,7 +58,7 @@ enum SubstrateExternal {
     seal_get_storage,
     seal_return,
     seal_hash_keccak_256,
-    seal_println,
+    seal_debug_message,
     seal_call,
     seal_instantiate,
     seal_value_transferred,
@@ -396,7 +396,7 @@ impl Externals for MockSubstrate {
                     _ => panic!("seal_return flag {} not valid", flags),
                 }
             }
-            Some(SubstrateExternal::seal_println) => {
+            Some(SubstrateExternal::seal_debug_message) => {
                 let data_ptr: u32 = args.nth_checked(0)?;
                 let len: u32 = args.nth_checked(1)?;
 
@@ -404,16 +404,16 @@ impl Externals for MockSubstrate {
                 buf.resize(len as usize, 0u8);
 
                 if let Err(e) = self.vm.memory.get_into(data_ptr, &mut buf) {
-                    panic!("seal_println: {}", e);
+                    panic!("seal_debug_message: {}", e);
                 }
 
-                let s = String::from_utf8_lossy(&buf);
+                let s = String::from_utf8(buf).expect("seal_debug_message: Invalid UFT8");
 
-                println!("seal_println: {}", s);
+                println!("seal_debug_message: {}", s);
 
                 self.printbuf.push_str(&s);
 
-                Ok(None)
+                Ok(Some(RuntimeValue::I32(0)))
             }
             Some(SubstrateExternal::seal_random) => {
                 let data_ptr: u32 = args.nth_checked(0)?;
@@ -740,8 +740,8 @@ impl Externals for MockSubstrate {
             }
             Some(SubstrateExternal::seal_caller) => {
                 let dest_ptr: u32 = args.nth_checked(0)?;
-                let len_ptr: u32 = args.nth_checked(1)?;
 
+                let len_ptr: u32 = args.nth_checked(1)?;
                 let scratch = self.vm.caller;
 
                 set_seal_value!("seal_caller", dest_ptr, len_ptr, &scratch);
@@ -912,7 +912,7 @@ impl ModuleImportResolver for MockSubstrate {
             "seal_hash_keccak_256" => SubstrateExternal::seal_hash_keccak_256,
             "seal_hash_blake2_128" => SubstrateExternal::seal_hash_blake2_128,
             "seal_hash_blake2_256" => SubstrateExternal::seal_hash_blake2_256,
-            "seal_println" => SubstrateExternal::seal_println,
+            "seal_debug_message" => SubstrateExternal::seal_debug_message,
             "seal_call" => SubstrateExternal::seal_call,
             "seal_instantiate" => SubstrateExternal::seal_instantiate,
             "seal_value_transferred" => SubstrateExternal::seal_value_transferred,