Skip to content

Commit

Permalink
Add js libs (#52)
Browse files Browse the repository at this point in the history
* add js libs

* un-submodule js

* fix pipeline branch

* fix test

* remove duplicate simulation

* debug node location;

* fix cache locations

* fix simulation path

* debug proving key and node paths

* debug proving key and node paths

* debug proving key and node paths

* debug proving key and node paths

* debug proving key and node paths

* cleanup

* cleanup

* fix test runner

* fix test runner

* fix test runner

* debug; try build without test

* update gitignore

* stop uselessly caching manta node

* debug: change workflow names?

* runner os -> matrix os

* get node from S3

* get node from S3

* remove dists

* remove junk
  • Loading branch information
Kevingislason authored Feb 9, 2022
1 parent 3f3f8a1 commit 1c62b27
Show file tree
Hide file tree
Showing 77 changed files with 5,884 additions and 13 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: End-to-end test
on:
push:
branches:
- master
paths-ignore:
- '**.md'
pull_request:
branches:
- master
paths-ignore:
- '**.md'

jobs:
build_code:
name: End to end test
runs-on: ubuntu-latest
timeout-minutes: 120
strategy:
matrix:
node-version: [16.x]
env:
MANTA_SDK_BRANCH: "main"

steps:
- name: Cancel previous runs
uses: styfle/cancel-workflow-action@0.9.1
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Build manta-signer test server
run: cargo build --example test_server --release --features=unsafe-disable-cors
- name: Build manta-js
run: |
cd js
yarn install --immutable | grep -v 'YN0013'
yarn build
- name: Enable test scripts
run: |
chmod +x "${GITHUB_WORKSPACE}/.github/workflows/e2e/get_latest_sdk_version.sh"
chmod +x "${GITHUB_WORKSPACE}/.github/workflows/e2e/move_proving_keys.sh"
chmod +x "${GITHUB_WORKSPACE}/.github/workflows/e2e/get_node.sh"
chmod +x "${GITHUB_WORKSPACE}/.github/workflows/e2e/run_test.sh"
- name: Get latest Manta sdk version
run: |
LATEST_SDK_VERSION=`"${GITHUB_WORKSPACE}/.github/workflows/e2e/get_latest_sdk_version.sh" ${{ env.MANTA_SDK_BRANCH }}`
echo $LATEST_SDK_VERSION
echo "LATEST_SDK_VERSION=$LATEST_SDK_VERSION" >> $GITHUB_ENV
- name: Load proving keys from cache
id: load-cache-proving-keys
uses: actions/cache@v2
env:
cache-name: proving-keys
with:
path: ~/.local/share/manta-signer
key: ${{ env.cache-name }}-${{ env.LATEST_SDK_VERSION }}
- name: Get proving keys
if: steps.load-cache-proving-keys.outputs.cache-hit != 'true'
uses: actions/checkout@v2
with:
repository: Manta-Network/sdk
path: sdk
fetch-depth: 1
lfs: true
- name: Move proving keys
if: steps.load-cache-proving-keys.outputs.cache-hit != 'true'
run: "${GITHUB_WORKSPACE}/.github/workflows/e2e/move_proving_keys.sh"

- name: Get Dolphin node
run: "${GITHUB_WORKSPACE}/.github/workflows/e2e/get_node.sh"

- name: Run test
run: "${GITHUB_WORKSPACE}/.github/workflows/e2e/run_test.sh"
4 changes: 4 additions & 0 deletions .github/workflows/e2e/get_latest_sdk_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
BRANCH=$1

git ls-remote https://github.com/manta-network/sdk.git $BRANCH | awk '{ print $1}'
7 changes: 7 additions & 0 deletions .github/workflows/e2e/get_node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

cd ~
mkdir Manta
cd Manta
curl https://manta-ops.s3.amazonaws.com/Dolphin-v0.2.1-841eb2f-x86_64-linux-gnu/manta --output manta
chmod +x manta
7 changes: 7 additions & 0 deletions .github/workflows/e2e/move_proving_keys.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

mkdir ~/.local
mkdir ~/.local/share
mkdir ~/.local/share/manta-signer
cp ./sdk/zkp/reclaim_pk.bin ~/.local/share/manta-signer
cp ./sdk/zkp/transfer_pk.bin ~/.local/share/manta-signer
21 changes: 21 additions & 0 deletions .github/workflows/e2e/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Create 10-round simulation instructions and save output
cd js/e2e/simulation
cargo run 10 | tail -n +2 > out.json
cat out.json

# Run 3 headless copies of signer
cd ../../..
cargo run --example test_server --release --features=unsafe-disable-cors -- http://127.0.0.1:29988 &
cargo run --example test_server --release --features=unsafe-disable-cors -- http://127.0.0.1:29989 &
cargo run --example test_server --release --features=unsafe-disable-cors -- http://127.0.0.1:29990 &

# Run node
~/Manta/manta --chain dev --ws-port 9944 --port 30333 --alice \
--tmp --rpc-cors all --unsafe-ws-external --unsafe-rpc-external \
--rpc-methods=Unsafe &

# Run test
cd js
yarn test
24 changes: 12 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Build and upload binaries
name: Build and upload release binaries

on:
pull_request:
branches:
branches:
- master
release:
types: [published]
Expand Down Expand Up @@ -52,22 +52,22 @@ jobs:
cache-name: cache-cargo
with:
path: ~/.cargo
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./ui/src-tauri/Cargo.lock') }}
key: ${{ matrix.os }}-build-${{ env.cache-name }}-${{ hashFiles('./ui/src-tauri/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
${{ matrix.os }}-build-${{ env.cache-name }}-
${{ matrix.os }}-build-
${{ matrix.os }}-
- name: Cache target dir
uses: actions/cache@v2
env:
cache-name: cache-target
with:
path: ui/src-tauri/target
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./ui/src-tauri/Cargo.lock') }}
key: ${{ matrix.os }}-build-${{ env.cache-name }}-${{ hashFiles('./ui/src-tauri/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
${{ matrix.os }}-build-${{ env.cache-name }}-
${{ matrix.os }}-build-
${{ matrix.os }}-
- name: Fetch Proving Keys
uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -118,7 +118,7 @@ jobs:
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: "ui/src-tauri/target/release/bundle/msi/manta-signer_${{ needs.setup.outputs.release_version }}_x64.msi"
asset_name: "manta-signer-${{ matrix.os }}_${{ needs.setup.outputs.release_version }}_x64.msi"
asset_name: "manta-signer-${{ matrix.os }}_${{ needs.setup.outputs.release_version }}_x64.msi"
asset_content_type: application/binary
if: matrix.os_type == 'windows' && github.event_name == 'release' && github.event.action == 'published'
- name: Upload Mac Image
Expand All @@ -128,6 +128,6 @@ jobs:
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: "ui/src-tauri/target/release/bundle/dmg/manta-signer_${{ needs.setup.outputs.release_version }}_x64.dmg"
asset_name: "manta-signer-${{ matrix.os }}_${{ needs.setup.outputs.release_version }}_x64.dmg"
asset_name: "manta-signer-${{ matrix.os }}_${{ needs.setup.outputs.release_version }}_x64.dmg"
asset_content_type: application/binary
if: matrix.os_type == 'macos' && github.event_name == 'release' && github.event.action == 'published'
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
manta-signer
============

`manta-signer` is manta's native client that **turbo charges** zero-knowledge-proof generation.
`manta-signer` is manta's native client that **turbo charges** zero-knowledge-proof generation.

<img width="655" alt="Screen Shot 2021-11-21 at 3 50 01 PM" src="https://user-images.githubusercontent.com/720571/142786609-ce7455e1-dbe7-4a6d-8a78-4aa22984a3d7.png">

Expand All @@ -11,5 +11,6 @@ Disclaimer: `manta-signer` is experimental software, use it at your own risk.
```
-src: manta-signer zkp generation
-ui: manta-signer desktop UI
-js: external Javascript libraries that interact with manta-signer
```

1 change: 1 addition & 0 deletions js/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ESLINT_NO_DEV_ERRORS=true
30 changes: 30 additions & 0 deletions js/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
env:
commonjs: true
es2021: true
extends:
- standard
parser: '@typescript-eslint/parser'
parserOptions:
ecmaVersion: 12
plugins:
- '@typescript-eslint'
ignorePatterns: ['types.d.ts']
rules:
{
'indent': ['error', 2],
'linebreak-style': ['error', 'unix'],
'quotes': ['error', 'single'],
'semi': ['error', 'always'],
'space-before-function-paren': ['error', 'never'],
'comma-dangle':
[
'error',
{
'arrays': 'never',
'objects': 'never',
'imports': 'never',
'exports': 'never',
'functions': 'never'
}
]
}
6 changes: 6 additions & 0 deletions js/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"trailingComma": "none"
}
2 changes: 2 additions & 0 deletions js/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nodeLinker: node-modules
nmHoistingLimits: workspaces
63 changes: 63 additions & 0 deletions js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Signer JS Libraries

This workspace includes the following packages:

| name | path | description | status |
|------------------|---------------------|-----------------------------------------|---------------|
| dophin-api | `./dolphin-api` | api for dolphin nodes. | experimental |
| workflows | `./workflows` | logical workflows with extrinsics. | experimental |
| e2e | `./e2e` | end-to-end test suites. | experimental |
| singer-interface | `/signer-interface` | typescript interface for manta-signer. | experimental |
| coin-selection | `/coin-selection` | simple coin selection logic | experimental |


## Build
Tested environment:
* node: `v16.x`
* yarn: `1.22.x`

```yarn install && yarn build```

## Test Setup

1. Make sure you have a node running that you want to connect to.

```bash
git clone -b dolphin git@github.com:Manta-Network/Manta.git
cd Manta
cargo build --release
./target/release/manta --dev --tmp --alice --unsafe-ws-external
```

Which will be live at `ws://127.0.0.1:9944`.

2. [Run manta-signer test server](https://github.com/Manta-Network/manta-signer/tree/master/examples)


## Tests
You can run the entire testsuite with

```yarn run e2e test```


### Create a new test
The test suite is set up using [mocha](https://mochajs.org/) as the test runner and [chai](https://www.chaijs.com/) for the assertion library.
Both projects have good documentation on how to use them.

Add a new test by adding a `describe()` call in `e2e/test/test.ts`.


## Workflows
To create a new workflow to be uses in `dev-cli` or `e2e` tests,
start by choosing a name for your workflow. Then create a copy of
`/manta-workflows/src/workflows/init_asset_workflow.ts` with the new name, and
replace all instances of `initAssetWorkflow` in the file with the new name.

Both repositories already have `manta-workflows` as a dependency, so to use a
workflow recompile the project:

```yarn run workflows build```

And then import your workflow like

``` import { initAssetWorkflow } from 'manta-workflows';```
3 changes: 3 additions & 0 deletions js/coin-selection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Manta Coin Selection

Coin selection logic for Manta / Calamari Network, for now extremely basic
16 changes: 16 additions & 0 deletions js/coin-selection/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "coin-selection",
"version": "0.1.1",
"main": "dist/index.js",
"description": "Coin selection logic for Manta and Calamari Netowrk",
"license": "GPL-3.0-only",
"scripts": {
"build": "rm -rf coin-selection/dist ; tsc"
},
"dependencies": {
"bn.js": "^5.2.0"
},
"devDependencies": {
"typescript": "^4.4.4"
}
}
32 changes: 32 additions & 0 deletions js/coin-selection/src/coinSelection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// @ts-nocheck
export class CoinSelection {
constructor(coins, totalValueAtomicUnits, targetValueAtomicUnits, assetId) {
this.coins = coins;
this.totalValueAtomicUnits = totalValueAtomicUnits;
this.targetValueAtomicUnits = targetValueAtomicUnits;
this.assetId = assetId;
this.changeValueAtomicUnits = totalValueAtomicUnits.sub(
targetValueAtomicUnits
);
}

numberOfZeroCoinsRequired() {
return Math.max(0, 2 - this.coins.length);
}

last() {
const last = this.coins[this.coins.length - 1];
if (!last) {
throw new Error('Coin selection does not contain any coins');
}
return last;
}

secondLast() {
const secondLast = this.coins[this.coins.length - 2];
if (!secondLast) {
throw new Error('Coin selection contains fewer than two coins');
}
return secondLast;
}
}
4 changes: 4 additions & 0 deletions js/coin-selection/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { CoinSelection } from './coinSelection.js';
import { selectCoins } from './selectCoins.js';

export { CoinSelection, selectCoins };
Loading

0 comments on commit 1c62b27

Please sign in to comment.