From ab7c4add3ed775a9650a0d85923c962f6048e46f Mon Sep 17 00:00:00 2001 From: Ivan Zhelyazkov Date: Tue, 27 Aug 2024 14:19:50 +0300 Subject: [PATCH 1/4] fix health tests --- .github/workflows/health.yml | 12 +++++++++--- deploy/tests/network.ts | 2 -- deployments/run-fork.sh | 32 +++++++++++++++++++++++++++++--- package.json | 4 ++-- test/network/BancorNetwork.ts | 1 - 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/.github/workflows/health.yml b/.github/workflows/health.yml index d15b33753..3ae8bfc7a 100644 --- a/.github/workflows/health.yml +++ b/.github/workflows/health.yml @@ -9,8 +9,7 @@ jobs: test: name: Health Checks - runs-on: [self-hosted, HEALTH] - timeout-minutes: 600 + runs-on: ubuntu-latest steps: - name: Check out the repository @@ -43,6 +42,14 @@ jobs: - name: Build run: yarn build + - name: Setup tenderly + run: | + mkdir ~/.tenderly + touch ~/.tenderly/config.yaml + echo "access_key: $TENDERLY_ACCESS_KEY" >> ~/.tenderly/config.yaml + env: + TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }} + - name: Test deployment and network health run: yarn test:health env: @@ -50,4 +57,3 @@ jobs: TENDERLY_TEST_PROJECT: v3-temp-forks TENDERLY_USERNAME: bancor TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }} - SENTRY_DSN: ${{ secrets.SENTRY_DSN }} diff --git a/deploy/tests/network.ts b/deploy/tests/network.ts index a44110dd4..4cdd37b18 100644 --- a/deploy/tests/network.ts +++ b/deploy/tests/network.ts @@ -106,8 +106,6 @@ import { getNamedAccounts } from 'hardhat'; }); it('should have the correct set of roles', async () => { - const { deployer, deployerV2 } = await getNamedAccounts(); - // ensure that ownership transfer to the DAO was initiated expect(await liquidityProtection.newOwner()).to.equal(daoMultisig.address); diff --git a/deployments/run-fork.sh b/deployments/run-fork.sh index cd943e5c7..f1b737e70 100755 --- a/deployments/run-fork.sh +++ b/deployments/run-fork.sh @@ -12,6 +12,18 @@ else project=${TENDERLY_PROJECT} fi +# Read the network name from the environment variable, default to 'mainnet' if not set +network_name=${TENDERLY_NETWORK_NAME:-'mainnet'} + +# Check if network_id is null or empty +if [ -z "$network_id" ] || [ "$network_id" == "null" ]; then + # Fallback to the default network ID + network_id=${TENDERLY_NETWORK_ID:-"1"} +fi + +echo "Creating a $network_name Tenderly Fork with Chain Id $network_id... " +echo + TENDERLY_FORK_API="https://api.tenderly.co/api/v1/account/${username}/project/${project}/fork" cleanup() { @@ -28,12 +40,26 @@ trap cleanup TERM EXIT fork_id=$(curl -sX POST "${TENDERLY_FORK_API}" \ -H "Content-Type: application/json" -H "X-Access-Key: ${TENDERLY_ACCESS_KEY}" \ - -d '{"network_id": "1"}' | jq -r '.simulation_fork.id') + -d '{"network_id": "'${network_id}'"}' | jq -r '.simulation_fork.id') -echo "Created a fork ${fork_id} at ${username}/${project}..." +echo "Created Tenderly Fork ${fork_id} at ${username}/${project}..." echo -command="TENDERLY_FORK_ID=${fork_id} ${@:1}" +# if deployments/${network_name} doesn't exist, create it and create a .chainId file +if [ ! -d "./deployments/${network_name}" ]; then + mkdir -p ./deployments/${network_name} + echo ${network_id} > ./deployments/${network_name}/.chainId +fi + +# if deploy/scripts/${network_name} doesn't exist, create it and copy the network scripts +if [ ! -d "./deploy/scripts/${network_name}" ]; then + rsync -a --delete ./deploy/scripts/network/ ./deploy/scripts/${network_name}/ +fi + +# Create a new dir for the deploy script files and copy them there +rm -rf deployments/tenderly && cp -rf deployments/${network_name}/. deployments/tenderly + +command="TENDERLY_FORK_ID=${fork_id} TENDERLY_NETWORK_NAME=${network_name} ${@:1}" echo "Running:" echo diff --git a/package.json b/package.json index 6aa3c322b..03828d1e0 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,8 @@ "test:coverage:nightly": "NIGHTLY=1 yarn test:coverage", "test:ci": "CI=1 yarn test", "test:nightly": "NIGHTLY=1 CI=1 NODE_OPTIONS='--max-old-space-size=8192' hardhat test", - "test:deploy": "yarn deploy:prepare:fork && TEST_FORK=1 ./deployments/run-fork.sh HARDHAT_NETWORK=tenderly mocha --require hardhat/register --extension ts --recursive --exit --timeout 600000 --bail --no-exit 'deploy/tests/**/*.ts'", - "test:health": "yarn test:deploy --reporter test/reporters/SentryReporter", + "test:deploy": "TEST_FORK=1 ./deployments/run-fork.sh HARDHAT_NETWORK=tenderly mocha --require hardhat/register --extension ts --recursive --exit --timeout 600000 --bail --no-exit 'deploy/tests/**/*.ts'", + "test:health": "yarn test:deploy", "export:storage": "yarn rebuild && hardhat run deployments/storage-layout.ts", "deploy:prepare": "rm -rf ./node_modules && rm yarn.lock && yarn && yarn rebuild", "deploy:prepare:fork": "rm -rf deployments/tenderly && cp -rf deployments/mainnet/. deployments/tenderly", diff --git a/test/network/BancorNetwork.ts b/test/network/BancorNetwork.ts index a58b13d37..df4ba6e37 100644 --- a/test/network/BancorNetwork.ts +++ b/test/network/BancorNetwork.ts @@ -3190,7 +3190,6 @@ describe('BancorNetwork', () => { let token: TokenWithAddress; let emergencyStopper: SignerWithAddress; - let networkFeeManager: SignerWithAddress; const INITIAL_LIQUIDITY = toWei(50_000_000); const TRADING_FEE_PPM = toPPM(10); From 077e3b075758c7dbd1d269413e1fed587a6c5e77 Mon Sep 17 00:00:00 2001 From: Ivan Zhelyazkov Date: Tue, 27 Aug 2024 14:29:13 +0300 Subject: [PATCH 2/4] switch ci tests to github runners --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5123c27bd..432591c32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: test: name: Test - runs-on: [self-hosted, CI] + runs-on: ubuntu-latest timeout-minutes: 600 steps: From a2a0553b1034985ca1bda8f9b8b7431b0c8ea5f8 Mon Sep 17 00:00:00 2001 From: Ivan Zhelyazkov Date: Tue, 27 Aug 2024 14:34:23 +0300 Subject: [PATCH 3/4] minor fix --- test/network/BancorNetwork.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/network/BancorNetwork.ts b/test/network/BancorNetwork.ts index df4ba6e37..9526f194f 100644 --- a/test/network/BancorNetwork.ts +++ b/test/network/BancorNetwork.ts @@ -3195,7 +3195,7 @@ describe('BancorNetwork', () => { const TRADING_FEE_PPM = toPPM(10); before(async () => { - [, emergencyStopper, networkFeeManager] = await ethers.getSigners(); + [, emergencyStopper] = await ethers.getSigners(); }); beforeEach(async () => { From 3db58bb3174d13b8b431cc2d145f2f2bc69d6d6a Mon Sep 17 00:00:00 2001 From: Ivan Zhelyazkov Date: Tue, 27 Aug 2024 14:40:29 +0300 Subject: [PATCH 4/4] add tenderly config to ci --- .github/workflows/ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 432591c32..63869e71c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,5 +54,13 @@ jobs: - name: Build run: yarn build + - name: Setup tenderly + run: | + mkdir ~/.tenderly + touch ~/.tenderly/config.yaml + echo "access_key: $TENDERLY_ACCESS_KEY" >> ~/.tenderly/config.yaml + env: + TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }} + - name: Test run: yarn test:ci