diff --git a/test/libsolidity/SemanticTest.cpp b/test/libsolidity/SemanticTest.cpp index d30908627..b6c2b7e03 100644 --- a/test/libsolidity/SemanticTest.cpp +++ b/test/libsolidity/SemanticTest.cpp @@ -31,6 +31,7 @@ #include #include #include +#include using namespace std; using namespace solidity; @@ -52,6 +53,8 @@ SemanticTest::SemanticTest(string const& _filename, langutil::EVMVersion _evmVer m_lineOffset(m_reader.lineNumber()), m_enforceViaYul(enforceViaYul) { + initializeBuiltins(); + string choice = m_reader.stringSetting("compileViaYul", "default"); if (choice == "also") { @@ -107,6 +110,15 @@ SemanticTest::SemanticTest(string const& _filename, langutil::EVMVersion _evmVer soltestAssert(!m_tests.empty(), "No tests specified in " + _filename); } +void SemanticTest::initializeBuiltins() +{ + m_builtins["storage_empty"] = [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) { TestResult result = TestResult::Success; @@ -190,16 +202,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/SemanticTest.h b/test/libsolidity/SemanticTest.h index 6ba62c9f4..38d86197d 100644 --- a/test/libsolidity/SemanticTest.h +++ b/test/libsolidity/SemanticTest.h @@ -61,6 +61,9 @@ public: private: TestResult runTest(std::ostream& _stream, std::string const& _linePrefix, bool _formatted, bool _compileViaYul, bool _compileToEwasm); + + void initializeBuiltins(); + SourceMap m_sources; std::size_t m_lineOffset; std::vector m_tests; diff --git a/test/libsolidity/semanticTests/array/byte_array_storage_layout.sol b/test/libsolidity/semanticTests/array/byte_array_storage_layout.sol index 588b954ae..9594bd230 100644 --- a/test/libsolidity/semanticTests/array/byte_array_storage_layout.sol +++ b/test/libsolidity/semanticTests/array/byte_array_storage_layout.sol @@ -41,10 +41,10 @@ contract c { // ==== // compileViaYul: also // ---- -// storage: empty +// storage_empty -> true // test_short() -> 1780731860627700044960722568376587075150542249149356309979516913770823710 -// storage: nonempty +// storage_empty -> false // test_long() -> 67 -// storage: nonempty +// storage_empty -> false // test_pop() -> 1780731860627700044960722568376592200742329637303199754547598369979433020 -// storage: nonempty +// storage_empty -> false 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 a600bffdd..e1abe3354 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol @@ -37,6 +37,6 @@ contract c { // compileViaYul: also // ---- // test() -> 0x02000202 -// storage: empty +// storage_empty -> true // clear() -> 0, 0 -// storage: empty +// storage_empty -> true 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..ddbc372c1 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 +// storage_empty -> true 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 097c86dfe..444208690 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 @@ -19,4 +19,4 @@ contract c { // compileViaYul: also // ---- // test() -> 4, 5 -// storage: empty +// storage_empty -> true diff --git a/test/libsolidity/semanticTests/array/copying/bytes_inside_mappings.sol b/test/libsolidity/semanticTests/array/copying/bytes_inside_mappings.sol index 2decb1562..4105e674b 100644 --- a/test/libsolidity/semanticTests/array/copying/bytes_inside_mappings.sol +++ b/test/libsolidity/semanticTests/array/copying/bytes_inside_mappings.sol @@ -8,10 +8,10 @@ contract c { // ---- // set(uint256): 1, 2 -> true // set(uint256): 2, 2, 3, 4, 5 -> true -// storage: nonempty +// storage_empty -> false // copy(uint256,uint256): 1, 2 -> true -// storage: nonempty +// storage_empty -> false // copy(uint256,uint256): 99, 1 -> true -// storage: nonempty +// storage_empty -> false // copy(uint256,uint256): 99, 2 -> true -// storage: empty +// storage_empty -> true 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 f318ee099..ded14b2aa 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 @@ -39,4 +39,4 @@ contract C { // f() -> 0x40, 0x80, 6, 0x6162636465660000000000000000000000000000000000000000000000000000, 0x49, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738390000000000000000000000000000000000000000000000 // g() -> 0x40, 0xc0, 0x49, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738390000000000000000000000000000000000000000000000, 0x11, 0x3132333435363738393233343536373839000000000000000000000000000000 // h() -> 0x40, 0x60, 0x00, 0x00 -// storage: empty +// storage_empty -> true 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 ace34e872..ceba14c3e 100644 --- a/test/libsolidity/semanticTests/array/copying/copy_removes_bytes_data.sol +++ b/test/libsolidity/semanticTests/array/copying/copy_removes_bytes_data.sol @@ -9,6 +9,6 @@ contract c { // compileViaYul: also // ---- // set(): 1, 2, 3, 4, 5 -> true -// storage: nonempty +// storage_empty -> false // reset() -> true -// storage: empty +// storage_empty -> true 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..ec61d0f16 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 +// storage_empty -> false // del(): 7 -> true -// storage: empty +// storage_empty -> true diff --git a/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol b/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol index 07c3f63aa..d10564482 100644 --- a/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol +++ b/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol @@ -14,10 +14,10 @@ contract c { // ==== // compileViaYul: also // ---- -// storage: empty +// storage_empty -> true // fill() -> -// storage: nonempty +// storage_empty -> false // halfClear() -> -// storage: nonempty +// storage_empty -> false // fullClear() -> -// storage: empty +// storage_empty -> true diff --git a/test/libsolidity/semanticTests/array/dynamic_multi_array_cleanup.sol b/test/libsolidity/semanticTests/array/dynamic_multi_array_cleanup.sol index c58abad52..cc083876e 100644 --- a/test/libsolidity/semanticTests/array/dynamic_multi_array_cleanup.sol +++ b/test/libsolidity/semanticTests/array/dynamic_multi_array_cleanup.sol @@ -16,8 +16,8 @@ contract c { // ==== // compileViaYul: also // ---- -// storage: empty +// storage_empty -> true // fill() -> 8 -// storage: nonempty +// storage_empty -> false // clear() -> -// storage: empty +// storage_empty -> true diff --git a/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol b/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol index 074173e9a..2778331d4 100644 --- a/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol +++ b/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol @@ -11,8 +11,8 @@ contract c { // compileViaYul: also // compileToEwasm: also // ---- -// storage: empty +// storage_empty -> true // fill() -> -// storage: nonempty +// storage_empty -> false // clear() -> -// storage: empty +// storage_empty -> true 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 ece182803..370d91cd9 100644 --- a/test/libsolidity/semanticTests/array/pop/array_pop_array_transition.sol +++ b/test/libsolidity/semanticTests/array/pop/array_pop_array_transition.sol @@ -25,4 +25,4 @@ contract c { // compileViaYul: also // ---- // test() -> 1, 2, 3 -// storage: empty +// storage_empty -> true 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..e0bfa597f 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 +// storage_empty -> true 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 8cecac615..ea1a9b708 100644 --- a/test/libsolidity/semanticTests/array/pop/array_pop_uint16_transition.sol +++ b/test/libsolidity/semanticTests/array/pop/array_pop_uint16_transition.sol @@ -20,4 +20,4 @@ contract c { // compileViaYul: also // ---- // test() -> 38, 28, 18 -// storage: empty +// storage_empty -> true 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 467774cc2..65ae92217 100644 --- a/test/libsolidity/semanticTests/array/pop/array_pop_uint24_transition.sol +++ b/test/libsolidity/semanticTests/array/pop/array_pop_uint24_transition.sol @@ -20,4 +20,4 @@ contract c { // compileViaYul: also // ---- // test() -> 20, 10 -// storage: empty +// storage_empty -> true 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 b4d0adfc0..baf38202b 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 @@ -18,4 +18,4 @@ contract c { // compileViaYul: also // ---- // test() -> true -// storage: empty +// storage_empty -> true 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 a230eb033..8227529d6 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 @@ -17,4 +17,4 @@ contract c { // compileViaYul: also // ---- // test() -> -// storage: empty +// storage_empty -> true 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 ce4e8dae9..278c219cc 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 { // compileToEwasm: also // ---- // test() -> -// storage: empty +// storage_empty -> true diff --git a/test/libsolidity/semanticTests/array/short_fixed_array_cleanup.sol b/test/libsolidity/semanticTests/array/short_fixed_array_cleanup.sol index 2dd2b8f50..45f989b15 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 { // compileViaYul: also // compileToEwasm: also // ---- -// storage: empty +// storage_empty -> true // fill() -> -// storage: nonempty +// storage_empty -> false // clear() -> -// storage: empty +// storage_empty -> true 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..71fd0a11d --- /dev/null +++ b/test/libsolidity/semanticTests/builtins/storage/storage_empty.sol @@ -0,0 +1,6 @@ +contract StorageEmpty { +} +// ==== +// compileViaYul: also +// ---- +// storage_empty -> true 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..d0cbacc70 --- /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 +// ---- +// storage_empty -> true +// set(uint256): 1 -> +// storage_empty -> false diff --git a/test/libsolidity/semanticTests/storage/empty_nonempty_empty.sol b/test/libsolidity/semanticTests/storage/empty_nonempty_empty.sol index 234f0191f..8179af395 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 +// storage_empty -> false // set(bytes): 0x20, 0 -// storage: empty +// storage_empty -> true // set(bytes): 0x20, 31, "1234567890123456789012345678901" -// storage: nonempty +// storage_empty -> false // set(bytes): 0x20, 36, "12345678901234567890123456789012", "XXXX" -// storage: nonempty +// storage_empty -> false // set(bytes): 0x20, 3, "abc" -// storage: nonempty +// storage_empty -> false // set(bytes): 0x20, 0 -// storage: empty +// storage_empty -> true // set(bytes): 0x20, 3, "abc" -// storage: nonempty +// storage_empty -> false // set(bytes): 0x20, 36, "12345678901234567890123456789012", "XXXX" -// storage: nonempty +// storage_empty -> false // set(bytes): 0x20, 0 -// storage: empty +// storage_empty -> true // set(bytes): 0x20, 66, "12345678901234567890123456789012", "12345678901234567890123456789012", "12" -// storage: nonempty +// storage_empty -> false // set(bytes): 0x20, 3, "abc" -// storage: nonempty +// storage_empty -> false // set(bytes): 0x20, 0 -// storage: empty +// storage_empty -> true 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 e0f8d9fd9..9825ca5d4 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,13 +23,13 @@ contract c { // ==== // compileViaYul: also // ---- -// storage: empty +// storage_empty -> true // set(uint256,bytes,uint256): 12, 0x60, 13, 33, "12345678901234567890123456789012", "3" -> true // test(uint256): 32 -> "3" -// storage: nonempty +// storage_empty -> false // copy() -> true -// storage: empty +// storage_empty -> true // set(uint256,bytes,uint256): 12, 0x60, 13, 33, "12345678901234567890123456789012", "3" -> true -// storage: nonempty +// storage_empty -> false // del() -> true -// storage: empty +// storage_empty -> true diff --git a/test/libsolidity/util/SoltestTypes.h b/test/libsolidity/util/SoltestTypes.h index fc8c1dfc1..10709aea1 100644 --- a/test/libsolidity/util/SoltestTypes.h +++ b/test/libsolidity/util/SoltestTypes.h @@ -290,8 +290,6 @@ 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. Builtin }; diff --git a/test/libsolidity/util/TestFileParser.cpp b/test/libsolidity/util/TestFileParser.cpp index 2ba3a9cad..06b9b4cc8 100644 --- a/test/libsolidity/util/TestFileParser.cpp +++ b/test/libsolidity/util/TestFileParser.cpp @@ -85,21 +85,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 e13fccf09..ca51b09f2 100644 --- a/test/libsolidity/util/TestFunctionCall.cpp +++ b/test/libsolidity/util/TestFunctionCall.cpp @@ -60,20 +60,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 = _renderResult ? m_rawBytes.front() == 0 : m_call.expectations.rawBytes().front() == 0; - string output = isEmpty ? "empty" : "nonempty"; - if (_renderResult && !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;