Skip to content

Commit

Permalink
[Script] move test_daml_script_test_runner from sandbox to canton
Browse files Browse the repository at this point in the history
  • Loading branch information
remyhaemmerle-da committed Mar 28, 2023
1 parent f4cc3e6 commit bfaa652
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 38 deletions.
21 changes: 13 additions & 8 deletions daml-script/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ da_scala_test_suite(
"//ledger/participant-integration-api",
"//ledger/participant-integration-api:participant-integration-api-tests-lib",
"//ledger/participant-state",
"//ledger/sandbox-on-x",
"//ledger/sandbox-on-x:sandbox-on-x-test-lib",
"//libs-scala/contextualized-logging",
"//libs-scala/jwt",
"//libs-scala/ledger-resources",
Expand All @@ -239,18 +237,25 @@ 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)",
"$(location //daml-script/runner:daml-script-binary)",
"$(location :script-test.dar)",
"$(POSIX_DIFF)",
"$(POSIX_GREP)",
"$(POSIX_SED)",
"$(rootpath //ledger/sandbox-on-x:app)",
"$(location @jq_dev_env//:jq)",
"$(location :canton)",
],
data = [
":canton",
":script-test.dar",
"//:java",
"//daml-script/runner:daml-script-binary",
"//ledger/sandbox-on-x:app",
"@jq_dev_env//:jq",
],
toolchains = ["@rules_sh//sh/posix:make_variables"],
deps = ["@bazel_tools//tools/bash/runfiles"],
)

java_binary(
name = "canton",
main_class = "com.digitalasset.canton.CantonCommunityApp",
runtime_deps = ["@canton//:lib"],
)
82 changes: 52 additions & 30 deletions daml-script/test/daml-script-test-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,71 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \

set -euo pipefail

TEST_RUNNER=$(rlocation $TEST_WORKSPACE/$1)
DAR_FILE=$(rlocation $TEST_WORKSPACE/$2)
DIFF=$3
GREP=$4
SED=$5
SANDBOX=$(rlocation $TEST_WORKSPACE/$6)

PORTFILE_DIR=$(mktemp -d)
PORTFILE=$PORTFILE_DIR/port-file
$SANDBOX run-legacy-cli-config --participant=participant-id=example,port=0,port-file=$PORTFILE --stack-traces=true --static-time --enable-user-management=true &
SANDBOX_PID=$!
test_runner=$1; shift
dar_file=$1; shift
diff=$1; shift
jq=$1; shift
canton_binary=$1; shift

tmp_dir=$(mktemp -d)
canton_conf=${tmp_dir}/canton.conf
portsfile=${tmp_dir}/portsfile


cat << EOF | grep -v '#' > ${canton_conf}
canton {
parameters = {
ports-file = ${portsfile}
clock.type = sim-clock
}
domains.test_domain.storage.type = memory
participants.participant = {
storage.type=memory
testing-time.type = monotonic-time
}
}
EOF

${canton_binary} daemon -v --auto-connect-local -c ${canton_conf} &
canton_pid=$!

cleanup() {
kill $SANDBOX_PID || true
rm -rf $PORTFILE_DIR
kill ${canton_pid} || true
rm -rf ${tmp_dir}
}

trap cleanup EXIT

while [ ! -f $PORTFILE ]
do
sleep 0.5
attempts=0
while [ ! -f ${portsfile} ]; do
if [[ ${attempts} -le 60 ]]; then
attempts=$(( attempts + 1 ))
sleep 1
else
echo "Canton startup timeout"
exit 1
fi
done

PORT=$(cat $PORTFILE)
port=$(${jq} -r .participant.ledgerApi ${portsfile})

set +e
TEST_OUTPUT="$($TEST_RUNNER --all --static-time --dar=$DAR_FILE --max-inbound-message-size 41943040 --ledger-host localhost --ledger-port $PORT 2>&1)"
TEST_RESULT=$?
test_output="$(${test_runner} --all --static-time --dar=${dar_file} --max-inbound-message-size 41943040 --ledger-host localhost --ledger-port ${port} 2>&1)"
test_result=$?
set -e

echo "-- Runner Output -----------------------" >&2
echo "$TEST_OUTPUT" >&2
echo "${test_output}" >&2
echo "----------------------------------------" >&2

FAIL=
fail=

if [[ $TEST_RESULT = 0 ]]; then
FAIL=1
if [[ ${test_result} = 0 ]]; then
fail=1
echo "Expected non-zero exit-code." >&2
fi

EXPECTED="$(cat <<'EOF'
expected="$(cat <<'EOF'
MultiTest:listKnownPartiesTest SUCCESS
MultiTest:multiTest SUCCESS
MultiTest:partyIdHintTest SUCCESS
Expand All @@ -65,12 +87,12 @@ 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: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: [unknown source], 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: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: [unknown source], partial transaction:
ScriptTest:test0 SUCCESS
ScriptTest:test1 SUCCESS
ScriptTest:test3 SUCCESS
Expand All @@ -94,12 +116,12 @@ EOF
)"

# We strip away the actual partial transaction since contract ids are not deterministic.
ACTUAL="$(echo -n "$TEST_OUTPUT" | $GREP "SUCCESS\|FAILURE" | $SED 's/partial transaction: .*$/partial transaction:/g; s/INTERPRETATION_ERROR(\([[:digit:]]\),.\{8\})/INTERPRETATION_ERROR(\1,XXXXXXXX)/g')"
actual="$(echo -n "${test_output}" | grep "SUCCESS\|FAILURE" | sed 's/partial transaction: .*$/partial transaction:/g; s/INTERPRETATION_ERROR(\([[:digit:]]\),.\{8\})/INTERPRETATION_ERROR(\1,XXXXXXXX)/g')"

if ! $DIFF -du0 --label expected <(echo -n "$EXPECTED") --label actual <(echo -n "$ACTUAL") >&2; then
FAIL=1
if ! ${diff} -du0 --label expected <(echo -n "${expected}") --label actual <(echo -n "${actual}") >&2; then
fail=1
fi

if [[ $FAIL = 1 ]]; then
if [[ ${fail} = 1 ]]; then
exit 1
fi

0 comments on commit bfaa652

Please sign in to comment.