aboutsummaryrefslogtreecommitdiffstats
path: root/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-03-14 02:48:24 +0800
committerchriseth <c@ethdev.com>2015-03-17 01:07:14 +0800
commit1d44a8999e2dbbd5547f511958bcf744267938f7 (patch)
tree7d1491e530e4b797c67ddf48d8c08b7479dc87ea /SolidityEndToEndTest.cpp
parent354d84e0a72b66e627be5a50dc1d8608ac32bb7c (diff)
downloaddexon-solidity-1d44a8999e2dbbd5547f511958bcf744267938f7.tar
dexon-solidity-1d44a8999e2dbbd5547f511958bcf744267938f7.tar.gz
dexon-solidity-1d44a8999e2dbbd5547f511958bcf744267938f7.tar.bz2
dexon-solidity-1d44a8999e2dbbd5547f511958bcf744267938f7.tar.lz
dexon-solidity-1d44a8999e2dbbd5547f511958bcf744267938f7.tar.xz
dexon-solidity-1d44a8999e2dbbd5547f511958bcf744267938f7.tar.zst
dexon-solidity-1d44a8999e2dbbd5547f511958bcf744267938f7.zip
Fetch and store packed values.
Diffstat (limited to 'SolidityEndToEndTest.cpp')
-rw-r--r--SolidityEndToEndTest.cpp150
1 files changed, 138 insertions, 12 deletions
diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp
index de6f43b7..a07b7887 100644
--- a/SolidityEndToEndTest.cpp
+++ b/SolidityEndToEndTest.cpp
@@ -991,18 +991,20 @@ BOOST_AUTO_TEST_CASE(multiple_elementary_accessors)
BOOST_AUTO_TEST_CASE(complex_accessors)
{
- char const* sourceCode = "contract test {\n"
- " mapping(uint256 => bytes4) 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";
+ char const* sourceCode = R"(
+ contract test {
+ mapping(uint256 => bytes4) public to_string_map;
+ mapping(uint256 => bool) public to_bool_map;
+ mapping(uint256 => uint256) public to_uint_map;
+ mapping(uint256 => mapping(uint256 => uint256)) public to_multiple_map;
+ function test() {
+ to_string_map[42] = "24";
+ to_bool_map[42] = false;
+ to_uint_map[42] = 12;
+ to_multiple_map[42][23] = 31;
+ }
+ }
+ )";
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("to_string_map(uint256)", 42) == encodeArgs("24"));
BOOST_CHECK(callContractFunction("to_bool_map(uint256)", 42) == encodeArgs(false));
@@ -3269,6 +3271,130 @@ BOOST_AUTO_TEST_CASE(constant_variables)
})";
compileAndRun(sourceCode);
}
+
+BOOST_AUTO_TEST_CASE(packed_storage_structs_uint)
+{
+ char const* sourceCode = R"(
+ contract C {
+ struct str { uint8 a; uint16 b; uint248 c; }
+ str data;
+ function test() returns (uint) {
+ data.a = 2;
+ if (data.a != 2) return 2;
+ data.b = 0xabcd;
+ if (data.b != 0xabcd) return 3;
+ data.c = 0x1234567890;
+ if (data.c != 0x1234567890) return 4;
+ if (data.a != 2) return 5;
+ data.a = 8;
+ if (data.a != 8) return 6;
+ if (data.b != 0xabcd) return 7;
+ data.b = 0xdcab;
+ if (data.b != 0xdcab) return 8;
+ if (data.c != 0x1234567890) return 9;
+ data.c = 0x9876543210;
+ if (data.c != 0x9876543210) return 10;
+ return 1;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("test()") == encodeArgs(1));
+}
+
+BOOST_AUTO_TEST_CASE(packed_storage_structs_enum)
+{
+ char const* sourceCode = R"(
+ contract C {
+ enum small { A, B, C, D }
+ enum larger { A, B, C, D, E}
+ struct str { small a; small b; larger c; larger d; }
+ str data;
+ function test() returns (uint) {
+ data.a = small.B;
+ if (data.a != small.B) return 2;
+ data.b = small.C;
+ if (data.b != small.C) return 3;
+ data.c = larger.D;
+ if (data.c != larger.D) return 4;
+ if (data.a != small.B) return 5;
+ data.a = small.C;
+ if (data.a != small.C) return 6;
+ if (data.b != small.C) return 7;
+ data.b = small.D;
+ if (data.b != small.D) return 8;
+ if (data.c != larger.D) return 9;
+ data.c = larger.B;
+ if (data.c != larger.B) return 10;
+ return 1;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("test()") == encodeArgs(1));
+}
+
+BOOST_AUTO_TEST_CASE(packed_storage_structs_bytes)
+{
+ char const* sourceCode = R"(
+ contract C {
+ struct s1 { byte a; byte b; bytes10 c; bytes9 d; bytes10 e; }
+ struct s2 { byte a; s1 inner; byte b; byte c; }
+ byte x;
+ s2 data;
+ byte y;
+ function test() returns (bool) {
+ x = 1;
+ data.a = 2;
+ data.inner.a = 3;
+ data.inner.b = 4;
+ data.inner.c = "1234567890";
+ data.inner.d = "123456789";
+ data.inner.e = "abcdefghij";
+ data.b = 5;
+ data.c = 6;
+ y = 7;
+ return x == 1 && data.a == 2 && data.inner.a == 3 && data.inner.b == 4 &&
+ data.inner.c == "1234567890" && data.inner.d == "123456789" &&
+ data.inner.e == "abcdefghij" && data.b == 5 && data.c == 6 && y == 7;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("test()") == encodeArgs(true));
+}
+
+BOOST_AUTO_TEST_CASE(packed_storage_structs_delete)
+{
+ char const* sourceCode = R"(
+ contract C {
+ struct str { uint8 a; uint16 b; uint8 c; }
+ uint8 x;
+ uint16 y;
+ str data;
+ function test() returns (uint) {
+ x = 1;
+ y = 2;
+ data.a = 2;
+ data.b = 0xabcd;
+ data.c = 0xfa;
+ if (x != 1 || y != 2 || data.a != 2 || data.b != 0xabcd || data.c != 0xfa)
+ return 2;
+ delete y;
+ delete data.b;
+ if (x != 1 || y != 0 || data.a != 2 || data.b != 0 || data.c != 0xfa)
+ return 3;
+ delete x;
+ delete data;
+ return 1;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("test()") == encodeArgs(1));
+ BOOST_CHECK(m_state.storage(m_contractAddress).empty());
+}
+
BOOST_AUTO_TEST_SUITE_END()
}