Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/src/cln_grpc_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class GRPCClient extends LightningClient {
{required ListfundsRequest params, T Function(Map)? onDecode}) async {
/// request to server
var response = await stub.listFunds(params);
LogManager.getInstance.debug("response received by GRPC server: $response");
if (onDecode != null) {
return onDecode(toEncode(response.toProto3Json()));
}
Expand Down
2 changes: 1 addition & 1 deletion test/cln_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void main() {
};
var boltString = await unixCient.simpleCall("invoice", params: params);
try {
var response = await client.call<PayProxy, PayResponse>(
var _ = await client.call<PayProxy, PayResponse>(
method: "pay",
params: PayProxy.build(invoice: boltString["bolt11"]));
await client.close();
Expand Down
31 changes: 31 additions & 0 deletions test/cln_grpc_test.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'dart:io';

import 'package:cln_common/cln_common.dart';
import 'package:cln_grpc/cln_grpc.dart';
import 'package:test/test.dart';

import 'model/model.dart';

void main() {
var env = Platform.environment;
var tlsPath = env['TLS_PATH']!;
Expand All @@ -14,5 +17,33 @@ void main() {
expect(response.alias, "clighting4j-node");
await client.close();
});

test('Generic List Funds with decode function', () async {
var client = GRPCClient(rootPath: tlsPath);
var response =
await client.call<CLNListFundsRequest, Map<String, dynamic>>(
method: "listfunds",
params: CLNListFundsRequest.build(),
onDecode: (jsonResponse) {
LogManager.getInstance
.debug("Grpc list funds call returns: $jsonResponse");
return jsonResponse as Map<String, dynamic>;
});
expect(response.isNotEmpty, isTrue);
});

test('Stub List Funds with decode function', () async {
var client = GRPCClient(rootPath: tlsPath);
var response = await client.listFunds(
params: CLNListFundsRequest.build().proxy, onDecode: (json) => json);
expect(response.isNotEmpty, isTrue);
});

test('Stub List Funds without decode function', () async {
var client = GRPCClient(rootPath: tlsPath);
var response = await client.listFunds<ListfundsResponse>(
params: CLNListFundsRequest.build().proxy);
expect(response.channels.isEmpty, isTrue);
});
});
}
17 changes: 17 additions & 0 deletions test/model/model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:cln_common/cln_common.dart';
import 'package:cln_grpc/cln_grpc.dart';

class CLNListFundsRequest extends Serializable {
ListfundsRequest proxy;

CLNListFundsRequest(this.proxy);

factory CLNListFundsRequest.build() =>
CLNListFundsRequest(ListfundsRequest());

@override
Map<String, dynamic> toJSON() => proxy.toProto3Json() as Map<String, dynamic>;

@override
T as<T>() => proxy as T;
}