Skip to content

Commit

Permalink
ci: run integration tests on CI (#985)
Browse files Browse the repository at this point in the history
* ci: run integration tests on CI

* test: increase anvil's time for L1 execution

* ci: install Starknet Devnet in test workflow

* ci: cache cargo
  • Loading branch information
Sekhmet authored Nov 22, 2024
1 parent a3fe34e commit df02187
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 7 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: CI

on: [push]

env:
STARKNET_DEVNET_VERSION: 0.2.3

jobs:
lint-build-test:
runs-on: ubuntu-22.04
Expand All @@ -13,8 +16,20 @@ jobs:
with:
node-version: "18.x"
cache: "yarn"
- name: Setup Rust Toolchain
uses: dtolnay/rust-toolchain@stable
- name: Restore Cargo
uses: actions/cache@v4
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-${{ env.STARKNET_DEVNET_VERSION }}
- name: Install Starknet Devnet
run: cargo install starknet-devnet@${{ env.STARKNET_DEVNET_VERSION }}
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- run: yarn --frozen-lockfile
- run: yarn build
- run: yarn typecheck
- run: yarn lint
- run: yarn test
- run: yarn test:integration
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dev:full": "./scripts/dev-full.sh",
"build": "turbo run build",
"test": "turbo run test",
"test:integration": "turbo run test:integration",
"lint": "turbo run lint",
"typecheck": "turbo run typecheck",
"release": "yarn build && changeset publish"
Expand Down
1 change: 1 addition & 0 deletions packages/sx.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"node:evm": "anvil",
"node:starknet": "starknet-devnet --seed 1",
"test": "SEPOLIA_NODE_URL=https://rpc.snapshot.org/11155111 vitest run test/unit",
"test:integration": "./test/run-integration-tests.sh",
"test:integration:starknet": "vitest run test/integration/starknet",
"test:integration:evm": "vitest run test/integration/evm",
"test:integration:offchain": "vitest run test/integration/offchain"
Expand Down
5 changes: 2 additions & 3 deletions packages/sx.js/test/integration/starknet/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
increaseTime,
setTime,
setup,
sleep,
TestConfig
} from './utils';
import {
Expand Down Expand Up @@ -510,8 +509,7 @@ describe('sx-starknet', () => {
}
};

// NOTE: to avoid Votes: future lookup
await sleep(10000);
await increaseTime(1000);

const receipt = await client.vote(account, envelope);
console.log('Receipt', receipt);
Expand Down Expand Up @@ -586,6 +584,7 @@ describe('sx-starknet', () => {

it('should execute', async () => {
await increaseTime(86400);
await provider.send('evm_increaseTime', [86400]);

const { executionParams } = getExecutionData(
'EthRelayer',
Expand Down
4 changes: 0 additions & 4 deletions packages/sx.js/test/integration/starknet/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,3 @@ export function loadL1MessagingContract(networkUrl: string, address: string) {
export function flush() {
return postDevnet('postman/flush', {});
}

export function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
28 changes: 28 additions & 0 deletions packages/sx.js/test/run-integration-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

PIDS=()

function start_node() {
yarn node:"$1" > /dev/null 2>&1 &
PIDS+=($!)
echo "Started $1 with PID $!"
}

function cleanup() {
echo "Cleaning up..."
for pid in "${PIDS[@]}"; do
echo "Killing process $pid"
kill "$pid" 2>/dev/null || echo "Process $pid already terminated"
done
}

trap cleanup EXIT

start_node evm
start_node starknet

echo "Running evm tests"
yarn test:integration:evm

echo "Running starknet tests"
yarn test:integration:starknet
3 changes: 3 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"test": {
"dependsOn": ["^build"]
},
"test:integration": {
"dependsOn": ["^build"]
},
"dev": {
"cache": false,
"persistent": true,
Expand Down

0 comments on commit df02187

Please sign in to comment.