forked from peercoin/dart_coin_rpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection_test.dart
100 lines (99 loc) · 2.19 KB
/
connection_test.dart
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import 'package:dart_coin_rpc/dart_coin_rpc.dart';
import 'package:test/test.dart';
void main() async {
RPCClient client = RPCClient(
username: 'rpc',
password: 'password',
port: 9902,
host: '127.0.0.1',
useSSL: false,
);
group(
'success',
() {
test(
'try call with parameters',
() async {
var res = await client.call(
'validateaddress',
["p92W3t7YkKfQEPDb7cG9jQ6iMh7cpKLvwK"],
) as Map;
assert(res["isvalid"] == true);
},
);
test(
'try call without parameters',
() async {
var res = await client.call('help') as String;
assert(res.contains('walletlock'));
},
);
},
);
group(
'failure',
() {
test(
'try wrong credentials',
() async {
var client = RPCClient(
username: 'rpc',
password: 'verywrongpassword',
port: 9902,
host: '127.0.0.1',
useSSL: false,
);
expect(
() async => await client.call('help'),
throwsA(
isA<HTTPException>(),
),
);
},
);
test(
'try wrong port',
() async {
var client = RPCClient(
username: 'rpc',
password: 'verywrongpassword',
port: 9999,
host: '127.0.0.1',
useSSL: false,
);
expect(
() async => await client.call('help'),
throwsA(
isA<HTTPException>(),
),
);
},
);
test(
'try invalid method',
() async {
expect(
() async => await client.call('helpwontbeprovided'),
throwsA(
isA<RPCException>(),
),
);
},
);
test(
'try sendrawtransaction with invalid hex',
() async {
expect(
() async => await client.call(
'sendrawtransaction',
["asdf"],
),
throwsA(
isA<RPCException>(),
),
);
},
);
},
);
}