Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xunilrj committed May 4, 2024
1 parent 518236c commit 01ba901
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 25 deletions.
34 changes: 28 additions & 6 deletions sway-lib-core/src/codec.sw
Original file line number Diff line number Diff line change
Expand Up @@ -5073,26 +5073,48 @@ fn ok_abi_encoding() {
assert_encoding_and_decoding(true, [1u8]);

// numbers
assert_encoding_and_decoding(0u8, [0u8; 1]);
assert_encoding_and_decoding(255u8, [255u8; 1]);
assert_encoding_and_decoding(0u16, [0u8; 2]);
assert_encoding_and_decoding(65535u16, [255u8; 2]);
assert_encoding_and_decoding(0u32, [0u8; 4]);
assert_encoding_and_decoding(4294967295u32, [255u8; 4]);
assert_encoding_and_decoding(0u8, [0u8]);
assert_encoding_and_decoding(255u8, [255u8]);

assert_encoding_and_decoding(0u16, [0u8, 0u8]);
assert_encoding_and_decoding(128u16, [0u8, 128u8]);
assert_encoding_and_decoding(65535u16, [255u8, 255u8]);

assert_encoding_and_decoding(0u32, [0u8, 0u8, 0u8, 0u8]);
assert_encoding_and_decoding(128u32, [0u8, 0u8, 0u8, 128u8]);
assert_encoding_and_decoding(4294967295u32, [255u8, 255u8, 255u8, 255u8]);

assert_encoding_and_decoding(0u64, [0u8; 8]);
assert_encoding_and_decoding(128u64, [0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 128u8]);
assert_encoding_and_decoding(18446744073709551615u64, [255u8; 8]);

assert_encoding_and_decoding(
0x0000000000000000000000000000000000000000000000000000000000000000u256,
[0u8; 32],
);
assert_encoding_and_decoding(
0xAA000000000000000000000000000000000000000000000000000000000000BBu256,
[0xAAu8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0xBBu8]
);
assert_encoding_and_decoding(
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFu256,
[255u8; 32],
);

assert_encoding_and_decoding(
0x0000000000000000000000000000000000000000000000000000000000000000,
[0u8; 32],
);
assert_encoding_and_decoding(
0xAA000000000000000000000000000000000000000000000000000000000000BB,
[0xAAu8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0xBBu8]
);
assert_encoding_and_decoding(
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
[255u8; 32],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"typeArguments": null
},
"name": "C0",
"offset": 13232
"offset": 13324
},
{
"configurableType": {
Expand All @@ -16,7 +16,7 @@
"typeArguments": null
},
"name": "C1",
"offset": 13256
"offset": 13348
},
{
"configurableType": {
Expand All @@ -25,7 +25,7 @@
"typeArguments": null
},
"name": "C2",
"offset": 13272
"offset": 13364
},
{
"configurableType": {
Expand All @@ -34,7 +34,7 @@
"typeArguments": []
},
"name": "C3",
"offset": 13304
"offset": 13396
},
{
"configurableType": {
Expand All @@ -43,7 +43,7 @@
"typeArguments": []
},
"name": "C4",
"offset": 13320
"offset": 13412
},
{
"configurableType": {
Expand All @@ -52,7 +52,7 @@
"typeArguments": []
},
"name": "C5",
"offset": 13336
"offset": 13428
},
{
"configurableType": {
Expand All @@ -61,7 +61,7 @@
"typeArguments": null
},
"name": "C6",
"offset": 13352
"offset": 13444
},
{
"configurableType": {
Expand All @@ -70,7 +70,7 @@
"typeArguments": null
},
"name": "C7",
"offset": 13368
"offset": 13460
},
{
"configurableType": {
Expand All @@ -79,7 +79,16 @@
"typeArguments": null
},
"name": "C9",
"offset": 13416
"offset": 13508
},
{
"configurableType": {
"name": "",
"type": 5,
"typeArguments": null
},
"name": "BOOL",
"offset": 13604
},
{
"configurableType": {
Expand All @@ -88,7 +97,7 @@
"typeArguments": null
},
"name": "U8",
"offset": 13512
"offset": 13612
},
{
"configurableType": {
Expand All @@ -97,7 +106,7 @@
"typeArguments": null
},
"name": "ANOTHERU8",
"offset": 13528
"offset": 13628
},
{
"configurableType": {
Expand All @@ -106,7 +115,7 @@
"typeArguments": null
},
"name": "U16",
"offset": 13536
"offset": 13636
},
{
"configurableType": {
Expand All @@ -115,7 +124,7 @@
"typeArguments": null
},
"name": "U32",
"offset": 13544
"offset": 13644
},
{
"configurableType": {
Expand All @@ -124,7 +133,7 @@
"typeArguments": null
},
"name": "U64",
"offset": 13560
"offset": 13660
},
{
"configurableType": {
Expand All @@ -133,7 +142,7 @@
"typeArguments": null
},
"name": "U256",
"offset": 13576
"offset": 13676
},
{
"configurableType": {
Expand All @@ -142,7 +151,7 @@
"typeArguments": null
},
"name": "ARRAY_U8",
"offset": 13432
"offset": 13524
},
{
"configurableType": {
Expand All @@ -151,7 +160,7 @@
"typeArguments": null
},
"name": "ARRAY_U32",
"offset": 13464
"offset": 13556
}
],
"encoding": "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ configurable {
C9: u64 = 10 + 9 - 8 * 7 / 6 << 5 >> 4 ^ 3 | 2 & 1,

UNIT: () = (),
BOOL: bool = true,
U8: u8 = 8,
ANOTHERU8: AnotherU8 = 8,
U16: u16 = 16,
U32: u32 = 32,
U64: u64 = 64,
U256: u256 = 0x00000000000000000000000000000000000000000000000000000000000000FFu256,
U256: u256 = 0x1234567812345678123456781234567812345678123456781234567812345678u256,
ARRAY_U8: [u8; 4] = [1, 2, 3, 4],
ARRAY_U32: [u32; 3] = [1, 2, 3],
}
Expand All @@ -66,12 +67,13 @@ fn test_first_use() {

__log(UNIT);

assert(BOOL);
assert(U8 == 8);
assert(ANOTHERU8 == 8);
assert(U16 == 16);
assert(U32 == 32);
assert(U64 == 64);
assert(U256 == 0x00000000000000000000000000000000000000000000000000000000000000FFu256);
assert(U256 == 0x1234567812345678123456781234567812345678123456781234567812345678u256);

assert(ARRAY_U8[0] == 1);
assert(ARRAY_U8[1] == 2);
Expand Down

0 comments on commit 01ba901

Please sign in to comment.