Skip to content

Commit

Permalink
AVS v1.3.1 - Export Node data types, fix compareResult in tests (#68)
Browse files Browse the repository at this point in the history
* v1.3.4-dev.0

* Removed matcher from EventTrigger

* v0.9.4-dev.0

* v1.3.4-dev.1

* Revert "v0.9.4-dev.0"

This reverts commit 0ad7ea2.

* v1.3.4-dev.2

* Limit import of grpc library

* Export node and trigger data type

* v1.3.4-dev.3

* Revert "Removed matcher from EventTrigger"

This reverts commit 6bb4a52.

* Updated test utils for the compareResults() function

* Moved GetKeyRequest and its message function to types

* Moved GetKeyRequest types to the types package

* Save the current progress of editing

* --amend

* Fix the tsbuild error caused by tsup

* v0.9.4-dev.0

* v0.9.4-dev.1

* v0.9.4-dev.2

* Updated package release instructions in README

* correct signatuee due to wrong indentation and fix failed test (#73)

* correct signatuee due to wrong indentation

* fix all test

* rename

* Break tests into suites in github actions

* Break tests into suites in github actions (#76)

* Separate local test on PR into multiple workflows

* Upgrade npm versions of packages

---------

Co-authored-by: Vinh <vinh@avaprotocol.org>
  • Loading branch information
chrisli30 and v9n authored Feb 6, 2025
1 parent 37cdbd6 commit af371fa
Show file tree
Hide file tree
Showing 39 changed files with 794 additions and 697 deletions.
43 changes: 37 additions & 6 deletions .github/workflows/dev-test-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,41 @@ jobs:
sleep 5
done
- name: Run tests againts local AVS
- name: Build
run: yarn build

- name: Setup test environment
id: setup-env
run: |
export TEST_API_KEY="$(docker compose exec aggregator /ava create-api-key --role=admin --subject=apikey)"
export ENDPOINT="localhost:2206"
# We need to run yarn build here because the test is still importing from dist
yarn build
yarn test
echo "TEST_API_KEY=$(docker compose exec aggregator /ava create-api-key --role=admin --subject=apikey)" >> $GITHUB_ENV
echo "ENDPOINT=localhost:2206" >> $GITHUB_ENV
- name: Test Authentication
run: yarn test:auth

- name: Test Create Workflow
run: yarn test:createWorkflow

- name: Test Get Workflow
run: yarn test:getWorkflow

- name: Test Get Workflows
run: yarn test:getWorkflows

- name: Test Cancel Workflow
run: yarn test:cancelWorkflow

- name: Test Delete Workflow
run: yarn test:deleteWorkflow

- name: Test Get Executions
run: yarn test:getExecutions

- name: Test Get Wallet
run: yarn test:getWallet

- name: Test Get Wallets
run: yarn test:getWallets

- name: Test Secret
run: yarn test:secret
78 changes: 53 additions & 25 deletions .github/workflows/staging-test-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ name: Run tests against staging on PR

on:
pull_request:
branches: [ main ]
branches: [main]

jobs:
staging-test:
runs-on: ubuntu-latest
environment: test # The below environment variables are only available in the test environment

env:
TEST_API_KEY: ${{ secrets.TEST_API_KEY }}
TEST_PRIVATE_KEY: ${{ secrets.TEST_PRIVATE_KEY }}
Expand All @@ -24,27 +24,55 @@ jobs:
# on local test is continously wipe out on every run so it isn't a problem like staging
# We may want to sweep and delete task data on those test account
RUN_ID: ${{ github.run_id }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Debug environment variables
run: |
echo "TOKEN_CONTRACT: $TOKEN_CONTRACT"
echo "ORACLE_CONTRACT: $ORACLE_CONTRACT"
echo "ENDPOINT: $ENDPOINT"
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'yarn'

- name: Install dependencies
run: yarn install

- name: Run tests againts staging AVS
run: |
yarn build
yarn test
- name: Checkout repository
uses: actions/checkout@v4

- name: Debug environment variables
run: |
echo "TOKEN_CONTRACT: $TOKEN_CONTRACT"
echo "ORACLE_CONTRACT: $ORACLE_CONTRACT"
echo "ENDPOINT: $ENDPOINT"
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
cache: "yarn"

- name: Install dependencies
run: yarn install

- name: Build
run: yarn build

- name: Test Authentication
run: yarn test:auth

- name: Test Create Workflow
run: yarn test:createWorkflow

- name: Test Get Workflow
run: yarn test:getWorkflow

- name: Test Get Workflows
run: yarn test:getWorkflows

- name: Test Cancel Workflow
run: yarn test:cancelWorkflow

- name: Test Delete Workflow
run: yarn test:deleteWorkflow

- name: Test Get Executions
run: yarn test:getExecutions

- name: Test Get Wallet
run: yarn test:getWallet

- name: Test Get Wallets
run: yarn test:getWallets

- name: Test Secret
run: yarn test:secret
41 changes: 19 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,22 @@ To ensure the SDK is functioning correctly, we have a comprehensive test suite.
## Release Process
This repository uses a two-step workflow process for creating new releases:
### Releasing a new version for development
Once a package is ready for a new version, we first publish a dev version and test it in local environment.
1. Run `npm version prerelease --preid=dev` under either `packages/sdk-js` or `packages/types` to update the version in `package.json`.
2. Run `npm publish --tag dev` under either `packages/sdk-js` or `packages/types` to publish the new dev version to NPM. Most importantly, this **bumps up version number** in `package.json` of `packages/types`.
3. If the `types` package has a new version, since it is depended on by `sdk-js`, we need to make sure `sdk-js` can build with the new version.
1. `yarn run clean` **at the root folder** to remove existing node_modules folder and yarn.lock file.
2. Run `yarn install` under the root folder to re-install the dependencies. You should see a prompt asking the version of `@avaprotocol/types` to install. Choose the new version you just created in step 1.
3. Run `yarn build` under the root folder to build all packages.
4. Run `yarn run test` under the root folder to run all tests.
### Publishing to NPM
Once the dev version is tested and ready to be published to NPM, `changeset` can be used to create a new release for NPM.
1. **Record changeset workflow**
Expand All @@ -117,30 +132,12 @@ This repository uses a two-step workflow process for creating new releases:
- Examine the Pull Request created by the workflow, and merge it if everything looks correct. This will record any commits before it as a major, minor, or patch.
2. **Create release workflow**
- Go to the "Actions" tab in GitHub and run the "Create Release" workflow. This will run `npx changeset version` to bump up version in `package.json` based on the recorded changeset files. It will also create a new GitHub Release if the new version is higher than the current version in `package.json`.
There are two ways to create a release:
- Manually create a release in the GitHub UI. This will run `npx changeset version` to bump up version in `package.json` based on the recorded changeset files. It will also create a new GitHub Release if the new version is higher than the current version in `package.json`.
- Automatically create a release when a PR is merged. This will run `npx changeset version` to bump up version in `package.json` based on the recorded changeset files. It will also create a new GitHub Release if the new version is higher than the current version in `package.json`.
3. **Publish to NPM**
- After the last step, the version number in `package.json` is updated and a git tag with the new version number is created. Now you can publish the production version to NPM using `npm publish`.
### NPM Publishing Dev Versions
The NPM publishing of dev versions can be handled manually, since the test cases reference the dist folder and don’t require a new version on NPM. NPM publish on dev tag is only required for testing the new version in a web app.
1. Publish a dev version and test it in your local environment. The `npm publish` will use the version number in `package.json`, so run `npm version prerelease --preid=dev` first if you need a new version number.
```bash
# Optionally, update version with dev tag in package.json
yarn workspace @avaprotocol/types version --prerelease --preid=dev
# Publish to npm with dev tag
npm publish --tag dev
```
2. Once tested, and a release is created using GitHub Actions, publish the production version to NPM:
```bash
# Publish to npm with latest tag
npm publish
```
### Utility Scripts
To generate the key request message for signing, you can run the following command:
Expand Down
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@
"gen-protoc": "grpc_tools_node_protoc --js_out=import_style=commonjs,binary:./grpc_codegen/ --grpc_out=grpc_js:./grpc_codegen/ --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts --ts_out=grpc_js:./grpc_codegen --proto_path=./grpc_codegen grpc_codegen/avs.proto",
"gen-apikey": "sh -c 'API_KEY=$(docker compose exec aggregator /ava create-api-key --role=admin --subject=apikey) && echo \"Generated API key for tests: $API_KEY\" && echo \"Writing to .env.test to replace the TEST_API_KEY env variable\" && sed -i \"\" -e \"s/^TEST_API_KEY=.*/TEST_API_KEY=$API_KEY/\" .env.test && echo \"Done.\"'",
"build": "yarn workspaces run build",
"clean": "yarn workspaces run clean",
"clean": "rm -rf node_modules yarn.lock && yarn workspaces run clean",
"test": "jest --config jest.config.cjs",
"test:select": "npm run test -- --testNamePattern"
"test:auth": "jest tests/auth.test.ts --verbose --runInBand",
"test:createWorkflow": "jest tests/createWorkflow.test.ts --verbose --runInBand",
"test:getWorkflow": "jest tests/getWorkflow.test.ts --verbose --runInBand",
"test:getWorkflows": "jest tests/getWorkflows.test.ts --verbose --runInBand",
"test:cancelWorkflow": "jest tests/cancelWorkflow.test.ts --verbose --runInBand",
"test:deleteWorkflow": "jest tests/deleteWorkflow.test.ts --verbose --runInBand",
"test:getExecutions": "jest tests/getExecutions.test.ts --verbose --runInBand",
"test:getWallet": "jest tests/getWallet.test.ts --verbose --runInBand",
"test:getWallets": "jest tests/getWallets.test.ts --verbose --runInBand",
"test:secret": "jest tests/secret.test.ts --verbose --runInBand"
},
"devDependencies": {
"@babel/core": "^7.26.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/sdk-js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @avaprotocol/sdk-js

## 1.3.4

### Patch Changes

- Migrated getKeyRequestMessage to types; Added secret functions
- Updated dependencies
- @avaprotocol/types@0.9.4

## 1.3.3

### Patch Changes
Expand Down
10 changes: 3 additions & 7 deletions packages/sdk-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@avaprotocol/sdk-js",
"version": "1.3.3",
"version": "1.3.4",
"description": "A JavaScript/TypeScript SDK designed to simplify integration with Ava Protocol's AVS",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -24,7 +24,7 @@
},
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts",
"clean": "rm -rf dist"
"clean": "rm -rf node_modules dist tsconfig.tsbuildinfo"
},
"dependencies": {
"@avaprotocol/types": "workspace:*",
Expand All @@ -37,10 +37,6 @@
"lodash": "^4.17.21"
},
"devDependencies": {
"@types/google-protobuf": "^3.15.12",
"@types/lodash": "^4.17.12",
"globals": "^15.13.0",
"tsup": "^8.0.2",
"typescript": "^5.4.2"
"@types/google-protobuf": "^3.15.12"
}
}
6 changes: 3 additions & 3 deletions packages/sdk-js/src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export const getKeyRequestMessage = (chainId: number, address: string, issuedAt: string, expiredAt: string): string => {
export const getKeyRequestMessage = (chainId: number, address: string, issuedAt: Date, expiredAt: Date): string => {
return `Please sign the below text for ownership verification.
URI: https://app.avaprotocol.org
Chain ID: ${chainId}
Version: 1
Issued At: ${issuedAt}
Expire At: ${expiredAt}
Issued At: ${issuedAt.toISOString()}
Expire At: ${expiredAt.toISOString()}
Wallet: ${address}`;

}
Loading

0 comments on commit af371fa

Please sign in to comment.