aboutsummaryrefslogtreecommitdiffstats
path: root/jsonrpc.cpp
blob: 101e3d25f6690f9af1b6ebf9d073e314e2f15b52 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76


#if ETH_JSONRPC && 1

#include <boost/test/unit_test.hpp>
#include <libdevcore/Log.h>
#include <libdevcore/CommonIO.h>
#include <libdevcore/CommonJS.h>
#include <libwebthree/WebThree.h>
#include <libethrpc/EthStubServer.h>
#include <jsonrpc/connectors/httpserver.h>
#include <jsonrpc/connectors/httpclient.h>
#include "JsonSpiritHeaders.h"
#include "ethstubclient.h"

using namespace std;
using namespace dev;
using namespace dev::eth;
namespace js = json_spirit;


namespace jsonrpc_tests {

KeyPair us;
auto_ptr<EthStubServer> jsonrpcServer;
auto_ptr<EthStubClient> jsonrpcClient;


struct JsonrpcFixture  {
    JsonrpcFixture()
    {
        cnote << "setup jsonrpc";
        string name = "Ethereum(++) tests";
        string dbPath;
        dev::WebThreeDirect web3(name, dbPath);
        web3.setIdealPeerCount(5);
        
        us = KeyPair::create();
        jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::HttpServer(8080), web3));
        jsonrpcServer->setKeys({us});
        jsonrpcServer->StartListening();
        
        jsonrpcClient = auto_ptr<EthStubClient>(new EthStubClient(new jsonrpc::HttpClient("http://localhost:8080")));
    }
    ~JsonrpcFixture()
    {
        cnote << "teardown jsonrpc";
    }
};

BOOST_GLOBAL_FIXTURE(JsonrpcFixture)

BOOST_AUTO_TEST_CASE(jsonrpc_key)
{
    cnote << "Testing jsonrpc key...";
    Json::Value key = jsonrpcClient->key();
    BOOST_CHECK_EQUAL(key.isString(), true);
    BOOST_CHECK_EQUAL(jsToSecret(key.asString()), us.secret());
}
    
BOOST_AUTO_TEST_CASE(jsonrpc_keys)
{
    cnote << "Testing jsonrpc keys...";
    Json::Value keys = jsonrpcClient->keys();
    BOOST_CHECK_EQUAL(keys.isArray(), true);
    BOOST_CHECK_EQUAL(keys.size(),  1);
    BOOST_CHECK_EQUAL(jsToSecret(keys[0u].asString()) , us.secret());
}


}

#endif