From 4f5f3a8d92e3ce599376006c57e1665d3756ff27 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Wed, 8 Jun 2016 20:20:38 +0300 Subject: [PATCH 1/2] test client: setChainParams --- eth/main.cpp | 6 +++++- libweb3jsonrpc/Test.cpp | 17 +++++++++++++++++ libweb3jsonrpc/Test.h | 1 + libweb3jsonrpc/TestFace.h | 6 ++++++ libweb3jsonrpc/test.json | 1 + 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/eth/main.cpp b/eth/main.cpp index 694a137..d85b4e9 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -1222,7 +1222,11 @@ int main(int argc, char** argv) AddressHash allowedDestinations; - auto authenticator = [&](TransactionSkeleton const& _t, bool isProxy) -> bool { + std::function authenticator; + if (testingMode) + authenticator = [](TransactionSkeleton const&, bool) -> bool { return true; }; + else + authenticator = [&](TransactionSkeleton const& _t, bool isProxy) -> bool { // "unlockAccount" functionality is done in the AccountHolder. if (!alwaysConfirm || allowedDestinations.count(_t.to)) return true; diff --git a/libweb3jsonrpc/Test.cpp b/libweb3jsonrpc/Test.cpp index 235ae82..3cdb5bf 100644 --- a/libweb3jsonrpc/Test.cpp +++ b/libweb3jsonrpc/Test.cpp @@ -24,6 +24,7 @@ #include #include #include +#include using namespace std; using namespace dev; @@ -32,6 +33,22 @@ using namespace jsonrpc; Test::Test(eth::Client& _eth): m_eth(_eth) {} +bool Test::test_setChainParams(Json::Value const& param1) +{ + try + { + Json::FastWriter fastWriter; + std::string output = fastWriter.write(param1); + asClientTest(m_eth).setChainParams(output); + } + catch (std::exception const&) + { + BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR)); + } + + return true; +} + bool Test::test_mineBlocks(int _number) { try diff --git a/libweb3jsonrpc/Test.h b/libweb3jsonrpc/Test.h index 3b67c93..64facbf 100644 --- a/libweb3jsonrpc/Test.h +++ b/libweb3jsonrpc/Test.h @@ -43,6 +43,7 @@ class Test: public TestFace return RPCModules{RPCModule{"test", "1.0"}}; } + virtual bool test_setChainParams(const Json::Value ¶m1) override; virtual bool test_mineBlocks(int _number) override; virtual bool test_modifyTimestamp(int _timestamp) override; virtual bool test_addBlock(std::string const& _rlp) override; diff --git a/libweb3jsonrpc/TestFace.h b/libweb3jsonrpc/TestFace.h index 309b04a..4259258 100644 --- a/libweb3jsonrpc/TestFace.h +++ b/libweb3jsonrpc/TestFace.h @@ -14,12 +14,17 @@ namespace dev { public: TestFace() { + this->bindAndAddMethod(jsonrpc::Procedure("test_setChainParams", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_OBJECT, NULL), &dev::rpc::TestFace::test_setChainParamsI); this->bindAndAddMethod(jsonrpc::Procedure("test_mineBlocks", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_mineBlocksI); this->bindAndAddMethod(jsonrpc::Procedure("test_modifyTimestamp", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_modifyTimestampI); this->bindAndAddMethod(jsonrpc::Procedure("test_addBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &dev::rpc::TestFace::test_addBlockI); this->bindAndAddMethod(jsonrpc::Procedure("test_rewindToBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_rewindToBlockI); } + inline virtual void test_setChainParamsI(const Json::Value &request, Json::Value &response) + { + response = this->test_setChainParams(request[0u]); + } inline virtual void test_mineBlocksI(const Json::Value &request, Json::Value &response) { response = this->test_mineBlocks(request[0u].asInt()); @@ -36,6 +41,7 @@ namespace dev { { response = this->test_rewindToBlock(request[0u].asInt()); } + virtual bool test_setChainParams(const Json::Value& param1) = 0; virtual bool test_mineBlocks(int param1) = 0; virtual bool test_modifyTimestamp(int param1) = 0; virtual bool test_addBlock(const std::string& param1) = 0; diff --git a/libweb3jsonrpc/test.json b/libweb3jsonrpc/test.json index 28ae224..916d163 100644 --- a/libweb3jsonrpc/test.json +++ b/libweb3jsonrpc/test.json @@ -1,4 +1,5 @@ [ +{ "name": "test_setChainParams", "params": [{}], "order": [], "returns": false}, { "name": "test_mineBlocks", "params": [0], "returns": false }, { "name": "test_modifyTimestamp", "params": [0], "returns": false }, { "name": "test_addBlock", "params": [""], "returns": false }, From 49c9848ca1aba4281be68f5c023a84f6f328a744 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Thu, 9 Jun 2016 19:33:47 +0300 Subject: [PATCH 2/2] style --- eth/main.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/eth/main.cpp b/eth/main.cpp index d85b4e9..bf4f5c0 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -1227,24 +1227,24 @@ int main(int argc, char** argv) authenticator = [](TransactionSkeleton const&, bool) -> bool { return true; }; else authenticator = [&](TransactionSkeleton const& _t, bool isProxy) -> bool { - // "unlockAccount" functionality is done in the AccountHolder. - if (!alwaysConfirm || allowedDestinations.count(_t.to)) - return true; + // "unlockAccount" functionality is done in the AccountHolder. + if (!alwaysConfirm || allowedDestinations.count(_t.to)) + return true; - string r = getResponse(_t.userReadable(isProxy, - [&](TransactionSkeleton const& _t) -> pair - { - h256 contractCodeHash = web3.ethereum()->postState().codeHash(_t.to); - if (contractCodeHash == EmptySHA3) - return std::make_pair(false, std::string()); - // TODO: actually figure out the natspec. we'll need the natspec database here though. - return std::make_pair(true, std::string()); - }, [&](Address const& _a) { return ICAP(_a).encoded() + " (" + _a.abridged() + ")"; } - ) + "\nEnter yes/no/always (always to this address): ", {"yes", "n", "N", "no", "NO", "always"}); - if (r == "always") - allowedDestinations.insert(_t.to); - return r == "yes" || r == "always"; - }; + string r = getResponse(_t.userReadable(isProxy, + [&](TransactionSkeleton const& _t) -> pair + { + h256 contractCodeHash = web3.ethereum()->postState().codeHash(_t.to); + if (contractCodeHash == EmptySHA3) + return std::make_pair(false, std::string()); + // TODO: actually figure out the natspec. we'll need the natspec database here though. + return std::make_pair(true, std::string()); + }, [&](Address const& _a) { return ICAP(_a).encoded() + " (" + _a.abridged() + ")"; } + ) + "\nEnter yes/no/always (always to this address): ", {"yes", "n", "N", "no", "NO", "always"}); + if (r == "always") + allowedDestinations.insert(_t.to); + return r == "yes" || r == "always"; + }; ExitHandler exitHandler;