Skip to content
Merged
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
77 changes: 77 additions & 0 deletions antd-dart/lib/src/generated/antd/v1/health.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import 'dart:core' as $core;

import 'package:fixnum/fixnum.dart' as $fixnum;
import 'package:protobuf/protobuf.dart' as $pb;

export 'package:protobuf/protobuf.dart' show GeneratedMessageGenericExtensions;
Expand Down Expand Up @@ -58,10 +59,24 @@ class HealthCheckResponse extends $pb.GeneratedMessage {
factory HealthCheckResponse({
$core.String? status,
$core.String? network,
$core.String? version,
$core.String? evmNetwork,
$fixnum.Int64? uptimeSeconds,
$core.String? buildCommit,
$core.String? paymentTokenAddress,
$core.String? paymentVaultAddress,
}) {
final result = create();
if (status != null) result.status = status;
if (network != null) result.network = network;
if (version != null) result.version = version;
if (evmNetwork != null) result.evmNetwork = evmNetwork;
if (uptimeSeconds != null) result.uptimeSeconds = uptimeSeconds;
if (buildCommit != null) result.buildCommit = buildCommit;
if (paymentTokenAddress != null)
result.paymentTokenAddress = paymentTokenAddress;
if (paymentVaultAddress != null)
result.paymentVaultAddress = paymentVaultAddress;
return result;
}

Expand All @@ -80,6 +95,14 @@ class HealthCheckResponse extends $pb.GeneratedMessage {
createEmptyInstance: create)
..aOS(1, _omitFieldNames ? '' : 'status')
..aOS(2, _omitFieldNames ? '' : 'network')
..aOS(3, _omitFieldNames ? '' : 'version')
..aOS(4, _omitFieldNames ? '' : 'evmNetwork')
..a<$fixnum.Int64>(
5, _omitFieldNames ? '' : 'uptimeSeconds', $pb.PbFieldType.OU6,
defaultOrMaker: $fixnum.Int64.ZERO)
..aOS(6, _omitFieldNames ? '' : 'buildCommit')
..aOS(7, _omitFieldNames ? '' : 'paymentTokenAddress')
..aOS(8, _omitFieldNames ? '' : 'paymentVaultAddress')
..hasRequiredFields = false;

@$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.')
Expand Down Expand Up @@ -118,6 +141,60 @@ class HealthCheckResponse extends $pb.GeneratedMessage {
$core.bool hasNetwork() => $_has(1);
@$pb.TagNumber(2)
void clearNetwork() => $_clearField(2);

@$pb.TagNumber(3)
$core.String get version => $_getSZ(2);
@$pb.TagNumber(3)
set version($core.String value) => $_setString(2, value);
@$pb.TagNumber(3)
$core.bool hasVersion() => $_has(2);
@$pb.TagNumber(3)
void clearVersion() => $_clearField(3);

@$pb.TagNumber(4)
$core.String get evmNetwork => $_getSZ(3);
@$pb.TagNumber(4)
set evmNetwork($core.String value) => $_setString(3, value);
@$pb.TagNumber(4)
$core.bool hasEvmNetwork() => $_has(3);
@$pb.TagNumber(4)
void clearEvmNetwork() => $_clearField(4);

@$pb.TagNumber(5)
$fixnum.Int64 get uptimeSeconds => $_getI64(4);
@$pb.TagNumber(5)
set uptimeSeconds($fixnum.Int64 value) => $_setInt64(4, value);
@$pb.TagNumber(5)
$core.bool hasUptimeSeconds() => $_has(4);
@$pb.TagNumber(5)
void clearUptimeSeconds() => $_clearField(5);

@$pb.TagNumber(6)
$core.String get buildCommit => $_getSZ(5);
@$pb.TagNumber(6)
set buildCommit($core.String value) => $_setString(5, value);
@$pb.TagNumber(6)
$core.bool hasBuildCommit() => $_has(5);
@$pb.TagNumber(6)
void clearBuildCommit() => $_clearField(6);

@$pb.TagNumber(7)
$core.String get paymentTokenAddress => $_getSZ(6);
@$pb.TagNumber(7)
set paymentTokenAddress($core.String value) => $_setString(6, value);
@$pb.TagNumber(7)
$core.bool hasPaymentTokenAddress() => $_has(6);
@$pb.TagNumber(7)
void clearPaymentTokenAddress() => $_clearField(7);

@$pb.TagNumber(8)
$core.String get paymentVaultAddress => $_getSZ(7);
@$pb.TagNumber(8)
set paymentVaultAddress($core.String value) => $_setString(7, value);
@$pb.TagNumber(8)
$core.bool hasPaymentVaultAddress() => $_has(7);
@$pb.TagNumber(8)
void clearPaymentVaultAddress() => $_clearField(8);
}

const $core.bool _omitFieldNames =
Expand Down
24 changes: 23 additions & 1 deletion antd-dart/lib/src/generated/antd/v1/health.pbjson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,32 @@ const HealthCheckResponse$json = {
'2': [
{'1': 'status', '3': 1, '4': 1, '5': 9, '10': 'status'},
{'1': 'network', '3': 2, '4': 1, '5': 9, '10': 'network'},
{'1': 'version', '3': 3, '4': 1, '5': 9, '10': 'version'},
{'1': 'evm_network', '3': 4, '4': 1, '5': 9, '10': 'evmNetwork'},
{'1': 'uptime_seconds', '3': 5, '4': 1, '5': 4, '10': 'uptimeSeconds'},
{'1': 'build_commit', '3': 6, '4': 1, '5': 9, '10': 'buildCommit'},
{
'1': 'payment_token_address',
'3': 7,
'4': 1,
'5': 9,
'10': 'paymentTokenAddress'
},
{
'1': 'payment_vault_address',
'3': 8,
'4': 1,
'5': 9,
'10': 'paymentVaultAddress'
},
],
};

/// Descriptor for `HealthCheckResponse`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List healthCheckResponseDescriptor = $convert.base64Decode(
'ChNIZWFsdGhDaGVja1Jlc3BvbnNlEhYKBnN0YXR1cxgBIAEoCVIGc3RhdHVzEhgKB25ldHdvcm'
'sYAiABKAlSB25ldHdvcms=');
'sYAiABKAlSB25ldHdvcmsSGAoHdmVyc2lvbhgDIAEoCVIHdmVyc2lvbhIfCgtldm1fbmV0d29y'
'axgEIAEoCVIKZXZtTmV0d29yaxIlCg51cHRpbWVfc2Vjb25kcxgFIAEoBFINdXB0aW1lU2Vjb2'
'5kcxIhCgxidWlsZF9jb21taXQYBiABKAlSC2J1aWxkQ29tbWl0EjIKFXBheW1lbnRfdG9rZW5f'
'YWRkcmVzcxgHIAEoCVITcGF5bWVudFRva2VuQWRkcmVzcxIyChVwYXltZW50X3ZhdWx0X2FkZH'
'Jlc3MYCCABKAlSE3BheW1lbnRWYXVsdEFkZHJlc3M=');
6 changes: 6 additions & 0 deletions antd-dart/lib/src/grpc_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ class GrpcAntdClient {
return HealthStatus(
ok: resp.status == 'ok',
network: resp.network,
version: resp.version,
evmNetwork: resp.evmNetwork,
uptimeSeconds: resp.uptimeSeconds.toInt(),
buildCommit: resp.buildCommit,
paymentTokenAddress: resp.paymentTokenAddress,
paymentVaultAddress: resp.paymentVaultAddress,
);
} on GrpcError catch (e) {
_handleError(e);
Expand Down
44 changes: 42 additions & 2 deletions antd-dart/lib/src/models.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,62 @@
/// HealthStatus is the result of a health check.
///
/// The diagnostic fields ([version], [evmNetwork], [uptimeSeconds],
/// [buildCommit], [paymentTokenAddress], [paymentVaultAddress]) were added in
/// antd 0.4.0. They default to '' / 0 so the class stays usable when talking
/// to a pre-0.4.0 daemon that doesn't report them.
class HealthStatus {
/// Whether the daemon is healthy.
final bool ok;

/// The network the daemon is connected to.
final String network;

const HealthStatus({required this.ok, required this.network});
/// antd crate version, e.g. "0.4.0". Empty when talking to a pre-0.4.0 daemon.
final String version;

/// EVM preset name: "arbitrum-one", "arbitrum-sepolia", "local", "custom".
final String evmNetwork;

/// Seconds since the daemon process started.
final int uptimeSeconds;

/// Short git SHA captured at build time, "" if unknown.
final String buildCommit;

/// Payment token contract address, "" if unconfigured.
final String paymentTokenAddress;

/// Payment vault contract address, "" if unconfigured.
final String paymentVaultAddress;

const HealthStatus({
required this.ok,
required this.network,
this.version = '',
this.evmNetwork = '',
this.uptimeSeconds = 0,
this.buildCommit = '',
this.paymentTokenAddress = '',
this.paymentVaultAddress = '',
});

factory HealthStatus.fromJson(Map<String, dynamic> json) {
return HealthStatus(
ok: json['status'] == 'ok',
network: json['network'] as String? ?? '',
version: json['version'] as String? ?? '',
evmNetwork: json['evm_network'] as String? ?? '',
uptimeSeconds: (json['uptime_seconds'] as num?)?.toInt() ?? 0,
buildCommit: json['build_commit'] as String? ?? '',
paymentTokenAddress: json['payment_token_address'] as String? ?? '',
paymentVaultAddress: json['payment_vault_address'] as String? ?? '',
);
}

@override
String toString() => 'HealthStatus(ok: $ok, network: $network)';
String toString() => 'HealthStatus(ok: $ok, network: $network, '
'version: $version, evmNetwork: $evmNetwork, '
'uptimeSeconds: $uptimeSeconds, buildCommit: $buildCommit)';
}

/// PutResult is the result of a put/create operation.
Expand Down
31 changes: 29 additions & 2 deletions antd-dart/test/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ MockClient mockDaemon() {
switch ('$method $path') {
// Health
case 'GET /health':
body = {'status': 'ok', 'network': 'local'};
body = {
'status': 'ok',
'network': 'local',
'version': '0.4.0',
'evm_network': 'local',
'uptime_seconds': 42,
'build_commit': 'abcdef123456',
'payment_token_address': '0xtoken',
'payment_vault_address': '0xvault',
};
break;

// Data put public
Expand Down Expand Up @@ -123,13 +132,31 @@ MockClient errorDaemon(int statusCode, String errorMessage) {

void main() {
group('Health', () {
test('returns health status', () async {
test('returns health status with all diagnostic fields', () async {
final client = AntdClient(httpClient: mockDaemon());
final health = await client.health();
expect(health.ok, isTrue);
expect(health.network, equals('local'));
expect(health.version, equals('0.4.0'));
expect(health.evmNetwork, equals('local'));
expect(health.uptimeSeconds, equals(42));
expect(health.buildCommit, equals('abcdef123456'));
expect(health.paymentTokenAddress, equals('0xtoken'));
expect(health.paymentVaultAddress, equals('0xvault'));
client.close();
});

test('HealthStatus.fromJson defaults diagnostics for pre-0.4.0 daemon', () {
// Older daemons reply with just status + network; the factory defaults
// populate the diagnostic fields with empty / 0.
final h = HealthStatus.fromJson({'status': 'ok', 'network': 'default'});
expect(h.ok, isTrue);
expect(h.network, equals('default'));
expect(h.version, equals(''));
expect(h.evmNetwork, equals(''));
expect(h.uptimeSeconds, equals(0));
expect(h.buildCommit, equals(''));
});
});

group('Data Public', () {
Expand Down