Skip to content

Commit

Permalink
add CI for new shielder
Browse files Browse the repository at this point in the history
  • Loading branch information
kroist committed Feb 13, 2024
1 parent 6e22ae9 commit 35bbd8a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 24 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concurrency:
cancel-in-progress: true

jobs:
rust-checks:
legacy-shielder-rust-checks:
runs-on: [self-hosted, Linux, X64, large]
steps:
- name: Checkout source code
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Run tests for `shielder/public_token`
run: cd legacy-shielder/public_token/ && cargo test

build-contracts:
legacy-shielder-build-contracts:
runs-on: [self-hosted, Linux, X64, large]
env:
DOCKER_IMAGE: "public.ecr.aws/p6e8q1z1/ink-dev:1.0.0"
Expand Down Expand Up @@ -86,3 +86,23 @@ jobs:
--platform linux/amd64 \
${{ env.DOCKER_IMAGE }} \
cargo contract build --manifest-path legacy-shielder/contract/Cargo.toml
shielder-rust-checks:
runs-on: [self-hosted, Linux, X64, large]
steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2023-12-21

- name: Install WASM target
run: rustup target add wasm32-unknown-unknown

- name: Run checks for `shielder/contract`
run: cd shielder/ && make check-shielder

- name: Run tests for `shielder/contract`
run: cd shielder/ && make tests
10 changes: 8 additions & 2 deletions shielder/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
help: # Show help for each of the Makefile recipes.
@grep -E '^[a-zA-Z0-9 -]+:.*#' Makefile | sort | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done

.PHONY: check-shielder
check-shielder: ## Run cargo checks on shielder contract.
@echo "Checking shielder contract" ; \
cargo fmt --quiet --all --check --manifest-path contract/Cargo.toml ; \


.PHONY: build-psp22
build-psp22: ## Builds psp22 contracts.
@echo "Building psp22 contract" ; \
Expand All @@ -21,9 +27,9 @@ build-shielder: ## Builds shielder contracts.
setup-tests: build-psp22 ## Builds contracts and generates wrappers.

.PHONY: tests
tests: ## Runs tests for contract.
tests: setup-tests ## Runs tests for contract.
@echo "Running drink tests" ; \
cargo test --quiet --manifest-path contract/Cargo.toml --release -- --nocapture ; \

.PHONY:
all: setup-tests tests ## Runs all tests.
all: check-shielder tests ## Runs all tests.
10 changes: 3 additions & 7 deletions shielder/contract/drink_tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
mod utils;

use anyhow::Result;
use drink::{session::Session, AccountId32};

use crate::{
drink_tests::utils::{chain::*, ops::*, psp22::*, shielder::*},
test_utils::merkle::MerkleTree,
};
use anyhow::Result;

#[drink::contract_bundle_provider]
pub enum BundleProvider {}

#[drink::test]
fn deploy_single_deposit_single_withdraw(
mut session: Session,
) -> Result<()> {
fn deploy_single_deposit_single_withdraw(mut session: Session) -> Result<()> {
let alice: AccountId32 = init_alice(&mut session)?;
let bob: AccountId32 = init_bob(&mut session)?;

Expand Down Expand Up @@ -73,9 +71,7 @@ fn deploy_single_deposit_single_withdraw(
}

#[drink::test]
fn deploy_single_deposit_multiple_withdraw(
mut session: Session,
) -> Result<()> {
fn deploy_single_deposit_multiple_withdraw(mut session: Session) -> Result<()> {
let alice: AccountId32 = init_alice(&mut session)?;
session = session.with_actor(alice.clone());

Expand Down
13 changes: 5 additions & 8 deletions shielder/contract/drink_tests/utils/chain.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::drink_tests::utils::ACCOUNT_INITIAL_AMOUNT;
use drink::{runtime::MinimalRuntime, session::Session, AccountId32};
use anyhow::Result;
use drink::{runtime::MinimalRuntime, session::Session, AccountId32};

use crate::drink_tests::utils::ACCOUNT_INITIAL_AMOUNT;

pub fn init_acc_with_balance(
session: &mut Session<MinimalRuntime>,
Expand All @@ -13,17 +14,13 @@ pub fn init_acc_with_balance(
Ok(())
}

pub fn init_alice(
session: &mut Session<MinimalRuntime>,
) -> Result<AccountId32> {
pub fn init_alice(session: &mut Session<MinimalRuntime>) -> Result<AccountId32> {
let res = AccountId32::new([2u8; 32]);
init_acc_with_balance(session, &res)?;
Ok(res)
}

pub fn init_bob(
session: &mut Session<MinimalRuntime>,
) -> Result<AccountId32> {
pub fn init_bob(session: &mut Session<MinimalRuntime>) -> Result<AccountId32> {
let res = AccountId32::new([3u8; 32]);
init_acc_with_balance(session, &res)?;
Ok(res)
Expand Down
2 changes: 1 addition & 1 deletion shielder/contract/drink_tests/utils/psp22.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use anyhow::Result;
use drink::{
runtime::MinimalRuntime,
session::{Session, NO_ENDOWMENT, NO_SALT},
AccountId32, ContractBundle,
};
use anyhow::Result;

pub fn deploy_test_token(
session: &mut Session<MinimalRuntime>,
Expand Down
6 changes: 2 additions & 4 deletions shielder/contract/drink_tests/utils/shielder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::Result;
use drink::{
runtime::MinimalRuntime,
session::{Session, NO_ARGS, NO_ENDOWMENT, NO_SALT},
Expand All @@ -17,17 +18,14 @@ use crate::{
test_utils::merkle::MerkleTree,
types::Scalar,
};
use anyhow::Result;

pub struct ShielderUserEnv {
pub proof: ZkProof,
pub nullifier: Scalar,
pub tree_leaf_id: u32,
}

pub fn deploy_shielder(
session: &mut Session<MinimalRuntime>,
) -> Result<AccountId32> {
pub fn deploy_shielder(session: &mut Session<MinimalRuntime>) -> Result<AccountId32> {
let res = session.deploy_bundle(
BundleProvider::local()?,
"new",
Expand Down

0 comments on commit 35bbd8a

Please sign in to comment.