aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorMarek Kotewicz <marek.kotewicz@gmail.com>2015-07-01 17:27:59 +0800
committerMarek Kotewicz <marek.kotewicz@gmail.com>2015-07-01 17:27:59 +0800
commit2be64d1e238f9ef91c1de6492c7297770b3323a7 (patch)
tree25ce8cb77aa7952b5c049532b23a4ef0072535c7 /libsolidity/SolidityEndToEndTest.cpp
parent0dabcf119545708e66e7880aab1c27a277d7c014 (diff)
parentb82e0b93a4d0fc756c7ad2397099c8be09b9104e (diff)
downloaddexon-solidity-2be64d1e238f9ef91c1de6492c7297770b3323a7.tar
dexon-solidity-2be64d1e238f9ef91c1de6492c7297770b3323a7.tar.gz
dexon-solidity-2be64d1e238f9ef91c1de6492c7297770b3323a7.tar.bz2
dexon-solidity-2be64d1e238f9ef91c1de6492c7297770b3323a7.tar.lz
dexon-solidity-2be64d1e238f9ef91c1de6492c7297770b3323a7.tar.xz
dexon-solidity-2be64d1e238f9ef91c1de6492c7297770b3323a7.tar.zst
dexon-solidity-2be64d1e238f9ef91c1de6492c7297770b3323a7.zip
Merge branch 'develop' into client_ref
Diffstat (limited to 'libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r--libsolidity/SolidityEndToEndTest.cpp117
1 files changed, 116 insertions, 1 deletions
diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp
index 75793abf..a2dbc35e 100644
--- a/libsolidity/SolidityEndToEndTest.cpp
+++ b/libsolidity/SolidityEndToEndTest.cpp
@@ -4493,7 +4493,7 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors_packer)
}
}
contract Main is Base {
- function Main(bytes s, uint x) Base(x, s){}//f(s)) {}
+ function Main(bytes s, uint x) Base(x, f(s)) {}
function f(bytes s) returns (bytes) {
return s;
}
@@ -4517,6 +4517,45 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors_packer)
);
}
+BOOST_AUTO_TEST_CASE(arrays_in_constructors)
+{
+ char const* sourceCode = R"(
+ contract Base {
+ uint public m_x;
+ address[] m_s;
+ function Base(uint x, address[] s) {
+ m_x = x;
+ m_s = s;
+ }
+ function part(uint i) returns (address) {
+ return m_s[i];
+ }
+ }
+ contract Main is Base {
+ function Main(address[] s, uint x) Base(x, f(s)) {}
+ function f(address[] s) returns (address[]) {
+ return s;
+ }
+ }
+ contract Creator {
+ function f(uint x, address[] s) returns (uint r, address ch) {
+ var c = new Main(s, x);
+ r = c.m_x();
+ ch = c.part(x);
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Creator");
+ vector<u256> s1{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ bytes dyn1 = encodeArgs(u256(s1.size()), s1);
+ u256 x = 7;
+ bytes args1 = encodeArgs(x, u256(0x40)) + dyn1;
+ BOOST_REQUIRE(
+ callContractFunction("f(uint256,address[])", asString(args1)) ==
+ encodeArgs(x, s1[unsigned(x)])
+ );
+}
+
BOOST_AUTO_TEST_CASE(arrays_from_and_to_storage)
{
char const* sourceCode = R"(
@@ -4691,6 +4730,82 @@ BOOST_AUTO_TEST_CASE(memory_types_initialisation)
BOOST_CHECK(callContractFunction("nestedStat()") == encodeArgs(vector<u256>(3 * 7)));
}
+BOOST_AUTO_TEST_CASE(memory_arrays_delete)
+{
+ char const* sourceCode = R"(
+ contract Test {
+ function del() returns (uint24[3][4]) {
+ uint24[3][4] memory x;
+ for (uint24 i = 0; i < x.length; i ++)
+ for (uint24 j = 0; j < x[i].length; j ++)
+ x[i][j] = i * 0x10 + j;
+ delete x[1];
+ delete x[3][2];
+ return x;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Test");
+
+ vector<u256> data(3 * 4);
+ for (unsigned i = 0; i < 4; i++)
+ for (unsigned j = 0; j < 3; j++)
+ {
+ u256 v = 0;
+ if (!(i == 1 || (i == 3 && j == 2)))
+ v = i * 0x10 + j;
+ data[i * 3 + j] = v;
+ }
+ BOOST_CHECK(callContractFunction("del()") == encodeArgs(data));
+}
+
+BOOST_AUTO_TEST_CASE(memory_arrays_index_access_write)
+{
+ char const* sourceCode = R"(
+ contract Test {
+ function set(uint24[3][4] x) {
+ x[2][2] = 1;
+ x[3][2] = 7;
+ }
+ function f() returns (uint24[3][4]){
+ uint24[3][4] memory data;
+ set(data);
+ return data;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Test");
+
+ vector<u256> data(3 * 4);
+ data[3 * 2 + 2] = 1;
+ data[3 * 3 + 2] = 7;
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs(data));
+}
+
+BOOST_AUTO_TEST_CASE(memory_arrays_dynamic_index_access_write)
+{
+ char const* sourceCode = R"(
+ contract Test {
+ uint24[3][][4] data;
+ function set(uint24[3][][4] x) internal returns (uint24[3][][4]) {
+ x[1][2][2] = 1;
+ x[1][3][2] = 7;
+ return x;
+ }
+ function f() returns (uint24[3][]) {
+ data[1].length = 4;
+ return set(data)[1];
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Test");
+
+ vector<u256> data(3 * 4);
+ data[3 * 2 + 2] = 1;
+ data[3 * 3 + 2] = 7;
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0x20), u256(4), data));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}