From 1b6861e6c99ff244180eec8aac9dee50d6e45520 Mon Sep 17 00:00:00 2001 From: Daniel Ellison Date: Fri, 2 Dec 2016 07:45:42 -0500 Subject: [PATCH 1/6] Added 'panic' tests. --- test/liblll/EndToEndTest.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp index b5e32e94f..824e53cd5 100644 --- a/test/liblll/EndToEndTest.cpp +++ b/test/liblll/EndToEndTest.cpp @@ -43,6 +43,20 @@ BOOST_AUTO_TEST_CASE(smoke_test) BOOST_CHECK(callFallback() == encodeArgs(string("test", 4))); } +BOOST_AUTO_TEST_CASE(bare_panic) +{ + char const* sourceCode = "(panic)"; + compileAndRunWithoutCheck(sourceCode); + BOOST_REQUIRE(m_output.empty()); +} + +BOOST_AUTO_TEST_CASE(enclosed_panic) +{ + char const* sourceCode = "(seq (panic))"; + compileAndRunWithoutCheck(sourceCode); + BOOST_REQUIRE(m_output.empty()); +} + BOOST_AUTO_TEST_SUITE_END() } From a91b712ab8bfc5928428e308855244fb77766ca3 Mon Sep 17 00:00:00 2001 From: Daniel Ellison Date: Fri, 2 Dec 2016 09:00:33 -0500 Subject: [PATCH 2/6] Added tests for exponent operator. --- test/liblll/EndToEndTest.cpp | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp index 824e53cd5..980f8d10c 100644 --- a/test/liblll/EndToEndTest.cpp +++ b/test/liblll/EndToEndTest.cpp @@ -57,6 +57,43 @@ BOOST_AUTO_TEST_CASE(enclosed_panic) BOOST_REQUIRE(m_output.empty()); } +BOOST_AUTO_TEST_CASE(exp_operator_const) +{ + char const* sourceCode = R"( + (returnlll + (return (exp 2 3))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == toBigEndian(u256(8))); +} + +BOOST_AUTO_TEST_CASE(exp_operator_const_signed) +{ + char const* sourceCode = R"( + (returnlll + (return (exp (- 0 2) 3))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == toBigEndian(u256(-8))); +} + +BOOST_AUTO_TEST_CASE(exp_operator_parameter) +{ + char const* sourceCode = R"( + (seq + (def 'function (function-hash code-body) + (when (= (div (calldataload 0x00) (exp 2 224)) function-hash) + code-body)) + (returnlll + (seq + (function 0xb3de648b + (return (exp 2 (calldataload 0x04)))) + (jump 0x02)))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("f(uint256)", u256(16)) == toBigEndian(u256(65536))); +} + BOOST_AUTO_TEST_SUITE_END() } From 1152d2d2d4eefe36a08f7026be6d9d7031722c2e Mon Sep 17 00:00:00 2001 From: Daniel Ellison Date: Fri, 2 Dec 2016 09:26:35 -0500 Subject: [PATCH 3/6] Simplified exp_operator_on_range test and changed to tedting a range. --- test/liblll/EndToEndTest.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp index 980f8d10c..6a5a223e4 100644 --- a/test/liblll/EndToEndTest.cpp +++ b/test/liblll/EndToEndTest.cpp @@ -77,21 +77,17 @@ BOOST_AUTO_TEST_CASE(exp_operator_const_signed) BOOST_CHECK(callFallback() == toBigEndian(u256(-8))); } -BOOST_AUTO_TEST_CASE(exp_operator_parameter) +BOOST_AUTO_TEST_CASE(exp_operator_on_range) { char const* sourceCode = R"( - (seq - (def 'function (function-hash code-body) - (when (= (div (calldataload 0x00) (exp 2 224)) function-hash) - code-body)) - (returnlll - (seq - (function 0xb3de648b - (return (exp 2 (calldataload 0x04)))) - (jump 0x02)))) + (returnlll + (seq + (when (= (div (calldataload 0x00) (exp 2 224)) 0xb3de648b) + (return (exp 2 (calldataload 0x04)))) + (jump 0x02))) )"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("f(uint256)", u256(16)) == toBigEndian(u256(65536))); + testContractAgainstCppOnRange("f(uint256)", [](u256 const& a) -> u256 { return u256(1 << a.convert_to()); }, 0, 16); } BOOST_AUTO_TEST_SUITE_END() From 20a098e205020ce682c2bfe79e749167e87d41e1 Mon Sep 17 00:00:00 2001 From: Daniel Ellison Date: Fri, 2 Dec 2016 10:31:00 -0500 Subject: [PATCH 4/6] Removed enclosed_panic test until assembler bug is fixed. --- test/liblll/EndToEndTest.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp index 6a5a223e4..f4e9e4144 100644 --- a/test/liblll/EndToEndTest.cpp +++ b/test/liblll/EndToEndTest.cpp @@ -50,13 +50,6 @@ BOOST_AUTO_TEST_CASE(bare_panic) BOOST_REQUIRE(m_output.empty()); } -BOOST_AUTO_TEST_CASE(enclosed_panic) -{ - char const* sourceCode = "(seq (panic))"; - compileAndRunWithoutCheck(sourceCode); - BOOST_REQUIRE(m_output.empty()); -} - BOOST_AUTO_TEST_CASE(exp_operator_const) { char const* sourceCode = R"( From e23ef9db0265391e5a08d3ed432e0085faa78df1 Mon Sep 17 00:00:00 2001 From: Daniel Ellison Date: Fri, 2 Dec 2016 11:45:58 -0500 Subject: [PATCH 5/6] Added tests for LLL constructors. Fixed a few tab issues. --- test/liblll/EndToEndTest.cpp | 54 ++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp index f4e9e4144..5acf7822d 100644 --- a/test/liblll/EndToEndTest.cpp +++ b/test/liblll/EndToEndTest.cpp @@ -55,9 +55,9 @@ BOOST_AUTO_TEST_CASE(exp_operator_const) char const* sourceCode = R"( (returnlll (return (exp 2 3))) - )"; + )"; compileAndRun(sourceCode); - BOOST_CHECK(callFallback() == toBigEndian(u256(8))); + BOOST_CHECK(callFallback() == toBigEndian(u256(8))); } BOOST_AUTO_TEST_CASE(exp_operator_const_signed) @@ -65,9 +65,9 @@ BOOST_AUTO_TEST_CASE(exp_operator_const_signed) char const* sourceCode = R"( (returnlll (return (exp (- 0 2) 3))) - )"; + )"; compileAndRun(sourceCode); - BOOST_CHECK(callFallback() == toBigEndian(u256(-8))); + BOOST_CHECK(callFallback() == toBigEndian(u256(-8))); } BOOST_AUTO_TEST_CASE(exp_operator_on_range) @@ -78,11 +78,55 @@ BOOST_AUTO_TEST_CASE(exp_operator_on_range) (when (= (div (calldataload 0x00) (exp 2 224)) 0xb3de648b) (return (exp 2 (calldataload 0x04)))) (jump 0x02))) - )"; + )"; compileAndRun(sourceCode); testContractAgainstCppOnRange("f(uint256)", [](u256 const& a) -> u256 { return u256(1 << a.convert_to()); }, 0, 16); } +BOOST_AUTO_TEST_CASE(constructor_argument_internal_numeric) +{ + char const* sourceCode = R"( + (seq + (sstore 0x00 65535) + (returnlll + (return @@0x00))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs(u256(65535))); +} + +BOOST_AUTO_TEST_CASE(constructor_argument_internal_string) +{ + char const* sourceCode = R"( + (seq + (sstore 0x00 "test") + (returnlll + (return @@0x00))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs("test")); +} + +BOOST_AUTO_TEST_CASE(constructor_arguments_external) +{ + char const* sourceCode = R"( + (seq + (codecopy 0x00 (bytecodesize) 64) + (sstore 0x00 @0x00) + (sstore 0x01 @0x20) + (returnlll + (seq + (when (= (div (calldataload 0x00) (exp 2 224)) 0xf2c9ecd8) + (return @@0x00)) + (when (= (div (calldataload 0x00) (exp 2 224)) 0x89ea642f) + (return @@0x01)) + (jump 0x02)))) + )"; + compileAndRun(sourceCode, 0, "", encodeArgs(u256(65535), "test")); + BOOST_CHECK(callContractFunction("getNumber()") == encodeArgs(u256(65535))); + BOOST_CHECK(callContractFunction("getString()") == encodeArgs("test")); +} + BOOST_AUTO_TEST_SUITE_END() } From 0f304d2d898259f61418bdabdb83572579791674 Mon Sep 17 00:00:00 2001 From: Daniel Ellison Date: Tue, 6 Dec 2016 11:11:57 -0500 Subject: [PATCH 6/6] Removed 'panic' from 'constructor_arguments_external' and added specific test for fallback and fallthrough. Added one test for 'lit'. Added tests for arithmetic/binary/unary operations. Added the start of tests for assembler instructions within LLL source. --- test/liblll/EndToEndTest.cpp | 149 ++++++++++++++++++++++++++++++++++- 1 file changed, 147 insertions(+), 2 deletions(-) diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp index 5acf7822d..77c1f7409 100644 --- a/test/liblll/EndToEndTest.cpp +++ b/test/liblll/EndToEndTest.cpp @@ -119,14 +119,159 @@ BOOST_AUTO_TEST_CASE(constructor_arguments_external) (when (= (div (calldataload 0x00) (exp 2 224)) 0xf2c9ecd8) (return @@0x00)) (when (= (div (calldataload 0x00) (exp 2 224)) 0x89ea642f) - (return @@0x01)) - (jump 0x02)))) + (return @@0x01))))) )"; compileAndRun(sourceCode, 0, "", encodeArgs(u256(65535), "test")); BOOST_CHECK(callContractFunction("getNumber()") == encodeArgs(u256(65535))); BOOST_CHECK(callContractFunction("getString()") == encodeArgs("test")); } +BOOST_AUTO_TEST_CASE(fallback_and_invalid_function) +{ + char const* sourceCode = R"( + (returnlll + (seq + (when (= (div (calldataload 0x00) (exp 2 224)) 0xab5ed150) + (return "one")) + (when (= (div (calldataload 0x00) (exp 2 224)) 0xee784123) + (return "two")) + (return "three"))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("getOne()") == encodeArgs("one")); + BOOST_CHECK(callContractFunction("getTwo()") == encodeArgs("two")); + BOOST_CHECK(callContractFunction("invalidFunction()") == encodeArgs("three")); + BOOST_CHECK(callFallback() == encodeArgs("three")); +} + +BOOST_AUTO_TEST_CASE(lit_string) +{ + char const* sourceCode = R"( + (returnlll + (seq + (lit 0x00 "abcdef") + (return 0x00 0x20))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs(string("abcdef"))); +} + +BOOST_AUTO_TEST_CASE(arithmetic) +{ + char const* sourceCode = R"( + (returnlll + (seq + (mstore8 0x00 (+ 160 22)) + (mstore8 0x01 (- 223 41)) + (mstore8 0x02 (* 33 2)) + (mstore8 0x03 (/ 10 2)) + (mstore8 0x04 (% 67 2)) + (mstore8 0x05 (& 15 8)) + (mstore8 0x06 (| 18 8)) + (mstore8 0x07 (^ 26 6)) + (return 0x00 0x20))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs( + fromHex("b6b6420501081a1c000000000000000000000000000000000000000000000000"))); +} + +BOOST_AUTO_TEST_CASE(binary) +{ + char const* sourceCode = R"( + (returnlll + (seq + (mstore8 0x00 (< 53 87)) + (mstore8 0x01 (< 73 42)) + (mstore8 0x02 (<= 37 94)) + (mstore8 0x03 (<= 37 37)) + (mstore8 0x04 (<= 183 34)) + (mstore8 0x05 (S< (- 0 53) 87)) + (mstore8 0x06 (S< 73 (- 0 42))) + (mstore8 0x07 (S<= (- 0 37) 94)) + (mstore8 0x08 (S<= (- 0 37) (- 0 37))) + (mstore8 0x09 (S<= 183 (- 0 34))) + (mstore8 0x0a (> 73 42)) + (mstore8 0x0b (> 53 87)) + (mstore8 0x0c (>= 94 37)) + (mstore8 0x0d (>= 94 94)) + (mstore8 0x0e (>= 34 183)) + (mstore8 0x0f (S> 73 (- 0 42))) + (mstore8 0x10 (S> (- 0 53) 87)) + (mstore8 0x11 (S>= 94 (- 0 37))) + (mstore8 0x12 (S>= (- 0 94) (- 0 94))) + (mstore8 0x13 (S>= (- 0 34) 183)) + (mstore8 0x14 (= 53 53)) + (mstore8 0x15 (= 73 42)) + (mstore8 0x16 (!= 37 94)) + (mstore8 0x17 (!= 37 37)) + (return 0x00 0x20))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs( + fromHex("0100010100010001010001000101000100010100010001000000000000000000"))); +} + +BOOST_AUTO_TEST_CASE(unary) +{ + char const* sourceCode = R"( + (returnlll + (seq + (mstore8 0x00 (! (< 53 87))) + (mstore8 0x01 (! (>= 42 73))) + (mstore8 0x02 (~ 0x7f)) + (mstore8 0x03 (~ 0xaa)) + (return 0x00 0x20))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs( + fromHex("0001805500000000000000000000000000000000000000000000000000000000"))); +} + +BOOST_AUTO_TEST_CASE(assembly_mload_mstore) +{ + char const* sourceCode = R"( + (returnlll + (asm + 0x07 0x00 mstore + "abcdef" 0x20 mstore + 0x00 mload 0x40 mstore + 0x20 mload 0x60 mstore + 0x40 0x40 return)) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs(u256(7), string("abcdef"))); +} + +BOOST_AUTO_TEST_CASE(assembly_sload_sstore) +{ + char const* sourceCode = R"( + (returnlll + (asm + 0x07 0x00 sstore + "abcdef" 0x01 sstore + 0x00 sload 0x00 mstore + 0x01 sload 0x20 mstore + 0x40 0x00 return)) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs(u256(7), string("abcdef"))); +} + +BOOST_AUTO_TEST_CASE(assembly_codecopy) +{ + char const* sourceCode = R"( + (returnlll + (seq + (lit 0x00 "abcdef") + (asm + 0x06 0x16 0x20 codecopy + 0x20 0x20 return))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs(string("abcdef"))); +} + BOOST_AUTO_TEST_SUITE_END() }