Merge remote-tracking branch 'upstream/develop' into evmjit

This commit is contained in:
Paweł Bylica 2015-03-05 16:49:21 +01:00
commit 51e376efb8
17 changed files with 250 additions and 193 deletions

View File

@ -23,7 +23,9 @@
#include <thread> #include <thread>
#include <chrono> #include <chrono>
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
#include <libethereum/Client.h> #include <libethereum/Client.h>
#include <liblll/Compiler.h> #include <liblll/Compiler.h>
#include <libevm/VMFactory.h> #include <libevm/VMFactory.h>
@ -170,7 +172,7 @@ void ImportTest::importTransaction(json_spirit::mObject& _o)
} }
} }
void ImportTest::exportTest(bytes _output, State& _statePost) void ImportTest::exportTest(bytes const& _output, State const& _statePost)
{ {
// export output // export output
m_TestObject["out"] = "0x" + toHex(_output); m_TestObject["out"] = "0x" + toHex(_output);

View File

@ -22,7 +22,9 @@
#pragma once #pragma once
#include <functional> #include <functional>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include "JsonSpiritHeaders.h" #include "JsonSpiritHeaders.h"
#include <libethereum/State.h> #include <libethereum/State.h>
#include <libevm/ExtVMFace.h> #include <libevm/ExtVMFace.h>
@ -52,7 +54,7 @@ public:
void importEnv(json_spirit::mObject& _o); void importEnv(json_spirit::mObject& _o);
void importState(json_spirit::mObject& _o, eth::State& _state); void importState(json_spirit::mObject& _o, eth::State& _state);
void importTransaction(json_spirit::mObject& _o); void importTransaction(json_spirit::mObject& _o);
void exportTest(bytes _output, eth::State& _statePost); void exportTest(bytes const& _output, eth::State const& _statePost);
eth::State m_statePre; eth::State m_statePre;
eth::State m_statePost; eth::State m_statePost;

144
block.cpp
View File

@ -81,6 +81,76 @@ bytes createBlockRLPFromFields(mObject& _tObj)
return rlpStream.out(); return rlpStream.out();
} }
void overwriteBlockHeader(mObject& _o, BlockInfo _current_BlockHeader)
{
if (_o.count("blockHeader"))
{
if (_o["blockHeader"].get_obj().size() != 14)
{
BlockInfo tmp = _current_BlockHeader;
if (_o["blockHeader"].get_obj().count("parentHash"))
tmp.parentHash = h256(_o["blockHeader"].get_obj()["parentHash"].get_str());
if (_o["blockHeader"].get_obj().count("uncleHash"))
tmp.sha3Uncles = h256(_o["blockHeader"].get_obj()["uncleHash"].get_str());
if (_o["blockHeader"].get_obj().count("coinbase"))
tmp.coinbaseAddress = Address(_o["blockHeader"].get_obj()["coinbase"].get_str());
if (_o["blockHeader"].get_obj().count("stateRoot"))
tmp.stateRoot = h256(_o["blockHeader"].get_obj()["stateRoot"].get_str());
if (_o["blockHeader"].get_obj().count("transactionsTrie"))
tmp.transactionsRoot = h256(_o["blockHeader"].get_obj()["transactionsTrie"].get_str());
if (_o["blockHeader"].get_obj().count("receiptTrie"))
tmp.receiptsRoot = h256(_o["blockHeader"].get_obj()["receiptTrie"].get_str());
if (_o["blockHeader"].get_obj().count("bloom"))
tmp.logBloom = LogBloom(_o["blockHeader"].get_obj()["bloom"].get_str());
if (_o["blockHeader"].get_obj().count("difficulty"))
tmp.difficulty = toInt(_o["blockHeader"].get_obj()["difficulty"]);
if (_o["blockHeader"].get_obj().count("number"))
tmp.number = toInt(_o["blockHeader"].get_obj()["number"]);
if (_o["blockHeader"].get_obj().count("gasLimit"))
tmp.gasLimit = toInt(_o["blockHeader"].get_obj()["gasLimit"]);
if (_o["blockHeader"].get_obj().count("gasUsed"))
tmp.gasUsed = toInt(_o["blockHeader"].get_obj()["gasUsed"]);
if (_o["blockHeader"].get_obj().count("timestamp"))
tmp.timestamp = toInt(_o["blockHeader"].get_obj()["timestamp"]);
if (_o["blockHeader"].get_obj().count("extraData"))
tmp.extraData = importByteArray(_o["blockHeader"].get_obj()["extraData"].get_str());
// find new valid nonce
if (tmp != _current_BlockHeader)
{
_current_BlockHeader = tmp;
cout << "new header!\n";
ProofOfWork pow;
MineInfo ret;
while (!ProofOfWork::verify(_current_BlockHeader.headerHash(WithoutNonce), _current_BlockHeader.nonce, _current_BlockHeader.difficulty))
tie(ret, _current_BlockHeader.nonce) = pow.mine(_current_BlockHeader.headerHash(WithoutNonce), _current_BlockHeader.difficulty, 10000, true, true);
}
}
else
{
// take the blockheader as is
const bytes c_blockRLP = createBlockRLPFromFields(_o["blockHeader"].get_obj());
const RLP c_bRLP(c_blockRLP);
_current_BlockHeader.populateFromHeader(c_bRLP, false);
}
}
}
void doBlockTests(json_spirit::mValue& _v, bool _fillin) void doBlockTests(json_spirit::mValue& _v, bool _fillin)
{ {
for (auto& i: _v.get_obj()) for (auto& i: _v.get_obj())
@ -214,76 +284,9 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin)
BlockInfo current_BlockHeader = state.info(); BlockInfo current_BlockHeader = state.info();
// overwrite blockheader with (possible wrong) data from "blockheader" in filler; // overwrite blockheader with (possible wrong) data from "blockheader" in filler;
overwriteBlockHeader(o, current_BlockHeader);
if (o.count("blockHeader"))
{
if (o["blockHeader"].get_obj().size() != 14)
{
BlockInfo tmp = current_BlockHeader;
if (o["blockHeader"].get_obj().count("parentHash"))
tmp.parentHash = h256(o["blockHeader"].get_obj()["parentHash"].get_str());
if (o["blockHeader"].get_obj().count("uncleHash"))
tmp.sha3Uncles = h256(o["blockHeader"].get_obj()["uncleHash"].get_str());
if (o["blockHeader"].get_obj().count("coinbase"))
tmp.coinbaseAddress = Address(o["blockHeader"].get_obj()["coinbase"].get_str());
if (o["blockHeader"].get_obj().count("stateRoot"))
tmp.stateRoot = h256(o["blockHeader"].get_obj()["stateRoot"].get_str());
if (o["blockHeader"].get_obj().count("transactionsTrie"))
tmp.transactionsRoot = h256(o["blockHeader"].get_obj()["transactionsTrie"].get_str());
if (o["blockHeader"].get_obj().count("receiptTrie"))
tmp.receiptsRoot = h256(o["blockHeader"].get_obj()["receiptTrie"].get_str());
if (o["blockHeader"].get_obj().count("bloom"))
tmp.logBloom = LogBloom(o["blockHeader"].get_obj()["bloom"].get_str());
if (o["blockHeader"].get_obj().count("difficulty"))
tmp.difficulty = toInt(o["blockHeader"].get_obj()["difficulty"]);
if (o["blockHeader"].get_obj().count("number"))
tmp.number = toInt(o["blockHeader"].get_obj()["number"]);
if (o["blockHeader"].get_obj().count("gasLimit"))
tmp.gasLimit = toInt(o["blockHeader"].get_obj()["gasLimit"]);
if (o["blockHeader"].get_obj().count("gasUsed"))
tmp.gasUsed = toInt(o["blockHeader"].get_obj()["gasUsed"]);
if (o["blockHeader"].get_obj().count("timestamp"))
tmp.timestamp = toInt(o["blockHeader"].get_obj()["timestamp"]);
if (o["blockHeader"].get_obj().count("extraData"))
tmp.extraData = importByteArray(o["blockHeader"].get_obj()["extraData"].get_str());
// find new valid nonce
if (tmp != current_BlockHeader)
{
current_BlockHeader = tmp;
cout << "new header!\n";
ProofOfWork pow;
MineInfo ret;
while (!ProofOfWork::verify(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.nonce, current_BlockHeader.difficulty))
tie(ret, current_BlockHeader.nonce) = pow.mine(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.difficulty, 10000, true, true);
}
}
else
{
// take the blockheader as is
const bytes c_blockRLP = createBlockRLPFromFields(o["blockHeader"].get_obj());
const RLP c_bRLP(c_blockRLP);
current_BlockHeader.populateFromHeader(c_bRLP, false);
}
}
// write block header // write block header
mObject oBlockHeader; mObject oBlockHeader;
oBlockHeader["parentHash"] = toString(current_BlockHeader.parentHash); oBlockHeader["parentHash"] = toString(current_BlockHeader.parentHash);
oBlockHeader["uncleHash"] = toString(current_BlockHeader.sha3Uncles); oBlockHeader["uncleHash"] = toString(current_BlockHeader.sha3Uncles);
@ -423,7 +426,6 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin)
BOOST_CHECK_MESSAGE(blockHeaderFromFields == blockFromRlp, "However, blockHeaderFromFields != blockFromRlp!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields == blockFromRlp, "However, blockHeaderFromFields != blockFromRlp!");
//Check transaction list //Check transaction list
Transactions txsFromField; Transactions txsFromField;
for (auto const& txObj: o["transactions"].get_array()) for (auto const& txObj: o["transactions"].get_array())
@ -511,9 +513,9 @@ BOOST_AUTO_TEST_CASE(blForkBlocks)
dev::test::executeTests("blForkBlocks", "/BlockTests", dev::test::doBlockTests); dev::test::executeTests("blForkBlocks", "/BlockTests", dev::test::doBlockTests);
} }
BOOST_AUTO_TEST_CASE(userDefinedFileBl) BOOST_AUTO_TEST_CASE(userDefinedFile)
{ {
dev::test::userDefinedTest("--bltest", dev::test::doBlockTests); dev::test::userDefinedTest("--singletest", dev::test::doBlockTests);
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

View File

@ -23,8 +23,10 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <chrono> #include <chrono>
#include <boost/random.hpp> #include <boost/random.hpp>
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
#pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-parameter"
#include <json_spirit/json_spirit.h> #include <json_spirit/json_spirit.h>
#include <json_spirit/json_spirit_reader_template.h> #include <json_spirit/json_spirit_reader_template.h>

View File

@ -22,6 +22,7 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include <libethereum/Client.h> #include <libethereum/Client.h>
#include <libethereum/CanonBlockChain.h> #include <libethereum/CanonBlockChain.h>
#include <libethereum/EthereumHost.h> #include <libethereum/EthereumHost.h>

View File

@ -22,10 +22,12 @@
#include <fstream> #include <fstream>
#include <random> #include <random>
#include <boost/test/unit_test.hpp>
#include "JsonSpiritHeaders.h" #include "JsonSpiritHeaders.h"
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include <libethereum/CanonBlockChain.h> #include <libethereum/CanonBlockChain.h>
#include <boost/test/unit_test.hpp>
#include "TestHelper.h" #include "TestHelper.h"
using namespace std; using namespace std;
@ -40,7 +42,7 @@ BOOST_AUTO_TEST_CASE(emptySHA3Types)
{ {
h256 emptyListSHA3(fromHex("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347")); h256 emptyListSHA3(fromHex("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"));
BOOST_REQUIRE_EQUAL(emptyListSHA3, EmptyListSHA3); BOOST_REQUIRE_EQUAL(emptyListSHA3, EmptyListSHA3);
h256 emptySHA3(fromHex("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")); h256 emptySHA3(fromHex("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
BOOST_REQUIRE_EQUAL(emptySHA3, EmptySHA3); BOOST_REQUIRE_EQUAL(emptySHA3, EmptySHA3);
} }

View File

@ -21,11 +21,13 @@
*/ */
#include <fstream> #include <fstream>
#include <boost/test/unit_test.hpp>
#include "JsonSpiritHeaders.h" #include "JsonSpiritHeaders.h"
#include <libdevcore/Log.h> #include <libdevcore/Log.h>
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include <libdevcrypto/TrieCommon.h> #include <libdevcrypto/TrieCommon.h>
#include <boost/test/unit_test.hpp>
#include "TestHelper.h" #include "TestHelper.h"
using namespace std; using namespace std;
@ -53,8 +55,8 @@ BOOST_AUTO_TEST_CASE(hexPrefix_test)
for (auto& i: o["seq"].get_array()) for (auto& i: o["seq"].get_array())
v.push_back((byte)i.get_int()); v.push_back((byte)i.get_int());
auto e = hexPrefixEncode(v, o["term"].get_bool()); auto e = hexPrefixEncode(v, o["term"].get_bool());
BOOST_REQUIRE( ! o["out"].is_null() ); BOOST_REQUIRE( ! o["out"].is_null() );
BOOST_CHECK( o["out"].get_str() == toHex(e) ); BOOST_CHECK( o["out"].get_str() == toHex(e) );
} }
} }

37
net.cpp
View File

@ -20,6 +20,7 @@
*/ */
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <libdevcore/Worker.h> #include <libdevcore/Worker.h>
#include <libdevcrypto/Common.h> #include <libdevcrypto/Common.h>
#include <libp2p/UDP.h> #include <libp2p/UDP.h>
@ -43,7 +44,7 @@ public:
void start() { startWorking(); } void start() { startWorking(); }
void doWork() { m_io.run(); } void doWork() { m_io.run(); }
void doneWorking() { m_io.reset(); m_io.poll(); m_io.reset(); } void doneWorking() { m_io.reset(); m_io.poll(); m_io.reset(); }
protected: protected:
ba::io_service m_io; ba::io_service m_io;
}; };
@ -52,23 +53,23 @@ struct TestNodeTable: public NodeTable
{ {
/// Constructor /// Constructor
TestNodeTable(ba::io_service& _io, KeyPair _alias, uint16_t _port = 30300): NodeTable(_io, _alias, _port) {} TestNodeTable(ba::io_service& _io, KeyPair _alias, uint16_t _port = 30300): NodeTable(_io, _alias, _port) {}
static std::vector<std::pair<KeyPair,unsigned>> createTestNodes(unsigned _count) static std::vector<std::pair<KeyPair,unsigned>> createTestNodes(unsigned _count)
{ {
std::vector<std::pair<KeyPair,unsigned>> ret; std::vector<std::pair<KeyPair,unsigned>> ret;
asserts(_count < 1000); asserts(_count < 1000);
static uint16_t s_basePort = 30500; static uint16_t s_basePort = 30500;
ret.clear(); ret.clear();
for (unsigned i = 0; i < _count; i++) for (unsigned i = 0; i < _count; i++)
{ {
KeyPair k = KeyPair::create(); KeyPair k = KeyPair::create();
ret.push_back(make_pair(k,s_basePort+i)); ret.push_back(make_pair(k,s_basePort+i));
} }
return std::move(ret); return std::move(ret);
} }
void pingTestNodes(std::vector<std::pair<KeyPair,unsigned>> const& _testNodes) void pingTestNodes(std::vector<std::pair<KeyPair,unsigned>> const& _testNodes)
{ {
bi::address ourIp = bi::address::from_string("127.0.0.1"); bi::address ourIp = bi::address::from_string("127.0.0.1");
@ -78,7 +79,7 @@ struct TestNodeTable: public NodeTable
this_thread::sleep_for(chrono::milliseconds(2)); this_thread::sleep_for(chrono::milliseconds(2));
} }
} }
void populateTestNodes(std::vector<std::pair<KeyPair,unsigned>> const& _testNodes, size_t _count = 0) void populateTestNodes(std::vector<std::pair<KeyPair,unsigned>> const& _testNodes, size_t _count = 0)
{ {
if (!_count) if (!_count)
@ -91,7 +92,7 @@ struct TestNodeTable: public NodeTable
else else
break; break;
} }
void reset() void reset()
{ {
Guard l(x_state); Guard l(x_state);
@ -108,13 +109,13 @@ struct TestNodeTableHost: public TestHost
~TestNodeTableHost() { m_io.stop(); stopWorking(); } ~TestNodeTableHost() { m_io.stop(); stopWorking(); }
void setup() { for (auto n: testNodes) nodeTables.push_back(make_shared<TestNodeTable>(m_io,n.first,n.second)); } void setup() { for (auto n: testNodes) nodeTables.push_back(make_shared<TestNodeTable>(m_io,n.first,n.second)); }
void pingAll() { for (auto& t: nodeTables) t->pingTestNodes(testNodes); } void pingAll() { for (auto& t: nodeTables) t->pingTestNodes(testNodes); }
void populateAll(size_t _count = 0) { for (auto& t: nodeTables) t->populateTestNodes(testNodes, _count); } void populateAll(size_t _count = 0) { for (auto& t: nodeTables) t->populateTestNodes(testNodes, _count); }
void populate(size_t _count = 0) { nodeTable->populateTestNodes(testNodes, _count); } void populate(size_t _count = 0) { nodeTable->populateTestNodes(testNodes, _count); }
KeyPair m_alias; KeyPair m_alias;
shared_ptr<TestNodeTable> nodeTable; shared_ptr<TestNodeTable> nodeTable;
std::vector<std::pair<KeyPair,unsigned>> testNodes; // keypair and port std::vector<std::pair<KeyPair,unsigned>> testNodes; // keypair and port
@ -130,7 +131,7 @@ public:
void onReceived(UDPSocketFace*, bi::udp::endpoint const&, bytesConstRef _packet) { if (_packet.toString() == "AAAA") success = true; } void onReceived(UDPSocketFace*, bi::udp::endpoint const&, bytesConstRef _packet) { if (_packet.toString() == "AAAA") success = true; }
shared_ptr<UDPSocket<TestUDPSocket, 1024>> m_socket; shared_ptr<UDPSocket<TestUDPSocket, 1024>> m_socket;
bool success = false; bool success = false;
}; };
@ -139,7 +140,7 @@ BOOST_AUTO_TEST_CASE(test_neighbours_packet)
KeyPair k = KeyPair::create(); KeyPair k = KeyPair::create();
std::vector<std::pair<KeyPair,unsigned>> testNodes(TestNodeTable::createTestNodes(16)); std::vector<std::pair<KeyPair,unsigned>> testNodes(TestNodeTable::createTestNodes(16));
bi::udp::endpoint to(boost::asio::ip::address::from_string("127.0.0.1"), 30000); bi::udp::endpoint to(boost::asio::ip::address::from_string("127.0.0.1"), 30000);
Neighbours out(to); Neighbours out(to);
for (auto n: testNodes) for (auto n: testNodes)
{ {
@ -186,25 +187,25 @@ BOOST_AUTO_TEST_CASE(kademlia)
node.setup(); node.setup();
node.populate(); node.populate();
clog << "NodeTable:\n" << *node.nodeTable.get() << endl; clog << "NodeTable:\n" << *node.nodeTable.get() << endl;
node.populateAll(); node.populateAll();
clog << "NodeTable:\n" << *node.nodeTable.get() << endl; clog << "NodeTable:\n" << *node.nodeTable.get() << endl;
auto nodes = node.nodeTable->nodes(); auto nodes = node.nodeTable->nodes();
nodes.sort(); nodes.sort();
node.nodeTable->reset(); node.nodeTable->reset();
clog << "NodeTable:\n" << *node.nodeTable.get() << endl; clog << "NodeTable:\n" << *node.nodeTable.get() << endl;
node.populate(1); node.populate(1);
clog << "NodeTable:\n" << *node.nodeTable.get() << endl; clog << "NodeTable:\n" << *node.nodeTable.get() << endl;
node.nodeTable->discover(); node.nodeTable->discover();
this_thread::sleep_for(chrono::milliseconds(2000)); this_thread::sleep_for(chrono::milliseconds(2000));
clog << "NodeTable:\n" << *node.nodeTable.get() << endl; clog << "NodeTable:\n" << *node.nodeTable.get() << endl;
BOOST_REQUIRE_EQUAL(node.nodeTable->count(), 8); BOOST_REQUIRE_EQUAL(node.nodeTable->count(), 8);
auto netNodes = node.nodeTable->nodes(); auto netNodes = node.nodeTable->nodes();
netNodes.sort(); netNodes.sort();

148
rlp.cpp
View File

@ -22,11 +22,13 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <boost/test/unit_test.hpp>
#include <libdevcore/Log.h> #include <libdevcore/Log.h>
#include <libdevcore/RLP.h> #include <libdevcore/RLP.h>
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include <boost/test/unit_test.hpp>
#include <algorithm> #include <algorithm>
#include "JsonSpiritHeaders.h" #include "JsonSpiritHeaders.h"
#include "TestHelper.h" #include "TestHelper.h"
@ -66,76 +68,76 @@ namespace dev
testPath += "/BasicTests"; testPath += "/BasicTests";
string s = asString(contents(testPath + "/rlptest.json")); string s = asString(contents(testPath + "/rlptest.json"));
BOOST_REQUIRE_MESSAGE( s.length() > 0, BOOST_REQUIRE_MESSAGE( s.length() > 0,
"Contents of 'rlptest.json' is empty. Have you cloned the 'tests' repo branch develop?"); "Contents of 'rlptest.json' is empty. Have you cloned the 'tests' repo branch develop?");
js::read_string(s, v); js::read_string(s, v);
} }
static void checkRLPTestCase(js::mObject& o) static void checkRLPTestCase(js::mObject& o)
{ {
BOOST_REQUIRE( o.count("in") > 0 ); BOOST_REQUIRE( o.count("in") > 0 );
BOOST_REQUIRE( o.count("out") > 0 ); BOOST_REQUIRE( o.count("out") > 0 );
BOOST_REQUIRE(!o["out"].is_null()); BOOST_REQUIRE(!o["out"].is_null());
} }
static void checkRLPAgainstJson(js::mValue& v, RLP& u) static void checkRLPAgainstJson(js::mValue& v, RLP& u)
{ {
if ( v.type() == js::str_type ) if ( v.type() == js::str_type )
{ {
const std::string& expectedText = v.get_str(); const std::string& expectedText = v.get_str();
if ( !expectedText.empty() && expectedText.front() == '#' ) if ( !expectedText.empty() && expectedText.front() == '#' )
{ {
// Deal with bigint instead of a raw string // Deal with bigint instead of a raw string
std::string bigIntStr = expectedText.substr(1,expectedText.length()-1); std::string bigIntStr = expectedText.substr(1,expectedText.length()-1);
std::stringstream bintStream(bigIntStr); std::stringstream bintStream(bigIntStr);
bigint val; bigint val;
bintStream >> val; bintStream >> val;
BOOST_CHECK( !u.isList() ); BOOST_CHECK( !u.isList() );
BOOST_CHECK( !u.isNull() ); BOOST_CHECK( !u.isNull() );
BOOST_CHECK( u ); // operator bool() BOOST_CHECK( u ); // operator bool()
BOOST_CHECK(u == val); BOOST_CHECK(u == val);
}
else
{
BOOST_CHECK( !u.isList() );
BOOST_CHECK( !u.isNull() );
BOOST_CHECK( u.isData() );
BOOST_CHECK( u );
BOOST_CHECK( u.size() == expectedText.length() );
BOOST_CHECK(u == expectedText);
} }
} else
else if ( v.type() == js::int_type ) {
{ BOOST_CHECK( !u.isList() );
const int expectedValue = v.get_int(); BOOST_CHECK( !u.isNull() );
BOOST_CHECK( u.isInt() ); BOOST_CHECK( u.isData() );
BOOST_CHECK( !u.isList() ); BOOST_CHECK( u );
BOOST_CHECK( u.size() == expectedText.length() );
BOOST_CHECK(u == expectedText);
}
}
else if ( v.type() == js::int_type )
{
const int expectedValue = v.get_int();
BOOST_CHECK( u.isInt() );
BOOST_CHECK( !u.isList() );
BOOST_CHECK( !u.isNull() ); BOOST_CHECK( !u.isNull() );
BOOST_CHECK( u ); // operator bool() BOOST_CHECK( u ); // operator bool()
BOOST_CHECK(u == expectedValue); BOOST_CHECK(u == expectedValue);
} }
else if ( v.type() == js::array_type ) else if ( v.type() == js::array_type )
{ {
BOOST_CHECK( u.isList() ); BOOST_CHECK( u.isList() );
BOOST_CHECK( !u.isInt() ); BOOST_CHECK( !u.isInt() );
BOOST_CHECK( !u.isData() ); BOOST_CHECK( !u.isData() );
js::mArray& arr = v.get_array(); js::mArray& arr = v.get_array();
BOOST_CHECK( u.itemCount() == arr.size() ); BOOST_CHECK( u.itemCount() == arr.size() );
unsigned i; unsigned i;
for( i = 0; i < arr.size(); i++ ) for( i = 0; i < arr.size(); i++ )
{ {
RLP item = u[i]; RLP item = u[i];
checkRLPAgainstJson(arr[i], item); checkRLPAgainstJson(arr[i], item);
} }
} }
else else
{ {
BOOST_ERROR("Invalid Javascript object!"); BOOST_ERROR("Invalid Javascript object!");
} }
} }
} }
} }
BOOST_AUTO_TEST_SUITE(BasicTests) BOOST_AUTO_TEST_SUITE(BasicTests)
@ -154,30 +156,30 @@ BOOST_AUTO_TEST_CASE(rlp_encoding_test)
RLPStream s; RLPStream s;
dev::test::buildRLP(o["in"], s); dev::test::buildRLP(o["in"], s);
std::string expectedText(o["out"].get_str()); std::string expectedText(o["out"].get_str());
std::transform(expectedText.begin(), expectedText.end(), expectedText.begin(), ::tolower ); std::transform(expectedText.begin(), expectedText.end(), expectedText.begin(), ::tolower );
const std::string& computedText = toHex(s.out()); const std::string& computedText = toHex(s.out());
std::stringstream msg; std::stringstream msg;
msg << "Encoding Failed: expected: " << expectedText << std::endl; msg << "Encoding Failed: expected: " << expectedText << std::endl;
msg << " But Computed: " << computedText; msg << " But Computed: " << computedText;
BOOST_CHECK_MESSAGE( BOOST_CHECK_MESSAGE(
expectedText == computedText, expectedText == computedText,
msg.str() msg.str()
); );
} }
} }
BOOST_AUTO_TEST_CASE(rlp_decoding_test) BOOST_AUTO_TEST_CASE(rlp_decoding_test)
{ {
cnote << "Testing RLP decoding..."; cnote << "Testing RLP decoding...";
// Uses the same test cases as encoding but in reverse. // Uses the same test cases as encoding but in reverse.
// We read into the string of hex values, convert to bytes, // We read into the string of hex values, convert to bytes,
// and then compare the output structure to the json of the // and then compare the output structure to the json of the
// input object. // input object.
js::mValue v; js::mValue v;
dev::test::getRLPTestCases(v); dev::test::getRLPTestCases(v);
for (auto& i: v.get_obj()) for (auto& i: v.get_obj())
@ -185,11 +187,11 @@ BOOST_AUTO_TEST_CASE(rlp_decoding_test)
js::mObject& o = i.second.get_obj(); js::mObject& o = i.second.get_obj();
cnote << i.first; cnote << i.first;
dev::test::checkRLPTestCase(o); dev::test::checkRLPTestCase(o);
js::mValue& inputData = o["in"];
bytes payloadToDecode = fromHex(o["out"].get_str());
RLP payload(payloadToDecode); js::mValue& inputData = o["in"];
bytes payloadToDecode = fromHex(o["out"].get_str());
RLP payload(payloadToDecode);
dev::test::checkRLPAgainstJson(inputData, payload); dev::test::checkRLPAgainstJson(inputData, payload);

View File

@ -22,6 +22,7 @@
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include "JsonSpiritHeaders.h" #include "JsonSpiritHeaders.h"
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include <libethereum/CanonBlockChain.h> #include <libethereum/CanonBlockChain.h>
@ -241,7 +242,7 @@ BOOST_AUTO_TEST_CASE(stCreateTest)
BOOST_AUTO_TEST_CASE(userDefinedFileState) BOOST_AUTO_TEST_CASE(userDefinedFileState)
{ {
dev::test::userDefinedTest("--statetest", dev::test::doStateTests); dev::test::userDefinedTest("--singletest", dev::test::doStateTests);
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

View File

@ -104,7 +104,7 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
BOOST_AUTO_TEST_SUITE(TransactionTests) BOOST_AUTO_TEST_SUITE(TransactionTests)
BOOST_AUTO_TEST_CASE(TransactionTest) BOOST_AUTO_TEST_CASE(ttTransactionTest)
{ {
dev::test::executeTests("ttTransactionTest", "/TransactionTests", dev::test::doTransactionTests); dev::test::executeTests("ttTransactionTest", "/TransactionTests", dev::test::doTransactionTests);
} }
@ -167,9 +167,9 @@ BOOST_AUTO_TEST_CASE(ttCreateTest)
} }
} }
BOOST_AUTO_TEST_CASE(userDefinedFileTT) BOOST_AUTO_TEST_CASE(userDefinedFile)
{ {
dev::test::userDefinedTest("--ttTest", dev::test::doTransactionTests); dev::test::userDefinedTest("--singletest", dev::test::doTransactionTests);
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

View File

@ -22,12 +22,14 @@
#include <fstream> #include <fstream>
#include <random> #include <random>
#include <boost/test/unit_test.hpp>
#include "JsonSpiritHeaders.h" #include "JsonSpiritHeaders.h"
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include <libdevcrypto/TrieDB.h> #include <libdevcrypto/TrieDB.h>
#include "TrieHash.h" #include "TrieHash.h"
#include "MemTrie.h" #include "MemTrie.h"
#include <boost/test/unit_test.hpp>
#include "TestHelper.h" #include "TestHelper.h"
using namespace std; using namespace std;

View File

@ -59,6 +59,21 @@
} }
}, },
"WrongVRSTestVOverflow" : {
"transaction" :
{
"data" : "",
"gasLimit" : "2000",
"gasPrice" : "1",
"nonce" : "0",
"to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10",
"v" : "310",
"r" : "0x98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a",
"s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3"
}
},
"WrongVRSTestIncorrectSize" : { "WrongVRSTestIncorrectSize" : {
"transaction" : "transaction" :
{ {
@ -91,6 +106,22 @@
} }
}, },
"DataTest" : {
"transaction" :
{
"data" : "0x0358ac39584bc98a7c979f984b03",
"gasLimit" : "850",
"gasPrice" : "1",
"nonce" : "0",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "10",
"v" : "27",
"r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353",
"s" : "secretkey 45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804"
}
},
"TransactionWithTooManyRLPElements" : { "TransactionWithTooManyRLPElements" : {
"transaction" : "transaction" :
{ {

View File

@ -22,6 +22,7 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include <libethereum/Client.h> #include <libethereum/Client.h>
#include <libethereum/CanonBlockChain.h> #include <libethereum/CanonBlockChain.h>
#include <libethereum/EthereumHost.h> #include <libethereum/EthereumHost.h>

10
vm.cpp
View File

@ -21,7 +21,9 @@
*/ */
#include <chrono> #include <chrono>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <libethereum/Executive.h> #include <libethereum/Executive.h>
#include <libevm/VMFactory.h> #include <libevm/VMFactory.h>
#include "vm.h" #include "vm.h"
@ -286,7 +288,7 @@ eth::OnOpFunc FakeExtVM::simpleTrace()
/*add the storage*/ /*add the storage*/
Object storage; Object storage;
for (auto const& i: std::get<2>(ext.addresses.find(ext.myAddress)->second)) for (auto const& i: std::get<2>(ext.addresses.find(ext.myAddress)->second))
storage.push_back(Pair( (string)i.first , (string)i.second)); storage.push_back(Pair( (string)i.first , (string)i.second));
/*add all the other details*/ /*add all the other details*/
o_step.push_back(Pair("storage", storage)); o_step.push_back(Pair("storage", storage));
@ -365,7 +367,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
auto argc = boost::unit_test::framework::master_test_suite().argc; auto argc = boost::unit_test::framework::master_test_suite().argc;
auto argv = boost::unit_test::framework::master_test_suite().argv; auto argv = boost::unit_test::framework::master_test_suite().argv;
for (auto i = 0; i < argc; ++i) for (auto i = 0; i < argc; ++i)
{ {
if (std::string(argv[i]) == "--show-times") if (std::string(argv[i]) == "--show-times")
{ {
auto testDuration = endTime - startTime; auto testDuration = endTime - startTime;
@ -592,9 +594,9 @@ BOOST_AUTO_TEST_CASE(vmRandom)
} }
} }
BOOST_AUTO_TEST_CASE(userDefinedFileVM) BOOST_AUTO_TEST_CASE(userDefinedFile)
{ {
dev::test::userDefinedTest("--vmtest", dev::test::doVMTests); dev::test::userDefinedTest("--singletest", dev::test::doVMTests);
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

2
vm.h
View File

@ -25,7 +25,9 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
#include <fstream> #include <fstream>
#include <cstdint> #include <cstdint>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <json_spirit/json_spirit.h> #include <json_spirit/json_spirit.h>
#include <libdevcore/Log.h> #include <libdevcore/Log.h>
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>

View File

@ -19,7 +19,9 @@
* @date 2014 * @date 2014
*/ */
#include <functional> #include <functional>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <libp2p/Host.h> #include <libp2p/Host.h>
#include <libwhisper/WhisperPeer.h> #include <libwhisper/WhisperPeer.h>
#include <libwhisper/WhisperHost.h> #include <libwhisper/WhisperHost.h>
@ -40,10 +42,10 @@ BOOST_AUTO_TEST_CASE(topic)
Host host1("Test", NetworkPreferences(30303, "127.0.0.1", false, true)); Host host1("Test", NetworkPreferences(30303, "127.0.0.1", false, true));
auto whost1 = host1.registerCapability(new WhisperHost()); auto whost1 = host1.registerCapability(new WhisperHost());
host1.start(); host1.start();
while (!host1.isStarted()) while (!host1.isStarted())
this_thread::sleep_for(chrono::milliseconds(2)); this_thread::sleep_for(chrono::milliseconds(2));
bool started = false; bool started = false;
unsigned result = 0; unsigned result = 0;
std::thread listener([&]() std::thread listener([&]()
@ -71,19 +73,19 @@ BOOST_AUTO_TEST_CASE(topic)
} }
this_thread::sleep_for(chrono::milliseconds(50)); this_thread::sleep_for(chrono::milliseconds(50));
} }
}); });
Host host2("Test", NetworkPreferences(30300, "127.0.0.1", false, true)); Host host2("Test", NetworkPreferences(30300, "127.0.0.1", false, true));
auto whost2 = host2.registerCapability(new WhisperHost()); auto whost2 = host2.registerCapability(new WhisperHost());
host2.start(); host2.start();
while (!host2.isStarted()) while (!host2.isStarted())
this_thread::sleep_for(chrono::milliseconds(2)); this_thread::sleep_for(chrono::milliseconds(2));
this_thread::sleep_for(chrono::milliseconds(100)); this_thread::sleep_for(chrono::milliseconds(100));
host2.addNode(host1.id(), "127.0.0.1", 30303, 30303); host2.addNode(host1.id(), "127.0.0.1", 30303, 30303);
this_thread::sleep_for(chrono::milliseconds(500)); this_thread::sleep_for(chrono::milliseconds(500));
while (!started) while (!started)
@ -107,7 +109,7 @@ BOOST_AUTO_TEST_CASE(forwarding)
cnote << "Testing Whisper forwarding..."; cnote << "Testing Whisper forwarding...";
auto oldLogVerbosity = g_logVerbosity; auto oldLogVerbosity = g_logVerbosity;
g_logVerbosity = 0; g_logVerbosity = 0;
// Host must be configured not to share peers. // Host must be configured not to share peers.
Host host1("Listner", NetworkPreferences(30303, "", false, true)); Host host1("Listner", NetworkPreferences(30303, "", false, true));
host1.setIdealPeerCount(0); host1.setIdealPeerCount(0);
@ -115,7 +117,7 @@ BOOST_AUTO_TEST_CASE(forwarding)
host1.start(); host1.start();
while (!host1.isStarted()) while (!host1.isStarted())
this_thread::sleep_for(chrono::milliseconds(2)); this_thread::sleep_for(chrono::milliseconds(2));
unsigned result = 0; unsigned result = 0;
bool done = false; bool done = false;
@ -142,7 +144,7 @@ BOOST_AUTO_TEST_CASE(forwarding)
} }
}); });
// Host must be configured not to share peers. // Host must be configured not to share peers.
Host host2("Forwarder", NetworkPreferences(30305, "", false, true)); Host host2("Forwarder", NetworkPreferences(30305, "", false, true));
host2.setIdealPeerCount(1); host2.setIdealPeerCount(1);
@ -150,7 +152,7 @@ BOOST_AUTO_TEST_CASE(forwarding)
host2.start(); host2.start();
while (!host2.isStarted()) while (!host2.isStarted())
this_thread::sleep_for(chrono::milliseconds(2)); this_thread::sleep_for(chrono::milliseconds(2));
Public fwderid; Public fwderid;
bool startedForwarder = false; bool startedForwarder = false;
std::thread forwarder([&]() std::thread forwarder([&]()
@ -210,7 +212,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding)
unsigned result = 0; unsigned result = 0;
bool done = false; bool done = false;
// Host must be configured not to share peers. // Host must be configured not to share peers.
Host host1("Forwarder", NetworkPreferences(30305, "", false, true)); Host host1("Forwarder", NetworkPreferences(30305, "", false, true));
host1.setIdealPeerCount(1); host1.setIdealPeerCount(1);
@ -223,7 +225,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding)
std::thread forwarder([&]() std::thread forwarder([&]()
{ {
setThreadName("forwarder"); setThreadName("forwarder");
this_thread::sleep_for(chrono::milliseconds(500)); this_thread::sleep_for(chrono::milliseconds(500));
// ph.addNode("127.0.0.1", 30303, 30303); // ph.addNode("127.0.0.1", 30303, 30303);
@ -245,7 +247,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding)
while (!startedForwarder) while (!startedForwarder)
this_thread::sleep_for(chrono::milliseconds(2)); this_thread::sleep_for(chrono::milliseconds(2));
{ {
Host host2("Sender", NetworkPreferences(30300, "", false, true)); Host host2("Sender", NetworkPreferences(30300, "", false, true));
host2.setIdealPeerCount(1); host2.setIdealPeerCount(1);
@ -257,7 +259,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding)
while (!host2.peerCount()) while (!host2.peerCount())
this_thread::sleep_for(chrono::milliseconds(5)); this_thread::sleep_for(chrono::milliseconds(5));
KeyPair us = KeyPair::create(); KeyPair us = KeyPair::create();
whost2->post(us.sec(), RLPStream().append(1).out(), BuildTopic("test")); whost2->post(us.sec(), RLPStream().append(1).out(), BuildTopic("test"));
this_thread::sleep_for(chrono::milliseconds(250)); this_thread::sleep_for(chrono::milliseconds(250));