Skip to content

Commit

Permalink
chore: More test coverage and CI integration
Browse files Browse the repository at this point in the history
c
  • Loading branch information
Orlando committed Sep 3, 2023
1 parent 3a22511 commit d1a3b3e
Show file tree
Hide file tree
Showing 11 changed files with 710 additions and 125 deletions.
71 changes: 60 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: SX-Starknet Workflow

env:
STARKNET_SIERRA_COMPILE_PATH: ./cairo/bin/starknet-sierra-compile
OBJC_DISABLE_INITIALIZE_FORK_SAFETY: YES
ADDRESS: "0x347be35996a21f6bf0623e75dbce52baba918ad5ae8d83b6f416045ab22961a"
PK: "0xbdd640fb06671ad11c80317fa3b1799d"

on:
push:
branches:
Expand All @@ -14,28 +20,28 @@ jobs:
name: Forge tests
runs-on: ubuntu-latest
steps:
- name: Step 1 - Check out main branch
- name: Check out main branch
uses: actions/checkout@v3
with:
submodules: recursive

- name: Step 2 - Install Foundry
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Step 3 - Check formatting
- name: Check formatting
working-directory: ./ethereum
run: forge fmt --check

- name: Step 4 - Build Solidity contracts
- name: Build Solidity contracts
working-directory: ./ethereum
run: |
forge --version
forge build --sizes
id: build

- name: Step 5 - Run Forge tests
- name: Run Forge tests
working-directory: ./ethereum
run: |
forge test -vvv
Expand All @@ -46,24 +52,67 @@ jobs:
fail-fast: true

name: Cairo tests
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Step 1 - Check out main branch
- name: Check out main branch
uses: actions/checkout@v3

- name: Step 2 - Install Scarb
- name: Set up node
uses: actions/setup-node@v3
with:
node-version: 18.16.0

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Cache Yarn dependencies
uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
yarn-
- name: Install Yarn dependencies
run: yarn install

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install Python dependencies
run: |
sudo apt install -y libgmp3-dev
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Install Cairo
run: curl -L https://github.com/starkware-libs/cairo/releases/download/v2.2.0/release-x86_64-unknown-linux-musl.tar.gz > cairo.tar.gz

- name: Extract Cairo
run: tar -xvf cairo.tar.gz

- name: Install Scarb
uses: software-mansion/setup-scarb@v1
with:
scarb-version: 0.7.0

- name: Step 3 - Check formatting
- name: Step 3 - Check Cairo formatting
working-directory: ./starknet
run: scarb fmt --check

- name: Step 4 - Build Cairo contracts
working-directory: ./starknet
run: scarb build --verbose

- name: Step 4 - Running Cairo tests
- name: Step 4 - Run Cairo tests
working-directory: ./starknet
run: scarb test --verbose
run: scarb test --verbose

- name: Compile Cairo contracts for Hardhat tests
run: yarn hardhat starknet-build

- name: run Hardhat tests
run: yarn test:l1-execution
160 changes: 160 additions & 0 deletions audited_cairo_libfuncs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"allowed_libfuncs": [
"alloc_local",
"array_append",
"array_get",
"array_len",
"array_new",
"array_pop_front",
"array_pop_front_consume",
"array_slice",
"array_snapshot_pop_back",
"array_snapshot_pop_front",
"bitwise",
"bool_and_impl",
"bool_not_impl",
"bool_or_impl",
"bool_to_felt252",
"bool_xor_impl",
"branch_align",
"call_contract_syscall",
"class_hash_const",
"class_hash_to_felt252",
"class_hash_try_from_felt252",
"contract_address_const",
"contract_address_to_felt252",
"contract_address_try_from_felt252",
"deploy_syscall",
"disable_ap_tracking",
"downcast",
"drop",
"dup",
"ec_neg",
"ec_point_from_x_nz",
"ec_point_is_zero",
"ec_point_try_new_nz",
"ec_point_unwrap",
"ec_point_zero",
"ec_state_add",
"ec_state_add_mul",
"ec_state_init",
"ec_state_try_finalize_nz",
"emit_event_syscall",
"enable_ap_tracking",
"enum_init",
"enum_match",
"enum_snapshot_match",
"felt252_add",
"felt252_const",
"felt252_dict_entry_finalize",
"felt252_dict_entry_get",
"felt252_dict_new",
"felt252_dict_squash",
"felt252_div",
"felt252_is_zero",
"felt252_mul",
"felt252_sub",
"finalize_locals",
"function_call",
"get_block_hash_syscall",
"get_builtin_costs",
"get_execution_info_syscall",
"hades_permutation",
"into_box",
"jump",
"keccak_syscall",
"library_call_syscall",
"match_nullable",
"null",
"nullable_from_box",
"pedersen",
"rename",
"replace_class_syscall",
"revoke_ap_tracking",
"secp256k1_add_syscall",
"secp256k1_get_xy_syscall",
"secp256k1_get_point_from_x_syscall",
"secp256k1_mul_syscall",
"secp256k1_new_syscall",
"send_message_to_l1_syscall",
"snapshot_take",
"storage_address_from_base",
"storage_address_from_base_and_offset",
"storage_address_to_felt252",
"storage_address_try_from_felt252",
"storage_base_address_const",
"storage_base_address_from_felt252",
"storage_read_syscall",
"storage_write_syscall",
"store_local",
"store_temp",
"struct_construct",
"struct_deconstruct",
"struct_snapshot_deconstruct",
"u256_safe_divmod",
"u256_sqrt",
"u256_is_zero",
"u128_const",
"u128_eq",
"u128_is_zero",
"u128_overflowing_add",
"u128_overflowing_sub",
"u128_safe_divmod",
"u128_sqrt",
"u128_byte_reverse",
"u128_to_felt252",
"u128_guarantee_mul",
"u128_mul_guarantee_verify",
"u128s_from_felt252",
"u16_bitwise",
"u16_const",
"u16_eq",
"u16_is_zero",
"u16_overflowing_add",
"u16_overflowing_sub",
"u16_safe_divmod",
"u16_sqrt",
"u16_to_felt252",
"u16_try_from_felt252",
"u16_wide_mul",
"u32_bitwise",
"u32_const",
"u32_eq",
"u32_is_zero",
"u32_overflowing_add",
"u32_overflowing_sub",
"u32_safe_divmod",
"u32_sqrt",
"u32_to_felt252",
"u32_try_from_felt252",
"u32_wide_mul",
"u512_safe_divmod_by_u256",
"u64_bitwise",
"u64_const",
"u64_eq",
"u64_is_zero",
"u64_overflowing_add",
"u64_overflowing_sub",
"u64_safe_divmod",
"u64_sqrt",
"u64_to_felt252",
"u64_try_from_felt252",
"u64_wide_mul",
"u8_bitwise",
"u8_const",
"u8_eq",
"u8_is_zero",
"u8_overflowing_add",
"u8_overflowing_sub",
"u8_safe_divmod",
"u8_sqrt",
"u8_to_felt252",
"u8_try_from_felt252",
"u8_wide_mul",
"unbox",
"unwrap_non_zero",
"upcast",
"withdraw_gas",
"withdraw_gas_all"
]
}
1 change: 1 addition & 0 deletions ethereum/src/deps.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pragma solidity ^0.8.19;

import "@safe-global/safe-contracts/contracts/SafeL2.sol";
import "@safe-global/safe-contracts/contracts/proxies/SafeProxyFactory.sol";
import "@gnosis.pm/zodiac/contracts/factory/ModuleProxyFactory.sol";
5 changes: 3 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ const config: HardhatUserConfig = {
},
networks: {
ethereumLocal: {
url: 'http://localhost:8545',
url: 'http://127.0.0.1:8545/',
chainId: 31337,
},
starknetLocal: {
url: 'http://localhost:5050',
url: 'http://127.0.0.1:5050',
},
},
gasReporter: {
Expand All @@ -63,6 +63,7 @@ const config: HardhatUserConfig = {
network: 'starknetLocal',
recompile: false,
venv: 'active',
requestTimeout: 90_000,
},
paths: {
starknetSources: './starknet',
Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
"repository": "https://github.com/snapshot-labs/sx-starknet-2.git",
"author": "Snapshot Labs",
"license": "MIT",
"main": "index.js",
"scripts": {
"format:ts": "eslint . --ext .ts --fix",
"test:stark-sig-auth": "jest -c jest.config.ts"
"chain:l1": "hardhat node",
"chain:l2": "bash './scripts/chain-l2.sh'",
"chain": "yarn chain:l1 & yarn chain:l2",
"test:stark-sig-auth": "jest -c jest.config.ts",
"test:l1-execution": "bash './scripts/l1-execution.sh'"
},
"devDependencies": {
"@gnosis.pm/zodiac": "^3.3.7",
Expand All @@ -27,8 +32,9 @@
"@types/sinon-chai": "^3.2.9",
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.2.1",
"axios": "^1.5.0",
"chai": "^4.3.7",
"concurrently": "^8.2.1",
"concurrently": "^7.0.0",
"dotenv": "^16.3.1",
"eslint": "^8.46.0",
"eslint-plugin-prettier": "^5.0.0",
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/starkware-libs/cairo-lang/releases/download/v0.12.2/cairo-lang-0.12.2.zip
starknet-devnet==0.6.1

3 changes: 3 additions & 0 deletions scripts/chain-l2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
starknet-devnet --seed 42 --verbose --sierra-compiler-path "${STARKNET_SIERRA_COMPILE_PATH}" --compiler-args '--allowed-libfuncs-list-file ./audited_cairo_libfuncs.json --add-pythonic-hints' --lite-mode
exit 0
6 changes: 4 additions & 2 deletions scripts/l1-execution.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/bash

yarn wait-on tcp:5050 &&
yarn wait-on tcp:8545 &&
kill -9 $(lsof -t -i:8545)
kill -9 $(lsof -t -i:5050)
yarn chain &
sleep 10 &&
yarn hardhat test starknet/test/l1-execution.test.ts --network 'ethereumLocal' --starknet-network 'starknetLocal'
if [ $? -eq 0 ]
then
Expand Down
Loading

0 comments on commit d1a3b3e

Please sign in to comment.