Skip to content

Commit

Permalink
Full conformance test with self-service error codes on ledger-on-memo…
Browse files Browse the repository at this point in the history
…ry (#11524)

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
tudor-da authored Nov 4, 2021
1 parent efaf20b commit 5e93df6
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ private[testtool] abstract class CommandDeduplicationBase(
ledgerTimeInterval: FiniteDuration,
staticTime: Boolean,
) extends LedgerTestSuite {

val deduplicationDuration: FiniteDuration = scaledDuration(3.seconds)

val ledgerWaitInterval: FiniteDuration = ledgerTimeInterval * 2
val defaultDeduplicationWindowWait: FiniteDuration = deduplicationDuration + ledgerWaitInterval

def deduplicationFeatures: DeduplicationFeatures

protected def expectedDuplicateCommandErrorCode: ErrorCode

protected def runWithDeduplicationDelay(
participants: Seq[ParticipantTestContext]
)(
Expand Down Expand Up @@ -120,7 +121,7 @@ private[testtool] abstract class CommandDeduplicationBase(
_ <- submitRequestAndAssertSyncFailure(ledger)(
requestA,
Code.INVALID_ARGUMENT,
LedgerApiErrors.CommandValidation.InvalidArgument,
LedgerApiErrors.InterpreterErrors.AuthorizationError,
)
} yield {}
})
Expand Down Expand Up @@ -370,7 +371,7 @@ private[testtool] abstract class CommandDeduplicationBase(
submitRequestAndAssertSyncFailure(ledger)(
request,
Code.ALREADY_EXISTS,
LedgerApiErrors.CommandPreparation.DuplicateCommand,
expectedDuplicateCommandErrorCode,
)

private def submitRequestAndAssertSyncFailure(ledger: ParticipantTestContext)(
Expand Down Expand Up @@ -402,7 +403,7 @@ private[testtool] abstract class CommandDeduplicationBase(
ledger,
_,
expectedCode = Code.ALREADY_EXISTS,
selfServiceErrorCode = LedgerApiErrors.CommandPreparation.DuplicateCommand,
selfServiceErrorCode = expectedDuplicateCommandErrorCode,
exceptionMessageSubstring = None,
checkDefiniteAnswerMetadata = true,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package com.daml.ledger.api.testtool.suites

import com.daml.error.ErrorCode
import com.daml.error.definitions.LedgerApiErrors
import com.daml.ledger.api.testtool.infrastructure.deduplication.CommandDeduplicationBase
import com.daml.ledger.api.testtool.infrastructure.deduplication.CommandDeduplicationBase.{
DeduplicationFeatures,
Expand All @@ -23,6 +25,9 @@ final class CommandDeduplicationIT(
staticTime: Boolean,
) extends CommandDeduplicationBase(timeoutScaleFactor, ledgerTimeInterval, staticTime) {

override protected def expectedDuplicateCommandErrorCode: ErrorCode =
LedgerApiErrors.CommandPreparation.DuplicateCommand

override def runWithDeduplicationDelay(
participants: Seq[ParticipantTestContext]
)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ final class ConfigManagementServiceIT extends LedgerTestSuite {
ledger,
expiredMRTFailure,
Status.Code.ABORTED,
LedgerApiErrors.InterpreterErrors.GenericInterpretationError,
LedgerApiErrors.WriteErrors.RequestTimeOut,
exceptionMessageSubstring = None,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.daml.ledger.api.testtool.suites

import com.daml.error.ErrorCode
import com.daml.error.definitions.LedgerApiErrors
import com.daml.ledger.api.refinements.ApiTypes.Party
import com.daml.ledger.api.testtool.infrastructure.Allocation._
Expand Down Expand Up @@ -56,7 +57,7 @@ final class DeeplyNestedValueIT extends LedgerTestSuite {
// The nesting of the key of a `ContractWithKey` is one more than the nat it contains
val nKey = n - 1

def test[T](description: String)(
def test[T](description: String, errorCodeIfExpected: ErrorCode)(
update: ExecutionContext => (
ParticipantTestContext,
Party,
Expand All @@ -74,7 +75,7 @@ final class DeeplyNestedValueIT extends LedgerTestSuite {
alpha,
err,
Status.Code.INVALID_ARGUMENT,
LedgerApiErrors.PreprocessingErrors.PreprocessingFailed,
errorCodeIfExpected,
None,
checkDefiniteAnswerMetadata = true,
)
Expand All @@ -83,22 +84,27 @@ final class DeeplyNestedValueIT extends LedgerTestSuite {
}
})

test("create command") { implicit ec => (alpha, party) =>
waitForTransactionId(alpha, party, Contract(party, nContract, toNat(nContract)).create)
test("create command", LedgerApiErrors.PreprocessingErrors.PreprocessingFailed) {
implicit ec => (alpha, party) =>
waitForTransactionId(alpha, party, Contract(party, nContract, toNat(nContract)).create)
}

test("exercise command") { implicit ec => (alpha, party) =>
for {
handler <- alpha.create(party, Handler(party))
result <- waitForTransactionId(
alpha,
party,
handler.exerciseDestruct(party, toNat(nChoiceArgument)),
)
} yield result
test("exercise command", LedgerApiErrors.PreprocessingErrors.PreprocessingFailed) {
implicit ec => (alpha, party) =>
for {
handler <- alpha.create(party, Handler(party))
result <- waitForTransactionId(
alpha,
party,
handler.exerciseDestruct(party, toNat(nChoiceArgument)),
)
} yield result
}

test("create argument in CreateAndExercise command") { implicit ec => (alpha, party) =>
test(
"create argument in CreateAndExercise command",
LedgerApiErrors.PreprocessingErrors.PreprocessingFailed,
) { implicit ec => (alpha, party) =>
waitForTransactionId(
alpha,
party,
Expand All @@ -107,15 +113,21 @@ final class DeeplyNestedValueIT extends LedgerTestSuite {
)
}

test("choice argument in CreateAndExercise command") { implicit ec => (alpha, party) =>
test(
"choice argument in CreateAndExercise command",
LedgerApiErrors.PreprocessingErrors.PreprocessingFailed,
) { implicit ec => (alpha, party) =>
waitForTransactionId(
alpha,
party,
Handler(party).createAnd.exerciseDestruct(party, toNat(nChoiceArgument)),
)
}

test("exercise argument") { implicit ec => (alpha, party) =>
test(
"exercise argument",
LedgerApiErrors.InterpreterErrors.InvalidArgumentInterpretationError,
) { implicit ec => (alpha, party) =>
for {
handler <- alpha.create(party, Handler(party))
result <-
Expand All @@ -127,41 +139,48 @@ final class DeeplyNestedValueIT extends LedgerTestSuite {
} yield result
}

test("exercise output") { implicit ec => (alpha, party) =>
for {
handler <- alpha.create(party, Handler(party))
result <-
waitForTransactionId(alpha, party, handler.exerciseConstruct(party, n))
} yield result
test("exercise output", LedgerApiErrors.InterpreterErrors.InvalidArgumentInterpretationError) {
implicit ec => (alpha, party) =>
for {
handler <- alpha.create(party, Handler(party))
result <-
waitForTransactionId(alpha, party, handler.exerciseConstruct(party, n))
} yield result
}

test("create argument") { implicit ec => (alpha, party) =>
for {
handler <- alpha.create(party, Handler(party))
result <- waitForTransactionId(alpha, party, handler.exerciseCreate(party, nContract))
} yield result
test("create argument", LedgerApiErrors.InterpreterErrors.InvalidArgumentInterpretationError) {
implicit ec => (alpha, party) =>
for {
handler <- alpha.create(party, Handler(party))
result <- waitForTransactionId(alpha, party, handler.exerciseCreate(party, nContract))
} yield result
}

test("contract key") { implicit ec => (alpha, party) =>
for {
handler <- alpha.create(party, Handler(party))
result <- waitForTransactionId(alpha, party, handler.exerciseCreateKey(party, nKey))
} yield result
test("contract key", LedgerApiErrors.InterpreterErrors.InvalidArgumentInterpretationError) {
implicit ec => (alpha, party) =>
for {
handler <- alpha.create(party, Handler(party))
result <- waitForTransactionId(alpha, party, handler.exerciseCreateKey(party, nKey))
} yield result
}

if (accepted) {
// Because we cannot create contracts with nesting > 100,
// it does not make sense to test fetch of those kinds of contracts.
test("fetch by key") { implicit ec => (alpha, party) =>
for {
handler <- alpha.create(party, Handler(party))
_ <- alpha.exercise(party, handler.exerciseCreateKey(_, nKey))
result <- waitForTransactionId(alpha, party, handler.exerciseFetchByKey(party, nKey))
} yield result
test("fetch by key", LedgerApiErrors.InterpreterErrors.InvalidArgumentInterpretationError) {
implicit ec => (alpha, party) =>
for {
handler <- alpha.create(party, Handler(party))
_ <- alpha.exercise(party, handler.exerciseCreateKey(_, nKey))
result <- waitForTransactionId(alpha, party, handler.exerciseFetchByKey(party, nKey))
} yield result
}
}

test("failing lookup by key") { implicit ec => (alpha, party) =>
test(
"failing lookup by key",
LedgerApiErrors.InterpreterErrors.InvalidArgumentInterpretationError,
) { implicit ec => (alpha, party) =>
for {
handler <- alpha.create(party, Handler(party))
result <- waitForTransactionId(alpha, party, handler.exerciseLookupByKey(party, nKey))
Expand All @@ -171,7 +190,10 @@ final class DeeplyNestedValueIT extends LedgerTestSuite {
if (accepted) {
// Because we cannot create contracts with key nesting > 100,
// it does not make sens to test successful lookup for those keys.
test("successful lookup by key") { implicit ec => (alpha, party) =>
test(
"successful lookup by key",
LedgerApiErrors.InterpreterErrors.InvalidArgumentInterpretationError,
) { implicit ec => (alpha, party) =>
for {
handler <- alpha.create(party, Handler(party))
_ <- alpha.exercise(party, handler.exerciseCreateKey(_, nKey))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.daml.ledger.api.testtool.suites

import com.daml.error.ErrorCode
import com.daml.ledger.api.testtool.infrastructure.ProtobufConverters._
import com.daml.ledger.api.testtool.infrastructure.deduplication.CommandDeduplicationBase
import com.daml.ledger.api.testtool.infrastructure.deduplication.CommandDeduplicationBase.{
Expand All @@ -11,6 +12,7 @@ import com.daml.ledger.api.testtool.infrastructure.deduplication.CommandDeduplic
}
import com.daml.ledger.api.testtool.infrastructure.participant.ParticipantTestContext
import com.daml.ledger.api.v1.admin.config_management_service.TimeModel
import com.daml.ledger.participant.state.kvutils.errors.KVErrors
import com.daml.timer.Delayed
import org.slf4j.LoggerFactory

Expand Down Expand Up @@ -38,6 +40,8 @@ class KVCommandDeduplicationIT(
participantDeduplication = false
)

override protected def expectedDuplicateCommandErrorCode: ErrorCode = KVErrors.DuplicateCommand

protected override def runWithDeduplicationDelay(
participants: Seq[ParticipantTestContext]
)(
Expand Down
15 changes: 4 additions & 11 deletions ledger/ledger-on-memory/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ conformance_test(
],
)

# WIP Full conformance test asserting the Ledger API returning self-service error codes
# Full conformance test asserting the Ledger API returning self-service error codes
conformance_test(
name = "conformance-test-self-service-error-codes",
ports = [6865],
Expand All @@ -179,20 +179,13 @@ conformance_test(
"--additional=MultiPartySubmissionIT",
"--additional=ContractIdIT:RejectV0,ContractIdIT:AcceptSuffixedV1,ContractIdIT:AcceptNonSuffixedV1",
"--additional=ParticipantPruningIT",
"--additional=AppendOnlyCommandDeduplicationParallelIT",
"--additional=AppendOnlyCompletionDeduplicationInfoITCommandService",
"--additional=AppendOnlyCompletionDeduplicationInfoITCommandSubmissionService",
"--additional=CommandDeduplicationParallelIT",
"--additional=CompletionDeduplicationInfoITCommandService",
"--additional=CompletionDeduplicationInfoITCommandSubmissionService",
"--additional=KVCommandDeduplicationIT",
"--exclude=CommandDeduplicationIT", # It's a KV ledger so it needs the KV variant
# Disable tests targeting only multi-participant setups
"--exclude=ParticipantPruningIT:PRImmediateAndRetroactiveDivulgence",
# TODO error codes: Remove below exclusions when the pertaining self-service error codes are implemented and can be asserted
"--exclude=DeeplyNestedValueIT",
"--exclude=TransactionServiceValidationIT:TXRejectBeginAfterEnd",
"--exclude=ConfigManagementServiceIT:CMSetAndGetTimeModel",
"--exclude=ParticipantPruningIT",
# TODO error codes: Check flakiness
"--exclude=KVCommandDeduplicationIT",
],
)

Expand Down

0 comments on commit 5e93df6

Please sign in to comment.