Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ledger-api-test-tool: Govern ContractIdIT test runs through a feature. [KVL-1261] #12454

Merged
11 commits merged into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
11 changes: 11 additions & 0 deletions compatibility/bazel_tools/testing.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,17 @@ excluded_test_tool_tests = [
},
],
},
{
# Contract ID tests are governed by feature descriptors.
"platform_ranges": [
{
"end": "2.0.0-snapshot.20220110.8812.1",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure, ContractIdIT is not going to be run with any ledger-api-test-tool version against platform versions older than the next snapshot. Is that what you want?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this reproduces the old behavior, where these tests were optional and therefore not run.

"exclusions": [
"ContractIdIT",
],
},
],
},
]

def in_range(version, range):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ message ExperimentalFeatures {
ExperimentalSelfServiceErrorCodes self_service_error_codes = 1;
ExperimentalStaticTime static_time = 2;
CommandDeduplicationFeatures command_deduplication = 3;
ContractIdFeatures contract_ids = 4;
}

// GRPC self-service error codes are returned by the Ledger API.
Expand Down Expand Up @@ -67,3 +68,19 @@ enum CommandDeduplicationType {
// Duplicate commands are always reported synchronously via a synchronous gRPC error on the command submission.
SYNC_ONLY = 2;
}

// See `daml-lf/spec/contract-id.rst` for more information on contract ID formats.
message ContractIdFeatures {
ContractIdV1Support v1 = 1;

enum ContractIdV1Support {
// Contract IDs must be suffixed.
// Distributed ledger implementations must reject non-suffixed contract IDs.
SUFFIXED = 0;
// Contract IDs do not need to be suffixed.
// This can be useful for shorter contract IDs in centralized committer implementations.
NON_SUFFIXED = 1;
// Either contract ID format is supported.
BOTH = 2;
}
}
1 change: 0 additions & 1 deletion ledger/daml-on-sql/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ conformance_test(
"--additional=CommandDeduplicationPeriodValidationIT",
"--additional=CompletionDeduplicationInfoITCommandService",
"--additional=CompletionDeduplicationInfoITCommandSubmissionService",
"--additional=ContractIdIT:Accept",
],
)

Expand Down
19 changes: 11 additions & 8 deletions ledger/ledger-api-test-tool-on-canton/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ conformance_test(
",CompletionDeduplicationInfoITCommandService" +
",CompletionDeduplicationInfoITCommandSubmissionService" +
",CommandDeduplicationParallelIT" +
",ContractIdIT" +
",MultiPartySubmissionIT" +
",ParticipantPruningIT" +
",TLSOnePointThreeIT" +
Expand Down Expand Up @@ -163,13 +162,17 @@ conformance_test(
server = ":canton-test-runner-with-dependencies",
test_tool_args = [
"--verbose",
"--include=ContractIdIT:RejectV0,ContractIdIT:RejectNonSuffixedV1Cid,ContractIdIT:AcceptSuffixedV1Cid" +
",MultiPartySubmissionIT" +
#",CommandDeduplicationParallelIT" + - can be re-enabled once canton exposes the feature descriptors
",CompletionDeduplicationInfoITCommandService,CompletionDeduplicationInfoITCommandSubmissionService",
"--exclude=MultiPartySubmissionIT:MPSLookupOtherByKeyInvisible" + # Enable once error parsing more permissive
",MultiPartySubmissionIT:MPSCreateInsufficientAuthorization" + # canton returns INTERNAL instead of INVALID_ARGUMENT
",ContractIdIT:AcceptSuffixedV1CidExerciseTarget", # Racy with: ABORTED: CONTRACT_NOT_FOUND(14,0): Contract could not be found with id
"--include=" + ",".join([
"MultiPartySubmissionIT",
# ",CommandDeduplicationParallelIT", - can be re-enabled once canton exposes the feature descriptors
"CompletionDeduplicationInfoITCommandService",
"CompletionDeduplicationInfoITCommandSubmissionService",
]),
"--exclude=" + ",".join([
"MultiPartySubmissionIT:MPSLookupOtherByKeyInvisible", # Enable once error parsing more permissive
"MultiPartySubmissionIT:MPSCreateInsufficientAuthorization", # canton returns INTERNAL instead of INVALID_ARGUMENT
"ContractIdIT:AcceptSuffixedV1CidExerciseTarget", # Racy with: ABORTED: CONTRACT_NOT_FOUND(14,0): Contract could not be found with id
]),
],
) if not is_windows else None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,39 @@

package com.daml.ledger.api.testtool.infrastructure.participant

import com.daml.ledger.api.v1.experimental_features.CommandDeduplicationFeatures
import com.daml.ledger.api.v1.experimental_features.{
CommandDeduplicationFeatures,
ContractIdFeatures,
}
import com.daml.ledger.api.v1.version_service.GetLedgerApiVersionResponse

final case class Features(
selfServiceErrorCodes: Boolean = false,
userManagement: Boolean = false,
userManagement: Boolean,
selfServiceErrorCodes: Boolean,
staticTime: Boolean,
commandDeduplicationFeatures: CommandDeduplicationFeatures,
staticTime: Boolean = false,
contractIds: ContractIdFeatures,
)

object Features {
val defaultFeatures =
Features(commandDeduplicationFeatures = CommandDeduplicationFeatures.defaultInstance)
val defaultFeatures: Features = Features(
userManagement = false,
selfServiceErrorCodes = false,
staticTime = false,
commandDeduplicationFeatures = CommandDeduplicationFeatures.defaultInstance,
contractIds = ContractIdFeatures.defaultInstance,
)

def fromApiVersionResponse(response: GetLedgerApiVersionResponse): Features = {
val features = response.getFeatures
val experimental = features.getExperimental

Features(
selfServiceErrorCodes = experimental.selfServiceErrorCodes.isDefined,
userManagement = features.getUserManagement.supported,
selfServiceErrorCodes = experimental.selfServiceErrorCodes.isDefined,
staticTime = experimental.getStaticTime.supported,
commandDeduplicationFeatures = experimental.getCommandDeduplication,
contractIds = experimental.getContractIds,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.daml.ledger.api.testtool.infrastructure.Assertions.{
fail,
}
import com.daml.ledger.api.testtool.infrastructure.LedgerTestSuite
import com.daml.ledger.api.testtool.infrastructure.participant.ParticipantTestContext
import com.daml.ledger.api.testtool.infrastructure.participant.{Features, ParticipantTestContext}
import com.daml.ledger.api.v1.value.{Record, RecordField, Value}
import com.daml.ledger.client.binding.Primitive.ContractId
import com.daml.ledger.test.semantic.ContractIdTests._
Expand All @@ -26,33 +26,56 @@ import scala.util.{Failure, Success, Try}
// - Central committer ledger implementations (sandboxes, KV...) may accept non-suffixed CID
// - Distributed ledger implementations (e.g. Canton) must reject non-suffixed CID
final class ContractIdIT extends LedgerTestSuite {

private[this] val v0Cid = "#V0 Contract ID"
private[this] val nonSuffixedV1Cid = (0 to 32).map("%02x".format(_)).mkString
private[this] val suffixedV1Cid = (0 to 48).map("%02x".format(_)).mkString

private[this] def camlCase(s: String) =
s.split("[ -]").iterator.map(_.capitalize).mkString("")

List(
(v0Cid, "V0", true),
(v0Cid, "V0", false),
(nonSuffixedV1Cid, "non-suffixed V1", true),
(nonSuffixedV1Cid, "non-suffixed V1", false),
(suffixedV1Cid, "suffixed V1", true),
).foreach { case (testedCid, cidDescription, accepted) =>
List[(String, String, Boolean, Features => Boolean, String)](
(
nonSuffixedV1Cid,
"non-suffixed V1",
true,
features => features.contractIds.v1.isNonSuffixed || features.contractIds.v1.isBoth,
"non-suffixed V1 contract IDs are not supported",
),
(
nonSuffixedV1Cid,
"non-suffixed V1",
false,
features => !(features.contractIds.v1.isNonSuffixed || features.contractIds.v1.isBoth),
"non-suffixed V1 contract IDs are supported",
),
(
suffixedV1Cid,
"suffixed V1",
true,
features => features.contractIds.v1.isSuffixed || features.contractIds.v1.isBoth,
"suffixed V1 contract IDs are not supported",
),
(
suffixedV1Cid,
"suffixed V1",
false,
features => !(features.contractIds.v1.isSuffixed || features.contractIds.v1.isBoth),
"suffixed V1 contract IDs are supported",
),
).foreach { case (testedCid, cidDescription, accepted, isSupported, disabledReason) =>
val result = if (accepted) "Accept" else "Reject"

def test(description: String)(
update: ExecutionContext => (
ParticipantTestContext,
Party,
) => Future[Try[_]]
): Unit =
): Unit = {
super.test(
result + camlCase(cidDescription) + "Cid" + camlCase(description),
result + "s " + cidDescription + " Contract Id in " + description,
allocate(SingleParty),
shortIdentifier = result + camlCase(cidDescription) + "Cid" + camlCase(description),
description = result + "s " + cidDescription + " Contract Id in " + description,
participants = allocate(SingleParty),
enabled = isSupported,
disabledReason = disabledReason,
)(implicit ec => { case Participants(Participant(alpha, party)) =>
update(ec)(alpha, party).map {
case Success(_) if accepted => ()
Expand All @@ -70,6 +93,7 @@ final class ContractIdIT extends LedgerTestSuite {
fail("Unexpected " + otherwise.fold(err => s"failure: $err", _ => "success"))
}
})
}

test("create payload") { implicit ec => (alpha, party) =>
alpha
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ object Tests {
new CommandServiceIT,
new CommandSubmissionCompletionIT,
new ConfigManagementServiceIT,
new ContractIdIT,
new ContractKeysIT,
new DeeplyNestedValueIT,
new DivulgenceIT,
Expand Down Expand Up @@ -69,7 +70,6 @@ object Tests {
new CompletionDeduplicationInfoIT(CommandSubmissionService),
new CommandDeduplicationParallelIT,
new CommandDeduplicationPeriodValidationIT,
new ContractIdIT,
new MultiPartySubmissionIT,
new ParticipantPruningIT,
new MonotonicRecordTimeIT,
Expand Down
2 changes: 0 additions & 2 deletions ledger/ledger-on-memory/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ conformance_test(
],
test_tool_args = [
"--additional=MultiPartySubmissionIT",
"--additional=ContractIdIT:RejectV0,ContractIdIT:AcceptSuffixedV1,ContractIdIT:AcceptNonSuffixedV1",
# Notoriously times-out
#"--additional=ParticipantPruningIT",
"--additional=CommandDeduplicationParallelIT",
Expand All @@ -173,7 +172,6 @@ conformance_test(
],
test_tool_args = [
"--additional=MultiPartySubmissionIT",
"--additional=ContractIdIT:RejectV0,ContractIdIT:AcceptSuffixedV1,ContractIdIT:AcceptNonSuffixedV1",
# Notoriously times-out
#"--additional=ParticipantPruningIT",
"--additional=CommandDeduplicationParallelIT",
Expand Down
1 change: 0 additions & 1 deletion ledger/ledger-on-sql/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,5 @@ conformance_test(
],
test_tool_args = [
"--verbose",
"--include=ContractIdIT:RejectV0,ContractIdIT:AcceptSuffixedV1,ContractIdIT:AcceptNonSuffixedV1",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import com.daml.ledger.api.auth.Authorizer
import com.daml.ledger.api.auth.services._
import com.daml.ledger.api.domain.LedgerId
import com.daml.ledger.api.health.HealthChecks
import com.daml.ledger.api.v1.experimental_features.CommandDeduplicationFeatures
import com.daml.ledger.api.v1.experimental_features.{
CommandDeduplicationFeatures,
ContractIdFeatures,
}
import com.daml.ledger.client.services.commands.CommandSubmissionFlow
import com.daml.ledger.participant.state.index.v2._
import com.daml.ledger.participant.state.{v2 => state}
Expand Down Expand Up @@ -97,6 +100,7 @@ private[daml] object ApiServices {
enableSelfServiceErrorCodes: Boolean,
checkOverloaded: TelemetryContext => Option[state.SubmissionResult],
commandDeduplicationFeatures: CommandDeduplicationFeatures,
contractIdFeatures: ContractIdFeatures,
)(implicit
materializer: Materializer,
esf: ExecutionSequencerFactory,
Expand Down Expand Up @@ -164,6 +168,7 @@ private[daml] object ApiServices {
ApiVersionService.create(
enableSelfServiceErrorCodes,
commandDeduplicationFeatures,
contractIdFeatures,
optTimeServiceBackend.isDefined,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import com.daml.error.ErrorCodesVersionSwitcher
import com.daml.ledger.api.auth.interceptor.AuthorizationInterceptor
import com.daml.ledger.api.auth.{AuthService, Authorizer}
import com.daml.ledger.api.health.HealthChecks
import com.daml.ledger.api.v1.experimental_features.CommandDeduplicationFeatures
import com.daml.ledger.api.v1.experimental_features.{
CommandDeduplicationFeatures,
ContractIdFeatures,
}
import com.daml.ledger.configuration.LedgerId
import com.daml.ledger.participant.state.index.v2.{IndexService, UserManagementStore}
import com.daml.ledger.participant.state.{v2 => state}
Expand Down Expand Up @@ -60,6 +63,7 @@ object StandaloneApiServer {
checkOverloaded: TelemetryContext => Option[state.SubmissionResult] =
_ => None, // Used for Canton rate-limiting,
commandDeduplicationFeatures: CommandDeduplicationFeatures,
contractIdFeatures: ContractIdFeatures,
)(implicit
actorSystem: ActorSystem,
materializer: Materializer,
Expand Down Expand Up @@ -118,6 +122,7 @@ object StandaloneApiServer {
checkOverloaded = checkOverloaded,
userManagementStore = userManagementStore,
commandDeduplicationFeatures = commandDeduplicationFeatures,
contractIdFeatures = contractIdFeatures,
)(materializer, executionSequencerFactory, loggingContext)
.map(_.withServices(otherServices))
apiServer <- new LedgerApiServer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.daml.error.{
}
import com.daml.ledger.api.v1.experimental_features.{
CommandDeduplicationFeatures,
ContractIdFeatures,
ExperimentalFeatures,
ExperimentalSelfServiceErrorCodes,
ExperimentalStaticTime,
Expand All @@ -35,6 +36,7 @@ import scala.util.control.NonFatal
private[apiserver] final class ApiVersionService private (
enableSelfServiceErrorCodes: Boolean,
commandDeduplicationFeatures: CommandDeduplicationFeatures,
contractIdFeatures: ContractIdFeatures,
enableStaticTime: Boolean,
)(implicit
loggingContext: LoggingContext,
Expand All @@ -55,11 +57,12 @@ private[apiserver] final class ApiVersionService private (
FeaturesDescriptor.of(
userManagement = Some(UserManagementFeature(supported = true)),
experimental = Some(
ExperimentalFeatures(
ExperimentalFeatures.of(
selfServiceErrorCodes =
Option.when(enableSelfServiceErrorCodes)(ExperimentalSelfServiceErrorCodes()),
staticTime = Some(ExperimentalStaticTime(supported = enableStaticTime)),
commandDeduplication = Some(commandDeduplicationFeatures),
contractIds = Some(contractIdFeatures),
)
),
)
Expand Down Expand Up @@ -103,11 +106,13 @@ private[apiserver] object ApiVersionService {
def create(
enableSelfServiceErrorCodes: Boolean,
commandDeduplicationFeatures: CommandDeduplicationFeatures,
contractIdFeatures: ContractIdFeatures,
enableStaticTime: Boolean,
)(implicit loggingContext: LoggingContext, ec: ExecutionContext): ApiVersionService =
new ApiVersionService(
enableSelfServiceErrorCodes,
commandDeduplicationFeatures,
contractIdFeatures,
enableStaticTime,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.daml.ledger.api.v1.experimental_features.{
CommandDeduplicationFeatures,
CommandDeduplicationPeriodSupport,
CommandDeduplicationType,
ContractIdFeatures,
}
import com.daml.ledger.participant.state.index.impl.inmemory.InMemoryUserManagementStore
import com.daml.ledger.participant.state.v2.metrics.{TimedReadService, TimedWriteService}
Expand Down Expand Up @@ -211,6 +212,9 @@ final class Runner[T <: ReadWriteService, Extra](
deduplicationType = CommandDeduplicationType.ASYNC_ONLY,
maxDeduplicationDurationEnforced = true,
),
contractIdFeatures = ContractIdFeatures.of(
v1 = ContractIdFeatures.ContractIdV1Support.BOTH
),
).acquire()
} yield Some(apiServer.port)
case ParticipantRunMode.Indexer =>
Expand Down
2 changes: 0 additions & 2 deletions ledger/sandbox-classic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ server_conformance_test(
"--additional=CommandDeduplicationPeriodValidationIT",
"--additional=CompletionDeduplicationInfoITCommandService",
"--additional=CompletionDeduplicationInfoITCommandSubmissionService",
"--additional=ContractIdIT:Accept",
"--additional=ParticipantPruningIT",
# Excluding tests that require using pruneAllDivulgedContracts option that is not supported by sandbox-classic
"--exclude=ParticipantPruningIT:PRLocalAndNonLocalRetroactiveDivulgences,ParticipantPruningIT:PRRetroactiveDivulgences,ParticipantPruningIT:PRImmediateAndRetroactiveDivulgence",
Expand Down Expand Up @@ -386,7 +385,6 @@ server_conformance_test(
"--additional=CommandDeduplicationPeriodValidationIT",
"--additional=CompletionDeduplicationInfoITCommandService",
"--additional=CompletionDeduplicationInfoITCommandSubmissionService",
"--additional=ContractIdIT:Accept",
"--additional=ParticipantPruningIT",
# Excluding tests that require using pruneAllDivulgedContracts option that is not supported by sandbox-classic
"--exclude=ParticipantPruningIT:PRLocalAndNonLocalRetroactiveDivulgences,ParticipantPruningIT:PRRetroactiveDivulgences,ParticipantPruningIT:PRImmediateAndRetroactiveDivulgence",
Expand Down
Loading