aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-11-17 22:15:00 +0800
committerchriseth <c@ethdev.com>2015-11-26 20:10:12 +0800
commit879844dd0a9137602373c8f67f283a5895913732 (patch)
treeea084fcbf268c0a1644f62364c6d9713ed119604 /test/libsolidity
parentbf55aa6ae2b9aeec09bb8cf1e3715afd7dd59b7e (diff)
downloaddexon-solidity-879844dd0a9137602373c8f67f283a5895913732.tar.gz
dexon-solidity-879844dd0a9137602373c8f67f283a5895913732.tar.zst
dexon-solidity-879844dd0a9137602373c8f67f283a5895913732.zip
Code generation for creating arrays.
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 681ab107..0b356145 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -5816,6 +5816,50 @@ BOOST_AUTO_TEST_CASE(lone_struct_array_type)
BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(3)));
}
+BOOST_AUTO_TEST_CASE(create_memory_array)
+{
+ char const* sourceCode = R"(
+ contract C {
+ struct S { uint[2] a; bytes b; }
+ function f() returns (byte, uint, uint, byte) {
+ var x = new bytes(200);
+ x[199] = 'A';
+ var y = new uint[2][](300);
+ y[203][1] = 8;
+ var z = new S[](180);
+ z[170].a[1] = 4;
+ z[170].b = new bytes(102);
+ z[170].b[99] = 'B';
+ return (x[199], y[203][1], z[170].a[1], z[170].b[99]);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs(string("A"), u256(8), u256(4), string("B")));
+}
+
+BOOST_AUTO_TEST_CASE(memory_arrays_of_various_sizes)
+{
+ // Computes binomial coefficients the chinese way
+ char const* sourceCode = R"(
+ contract C {
+ function f(uint n, uint k) returns (uint) {
+ uint[][] memory rows = new uint[][](n + 1);
+ for (uint i = 1; i <= n; i++) {
+ rows[i] = new uint[](i);
+ rows[i][0] = rows[i][rows[i].length - 1] = 1;
+ for (uint j = 1; j < i - 1; j++)
+ rows[i][j] = rows[i - 1][j - 1] + rows[i - 1][j];
+ }
+ return rows[n][k - 1];
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("f(uint256,uint256)", encodeArgs(u256(3), u256(1))) == encodeArgs(u256(1)));
+ BOOST_CHECK(callContractFunction("f(uint256,uint256)", encodeArgs(u256(9), u256(5))) == encodeArgs(u256(70)));
+}
+
BOOST_AUTO_TEST_CASE(memory_overwrite)
{
char const* sourceCode = R"(