Skip to content

Commit

Permalink
WIP Running all conformance tests in ledger-on-memory against self-se…
Browse files Browse the repository at this point in the history
…rvice error-codes

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
tudor-da committed Nov 3, 2021
1 parent 8a9f15b commit 3ded1e6
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 62 deletions.
2 changes: 2 additions & 0 deletions ledger/ledger-api-test-tool/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ da_scala_binary(
"//ledger-api/grpc-definitions:ledger_api_proto_scala",
"//ledger/error",
"//ledger/ledger-api-common",
"//ledger/participant-state/kvutils",
"//libs-scala/build-info",
"//libs-scala/grpc-utils",
"//libs-scala/resources",
Expand Down Expand Up @@ -218,6 +219,7 @@ da_scala_test_suite(
":ledger-api-test-tool-default-lib",
":ledger-api-test-tool-default-tests",
"//daml-lf/data",
"//ledger/participant-state/kvutils",
"@maven//:org_scalatest_scalatest_compatible",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ object Assertions {
.collectFirst { case err: ErrorDetails.RetryInfoDetail => err.retryDelayInSeconds }

if (actualErrorId != expectedErrorId)
fail(s"Actual error id ($actualErrorId) does not match expected error id ($expectedErrorId}")
fail(s"""Actual error id ($actualErrorId) does not match expected error id ($expectedErrorId}.
|Actual error: $statusRuntimeException
|""".stripMargin)

Assertions.assertEquals(
"gRPC error code mismatch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.daml.ledger.api.v1.commands.Commands.DeduplicationPeriod
import com.daml.ledger.api.v1.completion.Completion
import com.daml.ledger.api.v1.ledger_offset.LedgerOffset
import com.daml.ledger.client.binding.Primitive.Party
import com.daml.ledger.participant.state.kvutils.errors.KVErrors
import com.daml.ledger.test.model.DA.Types.Tuple2
import com.daml.ledger.test.model.Test.{Dummy, DummyWithAnnotation, TextKey, TextKeyOperations}
import io.grpc.Status.Code
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,
KVErrors.DuplicateCommand,
)

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 = KVErrors.DuplicateCommand,
exceptionMessageSubstring = None,
checkDefiniteAnswerMetadata = true,
)
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
29 changes: 12 additions & 17 deletions ledger/ledger-on-memory/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,18 @@ conformance_test(
"--use-self-service-error-codes",
],
test_tool_args = [
"--additional=MultiPartySubmissionIT",
"--additional=ContractIdIT:RejectV0,ContractIdIT:AcceptSuffixedV1,ContractIdIT:AcceptNonSuffixedV1",
"--additional=ParticipantPruningIT",
"--additional=AppendOnlyCommandDeduplicationParallelIT",
"--additional=AppendOnlyCompletionDeduplicationInfoITCommandService",
"--additional=AppendOnlyCompletionDeduplicationInfoITCommandSubmissionService",
"--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",
# "--additional=MultiPartySubmissionIT",
# "--additional=ContractIdIT:RejectV0,ContractIdIT:AcceptSuffixedV1,ContractIdIT:AcceptNonSuffixedV1",
# "--additional=ParticipantPruningIT",
# "--additional=AppendOnlyCommandDeduplicationParallelIT",
# "--additional=AppendOnlyCompletionDeduplicationInfoITCommandService",
# "--additional=AppendOnlyCompletionDeduplicationInfoITCommandSubmissionService",
# "--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: Check flakiness
"--include=KVCommandDeduplicationIT",
],
)

Expand Down

0 comments on commit 3ded1e6

Please sign in to comment.