aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-11-09 22:58:45 +0800
committerchriseth <c@ethdev.com>2016-11-16 21:37:18 +0800
commit08763a206d4391f94546ef32a1d0f1495eeb99e4 (patch)
tree0cf5238c4d79f7969bc410022d641fa0e3dcaafe /test
parent925d6741466a423b58cb519b6cc400863426607e (diff)
downloaddexon-solidity-08763a206d4391f94546ef32a1d0f1495eeb99e4.tar.gz
dexon-solidity-08763a206d4391f94546ef32a1d0f1495eeb99e4.tar.zst
dexon-solidity-08763a206d4391f94546ef32a1d0f1495eeb99e4.zip
Test passing functions as arrays to other contracts.
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp43
1 files changed, 40 insertions, 3 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 8f9edadf..5054e275 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -8039,10 +8039,47 @@ BOOST_AUTO_TEST_CASE(copy_function_storage_array)
BOOST_CHECK(callContractFunction("test()") == encodeArgs(u256(7)));
}
+BOOST_AUTO_TEST_CASE(function_array_cross_calls)
+{
+ char const* sourceCode = R"(
+ contract D {
+ function f(function() external returns (function() external returns (uint))[] x)
+ returns (function() external returns (uint)[3] r)
+ {
+ r[0] = x[0]();
+ r[1] = x[1]();
+ r[2] = x[2]();
+ }
+ }
+ contract C {
+ function test() returns (uint, uint, uint) {
+ function() external returns (function() external returns (uint))[] memory x =
+ new function() external returns (function() external returns (uint))[](10);
+ for (uint i = 0; i < x.length; i ++)
+ x[i] = this.h;
+ x[0] = this.htwo;
+ var y = (new D()).f(x);
+ return (y[0](), y[1](), y[2]());
+ }
+ function e() returns (uint) { return 5; }
+ function f() returns (uint) { return 6; }
+ function g() returns (uint) { return 7; }
+ uint counter;
+ function h() returns (function() external returns (uint)) {
+ return counter++ == 0 ? this.f : this.g;
+ }
+ function htwo() returns (function() external returns (uint)) {
+ return this.e;
+ }
+ }
+ )";
+
+ compileAndRun(sourceCode, 0, "C");
+ BOOST_CHECK(callContractFunction("test()") == encodeArgs(u256(5), u256(6), u256(7)));
+}
+
BOOST_AUTO_TEST_CASE(copy_internal_function_array_to_storage)
{
- // This has to apply NOT to the functions because encoding in storage
- // is different than encoding in memory.
char const* sourceCode = R"(
contract C {
function() internal returns (uint)[20] x;
@@ -8056,7 +8093,7 @@ BOOST_AUTO_TEST_CASE(copy_internal_function_array_to_storage)
if (mutex > 0)
return 7;
mutex = 1;
- // If this test fails, it will jump to "0" and re-execute this function.
+ // If this test fails, it might re-execute this function.
x[0]();
return 2;
}