Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix net_version #1717

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libweb3jsonrpc/Net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Net::Net( const dev::eth::ChainParams& _chainParams ) : m_chainParams( _chainPar
// TODO Ask here real values from consensus/broadcast

std::string Net::net_version() {
return toJS( m_chainParams.chainID );
return toString( m_chainParams.chainID );
}

std::string Net::net_peerCount() {
Expand Down
23 changes: 20 additions & 3 deletions test/unittests/libweb3jsonrpc/jsonrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <libweb3jsonrpc/Debug.h>
#include <libweb3jsonrpc/Eth.h>
#include <libweb3jsonrpc/ModularServer.h>
// SKALE #include <libweb3jsonrpc/Net.h>
#include <libweb3jsonrpc/Net.h>
#include <libweb3jsonrpc/Test.h>
#include <libweb3jsonrpc/Web3.h>
#include <test/tools/libtesteth/TestHelper.h>
Expand Down Expand Up @@ -329,7 +329,7 @@ struct JsonRpcFixture : public TestOutputHelperFixture {
else
client->setAuthor( chainParams.sChain.blockAuthor );

using FullServer = ModularServer< rpc::EthFace, /* rpc::NetFace,*/ rpc::Web3Face,
using FullServer = ModularServer< rpc::EthFace, rpc::NetFace, rpc::Web3Face,
rpc::AdminEthFace /*, rpc::AdminNetFace*/, rpc::DebugFace, rpc::TestFace >;

accountHolder.reset( new FixedAccountHolder( [&]() { return client.get(); }, {} ) );
Expand All @@ -343,7 +343,7 @@ struct JsonRpcFixture : public TestOutputHelperFixture {

gasPricer = make_shared< eth::TrivialGasPricer >( 0, DefaultGasPrice );

rpcServer.reset( new FullServer( ethFace /*, new rpc::Net(*web3)*/,
rpcServer.reset( new FullServer( ethFace , new rpc::Net( chainParams ),
new rpc::Web3( /*web3->clientVersion()*/ ), // TODO Add real version?
new rpc::AdminEth( *client, *gasPricer, keyManager, *sessionManager.get() ),
/*new rpc::AdminNet(*web3, *sessionManager), */ new rpc::Debug( *client ),
Expand Down Expand Up @@ -502,6 +502,23 @@ BOOST_AUTO_TEST_CASE( jsonrpc_number ) {
// BOOST_CHECK_EQUAL(web3->isNetworkStarted(), false);
//}

BOOST_AUTO_TEST_CASE( jsonrpc_netVersion )
{
std::string _config = c_genesisConfigString;
Json::Value ret;
Json::Reader().parse( _config, ret );

// Set chainID = 65535
ret["params"]["chainID"] = "0xffff";

Json::FastWriter fastWriter;
std::string config = fastWriter.write( ret );
JsonRpcFixture fixture( config );

auto version = fixture.rpcClient->net_version();
BOOST_CHECK_EQUAL( version, "65535" );
}

BOOST_AUTO_TEST_CASE( jsonrpc_setMining ) {
JsonRpcFixture fixture;
fixture.rpcClient->admin_eth_setMining( true, fixture.adminSession );
Expand Down
Loading