Commit 3535fb2f authored by Kelvin Fichter's avatar Kelvin Fichter Committed by smartcontracts

feat(itests): remove Watcher from fundUser

This commit removes the deprecated Watcher class from the fundUser
function in favor of using the CrossChainMessenger class from the new
Optimism SDK. This is part of a series of commits that are designed to
eventually remove the Watcher entirely from the integration tests (and
then from the entire repository).
parent c826fddb
...@@ -38,7 +38,7 @@ describe('Native ETH value integration tests', () => { ...@@ -38,7 +38,7 @@ describe('Native ETH value integration tests', () => {
} }
const value = ethers.utils.parseEther('0.01') const value = ethers.utils.parseEther('0.01')
await fundUser(env.watcher, env.l1Bridge, value, wallet.address) await fundUser(env.messenger, value, wallet.address)
const initialBalances = await getBalances() const initialBalances = await getBalances()
...@@ -156,12 +156,7 @@ describe('Native ETH value integration tests', () => { ...@@ -156,12 +156,7 @@ describe('Native ETH value integration tests', () => {
beforeEach(async () => { beforeEach(async () => {
ValueCalls0 = await Factory__ValueCalls.deploy() ValueCalls0 = await Factory__ValueCalls.deploy()
ValueCalls1 = await Factory__ValueCalls.deploy() ValueCalls1 = await Factory__ValueCalls.deploy()
await fundUser( await fundUser(env.messenger, initialBalance0, ValueCalls0.address)
env.watcher,
env.l1Bridge,
initialBalance0,
ValueCalls0.address
)
// These tests ass assume ValueCalls0 starts with a balance, but ValueCalls1 does not. // These tests ass assume ValueCalls0 starts with a balance, but ValueCalls1 does not.
await checkBalances([initialBalance0, 0]) await checkBalances([initialBalance0, 0])
}) })
...@@ -203,12 +198,7 @@ describe('Native ETH value integration tests', () => { ...@@ -203,12 +198,7 @@ describe('Native ETH value integration tests', () => {
it('should have the correct ovmSELFBALANCE which includes the msg.value', async () => { it('should have the correct ovmSELFBALANCE which includes the msg.value', async () => {
// give an initial balance which the ovmCALLVALUE should be added to when calculating ovmSELFBALANCE // give an initial balance which the ovmCALLVALUE should be added to when calculating ovmSELFBALANCE
const initialBalance = 10 const initialBalance = 10
await fundUser( await fundUser(env.messenger, initialBalance, ValueCalls1.address)
env.watcher,
env.l1Bridge,
initialBalance,
ValueCalls1.address
)
const sendAmount = 15 const sendAmount = 15
const [success, returndata] = await ValueCalls0.callStatic.sendWithData( const [success, returndata] = await ValueCalls0.callStatic.sendWithData(
......
...@@ -219,7 +219,7 @@ describe('Basic RPC tests', () => { ...@@ -219,7 +219,7 @@ describe('Basic RPC tests', () => {
// Fund account to call from // Fund account to call from
const from = wallet.address const from = wallet.address
const value = 15 const value = 15
await fundUser(env.watcher, env.l1Bridge, value, from) await fundUser(env.messenger, value, from)
// Do the call and check msg.value // Do the call and check msg.value
const data = ValueContext.interface.encodeFunctionData('getCallValue') const data = ValueContext.interface.encodeFunctionData('getCallValue')
......
...@@ -85,6 +85,13 @@ export class OptimismEnv { ...@@ -85,6 +85,13 @@ export class OptimismEnv {
} }
static async new(): Promise<OptimismEnv> { static async new(): Promise<OptimismEnv> {
const network = await l1Provider.getNetwork()
const messenger = new CrossChainMessenger({
l1SignerOrProvider: l1Wallet,
l2SignerOrProvider: l2Wallet,
l1ChainId: network.chainId,
})
const addressManager = getAddressManager(l1Wallet) const addressManager = getAddressManager(l1Wallet)
const watcher = await initWatcher(l1Provider, l2Provider, addressManager) const watcher = await initWatcher(l1Provider, l2Provider, addressManager)
const l1Bridge = await getL1Bridge(l1Wallet, addressManager) const l1Bridge = await getL1Bridge(l1Wallet, addressManager)
...@@ -94,7 +101,7 @@ export class OptimismEnv { ...@@ -94,7 +101,7 @@ export class OptimismEnv {
const min = envConfig.L2_WALLET_MIN_BALANCE_ETH.toString() const min = envConfig.L2_WALLET_MIN_BALANCE_ETH.toString()
const topUp = envConfig.L2_WALLET_TOP_UP_AMOUNT_ETH.toString() const topUp = envConfig.L2_WALLET_TOP_UP_AMOUNT_ETH.toString()
if (balance.lt(utils.parseEther(min))) { if (balance.lt(utils.parseEther(min))) {
await fundUser(watcher, l1Bridge, utils.parseEther(topUp)) await fundUser(messenger, utils.parseEther(topUp))
} }
const l1Messenger = getContractFactory('L1CrossDomainMessenger') const l1Messenger = getContractFactory('L1CrossDomainMessenger')
.connect(l1Wallet) .connect(l1Wallet)
...@@ -129,13 +136,6 @@ export class OptimismEnv { ...@@ -129,13 +136,6 @@ export class OptimismEnv {
.connect(l2Wallet) .connect(l2Wallet)
.attach(predeploys.OVM_L1BlockNumber) .attach(predeploys.OVM_L1BlockNumber)
const network = await l1Provider.getNetwork()
const messenger = new CrossChainMessenger({
l1SignerOrProvider: l1Wallet,
l2SignerOrProvider: l2Wallet,
l1ChainId: network.chainId,
})
return new OptimismEnv({ return new OptimismEnv({
addressManager, addressManager,
l1Bridge, l1Bridge,
......
...@@ -4,7 +4,6 @@ import { ...@@ -4,7 +4,6 @@ import {
Wallet, Wallet,
constants, constants,
providers, providers,
BigNumberish,
BigNumber, BigNumber,
utils, utils,
} from 'ethers' } from 'ethers'
...@@ -13,13 +12,13 @@ import { ...@@ -13,13 +12,13 @@ import {
getContractInterface, getContractInterface,
predeploys, predeploys,
} from '@eth-optimism/contracts' } from '@eth-optimism/contracts'
import { injectL2Context, remove0x, Watcher } from '@eth-optimism/core-utils' import { injectL2Context, remove0x } from '@eth-optimism/core-utils'
import { CrossChainMessenger, NumberLike } from '@eth-optimism/sdk'
import { cleanEnv, str, num, bool, makeValidator } from 'envalid' import { cleanEnv, str, num, bool, makeValidator } from 'envalid'
import dotenv from 'dotenv' import dotenv from 'dotenv'
dotenv.config() dotenv.config()
/* Imports: Internal */ /* Imports: Internal */
import { Direction, waitForXDomainTransaction } from './watcher-utils'
import { OptimismEnv } from './env' import { OptimismEnv } from './env'
export const isLiveNetwork = () => { export const isLiveNetwork = () => {
...@@ -180,23 +179,26 @@ export const getOvmEth = (wallet: Wallet) => { ...@@ -180,23 +179,26 @@ export const getOvmEth = (wallet: Wallet) => {
} }
export const fundUser = async ( export const fundUser = async (
watcher: Watcher, messenger: CrossChainMessenger,
bridge: Contract, amount: NumberLike,
amount: BigNumberish,
recipient?: string recipient?: string
) => { ) => {
const value = BigNumber.from(amount) await messenger.waitForMessageReceipt(
const tx = recipient await messenger.depositETH(amount, {
? bridge.depositETHTo(recipient, DEFAULT_TEST_GAS_L2, '0x', { l2GasLimit: DEFAULT_TEST_GAS_L2,
value, overrides: {
gasLimit: DEFAULT_TEST_GAS_L1, gasPrice: DEFAULT_TEST_GAS_L1,
}) },
: bridge.depositETH(DEFAULT_TEST_GAS_L2, '0x', { })
value, )
gasLimit: DEFAULT_TEST_GAS_L1,
}) if (recipient !== undefined) {
const tx = await messenger.l2Signer.sendTransaction({
await waitForXDomainTransaction(watcher, tx, Direction.L1ToL2) to: recipient,
value: amount,
})
await tx.wait()
}
} }
export const conditionalTest = ( export const conditionalTest = (
......
...@@ -47,12 +47,7 @@ describe('stress tests', () => { ...@@ -47,12 +47,7 @@ describe('stress tests', () => {
} }
for (const wallet of wallets) { for (const wallet of wallets) {
await fundUser( await fundUser(env.messenger, utils.parseEther('0.1'), wallet.address)
env.watcher,
env.l1Bridge,
utils.parseEther('0.1'),
wallet.address
)
} }
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment