Skip to content

Commit

Permalink
Fix reset network back to mainnet fork
Browse files Browse the repository at this point in the history
  • Loading branch information
zZoMROT committed Jan 30, 2024
1 parent 1a43ad1 commit 2ce2222
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
24 changes: 24 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const { network } = require('hardhat');
const { Networks } = require('@1inch/solidity-utils/hardhat-setup');

const defaultValues = {
thresholdFilter: 10,
};
Expand Down Expand Up @@ -148,9 +151,30 @@ const deployParams = {
},
};

const resetHardhatNetworkFork = async function (networkName) {
if (networkName.toLowerCase() === 'hardhat') {
await network.provider.request({ // reset to local network
method: 'hardhat_reset',
params: [],
});
} else {
const { url, authKeyHttpHeader } = (new Networks())._parseRpcEnv(process.env[`${networkName.toUpperCase()}_RPC_URL`]);
await network.provider.request({ // reset to networkName fork
method: 'hardhat_reset',
params: [{
forking: {
jsonRpcUrl: url,
httpHeaders: authKeyHttpHeader ? { 'auth-key': authKeyHttpHeader } : undefined,
},
}],
});
}
};

module.exports = {
defaultValues,
tokens,
contracts,
deployParams,
resetHardhatNetworkFork,
};
22 changes: 3 additions & 19 deletions test/oracles/VelodromeV2Oracle.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
const { network } = require('hardhat');
const { assertRoughlyEqualValues, deployContract } = require('@1inch/solidity-utils');
const {
tokens,
deployParams: { VelodromeV2, UniswapV3 },
defaultValues: { thresholdFilter },
resetHardhatNetworkFork,
} = require('../helpers.js');

describe('VelodromeV2Oracle', function () {
before(async function () {
const optimisticRpcUrl = process.env.OPTIMISTIC_RPC_URL;
const [url, authKeyHttpHeader, overflow] = optimisticRpcUrl.split('|');
if (overflow || url === '') {
throw new Error(`Invalid RPC PARAM: ${optimisticRpcUrl}. It should be in the format: <RPC_URL> or <RPC_URL>|<AUTH_KEY_HTTP_HEADER>`);
}
await network.provider.request({ // take optimistic fork
method: 'hardhat_reset',
params: [{
forking: {
jsonRpcUrl: url,
httpHeaders: authKeyHttpHeader ? { 'auth-key': authKeyHttpHeader } : undefined,
},
}],
});
await resetHardhatNetworkFork('optimistic');
});

after(async function () {
await network.provider.request({ // reset back to local network
method: 'hardhat_reset',
params: [],
});
await resetHardhatNetworkFork('mainnet');
});

async function initContracts () {
Expand Down

0 comments on commit 2ce2222

Please sign in to comment.