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

Migrate tooling to pnpm, biome, lefthook and vitest #32

Merged
merged 13 commits into from
Nov 4, 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
45 changes: 0 additions & 45 deletions .github/workflows/check-build-test.yaml

This file was deleted.

63 changes: 63 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: CI

on:
pull_request:
branches:
- main
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "23"
- uses: pnpm/action-setup@v4
- run: pnpm install
- run: pnpm exec biome format
- run: pnpm exec biome lint
- run: pnpm exec tsc -p client-vms/tsconfig.json

test-client-vms:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Aws credentials are required so that nilup can access rc builds
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: "eu-west-1"
- uses: NillionNetwork/nillion-setup-action@main
with:
version: "v0.7.0-rc.38"
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: |
cd client-vms/tests-nada-programs
./build.sh
- uses: actions/setup-node@v4
with:
node-version: "23.0"
- uses: pnpm/action-setup@v4
- run: pnpm install
- run: |
nillion-devnet --seed test &
sleep 10
cd client-vms
pnpm vitest --coverage
killall -9 nillion-devnet
- run: cat client-vms/coverage/coverage-summary.json
- uses: davelosert/vitest-coverage-report-action@v2
if: always()
with:
working-directory: ./client-vms
comment-on: "pr"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
.DS_Store
.idea
.vscode
.husky

packages/**/gen-proto
**/gen-proto
!client-wasm/dist

node_modules
Expand Down
4 changes: 0 additions & 4 deletions .husky/commit-msg

This file was deleted.

3 changes: 0 additions & 3 deletions .husky/pre-commit

This file was deleted.

3 changes: 0 additions & 3 deletions .prettierignore

This file was deleted.

6 changes: 0 additions & 6 deletions .prettierrc.yaml

This file was deleted.

47 changes: 47 additions & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": false,
"include": ["client-vms/**/*.ts", "client-vms/*.mjs", "**/*.json"],
"ignore": ["client-vms/src/gen-proto"]
},
"formatter": {
"enabled": true,
"indentStyle": "space"
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"all": true,
"correctness": {
"all": true,
"noUndeclaredDependencies": "off",
"useImportExtensions": "off",
"noNodejsModules": "off"
},
"style": {
"all": true,
"noNonNullAssertion": "off",
"useNamingConvention": "off",
"noParameterProperties": "off"
},
"suspicious": {
"all": false
}
}
},
"javascript": {
"formatter": {
"quoteStyle": "double",
"trailingCommas": "all"
}
}
}
5 changes: 1 addition & 4 deletions client-react-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@
"browserslist": "^4.24.0",
"esbuild-plugin-browserslist": "^0.15.0"
},
"files": [
"dist",
"src"
]
"files": ["dist", "src"]
}
2 changes: 1 addition & 1 deletion client-react-hooks/src/nillion-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export const NillionProvider: React.FC<
// default to photon
let combined: ProviderNetworkConfig = NamedNetworkConfig.photon;

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- parse and on failure throw if invalid "network" value
if (network && NamedNetwork.parse(network)) {
combined = NamedNetworkConfig[network];
}
Expand All @@ -87,6 +86,7 @@ export const NillionProvider: React.FC<
}, []);

const context: NillionContext = {
// @ts-ignore
chainClient: nillionClient,
logout: async () => {
await nillionClient.disconnect();
Expand Down
1 change: 0 additions & 1 deletion client-react-hooks/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"jsx": "react"
}
Expand Down
8 changes: 6 additions & 2 deletions client-vms/.env → client-vms/.env.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
NILLION_BOOTNODE_URL=http://localhost:37939
# Nillion devnet parameters for --seed test
NILLION_CLUSTER_ID=b3b307bd-aaff-49f5-a73c-2e2546dca320
NILLION_NILCHAIN_CHAIN_ID=nillion-chain-devnet
NILLION_NILCHAIN_JSON_RPC=http://localhost:48102
NILLION_NILCHAIN_JSON_RPC=http://127.0.0.1:48102
NILLION_NILCHAIN_REST_API=http://localhost:26650
NILLION_NILCHAIN_GRPC=localhost:26649
NILLION_GRPC_ENDPOINT=http://127.0.0.1:43207
NILLION_NILCHAIN_PRIVATE_KEY_0=9a975f567428d054f2bf3092812e6c42f901ce07d9711bc77ee2cd81101f42c5
NILLION_NILCHAIN_PRIVATE_KEY_1=1e491133b9408b39572a29f91644873decea554224b20e2b0b923aeb860a1c18
NILLION_NILCHAIN_PRIVATE_KEY_2=980488572f235316cdb330191f8bafe4e635efbe88b3a40f5bee9bd21047c059
Expand Down
23 changes: 0 additions & 23 deletions client-vms/jest.config.ts

This file was deleted.

18 changes: 9 additions & 9 deletions client-vms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
"build": "node esbuild.config.mjs",
"build:watch": "node esbuild.config.mjs --watch",
"build:proto": "npx buf generate",
"test": "node --experimental-vm-modules --no-warnings ../node_modules/jest/bin/jest.js"
"test": "vitest test"
},
"dependencies": {
"@bufbuild/protobuf": "^2.2.0",
"@connectrpc/connect": "^2.0.0-beta.1",
"@connectrpc/connect-web": "^2.0.0-beta.1",
"@cosmjs/proto-signing": "^0.32.4",
"@cosmjs/stargate": "^0.32.4",
"@nillion/client-wasm": "0.2.0-rc.0",
"@nillion/client-wasm": "workspace:^",
"@noble/curves": "^1.6.0",
"@noble/hashes": "^1.5.0",
"@noble/secp256k1": "^2.1.0",
Expand All @@ -36,18 +36,18 @@
"devDependencies": {
"@bufbuild/buf": "^1.45.0",
"@bufbuild/protoc-gen-es": "^2.2.0",
"@jest/globals": "^29.7.0",
"@keplr-wallet/types": "^0.12.142",
"@types/debug": "^4.1.12",
"@types/node": "^22.8.7",
"@types/uuid": "^10.0.0",
"@vitest/coverage-v8": "^2.1.4",
"browserslist": "^4.24.2",
"dotenv": "^16.4.5",
"esbuild-plugin-browserslist": "^0.15.0",
"jest": "^29.7.0",
"ts-jest": "^29.2.5"
"vite": "^5.4.10",
"vite-plugin-wasm": "^3.3.0",
"vite-tsconfig-paths": "^5.0.1",
"vitest": "^2.1.4"
},
"files": [
"dist",
"src"
]
"files": ["dist", "src"]
}
13 changes: 6 additions & 7 deletions client-vms/src/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { create, fromBinary, toBinary } from "@bufbuild/protobuf";
import { timestampFromDate } from "@bufbuild/protobuf/wkt";
import { describe, it } from "@jest/globals";

import { TokenAuthManager } from "@nillion/client-vms/auth";
import { describe, expect, it } from "vitest";
import { TokenAuthManager } from "#/auth";
import {
SignedToken,
type SignedToken,
TokenSchema,
} from "@nillion/client-vms/gen-proto/nillion/auth/v1/token_pb";
import { NodeIdSchema } from "@nillion/client-vms/gen-proto/nillion/membership/v1/cluster_pb";
import { PartyId } from "@nillion/client-vms/types";
} from "#/gen-proto/nillion/auth/v1/token_pb";
import { NodeIdSchema } from "#/gen-proto/nillion/membership/v1/cluster_pb";
import { PartyId } from "#/types/types";

describe("TokenManager", () => {
const manager = TokenAuthManager.fromSeed("test");
Expand Down
18 changes: 8 additions & 10 deletions client-vms/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ import type { Interceptor } from "@connectrpc/connect";
import { secp256k1 } from "@noble/curves/secp256k1";
import { sha256 } from "@noble/hashes/sha2";
import { randomBytes } from "@noble/hashes/utils";

import {
PublicKey,
type PublicKey,
PublicKeySchema,
PublicKeyType,
} from "@nillion/client-vms/gen-proto/nillion/auth/v1/public_key_pb";
} from "#/gen-proto/nillion/auth/v1/public_key_pb";
import {
SignedToken,
type SignedToken,
SignedTokenSchema,
Token,
type Token,
TokenSchema,
} from "@nillion/client-vms/gen-proto/nillion/auth/v1/token_pb";
import { NodeIdSchema } from "@nillion/client-vms/gen-proto/nillion/membership/v1/cluster_pb";
import { PartyId } from "@nillion/client-vms/types";
} from "#/gen-proto/nillion/auth/v1/token_pb";
import { NodeIdSchema } from "#/gen-proto/nillion/membership/v1/cluster_pb";
import type { PartyId } from "#/types/types";

const HEADER_NAME_BASE64_AUTH = "x-nillion-token";
const NONCE_LENGTH = 32;
Expand Down Expand Up @@ -89,9 +88,8 @@ export class TokenAuthManager {
const expires = timestampDate(token.expiresAt);
const now = new Date();
return expires < now;
} else {
return false;
}
return false;
}

verify(signed: SignedToken): boolean {
Expand Down
2 changes: 1 addition & 1 deletion client-vms/src/gen-proto/nillion/auth/v1/public_key_pb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by protoc-gen-es v2.2.0 with parameter "target=ts"
// @generated by protoc-gen-es v2.2.2 with parameter "target=ts"
// @generated from file nillion/auth/v1/public_key.proto (package nillion.auth.v1.public_key, syntax proto3)
/* eslint-disable */

Expand Down
2 changes: 1 addition & 1 deletion client-vms/src/gen-proto/nillion/auth/v1/token_pb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by protoc-gen-es v2.2.0 with parameter "target=ts"
// @generated by protoc-gen-es v2.2.2 with parameter "target=ts"
// @generated from file nillion/auth/v1/token.proto (package nillion.auth.v1.token, syntax proto3)
/* eslint-disable */

Expand Down
2 changes: 1 addition & 1 deletion client-vms/src/gen-proto/nillion/auth/v1/user_pb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by protoc-gen-es v2.2.0 with parameter "target=ts"
// @generated by protoc-gen-es v2.2.2 with parameter "target=ts"
// @generated from file nillion/auth/v1/user.proto (package nillion.auth.v1.user, syntax proto3)
/* eslint-disable */

Expand Down
2 changes: 1 addition & 1 deletion client-vms/src/gen-proto/nillion/compute/v1/invoke_pb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by protoc-gen-es v2.2.0 with parameter "target=ts"
// @generated by protoc-gen-es v2.2.2 with parameter "target=ts"
// @generated from file nillion/compute/v1/invoke.proto (package nillion.compute.v1.invoke, syntax proto3)
/* eslint-disable */

Expand Down
2 changes: 1 addition & 1 deletion client-vms/src/gen-proto/nillion/compute/v1/retrieve_pb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by protoc-gen-es v2.2.0 with parameter "target=ts"
// @generated by protoc-gen-es v2.2.2 with parameter "target=ts"
// @generated from file nillion/compute/v1/retrieve.proto (package nillion.compute.v1.retrieve, syntax proto3)
/* eslint-disable */

Expand Down
2 changes: 1 addition & 1 deletion client-vms/src/gen-proto/nillion/compute/v1/service_pb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by protoc-gen-es v2.2.0 with parameter "target=ts"
// @generated by protoc-gen-es v2.2.2 with parameter "target=ts"
// @generated from file nillion/compute/v1/service.proto (package nillion.compute.v1, syntax proto3)
/* eslint-disable */

Expand Down
Loading