Migrate trigger tests from sandbox-classic to sandbox (#11478)

Deliberately does not include the tests for the trigger service.

changelog_begin
changelog_end
This commit is contained in:
Moritz Kiefer 2021-11-01 15:22:51 +01:00 committed by GitHub
parent f9ec12be12
commit c415d9d1ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 46 deletions

View File

@ -5,7 +5,7 @@ load(
"//bazel_tools:scala.bzl", "//bazel_tools:scala.bzl",
"da_scala_binary", "da_scala_binary",
"da_scala_library", "da_scala_library",
"da_scala_test", "da_scala_test_suite",
"silencer_plugin", "silencer_plugin",
) )
load("@build_environment//:configuration.bzl", "sdk_version") load("@build_environment//:configuration.bzl", "sdk_version")
@ -109,8 +109,8 @@ da_scala_library(
"//ledger/ledger-api-common", "//ledger/ledger-api-common",
"//ledger/ledger-api-domain", "//ledger/ledger-api-domain",
"//ledger/ledger-resources", "//ledger/ledger-resources",
"//ledger/sandbox-classic", "//ledger/sandbox",
"//ledger/sandbox-classic:sandbox-classic-scala-tests-lib", "//ledger/sandbox:sandbox-scala-tests-lib",
"//ledger/sandbox-common", "//ledger/sandbox-common",
"//ledger/sandbox-common:sandbox-common-scala-tests-lib", "//ledger/sandbox-common:sandbox-common-scala-tests-lib",
"//ledger/test-common", "//ledger/test-common",
@ -122,10 +122,8 @@ da_scala_library(
], ],
) )
# For now turning this into a scala_test_suite has too much overhead and ends up making
# things slower rather than faster. Once we have more tests, we might want to reconsider.
[ [
da_scala_test( da_scala_test_suite(
name = "trigger-integration-tests" + suffix, name = "trigger-integration-tests" + suffix,
srcs = [ srcs = [
"src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/%s.scala" % f "src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/%s.scala" % f
@ -167,8 +165,7 @@ da_scala_library(
"//ledger/ledger-configuration", "//ledger/ledger-configuration",
"//ledger/ledger-resources", "//ledger/ledger-resources",
"//ledger/participant-integration-api", "//ledger/participant-integration-api",
"//ledger/sandbox-classic", "//ledger/sandbox:sandbox-scala-tests-lib",
"//ledger/sandbox-classic:sandbox-classic-scala-tests-lib",
"//ledger/sandbox-common", "//ledger/sandbox-common",
"//ledger/sandbox-common:sandbox-common-scala-tests-lib", "//ledger/sandbox-common:sandbox-common-scala-tests-lib",
"//ledger/test-common", "//ledger/test-common",

View File

@ -17,22 +17,11 @@ maxInboundMessageSizeTrigger = Trigger
} }
maxInboundMessageSizeRule : Party -> TriggerA () () maxInboundMessageSizeRule : Party -> TriggerA () ()
maxInboundMessageSizeRule party = query @MessageSize >>= \case maxInboundMessageSizeRule party = do
[] -> void $ emitCommands [createCmd (T party)] []
void $ emitCommands [createAndExerciseCmd (MessageSize { p = party }) (CreateN {n = 50000})] []
_ -> pure ()
template MessageSize template T
with with
p : Party p : Party
where where
signatory p signatory p
nonconsuming choice CreateN : ()
with
n : Int
controller p
do
res <- forA [1..n] (\_ -> do
create this
)
return()

View File

@ -12,13 +12,13 @@ import com.daml.ledger.api.testing.utils.SuiteResourceManagementAroundAll
import com.daml.ledger.api.v1.commands.CreateCommand import com.daml.ledger.api.v1.commands.CreateCommand
import com.daml.ledger.api.v1.{value => LedgerApi} import com.daml.ledger.api.v1.{value => LedgerApi}
import com.daml.platform.services.time.TimeProviderType import com.daml.platform.services.time.TimeProviderType
import io.grpc.{Status, StatusRuntimeException}
import org.scalatest._ import org.scalatest._
import org.scalatest.matchers.should.Matchers import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AsyncWordSpec import org.scalatest.wordspec.AsyncWordSpec
import scalaz.syntax.traverse._ import scalaz.syntax.traverse._
import com.daml.lf.engine.trigger.TriggerMsg import com.daml.lf.engine.trigger.TriggerMsg
import com.daml.lf.engine.trigger.RunnerConfig
import java.util.UUID import java.util.UUID
@ -314,21 +314,23 @@ abstract class AbstractFuncTests
"MaxMessageSizeTests" should { "MaxMessageSizeTests" should {
val triggerId = val triggerId =
QualifiedName.assertFromString("MaxInboundMessageTest:maxInboundMessageSizeTrigger") QualifiedName.assertFromString("MaxInboundMessageTest:maxInboundMessageSizeTrigger")
val tId = LedgerApi.Identifier(packageId, "MaxInboundMessageTest", "MessageSize")
"fail" in { "fail" in {
for { for {
client <- ledgerClient( client <- ledgerClient(
maxInboundMessageSize = 5 * RunnerConfig.DefaultMaxInboundMessageSize // Sufficiently low that the transaction is larger than the max inbound message size
maxInboundMessageSize = 300
) )
party <- allocateParty(client) party <- allocateParty(client)
runner = getRunner(client, triggerId, party) runner = getRunner(client, triggerId, party)
(acs, offset) <- runner.queryACS() (acs, offset) <- runner.queryACS()
// 1 for create and exercise // 1 for create and exercise
// 1 for completion // 1 for completion
_ <- runner.runWithACS(acs, offset, msgFlow = Flow[TriggerMsg].take(2))._2 // 1 for the transaction
acs <- queryACS(client, party) ex <- recoverToExceptionIf[StatusRuntimeException](
runner.runWithACS(acs, offset, msgFlow = Flow[TriggerMsg].take(3))._2
)
} yield { } yield {
assert(acs(tId).length == 50001) ex.getStatus.getCode() shouldBe Status.Code.RESOURCE_EXHAUSTED
} }
} }
} }
@ -440,15 +442,12 @@ abstract class AbstractFuncTests
QualifiedName.assertFromString("TemplateIdFilter:testOne"), QualifiedName.assertFromString("TemplateIdFilter:testOne"),
party, party,
) )
(acs, offset) <- runner.queryACS()
// 2 for the creates from the test
// 2 for the completions from the test
// 1 for the create in the trigger
// 1 for the completion from the trigger
finalStateF = runner.runWithACS(acs, offset, msgFlow = Flow[TriggerMsg].take(6))._2
_ <- create(client, party, one(party)) _ <- create(client, party, one(party))
_ <- create(client, party, two(party)) _ <- create(client, party, two(party))
_ <- finalStateF (acs, offset) <- runner.queryACS()
// 1 for the create in the trigger
// 1 for the completion from the trigger
_ <- runner.runWithACS(acs, offset, msgFlow = Flow[TriggerMsg].take(2))._2
acs <- queryACS(client, party) acs <- queryACS(client, party)
} yield { } yield {
assert(acs(doneOneId).length == 1) assert(acs(doneOneId).length == 1)
@ -464,15 +463,12 @@ abstract class AbstractFuncTests
QualifiedName.assertFromString("TemplateIdFilter:testTwo"), QualifiedName.assertFromString("TemplateIdFilter:testTwo"),
party, party,
) )
(acs, offset) <- runner.queryACS()
// 2 for the creates from the test
// 2 for the completions from the test
// 1 for the create in the trigger
// 1 for the completion from the trigger
finalStateF = runner.runWithACS(acs, offset, msgFlow = Flow[TriggerMsg].take(6))._2
_ <- create(client, party, one(party)) _ <- create(client, party, one(party))
_ <- create(client, party, two(party)) _ <- create(client, party, two(party))
_ <- finalStateF (acs, offset) <- runner.queryACS()
// 1 for the create in the trigger
// 1 for the completion from the trigger
_ <- runner.runWithACS(acs, offset, msgFlow = Flow[TriggerMsg].take(2))._2
acs <- queryACS(client, party) acs <- queryACS(client, party)
} yield { } yield {
assert(!acs.contains(doneOneId)) assert(!acs.contains(doneOneId))

View File

@ -26,7 +26,8 @@ import com.daml.lf.archive.DarDecoder
import com.daml.lf.data.Ref._ import com.daml.lf.data.Ref._
import com.daml.lf.speedy.SValue import com.daml.lf.speedy.SValue
import com.daml.lf.speedy.SValue._ import com.daml.lf.speedy.SValue._
import com.daml.platform.sandbox.services.{SandboxFixture, TestCommands} import com.daml.platform.sandboxnext.SandboxNextFixture
import com.daml.platform.sandbox.services.TestCommands
import org.scalatest._ import org.scalatest._
import scalaz.syntax.tag._ import scalaz.syntax.tag._
@ -34,7 +35,7 @@ import scala.collection.compat._
import scala.concurrent.{ExecutionContext, Future} import scala.concurrent.{ExecutionContext, Future}
import scala.util.Try import scala.util.Try
trait AbstractTriggerTest extends SandboxFixture with TestCommands { trait AbstractTriggerTest extends SandboxNextFixture with TestCommands {
self: Suite => self: Suite =>
protected def toHighLevelResult(s: SValue) = s match { protected def toHighLevelResult(s: SValue) = s match {

View File

@ -12,7 +12,7 @@ import com.daml.ledger.client.configuration.LedgerClientConfiguration
import com.daml.lf.data.Ref._ import com.daml.lf.data.Ref._
import com.daml.lf.engine.trigger.TriggerMsg import com.daml.lf.engine.trigger.TriggerMsg
import com.daml.platform.sandbox.SandboxRequiringAuthorization import com.daml.platform.sandbox.SandboxRequiringAuthorization
import com.daml.platform.sandbox.services.SandboxFixture import com.daml.platform.sandboxnext.SandboxNextFixture
import org.scalatest._ import org.scalatest._
import org.scalatest.matchers.should.Matchers import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AsyncWordSpec import org.scalatest.wordspec.AsyncWordSpec
@ -20,7 +20,7 @@ import org.scalatest.wordspec.AsyncWordSpec
class Jwt class Jwt
extends AsyncWordSpec extends AsyncWordSpec
with AbstractTriggerTest with AbstractTriggerTest
with SandboxFixture with SandboxNextFixture
with SandboxRequiringAuthorization with SandboxRequiringAuthorization
with Matchers with Matchers
with SuiteResourceManagementAroundAll with SuiteResourceManagementAroundAll