mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-11 12:59:17 +03:00
remove script/trigger/cantonFixture deps on scala-bindings (#17954)
Basically we remove the dependency of different components on "//language-support/scala/bindings" by: - replacing com.daml.ledger.api.refinements.ApiTypes.Party by com.daml.lf.data.Ref.Party - replacing com.daml.ledger.api.refinements.ApiTypes.ApplicationId by Option[com.daml.lf.data.Ref.ApplicationId] (here we use option as ApiTypes.ApplicationId allows empty string while Ref.ApplicationId does not). - adding rounding logic for timestamp in com.daml.lf.data.Time.Timestamp and use it instead of the one from com.daml.api.util.TimestampConversion Note we did not clean daml-sript export as it have never pass the alpha stage and will be dropped with the 3.x fork.
This commit is contained in:
parent
935b351f74
commit
96f16df3c0
@ -35,7 +35,7 @@ object MeteringReport {
|
||||
final case class ApplicationReport(application: ApplicationId, events: Long)
|
||||
|
||||
implicit val TimestampFormat: RootJsonFormat[Timestamp] =
|
||||
stringJsonFormat(Timestamp.fromString)(_.toString)
|
||||
stringJsonFormat(Timestamp.fromString(_))(_.toString)
|
||||
|
||||
implicit val ApplicationIdFormat: RootJsonFormat[ApplicationId] =
|
||||
stringJsonFormat(ApplicationId.fromString)(identity)
|
||||
|
@ -8,7 +8,7 @@ import org.apache.pekko.actor.ActorSystem
|
||||
import org.apache.pekko.stream._
|
||||
import com.daml.auth.TokenHolder
|
||||
import com.daml.lf.PureCompiledPackages
|
||||
import com.daml.lf.data.assertRight
|
||||
import com.daml.lf.data.{assertRight, Ref}
|
||||
import com.daml.lf.data.Ref._
|
||||
import com.daml.lf.engine.script._
|
||||
import com.daml.lf.language.Ast._
|
||||
@ -22,7 +22,6 @@ import com.daml.lf.language.{
|
||||
import com.daml.lf.speedy.SExpr._
|
||||
import com.daml.lf.speedy.{Compiler, SDefinition, SError, SValue}
|
||||
import com.daml.grpc.adapter.{PekkoExecutionSequencerPool, ExecutionSequencerFactory}
|
||||
import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
|
||||
import com.daml.ledger.api.tls.{TlsConfiguration, TlsConfigurationCli}
|
||||
import com.daml.scalautil.Statement.discard
|
||||
import com.typesafe.scalalogging.StrictLogging
|
||||
@ -51,7 +50,7 @@ object ReplServiceMain extends App {
|
||||
ledgerHost: Option[String],
|
||||
ledgerPort: Option[Int],
|
||||
accessTokenFile: Option[Path],
|
||||
applicationId: Option[ApplicationId],
|
||||
applicationId: Option[Option[Ref.ApplicationId]],
|
||||
maxInboundMessageSize: Int,
|
||||
tlsConfig: TlsConfiguration,
|
||||
// optional so we can detect if both --static-time and --wall-clock-time are passed.
|
||||
@ -93,7 +92,9 @@ object ReplServiceMain extends App {
|
||||
opt[String]("application-id")
|
||||
.optional()
|
||||
.action { (appId, c) =>
|
||||
c.copy(applicationId = Some(ApplicationId(appId)))
|
||||
c.copy(applicationId =
|
||||
Some(Some(appId).filter(_.nonEmpty).map(Ref.ApplicationId.assertFromString))
|
||||
)
|
||||
}
|
||||
|
||||
TlsConfigurationCli.parse(this, colSpacer = " ")((f, c) =>
|
||||
|
@ -17,10 +17,12 @@ da_scala_binary(
|
||||
main_class = "com.daml.lf.scenario.ScenarioServiceMain",
|
||||
resources = glob(["src/main/resources/*"]),
|
||||
scala_deps = [
|
||||
"@maven//:com_github_scopt_scopt",
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_typelevel_paiges_core",
|
||||
"@maven//:com_github_scopt_scopt",
|
||||
],
|
||||
scalacopts = lf_scalacopts_stricter,
|
||||
runtime_deps = [
|
||||
@ -37,13 +39,13 @@ da_scala_binary(
|
||||
"//daml-lf/validation",
|
||||
"//daml-script/converter",
|
||||
"//daml-script/runner:script-runner-lib",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//libs-scala/contextualized-logging",
|
||||
"//libs-scala/rs-grpc-bridge",
|
||||
"//libs-scala/rs-grpc-pekko",
|
||||
"@maven//:com_google_protobuf_protobuf_java",
|
||||
"@maven//:io_grpc_grpc_api",
|
||||
"@maven//:io_grpc_grpc_netty",
|
||||
"@maven//:io_grpc_grpc_stub",
|
||||
"@maven//:org_slf4j_slf4j_api",
|
||||
],
|
||||
)
|
||||
|
@ -3,20 +3,25 @@
|
||||
|
||||
package com.daml.lf.data
|
||||
|
||||
import java.math.{RoundingMode, BigDecimal}
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.temporal.ChronoField
|
||||
import java.time.temporal.ChronoUnit.MICROS
|
||||
import java.time.{Duration, Instant, LocalDate, ZoneId}
|
||||
import java.time.temporal.{ChronoField, ChronoUnit}
|
||||
import java.time.{ZoneId, Instant, Duration, LocalDate}
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
import scalaz.std.anyVal._
|
||||
import scalaz.syntax.order._
|
||||
import scalaz.{Order, Ordering}
|
||||
|
||||
import scala.util.Try
|
||||
|
||||
object Time {
|
||||
|
||||
private[this] def safely[X](x: => X, error: String): Either[String, X] =
|
||||
try {
|
||||
Right(x)
|
||||
} catch {
|
||||
case scala.util.control.NonFatal(e) => Left(error + ":" + e.getMessage)
|
||||
}
|
||||
|
||||
case class Date private (days: Int) extends Ordered[Date] {
|
||||
|
||||
override def toString: String =
|
||||
@ -28,6 +33,7 @@ object Time {
|
||||
|
||||
object Date {
|
||||
|
||||
@deprecated("use com.daml.lf.data.Time.Data", since = "2.9.0")
|
||||
type T = Date
|
||||
|
||||
private val formatter: DateTimeFormatter =
|
||||
@ -59,12 +65,11 @@ object Time {
|
||||
Left(s"out of bound Date $days")
|
||||
|
||||
def fromString(str: String): Either[String, Date] =
|
||||
Try(assertDaysFromString(str)).toEither.left
|
||||
.map(_ => s"cannot interpret $str as Date")
|
||||
safely(assertDaysFromString(str), s"""cannot interpret string "$str" as Date""")
|
||||
.flatMap(fromDaysSinceEpoch)
|
||||
|
||||
@throws[IllegalArgumentException]
|
||||
final def assertFromString(s: String): T =
|
||||
final def assertFromString(s: String): Date =
|
||||
assertRight(fromString(s))
|
||||
|
||||
def assertFromDaysSinceEpoch(days: Int): Date =
|
||||
@ -112,57 +117,74 @@ object Time {
|
||||
|
||||
object Timestamp {
|
||||
|
||||
// TODO: https://github.com/digital-asset/daml/issues/17965
|
||||
// lets change that HalfUp for daml 3.
|
||||
val DefaultRounding = RoundingMode.FLOOR
|
||||
|
||||
@deprecated("use com.daml.lf.data.Time.Data", since = "2.9.0")
|
||||
type T = Timestamp
|
||||
|
||||
val Resolution: Duration = Duration.of(1L, ChronoUnit.MICROS)
|
||||
|
||||
private val formatter: DateTimeFormatter =
|
||||
DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.of("Z"))
|
||||
|
||||
private def assertMicrosFromInstant(i: Instant): Long =
|
||||
TimeUnit.SECONDS.toMicros(i.getEpochSecond) + TimeUnit.NANOSECONDS.toMicros(i.getNano.toLong)
|
||||
private[this] val ResolutionInNanos = BigDecimal.valueOf(Resolution.toNanos)
|
||||
private[this] val OneSecondInNanos = BigDecimal.valueOf(TimeUnit.SECONDS.toNanos(1))
|
||||
|
||||
private def assertMicrosFromString(str: String): Long =
|
||||
assertMicrosFromInstant(Instant.parse(str))
|
||||
private[this] def assertMicrosFromEpochSeconds(
|
||||
seconds: Long,
|
||||
nanos: Long,
|
||||
roundingMode: RoundingMode,
|
||||
): Long = {
|
||||
val secondPart = BigDecimal.valueOf(seconds) multiply OneSecondInNanos
|
||||
val nanoPart = BigDecimal.valueOf(nanos)
|
||||
val totalInNanos = secondPart add nanoPart
|
||||
totalInNanos.divide(ResolutionInNanos, roundingMode).longValueExact()
|
||||
}
|
||||
|
||||
private[this] def assertMicrosFromInstant(i: Instant, rounding: RoundingMode): Long =
|
||||
assertMicrosFromEpochSeconds(i.getEpochSecond, i.getNano.toLong, rounding)
|
||||
|
||||
private[this] def assertMicrosFromString(str: String, rounding: RoundingMode): Long =
|
||||
assertMicrosFromInstant(Instant.parse(str), rounding)
|
||||
|
||||
val MinValue: Timestamp =
|
||||
Timestamp(assertMicrosFromString("0001-01-01T00:00:00.000000Z"))
|
||||
Timestamp(assertMicrosFromString("0001-01-01T00:00:00.000000Z", RoundingMode.UNNECESSARY))
|
||||
|
||||
val MaxValue: Timestamp =
|
||||
Timestamp(assertMicrosFromString("9999-12-31T23:59:59.999999Z"))
|
||||
Timestamp(assertMicrosFromString("9999-12-31T23:59:59.999999Z", RoundingMode.UNNECESSARY))
|
||||
|
||||
val Resolution: Duration = Duration.of(1L, MICROS)
|
||||
val Epoch: Timestamp = Timestamp(0)
|
||||
|
||||
val Epoch: Timestamp =
|
||||
Timestamp(0)
|
||||
|
||||
def now(): Timestamp =
|
||||
assertFromLong(assertMicrosFromInstant(Instant.now()))
|
||||
def assertFromLong(micros: Long): Timestamp =
|
||||
if (MinValue.micros <= micros && micros <= MaxValue.micros)
|
||||
Timestamp(micros)
|
||||
else
|
||||
throw new IllegalArgumentException(s"out of bound Timestamp $micros")
|
||||
|
||||
def fromLong(micros: Long): Either[String, Timestamp] =
|
||||
if (MinValue.micros <= micros && micros <= MaxValue.micros)
|
||||
Right(Timestamp(micros))
|
||||
else
|
||||
Left(s"out of bound Timestamp $micros")
|
||||
safely(assertFromLong(micros), s"cannot convert long $micros into Timestamp")
|
||||
|
||||
@throws[IllegalArgumentException]
|
||||
def assertFromLong(micros: Long): Timestamp =
|
||||
assertRight(fromLong(micros))
|
||||
def assertFromInstant(i: Instant, rounding: RoundingMode = DefaultRounding): Timestamp =
|
||||
assertFromLong(assertMicrosFromInstant(i, rounding))
|
||||
|
||||
def fromString(str: String): Either[String, Timestamp] =
|
||||
Try(assertMicrosFromString(str)).toEither.left
|
||||
.map(_ => s"cannot interpret $str as Timestamp")
|
||||
.flatMap(fromLong)
|
||||
def fromInstant(
|
||||
i: Instant,
|
||||
rounding: RoundingMode = DefaultRounding,
|
||||
): Either[String, Timestamp] =
|
||||
safely(assertFromInstant(i, rounding), s"cannot convert instant $i into Timestamp")
|
||||
|
||||
@throws[IllegalArgumentException]
|
||||
final def assertFromString(s: String): T =
|
||||
assertRight(fromString(s))
|
||||
def assertFromString(str: String, rounding: RoundingMode = DefaultRounding): Timestamp =
|
||||
assertFromLong(assertMicrosFromString(str, rounding))
|
||||
|
||||
def fromInstant(i: Instant): Either[String, Timestamp] =
|
||||
Try(assertMicrosFromInstant(i)).toEither.left
|
||||
.map(_ => s"cannot interpret $i as Timestamp")
|
||||
.flatMap(fromLong)
|
||||
final def fromString(
|
||||
s: String,
|
||||
rounding: RoundingMode = DefaultRounding,
|
||||
): Either[String, Timestamp] =
|
||||
safely(assertFromString(s, rounding), s"cannot convert sting $s into Timestamp")
|
||||
|
||||
def assertFromInstant(i: Instant): Timestamp =
|
||||
assertFromLong(assertMicrosFromInstant(i))
|
||||
def now(): Timestamp = assertFromInstant(Instant.now(), DefaultRounding)
|
||||
|
||||
implicit val `Time.Timestamp Order`: Order[Timestamp] = new Order[Timestamp] {
|
||||
override def equalIsNatural = true
|
||||
|
@ -21,7 +21,5 @@ da_scala_library(
|
||||
"//daml-lf/interpreter",
|
||||
"//daml-lf/language",
|
||||
"//daml-lf/transaction",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
],
|
||||
)
|
||||
|
@ -62,7 +62,7 @@ final class ReproducesTransactions
|
||||
Some(
|
||||
Commands(
|
||||
ledgerId = client.ledgerId.unwrap,
|
||||
applicationId = applicationId.unwrap,
|
||||
applicationId = applicationId.getOrElse(""),
|
||||
commandId = UUID.randomUUID().toString(),
|
||||
party = p,
|
||||
commands = Seq(cmd),
|
||||
|
@ -47,6 +47,8 @@ da_scala_library(
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_apache_pekko_pekko_http_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_typelevel_paiges_core",
|
||||
@ -57,6 +59,7 @@ da_scala_library(
|
||||
tags = ["maven_coordinates=com.daml:daml-script-runner:__VERSION__"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//canton:ledger_api_proto_scala",
|
||||
"//daml-lf/api-type-signature",
|
||||
"//daml-lf/archive:daml_lf_archive_reader",
|
||||
"//daml-lf/archive:daml_lf_dev_archive_proto_java",
|
||||
@ -67,8 +70,6 @@ da_scala_library(
|
||||
"//daml-lf/scenario-interpreter",
|
||||
"//daml-lf/transaction",
|
||||
"//daml-script/converter",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger-service/cli-opts",
|
||||
"//ledger-service/lf-value-json",
|
||||
"//ledger/error",
|
||||
@ -76,13 +77,17 @@ da_scala_library(
|
||||
"//ledger/ledger-api-auth-client",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//ledger/ledger-api-domain",
|
||||
"//ledger/participant-local-store",
|
||||
"//libs-scala/auth-utils",
|
||||
"//libs-scala/contextualized-logging",
|
||||
"//libs-scala/jwt",
|
||||
"//libs-scala/nonempty",
|
||||
"//libs-scala/rs-grpc-bridge",
|
||||
"//libs-scala/rs-grpc-pekko",
|
||||
"@maven//:com_google_guava_guava",
|
||||
"@maven//:io_grpc_grpc_netty",
|
||||
"@maven//:io_netty_netty_handler",
|
||||
],
|
||||
)
|
||||
|
||||
@ -113,18 +118,22 @@ da_scala_test(
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_scalatest_scalatest_core",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
],
|
||||
deps = [
|
||||
"//bazel_tools/runfiles:scala_runfiles",
|
||||
"//canton:ledger_api_proto_scala",
|
||||
"//daml-lf/archive:daml_lf_archive_reader",
|
||||
"//daml-lf/archive:daml_lf_dev_archive_proto_java",
|
||||
"//daml-lf/data",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger-service/http-json:http-json-ce",
|
||||
"//ledger-service/http-json-cli:ce",
|
||||
"//ledger-service/http-json-testing:ce",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//ledger/ledger-api-domain",
|
||||
"//libs-scala/jwt",
|
||||
"//libs-scala/ledger-resources",
|
||||
"//libs-scala/ports",
|
||||
|
@ -10,7 +10,6 @@ import org.apache.pekko.http.scaladsl.model.Uri
|
||||
import org.apache.pekko.stream.Materializer
|
||||
import com.daml.grpc.adapter.ExecutionSequencerFactory
|
||||
import com.daml.jwt.domain.Jwt
|
||||
import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
|
||||
import com.daml.ledger.api.tls.TlsConfiguration
|
||||
import com.daml.ledger.client.LedgerClient
|
||||
import com.daml.ledger.client.configuration.{
|
||||
@ -20,6 +19,7 @@ import com.daml.ledger.client.configuration.{
|
||||
LedgerIdRequirement,
|
||||
}
|
||||
import com.daml.lf.archive.Dar
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref._
|
||||
import com.daml.lf.engine.script.ParticipantsJsonProtocol.ContractIdFormat
|
||||
import com.daml.lf.engine.script.ledgerinteraction.{
|
||||
@ -71,7 +71,7 @@ case class ApiParameters(
|
||||
host: String,
|
||||
port: Int,
|
||||
access_token: Option[String],
|
||||
application_id: Option[ApplicationId],
|
||||
application_id: Option[Option[Ref.ApplicationId]],
|
||||
adminPort: Option[Int] = None,
|
||||
)
|
||||
case class Participants[+T](
|
||||
@ -168,12 +168,12 @@ object ParticipantsJsonProtocol extends DefaultJsonProtocol {
|
||||
case _ => deserializationError("ContractId must be a string")
|
||||
}
|
||||
}
|
||||
implicit object ApplicationIdFormat extends JsonFormat[ApplicationId] {
|
||||
implicit object ApplicationIdFormat extends JsonFormat[Option[Ref.ApplicationId]] {
|
||||
def read(value: JsValue) = value match {
|
||||
case JsString(s) => ApplicationId(s)
|
||||
case JsString(s) => Some(s).filter(_.nonEmpty).map(Ref.ApplicationId.assertFromString)
|
||||
case _ => deserializationError("Expected ApplicationId string")
|
||||
}
|
||||
def write(id: ApplicationId) = JsString(ApplicationId.unwrap(id))
|
||||
def write(id: Option[Ref.ApplicationId]) = JsString(id.getOrElse(""))
|
||||
}
|
||||
implicit val apiParametersFormat: RootJsonFormat[ApiParameters] = jsonFormat5(ApiParameters)
|
||||
implicit val participantsFormat: RootJsonFormat[Participants[ApiParameters]] = jsonFormat3(
|
||||
@ -250,8 +250,10 @@ object Runner {
|
||||
)
|
||||
}
|
||||
|
||||
val BLANK_APPLICATION_ID: ApplicationId = ApplicationId("")
|
||||
val DEFAULT_APPLICATION_ID: ApplicationId = ApplicationId("daml-script")
|
||||
val BLANK_APPLICATION_ID: Option[Ref.ApplicationId] = None
|
||||
val DEFAULT_APPLICATION_ID: Option[Ref.ApplicationId] = Some(
|
||||
Ref.ApplicationId.assertFromString("daml-script")
|
||||
)
|
||||
private[script] def connectApiParameters(
|
||||
params: ApiParameters,
|
||||
tlsConfig: TlsConfiguration,
|
||||
@ -264,7 +266,7 @@ object Runner {
|
||||
if (params.access_token.nonEmpty) BLANK_APPLICATION_ID else DEFAULT_APPLICATION_ID
|
||||
)
|
||||
val clientConfig = LedgerClientConfiguration(
|
||||
applicationId = ApplicationId.unwrap(applicationId),
|
||||
applicationId = applicationId.getOrElse(""),
|
||||
ledgerIdRequirement = LedgerIdRequirement.none,
|
||||
commandClient = CommandClientConfiguration.default,
|
||||
token = params.access_token,
|
||||
@ -315,10 +317,15 @@ object Runner {
|
||||
Future.failed(new RuntimeException(s"The JSON API always requires access tokens"))
|
||||
case Some(token) =>
|
||||
val client = new JsonLedgerClient(uri, Jwt(token), envSig, system)
|
||||
if (params.application_id.isDefined && params.application_id != client.applicationId) {
|
||||
if (
|
||||
params.application_id.isDefined && params.application_id.map(
|
||||
_.getOrElse("")
|
||||
) != client.applicationId
|
||||
) {
|
||||
Future.failed(
|
||||
new RuntimeException(
|
||||
s"ApplicationId specified in token ${client.applicationId} must match ${params.application_id}"
|
||||
s"ApplicationId specified in token ${client.applicationId} must match ${params.application_id
|
||||
.map(_.getOrElse(""))}"
|
||||
)
|
||||
)
|
||||
} else {
|
||||
|
@ -6,7 +6,7 @@ package com.daml.lf.engine.script
|
||||
import java.nio.file.{Path, Paths}
|
||||
import java.io.File
|
||||
|
||||
import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.ledger.api.tls.{TlsConfiguration, TlsConfigurationCli}
|
||||
|
||||
case class RunnerMainConfig(
|
||||
@ -22,7 +22,7 @@ case class RunnerMainConfig(
|
||||
// While we do have a default application id, we
|
||||
// want to differentiate between not specifying the application id
|
||||
// and specifying the default for better error messages.
|
||||
applicationId: Option[ApplicationId],
|
||||
applicationId: Option[Option[Ref.ApplicationId]],
|
||||
uploadDar: Boolean,
|
||||
enableContractUpgrading: Boolean,
|
||||
)
|
||||
@ -74,7 +74,7 @@ private[script] case class RunnerMainConfigIntermediate(
|
||||
// While we do have a default application id, we
|
||||
// want to differentiate between not specifying the application id
|
||||
// and specifying the default for better error messages.
|
||||
applicationId: Option[ApplicationId],
|
||||
applicationId: Option[Option[Ref.ApplicationId]],
|
||||
// Legacy behaviour is to upload the dar when using --all and over grpc. None represents that behaviour
|
||||
// We will drop this for daml3, such that we default to not uploading.
|
||||
uploadDar: Option[Boolean],
|
||||
@ -262,7 +262,11 @@ private[script] object RunnerMainConfigIntermediate {
|
||||
)
|
||||
|
||||
opt[String]("application-id")
|
||||
.action((x, c) => c.copy(applicationId = Some(ApplicationId(x))))
|
||||
.action((x, c) =>
|
||||
c.copy(applicationId =
|
||||
Some(Some(x).filter(_.nonEmpty).map(Ref.ApplicationId.assertFromString))
|
||||
)
|
||||
)
|
||||
.optional()
|
||||
.text(
|
||||
s"Application ID used to interact with the ledger. Defaults to ${Runner.DEFAULT_APPLICATION_ID}"
|
||||
|
@ -5,7 +5,7 @@ package com.daml.lf
|
||||
package engine.script.ledgerinteraction
|
||||
|
||||
import com.daml.ledger.client.LedgerClient
|
||||
import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.engine.script.v2.ledgerinteraction.grpcLedgerClient.AdminLedgerClient
|
||||
import com.daml.lf.speedy.{TraceLog, WarningLog}
|
||||
import org.apache.pekko.http.scaladsl.model._
|
||||
@ -31,7 +31,7 @@ sealed trait ScriptLedgerClient extends Product with Serializable
|
||||
|
||||
final case class GrpcLedgerClient(
|
||||
grpcClient: LedgerClient,
|
||||
val applicationId: ApplicationId,
|
||||
val applicationId: Option[Ref.ApplicationId],
|
||||
val grpcAdminClient: Option[AdminLedgerClient] = None,
|
||||
) extends ScriptLedgerClient
|
||||
|
||||
|
@ -5,13 +5,13 @@ package com.daml.lf.engine.script
|
||||
package v1.ledgerinteraction
|
||||
|
||||
import java.util.UUID
|
||||
import java.time.Instant
|
||||
|
||||
import org.apache.pekko.stream.Materializer
|
||||
import org.apache.pekko.stream.scaladsl.Sink
|
||||
import com.daml.api.util.TimestampConversion
|
||||
import com.daml.grpc.adapter.ExecutionSequencerFactory
|
||||
import com.daml.grpc.adapter.client.pekko.ClientAdapter
|
||||
import com.daml.ledger.api.domain.{User, UserRight}
|
||||
import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
|
||||
import com.daml.ledger.api.v1.active_contracts_service.GetActiveContractsResponse
|
||||
import com.daml.ledger.api.v1.command_service.SubmitAndWaitRequest
|
||||
import com.daml.ledger.api.v1.commands._
|
||||
@ -40,6 +40,7 @@ import com.daml.platform.participant.util.LfEngineToApi.{
|
||||
lfValueToApiRecord,
|
||||
lfValueToApiValue,
|
||||
toApiIdentifier,
|
||||
toTimestamp,
|
||||
}
|
||||
import com.daml.script.converter.ConverterException
|
||||
import io.grpc.{Status, StatusRuntimeException}
|
||||
@ -53,7 +54,7 @@ import scalaz.syntax.tag._
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
||||
class GrpcLedgerClient(val grpcClient: LedgerClient, val applicationId: ApplicationId)
|
||||
class GrpcLedgerClient(val grpcClient: LedgerClient, val applicationId: Option[Ref.ApplicationId])
|
||||
extends ScriptLedgerClient {
|
||||
override val transport = "gRPC API"
|
||||
|
||||
@ -275,7 +276,7 @@ class GrpcLedgerClient(val grpcClient: LedgerClient, val applicationId: Applicat
|
||||
disclosedContracts = ledgerDisclosures,
|
||||
commands = ledgerCommands,
|
||||
ledgerId = grpcClient.ledgerId.unwrap,
|
||||
applicationId = applicationId.unwrap,
|
||||
applicationId = applicationId.getOrElse(""),
|
||||
commandId = UUID.randomUUID.toString,
|
||||
)
|
||||
val request = SubmitAndWaitRequest(Some(apiCommands))
|
||||
@ -332,7 +333,7 @@ class GrpcLedgerClient(val grpcClient: LedgerClient, val applicationId: Applicat
|
||||
readAs = readAs.toList,
|
||||
commands = ledgerCommands,
|
||||
ledgerId = grpcClient.ledgerId.unwrap,
|
||||
applicationId = applicationId.unwrap,
|
||||
applicationId = applicationId.getOrElse(""),
|
||||
commandId = UUID.randomUUID.toString,
|
||||
)
|
||||
request = SubmitAndWaitRequest(Some(apiCommands))
|
||||
@ -366,7 +367,8 @@ class GrpcLedgerClient(val grpcClient: LedgerClient, val applicationId: Applicat
|
||||
resp <- ClientAdapter
|
||||
.serverStreaming(GetTimeRequest(grpcClient.ledgerId.unwrap), timeService.getTime)
|
||||
.runWith(Sink.head)
|
||||
} yield TimestampConversion.toLf(resp.getCurrentTime, TimestampConversion.ConversionMode.HalfUp)
|
||||
instant = Instant.ofEpochSecond(resp.getCurrentTime.seconds, resp.getCurrentTime.nanos.toLong)
|
||||
} yield Time.Timestamp.assertFromInstant(instant, java.math.RoundingMode.HALF_UP)
|
||||
}
|
||||
|
||||
override def setStaticTime(time: Time.Timestamp)(implicit
|
||||
@ -383,7 +385,7 @@ class GrpcLedgerClient(val grpcClient: LedgerClient, val applicationId: Applicat
|
||||
SetTimeRequest(
|
||||
grpcClient.ledgerId.unwrap,
|
||||
oldTime.currentTime,
|
||||
Some(TimestampConversion.fromInstant(time.toInstant)),
|
||||
Some(toTimestamp(time.toInstant)),
|
||||
)
|
||||
)
|
||||
} yield ()
|
||||
|
@ -5,14 +5,13 @@ package com.daml.lf.engine.script
|
||||
package v2.ledgerinteraction
|
||||
package grpcLedgerClient
|
||||
|
||||
import java.time.Instant
|
||||
import java.util.UUID
|
||||
import org.apache.pekko.stream.Materializer
|
||||
import org.apache.pekko.stream.scaladsl.Sink
|
||||
import com.daml.api.util.TimestampConversion
|
||||
import com.daml.grpc.adapter.ExecutionSequencerFactory
|
||||
import com.daml.grpc.adapter.client.pekko.ClientAdapter
|
||||
import com.daml.ledger.api.domain.{User, UserRight}
|
||||
import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
|
||||
import com.daml.ledger.api.v1.active_contracts_service.GetActiveContractsResponse
|
||||
import com.daml.ledger.api.v1.command_service.SubmitAndWaitRequest
|
||||
import com.daml.ledger.api.v1.commands._
|
||||
@ -38,9 +37,10 @@ import com.daml.lf.speedy.{SValue, svalue}
|
||||
import com.daml.lf.value.Value
|
||||
import com.daml.lf.value.Value.ContractId
|
||||
import com.daml.platform.participant.util.LfEngineToApi.{
|
||||
lfValueToApiRecord,
|
||||
lfValueToApiValue,
|
||||
toApiIdentifier,
|
||||
lfValueToApiRecord,
|
||||
toTimestamp,
|
||||
}
|
||||
import com.daml.script.converter.ConverterException
|
||||
import io.grpc.{Status, StatusRuntimeException}
|
||||
@ -56,7 +56,7 @@ import scala.concurrent.{ExecutionContext, Future}
|
||||
|
||||
class GrpcLedgerClient(
|
||||
val grpcClient: LedgerClient,
|
||||
val applicationId: ApplicationId,
|
||||
val applicationId: Option[Ref.ApplicationId],
|
||||
val oAdminClient: Option[AdminLedgerClient],
|
||||
override val enableContractUpgrading: Boolean = false,
|
||||
) extends ScriptLedgerClient {
|
||||
@ -331,7 +331,7 @@ class GrpcLedgerClient(
|
||||
readAs = readAs.toList,
|
||||
commands = ledgerCommands,
|
||||
ledgerId = grpcClient.ledgerId.unwrap,
|
||||
applicationId = applicationId.unwrap,
|
||||
applicationId = applicationId.getOrElse(""),
|
||||
commandId = UUID.randomUUID.toString,
|
||||
disclosedContracts = ledgerDisclosures,
|
||||
)
|
||||
@ -389,7 +389,7 @@ class GrpcLedgerClient(
|
||||
readAs = readAs.toList,
|
||||
commands = ledgerCommands,
|
||||
ledgerId = grpcClient.ledgerId.unwrap,
|
||||
applicationId = applicationId.unwrap,
|
||||
applicationId = applicationId.getOrElse(""),
|
||||
commandId = UUID.randomUUID.toString,
|
||||
)
|
||||
request = SubmitAndWaitRequest(Some(apiCommands))
|
||||
@ -425,7 +425,8 @@ class GrpcLedgerClient(
|
||||
resp <- ClientAdapter
|
||||
.serverStreaming(GetTimeRequest(grpcClient.ledgerId.unwrap), timeService.getTime)
|
||||
.runWith(Sink.head)
|
||||
} yield TimestampConversion.toLf(resp.getCurrentTime, TimestampConversion.ConversionMode.HalfUp)
|
||||
instant = Instant.ofEpochSecond(resp.getCurrentTime.seconds, resp.getCurrentTime.nanos.toLong)
|
||||
} yield Time.Timestamp.assertFromInstant(instant, java.math.RoundingMode.HALF_UP)
|
||||
}
|
||||
|
||||
override def setStaticTime(time: Time.Timestamp)(implicit
|
||||
@ -442,7 +443,7 @@ class GrpcLedgerClient(
|
||||
SetTimeRequest(
|
||||
grpcClient.ledgerId.unwrap,
|
||||
oldTime.currentTime,
|
||||
Some(TimestampConversion.fromInstant(time.toInstant)),
|
||||
Some(toTimestamp(time.toInstant)),
|
||||
)
|
||||
)
|
||||
} yield ()
|
||||
|
@ -150,6 +150,8 @@ da_scala_library(
|
||||
name = "test-utils",
|
||||
srcs = glob(["src/test-utils/**/*.scala"]),
|
||||
scala_deps = [
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_scalactic_scalactic",
|
||||
@ -174,8 +176,7 @@ da_scala_library(
|
||||
"//daml-lf/language",
|
||||
"//daml-lf/transaction",
|
||||
"//daml-script/runner:script-runner-lib",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//libs-scala/ledger-resources",
|
||||
"//libs-scala/ports",
|
||||
@ -184,6 +185,9 @@ da_scala_library(
|
||||
"//libs-scala/scala-utils",
|
||||
"//libs-scala/testing-utils",
|
||||
"//test-common/canton/it-lib",
|
||||
"@maven//:ch_qos_logback_logback_classic",
|
||||
"@maven//:ch_qos_logback_logback_core",
|
||||
"@maven//:io_grpc_grpc_api",
|
||||
"@maven//:org_scalatest_scalatest_compatible",
|
||||
],
|
||||
)
|
||||
@ -352,10 +356,12 @@ da_scala_test_suite(
|
||||
],
|
||||
resources = glob(["src/main/resources/**/*"]),
|
||||
scala_deps = [
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_apache_pekko_pekko_http",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_http",
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
],
|
||||
tags = [
|
||||
@ -372,8 +378,6 @@ da_scala_test_suite(
|
||||
"//daml-lf/language",
|
||||
"//daml-lf/transaction",
|
||||
"//daml-script/runner:script-runner-lib",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger-service/cli-opts",
|
||||
"//ledger-service/http-json:http-json-ce",
|
||||
"//ledger-service/http-json-cli:ce",
|
||||
@ -381,7 +385,9 @@ da_scala_test_suite(
|
||||
"//ledger-service/metrics",
|
||||
"//ledger-service/utils",
|
||||
"//ledger/ledger-api-auth",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//ledger/ledger-api-domain",
|
||||
"//libs-scala/contextualized-logging",
|
||||
"//libs-scala/fs-utils",
|
||||
"//libs-scala/jwt",
|
||||
@ -389,10 +395,13 @@ da_scala_test_suite(
|
||||
"//libs-scala/ports",
|
||||
"//libs-scala/resources",
|
||||
"//libs-scala/rs-grpc-bridge",
|
||||
"//libs-scala/rs-grpc-pekko",
|
||||
"//libs-scala/scala-utils",
|
||||
"//libs-scala/testing-utils",
|
||||
"//observability/metrics",
|
||||
"//test-common/canton/it-lib",
|
||||
"@maven//:com_google_protobuf_protobuf_java",
|
||||
"@maven//:io_netty_netty_handler",
|
||||
],
|
||||
)
|
||||
|
||||
@ -425,6 +434,8 @@ da_scala_test_suite(
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
],
|
||||
tags = [
|
||||
"cpu:4",
|
||||
@ -442,8 +453,6 @@ da_scala_test_suite(
|
||||
"//daml-lf/language",
|
||||
"//daml-lf/transaction",
|
||||
"//daml-script/runner:script-runner-lib",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger-service/cli-opts",
|
||||
"//ledger-service/http-json:http-json-ce",
|
||||
"//ledger-service/http-json-cli:ce",
|
||||
@ -451,7 +460,9 @@ da_scala_test_suite(
|
||||
"//ledger-service/metrics",
|
||||
"//ledger-service/utils",
|
||||
"//ledger/ledger-api-auth",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//ledger/ledger-api-domain",
|
||||
"//libs-scala/caching",
|
||||
"//libs-scala/contextualized-logging",
|
||||
"//libs-scala/fs-utils",
|
||||
@ -464,6 +475,7 @@ da_scala_test_suite(
|
||||
"//libs-scala/resources-grpc",
|
||||
"//libs-scala/resources-pekko",
|
||||
"//libs-scala/rs-grpc-bridge",
|
||||
"//libs-scala/rs-grpc-pekko",
|
||||
"//libs-scala/scala-utils",
|
||||
"//libs-scala/testing-utils",
|
||||
"//observability/metrics",
|
||||
|
@ -20,7 +20,6 @@ import com.daml.jwt.JwtSigner
|
||||
import com.daml.jwt.domain.DecodedJwt
|
||||
import com.daml.ledger.api.auth.{AuthServiceJWTCodec, CustomDamlJWTPayload}
|
||||
import com.daml.ledger.api.domain.{User, UserRight}
|
||||
import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
|
||||
import com.daml.ledger.api.testing.utils.{
|
||||
PekkoBeforeAndAfterAll,
|
||||
OwnedResource,
|
||||
@ -30,6 +29,7 @@ import com.daml.ledger.api.testing.utils.{
|
||||
import com.daml.ledger.api.tls.TlsConfiguration
|
||||
import com.daml.ledger.resources.{Resource, ResourceContext, ResourceOwner}
|
||||
import com.daml.lf.archive.{Dar, DarDecoder}
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref._
|
||||
import com.daml.lf.engine.script._
|
||||
import com.daml.lf.engine.script.ledgerinteraction.ScriptLedgerClient
|
||||
@ -45,7 +45,6 @@ import com.daml.ports.Port
|
||||
import org.scalatest._
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AsyncWordSpec
|
||||
import scalaz.syntax.tag._
|
||||
import scalaz.syntax.traverse._
|
||||
import scalaz.{-\/, \/-}
|
||||
import spray.json._
|
||||
@ -82,7 +81,7 @@ trait JsonApiFixture
|
||||
|
||||
val darFileNoLedger = rlocation(Paths.get("daml-script/test/script-test-no-ledger.dar"))
|
||||
|
||||
val applicationId = ApplicationId(getClass.getName)
|
||||
val applicationId = Some(Ref.ApplicationId.assertFromString(getClass.getName))
|
||||
val darFiles = List(darFile)
|
||||
|
||||
val config = CantonConfig(authSecret = Some(secret))
|
||||
@ -107,7 +106,7 @@ trait JsonApiFixture
|
||||
ledgerId = Some(ledgerId),
|
||||
participantId = None,
|
||||
exp = None,
|
||||
applicationId = Some(applicationId.unwrap),
|
||||
applicationId = Some(applicationId.getOrElse("")),
|
||||
actAs = actAs,
|
||||
readAs = readAs,
|
||||
admin = admin,
|
||||
@ -186,7 +185,7 @@ final class JsonApiIt extends AsyncWordSpec with JsonApiFixture with Matchers wi
|
||||
parties: List[String],
|
||||
defaultParty: Option[Party] = None,
|
||||
admin: Boolean = false,
|
||||
applicationId: Option[ApplicationId] = None,
|
||||
applicationId: Option[Option[Ref.ApplicationId]] = None,
|
||||
envIface: EnvironmentSignature = envIface,
|
||||
) = {
|
||||
// We give the default participant some nonsense party so the checks for party mismatch fail
|
||||
@ -219,7 +218,7 @@ final class JsonApiIt extends AsyncWordSpec with JsonApiFixture with Matchers wi
|
||||
private def getMultiPartyClients(
|
||||
parties: List[String],
|
||||
readAs: List[String] = List.empty,
|
||||
applicationId: Option[ApplicationId] = None,
|
||||
applicationId: Option[Option[Ref.ApplicationId]] = None,
|
||||
envIface: EnvironmentSignature = envIface,
|
||||
) = {
|
||||
// We give the default participant some nonsense party so the checks for party mismatch fail
|
||||
@ -344,10 +343,13 @@ final class JsonApiIt extends AsyncWordSpec with JsonApiFixture with Matchers wi
|
||||
for {
|
||||
alice <- allocateParty
|
||||
exception <- recoverToExceptionIf[RuntimeException](
|
||||
getClients(List(alice), applicationId = Some(ApplicationId("wrong")))
|
||||
getClients(
|
||||
List(alice),
|
||||
applicationId = Some(Some(Ref.ApplicationId.assertFromString("wrong"))),
|
||||
)
|
||||
)
|
||||
} yield assert(
|
||||
exception.getMessage === s"ApplicationId specified in token Some(${applicationId.unwrap}) must match Some(wrong)"
|
||||
exception.getMessage === s"ApplicationId specified in token Some(${applicationId.getOrElse("")}) must match Some(wrong)"
|
||||
)
|
||||
}
|
||||
"application id correct" in {
|
||||
|
@ -403,7 +403,6 @@ da_scala_test(
|
||||
"@maven//:org_scalatest_scalatest_flatspec",
|
||||
"@maven//:org_scalatest_scalatest_matchers_core",
|
||||
"@maven//:org_scalatest_scalatest_shouldmatchers",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
],
|
||||
tags = ["cpu:4"],
|
||||
deps = [
|
||||
|
@ -481,7 +481,7 @@ class ScalaCodeGenIT
|
||||
Commands(
|
||||
ledgerId = ledger.ledgerId.unwrap,
|
||||
workflowId = WorkflowId.unwrap(workflowId),
|
||||
applicationId = applicationId.unwrap,
|
||||
applicationId = applicationId.getOrElse(""),
|
||||
commandId = CommandId.unwrap(commandId),
|
||||
party = P.Party.unwrap(party),
|
||||
commands = seq.map(_.command),
|
||||
|
@ -25,7 +25,6 @@ import com.daml.jwt.JwtSigner
|
||||
import com.daml.jwt.domain.{DecodedJwt, Jwt}
|
||||
import com.daml.ledger.api.auth.{AuthServiceJWTCodec, AuthServiceJWTPayload, CustomDamlJWTPayload}
|
||||
import com.daml.ledger.api.domain.LedgerId
|
||||
import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
|
||||
import com.daml.ledger.api.refinements.{ApiTypes => lar}
|
||||
import com.daml.ledger.api.tls.TlsConfiguration
|
||||
import com.daml.ledger.api.v1.{value => v}
|
||||
@ -37,6 +36,7 @@ import com.daml.ledger.client.configuration.{
|
||||
}
|
||||
import com.daml.ledger.client.withoutledgerid.{LedgerClient => DamlLedgerClient}
|
||||
import com.daml.ledger.resources.ResourceContext
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.logging.LoggingContextOf
|
||||
import com.daml.platform.services.time.TimeProviderType
|
||||
import com.daml.ports.Port
|
||||
@ -105,7 +105,7 @@ object HttpServiceTestFixture extends LazyLogging with Assertions with Inside {
|
||||
implicit val lc: LoggingContextOf[InstanceUUID] = instanceUUIDLogCtx()
|
||||
implicit val metrics: HttpJsonApiMetrics = HttpJsonApiMetrics.ForTesting
|
||||
val ledgerId = ledgerIdOverwrite.getOrElse(LedgerId("participant0"))
|
||||
val applicationId = ApplicationId(testName)
|
||||
val applicationId = lar.ApplicationId(testName)
|
||||
|
||||
val contractDaoF: Future[Option[ContractDao]] = jdbcConfig.map(c => initializeDb(c)).sequence
|
||||
|
||||
@ -190,7 +190,11 @@ object HttpServiceTestFixture extends LazyLogging with Assertions with Inside {
|
||||
val portsF = portsResource.asFuture
|
||||
|
||||
val clientF = portsF.map(ports =>
|
||||
config.ledgerClientWithoutId(ports.head.ledgerPort, None, ApplicationId("http-service-test"))
|
||||
config.ledgerClientWithoutId(
|
||||
ports.head.ledgerPort,
|
||||
None,
|
||||
Some(Ref.ApplicationId.assertFromString("http-service-test")),
|
||||
)
|
||||
)
|
||||
|
||||
val fa: Future[A] = for {
|
||||
@ -208,11 +212,11 @@ object HttpServiceTestFixture extends LazyLogging with Assertions with Inside {
|
||||
}
|
||||
|
||||
private def clientConfig(
|
||||
applicationId: ApplicationId,
|
||||
applicationId: lar.ApplicationId,
|
||||
token: Option[String],
|
||||
): LedgerClientConfiguration =
|
||||
LedgerClientConfiguration(
|
||||
applicationId = ApplicationId.unwrap(applicationId),
|
||||
applicationId = lar.ApplicationId.unwrap(applicationId),
|
||||
ledgerIdRequirement = LedgerIdRequirement.none,
|
||||
commandClient = CommandClientConfiguration.default,
|
||||
token = token,
|
||||
|
@ -93,7 +93,7 @@ final class CommandClientIT
|
||||
|
||||
private def commandClientWithoutTime(
|
||||
ledgerId: domain.LedgerId,
|
||||
appId: String = applicationId.unwrap,
|
||||
appId: String = applicationId.getOrElse(""),
|
||||
configuration: CommandClientConfiguration = defaultCommandClientConfiguration,
|
||||
): CommandClient =
|
||||
new CommandClient(
|
||||
@ -114,7 +114,7 @@ final class CommandClientIT
|
||||
|
||||
private def commandClient(
|
||||
ledgerId: domain.LedgerId = testLedgerId,
|
||||
appId: String = applicationId.unwrap,
|
||||
appId: String = applicationId.getOrElse(""),
|
||||
configuration: CommandClientConfiguration = defaultCommandClientConfiguration,
|
||||
): Future[CommandClient] =
|
||||
timeProvider(ledgerId)
|
||||
@ -133,7 +133,7 @@ final class CommandClientIT
|
||||
ledgerId = testLedgerId,
|
||||
commandId = commandId,
|
||||
commands = individualCommands,
|
||||
applicationId = applicationId.unwrap,
|
||||
applicationId = applicationId.getOrElse(""),
|
||||
party = party,
|
||||
)
|
||||
|
||||
|
@ -17,7 +17,6 @@ import org.scalatest.Inside
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AsyncWordSpec
|
||||
import scalaz.OneAnd
|
||||
import scalaz.syntax.tag._
|
||||
|
||||
final class LedgerClientIT extends AsyncWordSpec with Matchers with Inside with CantonFixture {
|
||||
|
||||
@ -26,7 +25,7 @@ final class LedgerClientIT extends AsyncWordSpec with Matchers with Inside with
|
||||
lazy val channel = config.channel(ports.head)
|
||||
|
||||
private val ClientConfiguration = LedgerClientConfiguration(
|
||||
applicationId = applicationId.unwrap,
|
||||
applicationId = applicationId.getOrElse(""),
|
||||
ledgerIdRequirement = LedgerIdRequirement.none,
|
||||
commandClient = CommandClientConfiguration.default,
|
||||
token = None,
|
||||
|
@ -100,13 +100,6 @@ da_scala_dar_resources_library(
|
||||
[
|
||||
[
|
||||
[
|
||||
dar_to_scala(
|
||||
name = "%s-tests-%s.scala-codegen" % (test_name, target),
|
||||
srcs = [":%s-tests-%s.dar" % (test_name, target)],
|
||||
package_prefix = "com.daml.ledger.test.%s" % test_name,
|
||||
srcjar_out = "%s-%s.scala.srcjar" % (test_name, target),
|
||||
visibility = ["//visibility:public"],
|
||||
),
|
||||
dar_to_java(
|
||||
name = "%s-tests-%s.java-codegen" % (test_name, target),
|
||||
src = ":%s-tests-%s.dar" % (test_name, target),
|
||||
|
@ -15,8 +15,9 @@ da_scala_library(
|
||||
"//test-common/test-certificates",
|
||||
],
|
||||
scala_deps = [
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:org_scalactic_scalactic",
|
||||
"@maven//:org_scalatest_scalatest_core",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
@ -25,12 +26,13 @@ da_scala_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//bazel_tools/runfiles:scala_runfiles",
|
||||
"//canton:ledger_api_proto_scala",
|
||||
"//daml-lf/archive:daml_lf_archive_reader",
|
||||
"//daml-lf/data",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger/ledger-api-auth",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//ledger/ledger-api-domain",
|
||||
"//libs-scala/fs-utils",
|
||||
"//libs-scala/jwt",
|
||||
"//libs-scala/ledger-resources",
|
||||
@ -41,6 +43,11 @@ da_scala_library(
|
||||
"//libs-scala/scala-utils",
|
||||
"//libs-scala/testing-utils",
|
||||
"//libs-scala/timer-utils",
|
||||
"@maven//:ch_qos_logback_logback_classic",
|
||||
"@maven//:ch_qos_logback_logback_core",
|
||||
"@maven//:io_grpc_grpc_api",
|
||||
"@maven//:io_grpc_grpc_netty",
|
||||
"@maven//:io_netty_netty_handler",
|
||||
"@maven//:org_scalatest_scalatest_compatible",
|
||||
],
|
||||
)
|
||||
|
@ -6,7 +6,6 @@ package integrationtest
|
||||
|
||||
import com.daml.bazeltools.BazelRunfiles.rlocation
|
||||
import com.daml.grpc.adapter.ExecutionSequencerFactory
|
||||
import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
|
||||
import com.daml.ledger.api.tls.TlsConfiguration
|
||||
import com.daml.ledger.client.{LedgerClient, GrpcChannel}
|
||||
import com.daml.ledger.client.withoutledgerid.{LedgerClient => LedgerClientWithoutId}
|
||||
@ -16,7 +15,6 @@ import com.daml.platform.services.time.TimeProviderType
|
||||
import com.daml.ports.Port
|
||||
import io.grpc.ManagedChannel
|
||||
import io.grpc.netty.NettyChannelBuilder
|
||||
import scalaz.syntax.tag._
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import java.nio.file.{Path, Paths}
|
||||
@ -117,14 +115,14 @@ final case class CantonConfig(
|
||||
def ledgerClient(
|
||||
port: Port,
|
||||
token: Option[String],
|
||||
applicationId: ApplicationId,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
maxInboundMessageSize: Int = 64 * 1024 * 1024,
|
||||
)(implicit ec: ExecutionContext, esf: ExecutionSequencerFactory): Future[LedgerClient] = {
|
||||
import com.daml.ledger.client.configuration._
|
||||
LedgerClient(
|
||||
channel = channel(port, maxInboundMessageSize),
|
||||
config = LedgerClientConfiguration(
|
||||
applicationId = token.fold(applicationId.unwrap)(_ => ""),
|
||||
applicationId = token.fold(applicationId.getOrElse(""))(_ => ""),
|
||||
ledgerIdRequirement = LedgerIdRequirement.none,
|
||||
commandClient = CommandClientConfiguration.default,
|
||||
token = token,
|
||||
@ -136,14 +134,14 @@ final case class CantonConfig(
|
||||
def ledgerClientWithoutId(
|
||||
port: Port,
|
||||
token: Option[String],
|
||||
applicationId: ApplicationId,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
maxInboundMessageSize: Int = 64 * 1024 * 1024,
|
||||
)(implicit ec: ExecutionContext, esf: ExecutionSequencerFactory): LedgerClientWithoutId = {
|
||||
import com.daml.ledger.client.configuration._
|
||||
LedgerClientWithoutId(
|
||||
channel = channel(port, maxInboundMessageSize),
|
||||
config = LedgerClientConfiguration(
|
||||
applicationId = token.fold(applicationId.unwrap)(_ => ""),
|
||||
applicationId = token.orElse(applicationId).getOrElse(""),
|
||||
ledgerIdRequirement = LedgerIdRequirement.none,
|
||||
commandClient = CommandClientConfiguration.default,
|
||||
token = token,
|
||||
|
@ -5,7 +5,6 @@ package com.daml
|
||||
package integrationtest
|
||||
|
||||
import com.daml.bazeltools.BazelRunfiles._
|
||||
import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
|
||||
import com.daml.ledger.api.testing.utils.{
|
||||
PekkoBeforeAndAfterAll,
|
||||
OwnedResource,
|
||||
@ -60,7 +59,8 @@ trait CantonFixtureWithResource[A]
|
||||
protected lazy val tlsEnable: Boolean = false
|
||||
protected lazy val enableContractUpgrading: Boolean = false
|
||||
protected lazy val bootstrapScript: Option[String] = Option.empty
|
||||
protected lazy val applicationId: ApplicationId = ApplicationId(getClass.getName)
|
||||
protected lazy val applicationId: Option[Ref.ApplicationId] =
|
||||
Some(Ref.ApplicationId.assertFromString(getClass.getName))
|
||||
protected lazy val cantonJar: Path = CantonRunner.cantonPath
|
||||
protected lazy val targetScope: Option[String] = Option.empty
|
||||
|
||||
|
@ -13,6 +13,7 @@ da_scala_library(
|
||||
srcs = glob(["src/main/scala/**/*.scala"]),
|
||||
scala_deps = [
|
||||
"@maven//:com_github_scopt_scopt",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_typelevel_paiges_core",
|
||||
@ -21,6 +22,7 @@ da_scala_library(
|
||||
tags = ["maven_coordinates=com.daml:trigger-runner:__VERSION__"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//canton:ledger_api_proto_scala",
|
||||
"//daml-lf/archive:daml_lf_archive_reader",
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/engine",
|
||||
@ -28,16 +30,21 @@ da_scala_library(
|
||||
"//daml-lf/language",
|
||||
"//daml-lf/transaction",
|
||||
"//daml-script/converter",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger-service/cli-opts",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//ledger/ledger-api-domain",
|
||||
"//libs-scala/auth-utils",
|
||||
"//libs-scala/contextualized-logging",
|
||||
"//libs-scala/logging-entries",
|
||||
"//libs-scala/rs-grpc-bridge",
|
||||
"//libs-scala/rs-grpc-pekko",
|
||||
"//libs-scala/scala-utils",
|
||||
"//observability/tracing",
|
||||
"@maven//:ch_qos_logback_logback_classic",
|
||||
"@maven//:io_grpc_grpc_api",
|
||||
"@maven//:io_netty_netty_handler",
|
||||
"@maven//:org_slf4j_slf4j_api",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -8,9 +8,8 @@ package trigger
|
||||
import scalaz.std.either._
|
||||
import scalaz.std.list._
|
||||
import scalaz.std.option._
|
||||
import scalaz.syntax.tag._
|
||||
import scalaz.syntax.traverse._
|
||||
import com.daml.lf.data.{BackStack, FrontStack, ImmArray, Ref}
|
||||
import com.daml.lf.data.{BackStack, FrontStack, ImmArray}
|
||||
import com.daml.lf.data.Ref._
|
||||
import com.daml.lf.language.Ast._
|
||||
import com.daml.lf.speedy.{ArrayList, SValue}
|
||||
@ -314,10 +313,8 @@ final class Converter(
|
||||
): Either[String, SValue] =
|
||||
for {
|
||||
acs <- fromActiveContracts(createdEvents)
|
||||
actAs = SParty(Ref.Party.assertFromString(parties.actAs.unwrap))
|
||||
readAs = SList(
|
||||
parties.readAs.map(p => SParty(Ref.Party.assertFromString(p.unwrap))).to(FrontStack)
|
||||
)
|
||||
actAs = SParty(parties.actAs)
|
||||
readAs = SList(parties.readAs.view.map(SParty).to(FrontStack))
|
||||
config = fromTriggerConfig(triggerConfig)
|
||||
} yield record(
|
||||
triggerSetupArgumentsTy,
|
||||
@ -416,10 +413,8 @@ final class Converter(
|
||||
triggerConfig: TriggerRunnerConfig,
|
||||
): SValue = {
|
||||
val acs = fromACS(createdEvents)
|
||||
val actAs = SParty(Ref.Party.assertFromString(parties.actAs.unwrap))
|
||||
val readAs = SList(
|
||||
parties.readAs.map(p => SParty(Ref.Party.assertFromString(p.unwrap))).to(FrontStack)
|
||||
)
|
||||
val actAs = SParty(parties.actAs)
|
||||
val readAs = SList(parties.readAs.map(SParty).to(FrontStack))
|
||||
val config = fromTriggerConfig(triggerConfig)
|
||||
|
||||
record(
|
||||
|
@ -8,8 +8,6 @@ import org.apache.pekko.actor.Cancellable
|
||||
import org.apache.pekko.event.Logging
|
||||
import org.apache.pekko.stream._
|
||||
import org.apache.pekko.stream.scaladsl._
|
||||
import com.daml.api.util.TimeProvider
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId, Party}
|
||||
import com.daml.ledger.api.v1.command_submission_service.SubmitRequest
|
||||
import com.daml.ledger.api.v1.commands._
|
||||
import com.daml.ledger.api.v1.completion.Completion
|
||||
@ -75,9 +73,9 @@ import io.grpc.StatusRuntimeException
|
||||
import scalaz.syntax.bifunctor._
|
||||
import scalaz.syntax.std.option._
|
||||
import scalaz.syntax.tag._
|
||||
import scalaz.{-\/, Tag, \/, \/-}
|
||||
import scalaz.{-\/, \/, \/-}
|
||||
|
||||
import java.time.Instant
|
||||
import java.time.{Clock, Instant}
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
import scala.annotation.{nowarn, tailrec}
|
||||
@ -123,13 +121,11 @@ private[lf] final case class Trigger(
|
||||
Array(converter.fromTriggerSetupArguments(parties, acs, triggerConfig).orConverterException)
|
||||
} else {
|
||||
val createdValue: SValue = converter.fromActiveContracts(acs).orConverterException
|
||||
val partyArg = SParty(Ref.Party.assertFromString(parties.actAs.unwrap))
|
||||
val partyArg = SParty(parties.actAs)
|
||||
|
||||
if (hasReadAs) {
|
||||
// trigger version SDK 1.18 and newer
|
||||
val readAsArg = SList(
|
||||
parties.readAs.map(p => SParty(Ref.Party.assertFromString(p.unwrap))).to(FrontStack)
|
||||
)
|
||||
val readAsArg = SList(parties.readAs.map(SParty).to(FrontStack))
|
||||
Array(partyArg, readAsArg, createdValue)
|
||||
} else {
|
||||
// trigger version prior to SDK 1.18
|
||||
@ -186,21 +182,21 @@ object Trigger {
|
||||
|
||||
private[trigger] def newTriggerLogContext[P, T](
|
||||
triggerDefinition: Identifier,
|
||||
actAs: Party,
|
||||
readAs: Set[Party],
|
||||
actAs: Ref.Party,
|
||||
readAs: Set[Ref.Party],
|
||||
triggerId: String,
|
||||
applicationId: ApplicationId,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
)(f: TriggerLogContext => T): T = {
|
||||
LoggingContextOf.newLoggingContext(
|
||||
LoggingContextOf.label[Trigger with P],
|
||||
"applicationId" -> applicationId.unwrap,
|
||||
"applicationId" -> applicationId.getOrElse[String](""),
|
||||
) { implicit loggingContext: LoggingContextOf[Trigger] =>
|
||||
TriggerLogContext.newRootSpan(
|
||||
"setup",
|
||||
"id" -> triggerId,
|
||||
"definition" -> triggerDefinition,
|
||||
"actAs" -> Tag.unwrap(actAs),
|
||||
"readAs" -> Tag.unsubst(readAs),
|
||||
"actAs" -> actAs,
|
||||
"readAs" -> readAs,
|
||||
) { implicit triggerContext: TriggerLogContext =>
|
||||
f(triggerContext)
|
||||
}
|
||||
@ -487,7 +483,7 @@ private[lf] class Runner private (
|
||||
triggerConfig: TriggerRunnerConfig,
|
||||
client: LedgerClient,
|
||||
timeProviderType: TimeProviderType,
|
||||
applicationId: ApplicationId,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
parties: TriggerParties,
|
||||
)(implicit triggerContext: TriggerLogContext) {
|
||||
|
||||
@ -554,7 +550,7 @@ private[lf] class Runner private (
|
||||
private[this] val inFlightCommands = new InFlightCommands
|
||||
|
||||
private val transactionFilter =
|
||||
TransactionFilter(parties.readers.map(p => (p.unwrap, trigger.filters)).toMap)
|
||||
TransactionFilter(parties.readers.map(p => (p, trigger.filters)).toMap)
|
||||
|
||||
// return whether uuid *was* present in pendingCommandIds
|
||||
private[this] def useCommandId(uuid: UUID, seeOne: SeenMsgs.One)(implicit
|
||||
@ -595,10 +591,10 @@ private[lf] class Runner private (
|
||||
|
||||
val commandsArg = Commands(
|
||||
ledgerId = client.ledgerId.unwrap,
|
||||
applicationId = applicationId.unwrap,
|
||||
applicationId = applicationId.getOrElse(""),
|
||||
commandId = commandUUID.toString,
|
||||
party = parties.actAs.unwrap,
|
||||
readAs = Party.unsubst(parties.readAs).toList,
|
||||
party = parties.actAs,
|
||||
readAs = parties.readAs.toList,
|
||||
commands = commands,
|
||||
)
|
||||
|
||||
@ -865,7 +861,7 @@ private[lf] class Runner private (
|
||||
triggerContext.logInfo("Subscribing to ledger API completion source")
|
||||
client.commandClient
|
||||
// Completions only take actAs into account so no need to include readAs.
|
||||
.completionSource(List(parties.actAs.unwrap), offset)
|
||||
.completionSource(List(parties.actAs), offset)
|
||||
.collect { case CompletionElement(completion, _) =>
|
||||
triggerContext.childSpan("update") { implicit triggerContext: TriggerLogContext =>
|
||||
triggerContext.logDebug("Completion source", "message" -> completion)
|
||||
@ -1136,7 +1132,7 @@ private[lf] class Runner private (
|
||||
}
|
||||
|
||||
val clientTime: Timestamp =
|
||||
Timestamp.assertFromInstant(Runner.getTimeProvider(timeProviderType).getCurrentTime)
|
||||
Timestamp.assertFromInstant(Runner.getCurrentTime(timeProviderType))
|
||||
val stateFun = Machine
|
||||
.stepToValue(compiledPackages, makeAppD(updateStateLambda, messageVal.value))
|
||||
.expect(
|
||||
@ -1225,7 +1221,7 @@ private[lf] class Runner private (
|
||||
triggerContext.logInfo("Trigger starting")
|
||||
|
||||
val clientTime: Timestamp =
|
||||
Timestamp.assertFromInstant(Runner.getTimeProvider(timeProviderType).getCurrentTime)
|
||||
Timestamp.assertFromInstant(Runner.getCurrentTime(timeProviderType))
|
||||
val hardLimitKillSwitch = KillSwitches.shared("hard-limit")
|
||||
|
||||
import UnfoldState.{flatMapConcatNodeOps, toSourceOps}
|
||||
@ -1445,7 +1441,7 @@ object Runner {
|
||||
triggerConfig: TriggerRunnerConfig,
|
||||
client: LedgerClient,
|
||||
timeProviderType: TimeProviderType,
|
||||
applicationId: ApplicationId,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
parties: TriggerParties,
|
||||
)(implicit triggerContext: TriggerLogContext): Runner = {
|
||||
triggerContext.enrichTriggerContext(
|
||||
@ -1778,11 +1774,10 @@ object Runner {
|
||||
private def overloadedRetryDelay(afterTries: Int): FiniteDuration =
|
||||
(250 * (1 << (afterTries - 1))).milliseconds
|
||||
|
||||
// Return the time provider for a given time provider type.
|
||||
def getTimeProvider(ty: TimeProviderType): TimeProvider = {
|
||||
def getCurrentTime(ty: TimeProviderType): Instant = {
|
||||
ty match {
|
||||
case TimeProviderType.Static => TimeProvider.Constant(Instant.EPOCH)
|
||||
case TimeProviderType.WallClock => TimeProvider.UTC
|
||||
case TimeProviderType.Static => Instant.EPOCH
|
||||
case TimeProviderType.WallClock => Clock.systemUTC().instant()
|
||||
case _ => throw new RuntimeException(s"Unexpected TimeProviderType: $ty")
|
||||
}
|
||||
}
|
||||
@ -1880,7 +1875,7 @@ object Runner {
|
||||
triggerId: Identifier,
|
||||
client: LedgerClient,
|
||||
timeProviderType: TimeProviderType,
|
||||
applicationId: ApplicationId,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
parties: TriggerParties,
|
||||
config: Compiler.Config,
|
||||
triggerConfig: TriggerRunnerConfig,
|
||||
|
@ -9,7 +9,6 @@ import java.nio.file.{Path, Paths}
|
||||
import java.time.Duration
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.ledger.api.domain
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId, Party}
|
||||
import com.daml.ledger.api.tls.TlsConfiguration
|
||||
import com.daml.ledger.api.tls.TlsConfigurationCli
|
||||
import com.daml.ledger.client.LedgerClient
|
||||
@ -53,7 +52,7 @@ case class RunnerConfig(
|
||||
timeProviderType: Option[TimeProviderType],
|
||||
commandTtl: Duration,
|
||||
accessTokenFile: Option[Path],
|
||||
applicationId: ApplicationId,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
tlsConfig: TlsConfiguration,
|
||||
compilerConfigBuilder: CompilerConfigBuilder,
|
||||
majorLanguageVersion: LanguageMajorVersion,
|
||||
@ -63,7 +62,7 @@ case class RunnerConfig(
|
||||
) {
|
||||
private def updatePartySpec(f: TriggerParties => TriggerParties): RunnerConfig =
|
||||
if (ledgerClaims == null) {
|
||||
copy(ledgerClaims = PartySpecification(f(TriggerParties(Party(""), Set.empty))))
|
||||
copy(ledgerClaims = PartySpecification(f(TriggerParties.Empty)))
|
||||
} else
|
||||
ledgerClaims match {
|
||||
case PartySpecification(claims) =>
|
||||
@ -73,10 +72,10 @@ case class RunnerConfig(
|
||||
s"Must specify either --ledger-party and --ledger-readas or --ledger-userid but not both"
|
||||
)
|
||||
}
|
||||
private def updateActAs(party: Party): RunnerConfig =
|
||||
updatePartySpec(spec => spec.copy(actAs = party))
|
||||
private def updateActAs(party: Ref.Party): RunnerConfig =
|
||||
updatePartySpec(spec => spec.copy(actAsOpt = Some(party)))
|
||||
|
||||
private def updateReadAs(parties: Seq[Party]): RunnerConfig =
|
||||
private def updateReadAs(parties: Seq[Ref.Party]): RunnerConfig =
|
||||
updatePartySpec(spec => spec.copy(readAs = spec.readAs ++ parties))
|
||||
|
||||
private def updateUser(userId: Ref.UserId): RunnerConfig =
|
||||
@ -133,14 +132,22 @@ final case class UserSpecification(userId: Ref.UserId) extends ClaimsSpecificati
|
||||
)
|
||||
}
|
||||
readers = (readAs ++ actAs) - primaryParty
|
||||
} yield TriggerParties(Party(primaryParty), readers.map(Party(_)))
|
||||
} yield TriggerParties(primaryParty, readers)
|
||||
}
|
||||
|
||||
final case class TriggerParties(
|
||||
actAs: Party,
|
||||
readAs: Set[Party],
|
||||
actAsOpt: Option[Ref.Party],
|
||||
readAs: Set[Ref.Party],
|
||||
) {
|
||||
lazy val readers: Set[Party] = readAs + actAs
|
||||
lazy val actAs = actAsOpt.get
|
||||
lazy val readers: Set[Ref.Party] = readAs + actAs
|
||||
}
|
||||
|
||||
object TriggerParties {
|
||||
def apply(actAs: Ref.Party, readAs: Set[Ref.Party]): TriggerParties =
|
||||
new TriggerParties(Some(actAs), readAs)
|
||||
|
||||
def Empty = new TriggerParties(None, Set.empty)
|
||||
}
|
||||
|
||||
object RunnerConfig {
|
||||
@ -151,8 +158,8 @@ object RunnerConfig {
|
||||
|
||||
private[trigger] val DefaultMaxInboundMessageSize: Int = 4194304
|
||||
private[trigger] val DefaultTimeProviderType: TimeProviderType = TimeProviderType.WallClock
|
||||
private[trigger] val DefaultApplicationId: ApplicationId =
|
||||
ApplicationId("daml-trigger")
|
||||
private[trigger] val DefaultApplicationId: Some[Ref.ApplicationId] =
|
||||
Some(Ref.ApplicationId.assertFromString("daml-trigger"))
|
||||
private[trigger] val DefaultCompilerConfigBuilder: CompilerConfigBuilder =
|
||||
CompilerConfigBuilder.Default
|
||||
private[trigger] val DefaultMajorLanguageVersion: LanguageMajorVersion = LanguageMajorVersion.V1
|
||||
@ -179,12 +186,12 @@ object RunnerConfig {
|
||||
.text("Ledger port")
|
||||
|
||||
opt[String]("ledger-party")
|
||||
.action((t, c) => c.updateActAs(Party(t)))
|
||||
.action((t, c) => c.updateActAs(Ref.Party.assertFromString(t)))
|
||||
.text("""The party the trigger can act as.
|
||||
|Mutually exclusive with --ledger-user.""".stripMargin)
|
||||
|
||||
opt[Seq[String]]("ledger-readas")
|
||||
.action((t, c) => c.updateReadAs(t.map(Party(_))))
|
||||
.action((t, c) => c.updateReadAs(t.map(Ref.Party.assertFromString)))
|
||||
.unbounded()
|
||||
.text(
|
||||
"""A comma-separated list of parties the trigger can read as.
|
||||
@ -240,7 +247,9 @@ object RunnerConfig {
|
||||
|
||||
opt[String]("application-id")
|
||||
.action { (appId, c) =>
|
||||
c.copy(applicationId = ApplicationId(appId))
|
||||
c.copy(applicationId =
|
||||
Some(appId).filterNot(_.isEmpty).map(Ref.ApplicationId.assertFromString)
|
||||
)
|
||||
}
|
||||
.text(s"Application ID used to submit commands. Defaults to ${DefaultApplicationId}")
|
||||
|
||||
@ -333,7 +342,7 @@ object RunnerConfig {
|
||||
failure("Missing option --ledger-party or --ledger-user")
|
||||
} else {
|
||||
c.ledgerClaims match {
|
||||
case PartySpecification(TriggerParties(actAs, _)) if actAs == Party("") =>
|
||||
case PartySpecification(TriggerParties(actAs, _)) if actAs.isEmpty =>
|
||||
failure("Missing option --ledger-party")
|
||||
case _ => success
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import org.apache.pekko.stream._
|
||||
import ch.qos.logback.classic.Level
|
||||
import com.daml.auth.TokenHolder
|
||||
import com.daml.grpc.adapter.PekkoExecutionSequencerPool
|
||||
import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
|
||||
import com.daml.ledger.client.LedgerClient
|
||||
import com.daml.ledger.client.configuration.{
|
||||
CommandClientConfiguration,
|
||||
@ -89,7 +88,7 @@ object RunnerMain {
|
||||
// to an expired token tear the trigger down and have some external monitoring process (e.g. systemd)
|
||||
// restart it.
|
||||
val clientConfig = LedgerClientConfiguration(
|
||||
applicationId = ApplicationId.unwrap(config.applicationId),
|
||||
applicationId = config.applicationId.getOrElse(""),
|
||||
ledgerIdRequirement = LedgerIdRequirement.none,
|
||||
commandClient =
|
||||
CommandClientConfiguration.default.copy(defaultDeduplicationTime = config.commandTtl),
|
||||
|
@ -35,15 +35,18 @@ da_scala_library(
|
||||
resources = glob(["src/main/resources/**/*"]),
|
||||
scala_deps = [
|
||||
"@maven//:com_chuusai_shapeless",
|
||||
"@maven//:com_github_pureconfig_pureconfig_core",
|
||||
"@maven//:com_github_pureconfig_pureconfig_generic",
|
||||
"@maven//:com_github_scopt_scopt",
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_actor_typed",
|
||||
"@maven//:org_apache_pekko_pekko_http",
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_apache_pekko_pekko_http_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_parboiled_parboiled",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_tpolecat_doobie_core",
|
||||
"@maven//:org_tpolecat_doobie_free",
|
||||
@ -52,9 +55,6 @@ da_scala_library(
|
||||
"@maven//:org_typelevel_cats_effect",
|
||||
"@maven//:org_typelevel_cats_free",
|
||||
"@maven//:org_typelevel_cats_kernel",
|
||||
"@maven//:com_github_pureconfig_pureconfig_core",
|
||||
"@maven//:com_github_pureconfig_pureconfig_generic",
|
||||
"@maven//:org_parboiled_parboiled",
|
||||
],
|
||||
scala_runtime_deps = [
|
||||
"@maven//:org_apache_pekko_pekko_slf4j",
|
||||
@ -70,13 +70,13 @@ da_scala_library(
|
||||
"@maven//:org_postgresql_postgresql",
|
||||
],
|
||||
deps = [
|
||||
"//canton:ledger_api_proto_scala",
|
||||
"//daml-lf/archive:daml_lf_archive_reader",
|
||||
"//daml-lf/archive:daml_lf_dev_archive_proto_java",
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/engine",
|
||||
"//daml-lf/interpreter",
|
||||
"//daml-lf/language",
|
||||
"//language-support/scala/bindings",
|
||||
"//ledger-service/cli-opts",
|
||||
"//ledger-service/metrics",
|
||||
"//ledger-service/pureconfig-utils",
|
||||
@ -114,12 +114,10 @@ scala_binary_deps = [
|
||||
]
|
||||
|
||||
binary_deps = [
|
||||
":trigger-service",
|
||||
"//daml-lf/archive:daml_lf_dev_archive_proto_java",
|
||||
"//daml-lf/archive:daml_lf_archive_reader",
|
||||
"//daml-lf/archive:daml_lf_dev_archive_proto_java",
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/interpreter",
|
||||
"//language-support/scala/bindings",
|
||||
"//ledger/ledger-api-common",
|
||||
"//libs-scala/contextualized-logging",
|
||||
"//libs-scala/db-utils",
|
||||
@ -128,8 +126,10 @@ binary_deps = [
|
||||
"//observability/metrics",
|
||||
"//triggers/runner:trigger-runner-lib",
|
||||
"//triggers/service/auth:middleware-api",
|
||||
"@maven//:org_slf4j_slf4j_api",
|
||||
":trigger-service",
|
||||
"@maven//:ch_qos_logback_logback_classic",
|
||||
"@maven//:com_google_protobuf_protobuf_java",
|
||||
"@maven//:org_slf4j_slf4j_api",
|
||||
]
|
||||
|
||||
trigger_service_runtime_deps = {
|
||||
@ -178,30 +178,35 @@ da_scala_library(
|
||||
resources = glob(["src/test/resources/**/*"]),
|
||||
scala_deps = [
|
||||
"@maven//:com_lihaoyi_sourcecode",
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_actor_typed",
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:org_parboiled_parboiled",
|
||||
"@maven//:org_scalactic_scalactic",
|
||||
"@maven//:org_scalatest_scalatest_core",
|
||||
"@maven//:org_scalatest_scalatest_flatspec",
|
||||
"@maven//:org_scalatest_scalatest_matchers_core",
|
||||
"@maven//:org_scalatest_scalatest_shouldmatchers",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_apache_pekko_pekko_actor_typed",
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_parboiled_parboiled",
|
||||
],
|
||||
visibility = ["//test-evidence:__pkg__"],
|
||||
deps = [
|
||||
":trigger-service",
|
||||
":trigger-service-binary-ce",
|
||||
"//bazel_tools/runfiles:scala_runfiles",
|
||||
"//canton:ledger_api_proto_scala",
|
||||
"//daml-lf/archive:daml_lf_archive_reader",
|
||||
"//daml-lf/archive:daml_lf_dev_archive_proto_java",
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/interpreter",
|
||||
"//daml-lf/language",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger/ledger-api-auth",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//ledger/ledger-api-domain",
|
||||
"//libs-scala/adjustable-clock",
|
||||
"//libs-scala/db-utils",
|
||||
"//libs-scala/jwt",
|
||||
@ -223,9 +228,13 @@ da_scala_library(
|
||||
"//triggers/service/auth:middleware-api",
|
||||
"//triggers/service/auth:oauth2-middleware",
|
||||
"//triggers/service/auth:oauth2-test-server",
|
||||
"@maven//:ch_qos_logback_logback_classic",
|
||||
"@maven//:ch_qos_logback_logback_core",
|
||||
"@maven//:com_auth0_java_jwt",
|
||||
"@maven//:com_google_protobuf_protobuf_java",
|
||||
"@maven//:eu_rekawek_toxiproxy_toxiproxy_java_2_1_7",
|
||||
"@maven//:org_scalatest_scalatest_compatible",
|
||||
"@maven//:org_slf4j_slf4j_api",
|
||||
],
|
||||
)
|
||||
|
||||
@ -241,32 +250,35 @@ da_scala_test_suite(
|
||||
":src/test-suite/resources/trigger-service-minimal.conf",
|
||||
],
|
||||
scala_deps = [
|
||||
"@maven//:com_github_pureconfig_pureconfig_core",
|
||||
"@maven//:com_github_scopt_scopt",
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:org_parboiled_parboiled",
|
||||
"@maven//:org_scalactic_scalactic",
|
||||
"@maven//:org_scalatest_scalatest_core",
|
||||
"@maven//:org_scalatest_scalatest_flatspec",
|
||||
"@maven//:org_scalatest_scalatest_matchers_core",
|
||||
"@maven//:org_scalatest_scalatest_shouldmatchers",
|
||||
"@maven//:org_scalatest_scalatest_wordspec",
|
||||
"@maven//:org_scalatest_scalatest_flatspec",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_scalactic_scalactic",
|
||||
"@maven//:com_github_scopt_scopt",
|
||||
"@maven//:org_parboiled_parboiled",
|
||||
],
|
||||
visibility = ["//test-evidence:__pkg__"],
|
||||
deps = [
|
||||
":trigger-service",
|
||||
":trigger-service-tests",
|
||||
"//bazel_tools/runfiles:scala_runfiles",
|
||||
"//canton:ledger_api_proto_scala",
|
||||
"//daml-lf/archive:daml_lf_archive_reader",
|
||||
"//daml-lf/archive:daml_lf_dev_archive_proto_java",
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/interpreter",
|
||||
"//daml-lf/language",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger-service/cli-opts",
|
||||
"//ledger-service/pureconfig-utils",
|
||||
"//ledger/ledger-api-auth",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//libs-scala/adjustable-clock",
|
||||
"//libs-scala/db-utils",
|
||||
@ -284,6 +296,8 @@ da_scala_test_suite(
|
||||
"//triggers/runner:trigger-runner-lib",
|
||||
"//triggers/service/auth:middleware-api",
|
||||
"//triggers/service/auth:oauth2-test-server",
|
||||
"@maven//:ch_qos_logback_logback_classic",
|
||||
"@maven//:ch_qos_logback_logback_core",
|
||||
"@maven//:eu_rekawek_toxiproxy_toxiproxy_java_2_1_7",
|
||||
"@maven//:org_flywaydb_flyway_core",
|
||||
"@maven//:org_scalatest_scalatest_compatible",
|
||||
@ -296,12 +310,12 @@ da_scala_test_suite(
|
||||
srcs = glob(["src/test-suite/scala/**/*Oracle*.scala"]),
|
||||
scala_deps = [
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:org_scalatest_scalatest_core",
|
||||
"@maven//:org_scalatest_scalatest_matchers_core",
|
||||
"@maven//:org_scalatest_scalatest_shouldmatchers",
|
||||
"@maven//:org_scalatest_scalatest_wordspec",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
],
|
||||
tags = oracle_tags,
|
||||
runtime_deps = [
|
||||
@ -310,12 +324,13 @@ da_scala_test_suite(
|
||||
deps = [
|
||||
":trigger-service",
|
||||
":trigger-service-tests",
|
||||
"//canton:ledger_api_proto_scala",
|
||||
"//daml-lf/archive:daml_lf_archive_reader",
|
||||
"//daml-lf/archive:daml_lf_dev_archive_proto_java",
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/language",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger/ledger-api-auth",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//libs-scala/adjustable-clock",
|
||||
"//libs-scala/db-utils",
|
||||
@ -330,6 +345,8 @@ da_scala_test_suite(
|
||||
"//test-common/canton/it-lib",
|
||||
"//triggers/runner:trigger-runner-lib",
|
||||
"//triggers/service/auth:oauth2-test-server",
|
||||
"@maven//:ch_qos_logback_logback_classic",
|
||||
"@maven//:ch_qos_logback_logback_core",
|
||||
"@maven//:eu_rekawek_toxiproxy_toxiproxy_java_2_1_7",
|
||||
"@maven//:org_scalatest_scalatest_compatible",
|
||||
],
|
||||
|
@ -59,11 +59,11 @@ da_scala_library(
|
||||
name = "oauth2-api",
|
||||
srcs = glob(["src/main/scala/com/daml/auth/oauth2/api/**/*.scala"]),
|
||||
scala_deps = [
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_http",
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_parboiled_parboiled",
|
||||
],
|
||||
scalacopts = lf_scalacopts_stricter,
|
||||
@ -74,20 +74,19 @@ da_scala_library(
|
||||
name = "middleware-api",
|
||||
srcs = glob(["src/main/scala/com/daml/auth/middleware/api/**/*.scala"]),
|
||||
scala_deps = [
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_http",
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_apache_pekko_pekko_http_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_parboiled_parboiled",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
],
|
||||
scalacopts = lf_scalacopts_stricter,
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//daml-lf/data",
|
||||
"//language-support/scala/bindings",
|
||||
],
|
||||
)
|
||||
|
||||
@ -96,25 +95,25 @@ da_scala_library(
|
||||
srcs = glob(["src/main/scala/com/daml/auth/middleware/oauth2/**/*.scala"]),
|
||||
resources = glob(["src/main/resources/com/daml/auth/middleware/oauth2/**"]),
|
||||
scala_deps = [
|
||||
"@maven//:com_chuusai_shapeless",
|
||||
"@maven//:com_github_pureconfig_pureconfig_core",
|
||||
"@maven//:com_github_pureconfig_pureconfig_generic",
|
||||
"@maven//:com_github_scopt_scopt",
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_http",
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_apache_pekko_pekko_http_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:org_parboiled_parboiled",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@triggers_maven//:com_lihaoyi_fastparse",
|
||||
"@triggers_maven//:com_lihaoyi_geny",
|
||||
"@triggers_maven//:com_lihaoyi_os_lib",
|
||||
"@triggers_maven//:com_lihaoyi_sjsonnet",
|
||||
"@triggers_maven//:com_lihaoyi_ujson",
|
||||
"@triggers_maven//:com_lihaoyi_upickle_core",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_http",
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_apache_pekko_pekko_http_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
"@maven//:com_chuusai_shapeless",
|
||||
"@maven//:com_github_pureconfig_pureconfig_core",
|
||||
"@maven//:com_github_pureconfig_pureconfig_generic",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_parboiled_parboiled",
|
||||
],
|
||||
scalacopts = lf_scalacopts_stricter,
|
||||
visibility = ["//visibility:public"],
|
||||
@ -123,11 +122,11 @@ da_scala_library(
|
||||
":middleware-api",
|
||||
":oauth2-api",
|
||||
"//daml-lf/data",
|
||||
"//language-support/scala/bindings",
|
||||
"//ledger-service/cli-opts",
|
||||
"//ledger-service/metrics",
|
||||
"//ledger-service/pureconfig-utils",
|
||||
"//ledger/ledger-api-auth",
|
||||
"//ledger/ledger-api-common",
|
||||
"//libs-scala/jwt",
|
||||
"//libs-scala/ledger-resources",
|
||||
"//libs-scala/ports",
|
||||
@ -160,20 +159,20 @@ da_scala_library(
|
||||
srcs = glob(["src/main/scala/com/daml/auth/oauth2/test/server/**/*.scala"]),
|
||||
scala_deps = [
|
||||
"@maven//:com_github_scopt_scopt",
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_http",
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_apache_pekko_pekko_http_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_parboiled_parboiled",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
],
|
||||
visibility = ["//triggers/service:__subpackages__"],
|
||||
deps = [
|
||||
":oauth2-api",
|
||||
"//language-support/scala/bindings",
|
||||
"//daml-lf/data",
|
||||
"//ledger/ledger-api-auth",
|
||||
"//libs-scala/jwt",
|
||||
"//libs-scala/ports",
|
||||
@ -197,20 +196,20 @@ da_scala_test(
|
||||
name = "oauth2-test-server-tests",
|
||||
srcs = glob(["src/test/scala/com/daml/auth/oauth2/test/server/**/*.scala"]),
|
||||
scala_deps = [
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_http",
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_apache_pekko_pekko_http_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_parboiled_parboiled",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
],
|
||||
scalacopts = test_scalacopts,
|
||||
deps = [
|
||||
":oauth2-api",
|
||||
":oauth2-test-server",
|
||||
"//language-support/scala/bindings",
|
||||
"//daml-lf/data",
|
||||
"//ledger/ledger-api-auth",
|
||||
"//libs-scala/adjustable-clock",
|
||||
"//libs-scala/jwt",
|
||||
@ -230,18 +229,18 @@ da_scala_test(
|
||||
":src/test/resources/oauth2-middleware-minimal.conf",
|
||||
],
|
||||
scala_deps = [
|
||||
"@maven//:com_github_pureconfig_pureconfig_core",
|
||||
"@maven//:com_lihaoyi_sourcecode",
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_http",
|
||||
"@maven//:org_apache_pekko_pekko_http_core",
|
||||
"@maven//:org_apache_pekko_pekko_http_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_http_testkit",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:com_typesafe_scala_logging_scala_logging",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:com_github_pureconfig_pureconfig_core",
|
||||
"@maven//:org_parboiled_parboiled",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
],
|
||||
scala_runtime_deps = [
|
||||
"@maven//:org_apache_pekko_pekko_stream_testkit",
|
||||
@ -254,7 +253,6 @@ da_scala_test(
|
||||
":oauth2-test-server",
|
||||
"//bazel_tools/runfiles:scala_runfiles",
|
||||
"//daml-lf/data",
|
||||
"//language-support/scala/bindings",
|
||||
"//ledger/ledger-api-auth",
|
||||
"//libs-scala/adjustable-clock",
|
||||
"//libs-scala/jwt",
|
||||
|
@ -9,7 +9,7 @@ import org.apache.pekko.http.scaladsl.model.{HttpHeader, Uri, headers}
|
||||
import org.apache.pekko.http.scaladsl.server.Directive1
|
||||
import org.apache.pekko.http.scaladsl.server.Directives._
|
||||
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshaller
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId, Party}
|
||||
import com.daml.lf.data.Ref
|
||||
import scalaz.{@@, Tag}
|
||||
import spray.json._
|
||||
|
||||
@ -37,9 +37,9 @@ object Request {
|
||||
// appId, i.e., either a wildcard token or a token with applicationId set to appId.
|
||||
case class Claims(
|
||||
admin: Boolean,
|
||||
actAs: List[Party],
|
||||
readAs: List[Party],
|
||||
applicationId: Option[ApplicationId],
|
||||
actAs: List[Ref.Party],
|
||||
readAs: List[Ref.Party],
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
) {
|
||||
def toQueryString() = {
|
||||
val adminS = if (admin) LazyList("admin") else LazyList()
|
||||
@ -52,27 +52,28 @@ object Request {
|
||||
object Claims {
|
||||
def apply(
|
||||
admin: Boolean = false,
|
||||
actAs: List[Party] = List(),
|
||||
readAs: List[Party] = List(),
|
||||
applicationId: Option[ApplicationId] = None,
|
||||
actAs: List[Ref.Party] = List(),
|
||||
readAs: List[Ref.Party] = List(),
|
||||
applicationId: Option[Ref.ApplicationId] = None,
|
||||
): Claims =
|
||||
new Claims(admin, actAs, readAs, applicationId)
|
||||
def apply(s: String): Claims = {
|
||||
var admin = false
|
||||
val actAs = ArrayBuffer[Party]()
|
||||
val readAs = ArrayBuffer[Party]()
|
||||
var applicationId: Option[ApplicationId] = None
|
||||
val actAs = ArrayBuffer[Ref.Party]()
|
||||
val readAs = ArrayBuffer[Ref.Party]()
|
||||
var applicationId: Option[Ref.ApplicationId] = None
|
||||
s.split(' ').foreach { w =>
|
||||
if (w == "admin") {
|
||||
admin = true
|
||||
} else if (w.startsWith("actAs:")) {
|
||||
actAs.append(Party(w.stripPrefix("actAs:")))
|
||||
actAs.append(Ref.Party.assertFromString(w.stripPrefix("actAs:")))
|
||||
} else if (w.startsWith("readAs:")) {
|
||||
readAs.append(Party(w.stripPrefix("readAs:")))
|
||||
readAs.append(Ref.Party.assertFromString(w.stripPrefix("readAs:")))
|
||||
} else if (w.startsWith("applicationId:")) {
|
||||
applicationId match {
|
||||
case None =>
|
||||
applicationId = Some(ApplicationId(w.stripPrefix("applicationId:")))
|
||||
applicationId =
|
||||
Some(Ref.ApplicationId.assertFromString(w.stripPrefix("applicationId:")))
|
||||
case Some(_) =>
|
||||
throw new IllegalArgumentException(
|
||||
"applicationId claim can only be specified once"
|
||||
|
@ -9,7 +9,6 @@ import java.util.UUID
|
||||
import org.apache.pekko.http.scaladsl.model.Uri
|
||||
import com.daml.auth.middleware.api.Request
|
||||
import com.daml.auth.middleware.api.Tagged.RefreshToken
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId, Party}
|
||||
|
||||
import scala.collection.concurrent.TrieMap
|
||||
import scala.io.{BufferedSource, Source}
|
||||
@ -116,11 +115,11 @@ private[oauth2] class RequestTemplates(
|
||||
"claims" -> ujson.Obj(
|
||||
"admin" -> claims.admin,
|
||||
"applicationId" -> (claims.applicationId match {
|
||||
case Some(appId) => ApplicationId.unwrap(appId)
|
||||
case Some(appId) => appId
|
||||
case None => ujson.Null
|
||||
}),
|
||||
"actAs" -> Party.unsubst(claims.actAs),
|
||||
"readAs" -> Party.unsubst(claims.readAs),
|
||||
"actAs" -> claims.actAs,
|
||||
"readAs" -> claims.readAs,
|
||||
),
|
||||
"redirectUri" -> redirectUri.toString,
|
||||
"state" -> requestId.toString,
|
||||
|
@ -15,7 +15,6 @@ import org.apache.pekko.http.scaladsl.server.Directives._
|
||||
import org.apache.pekko.http.scaladsl.unmarshalling.{Unmarshal, Unmarshaller}
|
||||
import com.daml.auth.oauth2.api.{JsonProtocol => OAuthJsonProtocol, Response => OAuthResponse}
|
||||
import com.daml.ledger.api.{auth => lapiauth}
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId, Party}
|
||||
import com.daml.ledger.resources.ResourceContext
|
||||
import com.daml.metrics.api.reporters.MetricsReporting
|
||||
import com.daml.metrics.pekkohttp.HttpMetricsInterceptor
|
||||
@ -371,13 +370,11 @@ object Server extends StrictLogging {
|
||||
case tp: lapiauth.CustomDamlJWTPayload =>
|
||||
(
|
||||
(tp.admin || !claims.admin) &&
|
||||
Party
|
||||
.unsubst(claims.actAs)
|
||||
.toSet
|
||||
claims.actAs
|
||||
.toSet[String]
|
||||
.subsetOf(tp.actAs.toSet) &&
|
||||
Party
|
||||
.unsubst(claims.readAs)
|
||||
.toSet
|
||||
claims.readAs
|
||||
.toSet[String]
|
||||
.subsetOf(tp.readAs.toSet ++ tp.actAs),
|
||||
tp.applicationId,
|
||||
)
|
||||
@ -391,7 +388,7 @@ object Server extends StrictLogging {
|
||||
case (None, _) => true
|
||||
// Token valid for all app ids.
|
||||
case (_, None) => true
|
||||
case (Some(expectedAppId), Some(actualAppId)) => expectedAppId == ApplicationId(actualAppId)
|
||||
case (Some(expectedAppId), Some(actualAppId)) => expectedAppId == actualAppId
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ import com.daml.ledger.api.auth.{
|
||||
StandardJWTPayload,
|
||||
StandardJWTTokenFormat,
|
||||
}
|
||||
import com.daml.ledger.api.refinements.ApiTypes.Party
|
||||
import com.daml.lf.data.Ref
|
||||
|
||||
import scala.collection.concurrent.TrieMap
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
@ -42,15 +42,15 @@ class Server(config: Config) {
|
||||
private val jwtHeader = """{"alg": "HS256", "typ": "JWT"}"""
|
||||
val tokenLifetimeSeconds = 24 * 60 * 60
|
||||
|
||||
private var unauthorizedParties: Set[Party] = Set()
|
||||
private var unauthorizedParties: Set[Ref.Party] = Set()
|
||||
|
||||
// Remove the given party from the set of unauthorized parties.
|
||||
def authorizeParty(party: Party): Unit = {
|
||||
def authorizeParty(party: Ref.Party): Unit = {
|
||||
unauthorizedParties = unauthorizedParties - party
|
||||
}
|
||||
|
||||
// Add the given party to the set of unauthorized parties.
|
||||
def revokeParty(party: Party): Unit = {
|
||||
def revokeParty(party: Ref.Party): Unit = {
|
||||
unauthorizedParties = unauthorizedParties + party
|
||||
}
|
||||
|
||||
@ -127,8 +127,8 @@ class Server(config: Config) {
|
||||
// Whether the current configuration of unauthorized parties and admin rights allows to grant the given token payload.
|
||||
private def authorize(payload: AuthServiceJWTPayload): Either[String, Unit] = payload match {
|
||||
case payload: CustomDamlJWTPayload =>
|
||||
val parties = Party.subst(payload.readAs ++ payload.actAs).toSet
|
||||
val deniedParties = parties.intersect(unauthorizedParties)
|
||||
val parties = (payload.readAs ++ payload.actAs).toSet
|
||||
val deniedParties = parties & unauthorizedParties.toSet[String]
|
||||
val deniedAdmin: Boolean = payload.admin && !allowAdmin
|
||||
if (deniedParties.nonEmpty) {
|
||||
Left(s"Access to parties ${deniedParties.mkString(" ")} denied")
|
||||
|
@ -22,9 +22,8 @@ import com.daml.ledger.api.auth.{
|
||||
StandardJWTPayload,
|
||||
StandardJWTTokenFormat,
|
||||
}
|
||||
import com.daml.ledger.api.refinements.ApiTypes
|
||||
import com.daml.ledger.api.refinements.ApiTypes.Party
|
||||
import com.daml.ledger.api.testing.utils.SuiteResourceManagementAroundAll
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.auth.oauth2.api.{Response => OAuthResponse}
|
||||
import com.daml.test.evidence.tag.Security.SecurityTest.Property.{Authenticity, Authorization}
|
||||
import com.daml.test.evidence.tag.Security.{Attack, SecurityTest}
|
||||
@ -95,7 +94,7 @@ abstract class TestMiddleware
|
||||
}
|
||||
"the /auth endpoint" should {
|
||||
"return unauthorized without cookie" taggedAs authorizationSecurity in {
|
||||
val claims = Request.Claims(actAs = List(Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
for {
|
||||
result <- middlewareClient.requestAuth(claims, Nil)
|
||||
} yield {
|
||||
@ -103,7 +102,7 @@ abstract class TestMiddleware
|
||||
}
|
||||
}
|
||||
"return the token from a cookie" taggedAs authorizationSecurity in {
|
||||
val claims = Request.Claims(actAs = List(Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
val token = makeToken(claims)
|
||||
val cookieHeader = Cookie("daml-ledger-token", token.toCookieValue)
|
||||
for {
|
||||
@ -116,13 +115,13 @@ abstract class TestMiddleware
|
||||
}
|
||||
"return unauthorized on insufficient app id claims" taggedAs authorizationSecurity in {
|
||||
val claims = Request.Claims(
|
||||
actAs = List(ApiTypes.Party("Alice")),
|
||||
applicationId = Some(ApiTypes.ApplicationId("other-id")),
|
||||
actAs = List(Ref.Party.assertFromString("Alice")),
|
||||
applicationId = Some(Ref.ApplicationId.assertFromString("other-id")),
|
||||
)
|
||||
val token = makeToken(
|
||||
Request.Claims(
|
||||
actAs = List(ApiTypes.Party("Alice")),
|
||||
applicationId = Some(ApiTypes.ApplicationId("my-app-id")),
|
||||
actAs = List(Ref.Party.assertFromString("Alice")),
|
||||
applicationId = Some(Ref.ApplicationId.assertFromString("my-app-id")),
|
||||
)
|
||||
)
|
||||
val cookieHeader = Cookie("daml-ledger-token", token.toCookieValue)
|
||||
@ -133,7 +132,7 @@ abstract class TestMiddleware
|
||||
}
|
||||
}
|
||||
"return unauthorized on an invalid token" taggedAs authorizationSecurity in {
|
||||
val claims = Request.Claims(actAs = List(ApiTypes.Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
val token = makeToken(claims, "wrong-secret")
|
||||
val cookieHeader = Cookie("daml-ledger-token", token.toCookieValue)
|
||||
for {
|
||||
@ -143,7 +142,7 @@ abstract class TestMiddleware
|
||||
}
|
||||
}
|
||||
"return unauthorized on an expired token" taggedAs authorizationSecurity in {
|
||||
val claims = Request.Claims(actAs = List(ApiTypes.Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
val token = makeToken(claims, expiresIn = Some(Duration.ZERO))
|
||||
val _ = clock.fastForward(Duration.ofSeconds(1))
|
||||
val cookieHeader = Cookie("daml-ledger-token", token.toCookieValue)
|
||||
@ -168,9 +167,9 @@ abstract class TestMiddleware
|
||||
),
|
||||
Claims(
|
||||
admin = true,
|
||||
actAs = List(ApiTypes.Party("Alice")),
|
||||
readAs = List(ApiTypes.Party("Bob")),
|
||||
applicationId = Some(ApiTypes.ApplicationId("foo")),
|
||||
actAs = List(Ref.Party.assertFromString("Alice")),
|
||||
readAs = List(Ref.Party.assertFromString("Bob")),
|
||||
applicationId = Some(Ref.ApplicationId.assertFromString("foo")),
|
||||
),
|
||||
) should ===(true)
|
||||
}
|
||||
@ -179,7 +178,7 @@ abstract class TestMiddleware
|
||||
"redirect and set cookie" taggedAs authenticationSecurity.setHappyCase(
|
||||
"A valid request to /login redirects to client callback and sets cookie"
|
||||
) in {
|
||||
val claims = Request.Claims(actAs = List(Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
val req = HttpRequest(uri = middlewareClientRoutes.loginUri(claims, None))
|
||||
for {
|
||||
resp <- Http().singleRequest(req)
|
||||
@ -209,7 +208,7 @@ abstract class TestMiddleware
|
||||
"return OK and set cookie without redirectUri" taggedAs authenticationSecurity.setHappyCase(
|
||||
"A valid request to /login returns OK and sets cookie when redirect is off"
|
||||
) in {
|
||||
val claims = Request.Claims(actAs = List(Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
val req = HttpRequest(uri = middlewareClientRoutes.loginUri(claims, None, redirect = false))
|
||||
for {
|
||||
resp <- Http().singleRequest(req)
|
||||
@ -240,7 +239,7 @@ abstract class TestMiddleware
|
||||
"return a new access token" taggedAs authorizationSecurity.setHappyCase(
|
||||
"A valid request to /refresh returns a new access token"
|
||||
) in {
|
||||
val claims = Request.Claims(actAs = List(Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
val loginReq = HttpRequest(uri = middlewareClientRoutes.loginUri(claims, None))
|
||||
for {
|
||||
resp <- Http().singleRequest(loginReq)
|
||||
@ -300,13 +299,13 @@ class TestMiddlewareClaimsToken extends TestMiddleware {
|
||||
participantId = None,
|
||||
exp = expiresIn.map(in => clock.instant.plus(in)),
|
||||
admin = claims.admin,
|
||||
actAs = claims.actAs.map(ApiTypes.Party.unwrap(_)),
|
||||
readAs = claims.readAs.map(ApiTypes.Party.unwrap(_)),
|
||||
actAs = claims.actAs,
|
||||
readAs = claims.readAs,
|
||||
)
|
||||
|
||||
"the /auth endpoint given claim token" should {
|
||||
"return unauthorized on insufficient party claims" taggedAs authorizationSecurity in {
|
||||
val claims = Request.Claims(actAs = List(Party("Bob")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Bob")))
|
||||
def r(actAs: String*)(readAs: String*) =
|
||||
middlewareClient
|
||||
.requestAuth(
|
||||
@ -316,8 +315,8 @@ class TestMiddlewareClaimsToken extends TestMiddleware {
|
||||
"daml-ledger-token",
|
||||
makeToken(
|
||||
Request.Claims(
|
||||
actAs = actAs.map(Party(_)).toList,
|
||||
readAs = readAs.map(Party(_)).toList,
|
||||
actAs = actAs.map(Ref.Party.assertFromString).toList,
|
||||
readAs = readAs.map(Ref.Party.assertFromString).toList,
|
||||
)
|
||||
).toCookieValue,
|
||||
)
|
||||
@ -349,8 +348,8 @@ class TestMiddlewareClaimsToken extends TestMiddleware {
|
||||
|
||||
"the /login endpoint with an oauth server checking claims" should {
|
||||
"not authorize unauthorized parties" taggedAs authorizationSecurity in {
|
||||
server.revokeParty(Party("Eve"))
|
||||
val claims = Request.Claims(actAs = List(Party("Eve")))
|
||||
server.revokeParty(Ref.Party.assertFromString("Eve"))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Eve")))
|
||||
ensureDisallowed(claims)
|
||||
}
|
||||
|
||||
@ -423,7 +422,7 @@ class TestMiddlewareCallbackUriOverride
|
||||
.setHappyCase(
|
||||
"A valid request to /login redirects to middleware callback"
|
||||
) in {
|
||||
val claims = Request.Claims(actAs = List(Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
val req = HttpRequest(uri = middlewareClientRoutes.loginUri(claims, None))
|
||||
for {
|
||||
resp <- Http().singleRequest(req)
|
||||
@ -462,7 +461,7 @@ class TestMiddlewareLimitedCallbackStore
|
||||
"Refuse request with SERVICE_UNAVAILABLE",
|
||||
)
|
||||
) in {
|
||||
def login(actAs: Party) = {
|
||||
def login(actAs: Ref.Party) = {
|
||||
val claims = Request.Claims(actAs = List(actAs))
|
||||
val uri = middlewareClientRoutes.loginUri(claims, None)
|
||||
val req = HttpRequest(uri = uri)
|
||||
@ -478,18 +477,18 @@ class TestMiddlewareLimitedCallbackStore
|
||||
|
||||
for {
|
||||
// Follow login flows up to redirect to middleware callback.
|
||||
redirectAlice <- login(Party("Alice"))
|
||||
redirectAlice <- login(Ref.Party.assertFromString("Alice"))
|
||||
.flatMap(followRedirect)
|
||||
redirectBob <- login(Party("Bob"))
|
||||
redirectBob <- login(Ref.Party.assertFromString("Bob"))
|
||||
.flatMap(followRedirect)
|
||||
// The store should be full
|
||||
refusedCarol <- login(Party("Carol"))
|
||||
refusedCarol <- login(Ref.Party.assertFromString("Carol"))
|
||||
_ = refusedCarol.status should ===(StatusCodes.ServiceUnavailable)
|
||||
// Follow first redirect to middleware callback.
|
||||
resultAlice <- followRedirect(redirectAlice)
|
||||
_ = resultAlice.status should ===(StatusCodes.Found)
|
||||
// The store should have space again
|
||||
redirectCarol <- login(Party("Carol"))
|
||||
redirectCarol <- login(Ref.Party.assertFromString("Carol"))
|
||||
.flatMap(followRedirect)
|
||||
// Follow redirects to middleware callback.
|
||||
resultBob <- followRedirect(redirectBob)
|
||||
@ -520,7 +519,7 @@ class TestMiddlewareClientLimitedCallbackStore
|
||||
"Refuse request with SERVICE_UNAVAILABLE",
|
||||
)
|
||||
) in {
|
||||
def login(actAs: Party) = {
|
||||
def login(actAs: Ref.Party) = {
|
||||
val claims = Request.Claims(actAs = List(actAs))
|
||||
val host = middlewareClientBinding.localAddress
|
||||
val uri = Uri()
|
||||
@ -541,22 +540,22 @@ class TestMiddlewareClientLimitedCallbackStore
|
||||
|
||||
for {
|
||||
// Follow login flows up to last redirect to middleware client.
|
||||
redirectAlice <- login(Party("Alice"))
|
||||
redirectAlice <- login(Ref.Party.assertFromString("Alice"))
|
||||
.flatMap(followRedirect)
|
||||
.flatMap(followRedirect)
|
||||
.flatMap(followRedirect)
|
||||
redirectBob <- login(Party("Bob"))
|
||||
redirectBob <- login(Ref.Party.assertFromString("Bob"))
|
||||
.flatMap(followRedirect)
|
||||
.flatMap(followRedirect)
|
||||
.flatMap(followRedirect)
|
||||
// The store should be full
|
||||
refusedCarol <- login(Party("Carol"))
|
||||
refusedCarol <- login(Ref.Party.assertFromString("Carol"))
|
||||
_ = refusedCarol.status should ===(StatusCodes.ServiceUnavailable)
|
||||
// Follow first redirect to middleware client.
|
||||
resultAlice <- followRedirect(redirectAlice)
|
||||
_ = resultAlice.status should ===(StatusCodes.OK)
|
||||
// The store should have space again
|
||||
redirectCarol <- login(Party("Carol"))
|
||||
redirectCarol <- login(Ref.Party.assertFromString("Carol"))
|
||||
.flatMap(followRedirect)
|
||||
.flatMap(followRedirect)
|
||||
.flatMap(followRedirect)
|
||||
@ -586,7 +585,7 @@ class TestMiddlewareClientNoRedirectToLogin
|
||||
"An unauthorized request should not redirect to /login using the JSON protocol"
|
||||
) in {
|
||||
import com.daml.auth.middleware.api.JsonProtocol.responseAuthenticateChallengeFormat
|
||||
val claims = Request.Claims(actAs = List(Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
val host = middlewareClientBinding.localAddress
|
||||
val uri = Uri()
|
||||
.withScheme("http")
|
||||
@ -638,7 +637,7 @@ class TestMiddlewareClientYesRedirectToLogin
|
||||
"redirect to /login" taggedAs authenticationSecurity.setHappyCase(
|
||||
"A valid HTTP request should redirect to /login"
|
||||
) in {
|
||||
val claims = Request.Claims(actAs = List(Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
val host = middlewareClientBinding.localAddress
|
||||
val uri = Uri()
|
||||
.withScheme("http")
|
||||
@ -676,7 +675,7 @@ class TestMiddlewareClientAutoRedirectToLogin
|
||||
"redirect to /login for HTML request" taggedAs authenticationSecurity.setHappyCase(
|
||||
"A HTML request is redirected to /login"
|
||||
) in {
|
||||
val claims = Request.Claims(actAs = List(Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
val host = middlewareClientBinding.localAddress
|
||||
val uri = Uri()
|
||||
.withScheme("http")
|
||||
@ -695,7 +694,7 @@ class TestMiddlewareClientAutoRedirectToLogin
|
||||
"not redirect to /login for JSON request" taggedAs authenticationSecurity.setHappyCase(
|
||||
"A JSON request is not redirected to /login"
|
||||
) in {
|
||||
val claims = Request.Claims(actAs = List(Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
val host = middlewareClientBinding.localAddress
|
||||
val uri = Uri()
|
||||
.withScheme("http")
|
||||
@ -735,7 +734,7 @@ class TestMiddlewareClientLoginCallbackUri
|
||||
}
|
||||
"be used in login URI" in {
|
||||
val routes = client.routes(Uri("http://client.domain/cb"))
|
||||
val claims = Request.Claims(actAs = List(Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
routes.loginUri(claims = claims) shouldBe
|
||||
Uri(
|
||||
s"http://auth.external/login?claims=${claims.toQueryString()}&redirect_uri=http://client.domain/cb"
|
||||
@ -745,7 +744,7 @@ class TestMiddlewareClientLoginCallbackUri
|
||||
"callback URI from request" should {
|
||||
"be used in login URI" in {
|
||||
val routes = client.routesFromRequestAuthority(Uri.Path./("cb"))
|
||||
val claims = Request.Claims(actAs = List(Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
import org.apache.pekko.http.scaladsl.server.directives.RouteDirectives._
|
||||
Get("http://client.domain") ~> routes { routes =>
|
||||
complete(routes.loginUri(claims).toString)
|
||||
@ -758,7 +757,7 @@ class TestMiddlewareClientLoginCallbackUri
|
||||
"automatic callback URI" should {
|
||||
"be fixed when absolute" in {
|
||||
val routes = client.routesAuto(Uri("http://client.domain/cb"))
|
||||
val claims = Request.Claims(actAs = List(Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
import org.apache.pekko.http.scaladsl.server.directives.RouteDirectives._
|
||||
Get() ~> routes { routes => complete(routes.loginUri(claims).toString) } ~> check {
|
||||
responseAs[String] shouldEqual
|
||||
@ -767,7 +766,7 @@ class TestMiddlewareClientLoginCallbackUri
|
||||
}
|
||||
"be from request when relative" in {
|
||||
val routes = client.routesAuto(Uri().withPath(Uri.Path./("cb")))
|
||||
val claims = Request.Claims(actAs = List(Party("Alice")))
|
||||
val claims = Request.Claims(actAs = List(Ref.Party.assertFromString("Alice")))
|
||||
import org.apache.pekko.http.scaladsl.server.directives.RouteDirectives._
|
||||
Get("http://client.domain") ~> routes { routes =>
|
||||
complete(routes.loginUri(claims).toString)
|
||||
|
@ -9,7 +9,7 @@ import java.util.UUID
|
||||
import org.apache.pekko.http.scaladsl.model.Uri
|
||||
import com.daml.auth.middleware.api.Request.Claims
|
||||
import com.daml.auth.middleware.api.Tagged.RefreshToken
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId, Party}
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.scalautil.Statement.discard
|
||||
import org.scalatest.{PartialFunctionValues, TryValues}
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
@ -98,7 +98,7 @@ class TestRequestTemplates
|
||||
val templates = getTemplates()
|
||||
val claims = Claims(
|
||||
admin = false,
|
||||
actAs = Party.subst(List("Alice", "Bob")),
|
||||
actAs = List("Alice", "Bob").map(Ref.Party.assertFromString),
|
||||
readAs = Nil,
|
||||
applicationId = None,
|
||||
)
|
||||
@ -128,7 +128,7 @@ class TestRequestTemplates
|
||||
val claims = Claims(
|
||||
admin = false,
|
||||
actAs = Nil,
|
||||
readAs = Party.subst(List("Alice", "Bob")),
|
||||
readAs = List("Alice", "Bob").map(Ref.Party.assertFromString),
|
||||
applicationId = None,
|
||||
)
|
||||
val requestId = UUID.randomUUID()
|
||||
@ -158,7 +158,7 @@ class TestRequestTemplates
|
||||
admin = false,
|
||||
actAs = Nil,
|
||||
readAs = Nil,
|
||||
applicationId = ApplicationId.subst(Some("application-id")),
|
||||
applicationId = Some(Ref.ApplicationId.assertFromString("application-id")),
|
||||
)
|
||||
val requestId = UUID.randomUUID()
|
||||
val redirectUri = Uri("https://localhost/cb")
|
||||
|
@ -17,7 +17,7 @@ import com.daml.ledger.api.auth.{
|
||||
AuthServiceJWTPayload,
|
||||
StandardJWTPayload,
|
||||
}
|
||||
import com.daml.ledger.api.refinements.ApiTypes.Party
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.ledger.api.testing.utils.SuiteResourceManagementAroundAll
|
||||
import org.scalatest.OptionValues
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
@ -224,7 +224,7 @@ class ClaimTokenTest extends Test {
|
||||
}
|
||||
}
|
||||
"deny access to unauthorized parties" in {
|
||||
server.revokeParty(Party("Eve"))
|
||||
server.revokeParty(Ref.Party.assertFromString("Eve"))
|
||||
for {
|
||||
error <- expectError(Seq("Alice", "Eve"))
|
||||
} yield {
|
||||
|
@ -3,9 +3,8 @@
|
||||
|
||||
package com.daml.lf.engine.trigger
|
||||
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId, Party}
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref.Identifier
|
||||
import scalaz.Tag
|
||||
import spray.json.DefaultJsonProtocol._
|
||||
import spray.json.{JsString, JsValue, JsonFormat, RootJsonFormat, deserializationError}
|
||||
|
||||
@ -19,22 +18,30 @@ object Request {
|
||||
def write(id: Identifier): JsValue = JsString(id.toString)
|
||||
}
|
||||
|
||||
private[trigger] implicit val PartyFormat: JsonFormat[Party] =
|
||||
Tag.subst(implicitly[JsonFormat[String]])
|
||||
private[this] def subStringFormat[X <: String](f: String => X): JsonFormat[X] =
|
||||
new JsonFormat[X] {
|
||||
override def write(obj: X): JsValue = StringJsonFormat.write(obj)
|
||||
override def read(json: JsValue): X = f(StringJsonFormat.read(json))
|
||||
}
|
||||
|
||||
private[trigger] implicit val PartyFormat: JsonFormat[Ref.Party] = subStringFormat(
|
||||
Ref.Party.assertFromString
|
||||
)
|
||||
|
||||
final case class StartParams(
|
||||
triggerName: Identifier,
|
||||
party: Party,
|
||||
applicationId: Option[ApplicationId],
|
||||
readAs: Option[List[Party]],
|
||||
party: Ref.Party,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
readAs: Option[List[Ref.Party]],
|
||||
)
|
||||
object StartParams {
|
||||
implicit val applicationIdFormat: JsonFormat[ApplicationId] =
|
||||
Tag.subst(implicitly[JsonFormat[String]])
|
||||
implicit val applicationIdFormat: JsonFormat[Ref.ApplicationId] = subStringFormat(
|
||||
Ref.ApplicationId.assertFromString
|
||||
)
|
||||
implicit val startParamsFormat: RootJsonFormat[StartParams] = jsonFormat4(StartParams.apply)
|
||||
}
|
||||
|
||||
final case class ListParams(party: Party)
|
||||
final case class ListParams(party: Ref.Party)
|
||||
object ListParams {
|
||||
implicit val listParamsFormat: RootJsonFormat[ListParams] = jsonFormat1(ListParams.apply)
|
||||
}
|
||||
|
@ -29,9 +29,9 @@ import scala.concurrent.duration._
|
||||
import com.daml.daml_lf_dev.DamlLf
|
||||
import com.daml.grpc.adapter.{PekkoExecutionSequencerPool, ExecutionSequencerFactory}
|
||||
import com.daml.dbutils.JdbcConfig
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId, Party}
|
||||
import com.daml.ledger.resources.ResourceContext
|
||||
import com.daml.lf.archive.{Dar, DarReader, Decode, Reader}
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref.{Identifier, PackageId}
|
||||
import com.daml.lf.engine._
|
||||
import com.daml.lf.engine.trigger.Request.StartParams
|
||||
@ -53,7 +53,6 @@ import com.daml.metrics.api.reporters.{MetricsReporter, MetricsReporting}
|
||||
import com.daml.scalautil.Statement.discard
|
||||
import com.daml.scalautil.ExceptionOps._
|
||||
import com.typesafe.scalalogging.StrictLogging
|
||||
import scalaz.Tag
|
||||
import scalaz.syntax.traverse._
|
||||
import spray.json.DefaultJsonProtocol._
|
||||
import spray.json._
|
||||
@ -140,19 +139,20 @@ class Server(
|
||||
case class TriggerConfig(
|
||||
instance: UUID,
|
||||
name: Identifier,
|
||||
party: Party,
|
||||
applicationId: ApplicationId,
|
||||
readAs: Set[Party],
|
||||
party: Ref.Party,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
readAs: Set[Ref.Party],
|
||||
)
|
||||
|
||||
private def newTrigger(
|
||||
party: Party,
|
||||
party: Ref.Party,
|
||||
triggerName: Identifier,
|
||||
optApplicationId: Option[ApplicationId],
|
||||
readAs: Set[Party],
|
||||
optApplicationId: Option[Ref.ApplicationId],
|
||||
readAs: Set[Ref.Party],
|
||||
): TriggerConfig = {
|
||||
val newInstance = UUID.randomUUID()
|
||||
val applicationId = optApplicationId.getOrElse(Tag(newInstance.toString): ApplicationId)
|
||||
val applicationId =
|
||||
optApplicationId.orElse(Some(Ref.ApplicationId.assertFromString(newInstance.toString)))
|
||||
TriggerConfig(newInstance, triggerName, party, applicationId, readAs)
|
||||
}
|
||||
|
||||
@ -216,8 +216,8 @@ class Server(
|
||||
uuid: UUID
|
||||
)(implicit ec: ExecutionContext, sys: ActorSystem): Future[Option[JsValue]] = {
|
||||
import Request.IdentifierFormat
|
||||
final case class Result(status: TriggerStatus, triggerId: Identifier, party: Party)
|
||||
implicit val partyFormat: JsonFormat[Party] = Tag.subst(implicitly[JsonFormat[String]])
|
||||
final case class Result(status: TriggerStatus, triggerId: Identifier, party: Ref.Party)
|
||||
implicit val partyFormat: JsonFormat[Ref.Party] = Request.PartyFormat
|
||||
implicit val resultFormat: RootJsonFormat[Result] = jsonFormat3(Result)
|
||||
triggerDao.getRunningTrigger(uuid).flatMap {
|
||||
case None => Future.successful(None)
|
||||
@ -235,7 +235,7 @@ class Server(
|
||||
}
|
||||
}
|
||||
|
||||
private def listTriggers(party: Party)(implicit ec: ExecutionContext): Future[JsValue] = {
|
||||
private def listTriggers(party: Ref.Party)(implicit ec: ExecutionContext): Future[JsValue] = {
|
||||
triggerDao.listRunningTriggers(party) map { triggerInstances =>
|
||||
JsObject(("triggerIds", triggerInstances.map(_.toString).toJson))
|
||||
}
|
||||
@ -298,7 +298,8 @@ class Server(
|
||||
}
|
||||
}
|
||||
|
||||
private implicit val unmarshalParty: Unmarshaller[String, Party] = Unmarshaller.strict(Party(_))
|
||||
private implicit val unmarshalParty: Unmarshaller[String, Ref.Party] =
|
||||
Unmarshaller.strict(Ref.Party.assertFromString(_))
|
||||
|
||||
private val route = concat(
|
||||
pathPrefix("v1" / "triggers") {
|
||||
@ -320,7 +321,7 @@ class Server(
|
||||
val claims =
|
||||
AuthRequest.Claims(
|
||||
actAs = List(params.party),
|
||||
applicationId = Some(config.applicationId),
|
||||
applicationId = config.applicationId,
|
||||
readAs = config.readAs.toList,
|
||||
)
|
||||
authorize(claims) { auth =>
|
||||
@ -350,7 +351,7 @@ class Server(
|
||||
},
|
||||
// List triggers currently running for the given party.
|
||||
get {
|
||||
parameters(Symbol("party").as[Party]) { party =>
|
||||
parameters(Symbol("party").as[Ref.Party]) { party =>
|
||||
val claims = Claims(readAs = List(party))
|
||||
authorize(claims) { _ =>
|
||||
extractExecutionContext { implicit ec =>
|
||||
|
@ -8,7 +8,6 @@ import org.apache.pekko.actor.typed.{ActorRef, Behavior, PostStop, PreRestart}
|
||||
import org.apache.pekko.stream.{KillSwitch, KillSwitches, Materializer}
|
||||
import com.daml.auth.middleware.api.Tagged.{AccessToken, RefreshToken}
|
||||
import com.daml.grpc.adapter.ExecutionSequencerFactory
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId, Party}
|
||||
import com.daml.ledger.api.tls.TlsConfiguration
|
||||
import com.daml.ledger.api.v1.event.CreatedEvent
|
||||
import com.daml.ledger.api.v1.ledger_offset.LedgerOffset
|
||||
@ -20,12 +19,12 @@ import com.daml.ledger.client.configuration.{
|
||||
LedgerIdRequirement,
|
||||
}
|
||||
import com.daml.lf.CompiledPackages
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.engine.trigger.Runner.TriggerContext
|
||||
import com.daml.lf.engine.trigger.ToLoggingContext._
|
||||
import com.daml.lf.engine.trigger.TriggerRunner.{QueryingACS, Running, TriggerStatus}
|
||||
import com.daml.logging.ContextualizedLogger
|
||||
import io.grpc.Status.Code
|
||||
import scalaz.syntax.tag._
|
||||
|
||||
import java.util.UUID
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
@ -37,8 +36,8 @@ object TriggerRunnerImpl {
|
||||
final case class Config(
|
||||
server: ActorRef[Server.Message],
|
||||
triggerInstance: UUID,
|
||||
party: Party,
|
||||
applicationId: ApplicationId,
|
||||
party: Ref.Party,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
accessToken: Option[AccessToken],
|
||||
refreshToken: Option[RefreshToken],
|
||||
compiledPackages: CompiledPackages,
|
||||
@ -47,7 +46,7 @@ object TriggerRunnerImpl {
|
||||
triggerConfig: TriggerRunnerConfig,
|
||||
ledgerConfig: LedgerConfig,
|
||||
restartConfig: TriggerRestartConfig,
|
||||
readAs: Set[Party],
|
||||
readAs: Set[Ref.Party],
|
||||
) {
|
||||
private[trigger] def withTriggerLogContext[T]: (TriggerLogContext => T) => T =
|
||||
Trigger.newTriggerLogContext(
|
||||
@ -81,7 +80,7 @@ object TriggerRunnerImpl {
|
||||
config.server ! Server.TriggerStarting(triggerInstance)
|
||||
logger.info(s"Trigger $name is starting")
|
||||
val clientConfig = LedgerClientConfiguration(
|
||||
applicationId = config.applicationId.unwrap,
|
||||
applicationId = config.applicationId.getOrElse(""),
|
||||
ledgerIdRequirement = LedgerIdRequirement.none,
|
||||
commandClient = CommandClientConfiguration.default.copy(
|
||||
defaultDeduplicationTime = config.ledgerConfig.commandTtl
|
||||
|
@ -8,8 +8,8 @@ import cats.effect.{ContextShift, IO}
|
||||
import cats.syntax.functor._
|
||||
import com.daml.daml_lf_dev.DamlLf
|
||||
import com.daml.dbutils.{ConnectionPool, JdbcConfig}
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId, Party}
|
||||
import com.daml.lf.archive.{ArchivePayloadParser, Dar}
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref.{Identifier, PackageId}
|
||||
import com.daml.lf.engine.trigger.RunningTrigger
|
||||
import doobie.free.connection.ConnectionIO
|
||||
@ -40,27 +40,22 @@ abstract class DbTriggerDao protected (
|
||||
protected implicit def uuidPut: Put[UUID]
|
||||
protected implicit def uuidGet: Get[UUID]
|
||||
|
||||
implicit val readAsPut: Put[Set[Party]] = {
|
||||
type F[A] = Put[Set[A]]
|
||||
Party.subst[F, String](implicitly[Put[String]].contramap {
|
||||
_.mkString("%")
|
||||
})
|
||||
}
|
||||
implicit val readAsPut: Put[Set[Ref.Party]] =
|
||||
implicitly[Put[String]].contramap(_.mkString("%"))
|
||||
|
||||
implicit val readAsGet: Get[Set[Party]] = {
|
||||
type F[A] = Get[Set[A]]
|
||||
Party.subst[F, String](implicitly[Get[String]].map {
|
||||
_.split("%").toSet.filter(_.nonEmpty)
|
||||
})
|
||||
}
|
||||
implicit val readAsGet: Get[Set[Ref.Party]] =
|
||||
implicitly[Get[String]].map(
|
||||
_.split("%").toSet.filter(_.nonEmpty).map(Ref.Party.assertFromString)
|
||||
)
|
||||
|
||||
implicit val partyPut: Put[Party] = Tag.subst(implicitly[Put[String]])
|
||||
implicit val partyPut: Put[Ref.Party] = implicitly[Put[String]].contramap(identity)
|
||||
|
||||
implicit val partyGet: Get[Party] = Tag.subst(implicitly[Get[String]])
|
||||
implicit val partyGet: Get[Ref.Party] = implicitly[Get[String]].map(Ref.Party.assertFromString)
|
||||
|
||||
implicit val appIdPut: Put[ApplicationId] = Tag.subst(implicitly[Put[String]])
|
||||
implicit val appIdPut: Put[Ref.ApplicationId] = implicitly[Put[String]].contramap(identity)
|
||||
|
||||
implicit val appIdGet: Get[ApplicationId] = Tag.subst(implicitly[Get[String]])
|
||||
implicit val appIdGet: Get[Ref.ApplicationId] =
|
||||
implicitly[Get[String]].map(Ref.ApplicationId.assertFromString)
|
||||
|
||||
implicit val accessTokenPut: Put[AccessToken] = Tag.subst(implicitly[Put[String]])
|
||||
|
||||
@ -73,7 +68,7 @@ abstract class DbTriggerDao protected (
|
||||
implicit val identifierPut: Put[Identifier] = implicitly[Put[String]].contramap(_.toString)
|
||||
|
||||
implicit val identifierGet: Get[Identifier] =
|
||||
implicitly[Get[String]].map(Identifier.assertFromString(_))
|
||||
implicitly[Get[String]].map(Identifier.assertFromString)
|
||||
|
||||
private implicit val logHandler: log.LogHandler = Slf4jLogHandler(classOf[DbTriggerDao])
|
||||
|
||||
@ -111,11 +106,11 @@ abstract class DbTriggerDao protected (
|
||||
(
|
||||
UUID,
|
||||
Identifier,
|
||||
Party,
|
||||
ApplicationId,
|
||||
Ref.Party,
|
||||
Option[Ref.ApplicationId],
|
||||
Option[AccessToken],
|
||||
Option[RefreshToken],
|
||||
Option[Set[Party]],
|
||||
Option[Set[Ref.Party]],
|
||||
)
|
||||
]
|
||||
.map(_.mapElements(_7 = it => it.getOrElse(Set.empty)))
|
||||
@ -146,7 +141,7 @@ abstract class DbTriggerDao protected (
|
||||
delete.update.run.map(_ == 1)
|
||||
}
|
||||
|
||||
private def selectRunningTriggers(party: Party): ConnectionIO[Vector[UUID]] = {
|
||||
private def selectRunningTriggers(party: Ref.Party): ConnectionIO[Vector[UUID]] = {
|
||||
val select: Fragment = sql"""
|
||||
select trigger_instance from ${Fragment.const(s"${tablePrefix}running_triggers")}
|
||||
where trigger_party = $party
|
||||
@ -192,11 +187,11 @@ abstract class DbTriggerDao protected (
|
||||
(
|
||||
UUID,
|
||||
Identifier,
|
||||
Party,
|
||||
ApplicationId,
|
||||
Ref.Party,
|
||||
Option[Ref.ApplicationId],
|
||||
Option[AccessToken],
|
||||
Option[RefreshToken],
|
||||
Option[Set[Party]],
|
||||
Option[Set[Ref.Party]],
|
||||
)
|
||||
]
|
||||
.map(_.mapElements(_7 = it => it.getOrElse(Set.empty)))
|
||||
@ -240,7 +235,7 @@ abstract class DbTriggerDao protected (
|
||||
run(deleteRunningTrigger(triggerInstance))
|
||||
|
||||
override def listRunningTriggers(
|
||||
party: Party
|
||||
party: Ref.Party
|
||||
)(implicit ec: ExecutionContext): Future[Vector[UUID]] = {
|
||||
// Note(RJR): Postgres' ordering of UUIDs is different to Scala/Java's.
|
||||
// We sort them after the query to be consistent with the ordering when not using a database.
|
||||
|
@ -7,8 +7,8 @@ import java.util.UUID
|
||||
|
||||
import com.daml.auth.middleware.api.Tagged.{AccessToken, RefreshToken}
|
||||
import com.daml.daml_lf_dev.DamlLf
|
||||
import com.daml.ledger.api.refinements.ApiTypes.Party
|
||||
import com.daml.lf.archive.Dar
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref.PackageId
|
||||
import com.daml.lf.engine.trigger.RunningTrigger
|
||||
|
||||
@ -16,7 +16,7 @@ import scala.concurrent.{ExecutionContext, Future}
|
||||
|
||||
final class InMemoryTriggerDao extends RunningTriggerDao {
|
||||
private var triggers: Map[UUID, RunningTrigger] = Map.empty
|
||||
private var triggersByParty: Map[Party, Set[UUID]] = Map.empty
|
||||
private var triggersByParty: Map[Ref.Party, Set[UUID]] = Map.empty
|
||||
|
||||
override def addRunningTrigger(t: RunningTrigger)(implicit ec: ExecutionContext): Future[Unit] =
|
||||
Future {
|
||||
@ -60,7 +60,7 @@ final class InMemoryTriggerDao extends RunningTriggerDao {
|
||||
}
|
||||
|
||||
override def listRunningTriggers(
|
||||
party: Party
|
||||
party: Ref.Party
|
||||
)(implicit ec: ExecutionContext): Future[Vector[UUID]] = Future {
|
||||
triggersByParty.getOrElse(party, Set()).toVector.sorted
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ import java.util.UUID
|
||||
|
||||
import com.daml.auth.middleware.api.Tagged.{AccessToken, RefreshToken}
|
||||
import com.daml.daml_lf_dev.DamlLf
|
||||
import com.daml.ledger.api.refinements.ApiTypes.Party
|
||||
import com.daml.lf.archive.Dar
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref.PackageId
|
||||
import com.daml.lf.engine.trigger.RunningTrigger
|
||||
|
||||
@ -26,7 +26,7 @@ trait RunningTriggerDao extends Closeable {
|
||||
refreshToken: Option[RefreshToken],
|
||||
)(implicit ec: ExecutionContext): Future[Unit]
|
||||
def removeRunningTrigger(triggerInstance: UUID)(implicit ec: ExecutionContext): Future[Boolean]
|
||||
def listRunningTriggers(party: Party)(implicit ec: ExecutionContext): Future[Vector[UUID]]
|
||||
def listRunningTriggers(party: Ref.Party)(implicit ec: ExecutionContext): Future[Vector[UUID]]
|
||||
def persistPackages(dar: Dar[(PackageId, DamlLf.ArchivePayload)])(implicit
|
||||
ec: ExecutionContext
|
||||
): Future[Unit]
|
||||
|
@ -6,7 +6,7 @@ package com.daml.lf.engine
|
||||
import java.time.Duration
|
||||
import java.util.UUID
|
||||
|
||||
import com.daml.ledger.api.refinements.ApiTypes.Party
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref.Identifier
|
||||
import com.daml.platform.services.time.TimeProviderType
|
||||
|
||||
@ -20,7 +20,6 @@ package trigger {
|
||||
final case class AuthMiddleware(internal: Uri, external: Uri) extends AuthConfig
|
||||
|
||||
import com.daml.auth.middleware.api.Tagged.{AccessToken, RefreshToken}
|
||||
import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
|
||||
|
||||
case class LedgerConfig(
|
||||
host: String,
|
||||
@ -39,11 +38,11 @@ package trigger {
|
||||
final case class RunningTrigger(
|
||||
triggerInstance: UUID,
|
||||
triggerName: Identifier,
|
||||
triggerParty: Party,
|
||||
triggerApplicationId: ApplicationId,
|
||||
triggerParty: Ref.Party,
|
||||
triggerApplicationId: Option[Ref.ApplicationId],
|
||||
triggerAccessToken: Option[AccessToken],
|
||||
triggerRefreshToken: Option[RefreshToken],
|
||||
triggerReadAs: Set[Party],
|
||||
triggerReadAs: Set[Ref.Party],
|
||||
) {
|
||||
private[trigger] def withTriggerLogContext[T]: (TriggerLogContext => T) => T =
|
||||
Trigger.newTriggerLogContext(
|
||||
|
@ -31,10 +31,10 @@ import com.daml.ledger.api.auth.{
|
||||
StandardJWTPayload,
|
||||
StandardJWTTokenFormat,
|
||||
}
|
||||
import com.daml.ledger.api.refinements.ApiTypes
|
||||
import com.daml.ledger.api.testing.utils.{PekkoBeforeAndAfterAll, OwnedResource}
|
||||
import com.daml.ledger.resources.{Resource, ResourceContext, ResourceOwner}
|
||||
import com.daml.lf.archive.Dar
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref._
|
||||
import com.daml.lf.engine.trigger.TriggerRunnerConfig.DefaultTriggerRunnerConfig
|
||||
import com.daml.lf.engine.trigger.dao.DbTriggerDao
|
||||
@ -126,8 +126,8 @@ trait AbstractAuthFixture extends SuiteMixin {
|
||||
protected def authService: Option[auth.AuthService]
|
||||
protected[this] def authToken(
|
||||
admin: Boolean,
|
||||
actAs: List[ApiTypes.Party],
|
||||
readAs: List[ApiTypes.Party],
|
||||
actAs: List[Ref.Party],
|
||||
readAs: List[Ref.Party],
|
||||
): Option[String]
|
||||
protected def authConfig: AuthConfig
|
||||
}
|
||||
@ -138,8 +138,8 @@ trait NoAuthFixture extends AbstractAuthFixture {
|
||||
protected override def authService: Option[auth.AuthService] = None
|
||||
protected[this] override final def authToken(
|
||||
admin: Boolean,
|
||||
actAs: List[ApiTypes.Party],
|
||||
readAs: List[ApiTypes.Party],
|
||||
actAs: List[Ref.Party],
|
||||
readAs: List[Ref.Party],
|
||||
) = None
|
||||
protected override def authConfig: AuthConfig = NoAuth
|
||||
}
|
||||
@ -157,8 +157,8 @@ trait AuthMiddlewareFixture
|
||||
|
||||
protected[this] override final def authToken(
|
||||
admin: Boolean,
|
||||
actAs: List[ApiTypes.Party],
|
||||
readAs: List[ApiTypes.Party],
|
||||
actAs: List[Ref.Party],
|
||||
readAs: List[Ref.Party],
|
||||
) = Some {
|
||||
val payload =
|
||||
if (sandboxClientTakesUserToken)
|
||||
@ -178,8 +178,8 @@ trait AuthMiddlewareFixture
|
||||
participantId = None,
|
||||
exp = None,
|
||||
admin = admin,
|
||||
actAs = ApiTypes.Party unsubst actAs,
|
||||
readAs = ApiTypes.Party unsubst readAs,
|
||||
actAs = actAs,
|
||||
readAs = readAs,
|
||||
)
|
||||
|
||||
val header = """{"alg": "HS256", "typ": "JWT"}"""
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
package com.daml.lf.engine.trigger
|
||||
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId, Party}
|
||||
import com.daml.lf.archive.{Dar, DarReader}
|
||||
import org.apache.pekko.http.scaladsl.Http
|
||||
import org.apache.pekko.http.scaladsl.model._
|
||||
@ -40,6 +39,7 @@ import com.daml.ledger.api.v1.value.{Identifier, Record, RecordField, Value}
|
||||
import com.daml.ledger.api.v1.transaction_filter.{Filters, InclusiveFilters, TransactionFilter}
|
||||
import com.daml.ledger.client.LedgerClient
|
||||
import com.daml.ledger.client.services.commands.CompletionStreamElement
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref.PackageId
|
||||
import com.daml.lf.engine.trigger.TriggerRunnerConfig.DefaultTriggerRunnerConfig
|
||||
import com.daml.timer.RetryStrategy
|
||||
@ -153,9 +153,9 @@ trait AbstractTriggerServiceTestHelper
|
||||
def startTrigger(
|
||||
uri: Uri,
|
||||
triggerName: String,
|
||||
party: Party,
|
||||
applicationId: Option[ApplicationId] = None,
|
||||
readAs: Set[Party] = Set(),
|
||||
party: Ref.Party,
|
||||
applicationId: Option[Option[Ref.ApplicationId]] = None,
|
||||
readAs: Set[Ref.Party] = Set(),
|
||||
): Future[HttpResponse] = {
|
||||
import Request.PartyFormat
|
||||
val readAsContent =
|
||||
@ -170,13 +170,14 @@ trait AbstractTriggerServiceTestHelper
|
||||
entity = HttpEntity(
|
||||
ContentTypes.`application/json`,
|
||||
s"""{"triggerName": "$triggerName", "party": "$party", "applicationId": "${applicationId
|
||||
.map(_.getOrElse(""))
|
||||
.getOrElse("null")}", "readAs": $readAsContent}""",
|
||||
),
|
||||
)
|
||||
httpRequestFollow(req)
|
||||
}
|
||||
|
||||
def listTriggers(uri: Uri, party: Party): Future[HttpResponse] = {
|
||||
def listTriggers(uri: Uri, party: Ref.Party): Future[HttpResponse] = {
|
||||
val req = HttpRequest(
|
||||
method = HttpMethods.GET,
|
||||
uri = uri.withPath(Uri.Path(s"/v1/triggers")).withQuery(Query(("party", party.toString))),
|
||||
@ -184,7 +185,7 @@ trait AbstractTriggerServiceTestHelper
|
||||
httpRequestFollow(req)
|
||||
}
|
||||
|
||||
def stopTrigger(uri: Uri, triggerInstance: UUID, party: Party): Future[HttpResponse] = {
|
||||
def stopTrigger(uri: Uri, triggerInstance: UUID, party: Ref.Party): Future[HttpResponse] = {
|
||||
// silence unused warning, we probably need this parameter again when we
|
||||
// support auth.
|
||||
val _ = party
|
||||
@ -254,11 +255,11 @@ trait AbstractTriggerServiceTestHelper
|
||||
|
||||
def getActiveContracts(
|
||||
client: LedgerClient,
|
||||
party: Party,
|
||||
party: Ref.Party,
|
||||
template: Identifier,
|
||||
): Future[Seq[CreatedEvent]] = {
|
||||
val filter = TransactionFilter(
|
||||
Map(party.unwrap -> Filters(Some(InclusiveFilters(Seq(template)))))
|
||||
Map(party -> Filters(Some(InclusiveFilters(Seq(template)))))
|
||||
)
|
||||
client.activeContractSetClient
|
||||
.getActiveContracts(filter)
|
||||
@ -266,7 +267,7 @@ trait AbstractTriggerServiceTestHelper
|
||||
.map(acsPages => acsPages.flatMap(_.activeContracts))
|
||||
}
|
||||
|
||||
def assertTriggerIds(uri: Uri, party: Party, expected: Vector[UUID]): Future[Assertion] =
|
||||
def assertTriggerIds(uri: Uri, party: Ref.Party, expected: Vector[UUID]): Future[Assertion] =
|
||||
for {
|
||||
resp <- listTriggers(uri, party)
|
||||
result <- parseTriggerIds(resp)
|
||||
@ -296,10 +297,10 @@ trait AbstractTriggerServiceTestHelper
|
||||
client: LedgerClient,
|
||||
hint: Option[String] = None,
|
||||
displayName: Option[String] = None,
|
||||
): Future[Party] =
|
||||
): Future[Ref.Party] =
|
||||
client.partyManagementClient
|
||||
.allocateParty(hint, displayName)
|
||||
.map(details => Party(details.party: String))
|
||||
.map(_.party)
|
||||
}
|
||||
|
||||
// Tests for all trigger service configurations go here
|
||||
@ -402,8 +403,8 @@ trait AbstractTriggerServiceTest extends AbstractTriggerServiceTestHelper {
|
||||
|
||||
_ <- submitCmd(
|
||||
client,
|
||||
public.unwrap,
|
||||
Command().withCreate(visibleToPublic(public.unwrap)),
|
||||
public,
|
||||
Command().withCreate(visibleToPublic(public)),
|
||||
)
|
||||
|
||||
// Start the trigger
|
||||
@ -486,14 +487,14 @@ trait AbstractTriggerServiceTest extends AbstractTriggerServiceTestHelper {
|
||||
Record(
|
||||
None,
|
||||
Seq(
|
||||
RecordField(value = Some(Value().withParty(aliceAcs.unwrap))),
|
||||
RecordField(value = Some(Value().withParty(aliceAcs))),
|
||||
RecordField(value = Some(Value().withInt64(42))),
|
||||
),
|
||||
)
|
||||
),
|
||||
)
|
||||
)
|
||||
submitCmd(client, aliceAcs.unwrap, cmd)
|
||||
submitCmd(client, aliceAcs, cmd)
|
||||
}
|
||||
// Query ACS until we see a B contract
|
||||
_ <- RetryStrategy.constant(20, 1.seconds) { (_, _) =>
|
||||
@ -502,7 +503,7 @@ trait AbstractTriggerServiceTest extends AbstractTriggerServiceTestHelper {
|
||||
}
|
||||
// Read completions to make sure we set the right app id.
|
||||
r <- client.commandClient
|
||||
.completionSource(List(aliceAcs.unwrap), LedgerOffset(Boundary(LEDGER_BEGIN)))
|
||||
.completionSource(List(aliceAcs), LedgerOffset(Boundary(LEDGER_BEGIN)))
|
||||
.collect({
|
||||
case CompletionStreamElement.CompletionElement(completion, _)
|
||||
if completion.transactionId.nonEmpty =>
|
||||
@ -647,7 +648,7 @@ trait AbstractTriggerServiceTest extends AbstractTriggerServiceTestHelper {
|
||||
} yield succeed
|
||||
}
|
||||
|
||||
def breedCat(party: Party, id: Long): Command = {
|
||||
def breedCat(party: Ref.Party, id: Long): Command = {
|
||||
Command().withCreate(
|
||||
CreateCommand(
|
||||
templateId = Some(Identifier(testPkgId, "Cats", "Cat")),
|
||||
@ -655,7 +656,7 @@ trait AbstractTriggerServiceTest extends AbstractTriggerServiceTestHelper {
|
||||
Record(
|
||||
None,
|
||||
Seq(
|
||||
RecordField(value = Some(Value().withParty(party.unwrap))),
|
||||
RecordField(value = Some(Value().withParty(party))),
|
||||
RecordField(value = Some(Value().withInt64(id))),
|
||||
),
|
||||
)
|
||||
@ -693,7 +694,7 @@ trait AbstractTriggerServiceTest extends AbstractTriggerServiceTestHelper {
|
||||
.map(_ shouldBe Vector.empty)
|
||||
// Create 100 Cat contracts
|
||||
_ <- Future.sequence(
|
||||
(1 to 100).map(id => submitCmd(client, party.unwrap, breedCat(party, id.toLong)))
|
||||
(1 to 100).map(id => submitCmd(client, party, breedCat(party, id.toLong)))
|
||||
)
|
||||
// Wait for our Cat contracts to be created
|
||||
_ <- RetryStrategy.constant(20, 1.seconds) { (_, _) =>
|
||||
@ -730,7 +731,7 @@ trait AbstractTriggerServiceTest extends AbstractTriggerServiceTestHelper {
|
||||
_ <- getActiveContracts(client, party, Identifier(testPkgId, "Cats", "Cat"))
|
||||
.flatMap(events =>
|
||||
Future.sequence(events.map { event =>
|
||||
submitCmd(client, party.unwrap, killCat(event.contractId))
|
||||
submitCmd(client, party, killCat(event.contractId))
|
||||
})
|
||||
)
|
||||
// Wait until there are no Cat contracts
|
||||
@ -769,7 +770,7 @@ trait AbstractTriggerServiceTest extends AbstractTriggerServiceTestHelper {
|
||||
_ <- getActiveContracts(client, party, Identifier(testPkgId, "Cats", "Cat"))
|
||||
.flatMap(events =>
|
||||
Future.sequence(events.map { event =>
|
||||
submitCmd(client, party.unwrap, killCat(event.contractId))
|
||||
submitCmd(client, party, killCat(event.contractId))
|
||||
})
|
||||
)
|
||||
// Wait until there are no Cat contracts
|
||||
@ -804,7 +805,7 @@ trait AbstractTriggerServiceTest extends AbstractTriggerServiceTestHelper {
|
||||
_ <- getActiveContracts(client, party, Identifier(testPkgId, "Cats", "Cat"))
|
||||
.flatMap(events =>
|
||||
Future.sequence(events.map { event =>
|
||||
submitCmd(client, party.unwrap, killCat(event.contractId))
|
||||
submitCmd(client, party, killCat(event.contractId))
|
||||
})
|
||||
)
|
||||
// Wait until there are no Cat contracts
|
||||
@ -843,7 +844,7 @@ trait AbstractTriggerServiceTest extends AbstractTriggerServiceTestHelper {
|
||||
_ <- getActiveContracts(client, party, Identifier(testPkgId, "Cats", "Cat"))
|
||||
.flatMap(events =>
|
||||
Future.sequence(events.map { event =>
|
||||
submitCmd(client, party.unwrap, killCat(event.contractId))
|
||||
submitCmd(client, party, killCat(event.contractId))
|
||||
})
|
||||
)
|
||||
// Wait until there are no Cat contracts
|
||||
@ -1110,7 +1111,7 @@ trait AbstractTriggerServiceTestAuthMiddleware
|
||||
Record(
|
||||
None,
|
||||
Seq(
|
||||
RecordField(value = Some(Value().withParty(aliceExp.unwrap))),
|
||||
RecordField(value = Some(Value().withParty(aliceExp))),
|
||||
RecordField(value = Some(Value().withInt64(v))),
|
||||
),
|
||||
)
|
||||
@ -1118,7 +1119,7 @@ trait AbstractTriggerServiceTestAuthMiddleware
|
||||
)
|
||||
)
|
||||
}
|
||||
_ <- submitCmd(client, aliceExp.unwrap, createACommand(7))
|
||||
_ <- submitCmd(client, aliceExp, createACommand(7))
|
||||
// Query ACS until we see a B contract
|
||||
_ <- RetryStrategy.constant(5, 2.seconds) { (_, _) =>
|
||||
getActiveContracts(client, aliceExp, Identifier(testPkgId, "TestTrigger", "B"))
|
||||
@ -1131,7 +1132,7 @@ trait AbstractTriggerServiceTestAuthMiddleware
|
||||
)
|
||||
|
||||
// Create another A contract
|
||||
_ <- submitCmd(client, aliceExp.unwrap, createACommand(42))
|
||||
_ <- submitCmd(client, aliceExp, createACommand(42))
|
||||
// Query ACS until we see a second B contract
|
||||
_ <- RetryStrategy.constant(5, 1.seconds) { (_, _) =>
|
||||
getActiveContracts(client, aliceExp, Identifier(testPkgId, "TestTrigger", "B"))
|
||||
@ -1140,7 +1141,7 @@ trait AbstractTriggerServiceTestAuthMiddleware
|
||||
|
||||
// Read completions to make sure we set the right app id.
|
||||
r <- client.commandClient
|
||||
.completionSource(List(aliceExp.unwrap), LedgerOffset(Boundary(LEDGER_BEGIN)))
|
||||
.completionSource(List(aliceExp), LedgerOffset(Boundary(LEDGER_BEGIN)))
|
||||
.collect({
|
||||
case CompletionStreamElement.CompletionElement(completion, _)
|
||||
if completion.transactionId.nonEmpty =>
|
||||
|
@ -16,9 +16,9 @@ da_scala_test_suite(
|
||||
srcs = glob(["scala/*.scala"]),
|
||||
resources = ["//triggers/runner:src/main/resources/logback.xml"],
|
||||
scala_deps = [
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_actor_typed",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_scalacheck_scalacheck",
|
||||
"@maven//:org_scalatestplus_scalacheck_1_15",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
@ -37,9 +37,8 @@ da_scala_test_suite(
|
||||
"//daml-lf/language",
|
||||
"//daml-lf/transaction",
|
||||
"//daml-script/converter",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger/ledger-api-auth",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//ledger/ledger-api-domain",
|
||||
"//libs-scala/contextualized-logging",
|
||||
@ -56,5 +55,10 @@ da_scala_test_suite(
|
||||
"//triggers/runner:trigger-runner-lib",
|
||||
"//triggers/tests:test-utils",
|
||||
"//triggers/tests:trigger-simulation-lib",
|
||||
"@maven//:ch_qos_logback_logback_classic",
|
||||
"@maven//:ch_qos_logback_logback_core",
|
||||
"@maven//:io_grpc_grpc_api",
|
||||
"@maven//:io_grpc_grpc_netty",
|
||||
"@maven//:io_netty_netty_handler",
|
||||
],
|
||||
)
|
||||
|
@ -70,7 +70,7 @@ This method is used to define all the components that a given simulation is to t
|
||||
.. code-block:: scala
|
||||
class ExampleSimulation extends TriggerMultiProcessSimulation {
|
||||
override protected def triggerMultiProcessSimulation: Behavior[Unit] = {
|
||||
implicit def applicationId: ApiTypes.ApplicationId = this.applicationId
|
||||
implicit def applicationId: Option[Ref.ApplicationId] = this.applicationId
|
||||
|
||||
withLedger { (client, ledger, actAs, controllerContext) =>
|
||||
// Trigger and external components could be defined here
|
||||
@ -287,7 +287,7 @@ So, in order to initialize a trigger process, we simply need to send it an initi
|
||||
|
||||
.. code-block:: scala
|
||||
override protected def triggerMultiProcessSimulation: Behavior[Unit] = {
|
||||
implicit def applicationId: ApiTypes.ApplicationId = this.applicationId
|
||||
implicit def applicationId: Option[Ref.ApplicationId] = this.applicationId
|
||||
|
||||
withLedger { (client, ledger, actAs, controllerContext) =>
|
||||
val breedingTrigger: Behavior[TriggerProcess.Message] = breedingFactory.create(Seq.empty)
|
||||
@ -304,7 +304,7 @@ Initializing trigger processes is a common use case, so an additional helper met
|
||||
|
||||
.. code-block:: scala
|
||||
override protected def triggerMultiProcessSimulation: Behavior[Unit] = {
|
||||
implicit def applicationId: ApiTypes.ApplicationId = this.applicationId
|
||||
implicit def applicationId: Option[Ref.ApplicationId] = this.applicationId
|
||||
|
||||
withLedger { (client, ledger, actAs, controllerContext) =>
|
||||
// Initialize the user state to be 0 (coded as an SValue) for the breeding trigger at create time
|
||||
@ -320,7 +320,7 @@ If a trigger fails at runtime, and we require the simulation to fail, then it is
|
||||
|
||||
.. code-block:: scala
|
||||
override protected def triggerMultiProcessSimulation: Behavior[Unit] = {
|
||||
implicit def applicationId: ApiTypes.ApplicationId = this.applicationId
|
||||
implicit def applicationId: Option[Ref.ApplicationId] = this.applicationId
|
||||
|
||||
withLedger { (client, ledger, actAs, controllerContext) =>
|
||||
// Initialize the user state to be 0 (coded as an SValue) for the breeding trigger at create time
|
||||
|
@ -5,7 +5,7 @@ package com.daml.lf.engine.trigger
|
||||
|
||||
import org.apache.pekko.actor.typed.Behavior
|
||||
import org.apache.pekko.actor.typed.scaladsl.Behaviors
|
||||
import com.daml.ledger.api.refinements.ApiTypes
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.engine.trigger.simulation.TriggerMultiProcessSimulation
|
||||
import com.daml.lf.engine.trigger.simulation.TriggerMultiProcessSimulation.TriggerSimulationConfig
|
||||
import com.daml.lf.engine.trigger.simulation.process.wrapper.TriggerTimer
|
||||
@ -33,7 +33,7 @@ class GenericACSGrowth(triggerName: String) extends TriggerMultiProcessSimulatio
|
||||
override protected val cantonFixtureDebugMode: Boolean = true
|
||||
|
||||
override protected def triggerMultiProcessSimulation: Behavior[Unit] = {
|
||||
implicit val applicationId: ApiTypes.ApplicationId = this.applicationId
|
||||
implicit val applicationId: Option[Ref.ApplicationId] = this.applicationId
|
||||
|
||||
withLedger { (client, ledger, actAs, controllerContext) =>
|
||||
val triggerFactory = triggerProcessFactory(client, ledger, s"Cats:$triggerName", actAs)
|
||||
|
@ -5,7 +5,7 @@ package com.daml.lf.engine.trigger
|
||||
|
||||
import org.apache.pekko.actor.typed.Behavior
|
||||
import org.apache.pekko.actor.typed.scaladsl.Behaviors
|
||||
import com.daml.ledger.api.refinements.ApiTypes
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.engine.trigger.simulation.TriggerMultiProcessSimulation
|
||||
import com.daml.lf.engine.trigger.simulation.TriggerMultiProcessSimulation.TriggerSimulationConfig
|
||||
import com.daml.lf.engine.trigger.simulation.process.wrapper.TriggerTimer
|
||||
@ -33,7 +33,7 @@ class GenericContention(delay: FiniteDuration) extends TriggerMultiProcessSimula
|
||||
override protected val cantonFixtureDebugMode: Boolean = true
|
||||
|
||||
override protected def triggerMultiProcessSimulation: Behavior[Unit] = {
|
||||
implicit val applicationId: ApiTypes.ApplicationId = this.applicationId
|
||||
implicit val applicationId: Option[Ref.ApplicationId] = this.applicationId
|
||||
|
||||
withLedger { (client, ledger, actAs, controllerContext) =>
|
||||
val breedingTriggerFactory =
|
||||
|
@ -21,6 +21,7 @@ da_scala_library(
|
||||
"src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/CompiledDar.scala",
|
||||
],
|
||||
scala_deps = [
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:org_scalactic_scalactic",
|
||||
"@maven//:org_scalatest_scalatest_core",
|
||||
@ -32,14 +33,15 @@ da_scala_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//bazel_tools/runfiles:scala_runfiles",
|
||||
"//canton:ledger_api_proto_scala",
|
||||
"//daml-lf/archive:daml_lf_archive_reader",
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/interpreter",
|
||||
"//daml-lf/language",
|
||||
"//daml-lf/transaction",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//ledger/ledger-api-domain",
|
||||
"//libs-scala/ledger-resources",
|
||||
"//libs-scala/ports",
|
||||
"//libs-scala/resources",
|
||||
@ -47,6 +49,7 @@ da_scala_library(
|
||||
"//libs-scala/testing-utils",
|
||||
"//test-common/canton/it-lib",
|
||||
"//triggers/runner:trigger-runner-lib",
|
||||
"@maven//:io_grpc_grpc_api",
|
||||
"@maven//:org_scalatest_scalatest_compatible",
|
||||
],
|
||||
)
|
||||
@ -133,6 +136,7 @@ da_scala_test_suite(
|
||||
],
|
||||
resources = ["//triggers/runner:src/main/resources/logback.xml"],
|
||||
scala_deps = [
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:org_scalacheck_scalacheck",
|
||||
"@maven//:org_scalatestplus_scalacheck_1_15",
|
||||
@ -142,15 +146,16 @@ da_scala_test_suite(
|
||||
deps = [
|
||||
":test-utils",
|
||||
"//bazel_tools/runfiles:scala_runfiles",
|
||||
"//canton:ledger_api_proto_scala",
|
||||
"//daml-lf/archive:daml_lf_archive_reader",
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/engine",
|
||||
"//daml-lf/interpreter",
|
||||
"//daml-lf/language",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger/ledger-api-auth",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//ledger/ledger-api-domain",
|
||||
"//libs-scala/caching",
|
||||
"//libs-scala/contextualized-logging",
|
||||
"//libs-scala/ledger-resources",
|
||||
@ -163,6 +168,11 @@ da_scala_test_suite(
|
||||
"//observability/tracing",
|
||||
"//test-common/canton/it-lib",
|
||||
"//triggers/runner:trigger-runner-lib",
|
||||
"@maven//:ch_qos_logback_logback_classic",
|
||||
"@maven//:ch_qos_logback_logback_core",
|
||||
"@maven//:io_grpc_grpc_api",
|
||||
"@maven//:io_grpc_grpc_netty",
|
||||
"@maven//:io_netty_netty_handler",
|
||||
],
|
||||
)
|
||||
|
||||
@ -178,6 +188,7 @@ da_scala_test_suite(
|
||||
],
|
||||
resources = ["//triggers/runner:src/main/resources/logback.xml"],
|
||||
scala_deps = [
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:org_scalacheck_scalacheck",
|
||||
"@maven//:org_scalatestplus_scalacheck_1_15",
|
||||
@ -187,15 +198,16 @@ da_scala_test_suite(
|
||||
deps = [
|
||||
":test-utils",
|
||||
"//bazel_tools/runfiles:scala_runfiles",
|
||||
"//canton:ledger_api_proto_scala",
|
||||
"//daml-lf/archive:daml_lf_archive_reader",
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/engine",
|
||||
"//daml-lf/interpreter",
|
||||
"//daml-lf/language",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger/ledger-api-auth",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//ledger/ledger-api-domain",
|
||||
"//libs-scala/caching",
|
||||
"//libs-scala/contextualized-logging",
|
||||
"//libs-scala/ledger-resources",
|
||||
@ -208,6 +220,11 @@ da_scala_test_suite(
|
||||
"//observability/tracing",
|
||||
"//test-common/canton/it-lib",
|
||||
"//triggers/runner:trigger-runner-lib",
|
||||
"@maven//:ch_qos_logback_logback_classic",
|
||||
"@maven//:ch_qos_logback_logback_core",
|
||||
"@maven//:io_grpc_grpc_api",
|
||||
"@maven//:io_grpc_grpc_netty",
|
||||
"@maven//:io_netty_netty_handler",
|
||||
],
|
||||
)
|
||||
|
||||
@ -219,8 +236,9 @@ da_scala_library(
|
||||
"src/test/scala/com/digitalasset/daml/lf/engine/trigger/simulation/TriggerRuleSimulationLib.scala",
|
||||
] + glob(["src/test/scala/com/digitalasset/daml/lf/engine/trigger/simulation/process/**/*.scala"]),
|
||||
scala_deps = [
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_actor_typed",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:org_scalacheck_scalacheck",
|
||||
"@maven//:org_scalactic_scalactic",
|
||||
"@maven//:org_scalatest_scalatest_core",
|
||||
@ -230,14 +248,14 @@ da_scala_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":test-utils",
|
||||
"//canton:ledger_api_proto_scala",
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/interpreter",
|
||||
"//daml-lf/language",
|
||||
"//daml-lf/parser",
|
||||
"//daml-lf/transaction",
|
||||
"//daml-script/converter",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//libs-scala/contextualized-logging",
|
||||
"//libs-scala/ledger-resources",
|
||||
@ -250,6 +268,7 @@ da_scala_library(
|
||||
"//observability/tracing",
|
||||
"//test-common/canton/it-lib",
|
||||
"//triggers/runner:trigger-runner-lib",
|
||||
"@maven//:io_grpc_grpc_api",
|
||||
"@maven//:org_scalatest_scalatest_compatible",
|
||||
],
|
||||
)
|
||||
@ -264,8 +283,9 @@ da_scala_test_suite(
|
||||
],
|
||||
resources = ["//triggers/runner:src/main/resources/logback.xml"],
|
||||
scala_deps = [
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:org_scalacheck_scalacheck",
|
||||
"@maven//:org_scalatestplus_scalacheck_1_15",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
@ -274,6 +294,8 @@ da_scala_test_suite(
|
||||
":test-utils",
|
||||
":trigger-simulation-lib",
|
||||
"//bazel_tools/runfiles:scala_runfiles",
|
||||
"//canton:ledger_api_proto_java",
|
||||
"//canton:ledger_api_proto_scala",
|
||||
"//daml-lf/archive:daml_lf_archive_reader",
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/engine",
|
||||
@ -281,10 +303,11 @@ da_scala_test_suite(
|
||||
"//daml-lf/language",
|
||||
"//daml-lf/transaction",
|
||||
"//daml-script/converter",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//language-support/java/bindings-rxjava",
|
||||
"//ledger/ledger-api-auth",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//ledger/ledger-api-domain",
|
||||
"//libs-scala/caching",
|
||||
"//libs-scala/contextualized-logging",
|
||||
"//libs-scala/ledger-resources",
|
||||
@ -298,6 +321,11 @@ da_scala_test_suite(
|
||||
"//observability/tracing",
|
||||
"//test-common/canton/it-lib",
|
||||
"//triggers/runner:trigger-runner-lib",
|
||||
"@maven//:ch_qos_logback_logback_classic",
|
||||
"@maven//:ch_qos_logback_logback_core",
|
||||
"@maven//:io_grpc_grpc_api",
|
||||
"@maven//:io_grpc_grpc_netty",
|
||||
"@maven//:io_netty_netty_handler",
|
||||
],
|
||||
)
|
||||
|
||||
@ -311,9 +339,10 @@ da_scala_test_suite(
|
||||
],
|
||||
resources = ["//triggers/runner:src/main/resources/logback.xml"],
|
||||
scala_deps = [
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_apache_pekko_pekko_actor",
|
||||
"@maven//:org_apache_pekko_pekko_actor_typed",
|
||||
"@maven//:org_apache_pekko_pekko_stream",
|
||||
"@maven//:io_spray_spray_json",
|
||||
"@maven//:org_scalacheck_scalacheck",
|
||||
"@maven//:org_scalatestplus_scalacheck_1_15",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
@ -322,6 +351,7 @@ da_scala_test_suite(
|
||||
":test-utils",
|
||||
":trigger-simulation-lib",
|
||||
"//bazel_tools/runfiles:scala_runfiles",
|
||||
"//canton:ledger_api_proto_scala",
|
||||
"//daml-lf/archive:daml_lf_archive_reader",
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/engine",
|
||||
@ -329,10 +359,10 @@ da_scala_test_suite(
|
||||
"//daml-lf/language",
|
||||
"//daml-lf/transaction",
|
||||
"//daml-script/converter",
|
||||
"//language-support/scala/bindings",
|
||||
"//language-support/scala/bindings-pekko",
|
||||
"//ledger/ledger-api-auth",
|
||||
"//ledger/ledger-api-client",
|
||||
"//ledger/ledger-api-common",
|
||||
"//ledger/ledger-api-domain",
|
||||
"//libs-scala/caching",
|
||||
"//libs-scala/contextualized-logging",
|
||||
"//libs-scala/ledger-resources",
|
||||
@ -346,5 +376,10 @@ da_scala_test_suite(
|
||||
"//observability/tracing",
|
||||
"//test-common/canton/it-lib",
|
||||
"//triggers/runner:trigger-runner-lib",
|
||||
"@maven//:ch_qos_logback_logback_classic",
|
||||
"@maven//:ch_qos_logback_logback_core",
|
||||
"@maven//:io_grpc_grpc_api",
|
||||
"@maven//:io_grpc_grpc_netty",
|
||||
"@maven//:io_netty_netty_handler",
|
||||
],
|
||||
)
|
||||
|
@ -5,9 +5,8 @@ package com.daml.lf.engine.trigger.simulation
|
||||
|
||||
import org.apache.pekko.actor.typed.{ActorRef, Behavior}
|
||||
import org.apache.pekko.actor.typed.scaladsl.Behaviors
|
||||
import com.daml.ledger.api.refinements.ApiTypes
|
||||
import com.daml.ledger.api.v1.event.CreatedEvent
|
||||
import com.daml.ledger.api.refinements.ApiTypes.Party
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.engine.trigger.simulation.TriggerMultiProcessSimulation.TriggerSimulationConfig
|
||||
import com.daml.lf.engine.trigger.simulation.process.ledger.{LedgerExternalAction, LedgerProcess}
|
||||
import com.daml.lf.engine.trigger.simulation.process.TriggerProcessFactory
|
||||
@ -15,7 +14,6 @@ import com.daml.lf.engine.trigger.test.AbstractTriggerTest
|
||||
import com.daml.lf.language.LanguageMajorVersion
|
||||
import com.daml.lf.speedy.SValue
|
||||
import org.scalacheck.Gen
|
||||
import scalaz.syntax.tag._
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
@ -37,7 +35,7 @@ class CatAndFoodTriggerSimulation(override val majorLanguageVersion: LanguageMaj
|
||||
override protected val cantonFixtureDebugMode: Boolean = true
|
||||
|
||||
override protected def triggerMultiProcessSimulation: Behavior[Unit] = {
|
||||
implicit def applicationId: ApiTypes.ApplicationId = this.applicationId
|
||||
implicit def applicationId: Option[Ref.ApplicationId] = this.applicationId
|
||||
Behaviors.setup { context =>
|
||||
val setup = for {
|
||||
client <- defaultLedgerClient()
|
||||
@ -67,7 +65,7 @@ class CatAndFoodTriggerSimulation(override val majorLanguageVersion: LanguageMaj
|
||||
}
|
||||
}
|
||||
|
||||
def workloadProcess(ledger: ActorRef[LedgerProcess.Message], owner: Party)(
|
||||
def workloadProcess(ledger: ActorRef[LedgerProcess.Message], owner: Ref.Party)(
|
||||
batchSize: Int,
|
||||
maxNumOfCats: Long,
|
||||
workloadFrequency: FiniteDuration,
|
||||
@ -90,11 +88,11 @@ class CatAndFoodTriggerSimulation(override val majorLanguageVersion: LanguageMaj
|
||||
.sample
|
||||
.foreach { case (isin, catCreateDelay, foodCreateDelay) =>
|
||||
timer.startSingleTimer(
|
||||
WorkloadProcess.CreateContract(createCat(owner.unwrap, isin)),
|
||||
WorkloadProcess.CreateContract(createCat(owner, isin)),
|
||||
catCreateDelay,
|
||||
)
|
||||
timer.startSingleTimer(
|
||||
WorkloadProcess.CreateContract(createFood(owner.unwrap, isin)),
|
||||
WorkloadProcess.CreateContract(createFood(owner, isin)),
|
||||
foodCreateDelay,
|
||||
)
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import com.daml.lf.speedy.SValue
|
||||
import org.scalatest.{Inside, TryValues}
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AsyncWordSpec
|
||||
import scalaz.syntax.tag._
|
||||
|
||||
import scala.concurrent.ExecutionContext
|
||||
|
||||
@ -63,17 +62,16 @@ class CatTriggerResourceUsageTest(override val majorLanguageVersion: LanguageMaj
|
||||
compiledPackages,
|
||||
timeProviderType,
|
||||
triggerRunnerConfiguration,
|
||||
party.unwrap,
|
||||
party,
|
||||
)
|
||||
result <- forAll(monotonicACS(party.unwrap, stateSizeGen), parallelism = parallelism) {
|
||||
acs =>
|
||||
for {
|
||||
(submissions, metrics, state) <- simulator.initialStateLambda(acs)
|
||||
} yield {
|
||||
withClue((acs, state, submissions, metrics)) {
|
||||
acs.size should be(2 * submissions.size)
|
||||
}
|
||||
result <- forAll(monotonicACS(party, stateSizeGen), parallelism = parallelism) { acs =>
|
||||
for {
|
||||
(submissions, metrics, state) <- simulator.initialStateLambda(acs)
|
||||
} yield {
|
||||
withClue((acs, state, submissions, metrics)) {
|
||||
acs.size should be(2 * submissions.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
} yield result
|
||||
}
|
||||
@ -90,28 +88,27 @@ class CatTriggerResourceUsageTest(override val majorLanguageVersion: LanguageMaj
|
||||
compiledPackages,
|
||||
timeProviderType,
|
||||
triggerRunnerConfiguration,
|
||||
party.unwrap,
|
||||
party,
|
||||
)
|
||||
converter = new Converter(compiledPackages, trigger)
|
||||
userState = SValue.SInt64(400L)
|
||||
msg = TriggerMsg.Heartbeat
|
||||
result <- forAll(monotonicACS(party.unwrap, stateSizeGen), parallelism = parallelism) {
|
||||
acs =>
|
||||
val startState = converter
|
||||
.fromTriggerUpdateState(
|
||||
acs,
|
||||
userState,
|
||||
parties = TriggerParties(party, Set.empty),
|
||||
triggerConfig = triggerRunnerConfiguration,
|
||||
)
|
||||
result <- forAll(monotonicACS(party, stateSizeGen), parallelism = parallelism) { acs =>
|
||||
val startState = converter
|
||||
.fromTriggerUpdateState(
|
||||
acs,
|
||||
userState,
|
||||
parties = TriggerParties(party, Set.empty),
|
||||
triggerConfig = triggerRunnerConfiguration,
|
||||
)
|
||||
|
||||
for {
|
||||
(submissions, metrics, endState) <- simulator.updateStateLambda(startState, msg)
|
||||
} yield {
|
||||
withClue((startState, msg, endState, submissions, metrics)) {
|
||||
acs.size should be(2 * submissions.size)
|
||||
}
|
||||
for {
|
||||
(submissions, metrics, endState) <- simulator.updateStateLambda(startState, msg)
|
||||
} yield {
|
||||
withClue((startState, msg, endState, submissions, metrics)) {
|
||||
acs.size should be(2 * submissions.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
} yield result
|
||||
}
|
||||
@ -133,7 +130,7 @@ class CatTriggerResourceUsageTest(override val majorLanguageVersion: LanguageMaj
|
||||
compiledPackages,
|
||||
timeProviderType,
|
||||
triggerRunnerConfiguration,
|
||||
party.unwrap,
|
||||
party,
|
||||
)
|
||||
converter = new Converter(compiledPackages, trigger)
|
||||
acs = Seq.empty
|
||||
@ -173,11 +170,11 @@ class CatTriggerResourceUsageTest(override val majorLanguageVersion: LanguageMaj
|
||||
compiledPackages,
|
||||
timeProviderType,
|
||||
triggerRunnerConfiguration,
|
||||
party.unwrap,
|
||||
party,
|
||||
)
|
||||
converter = new Converter(compiledPackages, trigger)
|
||||
catPopulation = 10L
|
||||
acs = acsGen(party.unwrap, catPopulation)
|
||||
acs = acsGen(party, catPopulation)
|
||||
userState = SValue.SInt64(catPopulation)
|
||||
startState = converter
|
||||
.fromTriggerUpdateState(
|
||||
|
@ -12,8 +12,8 @@ import org.apache.pekko.actor.typed.{
|
||||
SupervisorStrategy,
|
||||
}
|
||||
import org.apache.pekko.actor.typed.scaladsl.{ActorContext, Behaviors}
|
||||
import com.daml.ledger.api.refinements.ApiTypes
|
||||
import com.daml.ledger.client.LedgerClient
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.engine.trigger.simulation.process.TriggerProcessFactory
|
||||
import com.daml.lf.engine.trigger.simulation.process.ledger.LedgerProcess
|
||||
import com.daml.lf.engine.trigger.test.AbstractTriggerTest
|
||||
@ -105,7 +105,7 @@ abstract class TriggerMultiProcessSimulation extends AsyncWordSpec with Abstract
|
||||
client: LedgerClient,
|
||||
ledger: ActorRef[LedgerProcess.Message],
|
||||
name: String,
|
||||
actAs: ApiTypes.Party,
|
||||
actAs: Ref.Party,
|
||||
): TriggerProcessFactory = {
|
||||
new TriggerProcessFactory(
|
||||
client,
|
||||
@ -124,10 +124,10 @@ abstract class TriggerMultiProcessSimulation extends AsyncWordSpec with Abstract
|
||||
spawnTriggers: (
|
||||
LedgerClient,
|
||||
ActorRef[LedgerProcess.Message],
|
||||
ApiTypes.Party,
|
||||
Ref.Party,
|
||||
ActorContext[Unit],
|
||||
) => Behavior[Unit]
|
||||
)(implicit applicationId: ApiTypes.ApplicationId): Behavior[Unit] = {
|
||||
)(implicit applicationId: Option[Ref.ApplicationId]): Behavior[Unit] = {
|
||||
Behaviors.setup { controllerContext =>
|
||||
val setup = for {
|
||||
client <- defaultLedgerClient()
|
||||
|
@ -6,12 +6,12 @@ package simulation
|
||||
|
||||
import org.apache.pekko.stream.{FlowShape, KillSwitches, Materializer, RestartSettings, SourceShape}
|
||||
import org.apache.pekko.stream.scaladsl.{Flow, GraphDSL, Keep, RestartSource, Sink, Source}
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId, Party}
|
||||
import com.daml.ledger.api.v1.command_submission_service.SubmitRequest
|
||||
import com.daml.ledger.api.v1.event.CreatedEvent
|
||||
import com.daml.ledger.client.LedgerClient
|
||||
import com.daml.lf.PureCompiledPackages
|
||||
import com.daml.lf.data.FrontStack
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref.{Identifier, PackageId, QualifiedName}
|
||||
import com.daml.lf.data.Time.Timestamp
|
||||
import com.daml.lf.engine.trigger.Runner.{TriggerContext, TriggerContextualFlow}
|
||||
@ -28,8 +28,6 @@ import com.daml.util.Ctx
|
||||
import org.scalacheck.Gen
|
||||
import org.scalatest.Assertion
|
||||
import org.scalatest.Assertions.succeed
|
||||
import scalaz.Tag
|
||||
import scalaz.syntax.tag._
|
||||
|
||||
import java.util.UUID
|
||||
import scala.collection.mutable
|
||||
@ -710,7 +708,7 @@ final class TriggerRuleSimulationLib private[simulation] (
|
||||
triggerConfig: TriggerRunnerConfig,
|
||||
client: LedgerClient,
|
||||
timeProviderType: TimeProviderType,
|
||||
applicationId: ApplicationId,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
triggerParties: TriggerParties,
|
||||
)(implicit materializer: Materializer) {
|
||||
|
||||
@ -725,10 +723,10 @@ final class TriggerRuleSimulationLib private[simulation] (
|
||||
TriggerLogContext.newRootSpan(
|
||||
"simulation",
|
||||
"id" -> triggerId.toString,
|
||||
"applicationId" -> applicationId.unwrap,
|
||||
"applicationId" -> applicationId.getOrElse("").toString,
|
||||
"definition" -> triggerId.toString,
|
||||
"readAs" -> Tag.unsubst(triggerParties.readAs),
|
||||
"actAs" -> Tag.unwrap(triggerParties.actAs),
|
||||
"readAs" -> triggerParties.readAs,
|
||||
"actAs" -> triggerParties.actAs,
|
||||
)(identity)
|
||||
)
|
||||
.toOption
|
||||
@ -752,10 +750,10 @@ final class TriggerRuleSimulationLib private[simulation] (
|
||||
"simulation",
|
||||
logObserver,
|
||||
"id" -> triggerId.toString,
|
||||
"applicationId" -> applicationId.unwrap,
|
||||
"applicationId" -> applicationId.getOrElse("").toString,
|
||||
"definition" -> triggerId.toString,
|
||||
"readAs" -> Tag.unsubst(triggerParties.readAs),
|
||||
"actAs" -> Tag.unwrap(triggerParties.actAs),
|
||||
"readAs" -> triggerParties.readAs,
|
||||
"actAs" -> triggerParties.actAs,
|
||||
)(identity)
|
||||
|
||||
private[simulation] val runner = Runner(
|
||||
@ -781,7 +779,7 @@ final class TriggerRuleSimulationLib private[simulation] (
|
||||
|
||||
val clientTime: Timestamp =
|
||||
Timestamp.assertFromInstant(
|
||||
Runner.getTimeProvider(RunnerConfig.DefaultTimeProviderType).getCurrentTime
|
||||
Runner.getCurrentTime(RunnerConfig.DefaultTimeProviderType)
|
||||
)
|
||||
val killSwitch = KillSwitches.shared("init-state-simulation")
|
||||
val initialState = gb add context.runner.runInitialState(clientTime, killSwitch)(acs)
|
||||
@ -900,12 +898,12 @@ object TriggerRuleSimulationLib {
|
||||
client: LedgerClient,
|
||||
name: QualifiedName,
|
||||
packageId: PackageId,
|
||||
applicationId: ApplicationId,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
compiledPackages: PureCompiledPackages,
|
||||
timeProviderType: TimeProviderType,
|
||||
triggerConfig: TriggerRunnerConfig,
|
||||
actAs: String,
|
||||
readAs: Set[String] = Set.empty,
|
||||
actAs: Ref.Party,
|
||||
readAs: Set[Ref.Party] = Set.empty,
|
||||
)(implicit materializer: Materializer): (TriggerDefinition, TriggerRuleSimulationLib) = {
|
||||
val triggerId = Identifier(packageId, name)
|
||||
val simulator = new TriggerRuleSimulationLib(
|
||||
@ -916,8 +914,8 @@ object TriggerRuleSimulationLib {
|
||||
timeProviderType,
|
||||
applicationId,
|
||||
TriggerParties(
|
||||
actAs = Party(actAs),
|
||||
readAs = Party.subst(readAs),
|
||||
actAs = actAs,
|
||||
readAs = readAs,
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -19,7 +19,6 @@ import org.scalacheck.Gen
|
||||
import org.scalatest.{Inside, TryValues}
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AsyncWordSpec
|
||||
import scalaz.syntax.tag._
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
@ -56,7 +55,7 @@ class TriggerRuleSimulationLibTest(override val majorLanguageVersion: LanguageMa
|
||||
compiledPackages,
|
||||
timeProviderType,
|
||||
triggerRunnerConfiguration,
|
||||
party.unwrap,
|
||||
party,
|
||||
)
|
||||
result <- forAll(initState) { acs =>
|
||||
for {
|
||||
@ -105,7 +104,7 @@ class TriggerRuleSimulationLibTest(override val majorLanguageVersion: LanguageMa
|
||||
compiledPackages,
|
||||
timeProviderType,
|
||||
triggerRunnerConfiguration,
|
||||
party.unwrap,
|
||||
party,
|
||||
)
|
||||
converter = new Converter(compiledPackages, trigger)
|
||||
result <- forAll(updateState) { case (acs, userState, inFlightCmds, msg) =>
|
||||
|
@ -7,8 +7,8 @@ package ledger
|
||||
import org.apache.pekko.actor.typed.Behavior
|
||||
import org.apache.pekko.actor.typed.scaladsl.Behaviors
|
||||
import org.apache.pekko.stream.Materializer
|
||||
import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
|
||||
import com.daml.ledger.client.LedgerClient
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.engine.trigger.simulation.ReportingProcess
|
||||
import com.daml.lf.engine.trigger.simulation.TriggerMultiProcessSimulation.TriggerSimulationConfig
|
||||
|
||||
@ -28,7 +28,7 @@ object LedgerProcess {
|
||||
def create(client: LedgerClient)(implicit
|
||||
materializer: Materializer,
|
||||
config: TriggerSimulationConfig,
|
||||
applicationId: ApplicationId,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
): Behavior[Message] = {
|
||||
Behaviors.setup { context =>
|
||||
val report = context.spawn(ReportingProcess.create(context.self), "reporting")
|
||||
|
@ -8,7 +8,6 @@ import org.apache.pekko.actor.typed.{ActorRef, Behavior}
|
||||
import org.apache.pekko.actor.typed.scaladsl.Behaviors
|
||||
import org.apache.pekko.stream.Materializer
|
||||
import org.apache.pekko.util.Timeout
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId, Party}
|
||||
import com.daml.ledger.api.v1.event.CreatedEvent
|
||||
import com.daml.ledger.api.v1.transaction_filter.TransactionFilter
|
||||
import com.daml.ledger.client.LedgerClient
|
||||
@ -40,7 +39,6 @@ import java.util.UUID
|
||||
import scala.collection.immutable.TreeMap
|
||||
import scala.concurrent.Await
|
||||
import scala.util.{Failure, Success}
|
||||
import scalaz.syntax.tag._
|
||||
|
||||
import scala.jdk.CollectionConverters._
|
||||
|
||||
@ -62,12 +60,12 @@ final class TriggerProcessFactory private[simulation] (
|
||||
ledger: ActorRef[LedgerProcess.Message],
|
||||
name: String,
|
||||
packageId: PackageId,
|
||||
applicationId: ApplicationId,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
compiledPackages: PureCompiledPackages,
|
||||
timeProviderType: TimeProviderType,
|
||||
triggerConfig: TriggerRunnerConfig,
|
||||
actAs: Party,
|
||||
readAs: Set[Party] = Set.empty,
|
||||
actAs: Ref.Party,
|
||||
readAs: Set[Ref.Party] = Set.empty,
|
||||
)(implicit materializer: Materializer) {
|
||||
|
||||
import TriggerProcess._
|
||||
@ -118,7 +116,7 @@ final class TriggerProcessFactory private[simulation] (
|
||||
)
|
||||
val transactionFilter =
|
||||
TransactionFilter(
|
||||
triggerParties.readers.map(p => (p.unwrap, simulator.trigger.filters)).toMap
|
||||
triggerParties.readers.map(p => (p, simulator.trigger.filters)).toMap
|
||||
)
|
||||
|
||||
implicit val ledgerResponseTimeout: Timeout = Timeout(config.ledgerRegistrationTimeout)
|
||||
|
@ -7,10 +7,10 @@ package ledger
|
||||
import org.apache.pekko.actor.typed.Behavior
|
||||
import org.apache.pekko.actor.typed.scaladsl.Behaviors
|
||||
import org.apache.pekko.stream.Materializer
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId, Party}
|
||||
import com.daml.ledger.api.v1.commands.CreateCommand
|
||||
import com.daml.ledger.api.v1.event.{ArchivedEvent, CreatedEvent}
|
||||
import com.daml.ledger.client.LedgerClient
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.engine.trigger.simulation.TriggerMultiProcessSimulation.TriggerSimulationConfig
|
||||
import com.daml.lf.engine.trigger.test.AbstractTriggerTest
|
||||
import com.daml.scalautil.Statement.discard
|
||||
@ -21,7 +21,7 @@ import scala.util.control.NonFatal
|
||||
final class LedgerExternalAction(client: LedgerClient)(implicit
|
||||
materializer: Materializer,
|
||||
config: TriggerSimulationConfig,
|
||||
applicationId: ApplicationId,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
) {
|
||||
|
||||
import LedgerExternalAction._
|
||||
@ -80,11 +80,11 @@ object LedgerExternalAction {
|
||||
// Used by LedgerProcess
|
||||
final case class CreateContract(
|
||||
create: CreatedEvent,
|
||||
party: Party,
|
||||
party: Ref.Party,
|
||||
) extends Message
|
||||
// Used by LedgerProcess
|
||||
final case class ArchiveContract(
|
||||
archive: ArchivedEvent,
|
||||
party: Party,
|
||||
party: Ref.Party,
|
||||
) extends Message
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import org.apache.pekko.actor.typed.scaladsl.Behaviors
|
||||
import org.apache.pekko.actor.typed.{ActorRef, Behavior}
|
||||
import org.apache.pekko.stream.Materializer
|
||||
import org.apache.pekko.stream.scaladsl.Sink
|
||||
import com.daml.ledger.api.refinements.ApiTypes.Party
|
||||
import com.daml.ledger.api.v1.event.Event
|
||||
import com.daml.ledger.api.v1.ledger_offset.LedgerOffset
|
||||
import com.daml.ledger.api.v1.transaction_filter.TransactionFilter
|
||||
@ -24,7 +23,6 @@ import com.daml.lf.engine.trigger.simulation.TriggerMultiProcessSimulation.{
|
||||
}
|
||||
import com.daml.lf.engine.trigger.simulation.process.report.{ACSReporting, SubmissionReporting}
|
||||
import com.daml.lf.engine.trigger.{Converter, TriggerMsg}
|
||||
import scalaz.syntax.tag._
|
||||
|
||||
import java.util.UUID
|
||||
import scala.collection.concurrent.TrieMap
|
||||
@ -86,7 +84,7 @@ final class LedgerRegistration(client: LedgerClient)(implicit
|
||||
)
|
||||
}
|
||||
client.commandClient
|
||||
.completionSource(Seq(actAs.unwrap), offset)
|
||||
.completionSource(Seq(actAs), offset)
|
||||
.collect { case CompletionElement(completion, _) =>
|
||||
val timestamp = System.currentTimeMillis()
|
||||
trigger ! TriggerProcess.MessageWrapper(TriggerMsg.Completion(completion))
|
||||
@ -169,7 +167,7 @@ object LedgerRegistration {
|
||||
triggerId: UUID,
|
||||
triggerDefRef: Ref.DefinitionRef,
|
||||
trigger: ActorRef[TriggerProcess.Message],
|
||||
actAs: Party,
|
||||
actAs: Ref.Party,
|
||||
filter: TransactionFilter,
|
||||
replyTo: ActorRef[LedgerApi],
|
||||
) extends Message
|
||||
|
@ -4,11 +4,11 @@
|
||||
package com.daml.lf.engine.trigger.test
|
||||
|
||||
import org.apache.pekko.stream.scaladsl.Flow
|
||||
import com.daml.lf.data.Ref._
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref.{ApplicationId => _, Party => _, _}
|
||||
import com.daml.lf.speedy.SValue
|
||||
import com.daml.lf.speedy.SValue._
|
||||
import com.daml.lf.value.Value.ContractId
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{Party => ApiParty}
|
||||
import com.daml.ledger.api.v1.commands.CreateCommand
|
||||
import com.daml.ledger.api.v1.{value => LedgerApi}
|
||||
import com.daml.lf.engine.trigger.Runner.TriggerContext
|
||||
@ -17,7 +17,6 @@ import io.grpc.{Status => grpcStatus, StatusRuntimeException}
|
||||
import org.scalatest._
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AsyncWordSpec
|
||||
import scalaz.syntax.tag._
|
||||
import scalaz.syntax.traverse._
|
||||
|
||||
import scala.jdk.CollectionConverters._
|
||||
@ -67,12 +66,12 @@ abstract class AbstractFuncTests
|
||||
"AcsTests" should {
|
||||
val assetId = LedgerApi.Identifier(packageId, "ACS", "Asset")
|
||||
val assetMirrorId = LedgerApi.Identifier(packageId, "ACS", "AssetMirror")
|
||||
def asset(party: ApiParty): CreateCommand =
|
||||
def asset(party: Ref.Party): CreateCommand =
|
||||
CreateCommand(
|
||||
templateId = Some(assetId),
|
||||
createArguments = Some(
|
||||
LedgerApi.Record(fields =
|
||||
Seq(LedgerApi.RecordField("issuer", Some(LedgerApi.Value().withParty(party.unwrap))))
|
||||
Seq(LedgerApi.RecordField("issuer", Some(LedgerApi.Value().withParty(party))))
|
||||
)
|
||||
),
|
||||
)
|
||||
@ -126,7 +125,7 @@ abstract class AbstractFuncTests
|
||||
for {
|
||||
client <- defaultLedgerClient()
|
||||
party <- allocateParty(client)
|
||||
runner = getRunner(client, QualifiedName.assertFromString("ACS:test"), party)
|
||||
runner = getRunner(client, Ref.QualifiedName.assertFromString("ACS:test"), party)
|
||||
(acs, offset) <- runner.queryACS()
|
||||
|
||||
// 2 for the creates from the test
|
||||
@ -155,7 +154,7 @@ abstract class AbstractFuncTests
|
||||
for {
|
||||
client <- defaultLedgerClient()
|
||||
party <- allocateParty(client)
|
||||
runner = getRunner(client, QualifiedName.assertFromString("ACS:test"), party)
|
||||
runner = getRunner(client, Ref.QualifiedName.assertFromString("ACS:test"), party)
|
||||
(acs, offset) <- runner.queryACS()
|
||||
|
||||
// 2 for the creates from the test
|
||||
@ -185,34 +184,34 @@ abstract class AbstractFuncTests
|
||||
}
|
||||
|
||||
"CopyTests" should {
|
||||
val triggerId = QualifiedName.assertFromString("CopyTrigger:copyTrigger")
|
||||
val triggerId = Ref.QualifiedName.assertFromString("CopyTrigger:copyTrigger")
|
||||
val originalId = LedgerApi.Identifier(packageId, "CopyTrigger", "Original")
|
||||
val copyId = LedgerApi.Identifier(packageId, "CopyTrigger", "Copy")
|
||||
val subscriberId = LedgerApi.Identifier(packageId, "CopyTrigger", "Subscriber")
|
||||
def original(owner: ApiParty, name: String): CreateCommand =
|
||||
def original(owner: Ref.Party, name: String): CreateCommand =
|
||||
CreateCommand(
|
||||
templateId = Some(originalId),
|
||||
createArguments = Some(
|
||||
LedgerApi.Record(fields =
|
||||
Seq(
|
||||
LedgerApi.RecordField("owner", Some(LedgerApi.Value().withParty(owner.unwrap))),
|
||||
LedgerApi.RecordField("owner", Some(LedgerApi.Value().withParty(owner))),
|
||||
LedgerApi.RecordField("name", Some(LedgerApi.Value().withText(name))),
|
||||
LedgerApi.RecordField("textdata", Some(LedgerApi.Value().withText(""))),
|
||||
)
|
||||
)
|
||||
),
|
||||
)
|
||||
def subscriber(subscriber: ApiParty, subscribedTo: ApiParty): CreateCommand =
|
||||
def subscriber(subscriber: Ref.Party, subscribedTo: Ref.Party): CreateCommand =
|
||||
CreateCommand(
|
||||
templateId = Some(subscriberId),
|
||||
createArguments = Some(
|
||||
LedgerApi.Record(fields =
|
||||
Seq(
|
||||
LedgerApi
|
||||
.RecordField("subscriber", Some(LedgerApi.Value().withParty(subscriber.unwrap))),
|
||||
.RecordField("subscriber", Some(LedgerApi.Value().withParty(subscriber))),
|
||||
LedgerApi.RecordField(
|
||||
"subscribedTo",
|
||||
Some(LedgerApi.Value().withParty(subscribedTo.unwrap)),
|
||||
Some(LedgerApi.Value().withParty(subscribedTo)),
|
||||
),
|
||||
)
|
||||
)
|
||||
@ -292,7 +291,7 @@ abstract class AbstractFuncTests
|
||||
}
|
||||
|
||||
"RetryTests" should {
|
||||
val triggerId = QualifiedName.assertFromString("Retry:retryTrigger")
|
||||
val triggerId = Ref.QualifiedName.assertFromString("Retry:retryTrigger")
|
||||
val tId = LedgerApi.Identifier(packageId, "Retry", "T")
|
||||
val doneId = LedgerApi.Identifier(packageId, "Retry", "Done")
|
||||
|
||||
@ -317,7 +316,7 @@ abstract class AbstractFuncTests
|
||||
}
|
||||
|
||||
"ExerciseByKeyTest" should {
|
||||
val triggerId = QualifiedName.assertFromString("ExerciseByKey:exerciseByKeyTrigger")
|
||||
val triggerId = Ref.QualifiedName.assertFromString("ExerciseByKey:exerciseByKeyTrigger")
|
||||
val tId = LedgerApi.Identifier(packageId, "ExerciseByKey", "T")
|
||||
val tPrimeId = LedgerApi.Identifier(packageId, "ExerciseByKey", "T_")
|
||||
|
||||
@ -341,7 +340,8 @@ abstract class AbstractFuncTests
|
||||
}
|
||||
|
||||
"CreateAndExercise" should {
|
||||
val triggerId = QualifiedName.assertFromString("CreateAndExercise:createAndExerciseTrigger")
|
||||
val triggerId =
|
||||
Ref.QualifiedName.assertFromString("CreateAndExercise:createAndExerciseTrigger")
|
||||
val tId = LedgerApi.Identifier(packageId, "CreateAndExercise", "T")
|
||||
val uId = LedgerApi.Identifier(packageId, "CreateAndExercise", "U")
|
||||
|
||||
@ -364,7 +364,7 @@ abstract class AbstractFuncTests
|
||||
|
||||
"MaxMessageSizeTests" should {
|
||||
val triggerId =
|
||||
QualifiedName.assertFromString("MaxInboundMessageTest:maxInboundMessageSizeTrigger")
|
||||
Ref.QualifiedName.assertFromString("MaxInboundMessageTest:maxInboundMessageSizeTrigger")
|
||||
|
||||
"fail" in {
|
||||
for {
|
||||
@ -390,7 +390,7 @@ abstract class AbstractFuncTests
|
||||
}
|
||||
|
||||
"NumericTests" should {
|
||||
val triggerId = QualifiedName.assertFromString("Numeric:test")
|
||||
val triggerId = Ref.QualifiedName.assertFromString("Numeric:test")
|
||||
val tId = LedgerApi.Identifier(packageId, "Numeric", "T")
|
||||
|
||||
"numeric" in {
|
||||
@ -413,7 +413,7 @@ abstract class AbstractFuncTests
|
||||
}
|
||||
|
||||
"CommandIdTests" should {
|
||||
val triggerId = QualifiedName.assertFromString("CommandId:test")
|
||||
val triggerId = Ref.QualifiedName.assertFromString("CommandId:test")
|
||||
|
||||
"command-id" in {
|
||||
for {
|
||||
@ -441,7 +441,7 @@ abstract class AbstractFuncTests
|
||||
}
|
||||
|
||||
"PendingTests" should {
|
||||
val triggerId = QualifiedName.assertFromString("PendingSet:booTrigger")
|
||||
val triggerId = Ref.QualifiedName.assertFromString("PendingSet:booTrigger")
|
||||
val fooId = LedgerApi.Identifier(packageId, "PendingSet", "Foo")
|
||||
val booId = LedgerApi.Identifier(packageId, "PendingSet", "Boo")
|
||||
val doneId = LedgerApi.Identifier(packageId, "PendingSet", "Done")
|
||||
@ -472,24 +472,22 @@ abstract class AbstractFuncTests
|
||||
val oneId = LedgerApi.Identifier(packageId, "TemplateIdFilter", "One")
|
||||
val twoId = LedgerApi.Identifier(packageId, "TemplateIdFilter", "Two")
|
||||
|
||||
def one(party: ApiParty): CreateCommand =
|
||||
def one(party: Ref.Party): CreateCommand =
|
||||
CreateCommand(
|
||||
templateId = Some(oneId),
|
||||
createArguments = Some(
|
||||
LedgerApi.Record(
|
||||
fields =
|
||||
Seq(LedgerApi.RecordField("p", Some(LedgerApi.Value().withParty(party.unwrap))))
|
||||
fields = Seq(LedgerApi.RecordField("p", Some(LedgerApi.Value().withParty(party))))
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
def two(party: ApiParty): CreateCommand =
|
||||
def two(party: Ref.Party): CreateCommand =
|
||||
CreateCommand(
|
||||
templateId = Some(twoId),
|
||||
createArguments = Some(
|
||||
LedgerApi.Record(
|
||||
fields =
|
||||
Seq(LedgerApi.RecordField("p", Some(LedgerApi.Value().withParty(party.unwrap))))
|
||||
fields = Seq(LedgerApi.RecordField("p", Some(LedgerApi.Value().withParty(party))))
|
||||
)
|
||||
),
|
||||
)
|
||||
@ -592,12 +590,12 @@ abstract class AbstractFuncTests
|
||||
|
||||
"readAs" should {
|
||||
val visibleToPublicId = LedgerApi.Identifier(packageId, "ReadAs", "VisibleToPublic")
|
||||
def visibleToPublic(party: ApiParty): CreateCommand =
|
||||
def visibleToPublic(party: Ref.Party): CreateCommand =
|
||||
CreateCommand(
|
||||
templateId = Some(visibleToPublicId),
|
||||
createArguments = Some(
|
||||
LedgerApi.Record(fields =
|
||||
Seq(LedgerApi.RecordField("public", Some(LedgerApi.Value().withParty(party.unwrap))))
|
||||
Seq(LedgerApi.RecordField("public", Some(LedgerApi.Value().withParty(party))))
|
||||
)
|
||||
),
|
||||
)
|
||||
@ -645,7 +643,7 @@ abstract class AbstractFuncTests
|
||||
inside(toHighLevelResult(result).state) { case SRecord(_, _, values) =>
|
||||
// Check that both updateState and rule were executed.
|
||||
values.asScala shouldBe Seq[SValue](
|
||||
SParty(Party.assertFromString(party.unwrap)),
|
||||
SParty(party),
|
||||
SBool(true),
|
||||
SBool(true),
|
||||
)
|
||||
|
@ -12,7 +12,6 @@ import java.util.UUID
|
||||
import org.apache.pekko.stream.scaladsl.{Sink, Source}
|
||||
import com.daml.bazeltools.BazelRunfiles
|
||||
import com.daml.integrationtest.CantonFixture
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId, Party}
|
||||
import com.daml.ledger.api.v1.command_service.SubmitAndWaitRequest
|
||||
import com.daml.ledger.api.v1.commands.{Command, CreateCommand, ExerciseCommand, _}
|
||||
import com.daml.ledger.api.v1.event.CreatedEvent
|
||||
@ -25,7 +24,8 @@ import com.daml.ledger.client.configuration.{
|
||||
LedgerClientConfiguration,
|
||||
LedgerIdRequirement,
|
||||
}
|
||||
import com.daml.lf.data.Ref._
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref.{ApplicationId => _, Party => _, _}
|
||||
import com.daml.lf.engine.trigger.TriggerRunnerConfig.DefaultTriggerRunnerConfig
|
||||
import com.daml.lf.language.LanguageMajorVersion
|
||||
import com.daml.lf.speedy.SValue
|
||||
@ -49,7 +49,7 @@ trait AbstractTriggerTest extends CantonFixture {
|
||||
// TODO(#17366): remove once 2.0 is introduced
|
||||
override protected lazy val devMode: Boolean = (majorLanguageVersion == LanguageMajorVersion.V2)
|
||||
|
||||
implicit override protected lazy val applicationId: ApplicationId =
|
||||
implicit override protected lazy val applicationId: Option[Ref.ApplicationId] =
|
||||
RunnerConfig.DefaultApplicationId
|
||||
|
||||
protected def toHighLevelResult(s: SValue) = s match {
|
||||
@ -67,7 +67,7 @@ trait AbstractTriggerTest extends CantonFixture {
|
||||
|
||||
protected def ledgerClientConfiguration: LedgerClientConfiguration =
|
||||
LedgerClientConfiguration(
|
||||
applicationId = applicationId.unwrap,
|
||||
applicationId = applicationId.getOrElse(""),
|
||||
ledgerIdRequirement = LedgerIdRequirement.none,
|
||||
commandClient = CommandClientConfiguration.default,
|
||||
token = None,
|
||||
@ -85,8 +85,8 @@ trait AbstractTriggerTest extends CantonFixture {
|
||||
protected def getRunner(
|
||||
client: LedgerClient,
|
||||
name: QualifiedName,
|
||||
party: Party,
|
||||
readAs: Set[Party] = Set.empty,
|
||||
party: Ref.Party,
|
||||
readAs: Set[Ref.Party] = Set.empty,
|
||||
): Runner = {
|
||||
val triggerId = Identifier(packageId, name)
|
||||
|
||||
@ -129,16 +129,14 @@ object AbstractTriggerTest {
|
||||
client: LedgerClient,
|
||||
hint: Option[String] = None,
|
||||
displayName: Option[String] = None,
|
||||
)(implicit ec: ExecutionContext): Future[Party] =
|
||||
client.partyManagementClient
|
||||
.allocateParty(hint, displayName)
|
||||
.map(details => Party(details.party: String))
|
||||
)(implicit ec: ExecutionContext): Future[Ref.Party] =
|
||||
client.partyManagementClient.allocateParty(hint, displayName).map(_.party)
|
||||
|
||||
def queryACS(client: LedgerClient, party: Party)(implicit
|
||||
def queryACS(client: LedgerClient, party: Ref.Party)(implicit
|
||||
ec: ExecutionContext,
|
||||
materializer: Materializer,
|
||||
): Future[Map[LedgerApi.Identifier, Seq[LedgerApi.Record]]] = {
|
||||
val filter = TransactionFilter(List((party.unwrap, Filters.defaultInstance)).toMap)
|
||||
val filter = TransactionFilter(List((party, Filters.defaultInstance)).toMap)
|
||||
val contractsF: Future[Seq[CreatedEvent]] = client.activeContractSetClient
|
||||
.getActiveContracts(filter, verbose = true)
|
||||
.runWith(Sink.seq)
|
||||
@ -153,18 +151,18 @@ object AbstractTriggerTest {
|
||||
)
|
||||
}
|
||||
|
||||
def create(client: LedgerClient, party: Party, cmd: CreateCommand)(implicit
|
||||
def create(client: LedgerClient, party: Ref.Party, cmd: CreateCommand)(implicit
|
||||
ec: ExecutionContext,
|
||||
applicationId: ApplicationId,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
): Future[String] = {
|
||||
val commands = Seq(Command().withCreate(cmd))
|
||||
val request = SubmitAndWaitRequest(
|
||||
Some(
|
||||
Commands(
|
||||
party = party.unwrap,
|
||||
party = party,
|
||||
commands = commands,
|
||||
ledgerId = client.ledgerId.unwrap,
|
||||
applicationId = applicationId.unwrap,
|
||||
applicationId = applicationId.getOrElse(""),
|
||||
commandId = UUID.randomUUID.toString,
|
||||
)
|
||||
)
|
||||
@ -176,14 +174,14 @@ object AbstractTriggerTest {
|
||||
|
||||
def create(
|
||||
client: LedgerClient,
|
||||
party: Party,
|
||||
party: Ref.Party,
|
||||
commands: Seq[CreateCommand],
|
||||
elements: Int = 50,
|
||||
per: FiniteDuration = 1.second,
|
||||
)(implicit
|
||||
ec: ExecutionContext,
|
||||
materializer: Materializer,
|
||||
applicationId: ApplicationId,
|
||||
applicationId: Option[Ref.ApplicationId],
|
||||
): Future[Unit] = {
|
||||
Source(commands)
|
||||
.mapAsync(8) { cmd =>
|
||||
@ -196,12 +194,12 @@ object AbstractTriggerTest {
|
||||
|
||||
def exercise(
|
||||
client: LedgerClient,
|
||||
party: Party,
|
||||
party: Ref.Party,
|
||||
templateId: LedgerApi.Identifier,
|
||||
contractId: String,
|
||||
choice: String,
|
||||
choiceArgument: LedgerApi.Value,
|
||||
)(implicit ec: ExecutionContext, applicationId: ApplicationId): Future[Unit] = {
|
||||
)(implicit ec: ExecutionContext, applicationId: Option[Ref.ApplicationId]): Future[Unit] = {
|
||||
val commands = Seq(
|
||||
Command().withExercise(
|
||||
ExerciseCommand(
|
||||
@ -215,10 +213,10 @@ object AbstractTriggerTest {
|
||||
val request = SubmitAndWaitRequest(
|
||||
Some(
|
||||
Commands(
|
||||
party = party.unwrap,
|
||||
party = party,
|
||||
commands = commands,
|
||||
ledgerId = client.ledgerId.unwrap,
|
||||
applicationId = applicationId.unwrap,
|
||||
applicationId = applicationId.getOrElse(""),
|
||||
commandId = UUID.randomUUID.toString,
|
||||
)
|
||||
)
|
||||
@ -230,10 +228,10 @@ object AbstractTriggerTest {
|
||||
|
||||
def archive(
|
||||
client: LedgerClient,
|
||||
party: Party,
|
||||
party: Ref.Party,
|
||||
templateId: LedgerApi.Identifier,
|
||||
contractId: String,
|
||||
)(implicit ec: ExecutionContext, applicationId: ApplicationId): Future[Unit] = {
|
||||
)(implicit ec: ExecutionContext, applicationId: Option[Ref.ApplicationId]): Future[Unit] = {
|
||||
exercise(
|
||||
client,
|
||||
party,
|
||||
|
@ -7,7 +7,6 @@ package test
|
||||
import java.nio.file.Paths
|
||||
import com.daml.integrationtest.CantonFixture
|
||||
import com.daml.ledger.api.domain.{ObjectMeta, User, UserRight}
|
||||
import com.daml.ledger.api.refinements.ApiTypes
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref.UserId
|
||||
import com.google.protobuf.field_mask.FieldMask
|
||||
@ -20,9 +19,7 @@ import scala.language.implicitConversions
|
||||
|
||||
class ConfigSpec extends AsyncWordSpec with Matchers with CantonFixture {
|
||||
|
||||
private implicit def toParty(s: String): ApiTypes.Party =
|
||||
ApiTypes.Party(s)
|
||||
private implicit def toRefParty(s: String): Ref.Party =
|
||||
private implicit def toParty(s: String): Ref.Party =
|
||||
Ref.Party.assertFromString(s)
|
||||
private implicit def toUserId(s: String): UserId =
|
||||
UserId.assertFromString(s)
|
||||
@ -42,7 +39,7 @@ class ConfigSpec extends AsyncWordSpec with Matchers with CantonFixture {
|
||||
)
|
||||
"succeed with --ledger-party" in {
|
||||
RunnerConfig.parse(defaultArgs ++ Seq("--ledger-party=alice")) shouldBe Some(
|
||||
config.copy(ledgerClaims = PartySpecification(TriggerParties(toParty("alice"), Set.empty)))
|
||||
config.copy(ledgerClaims = PartySpecification(TriggerParties("alice", Set.empty)))
|
||||
)
|
||||
}
|
||||
"succeed with --ledger-party and --ledger-readas" in {
|
||||
|
@ -17,7 +17,6 @@ import org.scalatest.wordspec.AsyncWordSpec
|
||||
import com.daml.lf.engine.trigger.TriggerMsg
|
||||
import com.daml.lf.language.LanguageMajorVersion
|
||||
import com.daml.util.Ctx
|
||||
import scalaz.syntax.tag._
|
||||
|
||||
import scala.collection.concurrent.TrieMap
|
||||
|
||||
@ -83,7 +82,7 @@ class InterfaceSpec(override val majorLanguageVersion: LanguageMajorVersion)
|
||||
createArguments = Some(
|
||||
Record(
|
||||
fields = Seq(
|
||||
RecordField("owner", Some(Value().withParty(party.unwrap))),
|
||||
RecordField("owner", Some(Value().withParty(party))),
|
||||
RecordField("tag", Some(Value().withText(visibleViaAllInDar))),
|
||||
)
|
||||
)
|
||||
@ -98,7 +97,7 @@ class InterfaceSpec(override val majorLanguageVersion: LanguageMajorVersion)
|
||||
createArguments = Some(
|
||||
Record(
|
||||
fields = Seq(
|
||||
RecordField("owner", Some(Value().withParty(party.unwrap))),
|
||||
RecordField("owner", Some(Value().withParty(party))),
|
||||
RecordField("tag", Some(Value().withText(visibleViaAllInDar))),
|
||||
)
|
||||
)
|
||||
@ -140,7 +139,8 @@ class InterfaceSpec(override val majorLanguageVersion: LanguageMajorVersion)
|
||||
}
|
||||
|
||||
"succeed with interface registration and implementing template not registered" in {
|
||||
val triggerId = QualifiedName.assertFromString("InterfaceTriggers:triggerWithRegistration")
|
||||
val triggerId =
|
||||
QualifiedName.assertFromString("InterfaceTriggers:triggerWithRegistration")
|
||||
val transactionEvents = TrieMap.empty[String, Seq[Event]]
|
||||
|
||||
for {
|
||||
@ -159,7 +159,7 @@ class InterfaceSpec(override val majorLanguageVersion: LanguageMajorVersion)
|
||||
createArguments = Some(
|
||||
Record(
|
||||
fields = Seq(
|
||||
RecordField("owner", Some(Value().withParty(party.unwrap))),
|
||||
RecordField("owner", Some(Value().withParty(party))),
|
||||
RecordField(
|
||||
"tag",
|
||||
Some(Value().withText(visibleViaTemplateA)),
|
||||
@ -177,7 +177,7 @@ class InterfaceSpec(override val majorLanguageVersion: LanguageMajorVersion)
|
||||
createArguments = Some(
|
||||
Record(
|
||||
fields = Seq(
|
||||
RecordField("owner", Some(Value().withParty(party.unwrap))),
|
||||
RecordField("owner", Some(Value().withParty(party))),
|
||||
RecordField(
|
||||
"tag",
|
||||
Some(Value().withText(visibleViaInterfaceI)),
|
||||
@ -241,7 +241,7 @@ class InterfaceSpec(override val majorLanguageVersion: LanguageMajorVersion)
|
||||
createArguments = Some(
|
||||
Record(
|
||||
fields = Seq(
|
||||
RecordField("owner", Some(Value().withParty(party.unwrap))),
|
||||
RecordField("owner", Some(Value().withParty(party))),
|
||||
RecordField(
|
||||
"tag",
|
||||
Some(Value().withText(visibleViaInterfaceI)),
|
||||
@ -259,7 +259,7 @@ class InterfaceSpec(override val majorLanguageVersion: LanguageMajorVersion)
|
||||
createArguments = Some(
|
||||
Record(
|
||||
fields = Seq(
|
||||
RecordField("owner", Some(Value().withParty(party.unwrap))),
|
||||
RecordField("owner", Some(Value().withParty(party))),
|
||||
RecordField(
|
||||
"tag",
|
||||
Some(Value().withText(visibleViaInterfaceI)),
|
||||
|
@ -6,9 +6,9 @@ package com.daml.lf.engine.trigger.test
|
||||
import org.apache.pekko.stream.scaladsl.Flow
|
||||
import com.daml.integrationtest.CantonFixture
|
||||
import com.daml.ledger.api.domain
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{Party => ApiParty}
|
||||
import com.daml.ledger.api.v1.commands.CreateCommand
|
||||
import com.daml.ledger.api.v1.{value => LedgerApi}
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref._
|
||||
import com.daml.lf.engine.trigger.Runner.TriggerContext
|
||||
import com.daml.lf.engine.trigger.TriggerMsg
|
||||
@ -16,7 +16,6 @@ import com.daml.lf.language.LanguageMajorVersion
|
||||
import org.scalatest._
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AsyncWordSpec
|
||||
import scalaz.syntax.tag._
|
||||
|
||||
class JwtV1 extends Jwt(LanguageMajorVersion.V1)
|
||||
class JwtV2 extends Jwt(LanguageMajorVersion.V2)
|
||||
@ -34,13 +33,12 @@ class Jwt(override val majorLanguageVersion: LanguageMajorVersion)
|
||||
val assetId = LedgerApi.Identifier(packageId, "ACS", "Asset")
|
||||
val assetMirrorId = LedgerApi.Identifier(packageId, "ACS", "AssetMirror")
|
||||
|
||||
def asset(party: ApiParty): CreateCommand =
|
||||
def asset(party: Ref.Party): CreateCommand =
|
||||
CreateCommand(
|
||||
templateId = Some(assetId),
|
||||
createArguments = Some(
|
||||
LedgerApi.Record(
|
||||
fields =
|
||||
Seq(LedgerApi.RecordField("issuer", Some(LedgerApi.Value().withParty(party.unwrap))))
|
||||
fields = Seq(LedgerApi.RecordField("issuer", Some(LedgerApi.Value().withParty(party))))
|
||||
)
|
||||
),
|
||||
)
|
||||
@ -50,7 +48,7 @@ class Jwt(override val majorLanguageVersion: LanguageMajorVersion)
|
||||
userId = CantonFixture.freshUserId()
|
||||
party <- allocateParty(adminClient)
|
||||
user = domain.User(userId, None)
|
||||
rights = Seq(domain.UserRight.CanActAs(Party.assertFromString(party.unwrap)))
|
||||
rights = Seq(domain.UserRight.CanActAs(party))
|
||||
_ <- adminClient.userManagementClient.createUser(user, rights)
|
||||
client <- defaultLedgerClient(config.getToken(userId))
|
||||
runner = getRunner(client, QualifiedName.assertFromString("ACS:test"), party)
|
||||
|
@ -4,12 +4,12 @@
|
||||
package com.daml.lf.engine.trigger.test
|
||||
|
||||
import org.apache.pekko.stream.scaladsl.Flow
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{Party => ApiParty}
|
||||
import com.daml.ledger.api.v1.commands.CreateCommand
|
||||
import com.daml.ledger.api.v1.event.Event.Event.Created
|
||||
import com.daml.ledger.api.v1.event.{Event => ApiEvent}
|
||||
import com.daml.ledger.api.v1.transaction.{Transaction => ApiTransaction}
|
||||
import com.daml.ledger.api.v1.{value => LedgerApi}
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref.QualifiedName
|
||||
import com.daml.lf.engine.trigger.Runner.TriggerContext
|
||||
import com.daml.lf.engine.trigger.{
|
||||
@ -24,7 +24,6 @@ import com.daml.util.Ctx
|
||||
import org.scalatest.{Inside, TryValues}
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AsyncWordSpec
|
||||
import scalaz.syntax.tag._
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
@ -40,13 +39,13 @@ abstract class LoadTesting
|
||||
// The following value should be kept in sync with the value of breedingRate in Cats.daml
|
||||
val breedingRate: Int = 100
|
||||
|
||||
def command(template: String, owner: ApiParty, i: Int): CreateCommand =
|
||||
def command(template: String, owner: Ref.Party, i: Int): CreateCommand =
|
||||
CreateCommand(
|
||||
templateId = Some(LedgerApi.Identifier(packageId, "Cats", template)),
|
||||
createArguments = Some(
|
||||
LedgerApi.Record(fields =
|
||||
Seq(
|
||||
LedgerApi.RecordField("owner", Some(LedgerApi.Value().withParty(owner.unwrap))),
|
||||
LedgerApi.RecordField("owner", Some(LedgerApi.Value().withParty(owner))),
|
||||
template match {
|
||||
case "TestControl" =>
|
||||
LedgerApi.RecordField("size", Some(LedgerApi.Value().withInt64(i.toLong)))
|
||||
@ -58,9 +57,9 @@ abstract class LoadTesting
|
||||
),
|
||||
)
|
||||
|
||||
def cat(owner: ApiParty, i: Int): CreateCommand = command("Cat", owner, i)
|
||||
def cat(owner: Ref.Party, i: Int): CreateCommand = command("Cat", owner, i)
|
||||
|
||||
def food(owner: ApiParty, i: Int): CreateCommand = command("Food", owner, i)
|
||||
def food(owner: Ref.Party, i: Int): CreateCommand = command("Food", owner, i)
|
||||
|
||||
def notObserving(
|
||||
templateId: LedgerApi.Identifier
|
||||
|
@ -4,9 +4,9 @@
|
||||
package com.daml.lf.engine.trigger.test
|
||||
|
||||
import org.apache.pekko.stream.scaladsl.Flow
|
||||
import com.daml.ledger.api.refinements.ApiTypes.{Party => ApiParty}
|
||||
import com.daml.ledger.api.v1.commands.CreateCommand
|
||||
import com.daml.ledger.api.v1.{value => LedgerApi}
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.lf.data.Ref._
|
||||
import com.daml.lf.engine.trigger.Runner.TriggerContext
|
||||
import com.daml.lf.engine.trigger.TriggerMsg
|
||||
@ -14,7 +14,6 @@ import com.daml.lf.language.LanguageMajorVersion
|
||||
import org.scalatest._
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AsyncWordSpec
|
||||
import scalaz.syntax.tag._
|
||||
|
||||
class TlsV1 extends Tls(LanguageMajorVersion.V1)
|
||||
class TlsV2 extends Tls(LanguageMajorVersion.V2)
|
||||
@ -33,13 +32,12 @@ class Tls(override val majorLanguageVersion: LanguageMajorVersion)
|
||||
// We just need something simple to test the connection.
|
||||
val assetId = LedgerApi.Identifier(packageId, "ACS", "Asset")
|
||||
val assetMirrorId = LedgerApi.Identifier(packageId, "ACS", "AssetMirror")
|
||||
def asset(party: ApiParty): CreateCommand =
|
||||
def asset(party: Ref.Party): CreateCommand =
|
||||
CreateCommand(
|
||||
templateId = Some(assetId),
|
||||
createArguments = Some(
|
||||
LedgerApi.Record(
|
||||
fields =
|
||||
Seq(LedgerApi.RecordField("issuer", Some(LedgerApi.Value().withParty(party.unwrap))))
|
||||
fields = Seq(LedgerApi.RecordField("issuer", Some(LedgerApi.Value().withParty(party))))
|
||||
)
|
||||
),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user