-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configurable assertions in Ledger API test tool by feature descriptors (
#11328) * ApiVersionService propagates self-service error codes flag. * ParticipantTestContext is enriched with feature descriptors * ContractIdIT adapted with assertions for self-service error codes CHANGELOG_BEGIN CHANGELOG_END
- Loading branch information
Showing
20 changed files
with
292 additions
and
74 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
ledger-api/grpc-definitions/com/daml/ledger/api/v1/experimental_features.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
syntax = "proto3"; | ||
|
||
package com.daml.ledger.api.v1; | ||
|
||
option java_outer_classname = "ExperimentalFeaturesOuterClass"; | ||
option java_package = "com.daml.ledger.api.v1"; | ||
option csharp_namespace = "Com.Daml.Ledger.Api.V1"; | ||
|
||
/* | ||
IMPORTANT: in contrast to other parts of the Ledger API, only json-wire backwards | ||
compatibility guarantees are given for the messages in this file. | ||
*/ | ||
|
||
// See the feature message definitions for descriptions. | ||
message ExperimentalFeatures { | ||
ExperimentalSelfServiceErrorCodes self_service_error_codes = 1; | ||
} | ||
|
||
// GRPC self-service error codes are returned by the Ledger API. | ||
message ExperimentalSelfServiceErrorCodes {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
ledger/error/src/main/scala/com/daml/error/utils/ErrorDetails.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.error.utils | ||
|
||
import com.google.protobuf | ||
import com.google.rpc.{ErrorInfo, RequestInfo, ResourceInfo, RetryInfo} | ||
|
||
object ErrorDetails { | ||
sealed trait ErrorDetail extends Product with Serializable | ||
|
||
final case class ResourceInfoDetail(name: String, typ: String) extends ErrorDetail | ||
final case class ErrorInfoDetail(reason: String) extends ErrorDetail | ||
final case class RetryInfoDetail(retryDelayInSeconds: Long) extends ErrorDetail | ||
final case class RequestInfoDetail(requestId: String) extends ErrorDetail | ||
|
||
def from(anys: Seq[protobuf.Any]): Seq[ErrorDetail] = anys.toList.map { | ||
case any if any.is(classOf[ResourceInfo]) => | ||
val v = any.unpack(classOf[ResourceInfo]) | ||
ResourceInfoDetail(v.getResourceType, v.getResourceName) | ||
|
||
case any if any.is(classOf[ErrorInfo]) => | ||
val v = any.unpack(classOf[ErrorInfo]) | ||
ErrorInfoDetail(v.getReason) | ||
|
||
case any if any.is(classOf[RetryInfo]) => | ||
val v = any.unpack(classOf[RetryInfo]) | ||
RetryInfoDetail(v.getRetryDelay.getSeconds) | ||
|
||
case any if any.is(classOf[RequestInfo]) => | ||
val v = any.unpack(classOf[RequestInfo]) | ||
RequestInfoDetail(v.getRequestId) | ||
|
||
case any => throw new IllegalStateException(s"Could not unpack value of: |$any|") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...in/scala/com/daml/ledger/api/testtool/infrastructure/participant/ParticipantFeature.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.api.testtool.infrastructure.participant | ||
|
||
import com.daml.ledger.api.v1.version_service.GetLedgerApiVersionResponse | ||
|
||
object Features { | ||
def fromApiVersionResponse(request: GetLedgerApiVersionResponse): Features = { | ||
val selfServiceErrorCodesFeature = for { | ||
features <- request.features | ||
experimental <- features.experimental | ||
_ <- experimental.selfServiceErrorCodes | ||
} yield SelfServiceErrorCodes | ||
|
||
Features(selfServiceErrorCodesFeature.toList) | ||
} | ||
} | ||
|
||
case class Features(features: Seq[Feature]) { | ||
val selfServiceErrorCodes: Boolean = SelfServiceErrorCodes.enabled(features) | ||
} | ||
|
||
sealed trait Feature | ||
|
||
sealed trait ExperimentalFeature extends Feature | ||
|
||
case object SelfServiceErrorCodes extends ExperimentalFeature { | ||
def enabled(features: Seq[Feature]): Boolean = features.contains(SelfServiceErrorCodes) | ||
} |
Oops, something went wrong.