aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Jentzsch <jentzsch.software@gmail.com>2014-11-05 06:44:50 +0800
committerChristoph Jentzsch <jentzsch.software@gmail.com>2014-11-05 06:44:50 +0800
commit1fb562732e0b6fc59e709bc7f42c2881e86cf5b3 (patch)
treed1334f30ec97a3439a103f2ae15140865ed38a54
parenta6f297a27d204ac988231ec533ec07df744922bd (diff)
parent2d9771e4fedc4181080dc8d28b45abb51ddf46cf (diff)
downloaddexon-solidity-1fb562732e0b6fc59e709bc7f42c2881e86cf5b3.tar.gz
dexon-solidity-1fb562732e0b6fc59e709bc7f42c2881e86cf5b3.tar.zst
dexon-solidity-1fb562732e0b6fc59e709bc7f42c2881e86cf5b3.zip
Merge remote-tracking branch 'upstream/develop' into NewStateTests
-rw-r--r--jsonrpc.cpp96
1 files changed, 45 insertions, 51 deletions
diff --git a/jsonrpc.cpp b/jsonrpc.cpp
index 033339ec..68c30734 100644
--- a/jsonrpc.cpp
+++ b/jsonrpc.cpp
@@ -43,44 +43,39 @@ using namespace dev;
using namespace dev::eth;
namespace js = json_spirit;
-namespace jsonrpc_tests
-{
-
-string name = "Ethereum(++) tests";
-string dbPath;
-auto s = set<string>{"eth", "shh"};
-dev::p2p::NetworkPreferences np(30303, std::string(), false);
-dev::WebThreeDirect web3(name, dbPath, true, s, np);
-
+WebThreeDirect *web3;
unique_ptr<WebThreeStubServer> jsonrpcServer;
unique_ptr<WebThreeStubClient> jsonrpcClient;
-struct JsonrpcFixture {
- JsonrpcFixture()
+struct Setup
+{
+ Setup()
{
- cnote << "setup jsonrpc";
+ static bool setup = false;
+ if (setup)
+ return;
+ setup = true;
- web3.setIdealPeerCount(5);
- web3.ethereum()->setForceMining(true);
- jsonrpcServer = unique_ptr<WebThreeStubServer>(new WebThreeStubServer(new jsonrpc::CorsHttpServer(8080), web3, {}));
+ dev::p2p::NetworkPreferences nprefs(30303, std::string(), false);
+ web3 = new WebThreeDirect("Ethereum(++) tests", "", true, {"eth", "shh"}, nprefs);
+
+ web3->setIdealPeerCount(5);
+ web3->ethereum()->setForceMining(true);
+ jsonrpcServer = unique_ptr<WebThreeStubServer>(new WebThreeStubServer(new jsonrpc::CorsHttpServer(8080), *web3, {}));
jsonrpcServer->setIdentities({});
jsonrpcServer->StartListening();
jsonrpcClient = unique_ptr<WebThreeStubClient>(new WebThreeStubClient(new jsonrpc::HttpClient("http://localhost:8080")));
}
- ~JsonrpcFixture()
- {
- cnote << "teardown jsonrpc";
- }
};
-BOOST_GLOBAL_FIXTURE(JsonrpcFixture)
+BOOST_FIXTURE_TEST_SUITE(environment, Setup)
BOOST_AUTO_TEST_CASE(jsonrpc_defaultBlock)
{
cnote << "Testing jsonrpc defaultBlock...";
int defaultBlock = jsonrpcClient->defaultBlock();
- BOOST_CHECK_EQUAL(defaultBlock, web3.ethereum()->getDefault());
+ BOOST_CHECK_EQUAL(defaultBlock, web3->ethereum()->getDefault());
}
BOOST_AUTO_TEST_CASE(jsonrpc_gasPrice)
@@ -94,26 +89,26 @@ BOOST_AUTO_TEST_CASE(jsonrpc_isListening)
{
cnote << "Testing jsonrpc isListening...";
- web3.startNetwork();
+ web3->startNetwork();
bool listeningOn = jsonrpcClient->listening();
- BOOST_CHECK_EQUAL(listeningOn, web3.isNetworkStarted());
+ BOOST_CHECK_EQUAL(listeningOn, web3->isNetworkStarted());
- web3.stopNetwork();
+ web3->stopNetwork();
bool listeningOff = jsonrpcClient->listening();
- BOOST_CHECK_EQUAL(listeningOff, web3.isNetworkStarted());
+ BOOST_CHECK_EQUAL(listeningOff, web3->isNetworkStarted());
}
BOOST_AUTO_TEST_CASE(jsonrpc_isMining)
{
cnote << "Testing jsonrpc isMining...";
- web3.ethereum()->startMining();
+ web3->ethereum()->startMining();
bool miningOn = jsonrpcClient->mining();
- BOOST_CHECK_EQUAL(miningOn, web3.ethereum()->isMining());
+ BOOST_CHECK_EQUAL(miningOn, web3->ethereum()->isMining());
- web3.ethereum()->stopMining();
+ web3->ethereum()->stopMining();
bool miningOff = jsonrpcClient->mining();
- BOOST_CHECK_EQUAL(miningOff, web3.ethereum()->isMining());
+ BOOST_CHECK_EQUAL(miningOff, web3->ethereum()->isMining());
}
BOOST_AUTO_TEST_CASE(jsonrpc_accounts)
@@ -139,18 +134,18 @@ BOOST_AUTO_TEST_CASE(jsonrpc_number)
{
cnote << "Testing jsonrpc number2...";
int number = jsonrpcClient->number();
- BOOST_CHECK_EQUAL(number, web3.ethereum()->number() + 1);
- dev::eth::mine(*(web3.ethereum()), 1);
+ BOOST_CHECK_EQUAL(number, web3->ethereum()->number() + 1);
+ dev::eth::mine(*(web3->ethereum()), 1);
int numberAfter = jsonrpcClient->number();
BOOST_CHECK_EQUAL(number + 1, numberAfter);
- BOOST_CHECK_EQUAL(numberAfter, web3.ethereum()->number() + 1);
+ BOOST_CHECK_EQUAL(numberAfter, web3->ethereum()->number() + 1);
}
BOOST_AUTO_TEST_CASE(jsonrpc_peerCount)
{
cnote << "Testing jsonrpc peerCount...";
int peerCount = jsonrpcClient->peerCount();
- BOOST_CHECK_EQUAL(web3.peerCount(), peerCount);
+ BOOST_CHECK_EQUAL(web3->peerCount(), peerCount);
}
BOOST_AUTO_TEST_CASE(jsonrpc_setListening)
@@ -158,10 +153,10 @@ BOOST_AUTO_TEST_CASE(jsonrpc_setListening)
cnote << "Testing jsonrpc setListening...";
jsonrpcClient->setListening(true);
- BOOST_CHECK_EQUAL(web3.isNetworkStarted(), true);
+ BOOST_CHECK_EQUAL(web3->isNetworkStarted(), true);
jsonrpcClient->setListening(false);
- BOOST_CHECK_EQUAL(web3.isNetworkStarted(), false);
+ BOOST_CHECK_EQUAL(web3->isNetworkStarted(), false);
}
BOOST_AUTO_TEST_CASE(jsonrpc_setMining)
@@ -169,10 +164,10 @@ BOOST_AUTO_TEST_CASE(jsonrpc_setMining)
cnote << "Testing jsonrpc setMining...";
jsonrpcClient->setMining(true);
- BOOST_CHECK_EQUAL(web3.ethereum()->isMining(), true);
+ BOOST_CHECK_EQUAL(web3->ethereum()->isMining(), true);
jsonrpcClient->setMining(false);
- BOOST_CHECK_EQUAL(web3.ethereum()->isMining(), false);
+ BOOST_CHECK_EQUAL(web3->ethereum()->isMining(), false);
}
BOOST_AUTO_TEST_CASE(jsonrpc_stateAt)
@@ -181,36 +176,36 @@ BOOST_AUTO_TEST_CASE(jsonrpc_stateAt)
dev::KeyPair key = KeyPair::create();
auto address = key.address();
string stateAt = jsonrpcClient->stateAt(toJS(address), "0");
- BOOST_CHECK_EQUAL(toJS(web3.ethereum()->stateAt(address, jsToU256("0"), 0)), stateAt);
+ BOOST_CHECK_EQUAL(toJS(web3->ethereum()->stateAt(address, jsToU256("0"), 0)), stateAt);
}
BOOST_AUTO_TEST_CASE(jsonrpc_transact)
{
cnote << "Testing jsonrpc transact...";
string coinbase = jsonrpcClient->coinbase();
- BOOST_CHECK_EQUAL(jsToAddress(coinbase), web3.ethereum()->address());
+ BOOST_CHECK_EQUAL(jsToAddress(coinbase), web3->ethereum()->address());
dev::KeyPair key = KeyPair::create();
auto address = key.address();
auto receiver = KeyPair::create();
- web3.ethereum()->setAddress(address);
+ web3->ethereum()->setAddress(address);
coinbase = jsonrpcClient->coinbase();
- BOOST_CHECK_EQUAL(jsToAddress(coinbase), web3.ethereum()->address());
+ BOOST_CHECK_EQUAL(jsToAddress(coinbase), web3->ethereum()->address());
BOOST_CHECK_EQUAL(jsToAddress(coinbase), address);
jsonrpcServer->setAccounts({key});
- auto balance = web3.ethereum()->balanceAt(address, 0);
+ auto balance = web3->ethereum()->balanceAt(address, 0);
string balanceString = jsonrpcClient->balanceAt(toJS(address));
double countAt = jsonrpcClient->countAt(toJS(address));
- BOOST_CHECK_EQUAL(countAt, (double)(uint64_t)web3.ethereum()->countAt(address));
+ BOOST_CHECK_EQUAL(countAt, (double)(uint64_t)web3->ethereum()->countAt(address));
BOOST_CHECK_EQUAL(countAt, 0);
BOOST_CHECK_EQUAL(toJS(balance), balanceString);
BOOST_CHECK_EQUAL(jsToDecimal(balanceString), "0");
- dev::eth::mine(*(web3.ethereum()), 1);
- balance = web3.ethereum()->balanceAt(address, 0);
+ dev::eth::mine(*(web3->ethereum()), 1);
+ balance = web3->ethereum()->balanceAt(address, 0);
balanceString = jsonrpcClient->balanceAt(toJS(address));
BOOST_CHECK_EQUAL(toJS(balance), balanceString);
@@ -230,21 +225,20 @@ BOOST_AUTO_TEST_CASE(jsonrpc_transact)
jsonrpcClient->transact(t);
jsonrpcServer->setAccounts({});
- dev::eth::mine(*(web3.ethereum()), 1);
+ dev::eth::mine(*(web3->ethereum()), 1);
countAt = jsonrpcClient->countAt(toJS(address));
- auto balance2 = web3.ethereum()->balanceAt(receiver.address());
+ auto balance2 = web3->ethereum()->balanceAt(receiver.address());
string balanceString2 = jsonrpcClient->balanceAt(toJS(receiver.address()));
- BOOST_CHECK_EQUAL(countAt, (double)(uint64_t)web3.ethereum()->countAt(address));
+ BOOST_CHECK_EQUAL(countAt, (double)(uint64_t)web3->ethereum()->countAt(address));
BOOST_CHECK_EQUAL(countAt, 1);
BOOST_CHECK_EQUAL(toJS(balance2), balanceString2);
BOOST_CHECK_EQUAL(jsToDecimal(balanceString2), "750000000000000000");
BOOST_CHECK_EQUAL(txAmount, balance2);
}
-
-}
-
+
+BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
#endif