aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-01-15 23:50:00 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-03-06 22:30:18 +0800
commita3593df43b8d5639dd756d238cc744b1204cc3e8 (patch)
tree0f0e04fdb3301eca6fdd198811e6bfcd86e1ad45
parentb467116ea85383d5c8492e7f21ea16ce7c70ebc9 (diff)
downloaddexon-solidity-a3593df43b8d5639dd756d238cc744b1204cc3e8.tar.gz
dexon-solidity-a3593df43b8d5639dd756d238cc744b1204cc3e8.tar.zst
dexon-solidity-a3593df43b8d5639dd756d238cc744b1204cc3e8.zip
Test for using staticcall for view and pure functions.
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp60
1 files changed, 56 insertions, 4 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index ebb2f3ff..33cd1419 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -21,13 +21,20 @@
* Unit tests for the solidity expression compiler, testing the behaviour of the code.
*/
+#include <test/libsolidity/SolidityExecutionFramework.h>
+
+#include <test/TestHelper.h>
+
+#include <libsolidity/interface/Exceptions.h>
+#include <libsolidity/interface/EVMVersion.h>
+
+#include <libevmasm/Assembly.h>
+
+#include <boost/test/unit_test.hpp>
+
#include <functional>
#include <string>
#include <tuple>
-#include <boost/test/unit_test.hpp>
-#include <libevmasm/Assembly.h>
-#include <libsolidity/interface/Exceptions.h>
-#include <test/libsolidity/SolidityExecutionFramework.h>
using namespace std;
using namespace std::placeholders;
@@ -10778,6 +10785,51 @@ BOOST_AUTO_TEST_CASE(snark)
BOOST_CHECK(callContractFunction("verifyTx()") == encodeArgs(true));
}
+BOOST_AUTO_TEST_CASE(staticcall_for_view_and_pure)
+{
+ char const* sourceCode = R"(
+ pragma experimental "v0.5.0";
+ contract C {
+ uint x;
+ function f() public returns (uint) {
+ x = 3;
+ return 1;
+ }
+ }
+ interface CView {
+ function f() view external returns (uint);
+ }
+ interface CPure {
+ function f() pure external returns (uint);
+ }
+ contract D {
+ function f() public returns (uint) {
+ return (new C()).f();
+ }
+ function fview() public returns (uint) {
+ return (CView(new C())).f();
+ }
+ function fpure() public returns (uint) {
+ return (CPure(new C())).f();
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "D");
+ // This should work (called via CALL)
+ ABI_CHECK(callContractFunction("f()"), encodeArgs(1));
+ if (dev::test::Options::get().evmVersion().hasStaticCall())
+ {
+ // These should throw (called via STATICCALL)
+ ABI_CHECK(callContractFunction("fview()"), encodeArgs());
+ ABI_CHECK(callContractFunction("fpure()"), encodeArgs());
+ }
+ else
+ {
+ ABI_CHECK(callContractFunction("fview()"), encodeArgs(1));
+ ABI_CHECK(callContractFunction("fpure()"), encodeArgs(1));
+ }
+}
+
BOOST_AUTO_TEST_SUITE_END()
}