Skip to content

Commit

Permalink
fix(builtins): bystr20_to_bech32's None type parameter (#1166)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Trunov authored Sep 12, 2022
1 parent 93dbed7 commit 7b89520
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/eval/EvalBuiltins.ml
Original file line number Diff line number Diff line change
Expand Up @@ -675,15 +675,14 @@ module ScillaEvalBuiltIns (SR : Rep) (ER : Rep) = struct
let bystr20_to_bech32 _ ls _ =
match ls with
| [ StringLit prfx; ByStrX addr ] -> (
if Core.String.(prfx <> "zil") then
pure @@ build_none_lit (bystrx_typ Type.address_length)
if Core.String.(prfx <> "zil") then pure @@ build_none_lit string_typ
else
match
Bech32.encode_bech32_addr ~prfx ~addr:(Bystrx.to_raw_bytes addr)
with
| Some bech32 ->
pure @@ build_some_lit (StringLit bech32) string_typ
| None -> pure @@ build_none_lit (bystrx_typ Type.address_length))
| None -> pure @@ build_none_lit string_typ)
| _ -> builtin_fail "Crypto.bystr20_to_bech32" ls

let concat _ ls _ =
Expand Down
1 change: 1 addition & 0 deletions tests/eval/good/Good.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let explist =
"builtin-bech32-3.scilexp";
"builtin-bech32-4.scilexp";
"builtin-bech32-5.scilexp";
"builtin-bech32-6.scilexp";
"builtin-isqrt.scilexp";
"builtin-eq-bystr.scilexp";
"cons.scilexp";
Expand Down
9 changes: 9 additions & 0 deletions tests/eval/good/builtin-bech32-6.scilexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let emp = Emp (Int128) (Option String) in
let key = Int128 -3 in
let val =
let str = "tzil" in
let addr = 0x0000000000000000000000000000000000000000
in builtin bystr20_to_bech32 str addr
in
builtin put emp key val

5 changes: 5 additions & 0 deletions tests/eval/good/gold/builtin-bech32-6.scilexp.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(Map Int128 Option (String) [((Int128 -3) => (None))]),
{ [val -> (None)],
[key -> (Int128 -3)],
[emp -> (Map Int128 Option (String) [])] }
Gas remaining: 4001881

0 comments on commit 7b89520

Please sign in to comment.