From 4ff890f1dd174fde8c72c7b4dd802a712aa9cc9f Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 4 Aug 2015 16:31:27 +0200 Subject: Basic tests for auction registrar. --- libsolidity/solidityExecutionFramework.h | 64 ++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'libsolidity') diff --git a/libsolidity/solidityExecutionFramework.h b/libsolidity/solidityExecutionFramework.h index e4c4087f..6a62c445 100644 --- a/libsolidity/solidityExecutionFramework.h +++ b/libsolidity/solidityExecutionFramework.h @@ -25,6 +25,7 @@ #include #include #include "../TestHelper.h" +#include #include #include #include @@ -166,6 +167,69 @@ public: return encodeArgs(u256(0x20), u256(_arg.size()), _arg); } + class ContractInterface + { + public: + ContractInterface(ExecutionFramework& _framework): m_framework(_framework) {} + + protected: + template + 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 eth::abiOut(ret); + } + + std::string callAddressReturnsString(std::string const& _name, u160 const& _arg) + { + bytes const& ret = call(_name + "(address)", _arg); + BOOST_REQUIRE(ret.size() >= 0x20); + u256 len = eth::abiOut(ret); + BOOST_REQUIRE(ret.size() == (0x20 + len) / 32 * 32); + return std::string(ret.begin() + 0x20, ret.begin() + 0x20 + size_t(len)); + } + + 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 eth::abiOut(ret); + } + + private: + u256 m_nextValue; + ExecutionFramework& m_framework; + }; + private: template auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) -- cgit