TagWithLedgerEndSpec (#12346)

changelog_begin
changelog_end
This commit is contained in:
tudor-da 2022-01-11 16:12:52 +01:00 committed by GitHub
parent b84558732a
commit 8a2449b87f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 0 deletions

View File

@ -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",
],
)

View File

@ -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)
}
}