daml/daml-script/test/BUILD.bazel
Moritz Kiefer d4d0419c64
Use TO_TEXT_CONTRACT_ID in Show instance of ContractId (#7153)
fixes #7114

This PR changes the Show instance of ContractId and flips the switch
on triggers and DAML Script to run in off-ledger mode.

It also adds a test that for DAML Script we actually get back the
correct contract id.

There is a bit of a design decision here in how we want to print
contract ids, so let me list the options I considered. $cid will stand
for the actual cid and all options are wrapped in markdown inline
code.

1. `"$cid"`. Indistinguishable from string. Suggests that there might
be an IsString instance for ContractId.
2. `<$cid>`. Matches the dummy `<contract-id>` but it’s not a dummy so
I don’t think matching that is benefitial.
3. `$cid`. Easy to spot (contract ids start with # and have no
spaces), clearly not a string but might look slightly weird.

changelog_begin

- [DAML Script/DAML Triggers] When using DAML-LF 1.dev, the `Show` instance of `ContractId` will now display the actual contract id instead of a dummy `<contract-id>` value. Note that this only applies to DAML Script and DAML Triggers not to ledger code.

changelog_end
2020-08-17 17:06:24 +02:00

349 lines
10 KiB
Python

# Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
load(
"//bazel_tools:scala.bzl",
"da_scala_binary",
"da_scala_library",
"da_scala_test_suite",
)
load(
"//bazel_tools/client_server:client_server_test.bzl",
"client_server_test",
)
load("//bazel_tools:haskell.bzl", "da_haskell_test")
load("@build_environment//:configuration.bzl", "sdk_version")
genrule(
name = "script-test",
srcs =
glob(["**/*.daml"]) + [
"//daml-script/daml:daml-script.dar",
"//docs:source/daml-script/template-root/src/ScriptExample.daml",
],
outs = ["script-test.dar"],
cmd = """
set -eou pipefail
TMP_DIR=$$(mktemp -d)
mkdir -p $$TMP_DIR/daml
cp -L $(location :daml/ScriptTest.daml) $$TMP_DIR/daml
cp -L $(location :daml/MultiTest.daml) $$TMP_DIR/daml
cp -L $(location //docs:source/daml-script/template-root/src/ScriptExample.daml) $$TMP_DIR/daml
cp -L $(location //daml-script/daml:daml-script.dar) $$TMP_DIR/
cat << EOF > $$TMP_DIR/daml.yaml
sdk-version: {sdk}
name: script-test
source: daml
version: 0.0.1
dependencies:
- daml-stdlib
- daml-prim
- daml-script.dar
EOF
$(location //compiler/damlc) build --project-root=$$TMP_DIR -o $$PWD/$(location script-test.dar)
rm -rf $$TMP_DIR
""".format(sdk = sdk_version),
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)
# Test DAR in 1.dev to test new features.
genrule(
name = "script-test-1.dev",
srcs =
glob(["**/*.daml"]) + ["//daml-script/daml:daml-script-1.dev.dar"],
outs = ["script-test-1.dev.dar"],
cmd = """
set -eou pipefail
TMP_DIR=$$(mktemp -d)
mkdir -p $$TMP_DIR/daml
cp -L $(location :daml/TestContractId.daml) $$TMP_DIR/daml
cp -L $(location //daml-script/daml:daml-script-1.dev.dar) $$TMP_DIR/
cat << EOF > $$TMP_DIR/daml.yaml
sdk-version: {sdk}
name: script-test-1dev
version: 0.0.1
source: daml
build-options:
- --target=1.dev
dependencies:
- daml-stdlib
- daml-prim
- daml-script-1.dev.dar
EOF
$(location //compiler/damlc) build --project-root=$$TMP_DIR -o $$PWD/$(location script-test-1.dev.dar)
rm -rf $$TMP_DIR
""".format(sdk = sdk_version),
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)
# A variant of script-test that has not been uploaded to the ledger
# to test missing template ids. We only care that this has a different package id.
genrule(
name = "script-test-no-ledger",
srcs =
glob(["**/*.daml"]) + [
"//daml-script/daml:daml-script.dar",
"//docs:source/daml-script/template-root/src/ScriptExample.daml",
],
outs = ["script-test-no-ledger.dar"],
cmd = """
set -eou pipefail
TMP_DIR=$$(mktemp -d)
mkdir -p $$TMP_DIR/daml
cp -L $(location :daml/ScriptTest.daml) $$TMP_DIR/daml
cp -L $(location //daml-script/daml:daml-script.dar) $$TMP_DIR/
cat << EOF > $$TMP_DIR/daml.yaml
sdk-version: {sdk}
name: script-test-no-ledger
source: daml
version: 0.0.2
dependencies:
- daml-stdlib
- daml-prim
- daml-script.dar
EOF
$(location //compiler/damlc) build --project-root=$$TMP_DIR -o $$PWD/$(location script-test-no-ledger.dar)
rm -rf $$TMP_DIR
""".format(sdk = sdk_version),
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)
da_scala_library(
name = "test-lib",
srcs = glob(
["src/**/*.scala"],
exclude = ["src/com/digitalasset/daml/lf/engine/script/test/JsonApiIt.scala"],
),
resources = glob(["src/main/resources/**/*"]),
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",
"//daml-script/runner:script-runner-lib",
"//language-support/scala/bindings",
"//language-support/scala/bindings-akka",
"//ledger-api/rs-grpc-bridge",
"//ledger-service/jwt",
"//ledger/ledger-api-auth",
"//ledger/ledger-api-common",
"@maven//:com_github_scopt_scopt_2_12",
"@maven//:com_typesafe_akka_akka_stream_2_12",
"@maven//:io_spray_spray_json_2_12",
"@maven//:org_scalaz_scalaz_core_2_12",
],
)
da_scala_binary(
name = "test_client_single_participant",
main_class = "com.daml.lf.engine.script.test.SingleParticipant",
deps = [
":test-lib",
"//libs-scala/auth-utils",
],
)
da_scala_binary(
name = "test_client_multi_participant",
main_class = "com.daml.lf.engine.script.test.MultiParticipant",
deps = [":test-lib"],
)
da_scala_test_suite(
name = "test_json",
srcs = [
"src/com/digitalasset/daml/lf/engine/script/test/JsonApiIt.scala",
],
data = [
":script-test.dar",
":script-test-no-ledger.dar",
],
resources = glob(["src/main/resources/**/*"]),
deps = [
":test-lib",
"//bazel_tools/runfiles:scala_runfiles",
"//daml-lf/archive:daml_lf_archive_reader",
"//daml-lf/archive:daml_lf_dev_archive_java_proto",
"//daml-lf/data",
"//daml-lf/interface",
"//daml-lf/interpreter",
"//daml-lf/language",
"//daml-script/runner:script-runner-lib",
"//language-support/scala/bindings",
"//language-support/scala/bindings-akka",
"//ledger-api/rs-grpc-bridge",
"//ledger-api/testing-utils",
"//ledger-service/http-json",
"//ledger-service/jwt",
"//ledger/caching",
"//ledger/ledger-api-auth",
"//ledger/ledger-api-common",
"//ledger/participant-integration-api",
"//ledger/participant-integration-api:participant-integration-api-tests-lib",
"//ledger/participant-state",
"//ledger/sandbox-classic",
"//ledger/sandbox-classic:sandbox-classic-scala-tests-lib",
"//ledger/sandbox-common",
"//ledger/sandbox-common:sandbox-common-scala-tests-lib",
"//ledger/test-common",
"//libs-scala/auth-utils",
"//libs-scala/ports",
"//libs-scala/resources",
"@maven//:com_auth0_java_jwt",
"@maven//:com_github_scopt_scopt_2_12",
"@maven//:com_google_guava_guava",
"@maven//:com_typesafe_akka_akka_http_core_2_12",
"@maven//:com_typesafe_akka_akka_stream_2_12",
"@maven//:io_spray_spray_json_2_12",
"@maven//:org_scalaz_scalaz_core_2_12",
],
)
client_server_test(
name = "test_static_time",
client = ":test_client_single_participant",
client_files = [
"$(rootpath :script-test.dar)",
"$(rootpath :script-test-1.dev.dar)",
],
data = [
":script-test.dar",
":script-test-1.dev.dar",
],
server = "//ledger/sandbox-classic:sandbox-classic-binary",
server_args = [
"--static-time",
"--port=0",
],
server_files = [
"$(rootpath :script-test.dar)",
"$(rootpath :script-test-1.dev.dar)",
],
)
client_server_test(
name = "test_wallclock_time",
client = ":test_client_single_participant",
client_args = ["-w"],
client_files = [
"$(rootpath :script-test.dar)",
"$(rootpath :script-test-1.dev.dar)",
],
data = [
":script-test.dar",
":script-test-1.dev.dar",
],
server = "//ledger/sandbox-classic:sandbox-classic-binary",
server_args = [
"--wall-clock-time",
"--port=0",
],
server_files = [
"$(rootpath :script-test.dar)",
"$(rootpath :script-test-1.dev.dar)",
],
)
client_server_test(
name = "test_wallclock_time_authenticated",
client = ":test_client_single_participant",
client_args = [
"-w",
"--auth",
],
client_files = [
"$(rootpath :script-test.dar)",
"$(rootpath :script-test-1.dev.dar)",
],
data = [
":script-test.dar",
":script-test-1.dev.dar",
],
server = "//ledger/sandbox-classic:sandbox-classic-binary",
server_args = [
"--wall-clock-time",
"--port=0",
"--auth-jwt-hs256-unsafe=secret",
],
server_files = ["$(rootpath :script-test.dar)"],
)
client_server_test(
name = "test_wallclock_time_tls",
client = ":test_client_single_participant",
client_args = [
"-w",
"--cacrt $$(rlocation $$TEST_WORKSPACE/$(rootpath //ledger/test-common/test-certificates:ca.crt))",
],
client_files = [
"$(rootpath :script-test.dar)",
"$(rootpath :script-test-1.dev.dar)",
],
data = [
":script-test.dar",
":script-test-1.dev.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-classic:sandbox-classic-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 :script-test.dar)",
"$(rootpath :script-test-1.dev.dar)",
],
)
client_server_test(
name = "test_multiparticipant",
client = ":test_client_multi_participant",
client_args = [
"-w",
"--target-port=6865",
"--extra-participant-port=6866",
],
client_files = ["$(rootpath :script-test.dar)"],
data = [":script-test.dar"],
runner = "@//bazel_tools/client_server/runner_with_port_check:runner",
runner_args = [
"6865",
"6866",
],
server = "//ledger/ledger-on-memory:app",
server_args = [
"--participant participant-id=daml_on_x,port=6865",
"--participant participant-id=daml_on_x2,port=6866",
],
server_files = ["$(rootpath :script-test.dar)"],
tags = ["exclusive"],
)
sh_test(
name = "test_daml_script_test_runner",
srcs = [":daml-script-test-runner.sh"],
args = [
"$(rootpath //daml-script/runner:test-runner)",
"$(rootpath :script-test.dar)",
"$(POSIX_DIFF)",
"$(POSIX_GREP)",
"$(POSIX_SORT)",
],
data = [
":script-test.dar",
"//daml-script/runner:test-runner",
],
toolchains = ["@rules_sh//sh/posix:make_variables"],
deps = ["@bazel_tools//tools/bash/runfiles"],
)