From 976c380b615f71c9e5b59c9b6bcadefbd79c086f Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 10 Sep 2015 19:40:07 +0200 Subject: Possibility to call library functions. --- test/libsolidity/SolidityEndToEndTest.cpp | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') 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{{"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{{"Lib", m_contractAddress}}); + BOOST_CHECK(callContractFunction("f(uint256)", u256(33)) == encodeArgs(u256(42))); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit