-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more shared infrastructure for non-repudiation testing (#9035)
More dummy participant components, shared across the non-repudiation sub-tree. These will also be used in client bindings tests. changelog_begin changelog_end
- Loading branch information
1 parent
7514074
commit ae11036
Showing
7 changed files
with
155 additions
and
56 deletions.
There are no files selected for viewing
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
46 changes: 46 additions & 0 deletions
46
...udiation-testing/src/main/scala/com/daml/nonrepudiation/testing/DummyCommandService.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,46 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.nonrepudiation.testing | ||
|
||
import com.daml.ledger.api.v1.command_service.CommandServiceGrpc.CommandService | ||
import com.daml.ledger.api.v1.command_service.{ | ||
CommandServiceGrpc, | ||
SubmitAndWaitForTransactionIdResponse, | ||
SubmitAndWaitForTransactionResponse, | ||
SubmitAndWaitForTransactionTreeResponse, | ||
SubmitAndWaitRequest, | ||
} | ||
import com.google.protobuf.empty.Empty | ||
import io.grpc.ServerServiceDefinition | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
object DummyCommandService { | ||
|
||
def bind(executionContext: ExecutionContext): ServerServiceDefinition = | ||
CommandServiceGrpc.bindService(new DummyCommandService, executionContext) | ||
|
||
} | ||
|
||
final class DummyCommandService private extends CommandService { | ||
|
||
override def submitAndWait(request: SubmitAndWaitRequest): Future[Empty] = | ||
Future.successful(Empty.defaultInstance) | ||
|
||
override def submitAndWaitForTransactionId( | ||
request: SubmitAndWaitRequest | ||
): Future[SubmitAndWaitForTransactionIdResponse] = | ||
Future.successful(SubmitAndWaitForTransactionIdResponse.defaultInstance) | ||
|
||
override def submitAndWaitForTransaction( | ||
request: SubmitAndWaitRequest | ||
): Future[SubmitAndWaitForTransactionResponse] = | ||
Future.successful(SubmitAndWaitForTransactionResponse.defaultInstance) | ||
|
||
override def submitAndWaitForTransactionTree( | ||
request: SubmitAndWaitRequest | ||
): Future[SubmitAndWaitForTransactionTreeResponse] = | ||
Future.successful(SubmitAndWaitForTransactionTreeResponse.defaultInstance) | ||
|
||
} |
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
28 changes: 28 additions & 0 deletions
28
...n-testing/src/main/scala/com/daml/nonrepudiation/testing/DummyLedgerIdentityService.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,28 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.nonrepudiation.testing | ||
|
||
import com.daml.ledger.api.v1.ledger_identity_service.LedgerIdentityServiceGrpc.LedgerIdentityService | ||
import com.daml.ledger.api.v1.ledger_identity_service.{ | ||
GetLedgerIdentityRequest, | ||
GetLedgerIdentityResponse, | ||
LedgerIdentityServiceGrpc, | ||
} | ||
import io.grpc.ServerServiceDefinition | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
object DummyLedgerIdentityService { | ||
|
||
def bind(executionContext: ExecutionContext): ServerServiceDefinition = | ||
LedgerIdentityServiceGrpc.bindService(new DummyLedgerIdentityService, executionContext) | ||
|
||
} | ||
|
||
final class DummyLedgerIdentityService private extends LedgerIdentityService { | ||
override def getLedgerIdentity( | ||
request: GetLedgerIdentityRequest | ||
): Future[GetLedgerIdentityResponse] = | ||
Future.successful(GetLedgerIdentityResponse.of("dummy")) | ||
} |
71 changes: 71 additions & 0 deletions
71
...n-repudiation-testing/src/main/scala/com/daml/nonrepudiation/testing/DummyTestSetup.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,71 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.nonrepudiation.testing | ||
|
||
import java.net.{InetAddress, InetSocketAddress, SocketAddress} | ||
|
||
import com.daml.ports.FreePort | ||
import io.grpc.inprocess.{InProcessChannelBuilder, InProcessServerBuilder} | ||
import io.grpc.netty.{NettyChannelBuilder, NettyServerBuilder} | ||
import io.grpc.protobuf.services.ProtoReflectionService | ||
import io.grpc.{ManagedChannelBuilder, ServerBuilder} | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
object DummyTestSetup { | ||
|
||
final class Builders( | ||
val participantServer: ServerBuilder[_ <: ServerBuilder[_]], | ||
val participantChannel: ManagedChannelBuilder[_ <: ManagedChannelBuilder[_]], | ||
val proxyServer: ServerBuilder[_ <: ServerBuilder[_]], | ||
val proxyChannel: ManagedChannelBuilder[_ <: ManagedChannelBuilder[_]], | ||
) | ||
|
||
object Builders { | ||
|
||
private def withRequiredServices[Builder <: ServerBuilder[Builder]]( | ||
builder: Builder, | ||
executionContext: ExecutionContext, | ||
): Builder = | ||
builder | ||
.addService(DummyLedgerIdentityService.bind(executionContext)) | ||
.addService(DummyCommandSubmissionService.bind(executionContext)) | ||
.addService(DummyCommandService.bind(executionContext)) | ||
.addService(ProtoReflectionService.newInstance()) | ||
|
||
def apply(useNetworkStack: Boolean, serviceExecutionContext: ExecutionContext): Builders = { | ||
if (useNetworkStack) { | ||
val participantPort: Int = FreePort.find().value | ||
val participantAddress: SocketAddress = | ||
new InetSocketAddress(InetAddress.getLoopbackAddress, participantPort) | ||
val proxyPort: Int = FreePort.find().value | ||
val proxyAddress: SocketAddress = | ||
new InetSocketAddress(InetAddress.getLoopbackAddress, proxyPort) | ||
new Builders( | ||
withRequiredServices( | ||
NettyServerBuilder.forPort(participantPort), | ||
serviceExecutionContext, | ||
), | ||
NettyChannelBuilder.forAddress(participantAddress).usePlaintext(), | ||
NettyServerBuilder.forPort(proxyPort), | ||
NettyChannelBuilder.forAddress(proxyAddress).usePlaintext(), | ||
) | ||
} else { | ||
val participantName: String = InProcessServerBuilder.generateName() | ||
val proxyName: String = InProcessServerBuilder.generateName() | ||
new Builders( | ||
withRequiredServices( | ||
InProcessServerBuilder.forName(participantName), | ||
serviceExecutionContext, | ||
), | ||
InProcessChannelBuilder.forName(participantName), | ||
InProcessServerBuilder.forName(proxyName), | ||
InProcessChannelBuilder.forName(proxyName), | ||
) | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
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