Skip to content

Commit

Permalink
Changing to brightinventions docker images
Browse files Browse the repository at this point in the history
Deploy scrpit starts useing brightinventions images for:
- node
- cliain
- ink
  • Loading branch information
mgralinski-bright committed Jul 28, 2023
1 parent 0fdc991 commit f4f06b5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 28 deletions.
44 changes: 27 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,43 @@
This project is a dApp for raising and solving the disputes on the Substrate-based blockchains. Process of building and running smart contract can be found in the sections bellow. Showcase scenario can be found in the [documentation](https://github.com/bright/bright-disputes/blob/main/doc/README.md).

## Prerequisites
1. `cargo-contract 3.01`
1. `cargo-contract 3.0.1`
2. `ink-wrapper 0.5.0`
2. `rustc-1.69`

## Build
To build smart contract run:
## Build (manually)
To build a smart contract locally we can run:
```
cargo contract build --release --manifest-path contract/Cargo.toml
```
## Run
Running smart contract can be done by running `deploy.sh` script:
This call will generate files:
```
bash scripts/deploy.sh
contract/target/ink/bright_disputes.json
contract/target/ink/bright_disputes.wasm
contract/target/ink/bright_disputes.contract
```
Script will run an aleph-node, build and deploy smart contract.

This script is based on the [deploy.sh](https://github.com/Cardinal-Cryptography/zk-apps/blob/main/shielder/deploy/deploy.sh).
and they can be deployed on the node.

## Docker
## Build (docker)
Smart contract can be build with the Docker:
```
DOCKER_BUILDKIT=1 docker build -f docker/Dockerfile --output artifacts .
```
This will export *bright_disputes.json*, *bright_disputes.wasm*, *bright_disputes.contract*, to the *artifacts* directory.

## Build (script)
The last way to build and run Bright Disputes is to use a script. We simplify the whole process, by providing a `scripts/deploy.sh` script. It will starts aleph node, building and deploying smart contract on it. Script will also pre-fund [accounts](https://github.com/bright/bright-disputes/blob/main/doc/accounts), which can be used to play/test with the smart contract. More details can be found in the [showcase](https://github.com/bright/bright-disputes/blob/main/doc/README.md). Script is using three docker images:
* disputes-node - is an image of the aleph node, where our smart contract is going to be deployed
* disputes-cliain - is an image of `cliain` tool, which is a wrapper over `substrate-api-client` library. It simplify calls over Substrate chain extrinsic.
* disputes-ink-dev - this image contains environment for building a smart contract

To run a script just type:
```
bash scripts/deploy.sh
```

Please note, that this script is based on the [deploy.sh](https://github.com/Cardinal-Cryptography/zk-apps/blob/main/shielder/deploy/deploy.sh) created by the Cardinal-Cryptography.

## Tests
To run a unit test:
```
Expand All @@ -38,19 +50,17 @@ docker build -f docker/Dockerfile.testing --progress=plain .
```

## E2E tests
To run E2E tests on you local machine, first run a aleph-node. We can do it, by running `deploy.sh` from the running part. After that we need build contract on our local machine:
```
cargo contract build --release --manifest-path contract/Cargo.toml
```
and upload it to the node:
To run E2E tests on your local machine, first run a aleph-node, build and deploy smart contract. We can do it, by running `deploy.sh` script:
```
cargo contract upload --manifest-path contract/Cargo.toml --suri //Alice --url ws://localhost:9944 || true
bash scripts/deploy.sh
```
than we need to use [ink-wrapper](https://crates.io/crates/ink-wrapper) tool to generate a type-safe code for calling smart contract from our e2e tests:

Next we need to use [ink-wrapper](https://crates.io/crates/ink-wrapper) tool to generate a type-safe code for calling smart contract from our e2e tests:
```
cd tests
ink-wrapper -m ../contract/target/ink/bright_disputes.json --wasm-path ../contract/target/ink/bright_disputes.wasm | rustfmt +nightly --edition 2021 > bright_disputes.rs
```

Finally we can run a e2e tests by calling:
```
cargo +nightly test --release
Expand Down
9 changes: 4 additions & 5 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ set -euo pipefail

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

export NODE_IMAGE="public.ecr.aws/p6e8q1z1/aleph-node-liminal:d93048e"
export CLIAIN_IMAGE="public.ecr.aws/p6e8q1z1/cliain-liminal:d93048e"
export INK_DEV_IMAGE="public.ecr.aws/p6e8q1z1/ink-dev:1.1.0"
export NODE_IMAGE="brightinventions/disputes-node"
export CLIAIN_IMAGE="brightinventions/disputes-cliain"
export INK_DEV_IMAGE="brightinventions/disputes-ink-dev"

# actors
DAMIAN=//0
Expand Down Expand Up @@ -100,7 +100,6 @@ run_snarkeling_node() {

docker_ink_dev() {
docker run --rm \
-u "${DOCKER_USER}" \
-v "${PWD}":/code \
-v ~/.cargo/git:/usr/local/cargo/git \
-v ~/.cargo/registry:/usr/local/cargo/registry \
Expand All @@ -122,7 +121,7 @@ random_salt() {
}

contract_instantiate() {
docker_ink_dev "cargo contract instantiate --skip-confirm --url ${NODE} --suri ${ADMIN} --output-json --salt 0x$(random_salt) ${1}"
docker_ink_dev "cargo contract instantiate --skip-confirm --url ${NODE} --suri ${ADMIN} --output-json --execute --salt 0x$(random_salt) ${1}"
}

deploy_contract() {
Expand Down
23 changes: 19 additions & 4 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@

# Requirements
# Prerequisites

Install cargo-contract:
```
cargo install --force --locked cargo-contract --version 3.0.1
```

Install ink-wrapper
```
cargo install ink-wrapper --locked --force --version 0.5.0
```

and use it with the smart contract
# Build
First we need to build a smart contract:
```
cargo contract build --release --manifest-path contract/Cargo.toml
```

next we need use ink-wrapper to generate a safe code for our tests:
```
ink-wrapper -m ../contract/target/ink/bright_disputes.json | rustfmt --edition 2021 > bright_disputes.rs
```

# Run
Please note that, before running E2E test we need to have a running node.

We start from deploying our smart contract to the node:
```
cargo contract upload --manifest-path contract/Cargo.toml --suri //Alice --url ws://localhost:9944 --execute || true
```

To run tests:
Now we can run e2e tests:
```
cargo +nightly test --release
```
4 changes: 2 additions & 2 deletions tests/bright_disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use scale::Encode as _;

#[allow(dead_code)]
pub const CODE_HASH: [u8; 32] = [
45, 111, 185, 8, 42, 163, 254, 28, 39, 170, 97, 69, 154, 251, 14, 249, 204, 222, 75, 48, 163,
142, 251, 48, 70, 74, 55, 211, 162, 178, 3, 80,
74, 171, 47, 183, 197, 181, 13, 124, 128, 35, 80, 186, 0, 132, 168, 172, 26, 237, 209, 124,
143, 150, 217, 23, 239, 111, 34, 83, 70, 21, 47, 9,
];

#[derive(Debug, Clone, PartialEq, Eq, scale::Encode, scale::Decode)]
Expand Down

0 comments on commit f4f06b5

Please sign in to comment.