daml/triggers/tests/BUILD.bazel
Samir Talwar cbeeb5aafc
sandbox: Fail to start if a time mode is not explicitly specified. (#5033)
* sandbox: Fail to start if a time mode is not explicitly specified.

CHANGELOG_BEGIN
- [Sandbox] Sandbox is switching from Static Time mode to Wall Clock
  Time mode as the default. To ensure that our users know about this,
  for one version, there will be no default time mode. Instead, users
  will have to explicitly select their preferred time mode by means of
  the `--static-time` or `--wall-clock-time` switches. In the next
  release, Wall Clock Time will become the default, and users who are
  happy with the defaults will no longer need to specify the time mode.
CHANGELOG_END

* daml-script|triggers: Specify time mode when testing against Sandbox.

* daml-assistant: Default the Sandbox to wall clock time.

CHANGELOG_BEGIN
- [DAML Assistant] Initializing a new DAML project adds a switch to
  ``daml.yaml`` to ensure Sandbox can continue to start with ``daml
  start``::

      sandbox-options:
        - --wall-clock-time
CHANGELOG_END

* docs: Update the DAML Script and Triggers docs to use Wall Clock time.

It's now what Sandbox will use by default when using `daml init`.

* docs: Change the Quickstart to run Sandbox in wall clock time.

This explains why the contract IDs may vary.

It also updates the manual release testing script to match.
2020-03-18 08:25:03 +00:00

188 lines
6.9 KiB
Python

# Copyright (c) 2020 The DAML Authors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
load(
"//bazel_tools:scala.bzl",
"da_scala_binary",
)
load(
"//bazel_tools/client_server:client_server_test.bzl",
"client_server_test",
)
load("@build_environment//:configuration.bzl", "sdk_version")
genrule(
name = "acs",
srcs =
glob(["**/*.daml"]) + [
"//triggers/daml:daml-trigger.dar",
"//docs:source/triggers/template-root/src/CopyTrigger.daml",
],
outs = ["acs.dar"],
cmd = """
set -eou pipefail
TMP_DIR=$$(mktemp -d)
mkdir -p $$TMP_DIR/daml
cp -L $(location :daml/ACS.daml) $$TMP_DIR/daml
cp -L $(location :daml/Retry.daml) $$TMP_DIR/daml
cp -L $(location :daml/ExerciseByKey.daml) $$TMP_DIR/daml
cp -L $(location :daml/Numeric.daml) $$TMP_DIR/daml
cp -L $(location :daml/CommandId.daml) $$TMP_DIR/daml
cp -L $(location :daml/PendingSet.daml) $$TMP_DIR/daml
cp -L $(location :daml/TemplateIdFilter.daml) $$TMP_DIR/daml
cp -L $(location :daml/Time.daml) $$TMP_DIR/daml
cp -L $(location :daml/Heartbeat.daml) $$TMP_DIR/daml
cp -L $(location //docs:source/triggers/template-root/src/CopyTrigger.daml) $$TMP_DIR/daml
cp -L $(location //triggers/daml:daml-trigger.dar) $$TMP_DIR/
cat << EOF > $$TMP_DIR/daml.yaml
sdk-version: {sdk}
name: acs
source: daml
version: 0.0.1
dependencies:
- daml-stdlib
- daml-prim
- daml-trigger.dar
EOF
$(location //compiler/damlc) build --project-root=$$TMP_DIR -o $$PWD/$(location acs.dar)
rm -rf $$TMP_DIR
""".format(sdk = sdk_version),
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)
da_scala_binary(
name = "test_client",
srcs = glob(["src/**/*.scala"]),
main_class = "com.digitalasset.daml.lf.engine.trigger.test.TestMain",
resources = ["//triggers/runner:src/main/resources/logback.xml"],
deps = [
"//daml-lf/archive:daml_lf_archive_reader",
"//daml-lf/archive:daml_lf_dev_archive_java_proto",
"//daml-lf/data",
"//daml-lf/interpreter",
"//daml-lf/language",
"//daml-lf/transaction",
"//language-support/scala/bindings",
"//language-support/scala/bindings-akka",
"//ledger-api/rs-grpc-bridge",
"//ledger/ledger-api-common",
"//libs-scala/auth-utils",
"//triggers/runner:trigger-runner-lib",
"@maven//:com_github_scopt_scopt_2_12",
"@maven//:com_typesafe_akka_akka_stream_2_12",
"@maven//:org_scalaz_scalaz_core_2_12",
],
)
client_server_test(
name = "test_static_time",
timeout = "long",
client = ":test_client",
client_files = ["$(rootpath :acs.dar)"],
data = [":acs.dar"],
server = "//ledger/sandbox:sandbox-binary",
server_args = [
"--static-time",
"--port=0",
],
server_files = ["$(rootpath :acs.dar)"],
)
client_server_test(
name = "test_wallclock_time",
timeout = "long",
client = ":test_client",
client_args = ["-w"],
client_files = ["$(rootpath :acs.dar)"],
data = [":acs.dar"],
server = "//ledger/sandbox:sandbox-binary",
server_args = [
"--wall-clock-time",
"--port=0",
],
server_files = ["$(rootpath :acs.dar)"],
)
client_server_test(
name = "test_wallclock_time_tls",
timeout = "long",
client = ":test_client",
client_args = [
"-w",
"--cacrt $(rlocation $TEST_WORKSPACE/$(rootpath //ledger/test-common/test-certificates:ca.crt))",
],
client_files = [
"$(rootpath :acs.dar)",
],
data = [
":acs.dar",
"//ledger/test-common/test-certificates:ca.crt",
"//ledger/test-common/test-certificates:server.crt",
"//ledger/test-common/test-certificates:server.pem",
],
server = "//ledger/sandbox:sandbox-binary",
server_args = [
"--wall-clock-time",
"--port=0",
"--crt $(rlocation $TEST_WORKSPACE/$(rootpath //ledger/test-common/test-certificates:server.crt))",
"--pem $(rlocation $TEST_WORKSPACE/$(rootpath //ledger/test-common/test-certificates:server.pem))",
"--client-auth=none",
],
server_files = ["$(rootpath :acs.dar)"],
)
AUTH_TOKEN = "I_CAN_HAZ_AUTH"
# This is a genrule so we can replace it by something nicer that actually generates the token
# from some readable input so we can change it more easily.
# For now, this corresponds to a token that has admin set to false
# and actAs to Alice1, …, Alice100
genrule(
name = "test-auth-token",
outs = ["test-auth-token.jwt"],
cmd = """
cat <<EOF > $(location test-auth-token.jwt)
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY3RBcyI6WyJBbGljZTEiLCJBbGljZTIiLCJBbGljZTMiLCJBbGljZTQiLCJBbGljZTUiLCJBbGljZTYiLCJBbGljZTciLCJBbGljZTgiLCJBbGljZTkiLCJBbGljZTEwIiwiQWxpY2UxMSIsIkFsaWNlMTIiLCJBbGljZTEzIiwiQWxpY2UxNCIsIkFsaWNlMTUiLCJBbGljZTE2IiwiQWxpY2UxNyIsIkFsaWNlMTgiLCJBbGljZTE5IiwiQWxpY2UyMCIsIkFsaWNlMjEiLCJBbGljZTIyIiwiQWxpY2UyMyIsIkFsaWNlMjQiLCJBbGljZTI1IiwiQWxpY2UyNiIsIkFsaW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enticated",
timeout = "long",
client = ":test_client",
client_args = ["--access-token-file"],
client_files = [
"$(rootpath :test-auth-token.jwt)",
"$(rootpath :acs.dar)",
],
data = [
":acs.dar",
":test-auth-token.jwt",
],
server = "//ledger/sandbox:sandbox-binary",
server_args = [
"--static-time",
"--port=0",
"--auth-jwt-hs256-unsafe={}".format(AUTH_TOKEN),
],
server_files = ["$(rootpath :acs.dar)"],
)
sh_test(
name = "list-triggers",
srcs = ["list-triggers.sh"],
args = [
"$(location //triggers/runner:trigger-runner)",
"$(location :acs.dar)",
],
data = [
":acs.dar",
"//triggers/runner:trigger-runner",
],
deps = [
"@bazel_tools//tools/bash/runfiles",
],
)