Skip to content

Commit 740da50

Browse files
authored
Merge pull request ethereum#4922 from ethereum/smalltrpc
fix setting author in setChainParams for --test mode
2 parents 0ff6ef7 + ef71136 commit 740da50

File tree

4 files changed

+169
-63
lines changed

4 files changed

+169
-63
lines changed

libethereum/Client.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ void Client::reopenChain(ChainParams const& _p, WithExisting _we)
273273
WriteGuard l2(x_preSeal);
274274
WriteGuard l3(x_working);
275275

276-
auto author = m_preSeal.author(); // backup and restore author.
277276
m_preSeal = Block(chainParams().accountStartNonce);
278277
m_postSeal = Block(chainParams().accountStartNonce);
279278
m_working = Block(chainParams().accountStartNonce);
@@ -283,7 +282,7 @@ void Client::reopenChain(ChainParams const& _p, WithExisting _we)
283282
m_stateDB = State::openDB(Defaults::dbPath(), bc().genesisHash(), _we);
284283

285284
m_preSeal = bc().genesisBlock(m_stateDB);
286-
m_preSeal.setAuthor(author);
285+
m_preSeal.setAuthor(_p.author);
287286
m_postSeal = m_preSeal;
288287
m_working = Block(chainParams().accountStartNonce);
289288
}

libethereum/ClientTest.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ void ClientTest::setChainParams(string const& _genesis)
6161
BOOST_THROW_EXCEPTION(ChainParamsNotNoProof() << errinfo_comment("Provided configuration is not well formatted."));
6262

6363
reopenChain(params, WithExisting::Kill);
64-
setAuthor(params.author); //for some reason author is not being set
6564
}
6665
catch (...)
6766
{

libweb3jsonrpc/Test.cpp

+61-60
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/*
2-
This file is part of cpp-ethereum.
2+
This file is part of cpp-ethereum.
33
4-
cpp-ethereum is free software: you can redistribute it and/or modify
5-
it under the terms of the GNU General Public License as published by
6-
the Free Software Foundation, either version 3 of the License, or
7-
(at your option) any later version.
4+
cpp-ethereum is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
88
9-
cpp-ethereum is distributed in the hope that it will be useful,
10-
but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
GNU General Public License for more details.
9+
cpp-ethereum is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
1313
14-
You should have received a copy of the GNU General Public License
15-
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
14+
You should have received a copy of the GNU General Public License
15+
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717
/** @file Test.cpp
1818
* @authors:
@@ -35,71 +35,72 @@ Test::Test(eth::Client& _eth): m_eth(_eth) {}
3535

3636
bool Test::test_setChainParams(Json::Value const& param1)
3737
{
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-
}
38+
try
39+
{
40+
Json::FastWriter fastWriter;
41+
std::string output = fastWriter.write(param1);
42+
asClientTest(m_eth).setChainParams(output);
43+
asClientTest(m_eth).completeSync(); // set sync state to idle for mining
44+
}
45+
catch (std::exception const&)
46+
{
47+
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
48+
}
4849

49-
return true;
50+
return true;
5051
}
5152

5253
bool Test::test_mineBlocks(int _number)
5354
{
54-
try
55-
{
56-
asClientTest(m_eth).mineBlocks(_number);
57-
}
58-
catch (std::exception const&)
59-
{
60-
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
61-
}
55+
try
56+
{
57+
asClientTest(m_eth).mineBlocks(_number);
58+
}
59+
catch (std::exception const&)
60+
{
61+
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
62+
}
6263

63-
return true;
64+
return true;
6465
}
6566

6667
bool Test::test_modifyTimestamp(int _timestamp)
6768
{
68-
// FIXME: Fix year 2038 issue.
69-
try
70-
{
71-
asClientTest(m_eth).modifyTimestamp(_timestamp);
72-
}
73-
catch (std::exception const&)
74-
{
75-
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
76-
}
77-
return true;
69+
// FIXME: Fix year 2038 issue.
70+
try
71+
{
72+
asClientTest(m_eth).modifyTimestamp(_timestamp);
73+
}
74+
catch (std::exception const&)
75+
{
76+
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
77+
}
78+
return true;
7879
}
7980

8081
bool Test::test_addBlock(std::string const& _rlp)
8182
{
82-
try
83-
{
84-
asClientTest(m_eth).addBlock(_rlp);
85-
}
86-
catch (std::exception const&)
87-
{
88-
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
89-
}
90-
return true;
83+
try
84+
{
85+
asClientTest(m_eth).addBlock(_rlp);
86+
}
87+
catch (std::exception const&)
88+
{
89+
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
90+
}
91+
return true;
9192
}
9293

9394
bool Test::test_rewindToBlock(int _number)
9495
{
95-
try
96-
{
97-
m_eth.rewind(_number);
98-
asClientTest(m_eth).completeSync();
99-
}
100-
catch (std::exception const&)
101-
{
102-
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
103-
}
104-
return true;
96+
try
97+
{
98+
m_eth.rewind(_number);
99+
asClientTest(m_eth).completeSync();
100+
}
101+
catch (std::exception const&)
102+
{
103+
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
104+
}
105+
return true;
105106
}
+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
This file is part of cpp-ethereum.
3+
4+
cpp-ethereum is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
cpp-ethereum is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
/** @date 2018
18+
*/
19+
20+
#include <libethereum/ChainParams.h>
21+
#include <libethereum/ClientTest.h>
22+
#include <libp2p/Network.h>
23+
#include <libwebthree/WebThree.h>
24+
#include <test/tools/libtesteth/TestOutputHelper.h>
25+
#include <boost/test/unit_test.hpp>
26+
27+
using namespace std;
28+
using namespace dev;
29+
using namespace dev::eth;
30+
using namespace dev::test;
31+
using namespace dev::p2p;
32+
namespace fs = boost::filesystem;
33+
34+
class TestClientFixture : public TestOutputHelperFixture
35+
{
36+
public:
37+
TestClientFixture()
38+
{
39+
ChainParams chainParams;
40+
chainParams.sealEngineName = "NoProof";
41+
chainParams.allowFutureBlocks = true;
42+
43+
fs::path dir = fs::temp_directory_path();
44+
45+
string listenIP = "127.0.0.1";
46+
unsigned short listenPort = 30303;
47+
auto netPrefs = NetworkPreferences(listenIP, listenPort, false);
48+
netPrefs.discovery = false;
49+
netPrefs.pin = false;
50+
51+
auto nodesState = contents(dir / fs::path("network.rlp"));
52+
bool testingMode = true;
53+
m_web3.reset(new dev::WebThreeDirect(WebThreeDirect::composeClientVersion("eth"), dir, dir,
54+
chainParams, WithExisting::Kill, {"eth"}, netPrefs, &nodesState, testingMode));
55+
}
56+
57+
dev::WebThreeDirect* getWeb3() { return m_web3.get(); }
58+
59+
private:
60+
std::unique_ptr<dev::WebThreeDirect> m_web3;
61+
};
62+
63+
// genesis config string from solidity
64+
static std::string const c_configString = R"(
65+
{
66+
"sealEngine": "NoProof",
67+
"params": {
68+
"accountStartNonce": "0x00",
69+
"maximumExtraDataSize": "0x1000000",
70+
"blockReward": "0x",
71+
"allowFutureBlocks": true,
72+
"homesteadForkBlock": "0x00",
73+
"EIP150ForkBlock": "0x00",
74+
"EIP158ForkBlock": "0x00"
75+
},
76+
"genesis": {
77+
"author": "0000000000000010000000000000000000000000",
78+
"timestamp": "0x00",
79+
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
80+
"extraData": "0x",
81+
"gasLimit": "0x1000000000000"
82+
},
83+
"accounts": {
84+
"0000000000000000000000000000000000000001": { "wei": "1", "precompiled": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } },
85+
"0000000000000000000000000000000000000002": { "wei": "1", "precompiled": { "name": "sha256", "linear": { "base": 60, "word": 12 } } },
86+
"0000000000000000000000000000000000000003": { "wei": "1", "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } },
87+
"0000000000000000000000000000000000000004": { "wei": "1", "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } },
88+
"0000000000000000000000000000000000000005": { "wei": "1", "precompiled": { "name": "modexp" } },
89+
"0000000000000000000000000000000000000006": { "wei": "1", "precompiled": { "name": "alt_bn128_G1_add", "linear": { "base": 500, "word": 0 } } },
90+
"0000000000000000000000000000000000000007": { "wei": "1", "precompiled": { "name": "alt_bn128_G1_mul", "linear": { "base": 40000, "word": 0 } } },
91+
"0000000000000000000000000000000000000008": { "wei": "1", "precompiled": { "name": "alt_bn128_pairing_product" } }
92+
}
93+
}
94+
)";
95+
96+
97+
BOOST_FIXTURE_TEST_SUITE(ClientTestSuite, TestClientFixture)
98+
99+
BOOST_AUTO_TEST_CASE(ClientTest_setChainParamsAuthor)
100+
{
101+
ClientTest* testClient = asClientTest(getWeb3()->ethereum());
102+
BOOST_CHECK_EQUAL(testClient->author(), Address("0000000000000000000000000000000000000000"));
103+
testClient->setChainParams(c_configString);
104+
BOOST_CHECK_EQUAL(testClient->author(), Address("0000000000000010000000000000000000000000"));
105+
}
106+
107+
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)