Skip to content

Commit

Permalink
[Script] move test_daml_script_test_runner from sandbox to canton (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
remyhaemmerle-da committed Mar 31, 2023
1 parent dfc8619 commit c20fc05
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ trait CantonFixture extends SuiteResource[Vector[Port]] with AkkaBeforeAndAfterA
|""".stripMargin
)

private val tmpDir = Files.createTempDirectory("CantonFixture")
private val cantonConfigFile = tmpDir.resolve("participant.config")
private val cantonLogFile = tmpDir.resolve("canton.log")
private val portFile = tmpDir.resolve("portfile")
protected val tmpDir = Files.createTempDirectory("CantonFixture")
protected val cantonConfigFile = tmpDir.resolve("participant.config")
protected val cantonLogFile = tmpDir.resolve("canton.log")
protected val portFile = tmpDir.resolve("portfile")

private val files = List(cantonConfigFile, portFile, cantonLogFile)

Expand Down Expand Up @@ -168,7 +168,10 @@ trait CantonFixture extends SuiteResource[Vector[Port]] with AkkaBeforeAndAfterA
| ${tslConfig}
| }
| storage.type = memory
| parameters.dev-version-support = ${devMode}
| parameters = {
| enable-engine-stack-traces = true
| dev-version-support = ${devMode}
| }
| ${timeType.fold("")(x => "testing-time.type = " + x)}
| }""".stripMargin
}
Expand Down
22 changes: 2 additions & 20 deletions daml-script/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ da_scala_test_suite(
":script-test.dar",
":script-test-1.dev.dar",
":script-test-no-ledger.dar",
"//daml-script/runner:daml-script-binary",
"//test-common/test-certificates",
"@canton//:lib",
],
Expand Down Expand Up @@ -224,29 +225,10 @@ da_scala_test_suite(
"//libs-scala/resources",
"//libs-scala/resources-akka",
"//libs-scala/resources-grpc",
"//libs-scala/scala-utils",
"//observability/metrics",
"//test-common",
"@maven//:com_auth0_java_jwt",
"@maven//:io_dropwizard_metrics_metrics_core",
],
)

sh_test(
name = "test_daml_script_test_runner",
srcs = [":daml-script-test-runner.sh"],
args = [
"$(rootpath //daml-script/runner:daml-script-binary)",
"$(rootpath :script-test.dar)",
"$(POSIX_DIFF)",
"$(POSIX_GREP)",
"$(POSIX_SED)",
"$(rootpath //ledger/sandbox-on-x:app)",
],
data = [
":script-test.dar",
"//daml-script/runner:daml-script-binary",
"//ledger/sandbox-on-x:app",
],
toolchains = ["@rules_sh//sh/posix:make_variables"],
deps = ["@bazel_tools//tools/bash/runfiles"],
)
105 changes: 0 additions & 105 deletions daml-script/test/daml-script-test-runner.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package com.daml.lf.engine.script

import com.daml.bazeltools.BazelRunfiles
import com.daml.ledger.api.testing.utils.SuiteResourceManagementAroundAll
import com.daml.lf.integrationtest.CantonFixture
import com.daml.platform.services.time.TimeProviderType
import com.daml.scalautil.Statement.discard
import org.scalatest.Suite
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

import java.nio.file.Files

class DamlScriptTestRunner
extends AnyWordSpec
with CantonFixture
with Matchers
with SuiteResourceManagementAroundAll {
self: Suite =>

override protected def authSecret = None
override protected def darFiles = List.empty
override protected def devMode = false
override protected def nParticipants = 1
override protected def timeProviderType = TimeProviderType.Static
override protected def tlsEnable = false

private val exe = if (sys.props("os.name").toLowerCase.contains("windows")) ".exe" else ""
val scriptPath = BazelRunfiles.rlocation("daml-script/runner/daml-script-binary" + exe)
val darPath = BazelRunfiles.rlocation("daml-script/test/script-test.dar")

"daml-script command line" should {
"pick up all scripts and returns somewhat sensible outputs" in {
val expected =
"""MultiTest:listKnownPartiesTest SUCCESS
|MultiTest:multiTest SUCCESS
|MultiTest:partyIdHintTest SUCCESS
|ScriptExample:allocateParties SUCCESS
|ScriptExample:initializeFixed SUCCESS
|ScriptExample:initializeUser SUCCESS
|ScriptExample:test SUCCESS
|ScriptTest:clearUsers SUCCESS
|ScriptTest:failingTest FAILURE (com.daml.lf.engine.script.ScriptF$FailedCmd: Command submit failed: FAILED_PRECONDITION: DAML_INTERPRETATION_ERROR(9,XXXXXXXX): Interpretation error: Error: Unhandled Daml exception: DA.Exception.AssertionFailed:AssertionFailed@3f4deaf1{ message = "Assertion failed" }. Details: Last location: [DA.Internal.Exception:168], partial transaction: ...
|ScriptTest:listKnownPartiesTest SUCCESS
|ScriptTest:multiPartySubmission SUCCESS
|ScriptTest:partyIdHintTest SUCCESS
|ScriptTest:sleepTest SUCCESS
|ScriptTest:stackTrace FAILURE (com.daml.lf.engine.script.ScriptF$FailedCmd: Command submit failed: FAILED_PRECONDITION: DAML_INTERPRETATION_ERROR(9,XXXXXXXX): Interpretation error: Error: Unhandled Daml exception: DA.Exception.AssertionFailed:AssertionFailed@3f4deaf1{ message = "Assertion failed" }. Details: Last location: [DA.Internal.Exception:168], partial transaction: ...
|ScriptTest:test0 SUCCESS
|ScriptTest:test1 SUCCESS
|ScriptTest:test3 SUCCESS
|ScriptTest:test4 SUCCESS
|ScriptTest:testCreateAndExercise SUCCESS
|ScriptTest:testGetTime SUCCESS
|ScriptTest:testKey SUCCESS
|ScriptTest:testMaxInboundMessageSize SUCCESS
|ScriptTest:testMultiPartyQueries SUCCESS
|ScriptTest:testQueryContractId SUCCESS
|ScriptTest:testQueryContractKey SUCCESS
|ScriptTest:testSetTime SUCCESS
|ScriptTest:testStack SUCCESS
|ScriptTest:testUserListPagination SUCCESS
|ScriptTest:testUserManagement SUCCESS
|ScriptTest:testUserRightManagement SUCCESS
|ScriptTest:traceOrder SUCCESS
|ScriptTest:tree SUCCESS
|ScriptTest:tupleKey SUCCESS
|""".stripMargin

val port = suiteResource.value.head.value

import scala.sys.process._
val builder = new StringBuilder
def log(s: String) = discard(builder.append(s).append('\n'))

val cmd = Seq(
scriptPath,
"--all",
"--static-time",
"--dar",
darPath,
"--max-inbound-message-size",
"41943040",
"--ledger-host",
"localhost",
"--ledger-port",
port.toString,
)

cmd ! ProcessLogger(log, log)

val actual = builder
.toString()
.linesIterator
.filter(s => List("SUCCESS", "FAILURE").exists(s.contains))
.mkString("", f"%n", f"%n")
// ignore partial transactions as parties, cids, and package Ids are pretty unpredictable
.replaceAll("partial transaction: .*", "partial transaction: ...")
.replaceAll(
"""DAML_INTERPRETATION_ERROR\((\d+),\w{8}\)""",
"DAML_INTERPRETATION_ERROR($1,XXXXXXXX)",
)

if (cantonFixtureDebugMode) {
Files.writeString(tmpDir.resolve(getClass.getSimpleName + ".expected"), expected)
Files.writeString(tmpDir.resolve(getClass.getSimpleName + ".actual"), actual)
}

actual shouldBe expected
}
}
}

0 comments on commit c20fc05

Please sign in to comment.