Skip to content

Commit

Permalink
Merge pull request #979 from Zilliqa/conversions_fix
Browse files Browse the repository at this point in the history
Fix typo bug in Conversions.scillib and add test
  • Loading branch information
AmritKumar authored Apr 14, 2021
2 parents d4f6509 + 3560ff2 commit dfb9551
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/stdlib/Conversions.scillib
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ let append_uint128 : IntegerEncoding -> ByStr -> Uint128 -> ByStr =
let uib_endian =
match endian with | LittleEndian => builtin strrev uib | BigEndian => uib end
in
builtin concat bs uib
builtin concat bs uib_endian

(* Append serialized Uint256 value to given byte string *)
let append_uint256 : IntegerEncoding -> ByStr -> Uint256 -> ByStr =
Expand All @@ -218,4 +218,4 @@ let append_uint256 : IntegerEncoding -> ByStr -> Uint256 -> ByStr =
let uib_endian =
match endian with | LittleEndian => builtin strrev uib | BigEndian => uib end
in
builtin concat bs uib
builtin concat bs uib_endian
4 changes: 4 additions & 0 deletions tests/eval/good/Good.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ let explist =
"polynetwork_getBookKeeper.scilexp";
"polynetwork_txparam.scilexp";
"builtin_type_args.scilexp";
"endian_test32.scilexp";
"endian_test64.scilexp";
"endian_test128.scilexp";
"endian_test256.scilexp";
]

module Tests = Scilla_test.Util.DiffBasedTests (struct
Expand Down
15 changes: 15 additions & 0 deletions tests/eval/good/endian_test128.scilexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let i = Uint128 12345 in
let empty_x = 0x in

let empty = builtin to_bystr empty_x in

let ile = append_uint128_le empty i in

let big_endian = BigEndian in
let extract_uint128_be = extract_uint128 big_endian in
let append_uint128_be = append_uint128 big_endian in

let ibe = append_uint128_be empty i in

Pair {ByStr ByStr} ile ibe

15 changes: 15 additions & 0 deletions tests/eval/good/endian_test256.scilexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let i = Uint256 12345 in
let empty_x = 0x in

let empty = builtin to_bystr empty_x in

let ile = append_uint256_le empty i in

let big_endian = BigEndian in
let extract_uint256_be = extract_uint256 big_endian in
let append_uint256_be = append_uint256 big_endian in

let ibe = append_uint256_be empty i in

Pair {ByStr ByStr} ile ibe

15 changes: 15 additions & 0 deletions tests/eval/good/endian_test32.scilexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let i = Uint32 12345 in
let empty_x = 0x in

let empty = builtin to_bystr empty_x in

let ile = append_uint32_le empty i in

let big_endian = BigEndian in
let extract_uint32_be = extract_uint32 big_endian in
let append_uint32_be = append_uint32 big_endian in

let ibe = append_uint32_be empty i in

Pair {ByStr ByStr} ile ibe

15 changes: 15 additions & 0 deletions tests/eval/good/endian_test64.scilexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let i = Uint64 12345 in
let empty_x = 0x in

let empty = builtin to_bystr empty_x in

let ile = append_uint64_le empty i in

let big_endian = BigEndian in
let extract_uint64_be = extract_uint64 big_endian in
let append_uint64_be = append_uint64 big_endian in

let ibe = append_uint64_be empty i in

Pair {ByStr ByStr} ile ibe

10 changes: 10 additions & 0 deletions tests/eval/good/gold/endian_test128.scilexp.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(Pair (ByStr 0x39300000000000000000000000000000) (ByStr 0x00000000000000000000000000003039)),
{ [ibe -> (ByStr 0x00000000000000000000000000003039)],
[append_uint128_be -> <closure>],
[extract_uint128_be -> <closure>],
[big_endian -> (Conversions.BigEndian)],
[ile -> (ByStr 0x39300000000000000000000000000000)],
[empty -> (ByStr 0x)],
[empty_x -> (ByStr0 0x)],
[i -> (Uint128 12345)] }
Gas remaining: 4001096
10 changes: 10 additions & 0 deletions tests/eval/good/gold/endian_test256.scilexp.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(Pair (ByStr 0x3930000000000000000000000000000000000000000000000000000000000000) (ByStr 0x0000000000000000000000000000000000000000000000000000000000003039)),
{ [ibe -> (ByStr 0x0000000000000000000000000000000000000000000000000000000000003039)],
[append_uint256_be -> <closure>],
[extract_uint256_be -> <closure>],
[big_endian -> (Conversions.BigEndian)],
[ile -> (ByStr 0x3930000000000000000000000000000000000000000000000000000000000000)],
[empty -> (ByStr 0x)],
[empty_x -> (ByStr0 0x)],
[i -> (Uint256 12345)] }
Gas remaining: 4000984
10 changes: 10 additions & 0 deletions tests/eval/good/gold/endian_test32.scilexp.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(Pair (ByStr 0x39300000) (ByStr 0x00003039)),
{ [ibe -> (ByStr 0x00003039)],
[append_uint32_be -> <closure>],
[extract_uint32_be -> <closure>],
[big_endian -> (Conversions.BigEndian)],
[ile -> (ByStr 0x39300000)],
[empty -> (ByStr 0x)],
[empty_x -> (ByStr0 0x)],
[i -> (Uint32 12345)] }
Gas remaining: 4001180
10 changes: 10 additions & 0 deletions tests/eval/good/gold/endian_test64.scilexp.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(Pair (ByStr 0x3930000000000000) (ByStr 0x0000000000003039)),
{ [ibe -> (ByStr 0x0000000000003039)],
[append_uint64_be -> <closure>],
[extract_uint64_be -> <closure>],
[big_endian -> (Conversions.BigEndian)],
[ile -> (ByStr 0x3930000000000000)],
[empty -> (ByStr 0x)],
[empty_x -> (ByStr0 0x)],
[i -> (Uint64 12345)] }
Gas remaining: 4001152

0 comments on commit dfb9551

Please sign in to comment.