aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorYoichi Hirai <i@yoichihirai.com>2016-11-04 22:23:48 +0800
committerchriseth <c@ethdev.com>2016-11-16 21:37:18 +0800
commit3158a8ea7b06888472b09ac4bc5f6a5a2f7ae2ce (patch)
tree96129fa7af1ebea32713c2e2755e65252bbb04e5 /test
parentcc847df3c20982372d601016382b0a93266467a4 (diff)
downloaddexon-solidity-3158a8ea7b06888472b09ac4bc5f6a5a2f7ae2ce.tar
dexon-solidity-3158a8ea7b06888472b09ac4bc5f6a5a2f7ae2ce.tar.gz
dexon-solidity-3158a8ea7b06888472b09ac4bc5f6a5a2f7ae2ce.tar.bz2
dexon-solidity-3158a8ea7b06888472b09ac4bc5f6a5a2f7ae2ce.tar.lz
dexon-solidity-3158a8ea7b06888472b09ac4bc5f6a5a2f7ae2ce.tar.xz
dexon-solidity-3158a8ea7b06888472b09ac4bc5f6a5a2f7ae2ce.tar.zst
dexon-solidity-3158a8ea7b06888472b09ac4bc5f6a5a2f7ae2ce.zip
test: add a test for storing an internal function in the constructor and then using the stored function in runtime
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index ef64ad5a..7dbadc48 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -7732,6 +7732,52 @@ BOOST_AUTO_TEST_CASE(store_function)
BOOST_CHECK(callContractFunction("t()") == encodeArgs(u256(9)));
}
+BOOST_AUTO_TEST_CASE(store_function_in_constructor)
+{
+ char const* sourceCode = R"(
+ contract C {
+ uint result_in_constructor;
+ function (uint) internal returns (uint) x;
+ function C () {
+ x = double;
+ result_in_constructor = use(2);
+ }
+ function double(uint _arg) returns (uint _ret) {
+ _ret = _arg * 2;
+ }
+ function use(uint _arg) returns (uint) {
+ return x(_arg);
+ }
+ }
+ )";
+
+ compileAndRun(sourceCode, 0, "C");
+ BOOST_CHECK(callContractFunction("use(uint256)", encodeArgs(u256(3))) == encodeArgs(u256(6)));
+ BOOST_CHECK(callContractFunction("result_in_constructor()") == encodeArgs(u256(4)));
+}
+
+BOOST_AUTO_TEST_CASE(same_function_in_construction_and_runtime)
+{
+ char const* sourceCode = R"(
+ contract C {
+ uint public initial;
+ function C() {
+ initial = double(2);
+ }
+ function double(uint _arg) returns (uint _ret) {
+ _ret = _arg * 2;
+ }
+ function runtime(uint _arg) returns (uint) {
+ return double(_arg);
+ }
+ }
+ )";
+
+ compileAndRun(sourceCode, 0, "C");
+ BOOST_CHECK(callContractFunction("runtime(uint256)", encodeArgs(u256(3))) == encodeArgs(u256(6)));
+ BOOST_CHECK(callContractFunction("initial()") == encodeArgs(u256(4)));
+}
+
BOOST_AUTO_TEST_CASE(function_type_library_internal)
{
char const* sourceCode = R"(