aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp18
-rw-r--r--test/libsolidity/SolidityExpressionCompiler.cpp7
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp12
3 files changed, 34 insertions, 3 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 8c537346..30ae5792 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -6775,6 +6775,24 @@ BOOST_AUTO_TEST_CASE(iszero_bnot_correct)
BOOST_CHECK(callContractFunction("f()") == encodeArgs(true));
}
+BOOST_AUTO_TEST_CASE(cleanup_bytes_types)
+{
+ // Checks that bytesXX types are properly cleaned before they are compared.
+ char const* sourceCode = R"(
+ contract C {
+ function f(bytes2 a, uint16 x) returns (uint) {
+ if (a != "ab") return 1;
+ if (x != 0x0102) return 2;
+ if (bytes3(x) != 0x0102) return 3;
+ return 0;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ // We input longer data on purpose.
+ BOOST_CHECK(callContractFunction("f(bytes2,uint16)", string("abc"), u256(0x040102)) == encodeArgs(0));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp
index 398ac24f..967b2907 100644
--- a/test/libsolidity/SolidityExpressionCompiler.cpp
+++ b/test/libsolidity/SolidityExpressionCompiler.cpp
@@ -267,10 +267,10 @@ BOOST_AUTO_TEST_CASE(comparison)
"}\n";
bytes code = compileFirstExpression(sourceCode);
- bytes expectation({byte(Instruction::PUSH1), 0x1,
+ bytes expectation({byte(Instruction::PUSH1), 0x1, byte(Instruction::ISZERO), byte(Instruction::ISZERO),
byte(Instruction::PUSH2), 0x11, 0xaa,
byte(Instruction::PUSH2), 0x10, 0xaa,
- byte(Instruction::LT),
+ byte(Instruction::LT), byte(Instruction::ISZERO), byte(Instruction::ISZERO),
byte(Instruction::EQ),
byte(Instruction::ISZERO)});
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
@@ -296,7 +296,8 @@ BOOST_AUTO_TEST_CASE(short_circuiting)
byte(Instruction::EQ),
byte(Instruction::ISZERO), // after this we have 9 != 2
byte(Instruction::JUMPDEST),
- byte(Instruction::PUSH1), 0x1,
+ byte(Instruction::ISZERO), byte(Instruction::ISZERO),
+ byte(Instruction::PUSH1), 0x1, byte(Instruction::ISZERO), byte(Instruction::ISZERO),
byte(Instruction::EQ),
byte(Instruction::ISZERO)});
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index bbc77d34..52e0bf58 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -3683,6 +3683,18 @@ BOOST_AUTO_TEST_CASE(zero_handling)
BOOST_CHECK(success(text));
}
+BOOST_AUTO_TEST_CASE(missing_bool_conversion)
+{
+ char const* text = R"(
+ contract test {
+ function b(uint a) {
+ bool(a == 1);
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
BOOST_AUTO_TEST_CASE(integer_and_fixed_interaction)
{
char const* text = R"(