Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SoX unit testing] TagWithLedgerEndSpec [DPP-841] #12346

Merged
merged 2 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ledger/sandbox-on-x/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Comment on lines +55 to +58
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rautenrieth-da FYI forgot to copy this guy from my draft testing branch. Added it as a subsequent commit

}