diff --git a/test/_deadline.ts b/test/_deadline.ts index a994a47..91894c6 100644 --- a/test/_deadline.ts +++ b/test/_deadline.ts @@ -1,6 +1,7 @@ import Blockchains from '@depay/web3-blockchains' import deploy from './_helpers/deploy' import now from './_helpers/now' +import reset from './_helpers/reset' import { ethers } from 'hardhat' import { expect } from 'chai' @@ -20,7 +21,8 @@ export default ({ blockchain })=>{ let router let deadline - beforeEach(async ()=>{ + before(async ()=>{ + reset({ blockchain }) wallets = await ethers.getSigners() deadline = now()+ 86400 // 1 day }) diff --git a/test/_helpers/reset.ts b/test/_helpers/reset.ts new file mode 100644 index 0000000..41a0e4b --- /dev/null +++ b/test/_helpers/reset.ts @@ -0,0 +1,20 @@ +import { ethers, network } from 'hardhat' +import { request } from '@depay/web3-client-evm' + +export default async ({ blockchain }) => { + + if([ // blockchains requiring explicit reset + 'avalanche' + ].includes(blockchain)) { + + const blockNumber = await request({ blockchain, method: 'latestBlockNumber' }) + await new Promise(resolve => setTimeout(resolve, 3000)) + await ethers.send("hardhat_reset", [{ + forking: { + jsonRpcUrl: network.config.forking.url, + blockNumber + } + }]) + await new Promise(resolve => setTimeout(resolve, 3000)) + } +} diff --git a/test/_pay-to-contract-receiver.ts b/test/_pay-to-contract-receiver.ts index 64bf9a0..75bc2c5 100644 --- a/test/_pay-to-contract-receiver.ts +++ b/test/_pay-to-contract-receiver.ts @@ -1,11 +1,12 @@ +import Blockchains from '@depay/web3-blockchains' import deploy from './_helpers/deploy' import deployTestReceiver from './_helpers/deployTestReceiver' +import Exchanges from '@depay/web3-exchanges-evm' import getCallData from './_helpers/callData' import impersonate from './_helpers/impersonate' import now from './_helpers/now' +import reset from './_helpers/reset' import Token from '@depay/web3-tokens-evm' -import Blockchains from '@depay/web3-blockchains' -import Exchanges from '@depay/web3-exchanges-evm' import { ethers } from 'hardhat' import { expect } from 'chai' @@ -32,7 +33,8 @@ export default ({ blockchain, fromToken, fromAccount, toToken, exchange })=>{ let toDecimals let toTokenContract - beforeEach(async ()=>{ + before(async ()=>{ + reset({ blockchain }) toDecimals = await (new Token({ blockchain, address: toToken }).decimals()) wallets = await ethers.getSigners() deadline = now()+ 86400 // 1 day diff --git a/test/_pay-with-exchange-conversion.ts b/test/_pay-with-exchange-conversion.ts index 2221e81..e6feb8b 100644 --- a/test/_pay-with-exchange-conversion.ts +++ b/test/_pay-with-exchange-conversion.ts @@ -2,6 +2,7 @@ import deploy from './_helpers/deploy' import getCallData from './_helpers/callData' import impersonate from './_helpers/impersonate' import now from './_helpers/now' +import reset from './_helpers/reset' import Token from '@depay/web3-tokens-evm' import Blockchains from '@depay/web3-blockchains' import Exchanges from '@depay/web3-exchanges-evm' @@ -31,7 +32,8 @@ export default ({ blockchain, fromToken, fromAccount, toToken, exchanges })=>{ let toDecimals let toTokenContract - beforeEach(async ()=>{ + before(async ()=>{ + reset({ blockchain }) toDecimals = await (new Token({ blockchain, address: toToken }).decimals()) wallets = await ethers.getSigners() deadline = now()+ 86400 // 1 day diff --git a/test/_pay-with-native.ts b/test/_pay-with-native.ts index 669647e..05e458c 100644 --- a/test/_pay-with-native.ts +++ b/test/_pay-with-native.ts @@ -1,6 +1,7 @@ import Blockchains from '@depay/web3-blockchains' import deploy from './_helpers/deploy' import now from './_helpers/now' +import reset from './_helpers/reset' import { ethers } from 'hardhat' import { expect } from 'chai' @@ -20,7 +21,8 @@ export default ({ blockchain })=>{ let router let deadline - beforeEach(async ()=>{ + before(async ()=>{ + reset({ blockchain }) wallets = await ethers.getSigners() deadline = now()+ 86400 // 1 day }) diff --git a/test/_pay-with-permit2.ts b/test/_pay-with-permit2.ts index 3c5db82..d7ecb6d 100644 --- a/test/_pay-with-permit2.ts +++ b/test/_pay-with-permit2.ts @@ -1,6 +1,7 @@ import deploy from './_helpers/deploy' import impersonate from './_helpers/impersonate' import now from './_helpers/now' +import reset from './_helpers/reset' import Token from '@depay/web3-tokens-evm' import Blockchains from '@depay/web3-blockchains' import Exchanges from '@depay/web3-exchanges-evm' @@ -28,7 +29,8 @@ export default ({ blockchain, token, tokenHolder })=>{ let tokenContract let permit2Contract - beforeEach(async ()=>{ + before(async ()=>{ + reset({ blockchain }) wallets = await ethers.getSigners() tokenContract = new ethers.Contract(TOKEN, Token[blockchain]['20'], wallets[0]) if(typeof tokenHolder === 'string') { tokenHolder = await impersonate(tokenHolder) } diff --git a/test/_pay-with-token.ts b/test/_pay-with-token.ts index e42d916..5ccd8c5 100644 --- a/test/_pay-with-token.ts +++ b/test/_pay-with-token.ts @@ -1,6 +1,7 @@ import deploy from './_helpers/deploy' import impersonate from './_helpers/impersonate' import now from './_helpers/now' +import reset from './_helpers/reset' import Token from '@depay/web3-tokens-evm' import Blockchains from '@depay/web3-blockchains' import { ethers } from 'hardhat' @@ -24,7 +25,8 @@ export default ({ blockchain, token, fromAccount, reversalReason })=>{ let deadline let tokenContract - beforeEach(async ()=>{ + before(async ()=>{ + reset({ blockchain }) wallets = await ethers.getSigners() tokenContract = new ethers.Contract(TOKEN, Token[blockchain]['20'], wallets[0]) if(typeof fromAccount === 'string') { fromAccount = await impersonate(fromAccount) } diff --git a/test/_pay-with-wrapped-conversion.ts b/test/_pay-with-wrapped-conversion.ts index 5cde605..c89153f 100644 --- a/test/_pay-with-wrapped-conversion.ts +++ b/test/_pay-with-wrapped-conversion.ts @@ -1,5 +1,6 @@ import deploy from './_helpers/deploy' import now from './_helpers/now' +import reset from './_helpers/reset' import Token from '@depay/web3-tokens-evm' import Blockchains from '@depay/web3-blockchains' import { ethers } from 'hardhat' @@ -22,7 +23,8 @@ export default ({ blockchain })=>{ let deadline let wrapperContract - beforeEach(async ()=>{ + before(async ()=>{ + reset({ blockchain }) wallets = await ethers.getSigners() deadline = now()+ 86400 // 1 day wrapperContract = new ethers.Contract(WRAPPED, Token[blockchain].WRAPPED, wallets[0]) diff --git a/test/_various.ts b/test/_various.ts index 9271be8..df98997 100644 --- a/test/_various.ts +++ b/test/_various.ts @@ -1,5 +1,6 @@ import deploy from './_helpers/deploy' import now from './_helpers/now' +import reset from './_helpers/reset' import Token from '@depay/web3-tokens-evm' import Blockchains from '@depay/web3-blockchains' import { ethers } from 'hardhat' @@ -22,7 +23,8 @@ export default ({ blockchain })=>{ let router let deadline - beforeEach(async ()=>{ + before(async ()=>{ + reset({ blockchain }) wallets = await ethers.getSigners() deadline = now()+ 86400 // 1 day })