diff --git a/CMakeLists.txt b/CMakeLists.txt index d49bd76a3..f0b313164 100644 --- a/CMakeLists.txt +++ b/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() diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 35752680e..c606a1d20 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -859,9 +859,8 @@ void Main::readSettings(bool _skipGeometry) { p->readSettings(s); }); - - static_cast(ethereum()->gasPricer().get())->setAsk(u256(s.value("askPrice", "500000000000").toString().toStdString())); - static_cast(ethereum()->gasPricer().get())->setBid(u256(s.value("bidPrice", "500000000000").toString().toStdString())); + static_cast(ethereum()->gasPricer().get())->setAsk(u256(s.value("askPrice", QString::fromStdString(toString(c_defaultGasPrice))).toString().toStdString())); + static_cast(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()); diff --git a/alethzero/NatspecHandler.cpp b/alethzero/NatspecHandler.cpp index 6ed9f2b10..dc4a219ab 100644 --- a/alethzero/NatspecHandler.cpp +++ b/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); diff --git a/eth/main.cpp b/eth/main.cpp index b2425ba31..e8705bcd0 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -153,8 +153,8 @@ void help() /*<< " -B,--block-fees Set the block fee profit in the reference unit e.g. ¢ (default: 15)." << endl << " -e,--ether-price 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 Set the minimum ask gas price under which no transactions will be mined (default 500000000000)." << endl - << " --bid Set the bid gas price for to pay for transactions (default 500000000000)." << endl + << " --ask Set the minimum ask gas price under which no transactions will be mined (default " << toString(c_defaultGasPrice) << " )." << endl + << " --bid Set the bid gas price for to pay for transactions (default " << toString(c_defaultGasPrice) << " )." << endl << endl << "Client mining:" << endl << " -a,--address 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; diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index 0faba8e8e..5f4b0a39e 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -349,6 +349,26 @@ std::vector keysOf(std::unordered_map const& _m) return ret; } +template +std::vector valuesOf(std::map const& _m) +{ + std::vector ret; + ret.reserve(_m.size()); + for (auto const& i: _m) + ret.push_back(i.second); + return ret; +} + +template +std::vector valuesOf(std::unordered_map const& _m) +{ + std::vector ret; + ret.reserve(_m.size()); + for (auto const& i: _m) + ret.push_back(i.second); + return ret; +} + template bool contains(T const& _t, V const& _v) { diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index 5c501fde7..3c3b08845 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -128,7 +128,7 @@ void dev::writeFile(std::string const& _file, bytesConstRef _data, bool _writeDe s.write(reinterpret_cast(_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)); } } diff --git a/libdevcore/FixedHash.h b/libdevcore/FixedHash.h index e0125b005..973bc174e 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -238,7 +238,14 @@ public: explicit SecureFixedHash(bytes const* _d, ConstructFromPointerType _t): FixedHash(_d, _t) {} ~SecureFixedHash() { ref().cleanse(); } - SecureFixedHash& operator=(SecureFixedHash const& _c) { ref().cleanse(); FixedHash::operator=(static_cast const&>(_c)); return *this; } + SecureFixedHash& operator=(SecureFixedHash const& _c) + { + if (&_c == this) + return *this; + ref().cleanse(); + FixedHash::operator=(static_cast const&>(_c)); + return *this; + } using FixedHash::size; diff --git a/libdevcore/TransientDirectory.cpp b/libdevcore/TransientDirectory.cpp index 31a826c24..cd91bd0e4 100644 --- a/libdevcore/TransientDirectory.cpp +++ b/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() diff --git a/libdevcrypto/SecretStore.cpp b/libdevcrypto/SecretStore.cpp index 266f3735a..39f421f3e 100644 --- a/libdevcrypto/SecretStore.cpp +++ b/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); diff --git a/libdevcrypto/SecretStore.h b/libdevcrypto/SecretStore.h index fbc4c0bec..0fcb18734 100644 --- a/libdevcrypto/SecretStore.h +++ b/libdevcrypto/SecretStore.h @@ -70,6 +70,9 @@ public: /// Returns the uuids of all stored keys. std::vector 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; diff --git a/libethcore/Common.h b/libethcore/Common.h index 883a14e9b..621a893f1 100644 --- a/libethcore/Common.h +++ b/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)...); } + 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)...); + for (auto const& f: valuesOf(m_fire)) + if (auto h = f.lock()) + h->fire(_args...); } private: diff --git a/libethcore/KeyManager.cpp b/libethcore/KeyManager.cpp index 08892e453..8f3cd5e85 100644 --- a/libethcore/KeyManager.cpp +++ b/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]; } diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 230eb39eb..b38db9c8b 100644 --- a/libethereum/BlockChain.cpp +++ b/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; diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 955646f04..b7367a64f 100644 --- a/libethereum/State.cpp +++ b/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; diff --git a/libethereum/Utility.cpp b/libethereum/Utility.cpp index f34f66463..ac407999c 100644 --- a/libethereum/Utility.cpp +++ b/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)); diff --git a/libnatspec/NatspecExpressionEvaluator.h b/libnatspec/NatspecExpressionEvaluator.h index f7984f6e8..91d12399c 100644 --- a/libnatspec/NatspecExpressionEvaluator.h +++ b/libnatspec/NatspecExpressionEvaluator.h @@ -20,9 +20,11 @@ */ #pragma once - +#pragma warning(push) +#pragma clang diagnostic ignored "-Winconsistent-missing-override" #include #include +#pragma warning(pop) /** * Should be used to evaluate natspec expression. diff --git a/libp2p/Network.cpp b/libp2p/Network.cpp index 7a3b50385..b44ac1e0a 100644 --- a/libp2p/Network.cpp +++ b/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 (...) { diff --git a/libweb3jsonrpc/WebThreeStubServer.cpp b/libweb3jsonrpc/WebThreeStubServer.cpp index 627f18d38..b5d8dc35f 100644 --- a/libweb3jsonrpc/WebThreeStubServer.cpp +++ b/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); diff --git a/libwhisper/WhisperDB.cpp b/libwhisper/WhisperDB.cpp index 39d0629a7..ba3691a26 100644 --- a/libwhisper/WhisperDB.cpp +++ b/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; diff --git a/secp256k1/libsecp256k1-config.h b/secp256k1/libsecp256k1-config.h index d23fee837..0cbbc2434 100644 --- a/secp256k1/libsecp256k1-config.h +++ b/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 */ diff --git a/test/libwhisper/shhrpc.cpp b/test/libwhisper/shhrpc.cpp index 5d3fea641..f14aea6b2 100644 --- a/test/libwhisper/shhrpc.cpp +++ b/test/libwhisper/shhrpc.cpp @@ -44,7 +44,9 @@ namespace js = json_spirit; WebThreeDirect* web3; unique_ptr jsonrpcServer; unique_ptr 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 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 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 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 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() diff --git a/test/libwhisper/whisperDB.cpp b/test/libwhisper/whisperDB.cpp index a62539bfd..892714393 100644 --- a/test/libwhisper/whisperDB.cpp +++ b/test/libwhisper/whisperDB.cpp @@ -24,6 +24,7 @@ along with cpp-ethereum. If not, see . #include #include #include +#include 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 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); diff --git a/test/libwhisper/whisperTopic.cpp b/test/libwhisper/whisperTopic.cpp index 6ee5076c4..39728fb17 100644 --- a/test/libwhisper/whisperTopic.cpp +++ b/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...";