remove last usages of lapi v1 (#18390)

This commit is contained in:
mziolekda 2024-02-06 10:10:44 +01:00 committed by GitHub
parent 3b408892e1
commit 539926df53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 61 additions and 331 deletions

View File

@ -10,13 +10,7 @@ import java.util.concurrent.TimeUnit
import com.daml.ledger.api.v1.command_completion_service.Checkpoint
import com.daml.ledger.api.v1.ledger_offset.LedgerOffset
import com.daml.ledger.javaapi.data.ParticipantOffsetV2.Absolute
import com.daml.ledger.javaapi.data.{
Command,
CommandsSubmissionV2,
CreateCommand,
DamlRecord,
Identifier,
}
import com.daml.ledger.javaapi.data.{CreateCommand, DamlRecord, Identifier}
import com.daml.ledger.rxjava.grpc.helpers._
import com.digitalasset.canton.ledger.api.auth.{AuthService, AuthServiceWildcard}
import com.daml.ledger.api.v2.command_completion_service.CompletionStreamResponse
@ -38,7 +32,6 @@ import org.scalatest.matchers.should.Matchers
import scala.concurrent.Future
import scala.jdk.CollectionConverters._
import scala.util.chaining.scalaUtilChainingOps
class DamlLedgerClientTest
extends AnyFlatSpec
@ -140,27 +133,10 @@ class DamlLedgerClientTest
val recordId = new Identifier("recordPackageId", "recordModuleName", "recordEntityName")
val record = new DamlRecord(recordId, List.empty[DamlRecord.Field].asJava)
val command = new CreateCommand(new Identifier("a", "a", "b"), record)
val commands = genCommands(List(command), Option(someParty))
val domainId = UUID.randomUUID().toString
val params = CommandsSubmissionV2
.create(commands.getApplicationId, commands.getCommandId, domainId, commands.getCommands)
.withActAs(commands.getParty)
.pipe(p =>
if (commands.getMinLedgerTimeAbsolute.isPresent)
p.withMinLedgerTimeAbs(commands.getMinLedgerTimeAbsolute.get())
else p
)
.pipe(p =>
if (commands.getMinLedgerTimeRelative.isPresent)
p.withMinLedgerTimeRel(commands.getMinLedgerTimeRelative.get())
else p
)
.pipe(p =>
if (commands.getDeduplicationTime.isPresent)
p.withDeduplicationDuration(commands.getDeduplicationTime.get())
else p
)
val params = genCommands(List(command), Some(domainId))
.withActAs(someParty)
commandClient
.submitAndWait(params)
@ -192,27 +168,10 @@ class DamlLedgerClientTest
val recordId = new Identifier("recordPackageId", "recordModuleName", "recordEntityName")
val record = new DamlRecord(recordId, List.empty[DamlRecord.Field].asJava)
val command = new CreateCommand(new Identifier("a", "a", "b"), record)
val commands = genCommands(List[Command](command), Option(someParty))
val domainId = UUID.randomUUID().toString
val params = CommandsSubmissionV2
.create(commands.getApplicationId, commands.getCommandId, domainId, commands.getCommands)
.withActAs(commands.getParty)
.pipe(p =>
if (commands.getMinLedgerTimeAbsolute.isPresent)
p.withMinLedgerTimeAbs(commands.getMinLedgerTimeAbsolute.get())
else p
)
.pipe(p =>
if (commands.getMinLedgerTimeRelative.isPresent)
p.withMinLedgerTimeRel(commands.getMinLedgerTimeRelative.get())
else p
)
.pipe(p =>
if (commands.getDeduplicationTime.isPresent)
p.withDeduplicationDuration(commands.getDeduplicationTime.get())
else p
)
val params = genCommands(List(command), Some(domainId))
.withActAs(someParty)
commandSubmissionClient
.submit(params)

View File

@ -58,26 +58,9 @@ class CommandClientImplTest
it should "send the given command to the Ledger" in {
withCommandClient() { (client, service) =>
val commands = genCommands(List.empty)
val domainId = UUID.randomUUID().toString
val params = CommandsSubmissionV2
.create(commands.getApplicationId, commands.getCommandId, domainId, commands.getCommands)
.withActAs(commands.getParty)
.pipe(p =>
if (commands.getMinLedgerTimeAbsolute.isPresent)
p.withMinLedgerTimeAbs(commands.getMinLedgerTimeAbsolute.get())
else p
)
.pipe(p =>
if (commands.getMinLedgerTimeRelative.isPresent)
p.withMinLedgerTimeRel(commands.getMinLedgerTimeRelative.get())
else p
)
.pipe(p =>
if (commands.getDeduplicationTime.isPresent)
p.withDeduplicationDuration(commands.getDeduplicationTime.get())
else p
)
val params = genCommands(List.empty, Some(domainId))
.withActAs("party")
client
.submitAndWait(params)
@ -95,50 +78,30 @@ class CommandClientImplTest
val recordId = new Identifier("recordPackageId", "recordModuleName", "recordEntityName")
val record = new DamlRecord(recordId, List.empty[DamlRecord.Field].asJava)
val command = new CreateCommand(new Identifier("a", "a", "b"), record)
val commands = genCommands(List(command))
val domainId = UUID.randomUUID().toString
val params = CommandsSubmissionV2
.create(commands.getApplicationId, commands.getCommandId, domainId, commands.getCommands)
.withWorkflowId(commands.getWorkflowId)
.withActAs(commands.getParty)
.pipe(p =>
if (commands.getMinLedgerTimeAbsolute.isPresent)
p.withMinLedgerTimeAbs(commands.getMinLedgerTimeAbsolute.get())
else p
)
.pipe(p =>
if (commands.getMinLedgerTimeRelative.isPresent)
p.withMinLedgerTimeRel(commands.getMinLedgerTimeRelative.get())
else p
)
.pipe(p =>
if (commands.getDeduplicationTime.isPresent)
p.withDeduplicationDuration(commands.getDeduplicationTime.get())
else p
)
val params = genCommands(List(command), Some(domainId))
.withActAs("party")
client
.submitAndWait(params)
.timeout(TestConfiguration.timeoutInSeconds, TimeUnit.SECONDS)
.blockingGet()
service.getLastRequest.value.getCommands.applicationId shouldBe commands.getApplicationId
service.getLastRequest.value.getCommands.commandId shouldBe commands.getCommandId
service.getLastRequest.value.getCommands.party shouldBe commands.getParty
service.getLastRequest.value.getCommands.actAs shouldBe commands.getActAs.asScala
service.getLastRequest.value.getCommands.readAs shouldBe commands.getReadAs.asScala
commands.getActAs.get(0) shouldBe commands.getParty
service.getLastRequest.value.getCommands.workflowId shouldBe commands.getWorkflowId
service.getLastRequest.value.getCommands.applicationId shouldBe params.getApplicationId
service.getLastRequest.value.getCommands.commandId shouldBe params.getCommandId
service.getLastRequest.value.getCommands.actAs shouldBe params.getActAs.asScala
service.getLastRequest.value.getCommands.readAs shouldBe params.getReadAs.asScala
service.getLastRequest.value.getCommands.workflowId shouldBe params.getWorkflowId.get()
service.getLastRequest.value.getCommands.domainId shouldBe domainId
service.getLastRequest.value.getCommands.minLedgerTimeRel
.map(_.seconds) shouldBe commands.getMinLedgerTimeRelative.asScala.map(_.getSeconds)
.map(_.seconds) shouldBe params.getMinLedgerTimeRel.asScala.map(_.getSeconds)
service.getLastRequest.value.getCommands.minLedgerTimeRel
.map(_.nanos) shouldBe commands.getMinLedgerTimeRelative.asScala.map(_.getNano)
.map(_.nanos) shouldBe params.getMinLedgerTimeRel.asScala.map(_.getNano)
service.getLastRequest.value.getCommands.minLedgerTimeAbs
.map(_.seconds) shouldBe commands.getMinLedgerTimeAbsolute.asScala.map(_.getEpochSecond)
.map(_.seconds) shouldBe params.getMinLedgerTimeAbs.asScala.map(_.getEpochSecond)
service.getLastRequest.value.getCommands.minLedgerTimeAbs
.map(_.nanos) shouldBe commands.getMinLedgerTimeAbsolute.asScala.map(_.getNano)
.map(_.nanos) shouldBe params.getMinLedgerTimeAbs.asScala.map(_.getNano)
service.getLastRequest.value.getCommands.commands should have size 1
val receivedCommand = service.getLastRequest.value.getCommands.commands.head.command
receivedCommand.isCreate shouldBe true

View File

@ -3,13 +3,7 @@
package com.daml.ledger.rxjava.grpc
import com.daml.ledger.javaapi.data.{
Command,
CommandsSubmissionV2,
CreateCommand,
DamlRecord,
Identifier,
}
import com.daml.ledger.javaapi.data.{Command, CreateCommand, DamlRecord, Identifier}
import com.daml.ledger.rxjava._
import com.daml.ledger.rxjava.grpc.helpers.{DataLayerHelpers, LedgerServices, TestConfiguration}
import org.scalatest.OptionValues
@ -48,27 +42,10 @@ class CommandSubmissionClientImplTest
sequence(stuck, success),
timeout = Optional.of(Duration.of(5, ChronoUnit.SECONDS)),
) { (client, _) =>
val commands = genCommands(List.empty)
val domainId = UUID.randomUUID().toString
val params = CommandsSubmissionV2
.create(commands.getApplicationId, commands.getCommandId, domainId, commands.getCommands)
.withActAs(commands.getParty)
.pipe(p =>
if (commands.getMinLedgerTimeAbsolute.isPresent)
p.withMinLedgerTimeAbs(commands.getMinLedgerTimeAbsolute.get())
else p
)
.pipe(p =>
if (commands.getMinLedgerTimeRelative.isPresent)
p.withMinLedgerTimeRel(commands.getMinLedgerTimeRelative.get())
else p
)
.pipe(p =>
if (commands.getDeduplicationTime.isPresent)
p.withDeduplicationDuration(commands.getDeduplicationTime.get())
else p
)
val params = genCommands(List.empty, Some(domainId))
.withActAs("party")
withClue("The first command should be stuck") {
expectDeadlineExceeded(
@ -93,28 +70,10 @@ class CommandSubmissionClientImplTest
it should "send a commands to the ledger" in {
ledgerServices.withCommandSubmissionClient(alwaysSucceed) { (client, serviceImpl) =>
val commands = genCommands(List.empty)
val domainId = UUID.randomUUID().toString
val params = CommandsSubmissionV2
.create(commands.getApplicationId, commands.getCommandId, domainId, commands.getCommands)
.withWorkflowId(commands.getWorkflowId)
.withActAs(commands.getParty)
.pipe(p =>
if (commands.getMinLedgerTimeAbsolute.isPresent)
p.withMinLedgerTimeAbs(commands.getMinLedgerTimeAbsolute.get())
else p
)
.pipe(p =>
if (commands.getMinLedgerTimeRelative.isPresent)
p.withMinLedgerTimeRel(commands.getMinLedgerTimeRelative.get())
else p
)
.pipe(p =>
if (commands.getDeduplicationTime.isPresent)
p.withDeduplicationDuration(commands.getDeduplicationTime.get())
else p
)
val params = genCommands(List.empty, Some(domainId))
.withActAs("party")
client
.submit(params)
@ -124,27 +83,26 @@ class CommandSubmissionClientImplTest
val receivedCommands = serviceImpl.getSubmittedRequest.value.getCommands
receivedCommands.domainId shouldBe domainId
receivedCommands.applicationId shouldBe commands.getApplicationId
receivedCommands.workflowId shouldBe commands.getWorkflowId
receivedCommands.commandId shouldBe commands.getCommandId
receivedCommands.applicationId shouldBe params.getApplicationId
receivedCommands.workflowId shouldBe params.getWorkflowId.get()
receivedCommands.commandId shouldBe params.getCommandId
receivedCommands.minLedgerTimeAbs.map(
_.seconds
) shouldBe commands.getMinLedgerTimeAbsolute.asScala
) shouldBe params.getMinLedgerTimeAbs.asScala
.map(_.getEpochSecond)
receivedCommands.minLedgerTimeAbs.map(
_.nanos
) shouldBe commands.getMinLedgerTimeAbsolute.asScala
) shouldBe params.getMinLedgerTimeAbs.asScala
.map(_.getNano)
receivedCommands.minLedgerTimeRel.map(
_.seconds
) shouldBe commands.getMinLedgerTimeRelative.asScala
) shouldBe params.getMinLedgerTimeRel.asScala
.map(_.getSeconds)
receivedCommands.minLedgerTimeRel.map(
_.nanos
) shouldBe commands.getMinLedgerTimeRelative.asScala
) shouldBe params.getMinLedgerTimeRel.asScala
.map(_.getNano)
receivedCommands.party shouldBe commands.getParty
receivedCommands.commands.size shouldBe commands.getCommands.size()
receivedCommands.commands.size shouldBe params.getCommands.size()
}
}
@ -163,27 +121,10 @@ class CommandSubmissionClientImplTest
val recordId = new Identifier("recordPackageId", "recordModuleName", "recordEntityName")
val record = new DamlRecord(recordId, List.empty[DamlRecord.Field].asJava)
val command = new CreateCommand(new Identifier("a", "a", "b"), record)
val commands = genCommands(List[Command](command), Option(someParty))
val domainId = UUID.randomUUID().toString
val params = CommandsSubmissionV2
.create(commands.getApplicationId, commands.getCommandId, domainId, commands.getCommands)
.withActAs(commands.getParty)
.pipe(p =>
if (commands.getMinLedgerTimeAbsolute.isPresent)
p.withMinLedgerTimeAbs(commands.getMinLedgerTimeAbsolute.get())
else p
)
.pipe(p =>
if (commands.getMinLedgerTimeRelative.isPresent)
p.withMinLedgerTimeRel(commands.getMinLedgerTimeRelative.get())
else p
)
.pipe(p =>
if (commands.getDeduplicationTime.isPresent)
p.withDeduplicationDuration(commands.getDeduplicationTime.get())
else p
)
val params = genCommands(List[Command](command), Some(domainId))
.withActAs(someParty)
.pipe(p => accessToken.fold(p)(p.withAccessToken))
client

View File

@ -3,8 +3,6 @@
package com.daml.ledger.rxjava.grpc.helpers
import java.util.Optional
import com.daml.ledger.javaapi.data._
import com.daml.ledger.api.v2.state_service.{ActiveContract, GetActiveContractsResponse}
import com.daml.ledger.api.v2.testing.time_service.GetTimeResponse
@ -35,17 +33,18 @@ trait DataLayerHelpers {
new GetTimeResponse(Some(Timestamp(1L, 2)))
}
def genCommands(commands: List[Command], party: Option[String] = None): SubmitCommandsRequest = {
new SubmitCommandsRequest(
"workflowId",
"applicationId",
"commandId",
party.getOrElse("party"),
Optional.empty(),
Optional.empty(),
Optional.empty(),
commands.asJava,
)
def genCommands(
commands: List[Command],
domainId: Option[String] = None,
): CommandsSubmissionV2 = {
CommandsSubmissionV2
.create(
"applicationId",
"commandId",
domainId.getOrElse("domainId"),
commands.asJava,
)
.withWorkflowId("workflowId")
}
val filterNothing: FiltersByPartyV2 = new FiltersByPartyV2(Map[String, Filter]().asJava)

View File

@ -6,9 +6,9 @@ package com.daml
import com.daml.bazeltools.BazelRunfiles
import com.daml.integrationtest.CantonFixture
import com.daml.ledger.api.testing.utils.SuiteResourceManagementAroundAll
import com.daml.ledger.api.v1.{ActiveContractsServiceGrpc, CommandServiceGrpc}
import com.daml.ledger.api.v1.ActiveContractsServiceOuterClass.GetActiveContractsResponse
import com.daml.ledger.api.v1.CommandServiceOuterClass.SubmitAndWaitRequest
import com.daml.ledger.api.v2.{CommandServiceGrpc, StateServiceGrpc}
import com.daml.ledger.api.v2.StateServiceOuterClass.GetActiveContractsResponse
import com.daml.ledger.api.v2.CommandServiceOuterClass.SubmitAndWaitRequest
import com.digitalasset.canton.ledger.client.LedgerClient
import com.daml.ledger.javaapi.data
import com.daml.ledger.javaapi.data.{codegen => jcg, _}
@ -62,13 +62,13 @@ object TestUtil {
implicit def func2rxfunc[A, B](f: A => B): io.reactivex.functions.Function[A, B] = f(_)
private def randomId = UUID.randomUUID().toString
def allTemplates(partyName: String) = new FiltersByParty(
def allTemplates(partyName: String) = new FiltersByPartyV2(
Map[String, Filter](partyName -> NoFilter.instance).asJava
)
def sendCmd(channel: Channel, partyName: String, hasCmds: HasCommands*): Empty = {
val submission = CommandsSubmission
.create(randomId, randomId, HasCommands.toCommands(hasCmds.asJava))
val submission = CommandsSubmissionV2
.create(randomId, randomId, "", HasCommands.toCommands(hasCmds.asJava))
.withWorkflowId(randomId)
.withActAs(partyName)
@ -78,12 +78,7 @@ object TestUtil {
.submitAndWait(
SubmitAndWaitRequest
.newBuilder()
.setCommands(
SubmitCommandsRequest.toProto(
LedgerID,
submission,
)
)
.setCommands(submission.toProto)
.build
)
}
@ -94,8 +89,8 @@ object TestUtil {
readAs: java.util.List[String],
hasCmds: HasCommands*
): Empty = {
val submission = CommandsSubmission
.create(randomId, randomId, HasCommands.toCommands(hasCmds.asJava))
val submission = CommandsSubmissionV2
.create(randomId, randomId, "", HasCommands.toCommands(hasCmds.asJava))
.withWorkflowId(randomId)
.withActAs(actAs)
.withReadAs(readAs)
@ -106,12 +101,7 @@ object TestUtil {
.submitAndWait(
SubmitAndWaitRequest
.newBuilder()
.setCommands(
SubmitCommandsRequest.toProto(
LedgerID,
submission,
)
)
.setCommands(submission.toProto)
.build
)
}
@ -138,21 +128,22 @@ object TestUtil {
): List[C] = {
// Relies on ordering of ACS endpoint. This isnt documented but currently
// the ledger guarantees this.
val txService = ActiveContractsServiceGrpc.newBlockingStub(channel)
val txService = StateServiceGrpc.newBlockingStub(channel)
val txs = txService.getActiveContracts(
new GetActiveContractsRequest(
LedgerID,
new GetActiveContractsRequestV2(
allTemplates(partyName),
true,
"",
).toProto
)
val iterable: java.lang.Iterable[GetActiveContractsResponse] = () => txs
StreamSupport
.stream(iterable.spliterator(), false)
.flatMap[CreatedEvent]((r: GetActiveContractsResponse) =>
data.GetActiveContractsResponse
data.GetActiveContractsResponseV2
.fromProto(r)
.getCreatedEvents
.getContractEntry
.map(_.getCreatedEvent)
.stream()
)
.flatMap { createdEvent =>

View File

@ -1,123 +0,0 @@
// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package com.daml
import com.daml.ledger.api.v1.command_service.SubmitAndWaitRequest
import com.daml.ledger.api.v1.command_submission_service.SubmitRequest
import com.daml.ledger.api.v1.commands.Commands
import com.daml.ledger.api.v1.event._
import com.daml.ledger.api.v1.ledger_offset.LedgerOffset
import com.daml.ledger.api.v1.ledger_offset.LedgerOffset.LedgerBoundary.{LEDGER_BEGIN, LEDGER_END}
import com.daml.ledger.api.v1.ledger_offset.LedgerOffset.Value.Boundary
import com.daml.ledger.api.v1.transaction.{Transaction, TransactionTree, TreeEvent}
import com.daml.ledger.api.v1.transaction_filter.{Filters, TransactionFilter}
import com.daml.ledger.api.v1.value.Value.Sum.Text
import com.daml.ledger.api.v1.value.{Identifier, Value}
import com.google.protobuf.timestamp.Timestamp
import scala.util.Random
object MockMessages {
val ledgerBegin = LedgerOffset(Boundary(LEDGER_BEGIN))
val ledgerEnd = LedgerOffset(Boundary(LEDGER_END))
val ledgerId = "ledgerId"
val workflowId = "workflowId"
val applicationId = "applicationId"
val commandId = "commandId"
val party = "party"
val party2 = "party2"
val ledgerEffectiveTime = Timestamp(0L, 0)
val commands = Commands(ledgerId, workflowId, applicationId, commandId, party, Nil)
val submitRequest = SubmitRequest(Some(commands))
val submitAndWaitRequest = SubmitAndWaitRequest(Some(commands))
val moduleName = "moduleName"
val transactionId = "transactionId"
val eventIdCreated = "eventIdCreate"
val eventIdExercised = "eventIdExercise"
val contractId = "contractId"
val contractIdOther = contractId + "Other"
def contractKey = Value(Text("contractKey"))
val packageId = "packageId"
val templateName = "templateName"
val choice = "choice"
val templateId = Identifier(packageId, moduleName, templateName)
val offset = "offset"
val transactionFilter =
TransactionFilter(Map(party -> Filters()))
val createdEvent = CreatedEvent(eventIdCreated + "2", contractIdOther, Some(templateId))
val exercisedEvent = ExercisedEvent(
eventIdExercised,
contractId,
Some(templateId),
None,
choice,
None,
List(party),
true,
Nil, // No witnesses
List(createdEvent.eventId),
)
val transactionTree =
TransactionTree(
transactionId,
commandId,
workflowId,
Some(ledgerEffectiveTime),
offset,
Map(
exercisedEvent.eventId -> TreeEvent(TreeEvent.Kind.Exercised(exercisedEvent)),
createdEvent.eventId -> TreeEvent(TreeEvent.Kind.Created(createdEvent)),
),
List(exercisedEvent.eventId),
)
val filteredTransaction = Transaction(
transactionId,
commandId,
workflowId,
Some(ledgerEffectiveTime),
List.empty,
offset,
)
private val NO_OF_TRANSACTIONS = 1000
private def randomId(name: String) = s"$name-${Random.nextInt(10000)}"
private def generateEvent() = ExercisedEvent(
randomId("event-id"),
randomId("contract-id"),
Some(Identifier(randomId("package-id"), randomId("moduleName"), randomId("template-id"))),
None,
randomId("choice-id"),
None,
List(randomId("party")),
Random.nextBoolean(),
Nil,
)
def generateMockTransactions(): List[TransactionTree] =
(1 to NO_OF_TRANSACTIONS).map { i =>
val event = generateEvent()
TransactionTree(
randomId("transaction"),
randomId("command"),
randomId("workflow"),
Some(ledgerEffectiveTime),
i.toString,
Map(event.eventId -> TreeEvent(TreeEvent.Kind.Exercised(event))),
List(event.eventId),
)
}.toList
}