diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2014-10-14 19:32:27 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2014-10-14 19:32:27 +0800 |
commit | b5e22cad46fa136f9ff6e57a74349b50ece34e44 (patch) | |
tree | e564f7c870ea085af5333adf2d66d150109a1c02 | |
parent | 25d71c1167304f59ed9e5b845475d74ebd292362 (diff) | |
download | dexon-solidity-b5e22cad46fa136f9ff6e57a74349b50ece34e44.tar.gz dexon-solidity-b5e22cad46fa136f9ff6e57a74349b50ece34e44.tar.zst dexon-solidity-b5e22cad46fa136f9ff6e57a74349b50ece34e44.zip |
stateless tests
-rw-r--r-- | jsonrpc.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/jsonrpc.cpp b/jsonrpc.cpp index 9ef1e42d..f04e3109 100644 --- a/jsonrpc.cpp +++ b/jsonrpc.cpp @@ -27,8 +27,6 @@ string name = "Ethereum(++) tests"; string dbPath; dev::WebThreeDirect web3(name, dbPath, true); -std::vector<dev::KeyPair> keys = {KeyPair::create()}; - auto_ptr<EthStubServer> jsonrpcServer; auto_ptr<EthStubClient> jsonrpcClient; @@ -41,7 +39,6 @@ struct JsonrpcFixture { web3.setIdealPeerCount(5); web3.ethereum()->setForceMining(true); jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::CorsHttpServer(8080), web3)); - jsonrpcServer->setKeys(keys); jsonrpcServer->StartListening(); jsonrpcClient = auto_ptr<EthStubClient>(new EthStubClient(new jsonrpc::HttpClient("http://localhost:8080"))); @@ -57,7 +54,8 @@ BOOST_GLOBAL_FIXTURE(JsonrpcFixture) BOOST_AUTO_TEST_CASE(jsonrpc_balanceAt) { cnote << "Testing jsonrpc balanceAt..."; - auto address = keys[0].address(); + dev::KeyPair key = KeyPair::create(); + auto address = key.address(); string balance = jsonrpcClient->balanceAt(toJS(address), 0); BOOST_CHECK_EQUAL(jsToDecimal(toJS(web3.ethereum()->balanceAt(address))), balance); } @@ -80,7 +78,8 @@ BOOST_AUTO_TEST_CASE(jsonrpc_coinbase) BOOST_AUTO_TEST_CASE(jsonrpc_countAt) { cnote << "Testing jsonrpc countAt..."; - auto address = keys[0].address(); + dev::KeyPair key = KeyPair::create(); + auto address = key.address(); double countAt = jsonrpcClient->countAt(toJS(address), 0); BOOST_CHECK_EQUAL(countAt, (double)(uint64_t)web3.ethereum()->countAt(address, 0)); } @@ -140,14 +139,20 @@ BOOST_AUTO_TEST_CASE(jsonrpc_isMining) BOOST_AUTO_TEST_CASE(jsonrpc_key) { cnote << "Testing jsonrpc key..."; - string key = jsonrpcClient->key(); - BOOST_CHECK_EQUAL(jsToSecret(key), keys[0].secret()); + dev::KeyPair key = KeyPair::create(); + jsonrpcServer->setKeys({key}); + string clientSecret = jsonrpcClient->key(); + jsonrpcServer->setKeys({}); + BOOST_CHECK_EQUAL(jsToSecret(clientSecret), key.secret()); } BOOST_AUTO_TEST_CASE(jsonrpc_keys) { cnote << "Testing jsonrpc keys..."; + std::vector <dev::KeyPair> keys = {KeyPair::create(), KeyPair::create()}; + jsonrpcServer->setKeys(keys); Json::Value k = jsonrpcClient->keys(); + jsonrpcServer->setKeys({}); BOOST_CHECK_EQUAL(k.isArray(), true); BOOST_CHECK_EQUAL(k.size(), keys.size()); for (unsigned i = 0; i < k.size(); i++) @@ -222,7 +227,8 @@ BOOST_AUTO_TEST_CASE(jsonrpc_sha3) BOOST_AUTO_TEST_CASE(jsonrpc_stateAt) { cnote << "Testing jsonrpc stateAt..."; - auto address = keys[0].address(); + dev::KeyPair key = KeyPair::create(); + auto address = key.address(); string stateAt = jsonrpcClient->stateAt(toJS(address), 0, "0"); BOOST_CHECK_EQUAL(toJS(web3.ethereum()->stateAt(address, jsToU256("0"), 0)), stateAt); } @@ -256,18 +262,20 @@ BOOST_AUTO_TEST_CASE(jsonrpc_toFixed) BOOST_AUTO_TEST_CASE(jsonrpc_transact) { cnote << "Testing jsonrpc transact..."; - - web3.ethereum()->setAddress(keys[0].address()); + dev::KeyPair key = KeyPair::create(); + auto address = key.address(); auto receiver = KeyPair::create(); + + web3.ethereum()->setAddress(address); dev::eth::mine(*(web3.ethereum()), 1); - auto balance = web3.ethereum()->balanceAt(keys[0].address(), 0); + auto balance = web3.ethereum()->balanceAt(address, 0); BOOST_REQUIRE(balance > 0); auto txAmount = balance / 2u; auto gasPrice = 10 * dev::eth::szabo; auto gas = dev::eth::c_txGas; Json::Value t; - t["from"] = toJS(keys[0].secret()); + t["from"] = toJS(key.secret()); t["value"] = toJS(txAmount); t["to"] = toJS(receiver.address()); t["data"] = toJS(bytes()); |