mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add tests for selectors for public variables.
This commit is contained in:
parent
5916cf1e0a
commit
aea9e7fe54
@ -10219,24 +10219,29 @@ BOOST_AUTO_TEST_CASE(function_types_sig)
|
|||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
function f() returns (bytes4) {
|
uint public x;
|
||||||
|
function f() pure returns (bytes4) {
|
||||||
return this.f.selector;
|
return this.f.selector;
|
||||||
}
|
}
|
||||||
function g() returns (bytes4) {
|
function g() returns (bytes4) {
|
||||||
function () external returns (bytes4) fun = this.f;
|
function () pure external returns (bytes4) fun = this.f;
|
||||||
return fun.selector;
|
return fun.selector;
|
||||||
}
|
}
|
||||||
function h() returns (bytes4) {
|
function h() returns (bytes4) {
|
||||||
function () external returns (bytes4) fun = this.f;
|
function () pure external returns (bytes4) fun = this.f;
|
||||||
var funvar = fun;
|
var funvar = fun;
|
||||||
return funvar.selector;
|
return funvar.selector;
|
||||||
}
|
}
|
||||||
|
function i() pure returns (bytes4) {
|
||||||
|
return this.x.selector;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
compileAndRun(sourceCode, 0, "C");
|
compileAndRun(sourceCode, 0, "C");
|
||||||
ABI_CHECK(callContractFunction("f()"), encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes())));
|
ABI_CHECK(callContractFunction("f()"), encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes())));
|
||||||
ABI_CHECK(callContractFunction("g()"), encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes())));
|
ABI_CHECK(callContractFunction("g()"), encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes())));
|
||||||
ABI_CHECK(callContractFunction("h()"), encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes())));
|
ABI_CHECK(callContractFunction("h()"), encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes())));
|
||||||
|
ABI_CHECK(callContractFunction("i()"), encodeArgs(asString(FixedHash<4>(dev::keccak256("x()")).asBytes())));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(constant_string)
|
BOOST_AUTO_TEST_CASE(constant_string)
|
||||||
|
@ -330,10 +330,11 @@ BOOST_AUTO_TEST_CASE(selector)
|
|||||||
{
|
{
|
||||||
string text = R"(
|
string text = R"(
|
||||||
contract C {
|
contract C {
|
||||||
|
uint public x;
|
||||||
function f() payable public {
|
function f() payable public {
|
||||||
}
|
}
|
||||||
function g() pure public returns (bytes4) {
|
function g() pure public returns (bytes4) {
|
||||||
return this.f.selector;
|
return this.f.selector ^ this.x.selector;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
Loading…
Reference in New Issue
Block a user