Răsfoiți Sursa

Bugfix: Unwrap user types while processing WriteBuffer instructions (#1244)

Cyrill Leutwiler 2 ani în urmă
părinte
comite
01cd4f502a
2 a modificat fișierele cu 8 adăugiri și 1 ștergeri
  1. 1 1
      src/emit/instructions.rs
  2. 7 0
      tests/substrate_tests/builtins.rs

+ 1 - 1
src/emit/instructions.rs

@@ -1084,7 +1084,7 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                     .build_gep(bin.context.i8_type(), data, &[offset], "start")
             };
 
-            let is_bytes = if let Type::Bytes(n) = value.ty() {
+            let is_bytes = if let Type::Bytes(n) = value.ty().unwrap_user_type(ns) {
                 n
             } else if value.ty() == Type::FunctionSelector {
                 ns.target.selector_length()

+ 7 - 0
tests/substrate_tests/builtins.rs

@@ -725,6 +725,11 @@ fn hash() {
             function get() public view returns (Hash) {
                 return Hash.wrap(current2);
             }
+
+            function test_encoding() public view {
+                Hash h = Hash.wrap(current2);
+                assert(abi.encode(current2) == abi.encode(h));
+            }
         }
         "##,
     );
@@ -743,4 +748,6 @@ fn hash() {
 
     runtime.function("get", vec![]);
     assert_eq!(&runtime.vm.output[..], &h.0[..]);
+
+    runtime.function("test_encoding", vec![]);
 }