From c415d9d1eefe19db2488409a70dbb1e573dad05f Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Mon, 1 Nov 2021 15:22:51 +0100 Subject: [PATCH] Migrate trigger tests from sandbox-classic to sandbox (#11478) Deliberately does not include the tests for the trigger service. changelog_begin changelog_end --- triggers/tests/BUILD.bazel | 13 +++---- .../tests/daml/MaxInboundMessageTest.daml | 17 ++------- .../trigger/test/AbstractFuncTests.scala | 36 +++++++++---------- .../trigger/test/AbstractTriggerTest.scala | 5 +-- .../daml/lf/engine/trigger/test/Jwt.scala | 4 +-- 5 files changed, 29 insertions(+), 46 deletions(-) diff --git a/triggers/tests/BUILD.bazel b/triggers/tests/BUILD.bazel index a5b39df81d..f7ee716c04 100644 --- a/triggers/tests/BUILD.bazel +++ b/triggers/tests/BUILD.bazel @@ -5,7 +5,7 @@ load( "//bazel_tools:scala.bzl", "da_scala_binary", "da_scala_library", - "da_scala_test", + "da_scala_test_suite", "silencer_plugin", ) load("@build_environment//:configuration.bzl", "sdk_version") @@ -109,8 +109,8 @@ da_scala_library( "//ledger/ledger-api-common", "//ledger/ledger-api-domain", "//ledger/ledger-resources", - "//ledger/sandbox-classic", - "//ledger/sandbox-classic:sandbox-classic-scala-tests-lib", + "//ledger/sandbox", + "//ledger/sandbox:sandbox-scala-tests-lib", "//ledger/sandbox-common", "//ledger/sandbox-common:sandbox-common-scala-tests-lib", "//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, srcs = [ "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-resources", "//ledger/participant-integration-api", - "//ledger/sandbox-classic", - "//ledger/sandbox-classic:sandbox-classic-scala-tests-lib", + "//ledger/sandbox:sandbox-scala-tests-lib", "//ledger/sandbox-common", "//ledger/sandbox-common:sandbox-common-scala-tests-lib", "//ledger/test-common", diff --git a/triggers/tests/daml/MaxInboundMessageTest.daml b/triggers/tests/daml/MaxInboundMessageTest.daml index 60ef0fa1ff..e9416709e4 100644 --- a/triggers/tests/daml/MaxInboundMessageTest.daml +++ b/triggers/tests/daml/MaxInboundMessageTest.daml @@ -17,22 +17,11 @@ maxInboundMessageSizeTrigger = Trigger } maxInboundMessageSizeRule : Party -> TriggerA () () -maxInboundMessageSizeRule party = query @MessageSize >>= \case - [] -> - void $ emitCommands [createAndExerciseCmd (MessageSize { p = party }) (CreateN {n = 50000})] [] - _ -> pure () +maxInboundMessageSizeRule party = do + void $ emitCommands [createCmd (T party)] [] -template MessageSize +template T with p : Party where signatory p - nonconsuming choice CreateN : () - with - n : Int - controller p - do - res <- forA [1..n] (\_ -> do - create this - ) - return() diff --git a/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/AbstractFuncTests.scala b/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/AbstractFuncTests.scala index 0aa7ea5b18..9fbe68d247 100644 --- a/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/AbstractFuncTests.scala +++ b/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/AbstractFuncTests.scala @@ -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.{value => LedgerApi} import com.daml.platform.services.time.TimeProviderType +import io.grpc.{Status, StatusRuntimeException} import org.scalatest._ import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AsyncWordSpec import scalaz.syntax.traverse._ import com.daml.lf.engine.trigger.TriggerMsg -import com.daml.lf.engine.trigger.RunnerConfig import java.util.UUID @@ -314,21 +314,23 @@ abstract class AbstractFuncTests "MaxMessageSizeTests" should { val triggerId = QualifiedName.assertFromString("MaxInboundMessageTest:maxInboundMessageSizeTrigger") - val tId = LedgerApi.Identifier(packageId, "MaxInboundMessageTest", "MessageSize") "fail" in { for { client <- ledgerClient( - maxInboundMessageSize = 5 * RunnerConfig.DefaultMaxInboundMessageSize + // Sufficiently low that the transaction is larger than the max inbound message size + maxInboundMessageSize = 300 ) party <- allocateParty(client) runner = getRunner(client, triggerId, party) (acs, offset) <- runner.queryACS() // 1 for create and exercise // 1 for completion - _ <- runner.runWithACS(acs, offset, msgFlow = Flow[TriggerMsg].take(2))._2 - acs <- queryACS(client, party) + // 1 for the transaction + ex <- recoverToExceptionIf[StatusRuntimeException]( + runner.runWithACS(acs, offset, msgFlow = Flow[TriggerMsg].take(3))._2 + ) } 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"), 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, 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) } yield { assert(acs(doneOneId).length == 1) @@ -464,15 +463,12 @@ abstract class AbstractFuncTests QualifiedName.assertFromString("TemplateIdFilter:testTwo"), 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, 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) } yield { assert(!acs.contains(doneOneId)) diff --git a/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/AbstractTriggerTest.scala b/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/AbstractTriggerTest.scala index 0b5e1ac30f..773434df94 100644 --- a/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/AbstractTriggerTest.scala +++ b/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/AbstractTriggerTest.scala @@ -26,7 +26,8 @@ import com.daml.lf.archive.DarDecoder import com.daml.lf.data.Ref._ 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 scalaz.syntax.tag._ @@ -34,7 +35,7 @@ import scala.collection.compat._ import scala.concurrent.{ExecutionContext, Future} import scala.util.Try -trait AbstractTriggerTest extends SandboxFixture with TestCommands { +trait AbstractTriggerTest extends SandboxNextFixture with TestCommands { self: Suite => protected def toHighLevelResult(s: SValue) = s match { diff --git a/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/Jwt.scala b/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/Jwt.scala index ffeb5795f1..78a889f9ed 100644 --- a/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/Jwt.scala +++ b/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/Jwt.scala @@ -12,7 +12,7 @@ import com.daml.ledger.client.configuration.LedgerClientConfiguration import com.daml.lf.data.Ref._ import com.daml.lf.engine.trigger.TriggerMsg 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.matchers.should.Matchers import org.scalatest.wordspec.AsyncWordSpec @@ -20,7 +20,7 @@ import org.scalatest.wordspec.AsyncWordSpec class Jwt extends AsyncWordSpec with AbstractTriggerTest - with SandboxFixture + with SandboxNextFixture with SandboxRequiringAuthorization with Matchers with SuiteResourceManagementAroundAll