Skip to content

Commit 5ce4437

Browse files
committed
add test for disconnect method
1 parent 31a5593 commit 5ce4437

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

packages/tfchain_client/lib/src/client.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ class QueryClient {
7474
}
7575

7676
Future<void> disconnect() async {
77-
await api.disconnect();
77+
if (provider!.isConnected()) {
78+
await api.disconnect();
79+
}
7880
}
7981
}
8082

packages/tfchain_client/test/client_test.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ void main() {
4242
expect(queryClient.api, isNotNull);
4343
});
4444

45-
// TODO: How to test disconnect ??
45+
test('Disconnect', () async {
46+
await queryClient.disconnect();
47+
expect(false, queryClient.provider!.isConnected());
48+
});
4649
});
4750

4851
group("Full Client Tests", () {
@@ -78,5 +81,10 @@ void main() {
7881
expect(client.provider, isA<WsProvider>());
7982
expect(client.api, isNotNull);
8083
});
84+
85+
test('Disconnect', () async {
86+
await client.disconnect();
87+
expect(false, client.provider!.isConnected());
88+
});
8189
});
8290
}

packages/tfchain_client/test/contracts_test.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,16 @@ void main() {
134134
});
135135

136136
// TODO:
137-
// test('Test Create Name Contract then cancel it', () async {
138-
// BigInt? contractId = await client.contracts.createName(name: "xxx");
139-
// expect(contractId, isNotNull);
140-
// await Future.delayed(Duration(seconds: 5));
141-
// try {
142-
// await client.contracts.cancel(contractId: contractId!);
143-
// } catch (error) {
144-
// expect(error, isNull);
145-
// }
146-
// });
137+
test('Test Create Name Contract then cancel it', () async {
138+
BigInt? contractId = await client.contracts.createName(name: "xxx");
139+
expect(contractId, isNotNull);
140+
await Future.delayed(Duration(seconds: 5));
141+
try {
142+
await client.contracts.cancel(contractId: contractId!);
143+
} catch (error) {
144+
expect(error, isNull);
145+
}
146+
});
147147

148148
test('Test Create Rent Contract with no solution provider', () async {
149149
try {

0 commit comments

Comments
 (0)