diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 32 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 16 | ||||
-rw-r--r-- | test/libsolidity/solidityExecutionFramework.h | 14 |
3 files changed, 57 insertions, 5 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index aa423330..c56845aa 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5230,6 +5230,38 @@ BOOST_AUTO_TEST_CASE(storage_string_as_mapping_key_without_variable) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(2))); } +BOOST_AUTO_TEST_CASE(library_call) +{ + char const* sourceCode = R"( + library Lib { function m(uint x, uint y) returns (uint) { return x * y; } } + contract Test { + function f(uint x) returns (uint) { + return Lib.m(x, 9); + } + } + )"; + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map<string, Address>{{"Lib", m_contractAddress}}); + BOOST_CHECK(callContractFunction("f(uint256)", u256(33)) == encodeArgs(u256(33) * 9)); +} + +BOOST_AUTO_TEST_CASE(library_stray_values) +{ + char const* sourceCode = R"( + library Lib { function m(uint x, uint y) returns (uint) { return x * y; } } + contract Test { + function f(uint x) returns (uint) { + Lib; + Lib.m; + return x + 9; + } + } + )"; + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map<string, Address>{{"Lib", m_contractAddress}}); + BOOST_CHECK(callContractFunction("f(uint256)", u256(33)) == encodeArgs(u256(42))); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index adff9499..99497ff3 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2228,6 +2228,22 @@ BOOST_AUTO_TEST_CASE(valid_library) BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); } +BOOST_AUTO_TEST_CASE(call_to_library_function) +{ + char const* text = R"( + library Lib { + uint constant public pimil = 3141592; + function min(uint x, uint y) returns (uint); + } + contract Test { + function f() { + uint t = Lib.min(Lib.pimil(), 7); + } + } + )"; + BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); +} + BOOST_AUTO_TEST_CASE(creating_contract_within_the_contract) { char const* sourceCode = R"( diff --git a/test/libsolidity/solidityExecutionFramework.h b/test/libsolidity/solidityExecutionFramework.h index 8823114a..3370044c 100644 --- a/test/libsolidity/solidityExecutionFramework.h +++ b/test/libsolidity/solidityExecutionFramework.h @@ -53,14 +53,17 @@ public: std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "", - bytes const& _arguments = bytes() + bytes const& _arguments = bytes(), + std::map<std::string, Address> const& _libraryAddresses = std::map<std::string, Address>() ) { m_compiler.reset(false, m_addStandardSources); m_compiler.addSource("", _sourceCode); ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), "Compiling contract failed"); - bytes code = m_compiler.object(_contractName).bytecode; - sendMessage(code + _arguments, true, _value); + eth::LinkerObject obj = m_compiler.object(_contractName); + obj.link(_libraryAddresses); + BOOST_REQUIRE(obj.linkReferences.empty()); + sendMessage(obj.bytecode + _arguments, true, _value); return m_output; } @@ -76,10 +79,11 @@ public: std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "", - bytes const& _arguments = bytes() + bytes const& _arguments = bytes(), + std::map<std::string, Address> const& _libraryAddresses = std::map<std::string, Address>() ) { - compileAndRunWithoutCheck(_sourceCode, _value, _contractName, _arguments); + compileAndRunWithoutCheck(_sourceCode, _value, _contractName, _arguments, _libraryAddresses); BOOST_REQUIRE(!m_output.empty()); return m_output; } |