stack_wallet/test/json_rpc_test.dart

52 lines
1.5 KiB
Dart
Raw Normal View History

2022-08-26 08:11:35 +00:00
import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
2023-05-25 16:27:35 +00:00
import 'package:stackwallet/electrumx_rpc/rpc2.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/utilities/default_nodes.dart';
void main() {
test("REQUIRES INTERNET - JsonRPC.request success", () async {
final jsonRPC = JsonRPC(
host: DefaultNodes.bitcoin.host,
port: DefaultNodes.bitcoin.port,
useSSL: true,
connectionTimeout: const Duration(seconds: 40),
);
const jsonRequestString =
'{"jsonrpc": "2.0", "id": "some id","method": "server.ping","params": []}';
final result = await jsonRPC.request(jsonRequestString);
expect(result, {"jsonrpc": "2.0", "result": null, "id": "some id"});
});
test("JsonRPC.request fails due to SocketException", () async {
final jsonRPC = JsonRPC(
host: "some.bad.address.thingdsfsdfsdaf",
port: 3000,
connectionTimeout: Duration(seconds: 10),
);
const jsonRequestString =
'{"jsonrpc": "2.0", "id": "some id","method": "server.ping","params": []}';
expect(() => jsonRPC.request(jsonRequestString),
throwsA(isA<SocketException>()));
});
test("JsonRPC.request fails due to connection timeout", () async {
final jsonRPC = JsonRPC(
host: "8.8.8.8",
port: 3000,
useSSL: false,
connectionTimeout: const Duration(seconds: 1),
);
const jsonRequestString =
'{"jsonrpc": "2.0", "id": "some id","method": "server.ping","params": []}';
expect(() => jsonRPC.request(jsonRequestString),
throwsA(isA<SocketException>()));
});
}