|
| 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