From 220ccfb492511eab5a45936e477e6882f52be96a Mon Sep 17 00:00:00 2001 From: Rhett Aultman Date: Mon, 12 Dec 2016 00:00:50 -0800 Subject: Move clashing libraries to common source in test Since contracts and libraries only collide if they share a common source file now, this test only works if both libraries are in the same source. --- test/libsolidity/Imports.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/Imports.cpp b/test/libsolidity/Imports.cpp index 56895fdc..e01d2e90 100644 --- a/test/libsolidity/Imports.cpp +++ b/test/libsolidity/Imports.cpp @@ -104,8 +104,7 @@ BOOST_AUTO_TEST_CASE(simple_alias) BOOST_AUTO_TEST_CASE(library_name_clash) { CompilerStack c; - c.addSource("a", "library A {} pragma solidity >=0.0;"); - c.addSource("b", "library A {} pragma solidity >=0.0;"); + c.addSource("a", "library A {} library A {} pragma solidity >=0.0;"); BOOST_CHECK(!c.compile()); } -- cgit From f8914c6b281f398d6084f10708233bf79d633ef0 Mon Sep 17 00:00:00 2001 From: Rhett Aultman Date: Fri, 16 Dec 2016 07:54:18 -0800 Subject: Fix contract lookup in tests The fully-qualified name of a contract with no source unit is : instead of just , so the test system needed to be adjusted accordingly. --- test/libsolidity/SolidityABIJSON.cpp | 4 ++-- test/libsolidity/SolidityExecutionFramework.h | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp index 043d74ed..a54e9b7e 100644 --- a/test/libsolidity/SolidityABIJSON.cpp +++ b/test/libsolidity/SolidityABIJSON.cpp @@ -762,8 +762,8 @@ BOOST_AUTO_TEST_CASE(metadata_stamp) } )"; BOOST_REQUIRE(m_compilerStack.compile(std::string(sourceCode))); - bytes const& bytecode = m_compilerStack.runtimeObject("test").bytecode; - bytes hash = dev::swarmHash(m_compilerStack.onChainMetadata("test")).asBytes(); + bytes const& bytecode = m_compilerStack.runtimeObject(":test").bytecode; + bytes hash = dev::swarmHash(m_compilerStack.onChainMetadata(":test")).asBytes(); BOOST_REQUIRE(hash.size() == 32); BOOST_REQUIRE(bytecode.size() >= 2); size_t metadataCBORSize = (size_t(bytecode.end()[-2]) << 8) + size_t(bytecode.end()[-1]); diff --git a/test/libsolidity/SolidityExecutionFramework.h b/test/libsolidity/SolidityExecutionFramework.h index 03e3a881..00e8330c 100644 --- a/test/libsolidity/SolidityExecutionFramework.h +++ b/test/libsolidity/SolidityExecutionFramework.h @@ -67,7 +67,11 @@ public: ); BOOST_ERROR("Compiling contract failed"); } - eth::LinkerObject obj = m_compiler.object(_contractName); + eth::LinkerObject obj; + if (_contractName.empty()) + obj = m_compiler.object(_contractName); + else + obj = m_compiler.object(":" + _contractName); BOOST_REQUIRE(obj.linkReferences.empty()); sendMessage(obj.bytecode + _arguments, true, _value); return m_output; -- cgit From 1f30982ab532fdf719f3924e24e80057fe85e031 Mon Sep 17 00:00:00 2001 From: Rhett Aultman Date: Wed, 21 Dec 2016 11:26:22 -0800 Subject: Use fully-qualified names for linking, too Using libraries leaves behind a library link reference in the binary which the linker must later resolve. These link references were still being generated by name and not by fully-qualified name. This would lead to a link-time collision between two libraries having the same name but in different source units. This change changes linker symbols over to fully-qualified names, which resolves that issue. This does potentially introduce a new problem, which is that linker symbols appear to be limited to 36 characters and are truncated. Storing paths extends the average symbol size, and it would be great if truncation was from the tail rather than the head. --- test/libsolidity/SolidityEndToEndTest.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 19161831..03aa2699 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3192,7 +3192,7 @@ BOOST_AUTO_TEST_CASE(library_call_in_homestead) } )"; compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); BOOST_CHECK(callContractFunction("f()") == encodeArgs()); BOOST_CHECK(callContractFunction("sender()") == encodeArgs(u160(m_sender))); } @@ -6191,7 +6191,7 @@ BOOST_AUTO_TEST_CASE(library_call) } )"; compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); BOOST_CHECK(callContractFunction("f(uint256)", u256(33)) == encodeArgs(u256(33) * 9)); } @@ -6208,7 +6208,7 @@ BOOST_AUTO_TEST_CASE(library_stray_values) } )"; compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); BOOST_CHECK(callContractFunction("f(uint256)", u256(33)) == encodeArgs(u256(42))); } @@ -6341,7 +6341,7 @@ BOOST_AUTO_TEST_CASE(internal_types_in_library) } )"; compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(4), u256(17))); } @@ -6368,7 +6368,7 @@ BOOST_AUTO_TEST_CASE(using_library_structs) } )"; compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{":Lib", m_contractAddress}}); BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(7), u256(8))); } @@ -6902,7 +6902,7 @@ BOOST_AUTO_TEST_CASE(using_for_function_on_int) } )"; compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{{":D", m_contractAddress}}); BOOST_CHECK(callContractFunction("f(uint256)", u256(9)) == encodeArgs(u256(2 * 9))); } @@ -6920,7 +6920,7 @@ BOOST_AUTO_TEST_CASE(using_for_function_on_struct) } )"; compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{{":D", m_contractAddress}}); BOOST_CHECK(callContractFunction("f(uint256)", u256(7)) == encodeArgs(u256(3 * 7))); BOOST_CHECK(callContractFunction("x()") == encodeArgs(u256(3 * 7))); } @@ -6943,7 +6943,7 @@ BOOST_AUTO_TEST_CASE(using_for_overload) } )"; compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{{":D", m_contractAddress}}); BOOST_CHECK(callContractFunction("f(uint256)", u256(7)) == encodeArgs(u256(6 * 7))); BOOST_CHECK(callContractFunction("x()") == encodeArgs(u256(6 * 7))); } @@ -6962,7 +6962,7 @@ BOOST_AUTO_TEST_CASE(using_for_by_name) } )"; compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{{":D", m_contractAddress}}); BOOST_CHECK(callContractFunction("f(uint256)", u256(7)) == encodeArgs(u256(6 * 7))); BOOST_CHECK(callContractFunction("x()") == encodeArgs(u256(6 * 7))); } @@ -6982,7 +6982,7 @@ BOOST_AUTO_TEST_CASE(bound_function_in_var) } )"; compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{{":D", m_contractAddress}}); BOOST_CHECK(callContractFunction("f(uint256)", u256(7)) == encodeArgs(u256(6 * 7))); BOOST_CHECK(callContractFunction("x()") == encodeArgs(u256(6 * 7))); } @@ -7005,7 +7005,7 @@ BOOST_AUTO_TEST_CASE(bound_function_to_string) } )"; compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{{":D", m_contractAddress}}); BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(3))); BOOST_CHECK(callContractFunction("g()") == encodeArgs(u256(3))); } @@ -7751,7 +7751,7 @@ BOOST_AUTO_TEST_CASE(payable_function_calls_library) } )"; compileAndRun(sourceCode, 0, "L"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"L", m_contractAddress}}); + compileAndRun(sourceCode, 0, "C", bytes(), map{{":L", m_contractAddress}}); BOOST_CHECK(callContractFunctionWithValue("f()", 27) == encodeArgs(u256(7))); } -- cgit From a7f8a1986a9b3997c75cfc84235e567d2fa9aab4 Mon Sep 17 00:00:00 2001 From: Rhett Aultman Date: Wed, 21 Dec 2016 11:45:34 -0800 Subject: Revert "Move clashing libraries to common source in test" This reverts commit c4a9ca5cfe7a8b4ba9d2d84392c57d5eefacd1f7. --- test/libsolidity/Imports.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/Imports.cpp b/test/libsolidity/Imports.cpp index e01d2e90..56895fdc 100644 --- a/test/libsolidity/Imports.cpp +++ b/test/libsolidity/Imports.cpp @@ -104,7 +104,8 @@ BOOST_AUTO_TEST_CASE(simple_alias) BOOST_AUTO_TEST_CASE(library_name_clash) { CompilerStack c; - c.addSource("a", "library A {} library A {} pragma solidity >=0.0;"); + c.addSource("a", "library A {} pragma solidity >=0.0;"); + c.addSource("b", "library A {} pragma solidity >=0.0;"); BOOST_CHECK(!c.compile()); } -- cgit From fda39afdba9591131aac6d647cb46247e9495606 Mon Sep 17 00:00:00 2001 From: Rhett Aultman Date: Thu, 22 Dec 2016 08:30:53 -0800 Subject: Modify library collision test Since libaraies no longer collide on name but on fully-qualified name, you can only induce collision by colliding them as idenfitiers. --- test/libsolidity/Imports.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/Imports.cpp b/test/libsolidity/Imports.cpp index 56895fdc..6aa96fb8 100644 --- a/test/libsolidity/Imports.cpp +++ b/test/libsolidity/Imports.cpp @@ -106,6 +106,7 @@ BOOST_AUTO_TEST_CASE(library_name_clash) CompilerStack c; c.addSource("a", "library A {} pragma solidity >=0.0;"); c.addSource("b", "library A {} pragma solidity >=0.0;"); + c.addSource("c", "import {A} from \"./a\"; import {A} from \"./b\";"); BOOST_CHECK(!c.compile()); } -- cgit From 88a2ac25e5e10aa7cea8627b60aa663f7ed6066d Mon Sep 17 00:00:00 2001 From: Rhett Aultman Date: Mon, 16 Jan 2017 18:07:48 -0500 Subject: Revert "Fix contract lookup in tests" This reverts commit f8914c6b281f398d6084f10708233bf79d633ef0. --- test/libsolidity/SolidityABIJSON.cpp | 4 ++-- test/libsolidity/SolidityExecutionFramework.h | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp index a54e9b7e..043d74ed 100644 --- a/test/libsolidity/SolidityABIJSON.cpp +++ b/test/libsolidity/SolidityABIJSON.cpp @@ -762,8 +762,8 @@ BOOST_AUTO_TEST_CASE(metadata_stamp) } )"; BOOST_REQUIRE(m_compilerStack.compile(std::string(sourceCode))); - bytes const& bytecode = m_compilerStack.runtimeObject(":test").bytecode; - bytes hash = dev::swarmHash(m_compilerStack.onChainMetadata(":test")).asBytes(); + bytes const& bytecode = m_compilerStack.runtimeObject("test").bytecode; + bytes hash = dev::swarmHash(m_compilerStack.onChainMetadata("test")).asBytes(); BOOST_REQUIRE(hash.size() == 32); BOOST_REQUIRE(bytecode.size() >= 2); size_t metadataCBORSize = (size_t(bytecode.end()[-2]) << 8) + size_t(bytecode.end()[-1]); diff --git a/test/libsolidity/SolidityExecutionFramework.h b/test/libsolidity/SolidityExecutionFramework.h index 00e8330c..03e3a881 100644 --- a/test/libsolidity/SolidityExecutionFramework.h +++ b/test/libsolidity/SolidityExecutionFramework.h @@ -67,11 +67,7 @@ public: ); BOOST_ERROR("Compiling contract failed"); } - eth::LinkerObject obj; - if (_contractName.empty()) - obj = m_compiler.object(_contractName); - else - obj = m_compiler.object(":" + _contractName); + eth::LinkerObject obj = m_compiler.object(_contractName); BOOST_REQUIRE(obj.linkReferences.empty()); sendMessage(obj.bytecode + _arguments, true, _value); return m_output; -- cgit