From 816d8021e4f57b1b32eb3ce1fbfa421a585a0f0f Mon Sep 17 00:00:00 2001 From: soroosh-sdi Date: Fri, 1 Oct 2021 09:18:52 +0330 Subject: [PATCH] Remove linking to unqualified library name - SemanticTests accepts fully qualified library name and also unqualifed library name when the library is defined in the same file for convenience. - commandline tests are added! Signed-off-by: soroosh-sdi --- Changelog.md | 2 +- libevmasm/LinkerObject.cpp | 8 ---- .../linking_qualified_library_name/args | 1 + .../contract1.sol | 10 ++++ .../linking_qualified_library_name/math.sol | 6 +++ .../linking_qualified_library_name/output | 8 ++++ .../output | 26 ---------- .../args | 1 + .../err | 0 .../input.yul | 6 +++ .../output | 21 ++++++++ .../args | 1 + .../err | 1 + .../input.yul | 0 .../output | 21 ++++++++ .../args | 2 +- .../err | 1 + .../input.yul | 6 +++ .../output | 21 ++++++++ .../args | 1 + .../err | 1 + .../input.yul | 6 +++ .../output | 21 ++++++++ .../linking_unqualified_library_name/args | 1 + .../contract1.sol | 11 +++++ .../contract2.sol | 10 ++++ .../error.sol | 6 +++ .../linking_unqualified_library_name/math.sol | 6 +++ .../linking_unqualified_library_name/output | 20 ++++++++ test/libsolidity/SemanticTest.cpp | 9 +++- test/libsolidity/SolidityEndToEndTest.cpp | 48 +++++++++---------- .../libraries/library_address_via_module.sol | 2 +- test/libsolidity/util/TestFileParser.cpp | 22 ++++++++- 33 files changed, 242 insertions(+), 64 deletions(-) create mode 100644 test/cmdlineTests/linking_qualified_library_name/args create mode 100644 test/cmdlineTests/linking_qualified_library_name/contract1.sol create mode 100644 test/cmdlineTests/linking_qualified_library_name/math.sol create mode 100644 test/cmdlineTests/linking_qualified_library_name/output delete mode 100644 test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/output create mode 100644 test/cmdlineTests/linking_strict_assembly_qualified_library_qualified_reference/args rename test/cmdlineTests/{linking_strict_assembly_no_file_name_in_link_reference => linking_strict_assembly_qualified_library_qualified_reference}/err (100%) create mode 100644 test/cmdlineTests/linking_strict_assembly_qualified_library_qualified_reference/input.yul create mode 100644 test/cmdlineTests/linking_strict_assembly_qualified_library_qualified_reference/output create mode 100644 test/cmdlineTests/linking_strict_assembly_qualified_library_unqualified_reference/args create mode 100644 test/cmdlineTests/linking_strict_assembly_qualified_library_unqualified_reference/err rename test/cmdlineTests/{linking_strict_assembly_no_file_name_in_link_reference => linking_strict_assembly_qualified_library_unqualified_reference}/input.yul (100%) create mode 100644 test/cmdlineTests/linking_strict_assembly_qualified_library_unqualified_reference/output rename test/cmdlineTests/{linking_strict_assembly_no_file_name_in_link_reference => linking_strict_assembly_unqualified_library_qualified_reference}/args (68%) create mode 100644 test/cmdlineTests/linking_strict_assembly_unqualified_library_qualified_reference/err create mode 100644 test/cmdlineTests/linking_strict_assembly_unqualified_library_qualified_reference/input.yul create mode 100644 test/cmdlineTests/linking_strict_assembly_unqualified_library_qualified_reference/output create mode 100644 test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/args create mode 100644 test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/err create mode 100644 test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/input.yul create mode 100644 test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/output create mode 100644 test/cmdlineTests/linking_unqualified_library_name/args create mode 100644 test/cmdlineTests/linking_unqualified_library_name/contract1.sol create mode 100644 test/cmdlineTests/linking_unqualified_library_name/contract2.sol create mode 100644 test/cmdlineTests/linking_unqualified_library_name/error.sol create mode 100644 test/cmdlineTests/linking_unqualified_library_name/math.sol create mode 100644 test/cmdlineTests/linking_unqualified_library_name/output diff --git a/Changelog.md b/Changelog.md index ddfe1648e..60a62a402 100644 --- a/Changelog.md +++ b/Changelog.md @@ -20,7 +20,7 @@ Bugfixes: * SMTChecker: Fix internal error in magic type access (``block``, ``msg``, ``tx``). * TypeChecker: Fix internal error when using user defined value types in public library functions. * Yul IR Generator: Do not output empty switches/if-bodies for empty contracts. - + * Commandline Interface: When linking only accept exact matches for library names passed to the ``--libraries`` option. Library names not prefixed with a file name used to match any library with that name. diff --git a/libevmasm/LinkerObject.cpp b/libevmasm/LinkerObject.cpp index fdb9a460f..07e34acab 100644 --- a/libevmasm/LinkerObject.cpp +++ b/libevmasm/LinkerObject.cpp @@ -73,14 +73,6 @@ LinkerObject::matchLibrary( ) { auto it = _libraryAddresses.find(_linkRefName); - if (it != _libraryAddresses.end()) - return &it->second; - // If the user did not supply a fully qualified library name, - // try to match only the simple library name - size_t colon = _linkRefName.find(':'); - if (colon == string::npos) - return nullptr; - it = _libraryAddresses.find(_linkRefName.substr(colon + 1)); if (it != _libraryAddresses.end()) return &it->second; return nullptr; diff --git a/test/cmdlineTests/linking_qualified_library_name/args b/test/cmdlineTests/linking_qualified_library_name/args new file mode 100644 index 000000000..dc996f46e --- /dev/null +++ b/test/cmdlineTests/linking_qualified_library_name/args @@ -0,0 +1 @@ +linking_qualified_library_name/contract1.sol --bin --libraries linking_qualified_library_name/math.sol:Log:0x7777777777777777777777777777777777777777 diff --git a/test/cmdlineTests/linking_qualified_library_name/contract1.sol b/test/cmdlineTests/linking_qualified_library_name/contract1.sol new file mode 100644 index 000000000..aedea65fa --- /dev/null +++ b/test/cmdlineTests/linking_qualified_library_name/contract1.sol @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; + +import "linking_qualified_library_name/math.sol"; + +contract C { + function foo() public { + Log.log10(); + } +} diff --git a/test/cmdlineTests/linking_qualified_library_name/math.sol b/test/cmdlineTests/linking_qualified_library_name/math.sol new file mode 100644 index 000000000..62f00ec34 --- /dev/null +++ b/test/cmdlineTests/linking_qualified_library_name/math.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; + +library Log { + function log10() external {} +} diff --git a/test/cmdlineTests/linking_qualified_library_name/output b/test/cmdlineTests/linking_qualified_library_name/output new file mode 100644 index 000000000..834874bf8 --- /dev/null +++ b/test/cmdlineTests/linking_qualified_library_name/output @@ -0,0 +1,8 @@ + +======= linking_qualified_library_name/contract1.sol:C ======= +Binary: + + +======= linking_qualified_library_name/math.sol:Log ======= +Binary: + diff --git a/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/output b/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/output deleted file mode 100644 index 5d5b87c67..000000000 --- a/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/output +++ /dev/null @@ -1,26 +0,0 @@ - -======= linking_strict_assembly_no_file_name_in_link_reference/input.yul (EVM) ======= - -Pretty printed source: -object "a" { - code { - let addr := linkersymbol("L") - sstore(0, addr) - } -} - - -Binary representation: -7312345678901234567890123456789012345678908060005550 - -Text representation: - /* "linking_strict_assembly_no_file_name_in_link_reference/input.yul":44:61 */ - linkerSymbol("8aa64f937099b65a4febc243a5ae0f2d6416bb9e473c30dd29c1ee498fb7c5a8") - /* "linking_strict_assembly_no_file_name_in_link_reference/input.yul":80:84 */ - dup1 - /* "linking_strict_assembly_no_file_name_in_link_reference/input.yul":77:78 */ - 0x00 - /* "linking_strict_assembly_no_file_name_in_link_reference/input.yul":70:85 */ - sstore - /* "linking_strict_assembly_no_file_name_in_link_reference/input.yul":22:91 */ - pop diff --git a/test/cmdlineTests/linking_strict_assembly_qualified_library_qualified_reference/args b/test/cmdlineTests/linking_strict_assembly_qualified_library_qualified_reference/args new file mode 100644 index 000000000..1c8721f24 --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_qualified_library_qualified_reference/args @@ -0,0 +1 @@ +--strict-assembly --libraries :L=0x1234567890123456789012345678901234567890 --debug-info none diff --git a/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/err b/test/cmdlineTests/linking_strict_assembly_qualified_library_qualified_reference/err similarity index 100% rename from test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/err rename to test/cmdlineTests/linking_strict_assembly_qualified_library_qualified_reference/err diff --git a/test/cmdlineTests/linking_strict_assembly_qualified_library_qualified_reference/input.yul b/test/cmdlineTests/linking_strict_assembly_qualified_library_qualified_reference/input.yul new file mode 100644 index 000000000..e5c134b87 --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_qualified_library_qualified_reference/input.yul @@ -0,0 +1,6 @@ +object "a" { + code { + let addr := linkersymbol(":L") + sstore(0, addr) + } +} diff --git a/test/cmdlineTests/linking_strict_assembly_qualified_library_qualified_reference/output b/test/cmdlineTests/linking_strict_assembly_qualified_library_qualified_reference/output new file mode 100644 index 000000000..261856e96 --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_qualified_library_qualified_reference/output @@ -0,0 +1,21 @@ + +======= linking_strict_assembly_qualified_library_qualified_reference/input.yul (EVM) ======= + +Pretty printed source: +object "a" { + code { + let addr := linkersymbol(":L") + sstore(0, addr) + } +} + + +Binary representation: +7312345678901234567890123456789012345678908060005550 + +Text representation: + linkerSymbol("20a18a9bf97d889dcf77111b674da319a4e9e3e05d3f4df9e0bf5c588dd4f0f8") + dup1 + 0x00 + sstore + pop diff --git a/test/cmdlineTests/linking_strict_assembly_qualified_library_unqualified_reference/args b/test/cmdlineTests/linking_strict_assembly_qualified_library_unqualified_reference/args new file mode 100644 index 000000000..1c8721f24 --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_qualified_library_unqualified_reference/args @@ -0,0 +1 @@ +--strict-assembly --libraries :L=0x1234567890123456789012345678901234567890 --debug-info none diff --git a/test/cmdlineTests/linking_strict_assembly_qualified_library_unqualified_reference/err b/test/cmdlineTests/linking_strict_assembly_qualified_library_unqualified_reference/err new file mode 100644 index 000000000..014a1178f --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_qualified_library_unqualified_reference/err @@ -0,0 +1 @@ +Warning: Yul is still experimental. Please use the output with care. diff --git a/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/input.yul b/test/cmdlineTests/linking_strict_assembly_qualified_library_unqualified_reference/input.yul similarity index 100% rename from test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/input.yul rename to test/cmdlineTests/linking_strict_assembly_qualified_library_unqualified_reference/input.yul diff --git a/test/cmdlineTests/linking_strict_assembly_qualified_library_unqualified_reference/output b/test/cmdlineTests/linking_strict_assembly_qualified_library_unqualified_reference/output new file mode 100644 index 000000000..84204264d --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_qualified_library_unqualified_reference/output @@ -0,0 +1,21 @@ + +======= linking_strict_assembly_qualified_library_unqualified_reference/input.yul (EVM) ======= + +Pretty printed source: +object "a" { + code { + let addr := linkersymbol("L") + sstore(0, addr) + } +} + + +Binary representation: +73__$8aa64f937099b65a4febc243a5ae0f2d64$__8060005550 + +Text representation: + linkerSymbol("8aa64f937099b65a4febc243a5ae0f2d6416bb9e473c30dd29c1ee498fb7c5a8") + dup1 + 0x00 + sstore + pop diff --git a/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/args b/test/cmdlineTests/linking_strict_assembly_unqualified_library_qualified_reference/args similarity index 68% rename from test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/args rename to test/cmdlineTests/linking_strict_assembly_unqualified_library_qualified_reference/args index c7de26a69..c8299b9b6 100644 --- a/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/args +++ b/test/cmdlineTests/linking_strict_assembly_unqualified_library_qualified_reference/args @@ -1 +1 @@ ---strict-assembly --libraries L=0x1234567890123456789012345678901234567890 +--strict-assembly --libraries L=0x1234567890123456789012345678901234567890 --debug-info none diff --git a/test/cmdlineTests/linking_strict_assembly_unqualified_library_qualified_reference/err b/test/cmdlineTests/linking_strict_assembly_unqualified_library_qualified_reference/err new file mode 100644 index 000000000..014a1178f --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_unqualified_library_qualified_reference/err @@ -0,0 +1 @@ +Warning: Yul is still experimental. Please use the output with care. diff --git a/test/cmdlineTests/linking_strict_assembly_unqualified_library_qualified_reference/input.yul b/test/cmdlineTests/linking_strict_assembly_unqualified_library_qualified_reference/input.yul new file mode 100644 index 000000000..e5c134b87 --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_unqualified_library_qualified_reference/input.yul @@ -0,0 +1,6 @@ +object "a" { + code { + let addr := linkersymbol(":L") + sstore(0, addr) + } +} diff --git a/test/cmdlineTests/linking_strict_assembly_unqualified_library_qualified_reference/output b/test/cmdlineTests/linking_strict_assembly_unqualified_library_qualified_reference/output new file mode 100644 index 000000000..e7dc14542 --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_unqualified_library_qualified_reference/output @@ -0,0 +1,21 @@ + +======= linking_strict_assembly_unqualified_library_qualified_reference/input.yul (EVM) ======= + +Pretty printed source: +object "a" { + code { + let addr := linkersymbol(":L") + sstore(0, addr) + } +} + + +Binary representation: +73__$20a18a9bf97d889dcf77111b674da319a4$__8060005550 + +Text representation: + linkerSymbol("20a18a9bf97d889dcf77111b674da319a4e9e3e05d3f4df9e0bf5c588dd4f0f8") + dup1 + 0x00 + sstore + pop diff --git a/test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/args b/test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/args new file mode 100644 index 000000000..c8299b9b6 --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/args @@ -0,0 +1 @@ +--strict-assembly --libraries L=0x1234567890123456789012345678901234567890 --debug-info none diff --git a/test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/err b/test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/err new file mode 100644 index 000000000..014a1178f --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/err @@ -0,0 +1 @@ +Warning: Yul is still experimental. Please use the output with care. diff --git a/test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/input.yul b/test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/input.yul new file mode 100644 index 000000000..fcfab5bcf --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/input.yul @@ -0,0 +1,6 @@ +object "a" { + code { + let addr := linkersymbol("L") + sstore(0, addr) + } +} diff --git a/test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/output b/test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/output new file mode 100644 index 000000000..103b67e2e --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_unqualified_library_unqualified_reference/output @@ -0,0 +1,21 @@ + +======= linking_strict_assembly_unqualified_library_unqualified_reference/input.yul (EVM) ======= + +Pretty printed source: +object "a" { + code { + let addr := linkersymbol("L") + sstore(0, addr) + } +} + + +Binary representation: +7312345678901234567890123456789012345678908060005550 + +Text representation: + linkerSymbol("8aa64f937099b65a4febc243a5ae0f2d6416bb9e473c30dd29c1ee498fb7c5a8") + dup1 + 0x00 + sstore + pop diff --git a/test/cmdlineTests/linking_unqualified_library_name/args b/test/cmdlineTests/linking_unqualified_library_name/args new file mode 100644 index 000000000..6118acf02 --- /dev/null +++ b/test/cmdlineTests/linking_unqualified_library_name/args @@ -0,0 +1 @@ +linking_unqualified_library_name/contract1.sol linking_unqualified_library_name/contract2.sol --bin --libraries Log:0x7777777777777777777777777777777777777777 diff --git a/test/cmdlineTests/linking_unqualified_library_name/contract1.sol b/test/cmdlineTests/linking_unqualified_library_name/contract1.sol new file mode 100644 index 000000000..38e43f9d4 --- /dev/null +++ b/test/cmdlineTests/linking_unqualified_library_name/contract1.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; + + +import "linking_unqualified_library_name/error.sol"; + +contract C { + function foo() public { + Log.print(); + } +} diff --git a/test/cmdlineTests/linking_unqualified_library_name/contract2.sol b/test/cmdlineTests/linking_unqualified_library_name/contract2.sol new file mode 100644 index 000000000..6ddb8ad6e --- /dev/null +++ b/test/cmdlineTests/linking_unqualified_library_name/contract2.sol @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; + +import "linking_unqualified_library_name/math.sol"; + +contract C { + function foo() public { + Log.log10(); + } +} diff --git a/test/cmdlineTests/linking_unqualified_library_name/error.sol b/test/cmdlineTests/linking_unqualified_library_name/error.sol new file mode 100644 index 000000000..ec29bda35 --- /dev/null +++ b/test/cmdlineTests/linking_unqualified_library_name/error.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; + +library Log { + function print() external {} +} diff --git a/test/cmdlineTests/linking_unqualified_library_name/math.sol b/test/cmdlineTests/linking_unqualified_library_name/math.sol new file mode 100644 index 000000000..62f00ec34 --- /dev/null +++ b/test/cmdlineTests/linking_unqualified_library_name/math.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; + +library Log { + function log10() external {} +} diff --git a/test/cmdlineTests/linking_unqualified_library_name/output b/test/cmdlineTests/linking_unqualified_library_name/output new file mode 100644 index 000000000..be64a93c9 --- /dev/null +++ b/test/cmdlineTests/linking_unqualified_library_name/output @@ -0,0 +1,20 @@ + +======= linking_unqualified_library_name/contract1.sol:C ======= +Binary: +__$cdf6d5ab08a9335b02e7c2475aa27d04fa$__ + +// $cdf6d5ab08a9335b02e7c2475aa27d04fa$ -> linking_unqualified_library_name/error.sol:Log + +======= linking_unqualified_library_name/contract2.sol:C ======= +Binary: +__$22584241c2fc4f2884d5222245463779a8$__ + +// $22584241c2fc4f2884d5222245463779a8$ -> linking_unqualified_library_name/math.sol:Log + +======= linking_unqualified_library_name/error.sol:Log ======= +Binary: + + +======= linking_unqualified_library_name/math.sol:Log ======= +Binary: + diff --git a/test/libsolidity/SemanticTest.cpp b/test/libsolidity/SemanticTest.cpp index 56e1b1a8b..c5ee04044 100644 --- a/test/libsolidity/SemanticTest.cpp +++ b/test/libsolidity/SemanticTest.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include using namespace std; @@ -383,7 +384,13 @@ TestCase::TestResult SemanticTest::runTest( soltestAssert( deploy(test.call().signature, 0, {}, libraries) && m_transactionSuccessful, "Failed to deploy library " + test.call().signature); - libraries[test.call().signature] = m_contractAddress; + // For convenience, in semantic tests we assume that an unqualified name like `L` is equivalent to one + // with an empty source unit name (`:L`). This is fine because the compiler never uses unqualified + // names in the Yul code it produces and does not allow `linkersymbol()` at all in inline assembly. + if (test.call().signature.find(':') == string::npos) + libraries[":" + test.call().signature] = m_contractAddress; + else + libraries[test.call().signature] = m_contractAddress; continue; } else diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index e724f9998..e5a6b8cf7 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1565,7 +1565,7 @@ BOOST_AUTO_TEST_CASE(library_call_in_homestead) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); ABI_CHECK(callContractFunction("f()"), encodeArgs()); ABI_CHECK(callContractFunction("sender()"), encodeArgs(m_sender)); ) @@ -1598,7 +1598,7 @@ BOOST_AUTO_TEST_CASE(library_call_protection) ABI_CHECK(callContractFunction("np(Lib.S storage)", 0), encodeArgs()); ABI_CHECK(callContractFunction("v(Lib.S storage)", 0), encodeArgs(m_sender)); ABI_CHECK(callContractFunction("pu()"), encodeArgs(2)); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); ABI_CHECK(callContractFunction("s()"), encodeArgs(0)); ABI_CHECK(callContractFunction("np()"), encodeArgs(m_sender)); ABI_CHECK(callContractFunction("s()"), encodeArgs(3)); @@ -1627,7 +1627,7 @@ BOOST_AUTO_TEST_CASE(library_staticcall_delegatecall) } )"; compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); ABI_CHECK(callContractFunction("f()"), encodeArgs(1)); } @@ -1883,7 +1883,7 @@ BOOST_AUTO_TEST_CASE(struct_referencing) compileAndRun(sourceCode, 0, "L"); ABI_CHECK(callContractFunction("f()"), encodeArgs(0, 3)); ABI_CHECK(callContractFunction("g()"), encodeArgs(4)); - compileAndRun(sourceCode, 0, "C", bytes(), map{ {"L", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{ {":L", m_contractAddress}}); ABI_CHECK(callContractFunction("f()"), encodeArgs(1)); ABI_CHECK(callContractFunction("g()"), encodeArgs(2)); ABI_CHECK(callContractFunction("h()"), encodeArgs(0, 5)); @@ -1932,7 +1932,7 @@ BOOST_AUTO_TEST_CASE(enum_referencing) compileAndRun(sourceCode, 0, "L"); ABI_CHECK(callContractFunction("f()"), encodeArgs(1)); ABI_CHECK(callContractFunction("g()"), encodeArgs(3)); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"L", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{{":L", m_contractAddress}}); ABI_CHECK(callContractFunction("f()"), encodeArgs(3)); ABI_CHECK(callContractFunction("g()"), encodeArgs(3)); ABI_CHECK(callContractFunction("h()"), encodeArgs(1)); @@ -2763,7 +2763,7 @@ BOOST_AUTO_TEST_CASE(library_call) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); ABI_CHECK(callContractFunction("f(uint256)", u256(33)), encodeArgs(u256(33) * 9)); ) } @@ -2781,7 +2781,7 @@ BOOST_AUTO_TEST_CASE(library_function_external) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); ABI_CHECK(callContractFunction("f(bytes)", u256(0x20), u256(5), "abcde"), encodeArgs("c")); ) } @@ -2801,7 +2801,7 @@ BOOST_AUTO_TEST_CASE(library_stray_values) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); ABI_CHECK(callContractFunction("f(uint256)", u256(33)), encodeArgs(u256(42))); ) } @@ -2834,7 +2834,7 @@ BOOST_AUTO_TEST_CASE(internal_types_in_library) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(4), u256(17))); ) } @@ -2868,7 +2868,7 @@ BOOST_AUTO_TEST_CASE(mapping_arguments_in_library) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(1), u256(42)), encodeArgs(u256(0))); ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(2), u256(84)), encodeArgs(u256(0))); ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(21), u256(7)), encodeArgs(u256(0))); @@ -2919,7 +2919,7 @@ BOOST_AUTO_TEST_CASE(mapping_returns_in_library) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(1), u256(42)), encodeArgs(u256(0))); ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(2), u256(84)), encodeArgs(u256(0))); ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(21), u256(7)), encodeArgs(u256(0))); @@ -2998,7 +2998,7 @@ BOOST_AUTO_TEST_CASE(mapping_returns_in_library_named) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(0), u256(42), u256(0), u256(0), u256(21), u256(84))); ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(0), u256(42), u256(0), u256(0), u256(21), u256(17))); ) @@ -3029,7 +3029,7 @@ BOOST_AUTO_TEST_CASE(using_library_mappings_public) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1), u256(0), u256(42), u256(23), u256(0), u256(99))); ) } @@ -3065,7 +3065,7 @@ BOOST_AUTO_TEST_CASE(using_library_mappings_external) { string prefix = "pragma abicoder " + string(v2 ? "v2" : "v1") + ";\n"; compileAndRun(prefix + libSourceCode, 0, "Lib"); - compileAndRun(prefix + sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(prefix + sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(2), u256(0), u256(84), u256(46), u256(0), u256(198))); } } @@ -3093,7 +3093,7 @@ BOOST_AUTO_TEST_CASE(using_library_mappings_return) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1), u256(0), u256(42), u256(23), u256(0), u256(99))); ) } @@ -3124,7 +3124,7 @@ BOOST_AUTO_TEST_CASE(using_library_structs) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(7), u256(8))); ) } @@ -3340,7 +3340,7 @@ BOOST_AUTO_TEST_CASE(using_for_function_on_struct) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{{":D", m_contractAddress}}); ABI_CHECK(callContractFunction("f(uint256)", u256(7)), encodeArgs(u256(3 * 7))); ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(3 * 7))); ) @@ -3366,7 +3366,7 @@ BOOST_AUTO_TEST_CASE(using_for_overload) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{{":D", m_contractAddress}}); ABI_CHECK(callContractFunction("f(uint256)", u256(7)), encodeArgs(u256(6 * 7))); ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(6 * 7))); ) @@ -3388,7 +3388,7 @@ BOOST_AUTO_TEST_CASE(using_for_by_name) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{{":D", m_contractAddress}}); ABI_CHECK(callContractFunction("f(uint256)", u256(7)), encodeArgs(u256(6 * 7))); ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(6 * 7))); ) @@ -3411,7 +3411,7 @@ BOOST_AUTO_TEST_CASE(bound_function_in_function) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "L"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"L", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{{":L", m_contractAddress}}); ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(7))); ) } @@ -3432,7 +3432,7 @@ BOOST_AUTO_TEST_CASE(bound_function_in_var) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{{":D", m_contractAddress}}); ABI_CHECK(callContractFunction("f(uint256)", u256(7)), encodeArgs(u256(6 * 7))); ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(6 * 7))); ) @@ -3458,7 +3458,7 @@ BOOST_AUTO_TEST_CASE(bound_function_to_string) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{{":D", m_contractAddress}}); ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(3))); ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(3))); ) @@ -3631,7 +3631,7 @@ BOOST_AUTO_TEST_CASE(payable_function_calls_library) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "L"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"L", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{{":L", m_contractAddress}}); ABI_CHECK(callContractFunctionWithValue("f()", 27), encodeArgs(u256(7))); ) } @@ -4720,7 +4720,7 @@ BOOST_AUTO_TEST_CASE(event_wrong_abi_name) ALSO_VIA_YUL( DISABLE_EWASM_TESTRUN() compileAndRun(sourceCode, 0, "ClientReceipt", bytes()); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"ClientReceipt", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":ClientReceipt", m_contractAddress}}); callContractFunction("f()"); BOOST_REQUIRE_EQUAL(numLogs(), 1); diff --git a/test/libsolidity/semanticTests/libraries/library_address_via_module.sol b/test/libsolidity/semanticTests/libraries/library_address_via_module.sol index ca7c9c271..effcd13c8 100644 --- a/test/libsolidity/semanticTests/libraries/library_address_via_module.sol +++ b/test/libsolidity/semanticTests/libraries/library_address_via_module.sol @@ -42,7 +42,7 @@ contract C { // EVMVersion: >=byzantium // compileViaYul: also // ---- -// library: L +// library: "a.sol":L // addr() -> false // g(uint256): 1 -> 1 // g(uint256): 2 -> 4 diff --git a/test/libsolidity/util/TestFileParser.cpp b/test/libsolidity/util/TestFileParser.cpp index 65a7e9c0f..6652f704a 100644 --- a/test/libsolidity/util/TestFileParser.cpp +++ b/test/libsolidity/util/TestFileParser.cpp @@ -100,8 +100,26 @@ vector TestFileParser::parseFunctionCall if (accept(Token::Library, true)) { expect(Token::Colon); - call.signature = m_scanner.currentLiteral(); - expect(Token::Identifier); + string libraryName; + if (accept(Token::String)) + { + libraryName = m_scanner.currentLiteral(); + expect(Token::String); + expect(Token::Colon); + libraryName += ':' + m_scanner.currentLiteral(); + expect(Token::Identifier); + } + else if (accept(Token::Colon, true)) + { + libraryName = ':' + m_scanner.currentLiteral(); + expect(Token::Identifier); + } + else + { + libraryName = m_scanner.currentLiteral(); + expect(Token::Identifier); + } + call.signature = libraryName; call.kind = FunctionCall::Kind::Library; call.expectations.failure = false; }