diff options
author | Gav Wood <g@ethdev.com> | 2015-01-11 18:07:36 +0800 |
---|---|---|
committer | Gav Wood <g@ethdev.com> | 2015-01-11 18:07:36 +0800 |
commit | 04a57f8c5399a8930a6efaf333d245b9557b5ec1 (patch) | |
tree | 87bc4e6a832d790847aae4f2b2505e351c192ae8 | |
parent | 3302425aa927d60fad8af862a6d06296c749037f (diff) | |
parent | 4b11eea653edf2361fad58a97e2010eeffca9832 (diff) | |
download | dexon-solidity-04a57f8c5399a8930a6efaf333d245b9557b5ec1.tar dexon-solidity-04a57f8c5399a8930a6efaf333d245b9557b5ec1.tar.gz dexon-solidity-04a57f8c5399a8930a6efaf333d245b9557b5ec1.tar.bz2 dexon-solidity-04a57f8c5399a8930a6efaf333d245b9557b5ec1.tar.lz dexon-solidity-04a57f8c5399a8930a6efaf333d245b9557b5ec1.tar.xz dexon-solidity-04a57f8c5399a8930a6efaf333d245b9557b5ec1.tar.zst dexon-solidity-04a57f8c5399a8930a6efaf333d245b9557b5ec1.zip |
Merge pull request #768 from chriseth/sol_contractsAreAddresses
Contracts inherit all address members
-rw-r--r-- | SolidityEndToEndTest.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index 0ba3c137..2afe875f 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -834,6 +834,21 @@ BOOST_AUTO_TEST_CASE(function_types) BOOST_CHECK(callContractFunction("a(bool)", true) == encodeArgs(12)); } +BOOST_AUTO_TEST_CASE(type_conversions_cleanup) +{ + // 22-byte integer converted to a contract (i.e. address, 20 bytes), converted to a 32 byte + // integer should drop the first two bytes + char const* sourceCode = R"( + contract Test { + function test() returns (uint ret) { return uint(address(Test(address(0x11223344556677889900112233445566778899001122)))); } + })"; + compileAndRun(sourceCode); + BOOST_REQUIRE(callContractFunction("test()") == bytes({0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, + 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22})); +} + + BOOST_AUTO_TEST_CASE(send_ether) { char const* sourceCode = "contract test {\n" @@ -1261,6 +1276,24 @@ BOOST_AUTO_TEST_CASE(functions_called_by_constructor) BOOST_REQUIRE(callContractFunction("getName()") == encodeArgs("abc")); } +BOOST_AUTO_TEST_CASE(contracts_as_addresses) +{ + char const* sourceCode = R"( + contract helper { + } + contract test { + helper h; + function test() { h = new helper(); h.send(5); } + function getBalance() returns (uint256 myBalance, uint256 helperBalance) { + myBalance = this.balance; + helperBalance = h.balance; + } + } + )"; + compileAndRun(sourceCode, 20); + BOOST_REQUIRE(callContractFunction("getBalance()") == toBigEndian(u256(20 - 5)) + toBigEndian(u256(5))); +} + BOOST_AUTO_TEST_SUITE_END() } |