aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-10-19 17:15:49 +0800
committerGitHub <noreply@github.com>2017-10-19 17:15:49 +0800
commitc58d9d2c4269a89b07b7cd10a33d806c8315c3cc (patch)
treedf5f2b2e2b266d85a7fe62a5ecc4c03fd78c5d68 /test
parent6d7a366a32b4c19afeeadacb10605c4af87ea6b2 (diff)
parent4ca160d9fb94920b6708d691976154e1ddfb76d2 (diff)
downloaddexon-solidity-c58d9d2c4269a89b07b7cd10a33d806c8315c3cc.tar.gz
dexon-solidity-c58d9d2c4269a89b07b7cd10a33d806c8315c3cc.tar.zst
dexon-solidity-c58d9d2c4269a89b07b7cd10a33d806c8315c3cc.zip
Merge pull request #3106 from ethereum/test-cleanup
Move contract related code to test/contracts
Diffstat (limited to 'test')
-rw-r--r--test/ExecutionFramework.h67
-rw-r--r--test/contracts/AuctionRegistrar.cpp2
-rw-r--r--test/contracts/ContractInterface.h99
3 files changed, 101 insertions, 67 deletions
diff --git a/test/ExecutionFramework.h b/test/ExecutionFramework.h
index cc25bea7..2c61c0a6 100644
--- a/test/ExecutionFramework.h
+++ b/test/ExecutionFramework.h
@@ -172,78 +172,13 @@ public:
{
return bytes();
}
+
//@todo might be extended in the future
template <class Arg>
static bytes encodeDyn(Arg const& _arg)
{
return encodeArgs(u256(0x20), u256(_arg.size()), _arg);
}
- class ContractInterface
- {
- public:
- ContractInterface(ExecutionFramework& _framework): m_framework(_framework) {}
-
- void setNextValue(u256 const& _value) { m_nextValue = _value; }
-
- protected:
- template <class... Args>
- bytes const& call(std::string const& _sig, Args const&... _arguments)
- {
- auto const& ret = m_framework.callContractFunctionWithValue(_sig, m_nextValue, _arguments...);
- m_nextValue = 0;
- return ret;
- }
-
- void callString(std::string const& _name, std::string const& _arg)
- {
- BOOST_CHECK(call(_name + "(string)", u256(0x20), _arg.length(), _arg).empty());
- }
-
- void callStringAddress(std::string const& _name, std::string const& _arg1, u160 const& _arg2)
- {
- BOOST_CHECK(call(_name + "(string,address)", u256(0x40), _arg2, _arg1.length(), _arg1).empty());
- }
-
- void callStringAddressBool(std::string const& _name, std::string const& _arg1, u160 const& _arg2, bool _arg3)
- {
- BOOST_CHECK(call(_name + "(string,address,bool)", u256(0x60), _arg2, _arg3, _arg1.length(), _arg1).empty());
- }
-
- void callStringBytes32(std::string const& _name, std::string const& _arg1, h256 const& _arg2)
- {
- BOOST_CHECK(call(_name + "(string,bytes32)", u256(0x40), _arg2, _arg1.length(), _arg1).empty());
- }
-
- u160 callStringReturnsAddress(std::string const& _name, std::string const& _arg)
- {
- bytes const& ret = call(_name + "(string)", u256(0x20), _arg.length(), _arg);
- BOOST_REQUIRE(ret.size() == 0x20);
- BOOST_CHECK(std::count(ret.begin(), ret.begin() + 12, 0) == 12);
- return u160(u256(h256(ret)));
- }
-
- std::string callAddressReturnsString(std::string const& _name, u160 const& _arg)
- {
- bytesConstRef const ret(&call(_name + "(address)", _arg));
- BOOST_REQUIRE(ret.size() >= 0x40);
- u256 offset(h256(ret.cropped(0, 0x20)));
- BOOST_REQUIRE_EQUAL(offset, 0x20);
- u256 len(h256(ret.cropped(0x20, 0x20)));
- BOOST_REQUIRE_EQUAL(ret.size(), 0x40 + ((len + 0x1f) / 0x20) * 0x20);
- return ret.cropped(0x40, size_t(len)).toString();
- }
-
- h256 callStringReturnsBytes32(std::string const& _name, std::string const& _arg)
- {
- bytes const& ret = call(_name + "(string)", u256(0x20), _arg.length(), _arg);
- BOOST_REQUIRE(ret.size() == 0x20);
- return h256(ret);
- }
-
- private:
- u256 m_nextValue;
- ExecutionFramework& m_framework;
- };
private:
template <class CppFunction, class... Args>
diff --git a/test/contracts/AuctionRegistrar.cpp b/test/contracts/AuctionRegistrar.cpp
index 73a5d1ed..c9c744af 100644
--- a/test/contracts/AuctionRegistrar.cpp
+++ b/test/contracts/AuctionRegistrar.cpp
@@ -24,6 +24,7 @@
#include <tuple>
#include <boost/test/unit_test.hpp>
#include <test/libsolidity/SolidityExecutionFramework.h>
+#include <test/contracts/ContractInterface.h>
using namespace std;
using namespace dev::test;
@@ -230,7 +231,6 @@ protected:
BOOST_REQUIRE(!m_output.empty());
}
- using ContractInterface = SolidityExecutionFramework::ContractInterface;
class RegistrarInterface: public ContractInterface
{
public:
diff --git a/test/contracts/ContractInterface.h b/test/contracts/ContractInterface.h
new file mode 100644
index 00000000..052b0db2
--- /dev/null
+++ b/test/contracts/ContractInterface.h
@@ -0,0 +1,99 @@
+/*
+ This file is part of solidity.
+
+ solidity is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ solidity is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with solidity. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#pragma once
+
+#include <boost/test/unit_test.hpp>
+#include <test/ExecutionFramework.h>
+
+#include <functional>
+
+namespace dev
+{
+namespace test
+{
+
+class ContractInterface
+{
+public:
+ ContractInterface(ExecutionFramework& _framework): m_framework(_framework) {}
+
+ void setNextValue(u256 const& _value) { m_nextValue = _value; }
+
+protected:
+ template <class... Args>
+ bytes const& call(std::string const& _sig, Args const&... _arguments)
+ {
+ auto const& ret = m_framework.callContractFunctionWithValue(_sig, m_nextValue, _arguments...);
+ m_nextValue = 0;
+ return ret;
+ }
+
+ void callString(std::string const& _name, std::string const& _arg)
+ {
+ BOOST_CHECK(call(_name + "(string)", u256(0x20), _arg.length(), _arg).empty());
+ }
+
+ void callStringAddress(std::string const& _name, std::string const& _arg1, u160 const& _arg2)
+ {
+ BOOST_CHECK(call(_name + "(string,address)", u256(0x40), _arg2, _arg1.length(), _arg1).empty());
+ }
+
+ void callStringAddressBool(std::string const& _name, std::string const& _arg1, u160 const& _arg2, bool _arg3)
+ {
+ BOOST_CHECK(call(_name + "(string,address,bool)", u256(0x60), _arg2, _arg3, _arg1.length(), _arg1).empty());
+ }
+
+ void callStringBytes32(std::string const& _name, std::string const& _arg1, h256 const& _arg2)
+ {
+ BOOST_CHECK(call(_name + "(string,bytes32)", u256(0x40), _arg2, _arg1.length(), _arg1).empty());
+ }
+
+ u160 callStringReturnsAddress(std::string const& _name, std::string const& _arg)
+ {
+ bytes const& ret = call(_name + "(string)", u256(0x20), _arg.length(), _arg);
+ BOOST_REQUIRE(ret.size() == 0x20);
+ BOOST_CHECK(std::count(ret.begin(), ret.begin() + 12, 0) == 12);
+ return u160(u256(h256(ret)));
+ }
+
+ std::string callAddressReturnsString(std::string const& _name, u160 const& _arg)
+ {
+ bytesConstRef const ret(&call(_name + "(address)", _arg));
+ BOOST_REQUIRE(ret.size() >= 0x40);
+ u256 offset(h256(ret.cropped(0, 0x20)));
+ BOOST_REQUIRE_EQUAL(offset, 0x20);
+ u256 len(h256(ret.cropped(0x20, 0x20)));
+ BOOST_REQUIRE_EQUAL(ret.size(), 0x40 + ((len + 0x1f) / 0x20) * 0x20);
+ return ret.cropped(0x40, size_t(len)).toString();
+ }
+
+ h256 callStringReturnsBytes32(std::string const& _name, std::string const& _arg)
+ {
+ bytes const& ret = call(_name + "(string)", u256(0x20), _arg.length(), _arg);
+ BOOST_REQUIRE(ret.size() == 0x20);
+ return h256(ret);
+ }
+
+private:
+ u256 m_nextValue;
+ ExecutionFramework& m_framework;
+};
+
+}
+} // end namespaces
+