From f26fe5bc1c835302af27981e96d0ebbf31c80389 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 9 Feb 2017 16:34:48 +0000 Subject: Add tests for revert() --- test/libsolidity/InlineAssembly.cpp | 5 +++++ test/libsolidity/SolidityEndToEndTest.cpp | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index cf0343a9..37d17495 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -205,6 +205,11 @@ BOOST_AUTO_TEST_CASE(inline_assembly_shadowed_instruction_functional_assignment) BOOST_CHECK(!successAssemble("{ gas := 2 }")); } +BOOST_AUTO_TEST_CASE(revert) +{ + BOOST_CHECK(successAssemble("{ revert(0, 0) }")); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index e49db34e..8c0e29fd 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -9096,6 +9096,25 @@ BOOST_AUTO_TEST_CASE(assert) BOOST_CHECK(callContractFunction("g(bool)", true) == encodeArgs(true)); } +BOOST_AUTO_TEST_CASE(revert) +{ + char const* sourceCode = R"( + contract C { + function f() { + revert(); + } + function g() { + assembly { + revert(0, 0) + } + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs()); + BOOST_CHECK(callContractFunction("g()") == encodeArgs()); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit From 30cfad35484e9b903bf90bb723382aebc832d560 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 10 Feb 2017 13:37:06 +0000 Subject: Check for state changes in revert() tests --- test/libsolidity/SolidityEndToEndTest.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 8c0e29fd..92c1a9a1 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -9100,10 +9100,13 @@ BOOST_AUTO_TEST_CASE(revert) { char const* sourceCode = R"( contract C { + uint public a = 42; function f() { + a = 1; revert(); } function g() { + a = 1; assembly { revert(0, 0) } @@ -9112,7 +9115,9 @@ BOOST_AUTO_TEST_CASE(revert) )"; compileAndRun(sourceCode, 0, "C"); BOOST_CHECK(callContractFunction("f()") == encodeArgs()); + BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(42))); BOOST_CHECK(callContractFunction("g()") == encodeArgs()); + BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(42))); } BOOST_AUTO_TEST_SUITE_END() -- cgit