diff --git a/src/stdlib/Conversions.scillib b/src/stdlib/Conversions.scillib index 06b358652..26bfc96d6 100644 --- a/src/stdlib/Conversions.scillib +++ b/src/stdlib/Conversions.scillib @@ -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 = @@ -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 diff --git a/tests/eval/good/Good.ml b/tests/eval/good/Good.ml index 6499cbba4..51e91aaea 100644 --- a/tests/eval/good/Good.ml +++ b/tests/eval/good/Good.ml @@ -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 diff --git a/tests/eval/good/endian_test128.scilexp b/tests/eval/good/endian_test128.scilexp new file mode 100644 index 000000000..515bdf9d1 --- /dev/null +++ b/tests/eval/good/endian_test128.scilexp @@ -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 + diff --git a/tests/eval/good/endian_test256.scilexp b/tests/eval/good/endian_test256.scilexp new file mode 100644 index 000000000..e2181f202 --- /dev/null +++ b/tests/eval/good/endian_test256.scilexp @@ -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 + diff --git a/tests/eval/good/endian_test32.scilexp b/tests/eval/good/endian_test32.scilexp new file mode 100644 index 000000000..c3eda25b3 --- /dev/null +++ b/tests/eval/good/endian_test32.scilexp @@ -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 + diff --git a/tests/eval/good/endian_test64.scilexp b/tests/eval/good/endian_test64.scilexp new file mode 100644 index 000000000..56757d446 --- /dev/null +++ b/tests/eval/good/endian_test64.scilexp @@ -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 + diff --git a/tests/eval/good/gold/endian_test128.scilexp.gold b/tests/eval/good/gold/endian_test128.scilexp.gold new file mode 100644 index 000000000..88fb2cc47 --- /dev/null +++ b/tests/eval/good/gold/endian_test128.scilexp.gold @@ -0,0 +1,10 @@ +(Pair (ByStr 0x39300000000000000000000000000000) (ByStr 0x00000000000000000000000000003039)), +{ [ibe -> (ByStr 0x00000000000000000000000000003039)], + [append_uint128_be -> ], + [extract_uint128_be -> ], + [big_endian -> (Conversions.BigEndian)], + [ile -> (ByStr 0x39300000000000000000000000000000)], + [empty -> (ByStr 0x)], + [empty_x -> (ByStr0 0x)], + [i -> (Uint128 12345)] } +Gas remaining: 4001096 diff --git a/tests/eval/good/gold/endian_test256.scilexp.gold b/tests/eval/good/gold/endian_test256.scilexp.gold new file mode 100644 index 000000000..87d14b4e4 --- /dev/null +++ b/tests/eval/good/gold/endian_test256.scilexp.gold @@ -0,0 +1,10 @@ +(Pair (ByStr 0x3930000000000000000000000000000000000000000000000000000000000000) (ByStr 0x0000000000000000000000000000000000000000000000000000000000003039)), +{ [ibe -> (ByStr 0x0000000000000000000000000000000000000000000000000000000000003039)], + [append_uint256_be -> ], + [extract_uint256_be -> ], + [big_endian -> (Conversions.BigEndian)], + [ile -> (ByStr 0x3930000000000000000000000000000000000000000000000000000000000000)], + [empty -> (ByStr 0x)], + [empty_x -> (ByStr0 0x)], + [i -> (Uint256 12345)] } +Gas remaining: 4000984 diff --git a/tests/eval/good/gold/endian_test32.scilexp.gold b/tests/eval/good/gold/endian_test32.scilexp.gold new file mode 100644 index 000000000..b60eb9084 --- /dev/null +++ b/tests/eval/good/gold/endian_test32.scilexp.gold @@ -0,0 +1,10 @@ +(Pair (ByStr 0x39300000) (ByStr 0x00003039)), +{ [ibe -> (ByStr 0x00003039)], + [append_uint32_be -> ], + [extract_uint32_be -> ], + [big_endian -> (Conversions.BigEndian)], + [ile -> (ByStr 0x39300000)], + [empty -> (ByStr 0x)], + [empty_x -> (ByStr0 0x)], + [i -> (Uint32 12345)] } +Gas remaining: 4001180 diff --git a/tests/eval/good/gold/endian_test64.scilexp.gold b/tests/eval/good/gold/endian_test64.scilexp.gold new file mode 100644 index 000000000..be1063157 --- /dev/null +++ b/tests/eval/good/gold/endian_test64.scilexp.gold @@ -0,0 +1,10 @@ +(Pair (ByStr 0x3930000000000000) (ByStr 0x0000000000003039)), +{ [ibe -> (ByStr 0x0000000000003039)], + [append_uint64_be -> ], + [extract_uint64_be -> ], + [big_endian -> (Conversions.BigEndian)], + [ile -> (ByStr 0x3930000000000000)], + [empty -> (ByStr 0x)], + [empty_x -> (ByStr0 0x)], + [i -> (Uint64 12345)] } +Gas remaining: 4001152