diff options
author | chriseth <c@ethdev.com> | 2014-12-19 18:38:45 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2014-12-19 18:38:45 +0800 |
commit | 7d7fa86697e07de2261d8b650be9eebf1c369469 (patch) | |
tree | 8f74362b38386ea561754fd8e09493bb2adf85f2 | |
parent | d7d40a13c263d69da0769bece3558496bbcc3bc8 (diff) | |
parent | beb060672675a4b658a7d7aa39169043bce1cfaf (diff) | |
download | dexon-solidity-7d7fa86697e07de2261d8b650be9eebf1c369469.tar.gz dexon-solidity-7d7fa86697e07de2261d8b650be9eebf1c369469.tar.zst dexon-solidity-7d7fa86697e07de2261d8b650be9eebf1c369469.zip |
Merge pull request #664 from chriseth/sol_fix_compoundAssign
Bugfix: Additional swap for compound assignment.
-rw-r--r-- | SolidityEndToEndTest.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index aa74f818..9559e370 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -504,6 +504,41 @@ BOOST_AUTO_TEST_CASE(state_smoke_test) BOOST_CHECK(callContractFunction(0, bytes(1, 0x00)) == toBigEndian(u256(0x3))); } +BOOST_AUTO_TEST_CASE(compound_assign) +{ + char const* sourceCode = "contract test {\n" + " uint value1;\n" + " uint value2;\n" + " function f(uint x, uint y) returns (uint w) {\n" + " uint value3 = y;" + " value1 += x;\n" + " value3 *= x;" + " value2 *= value3 + value1;\n" + " return value2 += 7;" + " }\n" + "}\n"; + compileAndRun(sourceCode); + + u256 value1; + u256 value2; + auto f = [&](u256 const& _x, u256 const& _y) -> u256 + { + u256 value3 = _y; + value1 += _x; + value3 *= _x; + value2 *= value3 + value1; + return value2 += 7; + }; + testSolidityAgainstCpp(0, f, u256(0), u256(6)); + testSolidityAgainstCpp(0, f, u256(1), u256(3)); + testSolidityAgainstCpp(0, f, u256(2), u256(25)); + testSolidityAgainstCpp(0, f, u256(3), u256(69)); + testSolidityAgainstCpp(0, f, u256(4), u256(84)); + testSolidityAgainstCpp(0, f, u256(5), u256(2)); + testSolidityAgainstCpp(0, f, u256(6), u256(51)); + testSolidityAgainstCpp(0, f, u256(7), u256(48)); +} + BOOST_AUTO_TEST_CASE(simple_mapping) { char const* sourceCode = "contract test {\n" |