mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #5451 from ethereum/bound_function_tests
Add assert and tests for bound functions
This commit is contained in:
@@ -9388,6 +9388,25 @@ BOOST_AUTO_TEST_CASE(using_for_by_name)
|
||||
ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(6 * 7)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(bound_function_in_function)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
library L {
|
||||
function g(function() internal returns (uint) _t) internal returns (uint) { return _t(); }
|
||||
}
|
||||
contract C {
|
||||
using L for *;
|
||||
function f() public returns (uint) {
|
||||
return t.g();
|
||||
}
|
||||
function t() public pure returns (uint) { return 7; }
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode, 0, "L");
|
||||
compileAndRun(sourceCode, 0, "C", bytes(), map<string, Address>{{"L", m_contractAddress}});
|
||||
ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(7)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(bound_function_in_var)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
library L {
|
||||
function g(function() internal returns (uint) _t) internal returns (uint) { return _t(); }
|
||||
}
|
||||
contract C {
|
||||
using L for *;
|
||||
function f() public returns (uint) {
|
||||
return t.g();
|
||||
}
|
||||
function t() public pure returns (uint) { return 7; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
library D { function double(uint self) internal pure returns (uint) { return 2*self; } }
|
||||
contract C {
|
||||
using D for uint;
|
||||
function f(uint a) public pure {
|
||||
a.double();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
library D { function double(uint self) public pure returns (uint) { return 2*self; } }
|
||||
contract C {
|
||||
using D for uint;
|
||||
function f(uint a) public pure {
|
||||
a.double;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user