From 6172590b870832d7aa132209afb890125f301c15 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 14 Oct 2016 17:54:12 +0200 Subject: Add a test around storing functions in an array --- test/libsolidity/SolidityEndToEndTest.cpp | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 79dfd90e..704fc1a1 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -7750,6 +7750,45 @@ BOOST_AUTO_TEST_CASE(call_function_returning_function) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(2))); } +BOOST_AUTO_TEST_CASE(array_of_functions) +{ + char const* sourceCode = R"( + contract Flow { + bool success; + function checkSuccess() returns(bool) { + return success; + } + + mapping (address => function () internal returns()) stages; + + function stage0() internal { + stages[msg.sender] = stage1; + } + + function stage1() internal { + stages[msg.sender] = stage2; + } + + function stage2() internal { + success = true; + } + + function f () { + if (0 == steps[msg.sender]) + stages[msg.sender] = stage0; + stages[msg.sender](); + } + } + )"; + + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("checkSuccess()") == encodeArgs(false)); + callContractFunction("f()"); + callContractFunction("f()"); + BOOST_CHECK(callContractFunction("checkSuccess()") == encodeArgs(false)); + callContractFunction("f()"); + BOOST_CHECK(callContractFunction("checkSuccess()") == encodeArgs(true)); +} // TODO: arrays, libraries with external functions -- cgit