mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 01:07:18 +03:00
parent
b84558732a
commit
8a2449b87f
@ -77,14 +77,23 @@ da_scala_test_suite(
|
||||
":sandbox-on-x",
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/transaction",
|
||||
"//daml-lf/transaction-test-lib",
|
||||
"//language-support/scala/bindings",
|
||||
"//ledger/error",
|
||||
"//ledger/ledger-api-common",
|
||||
"//ledger/ledger-api-domain",
|
||||
"//ledger/ledger-api-health",
|
||||
"//ledger/ledger-configuration",
|
||||
"//ledger/ledger-offset",
|
||||
"//ledger/metrics",
|
||||
"//ledger/participant-integration-api",
|
||||
"//ledger/participant-state",
|
||||
"//ledger/participant-state-index",
|
||||
"//ledger/participant-state-metrics",
|
||||
"//libs-scala/contextualized-logging",
|
||||
"//libs-scala/logging-entries",
|
||||
"@maven//:com_google_protobuf_protobuf_java",
|
||||
"@maven//:io_dropwizard_metrics_metrics_core",
|
||||
"@maven//:org_mockito_mockito_core",
|
||||
],
|
||||
)
|
||||
|
@ -0,0 +1,59 @@
|
||||
// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package com.daml.ledger.sandbox.bridge.validate
|
||||
|
||||
import com.codahale.metrics.MetricRegistry
|
||||
import com.daml.ledger.api.domain
|
||||
import com.daml.ledger.offset.Offset
|
||||
import com.daml.ledger.participant.state.index.v2.IndexService
|
||||
import com.daml.ledger.sandbox.bridge.{BridgeMetrics, PreparedSubmission}
|
||||
import com.daml.ledger.sandbox.domain.{Rejection, Submission}
|
||||
import com.daml.lf.data.Ref
|
||||
import com.daml.logging.LoggingContext
|
||||
import com.daml.metrics.Metrics
|
||||
import org.mockito.MockitoSugar
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.util.chaining._
|
||||
|
||||
class TagWithLedgerEndSpec extends AnyFlatSpec with Matchers with MockitoSugar {
|
||||
behavior of classOf[TagWithLedgerEndImpl].getSimpleName
|
||||
|
||||
private implicit val ec: ExecutionContext = scala.concurrent.ExecutionContext.global
|
||||
private implicit val loggingContext: LoggingContext = LoggingContext.ForTesting
|
||||
|
||||
private val indexServiceMock = mock[IndexService]
|
||||
private val tagWithLedgerEnd = new TagWithLedgerEndImpl(
|
||||
indexService = indexServiceMock,
|
||||
bridgeMetrics = new BridgeMetrics(new Metrics(new MetricRegistry)),
|
||||
)
|
||||
|
||||
"tagWithLedgerEnd" should "tag the incoming submissions with the index service ledger end" in {
|
||||
val offsetString = Ref.HexString.assertFromString("ab")
|
||||
val expectedOffset = Offset.fromHexString(offsetString)
|
||||
val indexServiceProvidedOffset = domain.LedgerOffset.Absolute(offsetString)
|
||||
|
||||
val somePreparedSubmission =
|
||||
mock[PreparedSubmission]
|
||||
.tap { preparedSubmission =>
|
||||
val someSubmission = mock[Submission].tap { submission =>
|
||||
when(submission.loggingContext).thenReturn(loggingContext)
|
||||
}
|
||||
when(preparedSubmission.submission).thenReturn(someSubmission)
|
||||
}
|
||||
|
||||
when(indexServiceMock.currentLedgerEnd())
|
||||
.thenReturn(Future.successful(indexServiceProvidedOffset))
|
||||
|
||||
tagWithLedgerEnd(Right(somePreparedSubmission))
|
||||
.map(_ shouldBe Right(expectedOffset -> somePreparedSubmission))
|
||||
}
|
||||
|
||||
"tagWithLedgerEnd" should "propagate a rejection" in {
|
||||
val rejectionIn = Left(mock[Rejection])
|
||||
tagWithLedgerEnd(rejectionIn).map(_ shouldBe rejectionIn)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user