Skip to content
This repository was archived by the owner on Dec 30, 2024. It is now read-only.

Commit 7068e23

Browse files
committed
Merge pull request #177 from winsvega/testclient
testclient: setChainParams
2 parents 7ca01ad + 49c9848 commit 7068e23

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

eth/main.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,25 +1197,29 @@ int main(int argc, char** argv)
11971197

11981198
AddressHash allowedDestinations;
11991199

1200-
auto authenticator = [&](TransactionSkeleton const& _t, bool isProxy) -> bool {
1201-
// "unlockAccount" functionality is done in the AccountHolder.
1202-
if (!alwaysConfirm || allowedDestinations.count(_t.to))
1203-
return true;
1200+
std::function<bool(TransactionSkeleton const&, bool)> authenticator;
1201+
if (testingMode)
1202+
authenticator = [](TransactionSkeleton const&, bool) -> bool { return true; };
1203+
else
1204+
authenticator = [&](TransactionSkeleton const& _t, bool isProxy) -> bool {
1205+
// "unlockAccount" functionality is done in the AccountHolder.
1206+
if (!alwaysConfirm || allowedDestinations.count(_t.to))
1207+
return true;
12041208

1205-
string r = getResponse(_t.userReadable(isProxy,
1206-
[&](TransactionSkeleton const& _t) -> pair<bool, string>
1207-
{
1208-
h256 contractCodeHash = web3.ethereum()->postState().codeHash(_t.to);
1209-
if (contractCodeHash == EmptySHA3)
1210-
return std::make_pair(false, std::string());
1211-
// TODO: actually figure out the natspec. we'll need the natspec database here though.
1212-
return std::make_pair(true, std::string());
1213-
}, [&](Address const& _a) { return ICAP(_a).encoded() + " (" + _a.abridged() + ")"; }
1214-
) + "\nEnter yes/no/always (always to this address): ", {"yes", "n", "N", "no", "NO", "always"});
1215-
if (r == "always")
1216-
allowedDestinations.insert(_t.to);
1217-
return r == "yes" || r == "always";
1218-
};
1209+
string r = getResponse(_t.userReadable(isProxy,
1210+
[&](TransactionSkeleton const& _t) -> pair<bool, string>
1211+
{
1212+
h256 contractCodeHash = web3.ethereum()->postState().codeHash(_t.to);
1213+
if (contractCodeHash == EmptySHA3)
1214+
return std::make_pair(false, std::string());
1215+
// TODO: actually figure out the natspec. we'll need the natspec database here though.
1216+
return std::make_pair(true, std::string());
1217+
}, [&](Address const& _a) { return ICAP(_a).encoded() + " (" + _a.abridged() + ")"; }
1218+
) + "\nEnter yes/no/always (always to this address): ", {"yes", "n", "N", "no", "NO", "always"});
1219+
if (r == "always")
1220+
allowedDestinations.insert(_t.to);
1221+
return r == "yes" || r == "always";
1222+
};
12191223

12201224
ExitHandler exitHandler;
12211225

libweb3jsonrpc/Test.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <jsonrpccpp/common/errors.h>
2525
#include <jsonrpccpp/common/exception.h>
2626
#include <libethereum/ClientTest.h>
27+
#include <libethereum/ChainParams.h>
2728

2829
using namespace std;
2930
using namespace dev;
@@ -32,6 +33,22 @@ using namespace jsonrpc;
3233

3334
Test::Test(eth::Client& _eth): m_eth(_eth) {}
3435

36+
bool Test::test_setChainParams(Json::Value const& param1)
37+
{
38+
try
39+
{
40+
Json::FastWriter fastWriter;
41+
std::string output = fastWriter.write(param1);
42+
asClientTest(m_eth).setChainParams(output);
43+
}
44+
catch (std::exception const&)
45+
{
46+
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
47+
}
48+
49+
return true;
50+
}
51+
3552
bool Test::test_mineBlocks(int _number)
3653
{
3754
try

libweb3jsonrpc/Test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Test: public TestFace
4343
return RPCModules{RPCModule{"test", "1.0"}};
4444
}
4545

46+
virtual bool test_setChainParams(const Json::Value &param1) override;
4647
virtual bool test_mineBlocks(int _number) override;
4748
virtual bool test_modifyTimestamp(int _timestamp) override;
4849
virtual bool test_addBlock(std::string const& _rlp) override;

libweb3jsonrpc/TestFace.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ namespace dev {
1414
public:
1515
TestFace()
1616
{
17+
this->bindAndAddMethod(jsonrpc::Procedure("test_setChainParams", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_OBJECT, NULL), &dev::rpc::TestFace::test_setChainParamsI);
1718
this->bindAndAddMethod(jsonrpc::Procedure("test_mineBlocks", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_mineBlocksI);
1819
this->bindAndAddMethod(jsonrpc::Procedure("test_modifyTimestamp", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_modifyTimestampI);
1920
this->bindAndAddMethod(jsonrpc::Procedure("test_addBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &dev::rpc::TestFace::test_addBlockI);
2021
this->bindAndAddMethod(jsonrpc::Procedure("test_rewindToBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_rewindToBlockI);
2122
}
2223

24+
inline virtual void test_setChainParamsI(const Json::Value &request, Json::Value &response)
25+
{
26+
response = this->test_setChainParams(request[0u]);
27+
}
2328
inline virtual void test_mineBlocksI(const Json::Value &request, Json::Value &response)
2429
{
2530
response = this->test_mineBlocks(request[0u].asInt());
@@ -36,6 +41,7 @@ namespace dev {
3641
{
3742
response = this->test_rewindToBlock(request[0u].asInt());
3843
}
44+
virtual bool test_setChainParams(const Json::Value& param1) = 0;
3945
virtual bool test_mineBlocks(int param1) = 0;
4046
virtual bool test_modifyTimestamp(int param1) = 0;
4147
virtual bool test_addBlock(const std::string& param1) = 0;

libweb3jsonrpc/test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[
2+
{ "name": "test_setChainParams", "params": [{}], "order": [], "returns": false},
23
{ "name": "test_mineBlocks", "params": [0], "returns": false },
34
{ "name": "test_modifyTimestamp", "params": [0], "returns": false },
45
{ "name": "test_addBlock", "params": [""], "returns": false },

0 commit comments

Comments
 (0)