aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-07-12 04:44:41 +0800
committerGitHub <noreply@github.com>2017-07-12 04:44:41 +0800
commit699a3724ae57168578dbc9844ca20c4af1ed7bcf (patch)
tree9239c642e4027fbaabd98ea446ba1996cb4a2371 /test
parent709b1a99c10b0456987748c8dfa8f0c6dad2f7a6 (diff)
parent3bc935d932da3d7e8ff21bb3057276338c4ad497 (diff)
downloaddexon-solidity-699a3724ae57168578dbc9844ca20c4af1ed7bcf.tar.gz
dexon-solidity-699a3724ae57168578dbc9844ca20c4af1ed7bcf.tar.zst
dexon-solidity-699a3724ae57168578dbc9844ca20c4af1ed7bcf.zip
Merge pull request #2545 from benjaminion/lll-alloc-updated
LLL: alloc issues round-up
Diffstat (limited to 'test')
-rw-r--r--test/liblll/EndToEndTest.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp
index 7f4dd91a..4e896fd0 100644
--- a/test/liblll/EndToEndTest.cpp
+++ b/test/liblll/EndToEndTest.cpp
@@ -467,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"(