diff options
author | chriseth <chris@ethereum.org> | 2016-10-25 18:50:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-25 18:50:24 +0800 |
commit | e00a4b47c06d412cd9342b8be2163e861c591c28 (patch) | |
tree | 3c8584a2d12591f6dd5766f0c3f074bf0a6ffd97 /test/libsolidity | |
parent | d190f016ad70f78f3abb06a09472235844e7c04d (diff) | |
parent | 59f6c18c2be86152261bb20732161c60fd2a6485 (diff) | |
download | dexon-solidity-e00a4b47c06d412cd9342b8be2163e861c591c28.tar dexon-solidity-e00a4b47c06d412cd9342b8be2163e861c591c28.tar.gz dexon-solidity-e00a4b47c06d412cd9342b8be2163e861c591c28.tar.bz2 dexon-solidity-e00a4b47c06d412cd9342b8be2163e861c591c28.tar.lz dexon-solidity-e00a4b47c06d412cd9342b8be2163e861c591c28.tar.xz dexon-solidity-e00a4b47c06d412cd9342b8be2163e861c591c28.tar.zst dexon-solidity-e00a4b47c06d412cd9342b8be2163e861c591c28.zip |
Merge pull request #1264 from ethereum/988
State variable under contract's name
Diffstat (limited to 'test/libsolidity')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 114 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 13 |
2 files changed, 127 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index bb197cca..8ef9a45b 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5666,6 +5666,120 @@ BOOST_AUTO_TEST_CASE(accessor_for_const_state_variable) BOOST_CHECK(callContractFunction("ticketPrice()") == encodeArgs(u256(555))); } +BOOST_AUTO_TEST_CASE(state_variable_under_contract_name) +{ + char const* text = R"( + contract Scope { + uint stateVar = 42; + + function getStateVar() constant returns (uint stateVar) { + stateVar = Scope.stateVar; + } + } + )"; + compileAndRun(text); + BOOST_CHECK(callContractFunction("getStateVar()") == encodeArgs(u256(42))); +} + +BOOST_AUTO_TEST_CASE(state_variable_local_variable_mixture) +{ + char const* sourceCode = R"( + contract A { + uint x = 1; + uint y = 2; + function a() returns (uint x) { + x = A.y; + } + } + )"; + + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(2))); +} + +BOOST_AUTO_TEST_CASE(inherited_function) { + char const* sourceCode = R"( + contract A { function f() internal returns (uint) { return 1; } } + contract B is A { + function f() internal returns (uint) { return 2; } + function g() returns (uint) { + return A.f(); + } + } + )"; + + compileAndRun(sourceCode, 0, "B"); + BOOST_CHECK(callContractFunction("g()") == encodeArgs(u256(1))); +} + +BOOST_AUTO_TEST_CASE(inherited_function_from_a_library) { + char const* sourceCode = R"( + library A { function f() internal returns (uint) { return 1; } } + contract B { + function f() internal returns (uint) { return 2; } + function g() returns (uint) { + return A.f(); + } + } + )"; + + compileAndRun(sourceCode, 0, "B"); + BOOST_CHECK(callContractFunction("g()") == encodeArgs(u256(1))); +} + +BOOST_AUTO_TEST_CASE(inherited_constant_state_var) +{ + char const* sourceCode = R"( + contract A { + uint constant x = 7; + } + contract B is A { + function f() returns (uint) { + return A.x; + } + } + )"; + + compileAndRun(sourceCode, 0, "B"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(7))); +} + +BOOST_AUTO_TEST_CASE(multiple_inherited_state_vars) +{ + char const* sourceCode = R"( + contract A { + uint x = 7; + } + contract B { + uint x = 9; + } + contract C is A, B { + function a() returns (uint) { + return A.x; + } + function b() returns (uint) { + return B.x; + } + function a_set(uint _x) returns (uint) { + A.x = _x; + return 1; + } + function b_set(uint _x) returns (uint) { + B.x = _x; + return 1; + } + } + )"; + + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(7))); + BOOST_CHECK(callContractFunction("b()") == encodeArgs(u256(9))); + BOOST_CHECK(callContractFunction("a_set(uint256)", u256(1)) == encodeArgs(u256(1))); + BOOST_CHECK(callContractFunction("b_set(uint256)", u256(3)) == encodeArgs(u256(1))); + BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(1))); + BOOST_CHECK(callContractFunction("b()") == encodeArgs(u256(3))); +} + BOOST_AUTO_TEST_CASE(constant_string_literal) { char const* sourceCode = R"( diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index f7ac73ae..9fe91cca 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1036,6 +1036,19 @@ BOOST_AUTO_TEST_CASE(private_state_variable) BOOST_CHECK_MESSAGE(function == nullptr, "Accessor function of an internal variable should not exist"); } +BOOST_AUTO_TEST_CASE(missing_state_variable) +{ + char const* text = R"( + contract Scope { + function getStateVar() constant returns (uint stateVar) { + stateVar = Scope.stateVar; // should fail. + } + } + )"; + BOOST_CHECK(expectError(text) == Error::Type::TypeError); +} + + BOOST_AUTO_TEST_CASE(base_class_state_variable_accessor) { // test for issue #1126 https://github.com/ethereum/cpp-ethereum/issues/1126 |