aboutsummaryrefslogtreecommitdiffstats
path: root/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-01-15 01:22:16 +0800
committerchriseth <c@ethdev.com>2015-01-15 01:22:16 +0800
commit25fc28422bf864f5299a5995e68fa1c17d2cb75c (patch)
tree3f420016fbc7b318bb4e2c8c51883a5533126801 /SolidityEndToEndTest.cpp
parentf8f1ec30f4b2fdb3215544276474ba92b71cffec (diff)
parente1559df82e16737e694613e8ffd2065a0bc21fa1 (diff)
downloaddexon-solidity-25fc28422bf864f5299a5995e68fa1c17d2cb75c.tar
dexon-solidity-25fc28422bf864f5299a5995e68fa1c17d2cb75c.tar.gz
dexon-solidity-25fc28422bf864f5299a5995e68fa1c17d2cb75c.tar.bz2
dexon-solidity-25fc28422bf864f5299a5995e68fa1c17d2cb75c.tar.lz
dexon-solidity-25fc28422bf864f5299a5995e68fa1c17d2cb75c.tar.xz
dexon-solidity-25fc28422bf864f5299a5995e68fa1c17d2cb75c.tar.zst
dexon-solidity-25fc28422bf864f5299a5995e68fa1c17d2cb75c.zip
Merge pull request #799 from chriseth/sol_gasAndValue
Specify gas and value for function calls and contract creation calls.
Diffstat (limited to 'SolidityEndToEndTest.cpp')
-rw-r--r--SolidityEndToEndTest.cpp108
1 files changed, 107 insertions, 1 deletions
diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp
index 9543497a..16787c8e 100644
--- a/SolidityEndToEndTest.cpp
+++ b/SolidityEndToEndTest.cpp
@@ -1295,7 +1295,113 @@ BOOST_AUTO_TEST_CASE(contracts_as_addresses)
}
)";
compileAndRun(sourceCode, 20);
- BOOST_REQUIRE(callContractFunction("getBalance()") == toBigEndian(u256(20 - 5)) + toBigEndian(u256(5)));
+ BOOST_REQUIRE(callContractFunction("getBalance()") == encodeArgs(u256(20 - 5), u256(5)));
+}
+
+BOOST_AUTO_TEST_CASE(gas_and_value_basic)
+{
+ char const* sourceCode = R"(
+ contract helper {
+ bool flag;
+ function getBalance() returns (uint256 myBalance) {
+ return this.balance;
+ }
+ function setFlag() { flag = true; }
+ function getFlag() returns (bool fl) { return flag; }
+ }
+ contract test {
+ helper h;
+ function test() { h = new helper(); }
+ function sendAmount(uint amount) returns (uint256 bal) {
+ return h.getBalance.value(amount)();
+ }
+ function outOfGas() returns (bool flagBefore, bool flagAfter, uint myBal) {
+ flagBefore = h.getFlag();
+ h.setFlag.gas(2)(); // should fail due to OOG, return value can be garbage
+ flagAfter = h.getFlag();
+ myBal = this.balance;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 20);
+ BOOST_REQUIRE(callContractFunction("sendAmount(uint256)", 5) == encodeArgs(5));
+ // call to helper should not succeed but amount should be transferred anyway
+ BOOST_REQUIRE(callContractFunction("outOfGas()", 5) == encodeArgs(false, false, 20 - 5));
+}
+
+BOOST_AUTO_TEST_CASE(value_complex)
+{
+ char const* sourceCode = R"(
+ contract helper {
+ function getBalance() returns (uint256 myBalance) {
+ return this.balance;
+ }
+ }
+ contract test {
+ helper h;
+ function test() { h = new helper(); }
+ function sendAmount(uint amount) returns (uint256 bal) {
+ var x1 = h.getBalance.value(amount);
+ uint someStackElement = 20;
+ var x2 = x1.gas(1000);
+ return x2.value(amount + 3)();// overwrite value
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 20);
+ BOOST_REQUIRE(callContractFunction("sendAmount(uint256)", 5) == encodeArgs(8));
+}
+
+BOOST_AUTO_TEST_CASE(value_insane)
+{
+ char const* sourceCode = R"(
+ contract helper {
+ function getBalance() returns (uint256 myBalance) {
+ return this.balance;
+ }
+ }
+ contract test {
+ helper h;
+ function test() { h = new helper(); }
+ function sendAmount(uint amount) returns (uint256 bal) {
+ var x1 = h.getBalance.value;
+ uint someStackElement = 20;
+ var x2 = x1(amount).gas;
+ var x3 = x2(1000).value;
+ return x3(amount + 3)();// overwrite value
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 20);
+ BOOST_REQUIRE(callContractFunction("sendAmount(uint256)", 5) == encodeArgs(8));
+}
+
+BOOST_AUTO_TEST_CASE(value_for_constructor)
+{
+ char const* sourceCode = R"(
+ contract Helper {
+ string3 name;
+ bool flag;
+ function Helper(string3 x, bool f) {
+ name = x;
+ flag = f;
+ }
+ function getName() returns (string3 ret) { return name; }
+ function getFlag() returns (bool ret) { return flag; }
+ }
+ contract Main {
+ Helper h;
+ function Main() {
+ h = new Helper.value(10)("abc", true);
+ }
+ function getFlag() returns (bool ret) { return h.getFlag(); }
+ function getName() returns (string3 ret) { return h.getName(); }
+ function getBalances() returns (uint me, uint them) { me = this.balance; them = h.balance;}
+ })";
+ compileAndRun(sourceCode, 22, "Main");
+ BOOST_REQUIRE(callContractFunction("getFlag()") == encodeArgs(true));
+ BOOST_REQUIRE(callContractFunction("getName()") == encodeArgs("abc"));
+ BOOST_REQUIRE(callContractFunction("getBalances()") == encodeArgs(12, 10));
}
BOOST_AUTO_TEST_SUITE_END()