From 5375dfff9dd7e97df34f1ae38341481a1eee5295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 14 Jun 2022 12:00:16 +0200 Subject: [PATCH] Refactor error/event selector tests - Remove redundant semantic tests for error selector - Consolidate semanticTests/error/ and semanticTests/errors/ dirs - Make "selector syntax test" for errors and event an actual test for syntax rather than a copy of the same semantic test --- .../semanticTests/error/selector.sol | 18 ------- .../{error => errors}/error_selector.sol | 0 .../errors/error_selector_syntax.sol | 54 +++++++------------ ...elector_library_called_inside_function.sol | 1 - .../events/event_selector_syntax.sol | 39 ++++---------- 5 files changed, 31 insertions(+), 81 deletions(-) delete mode 100644 test/libsolidity/semanticTests/error/selector.sol rename test/libsolidity/semanticTests/{error => errors}/error_selector.sol (100%) diff --git a/test/libsolidity/semanticTests/error/selector.sol b/test/libsolidity/semanticTests/error/selector.sol deleted file mode 100644 index 762929026..000000000 --- a/test/libsolidity/semanticTests/error/selector.sol +++ /dev/null @@ -1,18 +0,0 @@ -library L { - error E(); -} -library S { - error E(uint); -} -library T { - error E(); -} -contract C { - function f() public pure returns (bytes4, bytes4) { - assert(L.E.selector == T.E.selector); - assert(L.E.selector != S.E.selector); - return (L.E.selector, S.E.selector); - } -} -// ---- -// f() -> 0x92bbf6e800000000000000000000000000000000000000000000000000000000, 0x2ff06700000000000000000000000000000000000000000000000000000000 diff --git a/test/libsolidity/semanticTests/error/error_selector.sol b/test/libsolidity/semanticTests/errors/error_selector.sol similarity index 100% rename from test/libsolidity/semanticTests/error/error_selector.sol rename to test/libsolidity/semanticTests/errors/error_selector.sol diff --git a/test/libsolidity/syntaxTests/errors/error_selector_syntax.sol b/test/libsolidity/syntaxTests/errors/error_selector_syntax.sol index ebd598cb2..1af3bbcd2 100644 --- a/test/libsolidity/syntaxTests/errors/error_selector_syntax.sol +++ b/test/libsolidity/syntaxTests/errors/error_selector_syntax.sol @@ -1,48 +1,34 @@ library L { - error E(); -} -library S { - error E(uint); -} -library T { - error E(); + error E(bytes4, bool, bytes); } -error E(); +error E(bytes4, bool, bytes); interface I { - error E(); - function f() external pure; + error E(bytes4, bool, bytes); } -contract D { - error F(); +contract B { + error E(bytes4, bool, bytes); } -contract C is D { - function test1() public pure returns (bytes4, bytes4, bytes4, bytes4) { - assert(L.E.selector == T.E.selector); - assert(L.E.selector != S.E.selector); - assert(E.selector == L.E.selector); - assert(I.E.selector == L.E.selector); - return (L.E.selector, S.E.selector, E.selector, I.E.selector); - } +contract C is B { + bytes4 public librarySelector = L.E.selector; + bytes4 internal freeSelector = E.selector; + bytes4 internal contractSelector = B.E.selector; + bytes4 private interfaceSelector = I.E.selector; - bytes4 s1 = L.E.selector; - bytes4 s2 = S.E.selector; - bytes4 s3 = T.E.selector; - bytes4 s4 = I.E.selector; + function f(bool condition) public view { + assert(librarySelector == L.E.selector); + assert(E.selector == B.E.selector); - function test2() view external returns (bytes4, bytes4, bytes4, bytes4) { - return (s1, s2, s3, s4); - } - - function test3() pure external returns (bytes4) { - return (F.selector); + if (condition) + revert E(E.selector, true, "123"); + else + revert L.E((B.E.selector), true, "123"); } } // ---- -// Warning 2519: (16-26): This declaration shadows an existing declaration. -// Warning 2519: (45-59): This declaration shadows an existing declaration. -// Warning 2519: (78-88): This declaration shadows an existing declaration. -// Warning 2519: (122-132): This declaration shadows an existing declaration. +// Warning 2519: (16-45): This declaration shadows an existing declaration. +// Warning 2519: (98-127): This declaration shadows an existing declaration. +// Warning 2519: (148-177): This declaration shadows an existing declaration. diff --git a/test/libsolidity/syntaxTests/events/event_selector_library_called_inside_function.sol b/test/libsolidity/syntaxTests/events/event_selector_library_called_inside_function.sol index 49741a5ca..45e050e45 100644 --- a/test/libsolidity/syntaxTests/events/event_selector_library_called_inside_function.sol +++ b/test/libsolidity/syntaxTests/events/event_selector_library_called_inside_function.sol @@ -6,7 +6,6 @@ contract D { function test1() external pure returns (bytes32) { return Y.E.selector; } - } // ---- // TypeError 9582: (123-135): Member "selector" not found or not visible after argument-dependent lookup in function (). diff --git a/test/libsolidity/syntaxTests/events/event_selector_syntax.sol b/test/libsolidity/syntaxTests/events/event_selector_syntax.sol index ebb88d298..ecbfe9bc5 100644 --- a/test/libsolidity/syntaxTests/events/event_selector_syntax.sol +++ b/test/libsolidity/syntaxTests/events/event_selector_syntax.sol @@ -1,37 +1,20 @@ library L { - event E(); -} -library S { - event E(uint); -} -library T { - event E(); + event E(bytes32, bool, bytes indexed); } -contract D { - event F(); +contract B { + event E(bytes32, bool, bytes indexed); } -contract C is D { - function test1() external pure returns (bytes32, bytes32) { - assert(L.E.selector == T.E.selector); +contract C is B { + bytes32 public librarySelector = L.E.selector; + bytes32 inheritedSelector = E.selector; - assert(L.E.selector != S.E.selector); - assert(T.E.selector != S.E.selector); + function f() public { + assert(librarySelector == L.E.selector); + assert(E.selector == B.E.selector); - return (L.E.selector, S.E.selector); - } - - bytes32 s1 = L.E.selector; - bytes32 s2 = S.E.selector; - bytes32 s3 = T.E.selector; - - function test2() view external returns (bytes32, bytes32, bytes32) { - return (s1, s2, s3); - } - - function test3() pure external returns (bytes32) { - return (F.selector); + emit E(E.selector, true, "123"); + emit L.E((B.E.selector), true, "123"); } } -// ----