Skip to content

Commit

Permalink
Add first integration test (#11)
Browse files Browse the repository at this point in the history
Fixes #36

This is the first test to establish the testing framework: a script in
ran before the tests to ensure that the SDK 0.12.16 is installed and run
a sandbox with testing packages.

The LedgerIdentityClient is tested as a proof of concept before applying
this approach to other clients.

gRPC reflection service is also introduced for future use (feature
discovery to target multiple versions of the ledger).
  • Loading branch information
stefanobaghino-da authored and mergify[bot] committed May 15, 2019
1 parent 05b18d3 commit 192179e
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Expand Up @@ -2,6 +2,15 @@
*.iml
node_modules
src/generated
test/generated
proto
docs
lib
sandbox.port
test/integration/src/sandbox.err
test/integration/src/sandbox.out
test/integration/src/sandbox.log
test/integration/src/.package-database
test/integration/src/daml/*.hi
test/integration/src/daml/*.hie
test/integration/src/dist
21 changes: 13 additions & 8 deletions azure-pipelines.yml
Expand Up @@ -18,17 +18,22 @@ pr:
- master

pool:
name: 'linux-pool'
vmImage: 'ubuntu-16.04'
strategy:
matrix:
node_8_x:
node_version: 8.x
node_10_x:
node_version: 10.x
node_8_daml_0.12.16:
nodejs_version: 8.x
daml_sdk_version: 0.12.16
node_10_daml_0.12.16:
nodejs_version: 10.x
daml_sdk_version: 0.12.16

steps:
- task: NodeTool@0
- script: curl -sSL https://get.daml.com/ | sh && "$HOME"/.daml/bin/daml install $(daml_sdk_version)
displayName: Install DAML SDK $(daml_sdk_version)
- task: NodeTool@0
displayName: Install Node.js $(nodejs_version)
inputs:
versionSpec: $(node_version)

versionSpec: $(nodejs_version)
- script: npm run ci-pipeline
displayName: Build and test
18 changes: 18 additions & 0 deletions grpc-codegen.sh
Expand Up @@ -11,6 +11,7 @@ SDK_VERSION=100.12.16

PROTO_PATH="./proto"
OUT_PATH="./src/generated"
TEST_OUT_PATH="./test/generated"

function clean() {
(cd "$(dirname "${0}")" && rm -rf "$PROTO_PATH" "$OUT_PATH")
Expand All @@ -25,6 +26,8 @@ if [ ! -d "$PROTO_PATH" ]; then
curl -s https://digitalassetsdk.bintray.com/DigitalAssetSDK/com/digitalasset/daml-lf-archive-protos/"$SDK_VERSION"/daml-lf-archive-protos-"$SDK_VERSION".tar.gz | tar xz --strip-components 3
mkdir -p google/rpc
curl -s https://raw.githubusercontent.com/grpc/grpc/v"$GRPC_VERSION"/src/proto/grpc/status/status.proto > google/rpc/status.proto
mkdir -p grpc/reflection/v1alpha
curl -s https://raw.githubusercontent.com/grpc/grpc/v"$GRPC_VERSION"/src/proto/grpc/reflection/v1alpha/reflection.proto > grpc/reflection/v1alpha/reflection.proto
)
fi

Expand Down Expand Up @@ -59,3 +62,18 @@ if [ ! -d "$OUT_PATH" ]; then
--ts_out="${OUT_PATH}" \
"${PROTO_PATH}"/da/*.proto
fi

if [ ! -d "$TEST_OUT_PATH" ]; then
mkdir -p "$TEST_OUT_PATH"
grpc_tools_node_protoc \
--plugin="protoc-gen-grpc=`which grpc_tools_node_protoc_plugin`" \
--js_out="import_style=commonjs,binary:${TEST_OUT_PATH}" \
--proto_path="${PROTO_PATH}" \
--grpc_out="${TEST_OUT_PATH}" \
"${PROTO_PATH}"/grpc/reflection/v1alpha/reflection.proto
grpc_tools_node_protoc \
--plugin=protoc-gen-ts=`which protoc-gen-ts` \
--proto_path="${PROTO_PATH}" \
--ts_out="${TEST_OUT_PATH}" \
"${PROTO_PATH}"/grpc/reflection/v1alpha/reflection.proto
fi
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -12,9 +12,9 @@
"ci-pipeline": "npm ci && ./check-copy.sh && rm -rf proto src/generated && npm run pretest && npm run test-with-fixed-seed",
"release-docs": "rm -rf docs && typedoc --tsconfig tsconfig-docs.json --out ./docs/$(git describe --tags) src",
"prepack": "./grpc-codegen.sh && tsc --build tsconfig-dist.json && cp -r src/generated lib",
"pretest": "./grpc-codegen.sh && tsc --build tsconfig-dist.json && tsc --build tsconfig-test.json",
"test": "TS_NODE_COMPILER_OPTIONS=$(node compiler-options) mocha -r ts-node/register --reporter dot --recursive './test/**/*.spec.ts'",
"test-with-fixed-seed": "TS_NODE_COMPILER_OPTIONS=$(node compiler-options) mocha -r ts-node/register --jsverifyRngState 86f24ba518063e9c7d --recursive './test/**/*.spec.ts'"
"pretest": " ./sandbox-start.sh && ./grpc-codegen.sh && tsc --build tsconfig-dist.json && tsc --build tsconfig-test.json",
"test": "DAML_SANDBOX_PORT=$(cat sandbox.port) TS_NODE_COMPILER_OPTIONS=$(node compiler-options) mocha -r ts-node/register --reporter dot --recursive './test/**/*.spec.ts'",
"test-with-fixed-seed": "DAML_SANDBOX_PORT=$(cat sandbox.port) TS_NODE_COMPILER_OPTIONS=$(node compiler-options) mocha -r ts-node/register --jsverifyRngState 86f24ba518063e9c7d --recursive './test/**/*.spec.ts'"
},
"repository": {
"type": "git",
Expand Down
9 changes: 9 additions & 0 deletions reserve-port.js
@@ -0,0 +1,9 @@
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

const dummy = require('net').createServer(_socket => {});

dummy.listen(0, () => {
console.log(dummy.address().port);
dummy.close(_error => {})
});
13 changes: 13 additions & 0 deletions sandbox-start.sh
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
# Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

set -euxo pipefail

cd "$(dirname "${0}")"
DAML_SRC=test/integration/src

(cd "$DAML_SRC" && "$HOME"/.daml/bin/daml build)
PORT=$(node reserve-port)
echo "$PORT" > sandbox.port
(cd "$DAML_SRC" && "$HOME"/.daml/bin/daml sandbox -p "$PORT" dist/*.dar >sandbox.out 2>sandbox.err &)
26 changes: 26 additions & 0 deletions test/integration/LedgerIdentityClient.spec.ts
@@ -0,0 +1,26 @@
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import {expect} from 'chai';
import {LedgerIdentityClient} from "../../src/client/LedgerIdentityClient";
import {LedgerIdentityServiceClient as GrpcLedgerIdentityClient} from "../../src/generated/com/digitalasset/ledger/api/v1/ledger_identity_service_grpc_pb";
import {credentials} from "grpc";

describe("LedgerIdentityClient", () => {

const grpcClient = new GrpcLedgerIdentityClient(`127.0.0.1:${process.env['DAML_SANDBOX_PORT']}`, credentials.createInsecure());
const client = new LedgerIdentityClient(grpcClient);

it("should successfully contact the server and get back a ledger identifier", (done) => {
client.getLedgerIdentity((error, response) => {
expect(error).to.be.null;
expect(response).to.not.be.null;
if (response) {
expect(response).to.haveOwnProperty('ledgerId');
expect(response.ledgerId).to.be.a('string');
}
done();
});
});

});
12 changes: 12 additions & 0 deletions test/integration/src/daml.yaml
@@ -0,0 +1,12 @@
sdk-version: 0.12.16
name: IntegrationTests
source: daml/IntegrationTests.daml
parties:
- Alice
- Bob
exposed-modules:
- PingPong
version: '0.0.0'
dependencies:
- daml-prim
- daml-stdlib
39 changes: 39 additions & 0 deletions test/integration/src/daml/IntegrationTests.daml
@@ -0,0 +1,39 @@
-- Copyright (c) 2019, Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

daml 1.2
module IntegrationTests where

template Ping
with
sender: Party
receiver: Party
count: Int
where
signatory sender
observer receiver

controller receiver can
ReplyPong : ()
do
if count >= 3 then return ()
else do
create Pong with sender = receiver; receiver = sender; count = count + 1
return ()

template Pong
with
sender: Party
receiver: Party
count: Int
where
signatory sender
observer receiver

controller receiver can
ReplyPing : ()
do
if count >= 3 then return ()
else do
create Ping with sender = receiver; receiver = sender; count = count + 1
return ()

0 comments on commit 192179e

Please sign in to comment.