Skip to content

Commit

Permalink
Update proto files, sample code and unit tests. (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
scalarindetail authored Mar 17, 2021
1 parent 07785b6 commit 014f00b
Show file tree
Hide file tree
Showing 15 changed files with 6,779 additions and 2,237 deletions.
28 changes: 0 additions & 28 deletions .circleci/README.md

This file was deleted.

14 changes: 14 additions & 0 deletions .circleci/README_CI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Setting up CircleCI for Scalar DL Node/Web client SDK

### Environment Variables

Set environment variables on CircleCi by following [this guide](https://circleci.com/blog/new-on-circleci-import-project-environment-variables/).
Please set environment variables in CircleCi as follows.

Set the environment variables in the [Context](https://circleci.com/gh/organizations/scalar-labs/settings#contexts) with the name `scalar`.
<pre>
<b>$GHCR_USERNAME</b>
<b>$GHCR_PAT</b>
</pre>

[Here](https://github.com/scalarindetail/scalardl-node-client-sdk/blob/feature/integration_test/.circleci/config.yml) is the configuration file.
85 changes: 49 additions & 36 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,9 @@
version: 2
jobs:
build:
docker:
machine: true
# set a fixed version for the image circleci/openjdk:8-jdk-node-browsers
- image: circleci/openjdk:8-jdk-node-browsers
environment:
MAX_HEAP_SIZE: 2048m
HEAP_NEWSIZE: 512m

- image: cassandra:3.11
environment:
MAX_HEAP_SIZE: 1300m
HEAP_NEWSIZE: 512m

- image: scalarlabs/scalar-ledger:2.0.2
auth:
username: $DOCKERHUB_USERNAME
password: $DOCKERHUB_PASSWORD
environment:
SCALAR_CASSANDRA_HOST: 127.0.0.1
MAX_HEAP_SIZE: 500m
HEAP_NEWSIZE: 512m
image: ubuntu-2004:202101-01

working_directory: ~/scalardl-node-client-sdk

Expand All @@ -36,35 +19,64 @@ jobs:
- dependency-cache-{{ checksum "package-lock.json" }}

- run:
name: Install cqlsh
# We need to edit DEFAULT_CQLVER defined in the cqlsh script
# to connect to the server without --cqlversion command line option
name: Docker login
command: |
curl -O https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
sudo pip install cqlsh
sudo sed -i "s/^DEFAULT_CQLVER = .*/DEFAULT_CQLVER = '3.4.4'/" /usr/local/bin/cqlsh
echo ${GHCR_PAT} | docker login https://ghcr.io -u ${GHCR_USERNAME} --password-stdin
- run:
name: Wait for Cassandra
# dockerize command is included in circleci/openjdk:8-jdk image
command: dockerize -wait tcp://127.0.0.1:9042 -timeout 1m
name: Update docker and docker compose
command: |
sudo apt-get purge docker-ce containerd.io
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
- run:
name: Install schema on Cassandra
command: cqlsh --execute "$SCHEMA_CONTENT" 127.0.0.1 9042
name: checkout scalar-samples repository as it contains the script to spin up scalardl environment and easier for us to maintain the CI
command: |
git init
git pull https://${GHCR_USERNAME}:${GITHUB_PASSWORD}@github.com/scalar-labs/scalar-samples.git
working_directory: .circleci/


- run:
name: Install schema for function purpose on Cassandra
command: cqlsh -f .circleci/function_schema.cql 127.0.0.1 9042
name: Start Scalar DL environment
command: docker-compose -f docker-compose.yml -f docker-compose-open-cassandra-port.yml up -d
working_directory: .circleci/

- run:
name: Wait for Scalardl
command: dockerize -wait tcp://127.0.0.1:50051 -timeout 1m
name: Install [email protected] # Update node for karma to work
command: |
export NVM_DIR="/opt/circleci/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install v14.16.0
nvm alias default v14.16.0
echo 'export NVM_DIR="/opt/circleci/.nvm"' >> $BASH_ENV
echo "[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\"" >> $BASH_ENV
- run:
name: Install npm
command: npm install

- run:
name: Wait for Cassandra to spin up to be able to update the Cassandra schema in the next step
command: |
echo -n "Wait for C* "
until docker exec scalar-samples-cassandra-1 cqlsh 2> /dev/null ; do
sleep 0.5
echo -n "#"
done
- run:
name: Insert function table and wait
command: |
docker cp function_schema.cql \
scalar-samples-cassandra-1:function_schema.cql
docker exec scalar-samples-cassandra-1 cqlsh -f function_schema.cql
sleep 10
working_directory: .circleci/

- save_cache:
key: v1-dependencies-{{ checksum "package-lock.json" }}
paths:
Expand All @@ -84,7 +96,8 @@ jobs:
path: ~/scalardl-node-client-sdk/mochawesome-report
deploy:
docker:
- image: circleci/node
#Node LTS 14.16 "fermium"
- image: circleci/node:14.16
steps:
- checkout
- run:
Expand Down
6 changes: 6 additions & 0 deletions .circleci/docker-compose-open-cassandra-port.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "3.5"
services:
cassandra:
ports:
- "9042:9042"

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules/
mochawesome-report/
.idea/
out/
.gradle
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v14.16.0
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## Scalar DL Node Client SDK
# Scalar DL Node Client SDK

This is a library for Node.js applications by which the applications can interact with a [Scalar DL](https://github.com/scalar-labs/scalardl) network.

## Node version used for development and testing
This package has been developed and tested using Node LTS v14.16.0. named "fermium".
This means we cannot guarantee the package nominal behaviour when using other Node versions.

## Install

We can use any NPM package manager to install this library. For example, to install with NPM:
Expand Down
4 changes: 2 additions & 2 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const path = require('path');
path.join(
__dirname,
'..',
'test/StateUpdater.class'
'test/StateUpdater.class',
)
);
const contractId =
Expand Down Expand Up @@ -105,7 +105,7 @@ const path = require('path');
console.log(r);

console.log('Validate ledger');
r = await clientService.validateLedger('foo');
r = await clientService.validateLedger('foo', 0, 1);
console.log(r);
} catch (e) {
console.log(`${e.code} ${e.message}`);
Expand Down
Loading

0 comments on commit 014f00b

Please sign in to comment.