From c2cbd8c2bf6a1ef4c5b535464b20c72c5a9838bc Mon Sep 17 00:00:00 2001 From: xunilrj Date: Mon, 8 Jul 2024 11:56:44 +0100 Subject: [PATCH 1/2] fix configurable tests --- .../json_abi_oracle_new_encoding.json | 249 +++++++++++++++++- .../language/configurable_consts/src/main.sw | 70 ++++- 2 files changed, 314 insertions(+), 5 deletions(-) diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json index 32f83d32de0..0f5917231cd 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json @@ -3,11 +3,137 @@ { "configurableType": { "name": "", - "type": 1, + "type": 5, "typeArguments": null }, "name": "BOOL", - "offset": 360 + "offset": 6888 + }, + { + "configurableType": { + "name": "", + "type": 13, + "typeArguments": null + }, + "name": "U8", + "offset": 7024 + }, + { + "configurableType": { + "name": "", + "type": 13, + "typeArguments": null + }, + "name": "ANOTHER_U8", + "offset": 6816 + }, + { + "configurableType": { + "name": "", + "type": 9, + "typeArguments": null + }, + "name": "U16", + "offset": 6968 + }, + { + "configurableType": { + "name": "", + "type": 11, + "typeArguments": null + }, + "name": "U32", + "offset": 7008 + }, + { + "configurableType": { + "name": "", + "type": 11, + "typeArguments": null + }, + "name": "U64", + "offset": 7016 + }, + { + "configurableType": { + "name": "", + "type": 10, + "typeArguments": null + }, + "name": "U256", + "offset": 6976 + }, + { + "configurableType": { + "name": "", + "type": 4, + "typeArguments": null + }, + "name": "B256", + "offset": 6856 + }, + { + "configurableType": { + "name": "", + "type": 8, + "typeArguments": [] + }, + "name": "CONFIGURABLE_STRUCT", + "offset": 6928 + }, + { + "configurableType": { + "name": "", + "type": 6, + "typeArguments": [] + }, + "name": "CONFIGURABLE_ENUM_A", + "offset": 6896 + }, + { + "configurableType": { + "name": "", + "type": 6, + "typeArguments": [] + }, + "name": "CONFIGURABLE_ENUM_B", + "offset": 6912 + }, + { + "configurableType": { + "name": "", + "type": 2, + "typeArguments": null + }, + "name": "ARRAY_BOOL", + "offset": 6824 + }, + { + "configurableType": { + "name": "", + "type": 3, + "typeArguments": null + }, + "name": "ARRAY_U64", + "offset": 6832 + }, + { + "configurableType": { + "name": "", + "type": 1, + "typeArguments": null + }, + "name": "TUPLE_BOOL_U64", + "offset": 6952 + }, + { + "configurableType": { + "name": "", + "type": 7, + "typeArguments": null + }, + "name": "STR_4", + "offset": 6944 } ], "encoding": "1", @@ -32,10 +158,127 @@ "typeId": 0, "typeParameters": null }, + { + "components": [ + { + "name": "__tuple_element", + "type": 5, + "typeArguments": null + }, + { + "name": "__tuple_element", + "type": 12, + "typeArguments": null + } + ], + "type": "(_, _)", + "typeId": 1, + "typeParameters": null + }, + { + "components": [ + { + "name": "__array_element", + "type": 5, + "typeArguments": null + } + ], + "type": "[_; 3]", + "typeId": 2, + "typeParameters": null + }, + { + "components": [ + { + "name": "__array_element", + "type": 12, + "typeArguments": null + } + ], + "type": "[_; 3]", + "typeId": 3, + "typeParameters": null + }, + { + "components": null, + "type": "b256", + "typeId": 4, + "typeParameters": null + }, { "components": null, "type": "bool", - "typeId": 1, + "typeId": 5, + "typeParameters": null + }, + { + "components": [ + { + "name": "A", + "type": 5, + "typeArguments": null + }, + { + "name": "B", + "type": 12, + "typeArguments": null + } + ], + "type": "enum ConfigurableEnum", + "typeId": 6, + "typeParameters": null + }, + { + "components": null, + "type": "str[4]", + "typeId": 7, + "typeParameters": null + }, + { + "components": [ + { + "name": "a", + "type": 5, + "typeArguments": null + }, + { + "name": "b", + "type": 12, + "typeArguments": null + } + ], + "type": "struct ConfigurableStruct", + "typeId": 8, + "typeParameters": null + }, + { + "components": null, + "type": "u16", + "typeId": 9, + "typeParameters": null + }, + { + "components": null, + "type": "u256", + "typeId": 10, + "typeParameters": null + }, + { + "components": null, + "type": "u32", + "typeId": 11, + "typeParameters": null + }, + { + "components": null, + "type": "u64", + "typeId": 12, + "typeParameters": null + }, + { + "components": null, + "type": "u8", + "typeId": 13, "typeParameters": null } ] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/src/main.sw index 59a4d92df27..e4bf5ef213b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/src/main.sw @@ -1,9 +1,75 @@ script; +use std::hash::*; + +struct ConfigurableStruct { + a: bool, + b: u64, +} + +enum ConfigurableEnum { + A: bool, + B: u64, +} + +impl core::ops::Eq for ConfigurableEnum { + fn eq(self, other: ConfigurableEnum) -> bool { + match (self, other) { + (ConfigurableEnum::A(inner1), ConfigurableEnum::A(inner2)) => inner1 == inner2, + (ConfigurableEnum::B(inner1), ConfigurableEnum::B(inner2)) => inner1 == inner2, + _ => false, + } + } +} + +type AnotherU8 = u8; + configurable { BOOL: bool = true, + U8: u8 = 1, + ANOTHER_U8: AnotherU8 = 3, + U16: u16 = 2, + U32: u32 = 3, + U64: u32 = 4, + U256: u256 = 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAu256, + B256: b256 = 0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB, + CONFIGURABLE_STRUCT: ConfigurableStruct = ConfigurableStruct { a: true, b: 5 }, + CONFIGURABLE_ENUM_A: ConfigurableEnum = ConfigurableEnum::A(true), + CONFIGURABLE_ENUM_B: ConfigurableEnum = ConfigurableEnum::B(12), + ARRAY_BOOL: [bool; 3] = [true, false, true], + ARRAY_U64: [u64; 3] = [9, 8, 7], + TUPLE_BOOL_U64: (bool, u64) = (true, 11), + STR_4: str[4] = __to_str_array("abcd"), } - + fn main() { assert(BOOL == true); -} \ No newline at end of file + assert(U8 == 1); + assert(ANOTHER_U8 == 3); + assert(U16 == 2); + assert(U64 == 4); + assert(U256 == 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAu256); + assert(B256 == 0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB); + assert(CONFIGURABLE_STRUCT.a == true); + assert(CONFIGURABLE_STRUCT.b == 5); + assert(CONFIGURABLE_ENUM_A == ConfigurableEnum::A(true)); + assert(CONFIGURABLE_ENUM_B == ConfigurableEnum::B(12)); + assert(ARRAY_BOOL[0] == true); + assert(ARRAY_BOOL[1] == false); + assert(ARRAY_BOOL[2] == true); + assert(ARRAY_U64[0] == 9); + assert(ARRAY_U64[1] == 8); + assert(ARRAY_U64[2] == 7); + assert(TUPLE_BOOL_U64.0 == true); + assert(TUPLE_BOOL_U64.1 == 11); + assert(sha256_str_array(STR_4) == sha256("abcd")); + + // Assert address do not change + let addr_1 = asm(addr: __addr_of(&BOOL)) { + addr: u64 + }; + let addr_2 = asm(addr: __addr_of(&BOOL)) { + addr: u64 + }; + assert(addr_1 == addr_2); +} From 955491736783bbe6a0a18169269ec363a0b01da2 Mon Sep 17 00:00:00 2001 From: xunilrj Date: Mon, 8 Jul 2024 11:59:57 +0100 Subject: [PATCH 2/2] fix test.toml --- .../json_abi_oracle_new_encoding.json | 39 ++++++++++++------- .../language/configurable_consts/src/main.sw | 3 ++ .../language/configurable_consts/test.toml | 5 +-- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json index 0f5917231cd..b76fb86d956 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json @@ -7,7 +7,7 @@ "typeArguments": null }, "name": "BOOL", - "offset": 6888 + "offset": 6944 }, { "configurableType": { @@ -16,7 +16,7 @@ "typeArguments": null }, "name": "U8", - "offset": 7024 + "offset": 7088 }, { "configurableType": { @@ -25,7 +25,7 @@ "typeArguments": null }, "name": "ANOTHER_U8", - "offset": 6816 + "offset": 6872 }, { "configurableType": { @@ -34,7 +34,7 @@ "typeArguments": null }, "name": "U16", - "offset": 6968 + "offset": 7032 }, { "configurableType": { @@ -43,7 +43,7 @@ "typeArguments": null }, "name": "U32", - "offset": 7008 + "offset": 7072 }, { "configurableType": { @@ -52,7 +52,7 @@ "typeArguments": null }, "name": "U64", - "offset": 7016 + "offset": 7080 }, { "configurableType": { @@ -61,7 +61,7 @@ "typeArguments": null }, "name": "U256", - "offset": 6976 + "offset": 7040 }, { "configurableType": { @@ -70,7 +70,7 @@ "typeArguments": null }, "name": "B256", - "offset": 6856 + "offset": 6912 }, { "configurableType": { @@ -79,7 +79,7 @@ "typeArguments": [] }, "name": "CONFIGURABLE_STRUCT", - "offset": 6928 + "offset": 6984 }, { "configurableType": { @@ -88,7 +88,7 @@ "typeArguments": [] }, "name": "CONFIGURABLE_ENUM_A", - "offset": 6896 + "offset": 6952 }, { "configurableType": { @@ -97,7 +97,7 @@ "typeArguments": [] }, "name": "CONFIGURABLE_ENUM_B", - "offset": 6912 + "offset": 6968 }, { "configurableType": { @@ -106,7 +106,7 @@ "typeArguments": null }, "name": "ARRAY_BOOL", - "offset": 6824 + "offset": 6880 }, { "configurableType": { @@ -115,7 +115,7 @@ "typeArguments": null }, "name": "ARRAY_U64", - "offset": 6832 + "offset": 6888 }, { "configurableType": { @@ -124,7 +124,7 @@ "typeArguments": null }, "name": "TUPLE_BOOL_U64", - "offset": 6952 + "offset": 7016 }, { "configurableType": { @@ -133,7 +133,16 @@ "typeArguments": null }, "name": "STR_4", - "offset": 6944 + "offset": 7008 + }, + { + "configurableType": { + "name": "", + "type": 13, + "typeArguments": null + }, + "name": "NOT_USED", + "offset": 7000 } ], "encoding": "1", diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/src/main.sw index e4bf5ef213b..b1ff46b7e0e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/src/main.sw @@ -40,6 +40,8 @@ configurable { ARRAY_U64: [u64; 3] = [9, 8, 7], TUPLE_BOOL_U64: (bool, u64) = (true, 11), STR_4: str[4] = __to_str_array("abcd"), + + NOT_USED: u8 = 1 } fn main() { @@ -47,6 +49,7 @@ fn main() { assert(U8 == 1); assert(ANOTHER_U8 == 3); assert(U16 == 2); + assert(U32 == 3); assert(U64 == 4); assert(U256 == 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAu256); assert(B256 == 0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/test.toml index 69ed91a1f33..a8b7c2f8903 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/test.toml @@ -2,8 +2,5 @@ category = "run" expected_result = { action = "return", value = 0 } expected_result_new_encoding = { action = "return_data", value = "" } validate_abi = true -expected_warnings = 6 +expected_warnings = 1 unsupported_profiles = ["debug"] - -# check: $()NOT_USED: u8 = 1 -# nextln: $()This declaration is never used