Skip to content

Commit

Permalink
feat: force withdrawal and chopsticks tests in container
Browse files Browse the repository at this point in the history
missing case
  • Loading branch information
Vovke committed Nov 6, 2024
1 parent b3f2236 commit 0f6998a
Show file tree
Hide file tree
Showing 16 changed files with 324 additions and 154 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.git
.github
.gitignore
.idea

chopsticks
docs
target
tests

Dockerfile
44 changes: 44 additions & 0 deletions .github/workflows/cargo-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Rust test

on:
pull_request:
push:
branches:
- main
- stable

jobs:
check:
name: Cargo test
runs-on: ubuntu-latest
steps:

- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.1
with:
access_token: ${{ github.token }}

- name: Checkout sources
uses: actions/checkout@v4.1.2
with:
fetch-depth: 50
submodules: 'recursive'

- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1.0.7
with:
profile: minimal
toolchain: stable
override: true

- name: Install cargo-nextest
uses: baptiste0928/cargo-install@v3
with:
crate: cargo-nextest
version: 0.9

- name: Rust Cache
uses: Swatinem/rust-cache@v2.7.3

- name: cargo nextest
run: cargo nextest run
66 changes: 21 additions & 45 deletions .github/workflows/kalatori-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Kalatori Tests
name: Kalatori Test

on:
pull_request:
Expand Down Expand Up @@ -30,52 +30,28 @@ jobs:
- name: Verify directory structure
run: ls -R

- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1.0.7
with:
profile: minimal
toolchain: stable
override: true

- name: Install cargo-nextest
uses: baptiste0928/cargo-install@v3
with:
crate: cargo-nextest
version: 0.9

- name: Rust Cache
uses: Swatinem/rust-cache@v2.7.5

- name: Run Rust app in background with environment variables
- name: Install Docker using Docker's official script
run: |
export KALATORI_HOST="127.0.0.1:16726"
export KALATORI_SEED="bottom drive obey lake curtain smoke basket hold race lonely fit walk"
export KALATORI_RECIPIENT="5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
export KALATORI_REMARK="test"
cargo build
nohup cargo r &
- name: Wait for Rust app to start
run: sleep 120
# Wait for the Rust app to start and then wait for the app to connect to RPC
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Install Yarn package manager
run: npm install --global yarn
- name: Install Docker Compose
run: |
sudo curl -L "https://github.com/docker/compose/releases/download/v2.3.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
- name: Install dependencies
working-directory: ./tests/kalatori-api-test-suite
run: yarn install --network-timeout 100000
- name: Build and Start Containers
working-directory: ./tests
run: |
docker-compose up -d --build chopsticks-polkadot chopsticks-statemint kalatori-rust-app
- name: Run tests
working-directory: ./tests/kalatori-api-test-suite
env:
DAEMON_HOST: 'http://127.0.0.1:16726'
run: yarn test
- name: Wait for Dependencies to Initialize
run: sleep 60

# - name: Run Rust tests
# run: cargo nextest run
- name: Run Tests and Capture Exit Code
working-directory: ./tests
run: |
docker-compose run tests || exit_code=$?
docker-compose down
exit ${exit_code:-0}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

## [0.2.6] - 2024-11-01

### 🚀 Features

- Force withdrawal call implementation
- Docker container for the app
- Containerized test environment

### 🐛 Bug Fixes

- Fixed the storage fetching.
Expand Down
30 changes: 24 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
FROM ubuntu:latest
RUN mkdir /app
COPY target/release/kalatori /app/kalatori
FROM rust:1.82 as builder

ENV KALATORI_HOST="0.0.0.0:16726"
ENV KALATORI_RPC="wss://rpc.ibp.network/polkadot"
WORKDIR /usr/src/kalatori

COPY Cargo.toml Cargo.lock ./

RUN mkdir -p src && echo "fn main() {}" > src/main.rs

RUN cargo build --release

RUN rm -rf src
COPY . .

RUN cargo build --release

FROM ubuntu:latest

WORKDIR /app

COPY --from=builder /usr/src/kalatori/target/release/kalatori /app/kalatori

EXPOSE 16726

CMD ["./kalatori"]
ENV KALATORI_HOST="0.0.0.0:16726"
ENV KALATORI_SEED="bottom drive obey lake curtain smoke basket hold race lonely fit walk"
ENV KALATORI_RECIPIENT="5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
ENV KALATORI_REMARK="test"

CMD ["/app/kalatori"]
22 changes: 22 additions & 0 deletions chopsticks/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ services:
- ./pd.yml:/app/config.yml
command: ["chopsticks", "-c", "/app/config.yml", "-p", "8000", "--addr", "0.0.0.0"]

chopsticks-polkadot-2:
build:
context: .
dockerfile: Dockerfile
container_name: chopsticks-polkadot-2
ports:
- "8500:8500"
volumes:
- ./pd-2.yml:/app/config.yml
command: [ "chopsticks", "-c", "/app/config.yml", "-p", "8500", "--addr", "0.0.0.0" ]

chopsticks-statemint:
build:
context: .
Expand All @@ -22,3 +33,14 @@ services:
volumes:
- ./pd-ah.yml:/app/config.yml
command: ["chopsticks", "-c", "/app/config.yml", "-p", "9000", "--addr", "0.0.0.0"]

chopsticks-statemint-2:
build:
context: .
dockerfile: Dockerfile
container_name: chopsticks-statemint-2
ports:
- "9500:9500"
volumes:
- ./pd-ah-2.yml:/app/config.yml
command: [ "chopsticks", "-c", "/app/config.yml", "-p", "9500", "--addr", "0.0.0.0" ]
25 changes: 25 additions & 0 deletions configs/chopsticks-docker.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
account-lifetime = 86400000 # 1 day.
depth = 3600000 # 1 hour.
debug = true

[[chain]]
name = "polkadot"
native-token = "DOT"
decimals = 10
endpoints = [
"ws://chopsticks-polkadot:8000",
]

[[chain]]
name = "statemint"
endpoints = [
"ws://chopsticks-statemint:9000",
]

[[chain.asset]]
name = "USDC"
id = 1337

[[chain.asset]]
name = "USDt"
id = 1984
7 changes: 4 additions & 3 deletions src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl SeedEnvVars {
#[serde(rename_all = "kebab-case")]
pub struct Config {
pub account_lifetime: Timestamp,
#[serde(default = "default_host")]
#[serde(default = "get_host")]
pub host: SocketAddr,
pub database: Option<String>,
pub debug: Option<bool>,
Expand All @@ -165,6 +165,7 @@ impl Config {
}
}

fn default_host() -> SocketAddr {
SOCKET_DEFAULT
fn get_host() -> SocketAddr {
let host = env::var("KALATORI_HOST").unwrap_or_else(|_| "127.0.0.1:16726".to_string());
host.parse().unwrap_or(SOCKET_DEFAULT)
}
41 changes: 2 additions & 39 deletions src/chain/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use tokio::sync::oneshot;

/// Abstraction to distinguish block hash from many other H256 things
#[derive(Debug, Clone)]
pub struct BlockHash(pub primitive_types::H256);
pub struct BlockHash(pub H256);

impl BlockHash {
/// Convert block hash to RPC-friendly format
Expand All @@ -45,45 +45,7 @@ pub struct EventFilter<'a> {
pub pallet: &'a str,
pub optional_event_variant: Option<&'a str>,
}
/*
#[derive(Debug)]
struct ChainProperties {
specs: ShortSpecs,
metadata: RuntimeMetadataV15,
existential_deposit: Option<Balance>,
assets_pallet: Option<AssetsPallet>,
block_hash_count: BlockNumber,
account_lifetime: BlockNumber,
depth: Option<NonZeroU64>,
}
#[derive(Debug)]
struct AssetsPallet {
multi_location: Option<PalletIndex>,
assets: HashMap<AssetId, AssetProperties>,
}
#[derive(Debug)]
struct AssetProperties {
min_balance: Balance,
decimals: Decimals,
}
#[derive(Debug)]
pub struct Currency {
chain: String,
asset: Option<AssetId>,
}
#[derive(Debug)]
pub struct ConnectedChain {
rpc: String,
client: WsClient,
genesis: BlockHash,
properties: ChainProperties,
}

*/
pub enum ChainRequest {
WatchAccount(WatchAccount),
Reap(WatchAccount),
Expand Down Expand Up @@ -127,6 +89,7 @@ pub enum ChainTrackerRequest {
WatchAccount(WatchAccount),
NewBlock(String),
Reap(WatchAccount),
ForceReap(WatchAccount),
Shutdown(oneshot::Sender<()>),
}

Expand Down
Loading

0 comments on commit 0f6998a

Please sign in to comment.