aboutsummaryrefslogtreecommitdiffstats
path: root/node/node_test.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-07-12 23:47:15 +0800
committerFelix Lange <fjl@twurst.com>2016-07-23 05:21:27 +0800
commit91b769042857f542b2792b23ec407e1c9bd4fe8d (patch)
treef6730b3e85a7ac5ca98f9a716505349958fcacd3 /node/node_test.go
parentbb01bea4e276dad359815c682a2dee730737f4dc (diff)
downloaddexon-91b769042857f542b2792b23ec407e1c9bd4fe8d.tar
dexon-91b769042857f542b2792b23ec407e1c9bd4fe8d.tar.gz
dexon-91b769042857f542b2792b23ec407e1c9bd4fe8d.tar.bz2
dexon-91b769042857f542b2792b23ec407e1c9bd4fe8d.tar.lz
dexon-91b769042857f542b2792b23ec407e1c9bd4fe8d.tar.xz
dexon-91b769042857f542b2792b23ec407e1c9bd4fe8d.tar.zst
dexon-91b769042857f542b2792b23ec407e1c9bd4fe8d.zip
rpc: add new client, use it everywhere
The new client implementation supports concurrent requests, subscriptions and replaces the various ad hoc RPC clients throughout go-ethereum.
Diffstat (limited to 'node/node_test.go')
-rw-r--r--node/node_test.go34
1 files changed, 18 insertions, 16 deletions
diff --git a/node/node_test.go b/node/node_test.go
index 372fc6b10..d9b26453b 100644
--- a/node/node_test.go
+++ b/node/node_test.go
@@ -507,21 +507,27 @@ func TestAPIGather(t *testing.T) {
}
// Register a batch of services with some configured APIs
calls := make(chan string, 1)
-
+ makeAPI := func(result string) *OneMethodApi {
+ return &OneMethodApi{fun: func() { calls <- result }}
+ }
services := map[string]struct {
APIs []rpc.API
Maker InstrumentingWrapper
}{
- "Zero APIs": {[]rpc.API{}, InstrumentedServiceMakerA},
- "Single API": {[]rpc.API{
- {"single", "1", &OneMethodApi{fun: func() { calls <- "single.v1" }}, true},
- }, InstrumentedServiceMakerB},
- "Many APIs": {[]rpc.API{
- {"multi", "1", &OneMethodApi{fun: func() { calls <- "multi.v1" }}, true},
- {"multi.v2", "2", &OneMethodApi{fun: func() { calls <- "multi.v2" }}, true},
- {"multi.v2.nested", "2", &OneMethodApi{fun: func() { calls <- "multi.v2.nested" }}, true},
- }, InstrumentedServiceMakerC},
+ "Zero APIs": {
+ []rpc.API{}, InstrumentedServiceMakerA},
+ "Single API": {
+ []rpc.API{
+ {Namespace: "single", Version: "1", Service: makeAPI("single.v1"), Public: true},
+ }, InstrumentedServiceMakerB},
+ "Many APIs": {
+ []rpc.API{
+ {Namespace: "multi", Version: "1", Service: makeAPI("multi.v1"), Public: true},
+ {Namespace: "multi.v2", Version: "2", Service: makeAPI("multi.v2"), Public: true},
+ {Namespace: "multi.v2.nested", Version: "2", Service: makeAPI("multi.v2.nested"), Public: true},
+ }, InstrumentedServiceMakerC},
}
+
for id, config := range services {
config := config
constructor := func(*ServiceContext) (Service, error) {
@@ -554,12 +560,8 @@ func TestAPIGather(t *testing.T) {
{"multi.v2.nested_theOneMethod", "multi.v2.nested"},
}
for i, test := range tests {
- if err := client.Send(rpc.JSONRequest{Id: []byte("1"), Version: "2.0", Method: test.Method}); err != nil {
- t.Fatalf("test %d: failed to send API request: %v", i, err)
- }
- reply := new(rpc.JSONSuccessResponse)
- if err := client.Recv(reply); err != nil {
- t.Fatalf("test %d: failed to read API reply: %v", i, err)
+ if err := client.Call(nil, test.Method); err != nil {
+ t.Errorf("test %d: API request failed: %v", i, err)
}
select {
case result := <-calls: