Skip to content

Commit

Permalink
Tests handle provider request (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanmino committed Mar 6, 2024
1 parent d0909b2 commit a11ec59
Show file tree
Hide file tree
Showing 10 changed files with 721 additions and 38 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,18 @@ jobs:
name: node_modules.tar.gz
- name: Unzip node_modules
run: tar xzf node_modules.tar.gz
- name: Append GitHub Access Token to .env
run: echo "ETH_MAINNET_RPC=${{ secrets.ETH_MAINNET_RPC }}" >> .env
- name: Install Anvil
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Run tests
run: yarn test
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 3
command: yarn test

# LINT, TYPECHECK, AUDIT
ci-checks:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.DS_Store
dist/
node_modules/
yarn-error.log
yarn-error.log

.env
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@
],
"scripts": {
"build": "tsc",
"test": "vitest",
"test": "./scripts/tests.sh",
"lint": "eslint --cache --max-warnings 0",
"typecheck": "tsc --noEmit",
"check-lockfile": "./scripts/check-lockfile.sh",
"audit:ci": "yarn audit-ci --moderate --config audit-ci.jsonc"
"audit:ci": "yarn audit-ci --moderate --config audit-ci.jsonc",
"anvil": "ETH_MAINNET_RPC=$(grep ETH_MAINNET_RPC .env | cut -d '=' -f2) && anvil --fork-url $ETH_MAINNET_RPC",
"anvil:kill": "lsof -i :8545|tail -n +2|awk '{print $2}'|xargs -r kill -s SIGINT"
},
"type": "module",
"module": "dist/index.js",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "6.20.0",
"@typescript-eslint/parser": "6.20.0",
"anvil": "0.0.6",
"audit-ci": "6.6.1",
"eslint": "8.56.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.1.3",
"jsdom": "^24.0.0",
"jsdom": "24.0.0",
"prettier": "3.2.4",
"typescript": "5.3.3",
"vitest": "^1.3.1"
"vitest": "1.3.1"
},
"dependencies": {
"@ethersproject/abstract-provider": "5.7.0",
Expand Down
29 changes: 29 additions & 0 deletions scripts/tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
ANVIL_PORT=8545

# Launch anvil in the bg
yarn anvil:kill
yarn anvil --chain-id 1 &
echo "Launching Anvil..."

# Give it some time to boot
interval=5
until nc -z localhost $ANVIL_PORT; do
sleep $interval
interval=$((interval * 2))
done
echo "Anvil Launched..."

# Run the tests and store the result
echo "Running Tests..."
yarn vitest --reporter=verbose --bail 1

# Store exit code
TEST_RESULT=$?

# kill anvil
echo "Cleaning Up..."
yarn anvil:kill

# return the result of the tests
exit "$TEST_RESULT"

0 comments on commit a11ec59

Please sign in to comment.