mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-10 10:46:11 +03:00
Move PackageServiceIT to the ledger api test tool
This commit is contained in:
parent
cc66d054a8
commit
afabb584c8
@ -1,126 +0,0 @@
|
|||||||
// Copyright (c) 2019 The DAML Authors. All rights reserved.
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
package com.digitalasset.platform.tests.integration.ledger.api
|
|
||||||
|
|
||||||
import java.util.UUID
|
|
||||||
|
|
||||||
import com.digitalasset.ledger.api.domain
|
|
||||||
import com.digitalasset.ledger.api.testing.utils.{
|
|
||||||
AkkaBeforeAndAfterAll,
|
|
||||||
IsStatusException,
|
|
||||||
SuiteResourceManagementAroundAll
|
|
||||||
}
|
|
||||||
import com.digitalasset.ledger.api.v1.package_service.PackageStatus
|
|
||||||
import com.digitalasset.ledger.client.services.pkg.PackageClient
|
|
||||||
import com.digitalasset.platform.apitesting.{LedgerContext, MultiLedgerFixture}
|
|
||||||
import io.grpc.Status
|
|
||||||
import org.scalatest.concurrent.AsyncTimeLimitedTests
|
|
||||||
import org.scalatest.time.Span
|
|
||||||
import org.scalatest.time.SpanSugar._
|
|
||||||
import org.scalatest.{AsyncWordSpec, Matchers, OptionValues}
|
|
||||||
|
|
||||||
import scalaz.syntax.tag._
|
|
||||||
|
|
||||||
@SuppressWarnings(Array("org.wartremover.warts.Any"))
|
|
||||||
class PackageServiceIT
|
|
||||||
extends AsyncWordSpec
|
|
||||||
with AkkaBeforeAndAfterAll
|
|
||||||
with MultiLedgerFixture
|
|
||||||
with SuiteResourceManagementAroundAll
|
|
||||||
with AsyncTimeLimitedTests
|
|
||||||
with Matchers
|
|
||||||
with OptionValues {
|
|
||||||
|
|
||||||
override def timeLimit: Span = scaled(5.seconds)
|
|
||||||
|
|
||||||
private def client(ctx: LedgerContext): PackageClient = {
|
|
||||||
new PackageClient(ctx.ledgerId, ctx.packageService)
|
|
||||||
}
|
|
||||||
|
|
||||||
private def getARegisteredPackageId(ctx: LedgerContext) =
|
|
||||||
client(ctx).listPackages().map(_.packageIds.headOption.value)
|
|
||||||
|
|
||||||
"Package Service" when {
|
|
||||||
|
|
||||||
"asked for the list of registered packages" should {
|
|
||||||
|
|
||||||
"return it" in allFixtures { context =>
|
|
||||||
client(context).listPackages() map {
|
|
||||||
_.packageIds.size shouldEqual 3 // package, stdlib, daml-prim
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"fail with the expected status on a ledger Id mismatch" in allFixtures { context =>
|
|
||||||
new PackageClient(
|
|
||||||
domain.LedgerId(s"not-${context.ledgerId.unwrap}"),
|
|
||||||
context.packageService)
|
|
||||||
.listPackages()
|
|
||||||
.failed map {
|
|
||||||
IsStatusException(Status.NOT_FOUND)(_)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"asked to get a package" should {
|
|
||||||
|
|
||||||
"return it if it's registered" in allFixtures { context =>
|
|
||||||
getARegisteredPackageId(context)
|
|
||||||
.flatMap(client(context).getPackage(_)) map {
|
|
||||||
_.archivePayload.size() should be > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
"return a NOT_FOUND error if it's not registered" in allFixtures { context =>
|
|
||||||
client(context).getPackage(UUID.randomUUID().toString).failed map {
|
|
||||||
IsStatusException(Status.NOT_FOUND)(_)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"fail with the expected status on a ledger Id mismatch" in allFixtures { context =>
|
|
||||||
getARegisteredPackageId(context)
|
|
||||||
.flatMap(
|
|
||||||
new PackageClient(
|
|
||||||
domain.LedgerId(s"not-${context.ledgerId.unwrap}"),
|
|
||||||
context.packageService)
|
|
||||||
.getPackage(_)
|
|
||||||
.failed) map {
|
|
||||||
IsStatusException(Status.NOT_FOUND)(_)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"asked to check a package's status" should {
|
|
||||||
|
|
||||||
"return true if it's registered" in allFixtures { context =>
|
|
||||||
getARegisteredPackageId(context)
|
|
||||||
.flatMap(client(context).getPackageStatus(_)) map {
|
|
||||||
_.packageStatus shouldEqual PackageStatus.REGISTERED
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"return false if it's not registered" in allFixtures { context =>
|
|
||||||
client(context).getPackageStatus(UUID.randomUUID().toString) map {
|
|
||||||
_.packageStatus shouldEqual PackageStatus.UNKNOWN
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
"fail with the expected status on a ledger Id mismatch" in allFixtures { context =>
|
|
||||||
getARegisteredPackageId(context)
|
|
||||||
.flatMap(
|
|
||||||
new PackageClient(
|
|
||||||
domain.LedgerId(s"not-${context.ledgerId.unwrap}"),
|
|
||||||
context.packageService)
|
|
||||||
.getPackageStatus(_)
|
|
||||||
.failed) map {
|
|
||||||
IsStatusException(Status.NOT_FOUND)(_)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override protected def config: Config = Config.default
|
|
||||||
}
|
|
@ -13,6 +13,8 @@ import com.digitalasset.ledger.api.v1.command_service.CommandServiceGrpc
|
|||||||
import com.digitalasset.ledger.api.v1.command_service.CommandServiceGrpc.CommandService
|
import com.digitalasset.ledger.api.v1.command_service.CommandServiceGrpc.CommandService
|
||||||
import com.digitalasset.ledger.api.v1.ledger_identity_service.LedgerIdentityServiceGrpc
|
import com.digitalasset.ledger.api.v1.ledger_identity_service.LedgerIdentityServiceGrpc
|
||||||
import com.digitalasset.ledger.api.v1.ledger_identity_service.LedgerIdentityServiceGrpc.LedgerIdentityService
|
import com.digitalasset.ledger.api.v1.ledger_identity_service.LedgerIdentityServiceGrpc.LedgerIdentityService
|
||||||
|
import com.digitalasset.ledger.api.v1.package_service.PackageServiceGrpc
|
||||||
|
import com.digitalasset.ledger.api.v1.package_service.PackageServiceGrpc.PackageService
|
||||||
import com.digitalasset.ledger.api.v1.testing.time_service.TimeServiceGrpc
|
import com.digitalasset.ledger.api.v1.testing.time_service.TimeServiceGrpc
|
||||||
import com.digitalasset.ledger.api.v1.testing.time_service.TimeServiceGrpc.TimeService
|
import com.digitalasset.ledger.api.v1.testing.time_service.TimeServiceGrpc.TimeService
|
||||||
import com.digitalasset.ledger.api.v1.transaction_service.TransactionServiceGrpc
|
import com.digitalasset.ledger.api.v1.transaction_service.TransactionServiceGrpc
|
||||||
@ -25,6 +27,7 @@ private[infrastructure] final class LedgerServices(channel: Channel) {
|
|||||||
val identity: LedgerIdentityService = LedgerIdentityServiceGrpc.stub(channel)
|
val identity: LedgerIdentityService = LedgerIdentityServiceGrpc.stub(channel)
|
||||||
val partyManagement: PartyManagementService = PartyManagementServiceGrpc.stub(channel)
|
val partyManagement: PartyManagementService = PartyManagementServiceGrpc.stub(channel)
|
||||||
val packageManagement: PackageManagementService = PackageManagementServiceGrpc.stub(channel)
|
val packageManagement: PackageManagementService = PackageManagementServiceGrpc.stub(channel)
|
||||||
|
val packages: PackageService = PackageServiceGrpc.stub(channel)
|
||||||
val transaction: TransactionService = TransactionServiceGrpc.stub(channel)
|
val transaction: TransactionService = TransactionServiceGrpc.stub(channel)
|
||||||
val time: TimeService = TimeServiceGrpc.stub(channel)
|
val time: TimeService = TimeServiceGrpc.stub(channel)
|
||||||
}
|
}
|
||||||
|
@ -90,9 +90,11 @@ private[testtool] abstract class LedgerTestSuite(val session: LedgerSession) {
|
|||||||
"Exception is neither a StatusRuntimeException nor a StatusException")
|
"Exception is neither a StatusRuntimeException nor a StatusException")
|
||||||
}
|
}
|
||||||
assert(actualCode == expectedCode, s"Expected code [$expectedCode], but got [$actualCode].")
|
assert(actualCode == expectedCode, s"Expected code [$expectedCode], but got [$actualCode].")
|
||||||
|
// Note: Status.getDescription() is nullable, map missing descriptions to an empty string
|
||||||
|
val nonNullMessage = Option(message).getOrElse("")
|
||||||
assert(
|
assert(
|
||||||
message.contains(pattern),
|
nonNullMessage.contains(pattern),
|
||||||
s"Error message did not contain [$pattern], but was [$message].")
|
s"Error message did not contain [$pattern], but was [$nonNullMessage].")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +30,13 @@ import com.digitalasset.ledger.api.v1.commands.{Command, Commands}
|
|||||||
import com.digitalasset.ledger.api.v1.event.Event.Event.Created
|
import com.digitalasset.ledger.api.v1.event.Event.Event.Created
|
||||||
import com.digitalasset.ledger.api.v1.event.{CreatedEvent, Event}
|
import com.digitalasset.ledger.api.v1.event.{CreatedEvent, Event}
|
||||||
import com.digitalasset.ledger.api.v1.ledger_offset.LedgerOffset
|
import com.digitalasset.ledger.api.v1.ledger_offset.LedgerOffset
|
||||||
|
import com.digitalasset.ledger.api.v1.package_service.{
|
||||||
|
GetPackageRequest,
|
||||||
|
GetPackageResponse,
|
||||||
|
GetPackageStatusRequest,
|
||||||
|
ListPackagesRequest,
|
||||||
|
PackageStatus
|
||||||
|
}
|
||||||
import com.digitalasset.ledger.api.v1.testing.time_service.{
|
import com.digitalasset.ledger.api.v1.testing.time_service.{
|
||||||
GetTimeRequest,
|
GetTimeRequest,
|
||||||
GetTimeResponse,
|
GetTimeResponse,
|
||||||
@ -156,6 +163,17 @@ private[testtool] final class ParticipantTestContext private[participant] (
|
|||||||
def participantId(): Future[String] =
|
def participantId(): Future[String] =
|
||||||
services.partyManagement.getParticipantId(new GetParticipantIdRequest).map(_.participantId)
|
services.partyManagement.getParticipantId(new GetParticipantIdRequest).map(_.participantId)
|
||||||
|
|
||||||
|
def listPackages(): Future[Seq[String]] =
|
||||||
|
services.packages.listPackages(new ListPackagesRequest(ledgerId)).map(_.packageIds)
|
||||||
|
|
||||||
|
def getPackage(packageId: String): Future[GetPackageResponse] =
|
||||||
|
services.packages.getPackage(new GetPackageRequest(ledgerId, packageId))
|
||||||
|
|
||||||
|
def getPackageStatus(packageId: String): Future[PackageStatus] =
|
||||||
|
services.packages
|
||||||
|
.getPackageStatus(new GetPackageStatusRequest(ledgerId, packageId))
|
||||||
|
.map(_.packageStatus)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Managed version of party allocation, should be used anywhere a party has
|
* Managed version of party allocation, should be used anywhere a party has
|
||||||
* to be allocated unless the party management service itself is under test
|
* to be allocated unless the party management service itself is under test
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
// Copyright (c) 2019 The DAML Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package com.daml.ledger.api.testtool.tests
|
||||||
|
|
||||||
|
import com.daml.ledger.api.testtool.infrastructure.{LedgerSession, LedgerTest, LedgerTestSuite}
|
||||||
|
import io.grpc.Status
|
||||||
|
|
||||||
|
final class Packages(session: LedgerSession) extends LedgerTestSuite(session) {
|
||||||
|
|
||||||
|
/** A package ID that is guaranteed to not be uploaded */
|
||||||
|
private[this] val unknownPackageId = " "
|
||||||
|
|
||||||
|
private[this] val listPackages =
|
||||||
|
LedgerTest("PackagesList", "Listing packages should return a result") { context =>
|
||||||
|
for {
|
||||||
|
ledger <- context.participant()
|
||||||
|
knownPackages <- ledger.listPackages()
|
||||||
|
} yield
|
||||||
|
assert(
|
||||||
|
knownPackages.size >= 3,
|
||||||
|
s"List of packages was expected to contain at least 3 packages, got ${knownPackages.size} instead.")
|
||||||
|
}
|
||||||
|
|
||||||
|
private[this] val getPackage =
|
||||||
|
LedgerTest("PackagesGet", "Getting package content should return a valid result") { context =>
|
||||||
|
for {
|
||||||
|
ledger <- context.participant()
|
||||||
|
somePackageId <- ledger.listPackages().map(_.headOption.getOrElse(fail("No package found")))
|
||||||
|
somePackage <- ledger.getPackage(somePackageId)
|
||||||
|
} yield {
|
||||||
|
assert(somePackage.hash.length > 0, s"Package $somePackageId has an empty hash.")
|
||||||
|
assert(
|
||||||
|
somePackage.hash == somePackageId,
|
||||||
|
s"Package $somePackageId has hash ${somePackage.hash}, expected hash to be equal to the package ID.")
|
||||||
|
assert(somePackage.archivePayload.size() >= 0, s"Package $somePackageId has zero size.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private[this] val getUnknownPackage =
|
||||||
|
LedgerTest("PackagesGetUnknown", "Getting package content for an unknown package should fail") {
|
||||||
|
context =>
|
||||||
|
for {
|
||||||
|
ledger <- context.participant()
|
||||||
|
failure <- ledger.getPackage(unknownPackageId).failed
|
||||||
|
} yield {
|
||||||
|
assertGrpcError(failure, Status.Code.NOT_FOUND, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private[this] val getPackageStatus =
|
||||||
|
LedgerTest("PackagesStatus", "Getting package status should return a valid result") { context =>
|
||||||
|
for {
|
||||||
|
ledger <- context.participant()
|
||||||
|
somePackageId <- ledger.listPackages().map(_.headOption.getOrElse(fail("No package found")))
|
||||||
|
status <- ledger.getPackageStatus(somePackageId)
|
||||||
|
} yield {
|
||||||
|
assert(status.isRegistered, s"Package $somePackageId is not registered.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private[this] val getUnknownPackageStatus =
|
||||||
|
LedgerTest("PackagesStatusUnknown", "Getting package status for an unknown package should fail") {
|
||||||
|
context =>
|
||||||
|
for {
|
||||||
|
ledger <- context.participant()
|
||||||
|
status <- ledger.getPackageStatus(unknownPackageId)
|
||||||
|
} yield {
|
||||||
|
assert(status.isUnknown, s"Package $unknownPackageId is not unknown.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override val tests: Vector[LedgerTest] = Vector(
|
||||||
|
listPackages,
|
||||||
|
getPackage,
|
||||||
|
getUnknownPackage,
|
||||||
|
getPackageStatus,
|
||||||
|
getUnknownPackageStatus
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
@ -26,6 +26,7 @@ package object tests {
|
|||||||
"ContractKeysSubmitterIsMaintainerIT" -> (new ContractKeysSubmitterIsMaintainer(_)),
|
"ContractKeysSubmitterIsMaintainerIT" -> (new ContractKeysSubmitterIsMaintainer(_)),
|
||||||
"DivulgenceIT" -> (new Divulgence(_)),
|
"DivulgenceIT" -> (new Divulgence(_)),
|
||||||
"IdentityIT" -> (new Identity(_)),
|
"IdentityIT" -> (new Identity(_)),
|
||||||
|
"PackageServiceIT" -> (new Packages(_)),
|
||||||
"PackageManagementServiceIT" -> (new PackageManagement(_)),
|
"PackageManagementServiceIT" -> (new PackageManagement(_)),
|
||||||
"PartyManagementServiceIT" -> (new PartyManagement(_)),
|
"PartyManagementServiceIT" -> (new PartyManagement(_)),
|
||||||
"TimeIT" -> (new Time(_)),
|
"TimeIT" -> (new Time(_)),
|
||||||
|
Loading…
Reference in New Issue
Block a user