diff --git a/test/libsolidity/SemanticTest.cpp b/test/libsolidity/SemanticTest.cpp index d17416d4f..dfa160cc2 100644 --- a/test/libsolidity/SemanticTest.cpp +++ b/test/libsolidity/SemanticTest.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -124,6 +125,12 @@ void SemanticTest::initializeBuiltins() { return util::toBigEndian(u256(0x1234)); }; + soltestAssert(m_builtins.count("storageEmpty") == 0, ""); + m_builtins["storageEmpty"] = [this](FunctionCall const& _call) -> std::optional + { + soltestAssert(_call.arguments.parameters.empty(), "No arguments expected."); + return toBigEndian(u256(storageEmpty(m_contractAddress) ? 1 : 0)); + }; } TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePrefix, bool _formatted) @@ -222,16 +229,7 @@ TestCase::TestResult SemanticTest::runTest( constructed = true; } - if (test.call().kind == FunctionCall::Kind::Storage) - { - test.setFailure(false); - bytes result(1, !storageEmpty(m_contractAddress)); - test.setRawBytes(result); - soltestAssert(test.call().expectations.rawBytes().size() == 1, ""); - if (test.call().expectations.rawBytes() != result) - success = false; - } - else if (test.call().kind == FunctionCall::Kind::Constructor) + if (test.call().kind == FunctionCall::Kind::Constructor) { if (m_transactionSuccessful == test.call().expectations.failure) success = false; diff --git a/test/libsolidity/semanticTests/array/byte_array_storage_layout.sol b/test/libsolidity/semanticTests/array/byte_array_storage_layout.sol index 317cab5cb..43c693e8b 100644 --- a/test/libsolidity/semanticTests/array/byte_array_storage_layout.sol +++ b/test/libsolidity/semanticTests/array/byte_array_storage_layout.sol @@ -41,17 +41,17 @@ contract c { // ==== // compileViaYul: also // ---- -// storage: empty +// storageEmpty -> 1 // test_short() -> 1780731860627700044960722568376587075150542249149356309979516913770823710 // gas legacy: 110938 // gas legacyOptimized: 109706 -// storage: nonempty +// storageEmpty -> 0 // test_long() -> 67 // gas irOptimized: 134320 // gas legacy: 213590 // gas legacyOptimized: 211044 -// storage: nonempty +// storageEmpty -> 0 // test_pop() -> 1780731860627700044960722568376592200742329637303199754547598369979433020 // gas legacy: 176030 // gas legacyOptimized: 173504 -// storage: nonempty +// storageEmpty -> 0 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol b/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol index ccb9ec2af..b9b928653 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol @@ -40,9 +40,9 @@ contract c { // gas irOptimized: 2470372 // gas legacy: 2288641 // gas legacyOptimized: 2258654 -// storage: empty +// storageEmpty -> 1 // clear() -> 0, 0 // gas irOptimized: 1852821 // gas legacy: 1727169 // gas legacyOptimized: 1698931 -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_dyn_dyn.sol b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_dyn_dyn.sol index f2235bf0d..5856e93fc 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_dyn_dyn.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_dyn_dyn.sol @@ -21,4 +21,4 @@ contract c { // setData1(uint256,uint256,uint256): 0, 0, 0 -> // copyStorageStorage() -> // getData2(uint256): 0 -> 0, 0 -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_struct.sol b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_struct.sol index 57ffa7090..9b5616994 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_struct.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_struct.sol @@ -22,4 +22,4 @@ contract c { // gas irOptimized: 257752 // gas legacy: 255936 // gas legacyOptimized: 254359 -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/copying/bytes_inside_mappings.sol b/test/libsolidity/semanticTests/array/copying/bytes_inside_mappings.sol index b946f7987..b1c321992 100644 --- a/test/libsolidity/semanticTests/array/copying/bytes_inside_mappings.sol +++ b/test/libsolidity/semanticTests/array/copying/bytes_inside_mappings.sol @@ -14,10 +14,10 @@ contract c { // gas irOptimized: 163929 // gas legacy: 164121 // gas legacyOptimized: 163766 -// storage: nonempty +// storageEmpty -> 0 // copy(uint256,uint256): 1, 2 -> true -// storage: nonempty +// storageEmpty -> 0 // copy(uint256,uint256): 99, 1 -> true -// storage: nonempty +// storageEmpty -> 0 // copy(uint256,uint256): 99, 2 -> true -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/copying/copy_byte_array_in_struct_to_storage.sol b/test/libsolidity/semanticTests/array/copying/copy_byte_array_in_struct_to_storage.sol index 4a4acad3c..7d9708703 100644 --- a/test/libsolidity/semanticTests/array/copying/copy_byte_array_in_struct_to_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/copy_byte_array_in_struct_to_storage.sol @@ -43,4 +43,4 @@ contract C { // g() -> 0x40, 0xc0, 0x49, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738390000000000000000000000000000000000000000000000, 0x11, 0x3132333435363738393233343536373839000000000000000000000000000000 // gas legacy: 100595 // h() -> 0x40, 0x60, 0x00, 0x00 -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/copying/copy_removes_bytes_data.sol b/test/libsolidity/semanticTests/array/copying/copy_removes_bytes_data.sol index 354eee307..bbf1b7ddd 100644 --- a/test/libsolidity/semanticTests/array/copying/copy_removes_bytes_data.sol +++ b/test/libsolidity/semanticTests/array/copying/copy_removes_bytes_data.sol @@ -12,6 +12,6 @@ contract c { // gas irOptimized: 163680 // gas legacy: 163756 // gas legacyOptimized: 163596 -// storage: nonempty +// storageEmpty -> 0 // reset() -> true -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/delete/delete_removes_bytes_data.sol b/test/libsolidity/semanticTests/array/delete/delete_removes_bytes_data.sol index 28d6e5d8f..4c573f6fa 100644 --- a/test/libsolidity/semanticTests/array/delete/delete_removes_bytes_data.sol +++ b/test/libsolidity/semanticTests/array/delete/delete_removes_bytes_data.sol @@ -7,6 +7,6 @@ contract c { // compileViaYul: also // ---- // (): 7 -> -// storage: nonempty +// storageEmpty -> 0 // del(): 7 -> true -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol b/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol index 24efe49ba..70864edbb 100644 --- a/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol +++ b/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol @@ -14,13 +14,13 @@ contract c { // ==== // compileViaYul: also // ---- -// storage: empty +// storageEmpty -> 1 // fill() -> // gas irOptimized: 535098 // gas legacy: 504373 // gas legacyOptimized: 499648 -// storage: nonempty +// storageEmpty -> 0 // halfClear() -> -// storage: nonempty +// storageEmpty -> 0 // fullClear() -> -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/dynamic_multi_array_cleanup.sol b/test/libsolidity/semanticTests/array/dynamic_multi_array_cleanup.sol index 79ce756ed..da759c7b1 100644 --- a/test/libsolidity/semanticTests/array/dynamic_multi_array_cleanup.sol +++ b/test/libsolidity/semanticTests/array/dynamic_multi_array_cleanup.sol @@ -16,11 +16,11 @@ contract c { // ==== // compileViaYul: also // ---- -// storage: empty +// storageEmpty -> 1 // fill() -> 8 // gas irOptimized: 168980 // gas legacy: 165456 // gas legacyOptimized: 164387 -// storage: nonempty +// storageEmpty -> 0 // clear() -> -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol b/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol index 49faa7777..5ba2ceab6 100644 --- a/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol +++ b/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol @@ -11,11 +11,11 @@ contract c { // compileToEwasm: also // compileViaYul: also // ---- -// storage: empty +// storageEmpty -> 1 // fill() -> // gas irOptimized: 423878 // gas legacy: 429460 // gas legacyOptimized: 425520 -// storage: nonempty +// storageEmpty -> 0 // clear() -> -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/array_pop_array_transition.sol b/test/libsolidity/semanticTests/array/pop/array_pop_array_transition.sol index 8ef94a432..7bbd86839 100644 --- a/test/libsolidity/semanticTests/array/pop/array_pop_array_transition.sol +++ b/test/libsolidity/semanticTests/array/pop/array_pop_array_transition.sol @@ -28,4 +28,4 @@ contract c { // gas irOptimized: 2455497 // gas legacy: 2416722 // gas legacyOptimized: 2405396 -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/array_pop_storage_empty.sol b/test/libsolidity/semanticTests/array/pop/array_pop_storage_empty.sol index 24f210177..b49a738ec 100644 --- a/test/libsolidity/semanticTests/array/pop/array_pop_storage_empty.sol +++ b/test/libsolidity/semanticTests/array/pop/array_pop_storage_empty.sol @@ -9,4 +9,4 @@ contract c { // compileViaYul: also // ---- // test() -> -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/array_pop_uint16_transition.sol b/test/libsolidity/semanticTests/array/pop/array_pop_uint16_transition.sol index 375487d97..5004ad13a 100644 --- a/test/libsolidity/semanticTests/array/pop/array_pop_uint16_transition.sol +++ b/test/libsolidity/semanticTests/array/pop/array_pop_uint16_transition.sol @@ -23,4 +23,4 @@ contract c { // gas irOptimized: 527367 // gas legacy: 454080 // gas legacyOptimized: 443170 -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/array_pop_uint24_transition.sol b/test/libsolidity/semanticTests/array/pop/array_pop_uint24_transition.sol index e849e2c91..aaf96d210 100644 --- a/test/libsolidity/semanticTests/array/pop/array_pop_uint24_transition.sol +++ b/test/libsolidity/semanticTests/array/pop/array_pop_uint24_transition.sol @@ -23,4 +23,4 @@ contract c { // gas irOptimized: 367121 // gas legacy: 320859 // gas legacyOptimized: 314681 -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty.sol b/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty.sol index 103563b2a..1c1323fdc 100644 --- a/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty.sol +++ b/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty.sol @@ -21,4 +21,4 @@ contract c { // gas irOptimized: 445718 // gas legacy: 552064 // gas legacyOptimized: 533164 -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty_garbage_ref.sol b/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty_garbage_ref.sol index 0e8bda56c..ee65fd911 100644 --- a/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty_garbage_ref.sol +++ b/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty_garbage_ref.sol @@ -20,4 +20,4 @@ contract c { // gas irOptimized: 291114 // gas legacy: 372763 // gas legacyOptimized: 366846 -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/byte_array_pop_storage_empty.sol b/test/libsolidity/semanticTests/array/pop/byte_array_pop_storage_empty.sol index 4bad1d7ac..52716ecb3 100644 --- a/test/libsolidity/semanticTests/array/pop/byte_array_pop_storage_empty.sol +++ b/test/libsolidity/semanticTests/array/pop/byte_array_pop_storage_empty.sol @@ -14,4 +14,4 @@ contract c { // compileViaYul: also // ---- // test() -> -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/short_fixed_array_cleanup.sol b/test/libsolidity/semanticTests/array/short_fixed_array_cleanup.sol index 9adb8446a..3665a8784 100644 --- a/test/libsolidity/semanticTests/array/short_fixed_array_cleanup.sol +++ b/test/libsolidity/semanticTests/array/short_fixed_array_cleanup.sol @@ -11,8 +11,8 @@ contract c { // compileToEwasm: also // compileViaYul: also // ---- -// storage: empty +// storageEmpty -> 1 // fill() -> -// storage: nonempty +// storageEmpty -> 0 // clear() -> -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/builtins/storage/storage_empty.sol b/test/libsolidity/semanticTests/builtins/storage/storage_empty.sol new file mode 100644 index 000000000..8fd5a635e --- /dev/null +++ b/test/libsolidity/semanticTests/builtins/storage/storage_empty.sol @@ -0,0 +1,6 @@ +contract StorageEmpty { +} +// ==== +// compileViaYul: also +// ---- +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/builtins/storage/storage_nonempty.sol b/test/libsolidity/semanticTests/builtins/storage/storage_nonempty.sol new file mode 100644 index 000000000..9c8a582e7 --- /dev/null +++ b/test/libsolidity/semanticTests/builtins/storage/storage_nonempty.sol @@ -0,0 +1,10 @@ +contract StorageNotEmpty { + uint256 x; + function set(uint256 _a) public { x = _a; } +} +// ==== +// compileViaYul: also +// ---- +// storageEmpty -> 1 +// set(uint256): 1 -> +// storageEmpty -> 0 diff --git a/test/libsolidity/semanticTests/storage/empty_nonempty_empty.sol b/test/libsolidity/semanticTests/storage/empty_nonempty_empty.sol index 234f0191f..eeeea2943 100644 --- a/test/libsolidity/semanticTests/storage/empty_nonempty_empty.sol +++ b/test/libsolidity/semanticTests/storage/empty_nonempty_empty.sol @@ -6,26 +6,26 @@ contract Test { // compileViaYul: also // ---- // set(bytes): 0x20, 3, "abc" -// storage: nonempty +// storageEmpty -> 0 // set(bytes): 0x20, 0 -// storage: empty +// storageEmpty -> 1 // set(bytes): 0x20, 31, "1234567890123456789012345678901" -// storage: nonempty +// storageEmpty -> 0 // set(bytes): 0x20, 36, "12345678901234567890123456789012", "XXXX" -// storage: nonempty +// storageEmpty -> 0 // set(bytes): 0x20, 3, "abc" -// storage: nonempty +// storageEmpty -> 0 // set(bytes): 0x20, 0 -// storage: empty +// storageEmpty -> 1 // set(bytes): 0x20, 3, "abc" -// storage: nonempty +// storageEmpty -> 0 // set(bytes): 0x20, 36, "12345678901234567890123456789012", "XXXX" -// storage: nonempty +// storageEmpty -> 0 // set(bytes): 0x20, 0 -// storage: empty +// storageEmpty -> 1 // set(bytes): 0x20, 66, "12345678901234567890123456789012", "12345678901234567890123456789012", "12" -// storage: nonempty +// storageEmpty -> 0 // set(bytes): 0x20, 3, "abc" -// storage: nonempty +// storageEmpty -> 0 // set(bytes): 0x20, 0 -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/structs/struct_containing_bytes_copy_and_delete.sol b/test/libsolidity/semanticTests/structs/struct_containing_bytes_copy_and_delete.sol index 363a44023..42bb2a118 100644 --- a/test/libsolidity/semanticTests/structs/struct_containing_bytes_copy_and_delete.sol +++ b/test/libsolidity/semanticTests/structs/struct_containing_bytes_copy_and_delete.sol @@ -23,16 +23,16 @@ contract c { // ==== // compileViaYul: also // ---- -// storage: empty +// storageEmpty -> 1 // set(uint256,bytes,uint256): 12, 0x60, 13, 33, "12345678901234567890123456789012", "3" -> true // gas irOptimized: 124227 // gas legacy: 124736 // gas legacyOptimized: 124179 // test(uint256): 32 -> "3" -// storage: nonempty +// storageEmpty -> 0 // copy() -> true -// storage: empty +// storageEmpty -> 1 // set(uint256,bytes,uint256): 12, 0x60, 13, 33, "12345678901234567890123456789012", "3" -> true -// storage: nonempty +// storageEmpty -> 0 // del() -> true -// storage: empty +// storageEmpty -> 1 diff --git a/test/libsolidity/util/SoltestTypes.h b/test/libsolidity/util/SoltestTypes.h index a19378030..b746fd80a 100644 --- a/test/libsolidity/util/SoltestTypes.h +++ b/test/libsolidity/util/SoltestTypes.h @@ -294,9 +294,8 @@ struct FunctionCall LowLevel, /// Marks a library deployment call. Library, - /// Check that the storage of the current contract is empty or non-empty. - Storage, /// Call to a builtin. + /// Builtins get registered in `SemanticTest::initializeBuiltins()`. Builtin }; Kind kind = Kind::Regular; diff --git a/test/libsolidity/util/TestFileParser.cpp b/test/libsolidity/util/TestFileParser.cpp index 19819ac1c..64ca552b8 100644 --- a/test/libsolidity/util/TestFileParser.cpp +++ b/test/libsolidity/util/TestFileParser.cpp @@ -106,21 +106,6 @@ vector TestFileParser::parseFunctionCall call.kind = FunctionCall::Kind::Library; call.expectations.failure = false; } - else if (accept(Token::Storage, true)) - { - expect(Token::Colon); - call.expectations.failure = false; - call.expectations.result.push_back(Parameter()); - // empty / non-empty is encoded as false / true - if (m_scanner.currentLiteral() == "empty") - call.expectations.result.back().rawBytes = bytes(1, uint8_t(false)); - else if (m_scanner.currentLiteral() == "nonempty") - call.expectations.result.back().rawBytes = bytes(1, uint8_t(true)); - else - BOOST_THROW_EXCEPTION(TestParserError("Expected \"empty\" or \"nonempty\".")); - call.kind = FunctionCall::Kind::Storage; - m_scanner.scanNextToken(); - } else { bool lowLevelCall = false; diff --git a/test/libsolidity/util/TestFileParserTests.cpp b/test/libsolidity/util/TestFileParserTests.cpp index 30d501669..02e95a355 100644 --- a/test/libsolidity/util/TestFileParserTests.cpp +++ b/test/libsolidity/util/TestFileParserTests.cpp @@ -958,28 +958,6 @@ BOOST_AUTO_TEST_CASE(library) ); } -BOOST_AUTO_TEST_CASE(empty_storage) -{ - char const* source = R"( - // storage: empty - )"; - auto const calls = parse(source); - BOOST_REQUIRE_EQUAL(calls.size(), 1); - BOOST_CHECK(calls.at(0).kind == FunctionCall::Kind::Storage); - BOOST_CHECK(calls.at(0).expectations.result.front().rawBytes == bytes(1, 0)); -} - -BOOST_AUTO_TEST_CASE(nonempty_storage) -{ - char const* source = R"( - // storage: nonempty - )"; - auto const calls = parse(source); - BOOST_REQUIRE_EQUAL(calls.size(), 1); - BOOST_CHECK(calls.at(0).kind == FunctionCall::Kind::Storage); - BOOST_CHECK(calls.at(0).expectations.result.front().rawBytes == bytes(1, 1)); -} - BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/util/TestFunctionCall.cpp b/test/libsolidity/util/TestFunctionCall.cpp index 0e411a458..65300512c 100644 --- a/test/libsolidity/util/TestFunctionCall.cpp +++ b/test/libsolidity/util/TestFunctionCall.cpp @@ -61,23 +61,6 @@ string TestFunctionCall::format( stream << _linePrefix << newline << ws << "library:" << ws << m_call.signature; return; } - else if (m_call.kind == FunctionCall::Kind::Storage) - { - stream << _linePrefix << newline << ws << "storage" << colon << ws; - soltestAssert(m_rawBytes.size() == 1, ""); - soltestAssert(m_call.expectations.rawBytes().size() == 1, ""); - bool isEmpty = - _renderMode == RenderMode::ActualValuesExpectedGas ? - m_rawBytes.front() == 0 : - m_call.expectations.rawBytes().front() == 0; - string output = isEmpty ? "empty" : "nonempty"; - if (_renderMode == RenderMode::ActualValuesExpectedGas && !matchesExpectation()) - AnsiColorized(stream, highlight, {util::formatting::RED_BACKGROUND}) << output; - else - stream << output; - - return; - } /// Formats the function signature. This is the same independent from the display-mode. stream << _linePrefix << newline << ws << m_call.signature;