Browse Source

Merge branch 'develop' into netFix

cl-refactor
subtly 10 years ago
parent
commit
a5254ad92c
  1. 2
      CMakeLists.txt
  2. 5
      alethzero/MainWin.cpp
  3. 2
      alethzero/NatspecHandler.cpp
  4. 8
      eth/main.cpp
  5. 20
      libdevcore/CommonData.h
  6. 2
      libdevcore/CommonIO.cpp
  7. 9
      libdevcore/FixedHash.h
  8. 2
      libdevcore/TransientDirectory.cpp
  9. 4
      libdevcrypto/SecretStore.cpp
  10. 3
      libdevcrypto/SecretStore.h
  11. 12
      libethcore/Common.h
  12. 7
      libethcore/KeyManager.cpp
  13. 2
      libethereum/BlockChain.cpp
  14. 4
      libethereum/State.cpp
  15. 4
      libethereum/Utility.cpp
  16. 4
      libnatspec/NatspecExpressionEvaluator.h
  17. 2
      libp2p/Network.cpp
  18. 2
      libweb3jsonrpc/WebThreeStubServer.cpp
  19. 2
      libwhisper/WhisperDB.cpp
  20. 18
      secp256k1/libsecp256k1-config.h
  21. 283
      test/libwhisper/shhrpc.cpp
  22. 10
      test/libwhisper/whisperDB.cpp
  23. 3
      test/libwhisper/whisperTopic.cpp

2
CMakeLists.txt

@ -1,7 +1,7 @@
# cmake global
cmake_minimum_required(VERSION 2.8.12)
set(PROJECT_VERSION "0.9.39")
set(PROJECT_VERSION "0.9.40")
if (${CMAKE_VERSION} VERSION_GREATER 3.0)
cmake_policy(SET CMP0042 OLD) # fix MACOSX_RPATH
cmake_policy(SET CMP0048 NEW) # allow VERSION argument in project()

5
alethzero/MainWin.cpp

@ -859,9 +859,8 @@ void Main::readSettings(bool _skipGeometry)
{
p->readSettings(s);
});
static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->setAsk(u256(s.value("askPrice", "500000000000").toString().toStdString()));
static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->setBid(u256(s.value("bidPrice", "500000000000").toString().toStdString()));
static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->setAsk(u256(s.value("askPrice", QString::fromStdString(toString(c_defaultGasPrice))).toString().toStdString()));
static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->setBid(u256(s.value("bidPrice", QString::fromStdString(toString(c_defaultGasPrice))).toString().toStdString()));
ui->upnp->setChecked(s.value("upnp", true).toBool());
ui->forcePublicIP->setText(s.value("forceAddress", "").toString());

2
alethzero/NatspecHandler.cpp

@ -38,7 +38,7 @@ NatspecHandler::NatspecHandler()
{
string path = Defaults::dbPath();
fs::create_directories(path);
fs::permissions(path, fs::owner_all);
DEV_IGNORE_EXCEPTIONS(fs::permissions(path, fs::owner_all));
ldb::Options o;
o.create_if_missing = true;
ldb::DB::Open(o, path + "/natspec", &m_db);

8
eth/main.cpp

@ -153,8 +153,8 @@ void help()
/*<< " -B,--block-fees <n> Set the block fee profit in the reference unit e.g. ¢ (default: 15)." << endl
<< " -e,--ether-price <n> Set the ether price in the reference unit e.g. ¢ (default: 30.679)." << endl
<< " -P,--priority <0 - 100> Default % priority of a transaction (default: 50)." << endl*/
<< " --ask <wei> Set the minimum ask gas price under which no transactions will be mined (default 500000000000)." << endl
<< " --bid <wei> Set the bid gas price for to pay for transactions (default 500000000000)." << endl
<< " --ask <wei> Set the minimum ask gas price under which no transactions will be mined (default " << toString(c_defaultGasPrice) << " )." << endl
<< " --bid <wei> Set the bid gas price for to pay for transactions (default " << toString(c_defaultGasPrice) << " )." << endl
<< endl
<< "Client mining:" << endl
<< " -a,--address <addr> Set the coinbase (mining payout) address to addr (default: auto)." << endl
@ -386,8 +386,8 @@ int main(int argc, char** argv)
TransactionPriority priority = TransactionPriority::Medium;
// double etherPrice = 30.679;
// double blockFees = 15.0;
u256 askPrice("500000000000");
u256 bidPrice("500000000000");
u256 askPrice = c_defaultGasPrice;
u256 bidPrice = c_defaultGasPrice;
// javascript console
bool useConsole = false;

20
libdevcore/CommonData.h

@ -349,6 +349,26 @@ std::vector<T> keysOf(std::unordered_map<T, U> const& _m)
return ret;
}
template<class T, class U>
std::vector<U> valuesOf(std::map<T, U> const& _m)
{
std::vector<U> ret;
ret.reserve(_m.size());
for (auto const& i: _m)
ret.push_back(i.second);
return ret;
}
template<class T, class U>
std::vector<U> valuesOf(std::unordered_map<T, U> const& _m)
{
std::vector<U> ret;
ret.reserve(_m.size());
for (auto const& i: _m)
ret.push_back(i.second);
return ret;
}
template <class T, class V>
bool contains(T const& _t, V const& _v)
{

2
libdevcore/CommonIO.cpp

@ -128,7 +128,7 @@ void dev::writeFile(std::string const& _file, bytesConstRef _data, bool _writeDe
s.write(reinterpret_cast<char const*>(_data.data()), _data.size());
if (!s)
BOOST_THROW_EXCEPTION(FileError() << errinfo_comment("Could not write to file: " + _file));
fs::permissions(_file, fs::owner_read|fs::owner_write);
DEV_IGNORE_EXCEPTIONS(fs::permissions(_file, fs::owner_read|fs::owner_write));
}
}

9
libdevcore/FixedHash.h

@ -238,7 +238,14 @@ public:
explicit SecureFixedHash(bytes const* _d, ConstructFromPointerType _t): FixedHash<T>(_d, _t) {}
~SecureFixedHash() { ref().cleanse(); }
SecureFixedHash<T>& operator=(SecureFixedHash<T> const& _c) { ref().cleanse(); FixedHash<T>::operator=(static_cast<FixedHash<T> const&>(_c)); return *this; }
SecureFixedHash<T>& operator=(SecureFixedHash<T> const& _c)
{
if (&_c == this)
return *this;
ref().cleanse();
FixedHash<T>::operator=(static_cast<FixedHash<T> const&>(_c));
return *this;
}
using FixedHash<T>::size;

2
libdevcore/TransientDirectory.cpp

@ -41,7 +41,7 @@ TransientDirectory::TransientDirectory(std::string const& _path):
BOOST_THROW_EXCEPTION(FileError());
fs::create_directories(m_path);
fs::permissions(m_path, fs::owner_all);
DEV_IGNORE_EXCEPTIONS(fs::permissions(m_path, fs::owner_all));
}
TransientDirectory::~TransientDirectory()

4
libdevcrypto/SecretStore.cpp

@ -148,7 +148,7 @@ void SecretStore::save(string const& _keysPath)
{
fs::path p(_keysPath);
fs::create_directories(p);
fs::permissions(p, fs::owner_all);
DEV_IGNORE_EXCEPTIONS(fs::permissions(p, fs::owner_all));
for (auto& k: m_keys)
{
string uuid = toUUID(k.first);
@ -170,7 +170,7 @@ void SecretStore::load(string const& _keysPath)
{
fs::path p(_keysPath);
fs::create_directories(p);
fs::permissions(p, fs::owner_all);
DEV_IGNORE_EXCEPTIONS(fs::permissions(p, fs::owner_all));
for (fs::directory_iterator it(p); it != fs::directory_iterator(); ++it)
if (fs::is_regular_file(it->path()))
readKey(it->path().string(), true);

3
libdevcrypto/SecretStore.h

@ -70,6 +70,9 @@ public:
/// Returns the uuids of all stored keys.
std::vector<h128> keys() const { return keysOf(m_keys); }
/// @returns true iff we have the given key stored.
bool contains(h128 const& _k) const { return m_keys.count(_k); }
/// Clears all cached decrypted keys. The passwords have to be supplied in order to retrieve
/// secrets again after calling this function.
void clearCache() const;

12
libethcore/Common.h

@ -154,9 +154,9 @@ public:
friend class Signal;
public:
~HandlerAux() { if (m_s) m_s->m_fire.erase(m_i); m_s = nullptr; }
~HandlerAux() { if (m_s) m_s->m_fire.erase(m_i); }
void reset() { m_s = nullptr; }
void fire(Args&&... _args) { m_h(std::forward<Args>(_args)...); }
void fire(Args const&... _args) { m_h(_args...); }
private:
HandlerAux(unsigned _i, Signal* _s, Callback const& _h): m_i(_i), m_s(_s), m_h(_h) {}
@ -181,11 +181,11 @@ public:
return h;
}
void operator()(Args&... _args)
void operator()(Args const&... _args)
{
for (auto const& f: m_fire)
if (auto h = f.second.lock())
h->fire(std::forward<Args>(_args)...);
for (auto const& f: valuesOf(m_fire))
if (auto h = f.lock())
h->fire(_args...);
}
private:

7
libethcore/KeyManager.cpp

@ -95,8 +95,11 @@ bool KeyManager::load(string const& _pass)
{
h128 uuid(i[1]);
Address addr(i[0]);
m_addrLookup[addr] = uuid;
m_keyInfo[uuid] = KeyInfo(h256(i[2]), string(i[3]));
if (m_store.contains(uuid))
{
m_addrLookup[addr] = uuid;
m_keyInfo[uuid] = KeyInfo(h256(i[2]), string(i[3]));
}
// cdebug << toString(addr) << toString(uuid) << toString((h256)i[2]) << (string)i[3];
}

2
libethereum/BlockChain.cpp

@ -180,7 +180,7 @@ unsigned BlockChain::openDatabase(std::string const& _path, WithExisting _we)
string extrasPath = chainPath + "/" + toString(c_databaseVersion);
fs::create_directories(extrasPath);
fs::permissions(extrasPath, fs::owner_all);
DEV_IGNORE_EXCEPTIONS(fs::permissions(extrasPath, fs::owner_all));
bytes status = contents(extrasPath + "/minor");
unsigned lastMinor = c_minorProtocolVersion;

4
libethereum/State.cpp

@ -47,8 +47,6 @@ namespace fs = boost::filesystem;
#define ctrace clog(StateTrace)
#define ETH_TIMED_ENACTMENTS 0
static const unsigned c_maxSyncTransactions = 256;
const char* StateSafeExceptions::name() { return EthViolet "" EthBlue ""; }
const char* StateDetail::name() { return EthViolet "" EthWhite ""; }
const char* StateTrace::name() { return EthViolet "" EthGray ""; }
@ -85,7 +83,7 @@ OverlayDB State::openDB(std::string const& _basePath, h256 const& _genesisHash,
path += "/" + toHex(_genesisHash.ref().cropped(0, 4)) + "/" + toString(c_databaseVersion);
boost::filesystem::create_directories(path);
fs::permissions(path, fs::owner_all);
DEV_IGNORE_EXCEPTIONS(fs::permissions(path, fs::owner_all));
ldb::Options o;
o.max_open_files = 256;

4
libethereum/Utility.cpp

@ -114,13 +114,13 @@ void dev::eth::upgradeDatabase(std::string const& _basePath, h256 const& _genesi
if (!fs::exists(chainPath + "/blocks"))
{
fs::create_directories(chainPath);
fs::permissions(chainPath, fs::owner_all);
DEV_IGNORE_EXCEPTIONS(fs::permissions(chainPath, fs::owner_all));
fs::rename(path + "/blocks", chainPath + "/blocks");
if (!fs::exists(extrasPath + "/extras"))
{
fs::create_directories(extrasPath);
fs::permissions(extrasPath, fs::owner_all);
DEV_IGNORE_EXCEPTIONS(fs::permissions(extrasPath, fs::owner_all));
fs::rename(path + "/details", extrasPath + "/extras");
fs::rename(path + "/state", extrasPath + "/state");
writeFile(extrasPath + "/minor", rlp(minorProtocolVersion));

4
libnatspec/NatspecExpressionEvaluator.h

@ -20,9 +20,11 @@
*/
#pragma once
#pragma warning(push)
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
#include <QtCore/QtCore>
#include <QtQml/QJSEngine>
#pragma warning(pop)
/**
* Should be used to evaluate natspec expression.

2
libp2p/Network.cpp

@ -216,7 +216,7 @@ bi::tcp::endpoint Network::resolveHost(string const& _addr)
int givenPort;
try
{
givenPort = stoi(split[1]);
givenPort = stoi(split.at(1));
}
catch (...)
{

2
libweb3jsonrpc/WebThreeStubServer.cpp

@ -59,7 +59,7 @@ WebThreeStubServer::WebThreeStubServer(jsonrpc::AbstractServerConnector& _conn,
{
auto path = getDataDir() + "/.web3";
fs::create_directories(path);
fs::permissions(path, fs::owner_all);
DEV_IGNORE_EXCEPTIONS(fs::permissions(path, fs::owner_all));
ldb::Options o;
o.create_if_missing = true;
ldb::DB::Open(o, path, &m_db);

2
libwhisper/WhisperDB.cpp

@ -34,7 +34,7 @@ WhisperDB::WhisperDB(string const& _type)
m_readOptions.verify_checksums = true;
string path = dev::getDataDir("shh");
fs::create_directories(path);
fs::permissions(path, fs::owner_all);
DEV_IGNORE_EXCEPTIONS(fs::permissions(path, fs::owner_all));
path += "/" + _type;
leveldb::Options op;
op.create_if_missing = true;

18
secp256k1/libsecp256k1-config.h

@ -51,7 +51,9 @@
#define HAVE_UNISTD_H 1
/* Define to 1 if the system has the type `__int128'. */
#if defined(__x86_64__) || defined(_M_X64)
#define HAVE___INT128 1
#endif
/* Define to the sub-directory where libtool stores uninstalled libraries. */
#define LT_OBJDIR ".libs/"
@ -86,11 +88,11 @@
/* Define this symbol to use endomorphism optimization */
/* #undef USE_ENDOMORPHISM */
/* Define this symbol to use the FIELD_10X26 implementation */
/* #undef USE_FIELD_10X26 */
/* Define this symbol to use the FIELD_5X52 implementation */
#if defined(__x86_64__) || defined(_M_X64)
#define USE_FIELD_5X52 1
#elif defined(__i386) || defined(_M_IX86)
#define USE_FIELD_10X26 1
#endif
/* Define this symbol to use the native field inverse implementation */
/* #undef USE_FIELD_INV_BUILTIN */
@ -104,11 +106,11 @@
/* Define this symbol to use no num implementation */
/* #undef USE_NUM_NONE */
/* Define this symbol to use the 4x64 scalar implementation */
#if defined(__x86_64__) || defined(_M_X64)
#define USE_SCALAR_4X64 1
/* Define this symbol to use the 8x32 scalar implementation */
/* #undef USE_SCALAR_8X32 */
#elif defined(__i386) || defined(_M_IX86)
#define USE_SCALAR_8X32 1
#endif
/* Define this symbol to use the native scalar inverse implementation */
/* #undef USE_SCALAR_INV_BUILTIN */

283
test/libwhisper/shhrpc.cpp

@ -44,7 +44,9 @@ namespace js = json_spirit;
WebThreeDirect* web3;
unique_ptr<WebThreeStubServer> jsonrpcServer;
unique_ptr<WebThreeStubClient> jsonrpcClient;
static uint16_t const web3port = 30333;
static uint16_t const c_web3port = 30333;
static string const c_version("shhrpc-web3");
static unsigned const c_ttl = 777000;
struct Setup
{
@ -53,13 +55,12 @@ struct Setup
dev::p2p::NodeIPEndpoint::test_allowLocal = true;
static bool setup = false;
if (!setup)
if (!setup && !test::Options::get().nonetwork)
{
setup = true;
NetworkPreferences nprefs(std::string(), web3port, false);
web3 = new WebThreeDirect("shhrpc-web3", "", WithExisting::Trust, {"eth", "shh"}, nprefs);
NetworkPreferences nprefs(std::string(), c_web3port, false);
web3 = new WebThreeDirect(c_version, "", WithExisting::Trust, {"shh"}, nprefs);
web3->setIdealPeerCount(1);
web3->ethereum()->setForceMining(false);
auto server = new jsonrpc::HttpServer(8080);
vector<KeyPair> v;
KeyManager keyMan;
@ -78,11 +79,35 @@ struct Setup
}
};
Json::Value createMessage(string const& _from, string const& _to, string const& _topic = "", string _payload = "")
{
Json::Value msg;
msg["from"] = _from;
msg["to"] = _to;
msg["ttl"] = toJS(c_ttl);
if (_payload.empty())
_payload = string("0x") + h256::random().hex();
msg["payload"] = _payload;
if (!_topic.empty())
{
Json::Value t(Json::arrayValue);
t.append(_topic);
msg["topics"] = t;
}
return msg;
}
BOOST_FIXTURE_TEST_SUITE(shhrpc, Setup)
BOOST_AUTO_TEST_CASE(basic)
{
if (test::Options::get().nonetwork)
return;
cnote << "Testing web3 basic functionality...";
web3->startNetwork();
@ -109,7 +134,7 @@ BOOST_AUTO_TEST_CASE(basic)
for (unsigned i = 0; i < 3000 && (!web3->peerCount() || !host2.peerCount()); i += step)
this_thread::sleep_for(chrono::milliseconds(step));
BOOST_REQUIRE_EQUAL(host2.peerCount(), 1);
BOOST_REQUIRE_EQUAL(host2.peerCount(), 1);
BOOST_REQUIRE_EQUAL(web3->peerCount(), 1);
vector<PeerSessionInfo> vpeers = web3->peers();
@ -130,6 +155,9 @@ BOOST_AUTO_TEST_CASE(basic)
BOOST_AUTO_TEST_CASE(send)
{
if (test::Options::get().nonetwork)
return;
cnote << "Testing web3 send...";
bool sent = false;
@ -149,9 +177,9 @@ BOOST_AUTO_TEST_CASE(send)
{
setThreadName("listener");
ready = true;
auto w = whost2->installWatch(BuildTopicMask("odd"));
auto w = whost2->installWatch(BuildTopicMask("odd"));
set<unsigned> received;
for (unsigned x = 0; x < 9000 && !sent; x += step)
for (unsigned x = 0; x < 7000 && !sent; x += step)
this_thread::sleep_for(chrono::milliseconds(step));
for (unsigned x = 0, last = 0; x < 100 && received.size() < messageCount; ++x)
@ -198,6 +226,9 @@ BOOST_AUTO_TEST_CASE(send)
BOOST_AUTO_TEST_CASE(receive)
{
if (test::Options::get().nonetwork)
return;
cnote << "Testing web3 receive...";
bool sent = false;
@ -219,7 +250,7 @@ BOOST_AUTO_TEST_CASE(receive)
auto w = web3->whisper()->installWatch(BuildTopicMask("odd"));
set<unsigned> received;
for (unsigned x = 0; x < 9000 && !sent; x += step)
for (unsigned x = 0; x < 7000 && !sent; x += step)
this_thread::sleep_for(chrono::milliseconds(step));
for (unsigned x = 0, last = 0; x < 100 && received.size() < messageCount; ++x)
@ -233,6 +264,8 @@ BOOST_AUTO_TEST_CASE(receive)
result += last;
}
}
web3->whisper()->uninstallWatch(w);
});
for (unsigned i = 0; i < 2000 && (!host2.haveNetwork() || !web3->haveNetwork()); i += step)
@ -241,7 +274,7 @@ BOOST_AUTO_TEST_CASE(receive)
BOOST_REQUIRE(host2.haveNetwork());
BOOST_REQUIRE(web3->haveNetwork());
host2.addNode(web3->id(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), web3port, web3port));
host2.addNode(web3->id(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), c_web3port, c_web3port));
for (unsigned i = 0; i < 3000 && (!web3->peerCount() || !host2.peerCount()); i += step)
this_thread::sleep_for(chrono::milliseconds(step));
@ -252,7 +285,7 @@ BOOST_AUTO_TEST_CASE(receive)
KeyPair us = KeyPair::create();
for (unsigned i = 0; i < messageCount; ++i)
{
web3->whisper()->post(us.sec(), RLPStream().append(i * i * i).out(), BuildTopic(i)(i % 2 ? "odd" : "even"), 777000, 1);
web3->whisper()->post(us.sec(), RLPStream().append(i * i * i).out(), BuildTopic(i)(i % 2 ? "odd" : "even"), c_ttl, 1);
this_thread::sleep_for(chrono::milliseconds(50));
}
@ -261,4 +294,232 @@ BOOST_AUTO_TEST_CASE(receive)
BOOST_REQUIRE_EQUAL(result, 1 + 27 + 125);
}
BOOST_AUTO_TEST_CASE(serverBasic)
{
if (test::Options::get().nonetwork)
return;
cnote << "Testing basic jsonrpc server...";
string s = jsonrpcServer->web3_clientVersion();
BOOST_REQUIRE_EQUAL(s, c_version);
s = jsonrpcServer->net_version();
BOOST_REQUIRE(s.empty());
s = jsonrpcServer->web3_sha3("some pseudo-random string here");
BOOST_REQUIRE_EQUAL(s.size(), h256::size * 2 + 2);
BOOST_REQUIRE('0' == s[0] && 'x' == s[1]);
s = jsonrpcServer->net_peerCount();
BOOST_REQUIRE_EQUAL(s, "0x0");
KeyPair src = KeyPair::create();
KeyPair dst = KeyPair::create();
Json::Value t1 = createMessage(toJS(src.address()), toJS(dst.address()));
bool b = jsonrpcServer->shh_post(t1);
BOOST_REQUIRE(b);
string const id = jsonrpcServer->shh_newIdentity();
BOOST_REQUIRE_EQUAL(id.size(), 130);
BOOST_REQUIRE('0' == id[0] && 'x' == id[1]);
b = jsonrpcServer->shh_hasIdentity(id);
BOOST_REQUIRE(b);
Json::Value t2 = createMessage(id, id);
b = jsonrpcServer->shh_post(t2);
BOOST_REQUIRE(b);
}
BOOST_AUTO_TEST_CASE(server)
{
if (test::Options::get().nonetwork)
return;
cnote << "Testing server functionality...";
bool b;
string s;
Json::Value j;
SessionPermissions permissions;
permissions.privileges.insert(Privilege::Admin);
string const text = string("0x") + h256::random().hex(); // message must be in raw form
string sess1 = jsonrpcServer->newSession(permissions);
string sess2("session number two");
jsonrpcServer->addSession(sess2, permissions);
b = jsonrpcServer->admin_web3_setVerbosity(5, sess1);
BOOST_REQUIRE(b);
b = jsonrpcServer->admin_net_start(sess1);
BOOST_REQUIRE(b);
unsigned const step = 10;
for (unsigned i = 0; i < 3000 && !jsonrpcServer->net_listening(); i += step)
this_thread::sleep_for(chrono::milliseconds(step));
b = jsonrpcServer->net_listening();
BOOST_REQUIRE(b);
b = jsonrpcServer->admin_net_stop(sess1);
BOOST_REQUIRE(b);
b = jsonrpcServer->net_listening();
BOOST_REQUIRE(!b);
j = jsonrpcServer->admin_net_peers(sess1);
BOOST_REQUIRE(j.empty());
j = jsonrpcServer->admin_net_nodeInfo(sess2);
BOOST_REQUIRE_EQUAL(j["id"].asString(), web3->id().hex());
BOOST_REQUIRE_EQUAL(j["port"].asUInt(), c_web3port);
uint16_t port2 = 30339;
Host host2("shhrpc-host2", NetworkPreferences("127.0.0.1", port2, false));
host2.setIdealPeerCount(1);
auto whost2 = host2.registerCapability(new WhisperHost());
host2.start();
b = jsonrpcServer->admin_net_start(sess2);
BOOST_REQUIRE(b);
for (unsigned i = 0; i < 2000 && !host2.haveNetwork(); i += step)
this_thread::sleep_for(chrono::milliseconds(step));
for (unsigned i = 0; i < 2000 && !jsonrpcServer->net_listening(); i += step)
this_thread::sleep_for(chrono::milliseconds(step));
BOOST_REQUIRE(host2.haveNetwork());
BOOST_REQUIRE(jsonrpcServer->net_listening());
string node("enode://");
node += host2.id().hex();
node += "@";
node += "127.0.0.1:30339";
b = jsonrpcServer->admin_net_connect(node, sess2);
for (unsigned i = 0; i < 3000 && !host2.peerCount(); i += step)
this_thread::sleep_for(chrono::milliseconds(step));
BOOST_REQUIRE_EQUAL(host2.peerCount(), 1);
this_thread::sleep_for(chrono::milliseconds(step));
j = jsonrpcServer->admin_net_peers(sess2);
BOOST_REQUIRE_EQUAL(j.size(), 1);
Json::Value peer = j[0];
s = peer["id"].asString();
BOOST_REQUIRE_EQUAL(s, host2.id().hex());
BOOST_REQUIRE_EQUAL(peer["port"].asUInt(), port2);
s = jsonrpcServer->net_peerCount();
BOOST_REQUIRE_EQUAL(s, "0x1");
KeyPair src = KeyPair::create();
KeyPair dst = KeyPair::create();
Json::Value t1 = createMessage(toJS(src.address()), toJS(dst.address()));
b = jsonrpcServer->shh_post(t1);
BOOST_REQUIRE(b);
string const id = jsonrpcServer->shh_newIdentity();
BOOST_REQUIRE_EQUAL(id.size(), 130);
BOOST_REQUIRE(jsonrpcServer->shh_hasIdentity(id));
Json::Value t2 = createMessage(id, id);
b = jsonrpcServer->shh_post(t2);
BOOST_REQUIRE(b);
string const nonexistent = "123456789";
b = jsonrpcServer->shh_uninstallFilter(nonexistent);
BOOST_REQUIRE(b);
j = jsonrpcServer->shh_getMessages(nonexistent);
BOOST_REQUIRE(j.empty());
string const topic = "unicorns";
Json::Value t(Json::arrayValue);
t.append(topic);
Json::Value f;
f["to"] = id;
f["topics"] = t;
string const filter = jsonrpcServer->shh_newFilter(f);
j = jsonrpcServer->shh_getFilterChanges(filter);
BOOST_REQUIRE(j.empty());
j = jsonrpcServer->shh_getMessages(filter);
BOOST_REQUIRE(j.empty());
Json::Value msg = createMessage(id, id, topic, text);
b = jsonrpcServer->shh_post(msg);
BOOST_REQUIRE(b);
this_thread::sleep_for(chrono::milliseconds(50));
j = jsonrpcServer->shh_getFilterChanges(filter);
BOOST_REQUIRE(!j.empty());
Json::Value m1 = j[0];
BOOST_REQUIRE_EQUAL(m1["ttl"], toJS(c_ttl));
BOOST_REQUIRE_EQUAL(m1["from"], id);
BOOST_REQUIRE_EQUAL(m1["to"], id);
BOOST_REQUIRE_EQUAL(m1["payload"], text);
j = jsonrpcServer->shh_getMessages(filter);
BOOST_REQUIRE(!j.empty());
Json::Value m2 = j[0];
BOOST_REQUIRE_EQUAL(m2["ttl"], toJS(c_ttl));
BOOST_REQUIRE_EQUAL(m2["from"], id);
BOOST_REQUIRE_EQUAL(m2["to"], id);
BOOST_REQUIRE_EQUAL(m2["payload"], text);
j = jsonrpcServer->shh_getFilterChanges(filter);
BOOST_REQUIRE(j.empty());
j = jsonrpcServer->shh_getMessages(filter);
BOOST_REQUIRE(!j.empty());
m1 = j[0];
BOOST_REQUIRE_EQUAL(m1["ttl"], toJS(c_ttl));
BOOST_REQUIRE_EQUAL(m1["from"], id);
BOOST_REQUIRE_EQUAL(m1["to"], id);
BOOST_REQUIRE_EQUAL(m1["payload"], text);
msg = createMessage(id, id, topic);
b = jsonrpcServer->shh_post(msg);
BOOST_REQUIRE(b);
this_thread::sleep_for(chrono::milliseconds(50));
j = jsonrpcServer->shh_getFilterChanges(filter);
BOOST_REQUIRE_EQUAL(j.size(), 1);
j = jsonrpcServer->shh_getMessages(filter);
BOOST_REQUIRE_EQUAL(j.size(), 2);
b = jsonrpcServer->shh_uninstallFilter(filter);
BOOST_REQUIRE(b);
j = jsonrpcServer->shh_getFilterChanges(filter);
BOOST_REQUIRE(j.empty());
j = jsonrpcServer->shh_getMessages(filter);
BOOST_REQUIRE(j.empty());
msg = createMessage(id, id, topic);
b = jsonrpcServer->shh_post(msg);
BOOST_REQUIRE(b);
this_thread::sleep_for(chrono::milliseconds(50));
j = jsonrpcServer->shh_getFilterChanges(filter);
BOOST_REQUIRE(j.empty());
j = jsonrpcServer->shh_getMessages(filter);
BOOST_REQUIRE(j.empty());
b = jsonrpcServer->admin_net_stop(sess2);
BOOST_REQUIRE(b);
b = jsonrpcServer->net_listening();
BOOST_REQUIRE(!b);
}
BOOST_AUTO_TEST_SUITE_END()

10
test/libwhisper/whisperDB.cpp

@ -24,6 +24,7 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
#include <libp2p/Host.h>
#include <libwhisper/WhisperDB.h>
#include <libwhisper/WhisperHost.h>
#include <test/TestHelper.h>
using namespace std;
using namespace dev;
@ -130,6 +131,9 @@ BOOST_AUTO_TEST_CASE(persistence)
BOOST_AUTO_TEST_CASE(messages)
{
if (test::Options::get().nonetwork)
return;
cnote << "Testing load/save Whisper messages...";
VerbosityHolder setTemporaryLevel(2);
unsigned const TestSize = 3;
@ -185,6 +189,9 @@ BOOST_AUTO_TEST_CASE(messages)
BOOST_AUTO_TEST_CASE(corruptedData)
{
if (test::Options::get().nonetwork)
return;
cnote << "Testing corrupted data...";
VerbosityHolder setTemporaryLevel(2);
map<h256, Envelope> m;
@ -211,6 +218,9 @@ BOOST_AUTO_TEST_CASE(corruptedData)
BOOST_AUTO_TEST_CASE(filters)
{
if (test::Options::get().nonetwork)
return;
cnote << "Testing filters saving...";
VerbosityHolder setTemporaryLevel(2);
h256 persistID(0xC0FFEE);

3
test/libwhisper/whisperTopic.cpp

@ -389,6 +389,9 @@ BOOST_AUTO_TEST_CASE(topicAdvertising)
BOOST_AUTO_TEST_CASE(selfAddressed)
{
if (test::Options::get().nonetwork)
return;
VerbosityHolder setTemporaryLevel(10);
cnote << "Testing self-addressed messaging with bloom filter matching...";

Loading…
Cancel
Save