From d84e9e7b6a91ddd9cb9462e96883fd681e2a90a0 Mon Sep 17 00:00:00 2001 From: benjaminion Date: Fri, 21 Jul 2017 10:23:03 +0100 Subject: LLL: Test cases for nested IF expressions. --- test/liblll/EndToEndTest.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'test/liblll/EndToEndTest.cpp') diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp index 4e896fd0..9292d963 100644 --- a/test/liblll/EndToEndTest.cpp +++ b/test/liblll/EndToEndTest.cpp @@ -165,6 +165,56 @@ BOOST_AUTO_TEST_CASE(conditional_seq) BOOST_CHECK(callFallback() == toBigEndian(u256(1))); } +BOOST_AUTO_TEST_CASE(conditional_nested_else) +{ + char const* sourceCode = R"( + (returnlll + (seq + (def 'input (calldataload 0x04)) + ;; Calculates width in bytes of utf-8 characters. + (return + (if (< input 0x80) 1 + (if (< input 0xE0) 2 + (if (< input 0xF0) 3 + (if (< input 0xF8) 4 + (if (< input 0xFC) 5 + 6)))))))) + + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("test()", 0x00) == encodeArgs(u256(1))); + BOOST_CHECK(callContractFunction("test()", 0x80) == encodeArgs(u256(2))); + BOOST_CHECK(callContractFunction("test()", 0xe0) == encodeArgs(u256(3))); + BOOST_CHECK(callContractFunction("test()", 0xf0) == encodeArgs(u256(4))); + BOOST_CHECK(callContractFunction("test()", 0xf8) == encodeArgs(u256(5))); + BOOST_CHECK(callContractFunction("test()", 0xfc) == encodeArgs(u256(6))); +} + +BOOST_AUTO_TEST_CASE(conditional_nested_then) +{ + char const* sourceCode = R"( + (returnlll + (seq + (def 'input (calldataload 0x04)) + ;; Calculates width in bytes of utf-8 characters. + (return + (if (>= input 0x80) + (if (>= input 0xE0) + (if (>= input 0xF0) + (if (>= input 0xF8) + (if (>= input 0xFC) + 6 5) 4) 3) 2) 1)))) + + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("test()", 0x00) == encodeArgs(u256(1))); + BOOST_CHECK(callContractFunction("test()", 0x80) == encodeArgs(u256(2))); + BOOST_CHECK(callContractFunction("test()", 0xe0) == encodeArgs(u256(3))); + BOOST_CHECK(callContractFunction("test()", 0xf0) == encodeArgs(u256(4))); + BOOST_CHECK(callContractFunction("test()", 0xf8) == encodeArgs(u256(5))); + BOOST_CHECK(callContractFunction("test()", 0xfc) == encodeArgs(u256(6))); +} + BOOST_AUTO_TEST_CASE(exp_operator_const) { char const* sourceCode = R"( -- cgit