Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript and rust clients #6

Merged
merged 21 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"linebreak-style": [
"error",
"unix"
],
"semi": [
"error",
"always"
],
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-non-null-asserted-optional-chain": 0,
"@typescript-eslint/explicit-function-return-type": "warn",
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
]
}
}
175 changes: 175 additions & 0 deletions .github/workflows/ci-code-review-ts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
name: Code Review - TypeScript

on:
pull_request:
branches: ['main']
paths: ['client/ts/**', 'yarn.lock']
push:
branches: ['main']
workflow_dispatch:

env:
CARGO_TERM_COLOR: always
SOLANA_VERSION: '1.18.22'
RUST_TOOLCHAIN: '1.78.0'

jobs:
format:
name: Format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Format
run: yarn format

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Lint
run: yarn lint

depcheck:
name: Dependency check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'yarn'

- name: Duplicates check
run: npx yarn-deduplicate --list --fail

test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Cache dependencies
uses: Swatinem/rust-cache@v2

- name: Set Rust version
run: rustup toolchain install ${{ env.RUST_TOOLCHAIN }}

- name: Install Solana
run: |
sh -c "$(curl -sSfL https://release.solana.com/v${{ env.SOLANA_VERSION }}/install)"
echo "$HOME/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
export PATH="/home/runner/.local/share/solana/install/active_release/bin:$PATH"
solana --version
echo "Generating keypair..."
solana-keygen new -o "$HOME/.config/solana/id.json" --no-passphrase --silent

- name: Start validator
run: |
solana-test-validator > /dev/null 2>&1 &
echo "Started test validator, sleeping for 15 seconds before starting"
sleep 15
echo "Updating hardcoded discriminant constants for the hardcoded deploy key"
sed -i 's/MNFSTqtC93rEfYHB6hF82sKdZpUDFWkViLByLd1k1Ms/bitpRsDktxXjwcQvx11p3JZ4A8ucwM1AYBgjNfhr3yf/' programs/manifest/src/lib.rs
sed -i 's/4859840929024028656/15533312255830019719/' programs/manifest/src/validation/manifest_checker.rs
sed -i 's/\[33, 31, 11, 6, 133, 143, 39, 71\]/[228, 66, 25, 184, 68, 250, 83, 68]/' programs/manifest/src/logs.rs
sed -i 's/\[129, 77, 152, 210, 218, 144, 163, 56\]/[83, 80, 13, 195, 157, 15, 144, 87]/' programs/manifest/src/logs.rs
sed -i 's/\[23, 214, 24, 34, 52, 104, 109, 188\]/[67, 61, 36, 241, 56, 245, 238, 146]/' programs/manifest/src/logs.rs
sed -i 's/\[112, 218, 111, 63, 18, 95, 136, 35\]/[216, 76, 133, 25, 77, 4, 208, 169]/' programs/manifest/src/logs.rs
sed -i 's/\[58, 230, 242, 3, 75, 113, 4, 169\]/[52, 81, 147, 82, 119, 191, 72, 172]/' programs/manifest/src/logs.rs
sed -i 's/\[157, 118, 247, 213, 47, 19, 164, 120\]/[192, 6, 190, 126, 253, 107, 243, 124]/' programs/manifest/src/logs.rs
sed -i 's/\[22, 65, 71, 33, 244, 235, 255, 215\]/[203, 247, 55, 164, 199, 233, 155, 33]/' programs/manifest/src/logs.rs
mkdir -p target/deploy
echo "[151,8,48,152,68,30,226,198,60,77,31,58,178,181,32,89,229,203,74,21,125,127,220,171,148,2,58,248,111,112,218,58,8,229,29,213,101,63,98,202,13,39,74,3,188,95,195,65,60,246,83,247,221,124,176,114,136,100,191,104,177,76,52,70]" > target/deploy/manifest-keypair.json
cargo build-sbf
echo "Rebuilt program"
rm target/deploy/manifest-keypair.json
touch target/deploy/manifest-keypair.json
echo "[151,8,48,152,68,30,226,198,60,77,31,58,178,181,32,89,229,203,74,21,125,127,220,171,148,2,58,248,111,112,218,58,8,229,29,213,101,63,98,202,13,39,74,3,188,95,195,65,60,246,83,247,221,124,176,114,136,100,191,104,177,76,52,70]" > target/deploy/manifest-keypair.json
solana config set --url l
solana program deploy target/deploy/manifest.so > deploy.log
cat deploy.log

solana program deploy target/deploy/wrapper.so > deploy.log
cat deploy.log
sed -i 's/'$(awk -F\" '/declare_id!/ {print$2}' programs/wrapper/src/lib.rs)'/'$(awk '/Program Id:/ {print$3}' deploy.log)'/' client/ts/src/wrapper/index.ts
for f in $(ls client/ts/src/wrapper/instructions); do
sed -i 's/'$(awk -F\" '/declare_id!/ {print$2}' programs/wrapper/src/lib.rs)'/'$(awk '/Program Id:/ {print$3}' deploy.log)'/' client/ts/src/wrapper/instructions/$f
echo "Updated -> $f"
done
sed -i 's/'$(awk -F\" '/declare_id!/ {print$2}' programs/wrapper/src/lib.rs)'/'$(awk '/Program Id:/ {print$3}' deploy.log)'/' client/ts/src/wrapper/instructions/*
sed -i 's/'$(awk -F\" '/declare_id!/ {print$2}' programs/wrapper/src/lib.rs)'/'$(awk '/Program Id:/ {print$3}' deploy.log)'/' programs/wrapper/src/lib.rs

for f in $(ls client/ts/src/manifest/instructions); do
sed -i 's/MNFSTqtC93rEfYHB6hF82sKdZpUDFWkViLByLd1k1Ms/bitpRsDktxXjwcQvx11p3JZ4A8ucwM1AYBgjNfhr3yf/' client/ts/src/manifest/instructions/$f
echo "Updated -> $f"
done
sed -i 's/MNFSTqtC93rEfYHB6hF82sKdZpUDFWkViLByLd1k1Ms/bitpRsDktxXjwcQvx11p3JZ4A8ucwM1AYBgjNfhr3yf/' client/ts/src/manifest/index.ts

echo "Built and deployed"

cargo build-sbf
echo "Rebuilt and redeploying because program id is hardcoded"

solana program deploy target/deploy/manifest.so
solana program deploy target/deploy/wrapper.so
echo "Done redeploy"

yarn clean
yarn build

- name: Run test
run: |
yarn test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
verbose: true
fail_ci_if_error: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

ts-pass:
name: TS tests pass
needs: ['format', 'lint', 'test', 'depcheck']
runs-on: ubuntu-latest
steps:
- run: echo ok
Loading
Loading