aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2016-10-20 20:20:58 +0800
committerGitHub <noreply@github.com>2016-10-20 20:20:58 +0800
commit9d30450167d5b262d0e7379f44f01637715fb878 (patch)
tree72c4f401a72a54c81c78b53870fc04483dc235e4 /test
parent2bb37f8203d5b64f603d4c7c802407a5500429b5 (diff)
parentd5c94cb4121f2ab97ea52a5471e18c26434dd6e3 (diff)
downloaddexon-solidity-9d30450167d5b262d0e7379f44f01637715fb878.tar.gz
dexon-solidity-9d30450167d5b262d0e7379f44f01637715fb878.tar.zst
dexon-solidity-9d30450167d5b262d0e7379f44f01637715fb878.zip
Merge pull request #1034 from ethereum/shift-constants
Shift constants (<< and >>)
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp44
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp40
2 files changed, 84 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 692abe57..088fe4d1 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -7260,6 +7260,50 @@ BOOST_AUTO_TEST_CASE(mem_resize_is_not_paid_at_call)
BOOST_CHECK(callContractFunction("f(address)", cAddrOpt) == encodeArgs(u256(7)));
}
+BOOST_AUTO_TEST_CASE(shift_constant_left)
+{
+ char const* sourceCode = R"(
+ contract C {
+ uint public a = 0x42 << 8;
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(0x4200)));
+}
+
+BOOST_AUTO_TEST_CASE(shift_negative_constant_left)
+{
+ char const* sourceCode = R"(
+ contract C {
+ int public a = -0x42 << 8;
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(-0x4200)));
+}
+
+BOOST_AUTO_TEST_CASE(shift_constant_right)
+{
+ char const* sourceCode = R"(
+ contract C {
+ uint public a = 0x4200 >> 8;
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(0x42)));
+}
+
+BOOST_AUTO_TEST_CASE(shift_negative_constant_right)
+{
+ char const* sourceCode = R"(
+ contract C {
+ int public a = -0x4200 >> 8;
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(-0x42)));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 1691b1c5..7eedbefa 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -4039,6 +4039,46 @@ BOOST_AUTO_TEST_CASE(using_directive_for_missing_selftype)
BOOST_CHECK(expectError(text, false) == Error::Type::TypeError);
}
+BOOST_AUTO_TEST_CASE(shift_constant_left_negative_rvalue)
+{
+ char const* text = R"(
+ contract C {
+ uint public a = 0x42 << -8;
+ }
+ )";
+ BOOST_CHECK(expectError(text, false) == Error::Type::TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(shift_constant_right_negative_rvalue)
+{
+ char const* text = R"(
+ contract C {
+ uint public a = 0x42 >> -8;
+ }
+ )";
+ BOOST_CHECK(expectError(text, false) == Error::Type::TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(shift_constant_left_excessive_rvalue)
+{
+ char const* text = R"(
+ contract C {
+ uint public a = 0x42 << 0x100000000;
+ }
+ )";
+ BOOST_CHECK(expectError(text, false) == Error::Type::TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(shift_constant_right_excessive_rvalue)
+{
+ char const* text = R"(
+ contract C {
+ uint public a = 0x42 >> 0x100000000;
+ }
+ )";
+ BOOST_CHECK(expectError(text, false) == Error::Type::TypeError);
+}
+
BOOST_AUTO_TEST_SUITE_END()
}