Skip to content

Commit

Permalink
Ledger API tests: option for non-unique identifiers (digital-asset#1735)
Browse files Browse the repository at this point in the history
* Ledger API Test Tool: Add --stable-identifiers option.

* Ledger API Test Tool: split stable party and command identifiers options.

This allows to control individually which identifiers are stable and which are
randomized.

* Ledger API tests: introduce TestIdsGenerator.

It combines all places where per-run unification of identifiers was generated.

* Ledger API Tests: use unification methods instead of run*Suffix

* Review fixes
  • Loading branch information
gleber-da authored and mergify[bot] committed Jun 28, 2019
1 parent 52e88b3 commit 2089b2d
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

package com.digitalasset.platform.tests.integration.ledger.api

import java.util.UUID

import akka.stream.scaladsl.Sink
import com.digitalasset.daml.lf.data.{ImmArray, Ref}
import com.digitalasset.daml.lf.data.Ref.{ContractIdString, LedgerString}
Expand All @@ -26,7 +24,12 @@ import com.digitalasset.ledger.api.v1.ledger_offset._
import com.digitalasset.ledger.api.v1.transaction_filter._
import com.digitalasset.ledger.client.services.acs.ActiveContractSetClient
import com.digitalasset.ledger.client.services.transactions.TransactionClient
import com.digitalasset.platform.apitesting.{LedgerContext, MultiLedgerFixture, TestTemplateIds}
import com.digitalasset.platform.apitesting.{
LedgerContext,
MultiLedgerFixture,
TestIdsGenerator,
TestTemplateIds
}
import com.digitalasset.platform.participant.util.LfEngineToApi
import com.google.protobuf.timestamp.Timestamp
import org.scalatest.Inside.inside
Expand All @@ -50,6 +53,7 @@ class DivulgenceIT

protected val testTemplateIds = new TestTemplateIds(config)
protected val templateIds = testTemplateIds.templateIds
protected val testIdsGenerator = new TestIdsGenerator(config)

private implicit def party(s: String): Ref.Party = Ref.Party.assertFromString(s)
private implicit def pkgId(s: String): Ref.PackageId = Ref.PackageId.assertFromString(s)
Expand Down Expand Up @@ -157,12 +161,10 @@ class DivulgenceIT
// but that it is visible in the transaction trees.
case class Setup(div1Cid: String, div2Cid: String)

private val runSuffix: UUID = UUID.randomUUID

private def createDivulgence1(ctx: LedgerContext, workflowId: String): Future[ContractIdString] =
create(
ctx,
s"create-Divulgence1-$runSuffix",
testIdsGenerator.testCommandId("create-Divulgence1"),
workflowId,
"alice",
templateIds.divulgence1,
Expand All @@ -172,7 +174,7 @@ class DivulgenceIT
private def createDivulgence2(ctx: LedgerContext, workflowId: String): Future[ContractIdString] =
create(
ctx,
s"create-Divulgence2-$runSuffix",
testIdsGenerator.testCommandId("create-Divulgence2"),
workflowId,
"bob",
templateIds.divulgence2,
Expand All @@ -190,7 +192,7 @@ class DivulgenceIT
workflowId: String): Future[Unit] =
exercise(
ctx,
s"exercise-Divulgence2Fetch-$runSuffix",
testIdsGenerator.testCommandId("exercise-Divulgence2Fetch"),
workflowId,
"alice",
templateIds.divulgence2,
Expand All @@ -208,7 +210,7 @@ class DivulgenceIT
workflowId: String): Future[Unit] =
exercise(
ctx,
s"exercise-Divulgence2Fetch-$runSuffix",
testIdsGenerator.testCommandId("exercise-Divulgence2Fetch"),
workflowId,
"alice",
templateIds.divulgence2,
Expand All @@ -228,7 +230,7 @@ class DivulgenceIT
Map("alice" -> Filters.defaultInstance, "bob" -> Filters.defaultInstance))

"should not expose divulged contracts in flat stream" in allFixtures { ctx =>
val wfid = s"divulgence-test-workflow-id-$runSuffix"
val wfid = testIdsGenerator.testWorkflowId("divulgence-test-workflow-id")
for {
beforeTest <- transactionClient(ctx).getLedgerEnd.map(_.getOffset)
div1Cid <- createDivulgence1(ctx, wfid)
Expand Down Expand Up @@ -321,7 +323,7 @@ class DivulgenceIT
}

"should not expose divulged contracts in ACS" in allFixtures { ctx =>
val wfid = s"divulgence-test-workflow-id-$runSuffix"
val wfid = testIdsGenerator.testWorkflowId("divulgence-test-workflow-id")
for {
beforeTest <- transactionClient(ctx).getLedgerEnd.map(_.getOffset)
div1Cid <- createDivulgence1(ctx, wfid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.digitalasset.daml.lf.archive.{DarReader, Decode}
import com.digitalasset.daml.lf.language.Ast
import com.digitalasset.daml_lf.DamlLf.Archive

import scala.util.{Random, Try}
import scala.util.Try
import com.digitalasset.ledger.api.testing.utils.{
AkkaBeforeAndAfterAll,
IsStatusException,
Expand All @@ -24,7 +24,7 @@ import com.digitalasset.ledger.api.v1.transaction_filter.{Filters, TransactionFi
import com.digitalasset.ledger.api.v1.value.{Identifier, Record, RecordField}
import com.digitalasset.ledger.client.services.admin.PackageManagementClient
import com.digitalasset.platform.apitesting.LedgerContextExtensions._
import com.digitalasset.platform.apitesting.MultiLedgerFixture
import com.digitalasset.platform.apitesting.{MultiLedgerFixture, TestIdsGenerator}
import com.digitalasset.platform.participant.util.ValueConversions._
import io.grpc.Status
import com.google.protobuf.ByteString
Expand All @@ -46,13 +46,11 @@ class PackageManagementServiceIT
with Matchers
with BazelRunfiles {

private val runSuffix = "-" + Random.alphanumeric.take(10).mkString
private val partyNameMangler =
(partyText: String) => partyText + runSuffix + Random.alphanumeric.take(10).mkString
private val commandIdMangler =
(testName: String, nodeId: String) => s"ledger-api-test-tool-$testName-$nodeId-$runSuffix"

override protected def config: Config = Config.default.copy(darFiles = Nil)
protected val testIdsGenerator = new TestIdsGenerator(config)

private def commandNodeIdUnifier(testName: String, nodeId: String) =
testIdsGenerator.testCommandId(s"ledger-api-test-tool-$testName-$nodeId")

private def packageManagementService(stub: PackageManagementService): PackageManagementClient =
new PackageManagementClient(stub)
Expand Down Expand Up @@ -136,7 +134,7 @@ class PackageManagementServiceIT
}

"should accept commands using the uploaded package" in allFixtures { ctx =>
val party = partyNameMangler("operator")
val party = testIdsGenerator.testPartyName("operator")
val createArg = Record(fields = List(RecordField("operator", party.asParty)))
def createCmd =
CreateCommand(Some(Identifier(testPackageId, "", "Test", "Dummy")), Some(createArg)).wrap
Expand All @@ -147,7 +145,8 @@ class PackageManagementServiceIT
_ <- client.uploadDarFile(ByteString.copyFrom(testDarBytes))
createTx <- ctx.testingHelpers.submitAndListenForSingleResultOfCommand(
ctx.testingHelpers
.submitRequestWithId(commandIdMangler("PackageManagementServiceIT_commands", "create"))
.submitRequestWithId(
commandNodeIdUnifier("PackageManagementServiceIT_commands", "create"))
.update(
_.commands.commands := List(createCmd),
_.commands.party := party
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.scalatest._
import org.scalatest.concurrent.AsyncTimeLimitedTests
import org.scalatest.time.Span
import org.scalatest.time.SpanSugar._

import scalaz.syntax.tag._

@SuppressWarnings(
Expand Down
Loading

0 comments on commit 2089b2d

Please sign in to comment.