mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge branch 'develop-evmcc' into pr-jit
This commit is contained in:
commit
72fa55410e
@ -27,8 +27,6 @@
|
||||
#include <libethereum/Client.h>
|
||||
#include <liblll/Compiler.h>
|
||||
|
||||
//#define FILL_TESTS
|
||||
|
||||
using namespace std;
|
||||
using namespace dev::eth;
|
||||
|
||||
@ -253,7 +251,7 @@ bytes importCode(json_spirit::mObject& _o)
|
||||
code.clear();
|
||||
for (auto const& j: _o["code"].get_array())
|
||||
code.push_back(toByte(j));
|
||||
}
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
@ -287,6 +285,12 @@ void checkStorage(map<u256, u256> _expectedStore, map<u256, u256> _resultStore,
|
||||
BOOST_CHECK_MESSAGE(expectedStoreValue == resultStoreValue, _expectedAddr << ": store[" << expectedStoreKey << "] = " << resultStoreValue << ", expected " << expectedStoreValue);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto&& resultStorePair : _resultStore)
|
||||
{
|
||||
if (!_expectedStore.count(resultStorePair.first))
|
||||
BOOST_ERROR("unexpected result store key " << resultStorePair.first);
|
||||
}
|
||||
}
|
||||
|
||||
std::string getTestPath()
|
||||
@ -305,33 +309,79 @@ std::string getTestPath()
|
||||
return testPath;
|
||||
}
|
||||
|
||||
void userDefinedTest(string testTypeFlag, std::function<void(json_spirit::mValue&, bool)> doTests)
|
||||
{
|
||||
for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
|
||||
{
|
||||
string arg = boost::unit_test::framework::master_test_suite().argv[i];
|
||||
if (arg == testTypeFlag)
|
||||
{
|
||||
if (i + 1 >= boost::unit_test::framework::master_test_suite().argc)
|
||||
{
|
||||
cnote << "Missing filename\nUsage: testeth " << testTypeFlag << " <filename>\n";
|
||||
return;
|
||||
}
|
||||
string filename = boost::unit_test::framework::master_test_suite().argv[i + 1];
|
||||
int currentVerbosity = g_logVerbosity;
|
||||
g_logVerbosity = 12;
|
||||
try
|
||||
{
|
||||
cnote << "Testing user defined test: " << filename;
|
||||
json_spirit::mValue v;
|
||||
string s = asString(contents(filename));
|
||||
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. ");
|
||||
json_spirit::read_string(s, v);
|
||||
doTests(v, false);
|
||||
}
|
||||
catch (Exception const& _e)
|
||||
{
|
||||
BOOST_ERROR("Failed Test with Exception: " << diagnostic_information(_e));
|
||||
g_logVerbosity = currentVerbosity;
|
||||
}
|
||||
catch (std::exception const& _e)
|
||||
{
|
||||
BOOST_ERROR("Failed Test with Exception: " << _e.what());
|
||||
g_logVerbosity = currentVerbosity;
|
||||
}
|
||||
g_logVerbosity = currentVerbosity;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
void executeTests(const string& _name, const string& _testPathAppendix, std::function<void(json_spirit::mValue&, bool)> doTests)
|
||||
{
|
||||
string testPath = getTestPath();
|
||||
testPath += _testPathAppendix;
|
||||
|
||||
#ifdef FILL_TESTS
|
||||
try
|
||||
for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
|
||||
{
|
||||
cnote << "Populating tests...";
|
||||
json_spirit::mValue v;
|
||||
boost::filesystem::path p(__FILE__);
|
||||
boost::filesystem::path dir = p.parent_path();
|
||||
string s = asString(dev::contents(dir.string() + "/" + _name + "Filler.json"));
|
||||
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + dir.string() + "/" + _name + "Filler.json is empty.");
|
||||
json_spirit::read_string(s, v);
|
||||
doTests(v, true);
|
||||
writeFile(testPath + "/" + _name + ".json", asBytes(json_spirit::write_string(v, true)));
|
||||
string arg = boost::unit_test::framework::master_test_suite().argv[i];
|
||||
if (arg == "--filltests")
|
||||
{
|
||||
try
|
||||
{
|
||||
cnote << "Populating tests...";
|
||||
json_spirit::mValue v;
|
||||
boost::filesystem::path p(__FILE__);
|
||||
boost::filesystem::path dir = p.parent_path();
|
||||
string s = asString(dev::contents(dir.string() + "/" + _name + "Filler.json"));
|
||||
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + dir.string() + "/" + _name + "Filler.json is empty.");
|
||||
json_spirit::read_string(s, v);
|
||||
doTests(v, true);
|
||||
writeFile(testPath + "/" + _name + ".json", asBytes(json_spirit::write_string(v, true)));
|
||||
}
|
||||
catch (Exception const& _e)
|
||||
{
|
||||
BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
|
||||
}
|
||||
catch (std::exception const& _e)
|
||||
{
|
||||
BOOST_ERROR("Failed test with Exception: " << _e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception const& _e)
|
||||
{
|
||||
BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
|
||||
}
|
||||
catch (std::exception const& _e)
|
||||
{
|
||||
BOOST_ERROR("Failed test with Exception: " << _e.what());
|
||||
}
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -57,7 +57,6 @@ public:
|
||||
eth::State m_statePost;
|
||||
eth::ExtVMFace m_environment;
|
||||
eth::Transaction m_transaction;
|
||||
bytes code;
|
||||
|
||||
private:
|
||||
json_spirit::mObject& m_TestObject;
|
||||
@ -72,6 +71,7 @@ void checkOutput(bytes const& _output, json_spirit::mObject& _o);
|
||||
void checkStorage(std::map<u256, u256> _expectedStore, std::map<u256, u256> _resultStore, Address _expectedAddr);
|
||||
void executeTests(const std::string& _name, const std::string& _testPathAppendix, std::function<void(json_spirit::mValue&, bool)> doTests);
|
||||
std::string getTestPath();
|
||||
void userDefinedTest(std::string testTypeFlag, std::function<void(json_spirit::mValue&, bool)> doTests);
|
||||
|
||||
template<typename mapType>
|
||||
void checkAddresses(mapType& _expectedAddrs, mapType& _resultAddrs)
|
||||
|
@ -31,7 +31,8 @@
|
||||
#include <json_spirit/json_spirit_writer_template.h>
|
||||
#include <libdevcore/CommonIO.h>
|
||||
#include <libdevcore/CommonData.h>
|
||||
#include <libevmface/Instruction.h>
|
||||
#include <libevmcore/Instruction.h>
|
||||
#include <libevm/VM.h>
|
||||
#include "vm.h"
|
||||
|
||||
using namespace std;
|
||||
@ -136,18 +137,24 @@ void doMyTests(json_spirit::mValue& v)
|
||||
o["pre"] = mValue(fev.exportState());
|
||||
|
||||
fev.importExec(o["exec"].get_obj());
|
||||
if (!fev.code)
|
||||
if (fev.code.empty())
|
||||
{
|
||||
fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress));
|
||||
fev.code = &fev.thisTxCode;
|
||||
fev.code = fev.thisTxCode;
|
||||
}
|
||||
|
||||
vm.reset(fev.gas);
|
||||
bytes output;
|
||||
u256 gas;
|
||||
try
|
||||
{
|
||||
output = vm.go(fev).toBytes();
|
||||
}
|
||||
catch (eth::VMException const& _e)
|
||||
{
|
||||
cnote << "VM did throw an exception: " << diagnostic_information(_e);
|
||||
gas = 0;
|
||||
}
|
||||
catch (Exception const& _e)
|
||||
{
|
||||
cnote << "VM did throw an exception: " << diagnostic_information(_e);
|
||||
@ -178,6 +185,6 @@ void doMyTests(json_spirit::mValue& v)
|
||||
o["post"] = mValue(fev.exportState());
|
||||
o["callcreates"] = fev.exportCallCreates();
|
||||
o["out"] = "0x" + toHex(output);
|
||||
fev.push(o, "gas", vm.gas());
|
||||
fev.push(o, "gas", gas);
|
||||
}
|
||||
}
|
||||
|
46
jsonrpc.cpp
46
jsonrpc.cpp
@ -74,14 +74,14 @@ BOOST_FIXTURE_TEST_SUITE(environment, Setup)
|
||||
BOOST_AUTO_TEST_CASE(jsonrpc_defaultBlock)
|
||||
{
|
||||
cnote << "Testing jsonrpc defaultBlock...";
|
||||
int defaultBlock = jsonrpcClient->defaultBlock();
|
||||
int defaultBlock = jsonrpcClient->eth_defaultBlock();
|
||||
BOOST_CHECK_EQUAL(defaultBlock, web3->ethereum()->getDefault());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(jsonrpc_gasPrice)
|
||||
{
|
||||
cnote << "Testing jsonrpc gasPrice...";
|
||||
string gasPrice = jsonrpcClient->gasPrice();
|
||||
string gasPrice = jsonrpcClient->eth_gasPrice();
|
||||
BOOST_CHECK_EQUAL(gasPrice, toJS(10 * dev::eth::szabo));
|
||||
}
|
||||
|
||||
@ -90,11 +90,11 @@ BOOST_AUTO_TEST_CASE(jsonrpc_isListening)
|
||||
cnote << "Testing jsonrpc isListening...";
|
||||
|
||||
web3->startNetwork();
|
||||
bool listeningOn = jsonrpcClient->listening();
|
||||
bool listeningOn = jsonrpcClient->eth_listening();
|
||||
BOOST_CHECK_EQUAL(listeningOn, web3->isNetworkStarted());
|
||||
|
||||
web3->stopNetwork();
|
||||
bool listeningOff = jsonrpcClient->listening();
|
||||
bool listeningOff = jsonrpcClient->eth_listening();
|
||||
BOOST_CHECK_EQUAL(listeningOff, web3->isNetworkStarted());
|
||||
}
|
||||
|
||||
@ -103,11 +103,11 @@ BOOST_AUTO_TEST_CASE(jsonrpc_isMining)
|
||||
cnote << "Testing jsonrpc isMining...";
|
||||
|
||||
web3->ethereum()->startMining();
|
||||
bool miningOn = jsonrpcClient->mining();
|
||||
bool miningOn = jsonrpcClient->eth_mining();
|
||||
BOOST_CHECK_EQUAL(miningOn, web3->ethereum()->isMining());
|
||||
|
||||
web3->ethereum()->stopMining();
|
||||
bool miningOff = jsonrpcClient->mining();
|
||||
bool miningOff = jsonrpcClient->eth_mining();
|
||||
BOOST_CHECK_EQUAL(miningOff, web3->ethereum()->isMining());
|
||||
}
|
||||
|
||||
@ -116,7 +116,7 @@ BOOST_AUTO_TEST_CASE(jsonrpc_accounts)
|
||||
cnote << "Testing jsonrpc accounts...";
|
||||
std::vector <dev::KeyPair> keys = {KeyPair::create(), KeyPair::create()};
|
||||
jsonrpcServer->setAccounts(keys);
|
||||
Json::Value k = jsonrpcClient->accounts();
|
||||
Json::Value k = jsonrpcClient->eth_accounts();
|
||||
jsonrpcServer->setAccounts({});
|
||||
BOOST_CHECK_EQUAL(k.isArray(), true);
|
||||
BOOST_CHECK_EQUAL(k.size(), keys.size());
|
||||
@ -133,10 +133,10 @@ BOOST_AUTO_TEST_CASE(jsonrpc_accounts)
|
||||
BOOST_AUTO_TEST_CASE(jsonrpc_number)
|
||||
{
|
||||
cnote << "Testing jsonrpc number2...";
|
||||
int number = jsonrpcClient->number();
|
||||
int number = jsonrpcClient->eth_number();
|
||||
BOOST_CHECK_EQUAL(number, web3->ethereum()->number() + 1);
|
||||
dev::eth::mine(*(web3->ethereum()), 1);
|
||||
int numberAfter = jsonrpcClient->number();
|
||||
int numberAfter = jsonrpcClient->eth_number();
|
||||
BOOST_CHECK_EQUAL(number + 1, numberAfter);
|
||||
BOOST_CHECK_EQUAL(numberAfter, web3->ethereum()->number() + 1);
|
||||
}
|
||||
@ -144,7 +144,7 @@ BOOST_AUTO_TEST_CASE(jsonrpc_number)
|
||||
BOOST_AUTO_TEST_CASE(jsonrpc_peerCount)
|
||||
{
|
||||
cnote << "Testing jsonrpc peerCount...";
|
||||
int peerCount = jsonrpcClient->peerCount();
|
||||
int peerCount = jsonrpcClient->eth_peerCount();
|
||||
BOOST_CHECK_EQUAL(web3->peerCount(), peerCount);
|
||||
}
|
||||
|
||||
@ -152,10 +152,10 @@ BOOST_AUTO_TEST_CASE(jsonrpc_setListening)
|
||||
{
|
||||
cnote << "Testing jsonrpc setListening...";
|
||||
|
||||
jsonrpcClient->setListening(true);
|
||||
jsonrpcClient->eth_setListening(true);
|
||||
BOOST_CHECK_EQUAL(web3->isNetworkStarted(), true);
|
||||
|
||||
jsonrpcClient->setListening(false);
|
||||
jsonrpcClient->eth_setListening(false);
|
||||
BOOST_CHECK_EQUAL(web3->isNetworkStarted(), false);
|
||||
}
|
||||
|
||||
@ -163,10 +163,10 @@ BOOST_AUTO_TEST_CASE(jsonrpc_setMining)
|
||||
{
|
||||
cnote << "Testing jsonrpc setMining...";
|
||||
|
||||
jsonrpcClient->setMining(true);
|
||||
jsonrpcClient->eth_setMining(true);
|
||||
BOOST_CHECK_EQUAL(web3->ethereum()->isMining(), true);
|
||||
|
||||
jsonrpcClient->setMining(false);
|
||||
jsonrpcClient->eth_setMining(false);
|
||||
BOOST_CHECK_EQUAL(web3->ethereum()->isMining(), false);
|
||||
}
|
||||
|
||||
@ -175,14 +175,14 @@ BOOST_AUTO_TEST_CASE(jsonrpc_stateAt)
|
||||
cnote << "Testing jsonrpc stateAt...";
|
||||
dev::KeyPair key = KeyPair::create();
|
||||
auto address = key.address();
|
||||
string stateAt = jsonrpcClient->stateAt(toJS(address), "0");
|
||||
string stateAt = jsonrpcClient->eth_stateAt(toJS(address), "0");
|
||||
BOOST_CHECK_EQUAL(toJS(web3->ethereum()->stateAt(address, jsToU256("0"), 0)), stateAt);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(jsonrpc_transact)
|
||||
{
|
||||
cnote << "Testing jsonrpc transact...";
|
||||
string coinbase = jsonrpcClient->coinbase();
|
||||
string coinbase = jsonrpcClient->eth_coinbase();
|
||||
BOOST_CHECK_EQUAL(jsToAddress(coinbase), web3->ethereum()->address());
|
||||
|
||||
dev::KeyPair key = KeyPair::create();
|
||||
@ -190,14 +190,14 @@ BOOST_AUTO_TEST_CASE(jsonrpc_transact)
|
||||
auto receiver = KeyPair::create();
|
||||
web3->ethereum()->setAddress(address);
|
||||
|
||||
coinbase = jsonrpcClient->coinbase();
|
||||
coinbase = jsonrpcClient->eth_coinbase();
|
||||
BOOST_CHECK_EQUAL(jsToAddress(coinbase), web3->ethereum()->address());
|
||||
BOOST_CHECK_EQUAL(jsToAddress(coinbase), address);
|
||||
|
||||
jsonrpcServer->setAccounts({key});
|
||||
auto balance = web3->ethereum()->balanceAt(address, 0);
|
||||
string balanceString = jsonrpcClient->balanceAt(toJS(address));
|
||||
double countAt = jsonrpcClient->countAt(toJS(address));
|
||||
string balanceString = jsonrpcClient->eth_balanceAt(toJS(address));
|
||||
double countAt = jsonrpcClient->eth_countAt(toJS(address));
|
||||
|
||||
BOOST_CHECK_EQUAL(countAt, (double)(uint64_t)web3->ethereum()->countAt(address));
|
||||
BOOST_CHECK_EQUAL(countAt, 0);
|
||||
@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE(jsonrpc_transact)
|
||||
|
||||
dev::eth::mine(*(web3->ethereum()), 1);
|
||||
balance = web3->ethereum()->balanceAt(address, 0);
|
||||
balanceString = jsonrpcClient->balanceAt(toJS(address));
|
||||
balanceString = jsonrpcClient->eth_balanceAt(toJS(address));
|
||||
|
||||
BOOST_CHECK_EQUAL(toJS(balance), balanceString);
|
||||
BOOST_CHECK_EQUAL(jsToDecimal(balanceString), "1500000000000000000");
|
||||
@ -223,13 +223,13 @@ BOOST_AUTO_TEST_CASE(jsonrpc_transact)
|
||||
t["gas"] = toJS(gas);
|
||||
t["gasPrice"] = toJS(gasPrice);
|
||||
|
||||
jsonrpcClient->transact(t);
|
||||
jsonrpcClient->eth_transact(t);
|
||||
jsonrpcServer->setAccounts({});
|
||||
dev::eth::mine(*(web3->ethereum()), 1);
|
||||
|
||||
countAt = jsonrpcClient->countAt(toJS(address));
|
||||
countAt = jsonrpcClient->eth_countAt(toJS(address));
|
||||
auto balance2 = web3->ethereum()->balanceAt(receiver.address());
|
||||
string balanceString2 = jsonrpcClient->balanceAt(toJS(receiver.address()));
|
||||
string balanceString2 = jsonrpcClient->eth_balanceAt(toJS(receiver.address()));
|
||||
|
||||
BOOST_CHECK_EQUAL(countAt, (double)(uint64_t)web3->ethereum()->countAt(address));
|
||||
BOOST_CHECK_EQUAL(countAt, 1);
|
||||
|
@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(smoke_test)
|
||||
"}\n";
|
||||
bytes code = compileContract(sourceCode);
|
||||
|
||||
unsigned boilerplateSize = 51;
|
||||
unsigned boilerplateSize = 42;
|
||||
bytes expectation({byte(Instruction::JUMPDEST),
|
||||
byte(Instruction::PUSH1), 0x0, // initialize local variable x
|
||||
byte(Instruction::PUSH1), 0x2,
|
||||
@ -100,8 +100,8 @@ BOOST_AUTO_TEST_CASE(different_argument_numbers)
|
||||
"}\n";
|
||||
bytes code = compileContract(sourceCode);
|
||||
|
||||
unsigned shift = 75;
|
||||
unsigned boilerplateSize = 88;
|
||||
unsigned shift = 70;
|
||||
unsigned boilerplateSize = 83;
|
||||
bytes expectation({byte(Instruction::JUMPDEST),
|
||||
byte(Instruction::PUSH1), 0x0, // initialize return variable d
|
||||
byte(Instruction::DUP3),
|
||||
@ -119,10 +119,10 @@ BOOST_AUTO_TEST_CASE(different_argument_numbers)
|
||||
byte(Instruction::JUMPDEST), // beginning of g
|
||||
byte(Instruction::PUSH1), 0x0,
|
||||
byte(Instruction::DUP1), // initialized e and h
|
||||
byte(Instruction::PUSH1), byte(0x20 + shift), // ret address
|
||||
byte(Instruction::PUSH1), 0x1,
|
||||
byte(Instruction::PUSH1), 0x2,
|
||||
byte(Instruction::PUSH1), 0x3,
|
||||
byte(Instruction::PUSH1), byte(0x29 + shift), // ret address
|
||||
byte(Instruction::PUSH1), 0x1, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND),
|
||||
byte(Instruction::PUSH1), 0x2, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND),
|
||||
byte(Instruction::PUSH1), 0x3, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND),
|
||||
byte(Instruction::PUSH1), byte(0x1 + shift),
|
||||
// stack here: ret e h 0x20 1 2 3 0x1
|
||||
byte(Instruction::JUMP),
|
||||
@ -153,8 +153,8 @@ BOOST_AUTO_TEST_CASE(ifStatement)
|
||||
"}\n";
|
||||
bytes code = compileContract(sourceCode);
|
||||
|
||||
unsigned shift = 38;
|
||||
unsigned boilerplateSize = 51;
|
||||
unsigned shift = 29;
|
||||
unsigned boilerplateSize = 42;
|
||||
bytes expectation({byte(Instruction::JUMPDEST),
|
||||
byte(Instruction::PUSH1), 0x0,
|
||||
byte(Instruction::DUP1),
|
||||
@ -195,8 +195,8 @@ BOOST_AUTO_TEST_CASE(loops)
|
||||
"}\n";
|
||||
bytes code = compileContract(sourceCode);
|
||||
|
||||
unsigned shift = 38;
|
||||
unsigned boilerplateSize = 51;
|
||||
unsigned shift = 29;
|
||||
unsigned boilerplateSize = 42;
|
||||
bytes expectation({byte(Instruction::JUMPDEST),
|
||||
byte(Instruction::JUMPDEST),
|
||||
byte(Instruction::PUSH1), 0x1,
|
||||
|
@ -22,6 +22,7 @@
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <libethereum/State.h>
|
||||
#include <libethereum/Executive.h>
|
||||
@ -41,31 +42,77 @@ class ExecutionFramework
|
||||
public:
|
||||
ExecutionFramework() { g_logVerbosity = 0; }
|
||||
|
||||
bytes compileAndRun(std::string const& _sourceCode)
|
||||
bytes const& compileAndRun(string const& _sourceCode)
|
||||
{
|
||||
bytes code = dev::solidity::CompilerStack::compile(_sourceCode);
|
||||
bytes code = dev::solidity::CompilerStack::staticCompile(_sourceCode);
|
||||
sendMessage(code, true);
|
||||
BOOST_REQUIRE(!m_output.empty());
|
||||
return m_output;
|
||||
}
|
||||
|
||||
bytes callFunction(byte _index, bytes const& _data)
|
||||
bytes const& callContractFunction(byte _index, bytes const& _data = bytes())
|
||||
{
|
||||
sendMessage(bytes(1, _index) + _data, false);
|
||||
return m_output;
|
||||
}
|
||||
|
||||
bytes callFunction(byte _index, u256 const& _argument1)
|
||||
template <class... Args>
|
||||
bytes const& callContractFunction(byte _index, Args const&... _arguments)
|
||||
{
|
||||
callFunction(_index, toBigEndian(_argument1));
|
||||
return m_output;
|
||||
return callContractFunction(_index, argsToBigEndian(_arguments...));
|
||||
}
|
||||
|
||||
template <class CppFunction, class... Args>
|
||||
void testSolidityAgainstCpp(byte _index, CppFunction const& _cppFunction, Args const&... _arguments)
|
||||
{
|
||||
bytes solidityResult = callContractFunction(_index, _arguments...);
|
||||
bytes cppResult = callCppAndEncodeResult(_cppFunction, _arguments...);
|
||||
BOOST_CHECK_MESSAGE(solidityResult == cppResult, "Computed values do not match."
|
||||
"\nSolidity: " + toHex(solidityResult) + "\nC++: " + toHex(cppResult));
|
||||
}
|
||||
|
||||
template <class CppFunction, class... Args>
|
||||
void testSolidityAgainstCppOnRange(byte _index, CppFunction const& _cppFunction,
|
||||
u256 const& _rangeStart, u256 const& _rangeEnd)
|
||||
{
|
||||
for (u256 argument = _rangeStart; argument < _rangeEnd; ++argument)
|
||||
{
|
||||
bytes solidityResult = callContractFunction(_index, argument);
|
||||
bytes cppResult = callCppAndEncodeResult(_cppFunction, argument);
|
||||
BOOST_CHECK_MESSAGE(solidityResult == cppResult, "Computed values do not match."
|
||||
"\nSolidity: " + toHex(solidityResult) + "\nC++: " + toHex(cppResult) +
|
||||
"\nArgument: " + toHex(toBigEndian(argument)));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
template <class FirstArg, class... Args>
|
||||
bytes argsToBigEndian(FirstArg const& _firstArg, Args const&... _followingArgs) const
|
||||
{
|
||||
return toBigEndian(_firstArg) + argsToBigEndian(_followingArgs...);
|
||||
}
|
||||
|
||||
bytes argsToBigEndian() const { return bytes(); }
|
||||
|
||||
template <class CppFunction, class... Args>
|
||||
auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments)
|
||||
-> typename enable_if<is_void<decltype(_cppFunction(_arguments...))>::value, bytes>::type
|
||||
{
|
||||
_cppFunction(_arguments...);
|
||||
return bytes();
|
||||
}
|
||||
template <class CppFunction, class... Args>
|
||||
auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments)
|
||||
-> typename enable_if<!is_void<decltype(_cppFunction(_arguments...))>::value, bytes>::type
|
||||
{
|
||||
return toBigEndian(_cppFunction(_arguments...));
|
||||
}
|
||||
|
||||
void sendMessage(bytes const& _data, bool _isCreation)
|
||||
{
|
||||
eth::Executive executive(m_state);
|
||||
eth::Transaction t = _isCreation ? eth::Transaction(0, m_gasPrice, m_gas, _data)
|
||||
: eth::Transaction(0, m_gasPrice, m_gas, m_contractAddress, _data);
|
||||
eth::Transaction t = _isCreation ? eth::Transaction(0, m_gasPrice, m_gas, _data, 0, KeyPair::create().sec())
|
||||
: eth::Transaction(0, m_gasPrice, m_gas, m_contractAddress, _data, 0, KeyPair::create().sec());
|
||||
bytes transactionRLP = t.rlp();
|
||||
try
|
||||
{
|
||||
@ -77,13 +124,17 @@ private:
|
||||
{
|
||||
BOOST_REQUIRE(!executive.create(Address(), 0, m_gasPrice, m_gas, &_data, Address()));
|
||||
m_contractAddress = executive.newAddress();
|
||||
BOOST_REQUIRE(m_contractAddress);
|
||||
BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress));
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress));
|
||||
BOOST_REQUIRE(!executive.call(m_contractAddress, Address(), 0, m_gasPrice, &_data, m_gas, Address()));
|
||||
}
|
||||
BOOST_REQUIRE(executive.go());
|
||||
executive.finalize();
|
||||
m_output = executive.out().toBytes();
|
||||
m_output = executive.out().toVector();
|
||||
}
|
||||
|
||||
Address m_contractAddress;
|
||||
@ -93,27 +144,23 @@ private:
|
||||
bytes m_output;
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(SolidityCompilerEndToEndTest)
|
||||
BOOST_FIXTURE_TEST_SUITE(SolidityCompilerEndToEndTest, ExecutionFramework)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(smoke_test)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function f(uint a) returns(uint d) { return a * 7; }\n"
|
||||
"}\n";
|
||||
ExecutionFramework framework;
|
||||
framework.compileAndRun(sourceCode);
|
||||
u256 a = 0x200030004;
|
||||
bytes result = framework.callFunction(0, a);
|
||||
BOOST_CHECK(result == toBigEndian(a * 7));
|
||||
compileAndRun(sourceCode);
|
||||
testSolidityAgainstCppOnRange(0, [](u256 const& a) -> u256 { return a * 7; }, 0, 100);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(empty_contract)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
"}\n";
|
||||
ExecutionFramework framework;
|
||||
framework.compileAndRun(sourceCode);
|
||||
BOOST_CHECK(framework.callFunction(0, bytes()).empty());
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callContractFunction(0, bytes()).empty());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(recursive_calls)
|
||||
@ -124,13 +171,32 @@ BOOST_AUTO_TEST_CASE(recursive_calls)
|
||||
" else return n * f(n - 1);\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
ExecutionFramework framework;
|
||||
framework.compileAndRun(sourceCode);
|
||||
BOOST_CHECK(framework.callFunction(0, u256(0)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(1)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(2)) == toBigEndian(u256(2)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(3)) == toBigEndian(u256(6)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(4)) == toBigEndian(u256(24)));
|
||||
compileAndRun(sourceCode);
|
||||
function<u256(u256)> recursive_calls_cpp = [&recursive_calls_cpp](u256 const& n) -> u256
|
||||
{
|
||||
if (n <= 1)
|
||||
return 1;
|
||||
else
|
||||
return n * recursive_calls_cpp(n - 1);
|
||||
};
|
||||
|
||||
testSolidityAgainstCppOnRange(0, recursive_calls_cpp, 0, 5);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(multiple_functions)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function a() returns(uint n) { return 0; }\n"
|
||||
" function b() returns(uint n) { return 1; }\n"
|
||||
" function c() returns(uint n) { return 2; }\n"
|
||||
" function f() returns(uint n) { return 3; }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callContractFunction(0, bytes()) == toBigEndian(u256(0)));
|
||||
BOOST_CHECK(callContractFunction(1, bytes()) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(callContractFunction(2, bytes()) == toBigEndian(u256(2)));
|
||||
BOOST_CHECK(callContractFunction(3, bytes()) == toBigEndian(u256(3)));
|
||||
BOOST_CHECK(callContractFunction(4, bytes()) == bytes());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(while_loop)
|
||||
@ -142,13 +208,19 @@ BOOST_AUTO_TEST_CASE(while_loop)
|
||||
" while (i <= n) nfac *= i++;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
ExecutionFramework framework;
|
||||
framework.compileAndRun(sourceCode);
|
||||
BOOST_CHECK(framework.callFunction(0, u256(0)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(1)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(2)) == toBigEndian(u256(2)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(3)) == toBigEndian(u256(6)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(4)) == toBigEndian(u256(24)));
|
||||
compileAndRun(sourceCode);
|
||||
|
||||
auto while_loop_cpp = [](u256 const& n) -> u256
|
||||
{
|
||||
u256 nfac = 1;
|
||||
u256 i = 2;
|
||||
while (i <= n)
|
||||
nfac *= i++;
|
||||
|
||||
return nfac;
|
||||
};
|
||||
|
||||
testSolidityAgainstCppOnRange(0, while_loop_cpp, 0, 5);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(break_outside_loop)
|
||||
@ -159,9 +231,8 @@ BOOST_AUTO_TEST_CASE(break_outside_loop)
|
||||
" break; continue; return 2;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
ExecutionFramework framework;
|
||||
framework.compileAndRun(sourceCode);
|
||||
BOOST_CHECK(framework.callFunction(0, u256(0)) == toBigEndian(u256(2)));
|
||||
compileAndRun(sourceCode);
|
||||
testSolidityAgainstCpp(0, [](u256 const&) -> u256 { return 2; }, u256(0));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(nested_loops)
|
||||
@ -184,20 +255,33 @@ BOOST_AUTO_TEST_CASE(nested_loops)
|
||||
" return x;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
ExecutionFramework framework;
|
||||
framework.compileAndRun(sourceCode);
|
||||
BOOST_CHECK(framework.callFunction(0, u256(0)) == toBigEndian(u256(0)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(1)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(2)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(3)) == toBigEndian(u256(2)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(4)) == toBigEndian(u256(2)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(5)) == toBigEndian(u256(4)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(6)) == toBigEndian(u256(5)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(7)) == toBigEndian(u256(5)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(8)) == toBigEndian(u256(7)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(9)) == toBigEndian(u256(8)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(10)) == toBigEndian(u256(10)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(11)) == toBigEndian(u256(10)));
|
||||
compileAndRun(sourceCode);
|
||||
|
||||
auto nested_loops_cpp = [](u256 n) -> u256
|
||||
{
|
||||
while (n > 1)
|
||||
{
|
||||
if (n == 10)
|
||||
break;
|
||||
while (n > 5)
|
||||
{
|
||||
if (n == 8)
|
||||
break;
|
||||
n--;
|
||||
if (n == 6)
|
||||
continue;
|
||||
return n;
|
||||
}
|
||||
n--;
|
||||
if (n == 3)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
};
|
||||
|
||||
testSolidityAgainstCppOnRange(0, nested_loops_cpp, 0, 12);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(calling_other_functions)
|
||||
@ -217,13 +301,36 @@ BOOST_AUTO_TEST_CASE(calling_other_functions)
|
||||
" return 3 * x + 1;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
ExecutionFramework framework;
|
||||
framework.compileAndRun(sourceCode);
|
||||
BOOST_CHECK(framework.callFunction(2, u256(0)) == toBigEndian(u256(0)));
|
||||
BOOST_CHECK(framework.callFunction(2, u256(1)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(framework.callFunction(2, u256(2)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(framework.callFunction(2, u256(8)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(framework.callFunction(2, u256(127)) == toBigEndian(u256(1)));
|
||||
compileAndRun(sourceCode);
|
||||
|
||||
auto evenStep_cpp = [](u256 const& n) -> u256
|
||||
{
|
||||
return n / 2;
|
||||
};
|
||||
|
||||
auto oddStep_cpp = [](u256 const& n) -> u256
|
||||
{
|
||||
return 3 * n + 1;
|
||||
};
|
||||
|
||||
auto collatz_cpp = [&evenStep_cpp, &oddStep_cpp](u256 n) -> u256
|
||||
{
|
||||
u256 y;
|
||||
while ((y = n) > 1)
|
||||
{
|
||||
if (n % 2 == 0)
|
||||
n = evenStep_cpp(n);
|
||||
else
|
||||
n = oddStep_cpp(n);
|
||||
}
|
||||
return y;
|
||||
};
|
||||
|
||||
testSolidityAgainstCpp(2, collatz_cpp, u256(0));
|
||||
testSolidityAgainstCpp(2, collatz_cpp, u256(1));
|
||||
testSolidityAgainstCpp(2, collatz_cpp, u256(2));
|
||||
testSolidityAgainstCpp(2, collatz_cpp, u256(8));
|
||||
testSolidityAgainstCpp(2, collatz_cpp, u256(127));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(many_local_variables)
|
||||
@ -235,10 +342,30 @@ BOOST_AUTO_TEST_CASE(many_local_variables)
|
||||
" y += b + x2;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
ExecutionFramework framework;
|
||||
framework.compileAndRun(sourceCode);
|
||||
BOOST_CHECK(framework.callFunction(0, toBigEndian(u256(0x1000)) + toBigEndian(u256(0x10000)) + toBigEndian(u256(0x100000)))
|
||||
== toBigEndian(u256(0x121121)));
|
||||
compileAndRun(sourceCode);
|
||||
auto f = [](u256 const& x1, u256 const& x2, u256 const& x3) -> u256
|
||||
{
|
||||
u256 a = 0x1;
|
||||
u256 b = 0x10;
|
||||
u256 c = 0x100;
|
||||
u256 y = a + b + c + x1 + x2 + x3;
|
||||
return y + b + x2;
|
||||
};
|
||||
testSolidityAgainstCpp(0, f, u256(0x1000), u256(0x10000), u256(0x100000));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(packing_unpacking_types)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function run(bool a, uint32 b, uint64 c) returns(uint256 y) {\n"
|
||||
" if (a) y = 1;\n"
|
||||
" y = y * 0x100000000 | ~b;\n"
|
||||
" y = y * 0x10000000000000000 | ~c;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callContractFunction(0, fromHex("01""0f0f0f0f""f0f0f0f0f0f0f0f0"))
|
||||
== fromHex("00000000000000000000000000000000000000""01""f0f0f0f0""0f0f0f0f0f0f0f0f"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(multiple_return_values)
|
||||
@ -248,9 +375,8 @@ BOOST_AUTO_TEST_CASE(multiple_return_values)
|
||||
" y1 = x2; y2 = x1;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
ExecutionFramework framework;
|
||||
framework.compileAndRun(sourceCode);
|
||||
BOOST_CHECK(framework.callFunction(0, bytes(1, 1) + toBigEndian(u256(0xcd)))
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callContractFunction(0, bytes(1, 1) + toBigEndian(u256(0xcd)))
|
||||
== toBigEndian(u256(0xcd)) + bytes(1, 1) + toBigEndian(u256(0)));
|
||||
}
|
||||
|
||||
@ -262,13 +388,113 @@ BOOST_AUTO_TEST_CASE(short_circuiting)
|
||||
" return x;"
|
||||
" }\n"
|
||||
"}\n";
|
||||
ExecutionFramework framework;
|
||||
framework.compileAndRun(sourceCode);
|
||||
BOOST_CHECK(framework.callFunction(0, u256(0)) == toBigEndian(u256(0)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(1)) == toBigEndian(u256(8)));
|
||||
compileAndRun(sourceCode);
|
||||
|
||||
auto short_circuiting_cpp = [](u256 n) -> u256
|
||||
{
|
||||
n == 0 || (n = 8) > 0;
|
||||
return n;
|
||||
};
|
||||
|
||||
testSolidityAgainstCppOnRange(0, short_circuiting_cpp, 0, 2);
|
||||
}
|
||||
|
||||
//@todo test smaller types
|
||||
BOOST_AUTO_TEST_CASE(high_bits_cleaning)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function run() returns(uint256 y) {\n"
|
||||
" uint32 x = uint32(0xffffffff) + 10;\n"
|
||||
" if (x >= 0xffffffff) return 0;\n"
|
||||
" return x;"
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
auto high_bits_cleaning_cpp = []() -> u256
|
||||
{
|
||||
uint32_t x = uint32_t(0xffffffff) + 10;
|
||||
if (x >= 0xffffffff)
|
||||
return 0;
|
||||
return x;
|
||||
};
|
||||
testSolidityAgainstCpp(0, high_bits_cleaning_cpp);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(sign_extension)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function run() returns(uint256 y) {\n"
|
||||
" int64 x = -int32(0xff);\n"
|
||||
" if (x >= 0xff) return 0;\n"
|
||||
" return -uint256(x);"
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
auto sign_extension_cpp = []() -> u256
|
||||
{
|
||||
int64_t x = -int32_t(0xff);
|
||||
if (x >= 0xff)
|
||||
return 0;
|
||||
return u256(x) * -1;
|
||||
};
|
||||
testSolidityAgainstCpp(0, sign_extension_cpp);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(small_unsigned_types)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function run() returns(uint256 y) {\n"
|
||||
" uint32 x = uint32(0xffffff) * 0xffffff;\n"
|
||||
" return x / 0x100;"
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
auto small_unsigned_types_cpp = []() -> u256
|
||||
{
|
||||
uint32_t x = uint32_t(0xffffff) * 0xffffff;
|
||||
return x / 0x100;
|
||||
};
|
||||
testSolidityAgainstCpp(0, small_unsigned_types_cpp);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(small_signed_types)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function run() returns(int256 y) {\n"
|
||||
" return -int32(10) * -int64(20);\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
auto small_signed_types_cpp = []() -> u256
|
||||
{
|
||||
return -int32_t(10) * -int64_t(20);
|
||||
};
|
||||
testSolidityAgainstCpp(0, small_signed_types_cpp);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(state_smoke_test)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" uint256 value1;\n"
|
||||
" uint256 value2;\n"
|
||||
" function get(uint8 which) returns (uint256 value) {\n"
|
||||
" if (which == 0) return value1;\n"
|
||||
" else return value2;\n"
|
||||
" }\n"
|
||||
" function set(uint8 which, uint256 value) {\n"
|
||||
" if (which == 0) value1 = value;\n"
|
||||
" else value2 = value;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callContractFunction(0, bytes(1, 0x00)) == toBigEndian(u256(0)));
|
||||
BOOST_CHECK(callContractFunction(0, bytes(1, 0x01)) == toBigEndian(u256(0)));
|
||||
BOOST_CHECK(callContractFunction(1, bytes(1, 0x00) + toBigEndian(u256(0x1234))) == bytes());
|
||||
BOOST_CHECK(callContractFunction(1, bytes(1, 0x01) + toBigEndian(u256(0x8765))) == bytes());
|
||||
BOOST_CHECK(callContractFunction(0, bytes(1, 0x00)) == toBigEndian(u256(0x1234)));
|
||||
BOOST_CHECK(callContractFunction(0, bytes(1, 0x01)) == toBigEndian(u256(0x8765)));
|
||||
BOOST_CHECK(callContractFunction(1, bytes(1, 0x00) + toBigEndian(u256(0x3))) == bytes());
|
||||
BOOST_CHECK(callContractFunction(0, bytes(1, 0x00)) == toBigEndian(u256(0x3)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
@ -154,10 +154,10 @@ BOOST_AUTO_TEST_CASE(comparison)
|
||||
"}\n";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
|
||||
bytes expectation({byte(eth::Instruction::PUSH2), 0x10, 0xaa,
|
||||
byte(eth::Instruction::PUSH2), 0x11, 0xaa,
|
||||
byte(eth::Instruction::GT),
|
||||
byte(eth::Instruction::PUSH1), 0x1,
|
||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x1,
|
||||
byte(eth::Instruction::PUSH2), 0x11, 0xaa, byte(eth::Instruction::PUSH2), 0xff, 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::PUSH2), 0x10, 0xaa, byte(eth::Instruction::PUSH2), 0xff, 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::LT),
|
||||
byte(eth::Instruction::EQ),
|
||||
byte(eth::Instruction::ISZERO)});
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
@ -166,22 +166,22 @@ BOOST_AUTO_TEST_CASE(comparison)
|
||||
BOOST_AUTO_TEST_CASE(short_circuiting)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function f() { var x = (10 + 8 >= 4 || 2 != 9) != true; }"
|
||||
" function f() { var x = true != (4 <= 8 + 10 || 9 != 2); }"
|
||||
"}\n";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
|
||||
bytes expectation({byte(eth::Instruction::PUSH1), 0xa,
|
||||
byte(eth::Instruction::PUSH1), 0x8,
|
||||
byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::PUSH1), 0x4,
|
||||
byte(eth::Instruction::ADD), byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::PUSH1), 0x4, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::GT),
|
||||
byte(eth::Instruction::ISZERO), // after this we have 10 + 8 >= 4
|
||||
byte(eth::Instruction::DUP1),
|
||||
byte(eth::Instruction::PUSH1), 0x14,
|
||||
byte(eth::Instruction::PUSH1), 0x20,
|
||||
byte(eth::Instruction::JUMPI), // short-circuit if it is true
|
||||
byte(eth::Instruction::POP),
|
||||
byte(eth::Instruction::PUSH1), 0x2,
|
||||
byte(eth::Instruction::PUSH1), 0x9,
|
||||
byte(eth::Instruction::PUSH1), 0x2, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::PUSH1), 0x9, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::EQ),
|
||||
byte(eth::Instruction::ISZERO), // after this we have 2 != 9
|
||||
byte(eth::Instruction::JUMPDEST),
|
||||
@ -194,13 +194,14 @@ BOOST_AUTO_TEST_CASE(short_circuiting)
|
||||
BOOST_AUTO_TEST_CASE(arithmetics)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function f() { var x = (1 * (2 / (3 % (4 + (5 - (6 | (7 & (8 ^ 9)))))))); }"
|
||||
" function f() { var x = ((((((((9 ^ 8) & 7) | 6) - 5) + 4) % 3) / 2) * 1); }"
|
||||
"}\n";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
|
||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x1,
|
||||
byte(eth::Instruction::PUSH1), 0x2,
|
||||
byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::PUSH1), 0x3,
|
||||
byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::PUSH1), 0x4,
|
||||
byte(eth::Instruction::PUSH1), 0x5,
|
||||
byte(eth::Instruction::PUSH1), 0x6,
|
||||
@ -210,12 +211,11 @@ BOOST_AUTO_TEST_CASE(arithmetics)
|
||||
byte(eth::Instruction::XOR),
|
||||
byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::OR),
|
||||
byte(eth::Instruction::SWAP1),
|
||||
byte(eth::Instruction::SUB),
|
||||
byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::SWAP1),
|
||||
byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::MOD),
|
||||
byte(eth::Instruction::SWAP1),
|
||||
byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::DIV),
|
||||
byte(eth::Instruction::MUL)});
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
@ -224,15 +224,15 @@ BOOST_AUTO_TEST_CASE(arithmetics)
|
||||
BOOST_AUTO_TEST_CASE(unary_operators)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function f() { var x = !(~+-1 == 2); }"
|
||||
" function f() { var x = !(~+- 1 == 2); }"
|
||||
"}\n";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
|
||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x1,
|
||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x2, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::PUSH1), 0x1,
|
||||
byte(eth::Instruction::PUSH1), 0x0,
|
||||
byte(eth::Instruction::SUB),
|
||||
byte(eth::Instruction::NOT),
|
||||
byte(eth::Instruction::PUSH1), 0x2,
|
||||
byte(eth::Instruction::NOT), byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::EQ),
|
||||
byte(eth::Instruction::ISZERO)});
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
@ -241,7 +241,7 @@ BOOST_AUTO_TEST_CASE(unary_operators)
|
||||
BOOST_AUTO_TEST_CASE(unary_inc_dec)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function f(uint a) { var x = ((a++ ^ ++a) ^ a--) ^ --a; }"
|
||||
" function f(uint a) { var x = --a ^ (a-- ^ (++a ^ a++)); }"
|
||||
"}\n";
|
||||
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "x"}});
|
||||
|
||||
@ -296,16 +296,15 @@ BOOST_AUTO_TEST_CASE(assignment)
|
||||
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "b"}});
|
||||
|
||||
// Stack: a, b
|
||||
bytes expectation({byte(eth::Instruction::DUP1),
|
||||
byte(eth::Instruction::DUP3),
|
||||
byte(eth::Instruction::SWAP1),
|
||||
byte(eth::Instruction::ADD),
|
||||
// Stack here: a b a+b
|
||||
byte(eth::Instruction::SWAP2),
|
||||
byte(eth::Instruction::POP),
|
||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x2, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::DUP2),
|
||||
// Stack here: a+b b a+b
|
||||
byte(eth::Instruction::PUSH1), 0x2,
|
||||
byte(eth::Instruction::DUP4),
|
||||
byte(eth::Instruction::ADD),
|
||||
// Stack here: a b 2 a+b
|
||||
byte(eth::Instruction::SWAP3),
|
||||
byte(eth::Instruction::POP),
|
||||
byte(eth::Instruction::DUP3),
|
||||
// Stack here: a+b b 2 a+b
|
||||
byte(eth::Instruction::MUL)});
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
}
|
||||
@ -320,21 +319,20 @@ BOOST_AUTO_TEST_CASE(function_call)
|
||||
{{"test", "f", "a"}, {"test", "f", "b"}});
|
||||
|
||||
// Stack: a, b
|
||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x0a,
|
||||
byte(eth::Instruction::DUP3),
|
||||
byte(eth::Instruction::PUSH1), 0x01,
|
||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x02, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::PUSH1), 0x12,
|
||||
byte(eth::Instruction::PUSH1), 0x01, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::DUP5),
|
||||
byte(eth::Instruction::ADD),
|
||||
// Stack here: a b <ret label> (a+1)
|
||||
byte(eth::Instruction::DUP3),
|
||||
byte(eth::Instruction::PUSH1), 0x14,
|
||||
// Stack here: a b 2 <ret label> (a+1)
|
||||
byte(eth::Instruction::DUP4),
|
||||
byte(eth::Instruction::PUSH1), 0x19,
|
||||
byte(eth::Instruction::JUMP),
|
||||
byte(eth::Instruction::JUMPDEST),
|
||||
// Stack here: a b g(a+1, b)
|
||||
byte(eth::Instruction::PUSH1), 0x02,
|
||||
// Stack here: a b 2 g(a+1, b)
|
||||
byte(eth::Instruction::MUL),
|
||||
// Stack here: a b g(a+1, b)*2
|
||||
byte(eth::Instruction::DUP3),
|
||||
byte(eth::Instruction::SWAP1),
|
||||
byte(eth::Instruction::ADD),
|
||||
// Stack here: a b a+g(a+1, b)*2
|
||||
byte(eth::Instruction::SWAP2),
|
||||
@ -344,6 +342,45 @@ BOOST_AUTO_TEST_CASE(function_call)
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(negative_literals_8bits)
|
||||
{
|
||||
// these all fit in 8 bits
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function f() { int8 x = -0 + -1 + -0x01 + -127 + -128; }\n"
|
||||
"}\n";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
|
||||
bytes expectation(bytes({byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x80) +
|
||||
bytes({byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x81) +
|
||||
bytes({byte(eth::Instruction::PUSH32)}) + bytes(32, 0xff) +
|
||||
bytes({byte(eth::Instruction::PUSH32)}) + bytes(32, 0xff) +
|
||||
bytes({byte(eth::Instruction::PUSH1), 0x00,
|
||||
byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::ADD)}));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(negative_literals_16bits)
|
||||
{
|
||||
// -1 should need 8 bits, -129 should need 16 bits, how many bits are used is visible
|
||||
// from the SIGNEXTEND opcodes
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function f() { int64 x = int64(-1 + -129); }\n"
|
||||
"}\n";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
|
||||
bytes expectation(bytes({byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x7f) +
|
||||
bytes({byte(eth::Instruction::PUSH32)}) + bytes(32, 0xff) +
|
||||
bytes({byte(eth::Instruction::PUSH1), 0x00,
|
||||
byte(eth::Instruction::SIGNEXTEND),
|
||||
byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::PUSH1), 0x01,
|
||||
byte(eth::Instruction::SIGNEXTEND)}));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
214
solidityJSONInterfaceTest.cpp
Normal file
214
solidityJSONInterfaceTest.cpp
Normal file
@ -0,0 +1,214 @@
|
||||
/*
|
||||
This file is part of cpp-ethereum.
|
||||
|
||||
cpp-ethereum 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.
|
||||
|
||||
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* @author Marek Kotewicz <marek@ethdev.com>
|
||||
* @date 2014
|
||||
* Unit tests for the solidity compiler JSON Interface output.
|
||||
*/
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <libsolidity/CompilerStack.h>
|
||||
#include <jsonrpc/json/json.h>
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class InterfaceChecker
|
||||
{
|
||||
public:
|
||||
bool checkInterface(std::string const& _code, std::string const& _expectedInterfaceString)
|
||||
{
|
||||
m_compilerStack.parse(_code);
|
||||
std::string generatedInterfaceString = m_compilerStack.getInterface();
|
||||
Json::Value generatedInterface;
|
||||
m_reader.parse(generatedInterfaceString, generatedInterface);
|
||||
Json::Value expectedInterface;
|
||||
m_reader.parse(_expectedInterfaceString, expectedInterface);
|
||||
return expectedInterface == generatedInterface;
|
||||
}
|
||||
|
||||
private:
|
||||
CompilerStack m_compilerStack;
|
||||
Json::Reader m_reader;
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(SolidityCompilerJSONInterfaceOutput, InterfaceChecker)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(basic_test)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function f(uint a) returns(uint d) { return a * 7; }\n"
|
||||
"}\n";
|
||||
|
||||
char const* interface = R"([
|
||||
{
|
||||
"name": "f",
|
||||
"inputs": [
|
||||
{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "d",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
}
|
||||
])";
|
||||
|
||||
BOOST_CHECK(checkInterface(sourceCode, interface));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(empty_contract)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
"}\n";
|
||||
|
||||
char const* interface = "[]";
|
||||
|
||||
BOOST_CHECK(checkInterface(sourceCode, interface));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(multiple_methods)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function f(uint a) returns(uint d) { return a * 7; }\n"
|
||||
" function g(uint b) returns(uint e) { return b * 8; }\n"
|
||||
"}\n";
|
||||
|
||||
char const* interface = R"([
|
||||
{
|
||||
"name": "f",
|
||||
"inputs": [
|
||||
{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "d",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "g",
|
||||
"inputs": [
|
||||
{
|
||||
"name": "b",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "e",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
}
|
||||
])";
|
||||
|
||||
BOOST_CHECK(checkInterface(sourceCode, interface));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(multiple_params)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function f(uint a, uint b) returns(uint d) { return a + b; }\n"
|
||||
"}\n";
|
||||
|
||||
char const* interface = R"([
|
||||
{
|
||||
"name": "f",
|
||||
"inputs": [
|
||||
{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"name": "b",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "d",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
}
|
||||
])";
|
||||
|
||||
BOOST_CHECK(checkInterface(sourceCode, interface));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(multiple_methods_order)
|
||||
{
|
||||
// methods are expected to be in alpabetical order
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function f(uint a) returns(uint d) { return a * 7; }\n"
|
||||
" function c(uint b) returns(uint e) { return b * 8; }\n"
|
||||
"}\n";
|
||||
|
||||
char const* interface = R"([
|
||||
{
|
||||
"name": "c",
|
||||
"inputs": [
|
||||
{
|
||||
"name": "b",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "e",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "f",
|
||||
"inputs": [
|
||||
{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "d",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
}
|
||||
])";
|
||||
|
||||
BOOST_CHECK(checkInterface(sourceCode, interface));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -162,6 +162,22 @@ BOOST_AUTO_TEST_CASE(type_checking_function_call)
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_conversion_for_comparison)
|
||||
{
|
||||
char const* text = "contract test {\n"
|
||||
" function f() { uint32(2) == int64(2); }"
|
||||
"}\n";
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_conversion_for_comparison_invalid)
|
||||
{
|
||||
char const* text = "contract test {\n"
|
||||
" function f() { int32(2) == uint64(2); }"
|
||||
"}\n";
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_inference_explicit_conversion)
|
||||
{
|
||||
char const* text = "contract test {\n"
|
||||
|
@ -97,6 +97,27 @@ BOOST_AUTO_TEST_CASE(hex_numbers)
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(negative_numbers)
|
||||
{
|
||||
Scanner scanner(CharStream("var x = -.2 + -0x78 + -7.3 + 8.9;"));
|
||||
BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::VAR);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::ASSIGN);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::NUMBER);
|
||||
BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), "-.2");
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::ADD);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::NUMBER);
|
||||
BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), "-0x78");
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::ADD);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::NUMBER);
|
||||
BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), "-7.3");
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::ADD);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::NUMBER);
|
||||
BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), "8.9");
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::SEMICOLON);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(locations)
|
||||
{
|
||||
Scanner scanner(CharStream("function_identifier has ; -0x743/*comment*/\n ident //comment"));
|
||||
@ -109,11 +130,8 @@ BOOST_AUTO_TEST_CASE(locations)
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::SEMICOLON);
|
||||
BOOST_CHECK_EQUAL(scanner.getCurrentLocation().start, 24);
|
||||
BOOST_CHECK_EQUAL(scanner.getCurrentLocation().end, 25);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::SUB);
|
||||
BOOST_CHECK_EQUAL(scanner.getCurrentLocation().start, 26);
|
||||
BOOST_CHECK_EQUAL(scanner.getCurrentLocation().end, 27);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::NUMBER);
|
||||
BOOST_CHECK_EQUAL(scanner.getCurrentLocation().start, 27);
|
||||
BOOST_CHECK_EQUAL(scanner.getCurrentLocation().start, 26);
|
||||
BOOST_CHECK_EQUAL(scanner.getCurrentLocation().end, 32);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER);
|
||||
BOOST_CHECK_EQUAL(scanner.getCurrentLocation().start, 45);
|
||||
|
717
stPreCompiledContractsFiller.json
Normal file
717
stPreCompiledContractsFiller.json
Normal file
@ -0,0 +1,717 @@
|
||||
{
|
||||
"CallEcrecover0": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code": "{ (MSTORE 0 0x18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c) (MSTORE 32 28) (MSTORE 64 0x73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75f) (MSTORE 96 0xeeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549) [[ 2 ]] (CALL 1000 1 0 0 128 128 32) [[ 0 ]] (MOD (MLOAD 128) (EXP 2 160)) [[ 1 ]] (EQ (ORIGIN) (SLOAD 0)) }",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallEcrecover0_gas500": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code": "{ (MSTORE 0 0x18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c) (MSTORE 32 28) (MSTORE 64 0x73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75f) (MSTORE 96 0xeeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549) [[ 2 ]] (CALL 500 1 0 0 128 128 32) [[ 0 ]] (MOD (MLOAD 128) (EXP 2 160)) [[ 1 ]] (EQ (ORIGIN) (SLOAD 0)) }",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallEcrecover0_Gas499": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code": "{ (MSTORE 0 0x18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c) (MSTORE 32 28) (MSTORE 64 0x73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75f) (MSTORE 96 0xeeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549) [[ 2 ]] (CALL 499 1 0 0 128 128 32) [[ 0 ]] (MOD (MLOAD 128) (EXP 2 160)) [[ 1 ]] (EQ (ORIGIN) (SLOAD 0)) }",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallEcrecover0_0input": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code": "{ [[ 2 ]] (CALL 1000 1 0 0 128 128 32) [[ 0 ]] (MOD (MLOAD 128) (EXP 2 160)) }",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallEcrecover1": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code": "{ (MSTORE 0 0x18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c) (MSTORE 32 1) (MSTORE 64 0x73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75f) (MSTORE 96 0xeeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549) [[ 2 ]] (CALL 1000 1 0 0 128 128 32) [[ 0 ]] (MOD (MLOAD 128) (EXP 2 160)) [[ 1 ]] (EQ (ORIGIN) (SLOAD 0)) }",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallEcrecover2": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code": "{ (MSTORE 0 0x18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c) (MSTORE 32 28) (MSTORE 33 0x73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75f) (MSTORE 65 0xeeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549) [[ 2 ]] (CALL 1000 1 0 0 97 97 32) [[ 0 ]] (MOD (MLOAD 97) (EXP 2 160)) [[ 1 ]] (EQ (ORIGIN) (SLOAD 0)) }",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallEcrecover3": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code": "{ (MSTORE 0 0x2f380a2dea7e778d81affc2443403b8fe4644db442ae4862ff5bb3732829cdb9) (MSTORE 32 27) (MSTORE 64 0x6b65ccb0558806e9b097f27a396d08f964e37b8b7af6ceeb516ff86739fbea0a) (MSTORE 96 0x37cbc8d883e129a4b1ef9d5f1df53c4f21a3ef147cf2a50a4ede0eb06ce092d4) [[ 2 ]] (CALL 1000 1 0 0 128 128 32) [[ 0 ]] (MOD (MLOAD 128) (EXP 2 160)) [[ 1 ]] (EQ (ORIGIN) (SLOAD 0)) }",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallSha256_0": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code" : "0x600160005260206000602060006000600260fff1600051600055",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallSha256_1": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code" : "{ [[ 2 ]] (CALL 500 2 0 0 0 0 32) [[ 0 ]] (MLOAD 0)}",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallSha256_2": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code" : "{ (MSTORE 5 0xf34578907f) [[ 2 ]] (CALL 500 2 0 0 37 0 32) [[ 0 ]] (MLOAD 0)}",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallSha256_3": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code" : "{ (MSTORE 0 0xf34578907f) [[ 2 ]] (CALL 500 2 0 0 37 0 32) [[ 0 ]] (MLOAD 0)}",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallSha256_4": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) [[ 2 ]] (CALL 100 2 0 0 32 0 32) [[ 0 ]] (MLOAD 0)}",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallSha256_4_gas99": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) [[ 2 ]] (CALL 99 2 0 0 32 0 32) [[ 0 ]] (MLOAD 0)}",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallSha256_5": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) [[ 2 ]] (CALL 500 2 0 0 1000000 0 32) [[ 0 ]] (MLOAD 0)}",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "10000000",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallRipemd160_0": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code" : "0x600160005260206000602060006000600360fff1600051600055",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallRipemd160_1": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code" : "{ [[ 2 ]] (CALL 500 3 0 0 0 0 32) [[ 0 ]] (MLOAD 0)}",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallRipemd160_2": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code" : "{ (MSTORE 5 0xf34578907f) [[ 2 ]] (CALL 500 3 0 0 37 0 32) [[ 0 ]] (MLOAD 0)}",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallRipemd160_3": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code" : "{ (MSTORE 0 0xf34578907f) [[ 2 ]] (CALL 500 3 0 0 37 0 32) [[ 0 ]] (MLOAD 0)}",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallRipemd160_4": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) [[ 2 ]] (CALL 100 3 0 0 32 0 32) [[ 0 ]] (MLOAD 0)}",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallRipemd160_4_gas99": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) [[ 2 ]] (CALL 99 3 0 0 32 0 32) [[ 0 ]] (MLOAD 0)}",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "365224",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
"CallRipemd160_5": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "20000000",
|
||||
"nonce" : 0,
|
||||
"code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) [[ 2 ]] (CALL 500 3 0 0 1000000 0 32) [[ 0 ]] (MLOAD 0)}",
|
||||
"storage": {}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "10000000",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
|
1334
stSystemOperationsTestFiller.json
Normal file
1334
stSystemOperationsTestFiller.json
Normal file
File diff suppressed because it is too large
Load Diff
53
state.cpp
53
state.cpp
@ -43,7 +43,6 @@ namespace dev { namespace test {
|
||||
|
||||
void doStateTests(json_spirit::mValue& v, bool _fillin)
|
||||
{
|
||||
cout << "start state test\n";
|
||||
for (auto& i: v.get_obj())
|
||||
{
|
||||
cnote << i.first;
|
||||
@ -55,12 +54,6 @@ void doStateTests(json_spirit::mValue& v, bool _fillin)
|
||||
|
||||
ImportTest importer(o, _fillin);
|
||||
|
||||
if (_fillin)
|
||||
{
|
||||
importer.code = importer.m_statePre.code(importer.m_environment.myAddress);
|
||||
importer.m_environment.code = &importer.code;
|
||||
}
|
||||
|
||||
State theState = importer.m_statePre;
|
||||
bytes tx = importer.m_transaction.rlp();
|
||||
bytes output;
|
||||
@ -124,12 +117,48 @@ BOOST_AUTO_TEST_CASE(stSystemOperationsTest)
|
||||
dev::test::executeTests("stSystemOperationsTest", "/StateTests", dev::test::doStateTests);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(tmp)
|
||||
BOOST_AUTO_TEST_CASE(stPreCompiledContracts)
|
||||
{
|
||||
int currentVerbosity = g_logVerbosity;
|
||||
g_logVerbosity = 12;
|
||||
dev::test::executeTests("tmp", "/StateTests", dev::test::doStateTests);
|
||||
g_logVerbosity = currentVerbosity;
|
||||
dev::test::executeTests("stPreCompiledContracts", "/StateTests", dev::test::doStateTests);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(stCreateTest)
|
||||
{
|
||||
for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
|
||||
{
|
||||
string arg = boost::unit_test::framework::master_test_suite().argv[i];
|
||||
if (arg == "--createtest")
|
||||
{
|
||||
if (boost::unit_test::framework::master_test_suite().argc <= i + 2)
|
||||
{
|
||||
cnote << "usage: ./testeth --createtest <PathToConstructor> <PathToDestiny>\n";
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
cnote << "Populating tests...";
|
||||
json_spirit::mValue v;
|
||||
string s = asString(dev::contents(boost::unit_test::framework::master_test_suite().argv[i + 1]));
|
||||
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Content of " + (string)boost::unit_test::framework::master_test_suite().argv[i + 1] + " is empty.");
|
||||
json_spirit::read_string(s, v);
|
||||
dev::test::doStateTests(v, true);
|
||||
writeFile(boost::unit_test::framework::master_test_suite().argv[i + 2], asBytes(json_spirit::write_string(v, true)));
|
||||
}
|
||||
catch (Exception const& _e)
|
||||
{
|
||||
BOOST_ERROR("Failed state test with Exception: " << diagnostic_information(_e));
|
||||
}
|
||||
catch (std::exception const& _e)
|
||||
{
|
||||
BOOST_ERROR("Failed state test with Exception: " << _e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(userDefinedFileState)
|
||||
{
|
||||
dev::test::userDefinedTest("--statetest", dev::test::doStateTests);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -1,44 +0,0 @@
|
||||
{
|
||||
"ABAcalls0": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "{ [[ (PC) ]] (CALL 1000 0x945304eb96065b2a98b57a48a06ae28d285a71b5 24 0 0 0 0) }",
|
||||
"storage": {}
|
||||
},
|
||||
"945304eb96065b2a98b57a48a06ae28d285a71b5" : {
|
||||
"balance" : "23",
|
||||
"code" : " { [[ (PC) ]] (ADD 1 (CALL 500 0x095e7baea6a6c7c4c2dfeb977efac326af552d87 23 0 0 0 0)) } ",
|
||||
"nonce" : "0",
|
||||
"storage" : {
|
||||
}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "10000",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
}
|
||||
|
||||
}
|
59
vm.cpp
59
vm.cpp
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "vm.h"
|
||||
using namespace std;
|
||||
using namespace json_spirit;
|
||||
@ -29,7 +30,7 @@ using namespace dev::eth;
|
||||
using namespace dev::test;
|
||||
|
||||
FakeExtVM::FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& _currentBlock, unsigned _depth): /// TODO: XXX: remove the default argument & fix.
|
||||
ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytesConstRef(), _previousBlock, _currentBlock, _depth) {}
|
||||
ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytes(), _previousBlock, _currentBlock, _depth) {}
|
||||
|
||||
h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFunc const&)
|
||||
{
|
||||
@ -195,11 +196,11 @@ void FakeExtVM::importExec(mObject& _o)
|
||||
gas = toInt(_o["gas"]);
|
||||
|
||||
thisTxCode.clear();
|
||||
code = &thisTxCode;
|
||||
code = thisTxCode;
|
||||
|
||||
thisTxCode = importCode(_o);
|
||||
if (_o["code"].type() != str_type && _o["code"].type() != array_type)
|
||||
code.reset();
|
||||
code.clear();
|
||||
|
||||
thisTxData.clear();
|
||||
thisTxData = importData(_o);
|
||||
@ -297,10 +298,10 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
|
||||
o["pre"] = mValue(fev.exportState());
|
||||
|
||||
fev.importExec(o["exec"].get_obj());
|
||||
if (!fev.code)
|
||||
if (fev.code.empty())
|
||||
{
|
||||
fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress));
|
||||
fev.code = &fev.thisTxCode;
|
||||
fev.code = fev.thisTxCode;
|
||||
}
|
||||
|
||||
auto vm = VMFace::create(vmKind, fev.gas);
|
||||
@ -308,21 +309,31 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
|
||||
auto outOfGas = false;
|
||||
|
||||
auto startTime = std::chrono::high_resolution_clock::now();
|
||||
u256 gas;
|
||||
try
|
||||
{
|
||||
output = vm->go(fev, fev.simpleTrace()).toVector();
|
||||
gas = vm->gas();
|
||||
}
|
||||
catch (OutOfGas const&)
|
||||
{
|
||||
outOfGas = true;
|
||||
gas = 0;
|
||||
}
|
||||
catch (VMException const& _e)
|
||||
{
|
||||
cnote << "VM did throw an exception: " << diagnostic_information(_e);
|
||||
gas = 0;
|
||||
}
|
||||
catch (Exception const& _e)
|
||||
{
|
||||
cnote << "VM did throw an exception: " << diagnostic_information(_e);
|
||||
BOOST_ERROR("Failed VM Test with Exception: " << _e.what());
|
||||
}
|
||||
catch (std::exception const& _e)
|
||||
{
|
||||
cnote << "VM did throw an exception: " << _e.what();
|
||||
BOOST_ERROR("Failed VM Test with Exception: " << _e.what());
|
||||
}
|
||||
|
||||
auto endTime = std::chrono::high_resolution_clock::now();
|
||||
@ -338,8 +349,6 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
|
||||
}
|
||||
}
|
||||
|
||||
auto gas = vm->gas();
|
||||
|
||||
// delete null entries in storage for the sake of comparison
|
||||
|
||||
for (auto &a: fev.addresses)
|
||||
@ -380,7 +389,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
|
||||
checkOutput(output, o);
|
||||
|
||||
BOOST_CHECK_EQUAL(toInt(o["gas"]), gas);
|
||||
|
||||
|
||||
if (outOfGas)
|
||||
BOOST_CHECK_MESSAGE(gas == 0, "Remaining gas not 0 in out-of-gas state");
|
||||
|
||||
@ -454,32 +463,42 @@ BOOST_AUTO_TEST_CASE(vmPushDupSwapTest)
|
||||
dev::test::executeTests("vmPushDupSwapTest", "/VMTests", dev::test::doVMTests);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(userDefinedFile)
|
||||
BOOST_AUTO_TEST_CASE(vmRandom)
|
||||
{
|
||||
if (boost::unit_test::framework::master_test_suite().argc >= 2)
|
||||
string testPath = getTestPath();
|
||||
testPath += "/VMTests/RandomTests";
|
||||
|
||||
vector<boost::filesystem::path> testFiles;
|
||||
boost::filesystem::directory_iterator iterator(testPath);
|
||||
for(; iterator != boost::filesystem::directory_iterator(); ++iterator)
|
||||
if (boost::filesystem::is_regular_file(iterator->path()) && iterator->path().extension() == ".json")
|
||||
testFiles.push_back(iterator->path());
|
||||
|
||||
for (auto& path: testFiles)
|
||||
{
|
||||
string filename = boost::unit_test::framework::master_test_suite().argv[1];
|
||||
int currentVerbosity = g_logVerbosity;
|
||||
g_logVerbosity = 12;
|
||||
try
|
||||
{
|
||||
cnote << "Testing VM..." << "user defined test";
|
||||
cnote << "Testing ..." << path.filename();
|
||||
json_spirit::mValue v;
|
||||
string s = asString(contents(filename));
|
||||
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. ");
|
||||
string s = asString(dev::contents(path.string()));
|
||||
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Content of " + path.string() + " is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?");
|
||||
json_spirit::read_string(s, v);
|
||||
dev::test::doVMTests(v, false);
|
||||
doVMTests(v, false);
|
||||
}
|
||||
catch (Exception const& _e)
|
||||
{
|
||||
BOOST_ERROR("Failed VM Test with Exception: " << diagnostic_information(_e));
|
||||
BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
|
||||
}
|
||||
catch (std::exception const& _e)
|
||||
{
|
||||
BOOST_ERROR("Failed VM Test with Exception: " << _e.what());
|
||||
BOOST_ERROR("Failed test with Exception: " << _e.what());
|
||||
}
|
||||
g_logVerbosity = currentVerbosity;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(userDefinedFileVM)
|
||||
{
|
||||
dev::test::userDefinedTest("--vmtest", dev::test::doVMTests);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
2
vm.h
2
vm.h
@ -29,7 +29,7 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include "JsonSpiritHeaders.h"
|
||||
#include <libdevcore/Log.h>
|
||||
#include <libdevcore/CommonIO.h>
|
||||
#include <libevmface/Instruction.h>
|
||||
#include <libevmcore/Instruction.h>
|
||||
#include <libevm/ExtVMFace.h>
|
||||
#include <libevm/VM.h>
|
||||
#include <liblll/Compiler.h>
|
||||
|
@ -1725,7 +1725,7 @@
|
||||
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "0x62122ff4600016600057",
|
||||
"code" : "0x62122ff460000b600055",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
@ -1753,7 +1753,7 @@
|
||||
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "0x62122f6a600016600057",
|
||||
"code" : "0x62122f6a60000b600055",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
@ -1781,7 +1781,7 @@
|
||||
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "0x6212faf4600116600057",
|
||||
"code" : "0x6212faf460010b600055",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
@ -1809,7 +1809,7 @@
|
||||
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "0x62126af4600116600057",
|
||||
"code" : "0x62126af460010b600055",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
@ -1837,7 +1837,7 @@
|
||||
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "0x62126af4605016600057",
|
||||
"code" : "0x62126af460500b600055",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
@ -2005,7 +2005,7 @@
|
||||
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "0x66f000000000000161ffff16600057",
|
||||
"code" : "0x66f000000000000161ffff0b600055",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
@ -2033,7 +2033,7 @@
|
||||
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "0x60ff68f0000000000000000116600057",
|
||||
"code" : "0x60ff68f000000000000000010b600055",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
|
@ -19,37 +19,13 @@ class WebThreeStubClient
|
||||
delete this->client;
|
||||
}
|
||||
|
||||
std::string account() throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("account",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
Json::Value accounts() throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("accounts",p);
|
||||
if (result.isArray())
|
||||
return result;
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
std::string addToGroup(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
|
||||
std::string db_get(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
|
||||
Json::Value result = this->client->CallMethod("addToGroup",p);
|
||||
Json::Value result = this->client->CallMethod("db_get",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
@ -57,12 +33,13 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
std::string balanceAt(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
std::string db_getString(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
|
||||
Json::Value result = this->client->CallMethod("balanceAt",p);
|
||||
Json::Value result = this->client->CallMethod("db_getString",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
@ -70,51 +47,14 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
Json::Value blockByHash(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
bool db_put(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
p.append(param3);
|
||||
|
||||
Json::Value result = this->client->CallMethod("blockByHash",p);
|
||||
if (result.isObject())
|
||||
return result;
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
Json::Value blockByNumber(const int& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("blockByNumber",p);
|
||||
if (result.isObject())
|
||||
return result;
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
std::string call(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("call",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool changed(const int& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("changed",p);
|
||||
Json::Value result = this->client->CallMethod("db_put",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
@ -122,24 +62,39 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
std::string codeAt(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
bool db_putString(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
p.append(param3);
|
||||
|
||||
Json::Value result = this->client->CallMethod("codeAt",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
Json::Value result = this->client->CallMethod("db_putString",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
std::string coinbase() throw (jsonrpc::JsonRpcException)
|
||||
Json::Value eth_accounts() throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("coinbase",p);
|
||||
Json::Value result = this->client->CallMethod("eth_accounts",p);
|
||||
if (result.isArray())
|
||||
return result;
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
std::string eth_balanceAt(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("eth_balanceAt",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
@ -147,12 +102,38 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
std::string compile(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
Json::Value eth_blockByHash(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("compile",p);
|
||||
Json::Value result = this->client->CallMethod("eth_blockByHash",p);
|
||||
if (result.isObject())
|
||||
return result;
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
Json::Value eth_blockByNumber(const int& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("eth_blockByNumber",p);
|
||||
if (result.isObject())
|
||||
return result;
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
std::string eth_call(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("eth_call",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
@ -160,12 +141,63 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
double countAt(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
bool eth_changed(const int& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("countAt",p);
|
||||
Json::Value result = this->client->CallMethod("eth_changed",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
std::string eth_codeAt(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("eth_codeAt",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
std::string eth_coinbase() throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("eth_coinbase",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
std::string eth_compile(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("eth_compile",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
double eth_countAt(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("eth_countAt",p);
|
||||
if (result.isDouble())
|
||||
return result.asDouble();
|
||||
else
|
||||
@ -173,11 +205,11 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
int defaultBlock() throw (jsonrpc::JsonRpcException)
|
||||
int eth_defaultBlock() throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("defaultBlock",p);
|
||||
Json::Value result = this->client->CallMethod("eth_defaultBlock",p);
|
||||
if (result.isInt())
|
||||
return result.asInt();
|
||||
else
|
||||
@ -185,11 +217,11 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
std::string gasPrice() throw (jsonrpc::JsonRpcException)
|
||||
std::string eth_gasPrice() throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("gasPrice",p);
|
||||
Json::Value result = this->client->CallMethod("eth_gasPrice",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
@ -197,26 +229,12 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
std::string get(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
|
||||
Json::Value result = this->client->CallMethod("get",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
Json::Value getMessages(const int& param1) throw (jsonrpc::JsonRpcException)
|
||||
Json::Value eth_getMessages(const int& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("getMessages",p);
|
||||
Json::Value result = this->client->CallMethod("eth_getMessages",p);
|
||||
if (result.isArray())
|
||||
return result;
|
||||
else
|
||||
@ -224,13 +242,24 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
std::string getString(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
|
||||
bool eth_listening() throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("eth_listening",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
std::string eth_lll(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
|
||||
Json::Value result = this->client->CallMethod("getString",p);
|
||||
Json::Value result = this->client->CallMethod("eth_lll",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
@ -238,49 +267,24 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
bool haveIdentity(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
bool eth_mining() throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("eth_mining",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
int eth_newFilter(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("haveIdentity",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool listening() throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("listening",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool mining() throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("mining",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
int newFilter(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("newFilter",p);
|
||||
Json::Value result = this->client->CallMethod("eth_newFilter",p);
|
||||
if (result.isInt())
|
||||
return result.asInt();
|
||||
else
|
||||
@ -288,12 +292,12 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
int newFilterString(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
int eth_newFilterString(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("newFilterString",p);
|
||||
Json::Value result = this->client->CallMethod("eth_newFilterString",p);
|
||||
if (result.isInt())
|
||||
return result.asInt();
|
||||
else
|
||||
@ -301,13 +305,89 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
std::string newGroup(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
|
||||
int eth_number() throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("eth_number",p);
|
||||
if (result.isInt())
|
||||
return result.asInt();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
int eth_peerCount() throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("eth_peerCount",p);
|
||||
if (result.isInt())
|
||||
return result.asInt();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool eth_setCoinbase(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("eth_setCoinbase",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool eth_setDefaultBlock(const int& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("eth_setDefaultBlock",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool eth_setListening(const bool& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("eth_setListening",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool eth_setMining(const bool& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("eth_setMining",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
std::string eth_stateAt(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
|
||||
Json::Value result = this->client->CallMethod("newGroup",p);
|
||||
Json::Value result = this->client->CallMethod("eth_stateAt",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
@ -315,11 +395,12 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
std::string newIdentity() throw (jsonrpc::JsonRpcException)
|
||||
std::string eth_transact(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("newIdentity",p);
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("eth_transact",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
@ -327,66 +408,68 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
int number() throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("number",p);
|
||||
if (result.isInt())
|
||||
return result.asInt();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
int peerCount() throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("peerCount",p);
|
||||
if (result.isInt())
|
||||
return result.asInt();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool post(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("post",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool put(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException)
|
||||
Json::Value eth_transactionByHash(const std::string& param1, const int& param2) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
p.append(param3);
|
||||
|
||||
Json::Value result = this->client->CallMethod("put",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
Json::Value result = this->client->CallMethod("eth_transactionByHash",p);
|
||||
if (result.isObject())
|
||||
return result;
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool putString(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException)
|
||||
Json::Value eth_transactionByNumber(const int& param1, const int& param2) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
p.append(param3);
|
||||
|
||||
Json::Value result = this->client->CallMethod("putString",p);
|
||||
Json::Value result = this->client->CallMethod("eth_transactionByNumber",p);
|
||||
if (result.isObject())
|
||||
return result;
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
Json::Value eth_uncleByHash(const std::string& param1, const int& param2) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
|
||||
Json::Value result = this->client->CallMethod("eth_uncleByHash",p);
|
||||
if (result.isObject())
|
||||
return result;
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
Json::Value eth_uncleByNumber(const int& param1, const int& param2) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
|
||||
Json::Value result = this->client->CallMethod("eth_uncleByNumber",p);
|
||||
if (result.isObject())
|
||||
return result;
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool eth_uninstallFilter(const int& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("eth_uninstallFilter",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
@ -394,64 +477,26 @@ p.append(param3);
|
||||
|
||||
}
|
||||
|
||||
bool setCoinbase(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
std::string shh_addToGroup(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
|
||||
Json::Value result = this->client->CallMethod("setCoinbase",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
Json::Value result = this->client->CallMethod("shh_addToGroup",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool setDefaultBlock(const int& param1) throw (jsonrpc::JsonRpcException)
|
||||
Json::Value shh_changed(const int& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("setDefaultBlock",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool setListening(const bool& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("setListening",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool setMining(const bool& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("setMining",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
Json::Value shhChanged(const int& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("shhChanged",p);
|
||||
Json::Value result = this->client->CallMethod("shh_changed",p);
|
||||
if (result.isArray())
|
||||
return result;
|
||||
else
|
||||
@ -459,25 +504,12 @@ p.append(param3);
|
||||
|
||||
}
|
||||
|
||||
int shhNewFilter(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
|
||||
bool shh_haveIdentity(const std::string& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("shhNewFilter",p);
|
||||
if (result.isInt())
|
||||
return result.asInt();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool shhUninstallFilter(const int& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("shhUninstallFilter",p);
|
||||
Json::Value result = this->client->CallMethod("shh_haveIdentity",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
@ -485,13 +517,26 @@ p.append(param3);
|
||||
|
||||
}
|
||||
|
||||
std::string stateAt(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
|
||||
int shh_newFilter(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("shh_newFilter",p);
|
||||
if (result.isInt())
|
||||
return result.asInt();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
std::string shh_newGroup(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
|
||||
Json::Value result = this->client->CallMethod("stateAt",p);
|
||||
Json::Value result = this->client->CallMethod("shh_newGroup",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
@ -499,12 +544,11 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
std::string transact(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
|
||||
std::string shh_newIdentity() throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("transact",p);
|
||||
p = Json::nullValue;
|
||||
Json::Value result = this->client->CallMethod("shh_newIdentity",p);
|
||||
if (result.isString())
|
||||
return result.asString();
|
||||
else
|
||||
@ -512,68 +556,25 @@ p.append(param2);
|
||||
|
||||
}
|
||||
|
||||
Json::Value transactionByHash(const std::string& param1, const int& param2) throw (jsonrpc::JsonRpcException)
|
||||
bool shh_post(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
|
||||
Json::Value result = this->client->CallMethod("transactionByHash",p);
|
||||
if (result.isObject())
|
||||
return result;
|
||||
Json::Value result = this->client->CallMethod("shh_post",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
Json::Value transactionByNumber(const int& param1, const int& param2) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
|
||||
Json::Value result = this->client->CallMethod("transactionByNumber",p);
|
||||
if (result.isObject())
|
||||
return result;
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
Json::Value uncleByHash(const std::string& param1, const int& param2) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
|
||||
Json::Value result = this->client->CallMethod("uncleByHash",p);
|
||||
if (result.isObject())
|
||||
return result;
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
Json::Value uncleByNumber(const int& param1, const int& param2) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
p.append(param2);
|
||||
|
||||
Json::Value result = this->client->CallMethod("uncleByNumber",p);
|
||||
if (result.isObject())
|
||||
return result;
|
||||
else
|
||||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
|
||||
|
||||
}
|
||||
|
||||
bool uninstallFilter(const int& param1) throw (jsonrpc::JsonRpcException)
|
||||
bool shh_uninstallFilter(const int& param1) throw (jsonrpc::JsonRpcException)
|
||||
{
|
||||
Json::Value p;
|
||||
p.append(param1);
|
||||
|
||||
Json::Value result = this->client->CallMethod("uninstallFilter",p);
|
||||
Json::Value result = this->client->CallMethod("shh_uninstallFilter",p);
|
||||
if (result.isBool())
|
||||
return result.asBool();
|
||||
else
|
||||
|
84
whisperTopic.cpp
Normal file
84
whisperTopic.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
This file is part of cpp-ethereum.
|
||||
|
||||
cpp-ethereum 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.
|
||||
|
||||
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @file whisperTopic.cpp
|
||||
* @author Gav Wood <i@gavwood.com>
|
||||
* @date 2014
|
||||
*/
|
||||
#include <functional>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <libp2p/Host.h>
|
||||
#include <libwhisper/WhisperPeer.h>
|
||||
#include <libwhisper/WhisperHost.h>
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace dev::p2p;
|
||||
using namespace dev::shh;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(whisper)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(topic)
|
||||
{
|
||||
g_logVerbosity = 0;
|
||||
|
||||
bool started = false;
|
||||
unsigned result = 0;
|
||||
std::thread listener([&]()
|
||||
{
|
||||
setThreadName("other");
|
||||
|
||||
Host ph("Test", NetworkPreferences(30303, "", false, true));
|
||||
auto wh = ph.registerCapability(new WhisperHost());
|
||||
ph.start();
|
||||
|
||||
started = true;
|
||||
|
||||
/// Only interested in odd packets
|
||||
auto w = wh->installWatch(BuildTopicMask()("odd"));
|
||||
|
||||
for (int i = 0, last = 0; i < 100 && last < 81; ++i)
|
||||
{
|
||||
for (auto i: wh->checkWatch(w))
|
||||
{
|
||||
Message msg = wh->envelope(i).open();
|
||||
last = RLP(msg.payload()).toInt<unsigned>();
|
||||
cnote << "New message from:" << msg.from().abridged() << RLP(msg.payload()).toInt<unsigned>();
|
||||
result += last;
|
||||
}
|
||||
this_thread::sleep_for(chrono::milliseconds(50));
|
||||
}
|
||||
});
|
||||
|
||||
while (!started)
|
||||
this_thread::sleep_for(chrono::milliseconds(50));
|
||||
|
||||
Host ph("Test", NetworkPreferences(30300, "", false, true));
|
||||
auto wh = ph.registerCapability(new WhisperHost());
|
||||
ph.start();
|
||||
ph.connect("127.0.0.1", 30303);
|
||||
|
||||
KeyPair us = KeyPair::create();
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
wh->post(us.sec(), RLPStream().append(i * i).out(), BuildTopic(i)(i % 2 ? "odd" : "even"));
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
|
||||
listener.join();
|
||||
BOOST_REQUIRE_EQUAL(result, 1 + 9 + 25 + 49 + 81);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
Loading…
Reference in New Issue
Block a user