aboutsummaryrefslogtreecommitdiffstats
path: root/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'SolidityEndToEndTest.cpp')
-rw-r--r--SolidityEndToEndTest.cpp55
1 files changed, 47 insertions, 8 deletions
diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp
index 7edc250c..f248a5a0 100644
--- a/SolidityEndToEndTest.cpp
+++ b/SolidityEndToEndTest.cpp
@@ -92,6 +92,26 @@ BOOST_AUTO_TEST_CASE(multiple_functions)
BOOST_CHECK(callContractFunction("i_am_not_there()", bytes()) == bytes());
}
+BOOST_AUTO_TEST_CASE(named_args)
+{
+ char const* sourceCode = "contract test {\n"
+ " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n"
+ " function b() returns (uint r) { r = a({a: 1, b: 2, c: 3}); }\n"
+ "}\n";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("b()", bytes()) == toBigEndian(u256(123)));
+}
+
+BOOST_AUTO_TEST_CASE(disorder_named_args)
+{
+ char const* sourceCode = "contract test {\n"
+ " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n"
+ " function b() returns (uint r) { r = a({c: 3, a: 1, b: 2}); }\n"
+ "}\n";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("b()", bytes()) == toBigEndian(u256(123)));
+}
+
BOOST_AUTO_TEST_CASE(while_loop)
{
char const* sourceCode = "contract test {\n"
@@ -885,7 +905,7 @@ BOOST_AUTO_TEST_CASE(constructor)
BOOST_AUTO_TEST_CASE(simple_accessor)
{
char const* sourceCode = "contract test {\n"
- " uint256 data;\n"
+ " uint256 public data;\n"
" function test() {\n"
" data = 8;\n"
" }\n"
@@ -897,10 +917,10 @@ BOOST_AUTO_TEST_CASE(simple_accessor)
BOOST_AUTO_TEST_CASE(multiple_elementary_accessors)
{
char const* sourceCode = "contract test {\n"
- " uint256 data;\n"
- " string6 name;\n"
- " hash a_hash;\n"
- " address an_address;\n"
+ " uint256 public data;\n"
+ " string6 public name;\n"
+ " hash public a_hash;\n"
+ " address public an_address;\n"
" function test() {\n"
" data = 8;\n"
" name = \"Celina\";\n"
@@ -908,7 +928,6 @@ BOOST_AUTO_TEST_CASE(multiple_elementary_accessors)
" an_address = address(0x1337);\n"
" super_secret_data = 42;\n"
" }\n"
- " private:"
" uint256 super_secret_data;"
"}\n";
compileAndRun(sourceCode);
@@ -919,6 +938,27 @@ BOOST_AUTO_TEST_CASE(multiple_elementary_accessors)
BOOST_CHECK(callContractFunction("super_secret_data()") == bytes());
}
+BOOST_AUTO_TEST_CASE(complex_accessors)
+{
+ char const* sourceCode = "contract test {\n"
+ " mapping(uint256 => string4) public to_string_map;\n"
+ " mapping(uint256 => bool) public to_bool_map;\n"
+ " mapping(uint256 => uint256) public to_uint_map;\n"
+ " mapping(uint256 => mapping(uint256 => uint256)) public to_multiple_map;\n"
+ " function test() {\n"
+ " to_string_map[42] = \"24\";\n"
+ " to_bool_map[42] = false;\n"
+ " to_uint_map[42] = 12;\n"
+ " to_multiple_map[42][23] = 31;\n"
+ " }\n"
+ "}\n";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("to_string_map(uint256)", 42) == encodeArgs("24"));
+ BOOST_CHECK(callContractFunction("to_bool_map(uint256)", 42) == encodeArgs(false));
+ BOOST_CHECK(callContractFunction("to_uint_map(uint256)", 42) == encodeArgs(12));
+ BOOST_CHECK(callContractFunction("to_multiple_map(uint256,uint256)", 42, 23) == encodeArgs(31));
+}
+
BOOST_AUTO_TEST_CASE(balance)
{
char const* sourceCode = "contract test {\n"
@@ -1490,8 +1530,7 @@ BOOST_AUTO_TEST_CASE(functions_called_by_constructor)
setName("abc");
}
function getName() returns (string3 ret) { return name; }
- private:
- function setName(string3 _name) { name = _name; }
+ function setName(string3 _name) private { name = _name; }
})";
compileAndRun(sourceCode);
BOOST_REQUIRE(callContractFunction("getName()") == encodeArgs("abc"));