Skip to content

Commit

Permalink
run with anvil
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanmino committed Mar 1, 2024
1 parent 5511421 commit 4514d0c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
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
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@
],
"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",
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"
4 changes: 2 additions & 2 deletions src/handleProviderRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from './references/messengers';
import { Address, isHex } from 'viem';
import { mainnet, optimism } from 'viem/chains';
import { getDefaultProvider } from '@ethersproject/providers';
import { StaticJsonRpcProvider } from '@ethersproject/providers';

const TESTMAR27_ETH_ADDRESS: Address =
'0x5e087b61aad29559e31565079fcdabe384b44614';
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('handleProviderRequest', () => {
switch (chainId) {
case 1:
default:
return getDefaultProvider('mainnet');
return new StaticJsonRpcProvider('http://127.0.0.1:8545');
}
});
const messengerProviderRequestMock = vi.fn(() => Promise.resolve({}));
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,11 @@ ansi-styles@^5.0.0:
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-5.2.0.tgz#07449690ad45777d1924ac2abb2fc8895dba836b"
integrity sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==

anvil@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/anvil/-/anvil-0.0.6.tgz#f572691462fd76c087fc6b76d77e628a8db7a7aa"
integrity sha512-k9GcppcaE1cruJj1Gi141q/5TlPO2HIitPz99K0tWWh5ImtYG3Lq83lIWQXqrNRA+hX7DN/EjS7J9tCI/wDofQ==

argparse@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
Expand Down

0 comments on commit 4514d0c

Please sign in to comment.