aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-11-27 22:02:46 +0800
committerGitHub <noreply@github.com>2017-11-27 22:02:46 +0800
commita1f59cbb17d29ca5f92fa1cc20d17f47026ade5a (patch)
treed17e5ab7a2c9cd5ffacba728851e6c127182fbe0 /test/libsolidity
parenta7136dbc16ba7e0cf8a7d6097d50cc40c1248914 (diff)
parent1d91b65b726d4757b866124d75834f28a9bc9eb9 (diff)
downloaddexon-solidity-a1f59cbb17d29ca5f92fa1cc20d17f47026ade5a.tar.gz
dexon-solidity-a1f59cbb17d29ca5f92fa1cc20d17f47026ade5a.tar.zst
dexon-solidity-a1f59cbb17d29ca5f92fa1cc20d17f47026ade5a.zip
Merge pull request #3220 from ethereum/IuliaIf
If statement for Iulia / Inline Assembly
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/InlineAssembly.cpp33
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp18
2 files changed, 50 insertions, 1 deletions
diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp
index da3522b4..e9fb8431 100644
--- a/test/libsolidity/InlineAssembly.cpp
+++ b/test/libsolidity/InlineAssembly.cpp
@@ -251,6 +251,27 @@ BOOST_AUTO_TEST_CASE(variable_use_before_decl)
CHECK_PARSE_ERROR("{ let x := mul(2, x) }", DeclarationError, "Variable x used before it was declared.");
}
+BOOST_AUTO_TEST_CASE(if_statement)
+{
+ BOOST_CHECK(successParse("{ if 42 {} }"));
+ BOOST_CHECK(successParse("{ if 42 { let x := 3 } }"));
+ BOOST_CHECK(successParse("{ function f() -> x {} if f() { pop(f()) } }"));
+}
+
+BOOST_AUTO_TEST_CASE(if_statement_scope)
+{
+ BOOST_CHECK(successParse("{ let x := 2 if 42 { x := 3 } }"));
+ CHECK_PARSE_ERROR("{ if 32 { let x := 3 } x := 2 }", DeclarationError, "Variable not found or variable not lvalue.");
+}
+
+BOOST_AUTO_TEST_CASE(if_statement_invalid)
+{
+ CHECK_PARSE_ERROR("{ if calldatasize {}", ParserError, "Instructions are not supported as conditions for if");
+ BOOST_CHECK("{ if calldatasize() {}");
+ CHECK_PARSE_ERROR("{ if mstore(1, 1) {} }", ParserError, "Instruction \"mstore\" not allowed in this context");
+ CHECK_PARSE_ERROR("{ if 32 let x := 3 }", ParserError, "Expected token LBrace");
+}
+
BOOST_AUTO_TEST_CASE(switch_statement)
{
BOOST_CHECK(successParse("{ switch 42 default {} }"));
@@ -275,7 +296,7 @@ BOOST_AUTO_TEST_CASE(switch_duplicate_case)
BOOST_AUTO_TEST_CASE(switch_invalid_expression)
{
CHECK_PARSE_ERROR("{ switch {} default {} }", ParserError, "Literal, identifier or instruction expected.");
- CHECK_PARSE_ERROR("{ switch calldatasize default {} }", ParserError, "Instructions are not supported as expressions for switch.");
+ CHECK_PARSE_ERROR("{ switch calldatasize default {} }", ParserError, "Instructions are not supported as expressions for switch");
CHECK_PARSE_ERROR("{ switch mstore(1, 1) default {} }", ParserError, "Instruction \"mstore\" not allowed in this context");
}
@@ -487,6 +508,11 @@ BOOST_AUTO_TEST_CASE(print_string_literal_unicode)
parsePrintCompare(parsed);
}
+BOOST_AUTO_TEST_CASE(print_if)
+{
+ parsePrintCompare("{\n if 2\n {\n pop(mload(0))\n }\n}");
+}
+
BOOST_AUTO_TEST_CASE(print_switch)
{
parsePrintCompare("{\n switch 42\n case 1 {\n }\n case 2 {\n }\n default {\n }\n}");
@@ -628,6 +654,11 @@ BOOST_AUTO_TEST_CASE(for_statement)
BOOST_CHECK(successAssemble("{ let x := calldatasize() for { let i := 0} lt(i, x) { i := add(i, 1) } { mstore(i, 2) } }"));
}
+BOOST_AUTO_TEST_CASE(if_statement)
+{
+ BOOST_CHECK(successAssemble("{ if 1 {} }"));
+ BOOST_CHECK(successAssemble("{ let x := 0 if eq(calldatasize(), 0) { x := 1 } mstore(0, x) }"));
+}
BOOST_AUTO_TEST_CASE(large_constant)
{
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index c2f96aaa..05dc9ba3 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -8032,6 +8032,24 @@ BOOST_AUTO_TEST_CASE(inline_assembly_embedded_function_call)
ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1), u256(4), u256(7), u256(0x10)));
}
+BOOST_AUTO_TEST_CASE(inline_assembly_if)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f(uint a) returns (uint b) {
+ assembly {
+ if gt(a, 1) { b := 2 }
+ }
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("f(uint256)", u256(0)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("f(uint256)", u256(1)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("f(uint256)", u256(2)), encodeArgs(u256(2)));
+ ABI_CHECK(callContractFunction("f(uint256)", u256(3)), encodeArgs(u256(2)));
+}
+
BOOST_AUTO_TEST_CASE(inline_assembly_switch)
{
char const* sourceCode = R"(