aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/liblll/EndToEndTest.cpp86
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp68
2 files changed, 152 insertions, 2 deletions
diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp
index f3bfb438..4e896fd0 100644
--- a/test/liblll/EndToEndTest.cpp
+++ b/test/liblll/EndToEndTest.cpp
@@ -387,6 +387,37 @@ BOOST_AUTO_TEST_CASE(assembly_codecopy)
BOOST_CHECK(callFallback() == encodeArgs(string("abcdef")));
}
+BOOST_AUTO_TEST_CASE(for_loop)
+{
+ char const* sourceCode = R"(
+ (returnlll
+ (seq
+ (for
+ { (set 'i 1) (set 'j 1) } ; INIT
+ (<= @i 10) ; PRED
+ [i]:(+ @i 1) ; POST
+ [j]:(* @j @i)) ; BODY
+ (return j 0x20)))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallback() == encodeArgs(u256(3628800))); // 10!
+}
+
+BOOST_AUTO_TEST_CASE(while_loop)
+{
+ char const* sourceCode = R"(
+ (returnlll
+ (seq
+ ;; Euclid's GCD algorithm
+ (set 'a 1071)
+ (set 'b 462)
+ (while @b
+ [a]:(raw @b [b]:(mod @a @b)))
+ (return a 0x20)))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallback() == encodeArgs(u256(21))); // GCD(1071,462)
+}
BOOST_AUTO_TEST_CASE(keccak256_32bytes)
{
@@ -436,6 +467,61 @@ BOOST_AUTO_TEST_CASE(send_three_args)
BOOST_CHECK(balanceAt(Address(0xdead)) == 42);
}
+// Regression test for edge case that previously failed
+BOOST_AUTO_TEST_CASE(alloc_zero)
+{
+ char const* sourceCode = R"(
+ (returnlll
+ (seq
+ (mstore 0x00 (~ 0))
+ (alloc 0)
+ (return 0x00 0x20)))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallback() == encodeArgs(u256(-1)));
+}
+
+BOOST_AUTO_TEST_CASE(alloc_size)
+{
+ char const* sourceCode = R"(
+ (returnlll
+ (seq
+ (mstore 0x00 0) ; reserve space for the result of the alloc
+ (mstore 0x00 (alloc (calldataload 0x04)))
+ (return (- (msize) (mload 0x00)))))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("test()", 0) == encodeArgs(u256(0)));
+ BOOST_CHECK(callContractFunction("test()", 1) == encodeArgs(u256(32)));
+ BOOST_CHECK(callContractFunction("test()", 32) == encodeArgs(u256(32)));
+ BOOST_CHECK(callContractFunction("test()", 33) == encodeArgs(u256(64)));
+}
+
+BOOST_AUTO_TEST_CASE(alloc_start)
+{
+ char const* sourceCode = R"(
+ (returnlll
+ (seq
+ (mstore 0x40 0) ; Set initial MSIZE to 0x60
+ (return (alloc 1))))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallback() == encodeArgs(96));
+}
+
+BOOST_AUTO_TEST_CASE(alloc_with_variable)
+{
+ char const* sourceCode = R"(
+ (returnlll
+ (seq
+ (set 'x (alloc 1))
+ (mstore8 @x 42) ; ASCII '*'
+ (return @x 0x20)))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallback() == encodeArgs("*"));
+}
+
BOOST_AUTO_TEST_CASE(msg_six_args)
{
char const* sourceCode = R"(
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index d0aee3d0..2ee5baac 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -2817,7 +2817,7 @@ BOOST_AUTO_TEST_CASE(uninitialized_mapping_array_variable)
char const* sourceCode = R"(
contract C {
function f() {
- mapping(uint => uint)[] x;
+ mapping(uint => uint)[] storage x;
x;
}
}
@@ -3103,7 +3103,7 @@ BOOST_AUTO_TEST_CASE(non_initialized_references)
}
function f()
{
- s x;
+ s storage x;
x.a = 2;
}
}
@@ -5428,6 +5428,20 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage_variable_access_out_of_functions)
CHECK_SUCCESS_NO_WARNINGS(text);
}
+BOOST_AUTO_TEST_CASE(inline_assembly_calldata_variables)
+{
+ char const* text = R"(
+ contract C {
+ function f(bytes bytesAsCalldata) external {
+ assembly {
+ let x := bytesAsCalldata
+ }
+ }
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Call data elements cannot be accessed directly.");
+}
+
BOOST_AUTO_TEST_CASE(invalid_mobile_type)
{
char const* text = R"(
@@ -5860,6 +5874,18 @@ BOOST_AUTO_TEST_CASE(using_interface_complex)
success(text);
}
+BOOST_AUTO_TEST_CASE(warn_about_throw)
+{
+ char const* text = R"(
+ contract C {
+ function f() {
+ throw;
+ }
+ }
+ )";
+ CHECK_WARNING(text, "\"throw\" is deprecated");
+}
+
BOOST_AUTO_TEST_CASE(bare_revert)
{
char const* text = R"(
@@ -6144,6 +6170,44 @@ BOOST_AUTO_TEST_CASE(shadowing_warning_can_be_removed)
CHECK_SUCCESS_NO_WARNINGS(text);
}
+BOOST_AUTO_TEST_CASE(warn_unspecified_storage)
+{
+ char const* text = R"(
+ contract C {
+ struct S { uint a; string b; }
+ S x;
+ function f() {
+ S storage y = x;
+ y;
+ }
+ }
+ )";
+ CHECK_SUCCESS_NO_WARNINGS(text);
+ text = R"(
+ contract C {
+ struct S { uint a; }
+ S x;
+ function f() {
+ S y = x;
+ y;
+ }
+ }
+ )";
+ CHECK_WARNING(text, "is declared as a storage pointer. Use an explicit \"storage\" keyword to silence this warning");
+}
+
+BOOST_AUTO_TEST_CASE(implicit_conversion_disallowed)
+{
+ char const* text = R"(
+ contract C {
+ function f() returns (bytes4) {
+ uint32 tmp = 1;
+ return tmp;
+ }
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Return argument type uint32 is not implicitly convertible to expected type (type of first return variable) bytes4.");
+}
BOOST_AUTO_TEST_SUITE_END()