diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..36a9430 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +.git +.github +.gitignore +.idea + +chopsticks +docs +target +tests + +Dockerfile \ No newline at end of file diff --git a/.github/workflows/cargo-test.yml b/.github/workflows/cargo-test.yml new file mode 100644 index 0000000..28aadc1 --- /dev/null +++ b/.github/workflows/cargo-test.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/kalatori-test.yml b/.github/workflows/kalatori-test.yml new file mode 100644 index 0000000..036a6ab --- /dev/null +++ b/.github/workflows/kalatori-test.yml @@ -0,0 +1,57 @@ +name: Kalatori Test + +on: + pull_request: + push: + branches: + - main + - stable + +jobs: + check: + name: Cargo and TypeScript Tests + 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.2.0 + with: + fetch-depth: 50 + submodules: recursive + + - name: Initialize Git Submodules + run: git submodule update --init --recursive + + - name: Verify directory structure + run: ls -R + + - name: Install Docker using Docker's official script + run: | + curl -fsSL https://get.docker.com -o get-docker.sh + sudo sh get-docker.sh + + - 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: Build and Start Containers + working-directory: ./tests + run: | + docker-compose up -d --build chopsticks-polkadot chopsticks-statemint kalatori-rust-app + + - name: Wait for Dependencies to Initialize + run: sleep 60 + + - name: Run Tests and Capture Exit Code + working-directory: ./tests + run: | + docker-compose run tests || exit_code=$? + docker-compose down + exit ${exit_code:-0} diff --git a/configs/chopsticks-docker.toml b/configs/chopsticks-docker.toml new file mode 100644 index 0000000..482cd9c --- /dev/null +++ b/configs/chopsticks-docker.toml @@ -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 diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml new file mode 100644 index 0000000..5b64f6f --- /dev/null +++ b/tests/docker-compose.yml @@ -0,0 +1,55 @@ +version: '3.8' + +services: + chopsticks-polkadot: + build: + context: ../chopsticks + dockerfile: Dockerfile + container_name: chopsticks-polkadot + ports: + - "8000:8000" + volumes: + - ../chopsticks/pd.yml:/app/config.yml + command: ["chopsticks", "-c", "/app/config.yml", "-p", "8000", "--addr", "0.0.0.0"] + + chopsticks-statemint: + build: + context: ../chopsticks + dockerfile: Dockerfile + container_name: chopsticks-statemint + ports: + - "9000:9000" + volumes: + - ../chopsticks/pd-ah.yml:/app/config.yml + command: ["chopsticks", "-c", "/app/config.yml", "-p", "9000", "--addr", "0.0.0.0"] + + kalatori-rust-app: + build: + context: .. + dockerfile: Dockerfile + container_name: kalatori-daemon + ports: + - "16726:16726" + volumes: + - ../configs:/app/configs + depends_on: + - chopsticks-polkadot + - chopsticks-statemint + environment: + - KALATORI_HOST=0.0.0.0:16726 + - KALATORI_CONFIG=configs/chopsticks-docker.toml + - KALATORI_SEED=bottom drive obey lake curtain smoke basket hold race lonely fit walk + - KALATORI_RECIPIENT=5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY + - KALATORI_REMARK=test + command: /bin/sh -c "sleep 10 && /app/kalatori" # 10-second sleep to ensure chopsticks is ready + + tests: + image: node:20 + working_dir: /app + volumes: + - ../tests/kalatori-api-test-suite:/app + depends_on: + - kalatori-rust-app + environment: + - DAEMON_HOST=http://kalatori-daemon:16726 + command: /bin/sh -c "sleep 50 && yarn install && yarn test"