aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-12-10 03:18:24 +0800
committerchriseth <c@ethdev.com>2016-12-12 18:12:12 +0800
commit2fac1d23a78d898ab78f1a8e347c40ae673c039c (patch)
treebe607dea37faf153880e9390195b29003902b483 /test/libsolidity/SolidityEndToEndTest.cpp
parent7bc2ecf30afe8fde3a178a9f9f298a56c845a078 (diff)
downloaddexon-solidity-2fac1d23a78d898ab78f1a8e347c40ae673c039c.tar.gz
dexon-solidity-2fac1d23a78d898ab78f1a8e347c40ae673c039c.tar.zst
dexon-solidity-2fac1d23a78d898ab78f1a8e347c40ae673c039c.zip
Tests for bytes.
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index ff128330..9e2c41af 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -8772,6 +8772,44 @@ BOOST_AUTO_TEST_CASE(shift_overflow)
BOOST_CHECK(callContractFunction("leftS(int8,int8)", 1, 6) == encodeArgs(u256(64)));
}
+BOOST_AUTO_TEST_CASE(shift_bytes)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function left(bytes20 x, uint8 y) returns (bytes20) {
+ return x << y;
+ }
+ function right(bytes20 x, uint8 y) returns (bytes20) {
+ return x >> y;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ BOOST_CHECK(callContractFunction("left(bytes20,uint8)", "12345678901234567890", 8 * 8) == encodeArgs("901234567890" + string(8, 0)));
+ BOOST_CHECK(callContractFunction("right(bytes20,uint8)", "12345678901234567890", 8 * 8) == encodeArgs(string(8, 0) + "123456789012"));
+}
+
+BOOST_AUTO_TEST_CASE(shift_bytes_cleanup)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function left(uint8 y) returns (bytes20) {
+ bytes20 x;
+ assembly { x := "12345678901234567890abcde" }
+ return x << y;
+ }
+ function right(uint8 y) returns (bytes20) {
+ bytes20 x;
+ assembly { x := "12345678901234567890abcde" }
+ return x >> y;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ BOOST_CHECK(callContractFunction("left(uint8)", 8 * 8) == encodeArgs("901234567890" + string(8, 0)));
+ BOOST_CHECK(callContractFunction("right(uint8)", 8 * 8) == encodeArgs(string(8, 0) + "123456789012"));
+}
+
BOOST_AUTO_TEST_CASE(cleanup_in_compound_assign)
{
char const* sourceCode = R"(