Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #4922 from ethereum/smalltrpc
Browse files Browse the repository at this point in the history
fix setting author in setChainParams for --test mode
  • Loading branch information
winsvega authored Apr 4, 2018
2 parents 0ff6ef7 + ef71136 commit 740da50
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 63 deletions.
3 changes: 1 addition & 2 deletions libethereum/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ void Client::reopenChain(ChainParams const& _p, WithExisting _we)
WriteGuard l2(x_preSeal);
WriteGuard l3(x_working);

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

m_preSeal = bc().genesisBlock(m_stateDB);
m_preSeal.setAuthor(author);
m_preSeal.setAuthor(_p.author);
m_postSeal = m_preSeal;
m_working = Block(chainParams().accountStartNonce);
}
Expand Down
1 change: 0 additions & 1 deletion libethereum/ClientTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ void ClientTest::setChainParams(string const& _genesis)
BOOST_THROW_EXCEPTION(ChainParamsNotNoProof() << errinfo_comment("Provided configuration is not well formatted."));

reopenChain(params, WithExisting::Kill);
setAuthor(params.author); //for some reason author is not being set
}
catch (...)
{
Expand Down
121 changes: 61 additions & 60 deletions libweb3jsonrpc/Test.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
This file is part of cpp-ethereum.
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file Test.cpp
* @authors:
Expand All @@ -35,71 +35,72 @@ 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));
}
try
{
Json::FastWriter fastWriter;
std::string output = fastWriter.write(param1);
asClientTest(m_eth).setChainParams(output);
asClientTest(m_eth).completeSync(); // set sync state to idle for mining
}
catch (std::exception const&)
{
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
}

return true;
return true;
}

bool Test::test_mineBlocks(int _number)
{
try
{
asClientTest(m_eth).mineBlocks(_number);
}
catch (std::exception const&)
{
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
}
try
{
asClientTest(m_eth).mineBlocks(_number);
}
catch (std::exception const&)
{
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
}

return true;
return true;
}

bool Test::test_modifyTimestamp(int _timestamp)
{
// FIXME: Fix year 2038 issue.
try
{
asClientTest(m_eth).modifyTimestamp(_timestamp);
}
catch (std::exception const&)
{
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
}
return true;
// FIXME: Fix year 2038 issue.
try
{
asClientTest(m_eth).modifyTimestamp(_timestamp);
}
catch (std::exception const&)
{
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
}
return true;
}

bool Test::test_addBlock(std::string const& _rlp)
{
try
{
asClientTest(m_eth).addBlock(_rlp);
}
catch (std::exception const&)
{
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
}
return true;
try
{
asClientTest(m_eth).addBlock(_rlp);
}
catch (std::exception const&)
{
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
}
return true;
}

bool Test::test_rewindToBlock(int _number)
{
try
{
m_eth.rewind(_number);
asClientTest(m_eth).completeSync();
}
catch (std::exception const&)
{
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
}
return true;
try
{
m_eth.rewind(_number);
asClientTest(m_eth).completeSync();
}
catch (std::exception const&)
{
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
}
return true;
}
107 changes: 107 additions & 0 deletions test/unittests/libethereum/ClientTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @date 2018
*/

#include <libethereum/ChainParams.h>
#include <libethereum/ClientTest.h>
#include <libp2p/Network.h>
#include <libwebthree/WebThree.h>
#include <test/tools/libtesteth/TestOutputHelper.h>
#include <boost/test/unit_test.hpp>

using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace dev::test;
using namespace dev::p2p;
namespace fs = boost::filesystem;

class TestClientFixture : public TestOutputHelperFixture
{
public:
TestClientFixture()
{
ChainParams chainParams;
chainParams.sealEngineName = "NoProof";
chainParams.allowFutureBlocks = true;

fs::path dir = fs::temp_directory_path();

string listenIP = "127.0.0.1";
unsigned short listenPort = 30303;
auto netPrefs = NetworkPreferences(listenIP, listenPort, false);
netPrefs.discovery = false;
netPrefs.pin = false;

auto nodesState = contents(dir / fs::path("network.rlp"));
bool testingMode = true;
m_web3.reset(new dev::WebThreeDirect(WebThreeDirect::composeClientVersion("eth"), dir, dir,
chainParams, WithExisting::Kill, {"eth"}, netPrefs, &nodesState, testingMode));
}

dev::WebThreeDirect* getWeb3() { return m_web3.get(); }

private:
std::unique_ptr<dev::WebThreeDirect> m_web3;
};

// genesis config string from solidity
static std::string const c_configString = R"(
{
"sealEngine": "NoProof",
"params": {
"accountStartNonce": "0x00",
"maximumExtraDataSize": "0x1000000",
"blockReward": "0x",
"allowFutureBlocks": true,
"homesteadForkBlock": "0x00",
"EIP150ForkBlock": "0x00",
"EIP158ForkBlock": "0x00"
},
"genesis": {
"author": "0000000000000010000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x",
"gasLimit": "0x1000000000000"
},
"accounts": {
"0000000000000000000000000000000000000001": { "wei": "1", "precompiled": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } },
"0000000000000000000000000000000000000002": { "wei": "1", "precompiled": { "name": "sha256", "linear": { "base": 60, "word": 12 } } },
"0000000000000000000000000000000000000003": { "wei": "1", "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } },
"0000000000000000000000000000000000000004": { "wei": "1", "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } },
"0000000000000000000000000000000000000005": { "wei": "1", "precompiled": { "name": "modexp" } },
"0000000000000000000000000000000000000006": { "wei": "1", "precompiled": { "name": "alt_bn128_G1_add", "linear": { "base": 500, "word": 0 } } },
"0000000000000000000000000000000000000007": { "wei": "1", "precompiled": { "name": "alt_bn128_G1_mul", "linear": { "base": 40000, "word": 0 } } },
"0000000000000000000000000000000000000008": { "wei": "1", "precompiled": { "name": "alt_bn128_pairing_product" } }
}
}
)";


BOOST_FIXTURE_TEST_SUITE(ClientTestSuite, TestClientFixture)

BOOST_AUTO_TEST_CASE(ClientTest_setChainParamsAuthor)
{
ClientTest* testClient = asClientTest(getWeb3()->ethereum());
BOOST_CHECK_EQUAL(testClient->author(), Address("0000000000000000000000000000000000000000"));
testClient->setChainParams(c_configString);
BOOST_CHECK_EQUAL(testClient->author(), Address("0000000000000010000000000000000000000000"));
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 740da50

Please sign in to comment.