mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
stateless tests
This commit is contained in:
parent
25d71c1167
commit
b5e22cad46
32
jsonrpc.cpp
32
jsonrpc.cpp
@ -27,8 +27,6 @@ string name = "Ethereum(++) tests";
|
|||||||
string dbPath;
|
string dbPath;
|
||||||
dev::WebThreeDirect web3(name, dbPath, true);
|
dev::WebThreeDirect web3(name, dbPath, true);
|
||||||
|
|
||||||
std::vector<dev::KeyPair> keys = {KeyPair::create()};
|
|
||||||
|
|
||||||
auto_ptr<EthStubServer> jsonrpcServer;
|
auto_ptr<EthStubServer> jsonrpcServer;
|
||||||
auto_ptr<EthStubClient> jsonrpcClient;
|
auto_ptr<EthStubClient> jsonrpcClient;
|
||||||
|
|
||||||
@ -41,7 +39,6 @@ struct JsonrpcFixture {
|
|||||||
web3.setIdealPeerCount(5);
|
web3.setIdealPeerCount(5);
|
||||||
web3.ethereum()->setForceMining(true);
|
web3.ethereum()->setForceMining(true);
|
||||||
jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::CorsHttpServer(8080), web3));
|
jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::CorsHttpServer(8080), web3));
|
||||||
jsonrpcServer->setKeys(keys);
|
|
||||||
jsonrpcServer->StartListening();
|
jsonrpcServer->StartListening();
|
||||||
|
|
||||||
jsonrpcClient = auto_ptr<EthStubClient>(new EthStubClient(new jsonrpc::HttpClient("http://localhost:8080")));
|
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)
|
BOOST_AUTO_TEST_CASE(jsonrpc_balanceAt)
|
||||||
{
|
{
|
||||||
cnote << "Testing 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);
|
string balance = jsonrpcClient->balanceAt(toJS(address), 0);
|
||||||
BOOST_CHECK_EQUAL(jsToDecimal(toJS(web3.ethereum()->balanceAt(address))), balance);
|
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)
|
BOOST_AUTO_TEST_CASE(jsonrpc_countAt)
|
||||||
{
|
{
|
||||||
cnote << "Testing 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);
|
double countAt = jsonrpcClient->countAt(toJS(address), 0);
|
||||||
BOOST_CHECK_EQUAL(countAt, (double)(uint64_t)web3.ethereum()->countAt(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)
|
BOOST_AUTO_TEST_CASE(jsonrpc_key)
|
||||||
{
|
{
|
||||||
cnote << "Testing jsonrpc key...";
|
cnote << "Testing jsonrpc key...";
|
||||||
string key = jsonrpcClient->key();
|
dev::KeyPair key = KeyPair::create();
|
||||||
BOOST_CHECK_EQUAL(jsToSecret(key), keys[0].secret());
|
jsonrpcServer->setKeys({key});
|
||||||
|
string clientSecret = jsonrpcClient->key();
|
||||||
|
jsonrpcServer->setKeys({});
|
||||||
|
BOOST_CHECK_EQUAL(jsToSecret(clientSecret), key.secret());
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(jsonrpc_keys)
|
BOOST_AUTO_TEST_CASE(jsonrpc_keys)
|
||||||
{
|
{
|
||||||
cnote << "Testing jsonrpc keys...";
|
cnote << "Testing jsonrpc keys...";
|
||||||
|
std::vector <dev::KeyPair> keys = {KeyPair::create(), KeyPair::create()};
|
||||||
|
jsonrpcServer->setKeys(keys);
|
||||||
Json::Value k = jsonrpcClient->keys();
|
Json::Value k = jsonrpcClient->keys();
|
||||||
|
jsonrpcServer->setKeys({});
|
||||||
BOOST_CHECK_EQUAL(k.isArray(), true);
|
BOOST_CHECK_EQUAL(k.isArray(), true);
|
||||||
BOOST_CHECK_EQUAL(k.size(), keys.size());
|
BOOST_CHECK_EQUAL(k.size(), keys.size());
|
||||||
for (unsigned i = 0; i < k.size(); i++)
|
for (unsigned i = 0; i < k.size(); i++)
|
||||||
@ -222,7 +227,8 @@ BOOST_AUTO_TEST_CASE(jsonrpc_sha3)
|
|||||||
BOOST_AUTO_TEST_CASE(jsonrpc_stateAt)
|
BOOST_AUTO_TEST_CASE(jsonrpc_stateAt)
|
||||||
{
|
{
|
||||||
cnote << "Testing 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");
|
string stateAt = jsonrpcClient->stateAt(toJS(address), 0, "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);
|
||||||
}
|
}
|
||||||
@ -256,18 +262,20 @@ BOOST_AUTO_TEST_CASE(jsonrpc_toFixed)
|
|||||||
BOOST_AUTO_TEST_CASE(jsonrpc_transact)
|
BOOST_AUTO_TEST_CASE(jsonrpc_transact)
|
||||||
{
|
{
|
||||||
cnote << "Testing jsonrpc transact...";
|
cnote << "Testing jsonrpc transact...";
|
||||||
|
dev::KeyPair key = KeyPair::create();
|
||||||
web3.ethereum()->setAddress(keys[0].address());
|
auto address = key.address();
|
||||||
auto receiver = KeyPair::create();
|
auto receiver = KeyPair::create();
|
||||||
|
|
||||||
|
web3.ethereum()->setAddress(address);
|
||||||
dev::eth::mine(*(web3.ethereum()), 1);
|
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);
|
BOOST_REQUIRE(balance > 0);
|
||||||
auto txAmount = balance / 2u;
|
auto txAmount = balance / 2u;
|
||||||
auto gasPrice = 10 * dev::eth::szabo;
|
auto gasPrice = 10 * dev::eth::szabo;
|
||||||
auto gas = dev::eth::c_txGas;
|
auto gas = dev::eth::c_txGas;
|
||||||
|
|
||||||
Json::Value t;
|
Json::Value t;
|
||||||
t["from"] = toJS(keys[0].secret());
|
t["from"] = toJS(key.secret());
|
||||||
t["value"] = toJS(txAmount);
|
t["value"] = toJS(txAmount);
|
||||||
t["to"] = toJS(receiver.address());
|
t["to"] = toJS(receiver.address());
|
||||||
t["data"] = toJS(bytes());
|
t["data"] = toJS(bytes());
|
||||||
|
Loading…
Reference in New Issue
Block a user