Commit 67146ed3 authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

Merge pull request #2259 from tonykogias/migrate-smock-to-v2

refactor(tests): migrate from smock v1 to smock v2
parents 7f42e184 0a082c8e
...@@ -66,7 +66,6 @@ ...@@ -66,7 +66,6 @@
"devDependencies": { "devDependencies": {
"@codechecks/client": "^0.1.11", "@codechecks/client": "^0.1.11",
"@defi-wonderland/smock": "^2.0.2", "@defi-wonderland/smock": "^2.0.2",
"@eth-optimism/smock": "1.1.10",
"@nomiclabs/ethereumjs-vm": "^4.2.2", "@nomiclabs/ethereumjs-vm": "^4.2.2",
"@nomiclabs/hardhat-ethers": "^2.0.2", "@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-etherscan": "^2.1.6", "@nomiclabs/hardhat-etherscan": "^2.1.6",
......
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract, BigNumber } from 'ethers' import { Signer, ContractFactory, Contract, BigNumber } from 'ethers'
import { smockit, MockContract } from '@eth-optimism/smock' import {
import { smock, MockContractFactory } from '@defi-wonderland/smock' smock,
MockContractFactory,
FakeContract,
} from '@defi-wonderland/smock'
import { import {
remove0x, remove0x,
toHexString, toHexString,
...@@ -56,9 +59,9 @@ describe('L1CrossDomainMessenger', () => { ...@@ -56,9 +59,9 @@ describe('L1CrossDomainMessenger', () => {
AddressManager = await makeAddressManager() AddressManager = await makeAddressManager()
}) })
let Mock__TargetContract: MockContract let Fake__TargetContract: FakeContract
let Mock__L2CrossDomainMessenger: MockContract let Fake__L2CrossDomainMessenger: FakeContract
let Mock__StateCommitmentChain: MockContract let Fake__StateCommitmentChain: FakeContract
let Factory__CanonicalTransactionChain: ContractFactory let Factory__CanonicalTransactionChain: ContractFactory
let Factory__ChainStorageContainer: ContractFactory let Factory__ChainStorageContainer: ContractFactory
...@@ -66,28 +69,28 @@ describe('L1CrossDomainMessenger', () => { ...@@ -66,28 +69,28 @@ describe('L1CrossDomainMessenger', () => {
let CanonicalTransactionChain: Contract let CanonicalTransactionChain: Contract
before(async () => { before(async () => {
Mock__TargetContract = await smockit( Fake__TargetContract = await smock.fake<Contract>(
await ethers.getContractFactory('Helper_SimpleProxy') await ethers.getContractFactory('Helper_SimpleProxy')
) )
Mock__L2CrossDomainMessenger = await smockit( Fake__L2CrossDomainMessenger = await smock.fake<Contract>(
await ethers.getContractFactory('L2CrossDomainMessenger'), await ethers.getContractFactory('L2CrossDomainMessenger'),
{ {
address: predeploys.L2CrossDomainMessenger, address: predeploys.L2CrossDomainMessenger,
} }
) )
Mock__StateCommitmentChain = await smockit( Fake__StateCommitmentChain = await smock.fake<Contract>(
await ethers.getContractFactory('StateCommitmentChain') await ethers.getContractFactory('StateCommitmentChain')
) )
await AddressManager.setAddress( await AddressManager.setAddress(
'L2CrossDomainMessenger', 'L2CrossDomainMessenger',
Mock__L2CrossDomainMessenger.address Fake__L2CrossDomainMessenger.address
) )
await setProxyTarget( await setProxyTarget(
AddressManager, AddressManager,
'StateCommitmentChain', 'StateCommitmentChain',
Mock__StateCommitmentChain Fake__StateCommitmentChain
) )
Factory__CanonicalTransactionChain = await ethers.getContractFactory( Factory__CanonicalTransactionChain = await ethers.getContractFactory(
...@@ -178,7 +181,7 @@ describe('L1CrossDomainMessenger', () => { ...@@ -178,7 +181,7 @@ describe('L1CrossDomainMessenger', () => {
['address', 'address', 'uint256', 'bytes'], ['address', 'address', 'uint256', 'bytes'],
[ [
applyL1ToL2Alias(L1CrossDomainMessenger.address), applyL1ToL2Alias(L1CrossDomainMessenger.address),
Mock__L2CrossDomainMessenger.address, Fake__L2CrossDomainMessenger.address,
gasLimit, gasLimit,
calldata, calldata,
] ]
...@@ -322,7 +325,7 @@ describe('L1CrossDomainMessenger', () => { ...@@ -322,7 +325,7 @@ describe('L1CrossDomainMessenger', () => {
.to.emit(CanonicalTransactionChain, 'TransactionEnqueued') .to.emit(CanonicalTransactionChain, 'TransactionEnqueued')
.withArgs( .withArgs(
applyL1ToL2Alias(L1CrossDomainMessenger.address), applyL1ToL2Alias(L1CrossDomainMessenger.address),
Mock__L2CrossDomainMessenger.address, Fake__L2CrossDomainMessenger.address,
newGasLimit, newGasLimit,
encodeXDomainCalldata(target, sender, message, queueIndex), encodeXDomainCalldata(target, sender, message, queueIndex),
newQueueIndex, newQueueIndex,
...@@ -388,7 +391,7 @@ describe('L1CrossDomainMessenger', () => { ...@@ -388,7 +391,7 @@ describe('L1CrossDomainMessenger', () => {
const storageKey = ethers.utils.keccak256( const storageKey = ethers.utils.keccak256(
ethers.utils.keccak256( ethers.utils.keccak256(
calldata + remove0x(Mock__L2CrossDomainMessenger.address) calldata + remove0x(Fake__L2CrossDomainMessenger.address)
) + '00'.repeat(32) ) + '00'.repeat(32)
) )
const storageGenerator = await TrieTestGenerator.fromNodes({ const storageGenerator = await TrieTestGenerator.fromNodes({
...@@ -439,8 +442,8 @@ describe('L1CrossDomainMessenger', () => { ...@@ -439,8 +442,8 @@ describe('L1CrossDomainMessenger', () => {
let proof: any let proof: any
let calldata: string let calldata: string
before(async () => { before(async () => {
target = Mock__TargetContract.address target = Fake__TargetContract.address
message = Mock__TargetContract.interface.encodeFunctionData('setTarget', [ message = Fake__TargetContract.interface.encodeFunctionData('setTarget', [
NON_ZERO_ADDRESS, NON_ZERO_ADDRESS,
]) ])
sender = await signer.getAddress() sender = await signer.getAddress()
...@@ -455,18 +458,12 @@ describe('L1CrossDomainMessenger', () => { ...@@ -455,18 +458,12 @@ describe('L1CrossDomainMessenger', () => {
}) })
beforeEach(async () => { beforeEach(async () => {
Mock__StateCommitmentChain.smocked.verifyStateCommitment.will.return.with( Fake__StateCommitmentChain.verifyStateCommitment.returns(true)
true Fake__StateCommitmentChain.insideFraudProofWindow.returns(false)
)
Mock__StateCommitmentChain.smocked.insideFraudProofWindow.will.return.with(
false
)
}) })
it('should revert if still inside the fraud proof window', async () => { it('should revert if still inside the fraud proof window', async () => {
Mock__StateCommitmentChain.smocked.insideFraudProofWindow.will.return.with( Fake__StateCommitmentChain.insideFraudProofWindow.returns(true)
true
)
const proof1 = { const proof1 = {
stateRoot: ethers.constants.HashZero, stateRoot: ethers.constants.HashZero,
...@@ -502,9 +499,7 @@ describe('L1CrossDomainMessenger', () => { ...@@ -502,9 +499,7 @@ describe('L1CrossDomainMessenger', () => {
}) })
it('should revert if provided an invalid state root proof', async () => { it('should revert if provided an invalid state root proof', async () => {
Mock__StateCommitmentChain.smocked.verifyStateCommitment.will.return.with( Fake__StateCommitmentChain.verifyStateCommitment.returns(false)
false
)
const proof1 = { const proof1 = {
stateRoot: ethers.constants.HashZero, stateRoot: ethers.constants.HashZero,
......
...@@ -2,7 +2,12 @@ ...@@ -2,7 +2,12 @@
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract, constants } from 'ethers' import { Signer, ContractFactory, Contract, constants } from 'ethers'
import { Interface } from 'ethers/lib/utils' import { Interface } from 'ethers/lib/utils'
import { smockit, MockContract, smoddit } from '@eth-optimism/smock' import {
smock,
MockContractFactory,
FakeContract,
MockContract,
} from '@defi-wonderland/smock'
/* Internal Imports */ /* Internal Imports */
import { expect } from '../../../setup' import { expect } from '../../../setup'
...@@ -30,15 +35,15 @@ describe('L1StandardBridge', () => { ...@@ -30,15 +35,15 @@ describe('L1StandardBridge', () => {
let aliceAddress let aliceAddress
// we can just make up this string since it's on the "other" Layer // we can just make up this string since it's on the "other" Layer
let Factory__L1ERC20: ContractFactory let Factory__L1ERC20: MockContractFactory<ContractFactory>
let IL2ERC20Bridge: Interface let IL2ERC20Bridge: Interface
before(async () => { before(async () => {
;[l1MessengerImpersonator, alice, bob] = await ethers.getSigners() ;[l1MessengerImpersonator, alice, bob] = await ethers.getSigners()
await smockit(await ethers.getContractFactory('OVM_ETH')) await smock.fake<Contract>(await ethers.getContractFactory('OVM_ETH'))
// deploy an ERC20 contract on L1 // deploy an ERC20 contract on L1
Factory__L1ERC20 = await smoddit( Factory__L1ERC20 = await smock.mock(
'@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20' '@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20'
) )
...@@ -49,12 +54,12 @@ describe('L1StandardBridge', () => { ...@@ -49,12 +54,12 @@ describe('L1StandardBridge', () => {
bobsAddress = await bob.getAddress() bobsAddress = await bob.getAddress()
}) })
let L1ERC20: Contract let L1ERC20: MockContract<Contract>
let L1StandardBridge: Contract let L1StandardBridge: Contract
let Mock__L1CrossDomainMessenger: MockContract let Fake__L1CrossDomainMessenger: FakeContract
beforeEach(async () => { beforeEach(async () => {
// Get a new mock L1 messenger // Get a new mock L1 messenger
Mock__L1CrossDomainMessenger = await smockit( Fake__L1CrossDomainMessenger = await smock.fake<Contract>(
await ethers.getContractFactory('L1CrossDomainMessenger'), await ethers.getContractFactory('L1CrossDomainMessenger'),
{ address: await l1MessengerImpersonator.getAddress() } // This allows us to use an ethers override {from: Mock__L2CrossDomainMessenger.address} to mock calls { address: await l1MessengerImpersonator.getAddress() } // This allows us to use an ethers override {from: Mock__L2CrossDomainMessenger.address} to mock calls
) )
...@@ -64,16 +69,15 @@ describe('L1StandardBridge', () => { ...@@ -64,16 +69,15 @@ describe('L1StandardBridge', () => {
await ethers.getContractFactory('L1StandardBridge') await ethers.getContractFactory('L1StandardBridge')
).deploy() ).deploy()
await L1StandardBridge.initialize( await L1StandardBridge.initialize(
Mock__L1CrossDomainMessenger.address, Fake__L1CrossDomainMessenger.address,
DUMMY_L2_BRIDGE_ADDRESS DUMMY_L2_BRIDGE_ADDRESS
) )
L1ERC20 = await Factory__L1ERC20.deploy('L1ERC20', 'ERC') L1ERC20 = await Factory__L1ERC20.deploy('L1ERC20', 'ERC')
await L1ERC20.smodify.put({
_totalSupply: INITIAL_TOTAL_L1_SUPPLY, await L1ERC20.setVariable('_totalSupply', INITIAL_TOTAL_L1_SUPPLY)
_balances: { await L1ERC20.setVariable('_balances', {
[aliceAddress]: INITIAL_TOTAL_L1_SUPPLY, [aliceAddress]: INITIAL_TOTAL_L1_SUPPLY,
},
}) })
}) })
...@@ -116,7 +120,7 @@ describe('L1StandardBridge', () => { ...@@ -116,7 +120,7 @@ describe('L1StandardBridge', () => {
) )
const depositCallToMessenger = const depositCallToMessenger =
Mock__L1CrossDomainMessenger.smocked.sendMessage.calls[0] Fake__L1CrossDomainMessenger.sendMessage.getCall(0)
const depositerBalance = await ethers.provider.getBalance(depositer) const depositerBalance = await ethers.provider.getBalance(depositer)
const receipt = await res.wait() const receipt = await res.wait()
...@@ -136,11 +140,11 @@ describe('L1StandardBridge', () => { ...@@ -136,11 +140,11 @@ describe('L1StandardBridge', () => {
// Check the correct cross-chain call was sent: // Check the correct cross-chain call was sent:
// Message should be sent to the L2 bridge // Message should be sent to the L2 bridge
expect(depositCallToMessenger._target).to.equal(DUMMY_L2_BRIDGE_ADDRESS) expect(depositCallToMessenger.args[0]).to.equal(DUMMY_L2_BRIDGE_ADDRESS)
// Message data should be a call telling the L2ETHToken to finalize the deposit // Message data should be a call telling the L2ETHToken to finalize the deposit
// the L1 bridge sends the correct message to the L1 messenger // the L1 bridge sends the correct message to the L1 messenger
expect(depositCallToMessenger._message).to.equal( expect(depositCallToMessenger.args[1]).to.equal(
IL2ERC20Bridge.encodeFunctionData('finalizeDeposit', [ IL2ERC20Bridge.encodeFunctionData('finalizeDeposit', [
constants.AddressZero, constants.AddressZero,
predeploys.OVM_ETH, predeploys.OVM_ETH,
...@@ -150,7 +154,7 @@ describe('L1StandardBridge', () => { ...@@ -150,7 +154,7 @@ describe('L1StandardBridge', () => {
NON_NULL_BYTES32, NON_NULL_BYTES32,
]) ])
) )
expect(depositCallToMessenger._gasLimit).to.equal(FINALIZATION_GAS) expect(depositCallToMessenger.args[2]).to.equal(FINALIZATION_GAS)
}) })
it('depositETHTo() escrows the deposit amount and sends the correct deposit message', async () => { it('depositETHTo() escrows the deposit amount and sends the correct deposit message', async () => {
...@@ -166,7 +170,7 @@ describe('L1StandardBridge', () => { ...@@ -166,7 +170,7 @@ describe('L1StandardBridge', () => {
} }
) )
const depositCallToMessenger = const depositCallToMessenger =
Mock__L1CrossDomainMessenger.smocked.sendMessage.calls[0] Fake__L1CrossDomainMessenger.sendMessage.getCall(0)
const depositerBalance = await ethers.provider.getBalance(aliceAddress) const depositerBalance = await ethers.provider.getBalance(aliceAddress)
const receipt = await res.wait() const receipt = await res.wait()
...@@ -186,11 +190,11 @@ describe('L1StandardBridge', () => { ...@@ -186,11 +190,11 @@ describe('L1StandardBridge', () => {
// Check the correct cross-chain call was sent: // Check the correct cross-chain call was sent:
// Message should be sent to the L2 bridge // Message should be sent to the L2 bridge
expect(depositCallToMessenger._target).to.equal(DUMMY_L2_BRIDGE_ADDRESS) expect(depositCallToMessenger.args[0]).to.equal(DUMMY_L2_BRIDGE_ADDRESS)
// Message data should be a call telling the L2ETHToken to finalize the deposit // Message data should be a call telling the L2ETHToken to finalize the deposit
// the L1 bridge sends the correct message to the L1 messenger // the L1 bridge sends the correct message to the L1 messenger
expect(depositCallToMessenger._message).to.equal( expect(depositCallToMessenger.args[1]).to.equal(
IL2ERC20Bridge.encodeFunctionData('finalizeDeposit', [ IL2ERC20Bridge.encodeFunctionData('finalizeDeposit', [
constants.AddressZero, constants.AddressZero,
predeploys.OVM_ETH, predeploys.OVM_ETH,
...@@ -200,7 +204,7 @@ describe('L1StandardBridge', () => { ...@@ -200,7 +204,7 @@ describe('L1StandardBridge', () => {
NON_NULL_BYTES32, NON_NULL_BYTES32,
]) ])
) )
expect(depositCallToMessenger._gasLimit).to.equal(FINALIZATION_GAS) expect(depositCallToMessenger.args[2]).to.equal(FINALIZATION_GAS)
}) })
it('cannot depositETH from a contract account', async () => { it('cannot depositETH from a contract account', async () => {
...@@ -233,11 +237,11 @@ describe('L1StandardBridge', () => { ...@@ -233,11 +237,11 @@ describe('L1StandardBridge', () => {
await ethers.getContractFactory('L1StandardBridge') await ethers.getContractFactory('L1StandardBridge')
).deploy() ).deploy()
await L1StandardBridge.initialize( await L1StandardBridge.initialize(
Mock__L1CrossDomainMessenger.address, Fake__L1CrossDomainMessenger.address,
DUMMY_L2_BRIDGE_ADDRESS DUMMY_L2_BRIDGE_ADDRESS
) )
Mock__L1CrossDomainMessenger.smocked.xDomainMessageSender.will.return.with( Fake__L1CrossDomainMessenger.xDomainMessageSender.returns(
'0x' + '22'.repeat(20) '0x' + '22'.repeat(20)
) )
...@@ -248,7 +252,7 @@ describe('L1StandardBridge', () => { ...@@ -248,7 +252,7 @@ describe('L1StandardBridge', () => {
1, 1,
NON_NULL_BYTES32, NON_NULL_BYTES32,
{ {
from: Mock__L1CrossDomainMessenger.address, from: Fake__L1CrossDomainMessenger.address,
} }
) )
).to.be.revertedWith(ERR_INVALID_X_DOMAIN_MSG_SENDER) ).to.be.revertedWith(ERR_INVALID_X_DOMAIN_MSG_SENDER)
...@@ -259,7 +263,7 @@ describe('L1StandardBridge', () => { ...@@ -259,7 +263,7 @@ describe('L1StandardBridge', () => {
expect(await ethers.provider.getBalance(NON_ZERO_ADDRESS)).to.be.equal(0) expect(await ethers.provider.getBalance(NON_ZERO_ADDRESS)).to.be.equal(0)
const withdrawalAmount = 100 const withdrawalAmount = 100
Mock__L1CrossDomainMessenger.smocked.xDomainMessageSender.will.return.with( Fake__L1CrossDomainMessenger.xDomainMessageSender.returns(
() => DUMMY_L2_BRIDGE_ADDRESS () => DUMMY_L2_BRIDGE_ADDRESS
) )
...@@ -270,7 +274,7 @@ describe('L1StandardBridge', () => { ...@@ -270,7 +274,7 @@ describe('L1StandardBridge', () => {
withdrawalAmount, withdrawalAmount,
NON_NULL_BYTES32, NON_NULL_BYTES32,
{ {
from: Mock__L1CrossDomainMessenger.address, from: Fake__L1CrossDomainMessenger.address,
} }
) )
).to.be.revertedWith( ).to.be.revertedWith(
...@@ -283,7 +287,7 @@ describe('L1StandardBridge', () => { ...@@ -283,7 +287,7 @@ describe('L1StandardBridge', () => {
expect(await ethers.provider.getBalance(NON_ZERO_ADDRESS)).to.be.equal(0) expect(await ethers.provider.getBalance(NON_ZERO_ADDRESS)).to.be.equal(0)
const withdrawalAmount = 100 const withdrawalAmount = 100
Mock__L1CrossDomainMessenger.smocked.xDomainMessageSender.will.return.with( Fake__L1CrossDomainMessenger.xDomainMessageSender.returns(
() => DUMMY_L2_BRIDGE_ADDRESS () => DUMMY_L2_BRIDGE_ADDRESS
) )
...@@ -302,7 +306,7 @@ describe('L1StandardBridge', () => { ...@@ -302,7 +306,7 @@ describe('L1StandardBridge', () => {
withdrawalAmount, withdrawalAmount,
NON_NULL_BYTES32, NON_NULL_BYTES32,
{ {
from: Mock__L1CrossDomainMessenger.address, from: Fake__L1CrossDomainMessenger.address,
} }
) )
...@@ -333,7 +337,7 @@ describe('L1StandardBridge', () => { ...@@ -333,7 +337,7 @@ describe('L1StandardBridge', () => {
) )
const depositCallToMessenger = const depositCallToMessenger =
Mock__L1CrossDomainMessenger.smocked.sendMessage.calls[0] Fake__L1CrossDomainMessenger.sendMessage.getCall(0)
const depositerBalance = await L1ERC20.balanceOf(aliceAddress) const depositerBalance = await L1ERC20.balanceOf(aliceAddress)
...@@ -345,11 +349,11 @@ describe('L1StandardBridge', () => { ...@@ -345,11 +349,11 @@ describe('L1StandardBridge', () => {
// Check the correct cross-chain call was sent: // Check the correct cross-chain call was sent:
// Message should be sent to the L2 bridge // Message should be sent to the L2 bridge
expect(depositCallToMessenger._target).to.equal(DUMMY_L2_BRIDGE_ADDRESS) expect(depositCallToMessenger.args[0]).to.equal(DUMMY_L2_BRIDGE_ADDRESS)
// Message data should be a call telling the L2DepositedERC20 to finalize the deposit // Message data should be a call telling the L2DepositedERC20 to finalize the deposit
// the L1 bridge sends the correct message to the L1 messenger // the L1 bridge sends the correct message to the L1 messenger
expect(depositCallToMessenger._message).to.equal( expect(depositCallToMessenger.args[1]).to.equal(
IL2ERC20Bridge.encodeFunctionData('finalizeDeposit', [ IL2ERC20Bridge.encodeFunctionData('finalizeDeposit', [
L1ERC20.address, L1ERC20.address,
DUMMY_L2_ERC20_ADDRESS, DUMMY_L2_ERC20_ADDRESS,
...@@ -359,7 +363,7 @@ describe('L1StandardBridge', () => { ...@@ -359,7 +363,7 @@ describe('L1StandardBridge', () => {
NON_NULL_BYTES32, NON_NULL_BYTES32,
]) ])
) )
expect(depositCallToMessenger._gasLimit).to.equal(FINALIZATION_GAS) expect(depositCallToMessenger.args[2]).to.equal(FINALIZATION_GAS)
}) })
it('depositERC20To() escrows the deposit amount and sends the correct deposit message', async () => { it('depositERC20To() escrows the deposit amount and sends the correct deposit message', async () => {
...@@ -373,7 +377,7 @@ describe('L1StandardBridge', () => { ...@@ -373,7 +377,7 @@ describe('L1StandardBridge', () => {
NON_NULL_BYTES32 NON_NULL_BYTES32
) )
const depositCallToMessenger = const depositCallToMessenger =
Mock__L1CrossDomainMessenger.smocked.sendMessage.calls[0] Fake__L1CrossDomainMessenger.sendMessage.getCall(0)
const depositerBalance = await L1ERC20.balanceOf(aliceAddress) const depositerBalance = await L1ERC20.balanceOf(aliceAddress)
expect(depositerBalance).to.equal(INITIAL_TOTAL_L1_SUPPLY - depositAmount) expect(depositerBalance).to.equal(INITIAL_TOTAL_L1_SUPPLY - depositAmount)
...@@ -384,11 +388,11 @@ describe('L1StandardBridge', () => { ...@@ -384,11 +388,11 @@ describe('L1StandardBridge', () => {
// Check the correct cross-chain call was sent: // Check the correct cross-chain call was sent:
// Message should be sent to the L2DepositedERC20 on L2 // Message should be sent to the L2DepositedERC20 on L2
expect(depositCallToMessenger._target).to.equal(DUMMY_L2_BRIDGE_ADDRESS) expect(depositCallToMessenger.args[0]).to.equal(DUMMY_L2_BRIDGE_ADDRESS)
// Message data should be a call telling the L2DepositedERC20 to finalize the deposit // Message data should be a call telling the L2DepositedERC20 to finalize the deposit
// the L1 bridge sends the correct message to the L1 messenger // the L1 bridge sends the correct message to the L1 messenger
expect(depositCallToMessenger._message).to.equal( expect(depositCallToMessenger.args[1]).to.equal(
IL2ERC20Bridge.encodeFunctionData('finalizeDeposit', [ IL2ERC20Bridge.encodeFunctionData('finalizeDeposit', [
L1ERC20.address, L1ERC20.address,
DUMMY_L2_ERC20_ADDRESS, DUMMY_L2_ERC20_ADDRESS,
...@@ -398,7 +402,7 @@ describe('L1StandardBridge', () => { ...@@ -398,7 +402,7 @@ describe('L1StandardBridge', () => {
NON_NULL_BYTES32, NON_NULL_BYTES32,
]) ])
) )
expect(depositCallToMessenger._gasLimit).to.equal(FINALIZATION_GAS) expect(depositCallToMessenger.args[2]).to.equal(FINALIZATION_GAS)
}) })
it('cannot depositERC20 from a contract account', async () => { it('cannot depositERC20 from a contract account', async () => {
...@@ -414,20 +418,20 @@ describe('L1StandardBridge', () => { ...@@ -414,20 +418,20 @@ describe('L1StandardBridge', () => {
}) })
describe('Handling ERC20.transferFrom() failures that revert ', () => { describe('Handling ERC20.transferFrom() failures that revert ', () => {
let MOCK__L1ERC20: MockContract let Fake__L1ERC20: FakeContract
before(async () => { before(async () => {
// Deploy the L1 ERC20 token, Alice will receive the full initialSupply // Deploy the L1 ERC20 token, Alice will receive the full initialSupply
MOCK__L1ERC20 = await smockit( Fake__L1ERC20 = await smock.fake<Contract>(
await Factory__L1ERC20.deploy('L1ERC20', 'ERC') await Factory__L1ERC20.deploy('L1ERC20', 'ERC')
) )
MOCK__L1ERC20.smocked.transferFrom.will.revert() Fake__L1ERC20.transferFrom.reverts()
}) })
it('depositERC20(): will revert if ERC20.transferFrom() reverts', async () => { it('depositERC20(): will revert if ERC20.transferFrom() reverts', async () => {
await expect( await expect(
L1StandardBridge.connect(alice).depositERC20( L1StandardBridge.connect(alice).depositERC20(
MOCK__L1ERC20.address, Fake__L1ERC20.address,
DUMMY_L2_ERC20_ADDRESS, DUMMY_L2_ERC20_ADDRESS,
depositAmount, depositAmount,
FINALIZATION_GAS, FINALIZATION_GAS,
...@@ -439,7 +443,7 @@ describe('L1StandardBridge', () => { ...@@ -439,7 +443,7 @@ describe('L1StandardBridge', () => {
it('depositERC20To(): will revert if ERC20.transferFrom() reverts', async () => { it('depositERC20To(): will revert if ERC20.transferFrom() reverts', async () => {
await expect( await expect(
L1StandardBridge.connect(alice).depositERC20To( L1StandardBridge.connect(alice).depositERC20To(
MOCK__L1ERC20.address, Fake__L1ERC20.address,
DUMMY_L2_ERC20_ADDRESS, DUMMY_L2_ERC20_ADDRESS,
bobsAddress, bobsAddress,
depositAmount, depositAmount,
...@@ -464,18 +468,18 @@ describe('L1StandardBridge', () => { ...@@ -464,18 +468,18 @@ describe('L1StandardBridge', () => {
}) })
describe('Handling ERC20.transferFrom failures that return false', () => { describe('Handling ERC20.transferFrom failures that return false', () => {
let MOCK__L1ERC20: MockContract let Fake__L1ERC20: FakeContract
before(async () => { before(async () => {
MOCK__L1ERC20 = await smockit( Fake__L1ERC20 = await smock.fake(
await Factory__L1ERC20.deploy('L1ERC20', 'ERC') await Factory__L1ERC20.deploy('L1ERC20', 'ERC')
) )
MOCK__L1ERC20.smocked.transferFrom.will.return.with(false) Fake__L1ERC20.transferFrom.returns(false)
}) })
it('deposit(): will revert if ERC20.transferFrom() returns false', async () => { it('deposit(): will revert if ERC20.transferFrom() returns false', async () => {
await expect( await expect(
L1StandardBridge.connect(alice).depositERC20( L1StandardBridge.connect(alice).depositERC20(
MOCK__L1ERC20.address, Fake__L1ERC20.address,
DUMMY_L2_ERC20_ADDRESS, DUMMY_L2_ERC20_ADDRESS,
depositAmount, depositAmount,
FINALIZATION_GAS, FINALIZATION_GAS,
...@@ -487,7 +491,7 @@ describe('L1StandardBridge', () => { ...@@ -487,7 +491,7 @@ describe('L1StandardBridge', () => {
it('depositTo(): will revert if ERC20.transferFrom() returns false', async () => { it('depositTo(): will revert if ERC20.transferFrom() returns false', async () => {
await expect( await expect(
L1StandardBridge.depositERC20To( L1StandardBridge.depositERC20To(
MOCK__L1ERC20.address, Fake__L1ERC20.address,
DUMMY_L2_ERC20_ADDRESS, DUMMY_L2_ERC20_ADDRESS,
bobsAddress, bobsAddress,
depositAmount, depositAmount,
...@@ -514,8 +518,8 @@ describe('L1StandardBridge', () => { ...@@ -514,8 +518,8 @@ describe('L1StandardBridge', () => {
}) })
it('onlyFromCrossDomainAccount: should revert on calls from the right crossDomainMessenger, but wrong xDomainMessageSender (ie. not the L2DepositedERC20)', async () => { it('onlyFromCrossDomainAccount: should revert on calls from the right crossDomainMessenger, but wrong xDomainMessageSender (ie. not the L2DepositedERC20)', async () => {
Mock__L1CrossDomainMessenger.smocked.xDomainMessageSender.will.return.with( Fake__L1CrossDomainMessenger.xDomainMessageSender.returns(
'0x' + '22'.repeat(20) () => NON_ZERO_ADDRESS
) )
await expect( await expect(
...@@ -527,7 +531,7 @@ describe('L1StandardBridge', () => { ...@@ -527,7 +531,7 @@ describe('L1StandardBridge', () => {
1, 1,
NON_NULL_BYTES32, NON_NULL_BYTES32,
{ {
from: Mock__L1CrossDomainMessenger.address, from: Fake__L1CrossDomainMessenger.address,
} }
) )
).to.be.revertedWith(ERR_INVALID_X_DOMAIN_MSG_SENDER) ).to.be.revertedWith(ERR_INVALID_X_DOMAIN_MSG_SENDER)
...@@ -556,7 +560,7 @@ describe('L1StandardBridge', () => { ...@@ -556,7 +560,7 @@ describe('L1StandardBridge', () => {
// make sure no balance at start of test // make sure no balance at start of test
expect(await L1ERC20.balanceOf(NON_ZERO_ADDRESS)).to.be.equal(0) expect(await L1ERC20.balanceOf(NON_ZERO_ADDRESS)).to.be.equal(0)
Mock__L1CrossDomainMessenger.smocked.xDomainMessageSender.will.return.with( Fake__L1CrossDomainMessenger.xDomainMessageSender.returns(
() => DUMMY_L2_BRIDGE_ADDRESS () => DUMMY_L2_BRIDGE_ADDRESS
) )
...@@ -567,7 +571,7 @@ describe('L1StandardBridge', () => { ...@@ -567,7 +571,7 @@ describe('L1StandardBridge', () => {
NON_ZERO_ADDRESS, NON_ZERO_ADDRESS,
withdrawalAmount, withdrawalAmount,
NON_NULL_BYTES32, NON_NULL_BYTES32,
{ from: Mock__L1CrossDomainMessenger.address } { from: Fake__L1CrossDomainMessenger.address }
) )
expect(await L1ERC20.balanceOf(NON_ZERO_ADDRESS)).to.be.equal( expect(await L1ERC20.balanceOf(NON_ZERO_ADDRESS)).to.be.equal(
......
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract } from 'ethers' import { Signer, ContractFactory, Contract } from 'ethers'
import { smoddit } from '@eth-optimism/smock' import { MockContract, smock } from '@defi-wonderland/smock'
import { expectApprox } from '@eth-optimism/core-utils' import { expectApprox } from '@eth-optimism/core-utils'
/* Internal Imports */ /* Internal Imports */
...@@ -92,7 +92,7 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge [ @skip-on-coverage ...@@ -92,7 +92,7 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge [ @skip-on-coverage
}) })
// 4 Bridge // 4 Bridge
let L1ERC20: Contract let L1ERC20: MockContract<Contract>
let L1StandardBridge: Contract let L1StandardBridge: Contract
before('Deploy the bridge and setup the token', async () => { before('Deploy the bridge and setup the token', async () => {
// Deploy the Bridge // Deploy the Bridge
...@@ -105,14 +105,12 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge [ @skip-on-coverage ...@@ -105,14 +105,12 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge [ @skip-on-coverage
) )
L1ERC20 = await ( L1ERC20 = await (
await smoddit('@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20') await smock.mock('@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20')
).deploy('L1ERC20', 'ERC') ).deploy('L1ERC20', 'ERC')
const aliceAddress = await alice.getAddress() const aliceAddress = await alice.getAddress()
await L1ERC20.smodify.put({ await L1ERC20.setVariable('_totalSupply', INITIAL_TOTAL_L1_SUPPLY)
_totalSupply: INITIAL_TOTAL_L1_SUPPLY, await L1ERC20.setVariable('_balances', {
_balances: {
[aliceAddress]: INITIAL_TOTAL_L1_SUPPLY, [aliceAddress]: INITIAL_TOTAL_L1_SUPPLY,
},
}) })
}) })
......
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract } from 'ethers' import { Signer, ContractFactory, Contract } from 'ethers'
import { smockit, MockContract } from '@eth-optimism/smock' import { smock, FakeContract } from '@defi-wonderland/smock'
import { import {
AppendSequencerBatchParams, AppendSequencerBatchParams,
BatchContext, BatchContext,
...@@ -46,7 +46,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain [ @skip-on-coverage ]', () = ...@@ -46,7 +46,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain [ @skip-on-coverage ]', () =
}) })
let AddressManager: Contract let AddressManager: Contract
let Mock__StateCommitmentChain: MockContract let Fake__StateCommitmentChain: FakeContract
before(async () => { before(async () => {
AddressManager = await makeAddressManager() AddressManager = await makeAddressManager()
await AddressManager.setAddress( await AddressManager.setAddress(
...@@ -54,14 +54,14 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain [ @skip-on-coverage ]', () = ...@@ -54,14 +54,14 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain [ @skip-on-coverage ]', () =
await sequencer.getAddress() await sequencer.getAddress()
) )
Mock__StateCommitmentChain = await smockit( Fake__StateCommitmentChain = await smock.fake<Contract>(
await ethers.getContractFactory('StateCommitmentChain') await ethers.getContractFactory('StateCommitmentChain')
) )
await setProxyTarget( await setProxyTarget(
AddressManager, AddressManager,
'StateCommitmentChain', 'StateCommitmentChain',
Mock__StateCommitmentChain Fake__StateCommitmentChain
) )
}) })
......
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract } from 'ethers' import { Signer, ContractFactory, Contract } from 'ethers'
import { smockit, MockContract } from '@eth-optimism/smock' import { smock, FakeContract } from '@defi-wonderland/smock'
import { import {
AppendSequencerBatchParams, AppendSequencerBatchParams,
encodeAppendSequencerBatch, encodeAppendSequencerBatch,
...@@ -69,7 +69,7 @@ describe('CanonicalTransactionChain', () => { ...@@ -69,7 +69,7 @@ describe('CanonicalTransactionChain', () => {
}) })
let AddressManager: Contract let AddressManager: Contract
let Mock__StateCommitmentChain: MockContract let Fake__StateCommitmentChain: FakeContract
before(async () => { before(async () => {
AddressManager = await makeAddressManager() AddressManager = await makeAddressManager()
await AddressManager.setAddress( await AddressManager.setAddress(
...@@ -77,14 +77,14 @@ describe('CanonicalTransactionChain', () => { ...@@ -77,14 +77,14 @@ describe('CanonicalTransactionChain', () => {
await sequencer.getAddress() await sequencer.getAddress()
) )
Mock__StateCommitmentChain = await smockit( Fake__StateCommitmentChain = await smock.fake<Contract>(
await ethers.getContractFactory('StateCommitmentChain') await ethers.getContractFactory('StateCommitmentChain')
) )
await setProxyTarget( await setProxyTarget(
AddressManager, AddressManager,
'StateCommitmentChain', 'StateCommitmentChain',
Mock__StateCommitmentChain Fake__StateCommitmentChain
) )
}) })
......
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract, constants } from 'ethers' import { Signer, ContractFactory, Contract, constants } from 'ethers'
import { smockit, MockContract } from '@eth-optimism/smock' import { smock, FakeContract } from '@defi-wonderland/smock'
/* Internal Imports */ /* Internal Imports */
import { expect } from '../../../setup' import { expect } from '../../../setup'
...@@ -25,26 +25,26 @@ describe('StateCommitmentChain', () => { ...@@ -25,26 +25,26 @@ describe('StateCommitmentChain', () => {
AddressManager = await makeAddressManager() AddressManager = await makeAddressManager()
}) })
let Mock__CanonicalTransactionChain: MockContract let Fake__CanonicalTransactionChain: FakeContract
let Mock__BondManager: MockContract let Fake__BondManager: FakeContract
before(async () => { before(async () => {
Mock__CanonicalTransactionChain = await smockit( Fake__CanonicalTransactionChain = await smock.fake<Contract>(
await ethers.getContractFactory('CanonicalTransactionChain') await ethers.getContractFactory('CanonicalTransactionChain')
) )
await setProxyTarget( await setProxyTarget(
AddressManager, AddressManager,
'CanonicalTransactionChain', 'CanonicalTransactionChain',
Mock__CanonicalTransactionChain Fake__CanonicalTransactionChain
) )
Mock__BondManager = await smockit( Fake__BondManager = await smock.fake<Contract>(
await ethers.getContractFactory('BondManager') await ethers.getContractFactory('BondManager')
) )
await setProxyTarget(AddressManager, 'BondManager', Mock__BondManager) await setProxyTarget(AddressManager, 'BondManager', Fake__BondManager)
Mock__BondManager.smocked.isCollateralized.will.return.with(true) Fake__BondManager.isCollateralized.returns(true)
await AddressManager.setAddress( await AddressManager.setAddress(
'OVM_Proposer', 'OVM_Proposer',
...@@ -114,7 +114,7 @@ describe('StateCommitmentChain', () => { ...@@ -114,7 +114,7 @@ describe('StateCommitmentChain', () => {
describe('when submitting more elements than present in the CanonicalTransactionChain', () => { describe('when submitting more elements than present in the CanonicalTransactionChain', () => {
before(() => { before(() => {
Mock__CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Fake__CanonicalTransactionChain.getTotalElements.returns(
batch.length - 1 batch.length - 1
) )
}) })
...@@ -130,9 +130,7 @@ describe('StateCommitmentChain', () => { ...@@ -130,9 +130,7 @@ describe('StateCommitmentChain', () => {
describe('when not submitting more elements than present in the CanonicalTransactionChain', () => { describe('when not submitting more elements than present in the CanonicalTransactionChain', () => {
before(() => { before(() => {
Mock__CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Fake__CanonicalTransactionChain.getTotalElements.returns(batch.length)
batch.length
)
}) })
it('should append the state batch', async () => { it('should append the state batch', async () => {
...@@ -143,7 +141,7 @@ describe('StateCommitmentChain', () => { ...@@ -143,7 +141,7 @@ describe('StateCommitmentChain', () => {
describe('when a sequencer submits ', () => { describe('when a sequencer submits ', () => {
beforeEach(async () => { beforeEach(async () => {
Mock__CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Fake__CanonicalTransactionChain.getTotalElements.returns(
batch.length * 2 batch.length * 2
) )
...@@ -182,7 +180,7 @@ describe('StateCommitmentChain', () => { ...@@ -182,7 +180,7 @@ describe('StateCommitmentChain', () => {
}) })
describe('when the proposer has not previously staked at the BondManager', () => { describe('when the proposer has not previously staked at the BondManager', () => {
before(() => { before(() => {
Mock__BondManager.smocked.isCollateralized.will.return.with(false) Fake__BondManager.isCollateralized.returns(false)
}) })
it('should revert', async () => { it('should revert', async () => {
...@@ -207,13 +205,11 @@ describe('StateCommitmentChain', () => { ...@@ -207,13 +205,11 @@ describe('StateCommitmentChain', () => {
} }
before(() => { before(() => {
Mock__BondManager.smocked.isCollateralized.will.return.with(true) Fake__BondManager.isCollateralized.returns(true)
}) })
beforeEach(async () => { beforeEach(async () => {
Mock__CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Fake__CanonicalTransactionChain.getTotalElements.returns(batch.length)
batch.length
)
await StateCommitmentChain.appendStateBatch(batch, 0) await StateCommitmentChain.appendStateBatch(batch, 0)
batchHeader.extraData = ethers.utils.defaultAbiCoder.encode( batchHeader.extraData = ethers.utils.defaultAbiCoder.encode(
['uint256', 'address'], ['uint256', 'address'],
...@@ -329,9 +325,7 @@ describe('StateCommitmentChain', () => { ...@@ -329,9 +325,7 @@ describe('StateCommitmentChain', () => {
describe('when one batch element has been inserted', () => { describe('when one batch element has been inserted', () => {
beforeEach(async () => { beforeEach(async () => {
const batch = [NON_NULL_BYTES32] const batch = [NON_NULL_BYTES32]
Mock__CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Fake__CanonicalTransactionChain.getTotalElements.returns(batch.length)
batch.length
)
await StateCommitmentChain.appendStateBatch(batch, 0) await StateCommitmentChain.appendStateBatch(batch, 0)
}) })
...@@ -343,9 +337,7 @@ describe('StateCommitmentChain', () => { ...@@ -343,9 +337,7 @@ describe('StateCommitmentChain', () => {
describe('when 64 batch elements have been inserted in one batch', () => { describe('when 64 batch elements have been inserted in one batch', () => {
beforeEach(async () => { beforeEach(async () => {
const batch = Array(64).fill(NON_NULL_BYTES32) const batch = Array(64).fill(NON_NULL_BYTES32)
Mock__CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Fake__CanonicalTransactionChain.getTotalElements.returns(batch.length)
batch.length
)
await StateCommitmentChain.appendStateBatch(batch, 0) await StateCommitmentChain.appendStateBatch(batch, 0)
}) })
...@@ -357,7 +349,7 @@ describe('StateCommitmentChain', () => { ...@@ -357,7 +349,7 @@ describe('StateCommitmentChain', () => {
describe('when 32 batch elements have been inserted in each of two batches', () => { describe('when 32 batch elements have been inserted in each of two batches', () => {
beforeEach(async () => { beforeEach(async () => {
const batch = Array(32).fill(NON_NULL_BYTES32) const batch = Array(32).fill(NON_NULL_BYTES32)
Mock__CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Fake__CanonicalTransactionChain.getTotalElements.returns(
batch.length * 2 batch.length * 2
) )
await StateCommitmentChain.appendStateBatch(batch, 0) await StateCommitmentChain.appendStateBatch(batch, 0)
...@@ -380,9 +372,7 @@ describe('StateCommitmentChain', () => { ...@@ -380,9 +372,7 @@ describe('StateCommitmentChain', () => {
describe('when one batch has been inserted', () => { describe('when one batch has been inserted', () => {
beforeEach(async () => { beforeEach(async () => {
const batch = [NON_NULL_BYTES32] const batch = [NON_NULL_BYTES32]
Mock__CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Fake__CanonicalTransactionChain.getTotalElements.returns(batch.length)
batch.length
)
await StateCommitmentChain.appendStateBatch(batch, 0) await StateCommitmentChain.appendStateBatch(batch, 0)
}) })
...@@ -394,7 +384,7 @@ describe('StateCommitmentChain', () => { ...@@ -394,7 +384,7 @@ describe('StateCommitmentChain', () => {
describe('when 8 batches have been inserted', () => { describe('when 8 batches have been inserted', () => {
beforeEach(async () => { beforeEach(async () => {
const batch = [NON_NULL_BYTES32] const batch = [NON_NULL_BYTES32]
Mock__CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Fake__CanonicalTransactionChain.getTotalElements.returns(
batch.length * 8 batch.length * 8
) )
...@@ -422,9 +412,7 @@ describe('StateCommitmentChain', () => { ...@@ -422,9 +412,7 @@ describe('StateCommitmentChain', () => {
let timestamp let timestamp
beforeEach(async () => { beforeEach(async () => {
const batch = [NON_NULL_BYTES32] const batch = [NON_NULL_BYTES32]
Mock__CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Fake__CanonicalTransactionChain.getTotalElements.returns(batch.length)
batch.length
)
await StateCommitmentChain.appendStateBatch(batch, 0) await StateCommitmentChain.appendStateBatch(batch, 0)
timestamp = await getEthTime(ethers.provider) timestamp = await getEthTime(ethers.provider)
}) })
...@@ -455,13 +443,11 @@ describe('StateCommitmentChain', () => { ...@@ -455,13 +443,11 @@ describe('StateCommitmentChain', () => {
const element = NON_NULL_BYTES32 const element = NON_NULL_BYTES32
before(async () => { before(async () => {
Mock__BondManager.smocked.isCollateralized.will.return.with(true) Fake__BondManager.isCollateralized.returns(true)
}) })
beforeEach(async () => { beforeEach(async () => {
Mock__CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Fake__CanonicalTransactionChain.getTotalElements.returns(batch.length)
batch.length
)
await StateCommitmentChain.appendStateBatch(batch, 0) await StateCommitmentChain.appendStateBatch(batch, 0)
batchHeader.extraData = ethers.utils.defaultAbiCoder.encode( batchHeader.extraData = ethers.utils.defaultAbiCoder.encode(
['uint256', 'address'], ['uint256', 'address'],
......
/* External Imports */ /* External Imports */
import hre, { ethers } from 'hardhat' import hre, { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract } from 'ethers' import { Signer, ContractFactory, Contract } from 'ethers'
import { smockit, MockContract } from '@eth-optimism/smock'
import { applyL1ToL2Alias } from '@eth-optimism/core-utils' import { applyL1ToL2Alias } from '@eth-optimism/core-utils'
import { smock, MockContractFactory } from '@defi-wonderland/smock' import {
smock,
MockContractFactory,
FakeContract,
} from '@defi-wonderland/smock'
/* Internal Imports */ /* Internal Imports */
import { expect } from '../../../setup' import { expect } from '../../../setup'
...@@ -20,17 +23,17 @@ describe('L2CrossDomainMessenger', () => { ...@@ -20,17 +23,17 @@ describe('L2CrossDomainMessenger', () => {
;[signer] = await ethers.getSigners() ;[signer] = await ethers.getSigners()
}) })
let Mock__TargetContract: MockContract let Fake__TargetContract: FakeContract
let Mock__L1CrossDomainMessenger: MockContract let Fake__L1CrossDomainMessenger: FakeContract
let Mock__OVM_L2ToL1MessagePasser: MockContract let Fake__OVM_L2ToL1MessagePasser: FakeContract
before(async () => { before(async () => {
Mock__TargetContract = await smockit( Fake__TargetContract = await smock.fake<Contract>(
await ethers.getContractFactory('Helper_SimpleProxy') await ethers.getContractFactory('Helper_SimpleProxy')
) )
Mock__L1CrossDomainMessenger = await smockit( Fake__L1CrossDomainMessenger = await smock.fake<Contract>(
await ethers.getContractFactory('L1CrossDomainMessenger') await ethers.getContractFactory('L1CrossDomainMessenger')
) )
Mock__OVM_L2ToL1MessagePasser = await smockit( Fake__OVM_L2ToL1MessagePasser = await smock.fake<Contract>(
await ethers.getContractFactory('OVM_L2ToL1MessagePasser'), await ethers.getContractFactory('OVM_L2ToL1MessagePasser'),
{ address: predeploys.OVM_L2ToL1MessagePasser } { address: predeploys.OVM_L2ToL1MessagePasser }
) )
...@@ -39,7 +42,7 @@ describe('L2CrossDomainMessenger', () => { ...@@ -39,7 +42,7 @@ describe('L2CrossDomainMessenger', () => {
let impersonatedL1CrossDomainMessengerSender: Signer let impersonatedL1CrossDomainMessengerSender: Signer
before(async () => { before(async () => {
const impersonatedAddress = applyL1ToL2Alias( const impersonatedAddress = applyL1ToL2Alias(
Mock__L1CrossDomainMessenger.address Fake__L1CrossDomainMessenger.address
) )
await hre.network.provider.request({ await hre.network.provider.request({
method: 'hardhat_impersonateAccount', method: 'hardhat_impersonateAccount',
...@@ -64,7 +67,7 @@ describe('L2CrossDomainMessenger', () => { ...@@ -64,7 +67,7 @@ describe('L2CrossDomainMessenger', () => {
let L2CrossDomainMessenger: Contract let L2CrossDomainMessenger: Contract
beforeEach(async () => { beforeEach(async () => {
L2CrossDomainMessenger = await Factory__L2CrossDomainMessenger.deploy( L2CrossDomainMessenger = await Factory__L2CrossDomainMessenger.deploy(
Mock__L1CrossDomainMessenger.address Fake__L1CrossDomainMessenger.address
) )
}) })
...@@ -77,7 +80,7 @@ describe('L2CrossDomainMessenger', () => { ...@@ -77,7 +80,7 @@ describe('L2CrossDomainMessenger', () => {
) )
Mock__L2CrossDomainMessenger = Mock__L2CrossDomainMessenger =
await Mock__Factory__L2CrossDomainMessenger.deploy( await Mock__Factory__L2CrossDomainMessenger.deploy(
Mock__L1CrossDomainMessenger.address Fake__L1CrossDomainMessenger.address
) )
}) })
...@@ -103,10 +106,10 @@ describe('L2CrossDomainMessenger', () => { ...@@ -103,10 +106,10 @@ describe('L2CrossDomainMessenger', () => {
).to.not.be.reverted ).to.not.be.reverted
expect( expect(
Mock__OVM_L2ToL1MessagePasser.smocked.passMessageToL1.calls[0] Fake__OVM_L2ToL1MessagePasser.passMessageToL1.getCall(0).args[0]
).to.deep.equal([ ).to.deep.equal(
encodeXDomainCalldata(target, await signer.getAddress(), message, 0), encodeXDomainCalldata(target, await signer.getAddress(), message, 0)
]) )
}) })
it('should be able to send the same message twice', async () => { it('should be able to send the same message twice', async () => {
...@@ -123,8 +126,8 @@ describe('L2CrossDomainMessenger', () => { ...@@ -123,8 +126,8 @@ describe('L2CrossDomainMessenger', () => {
let message: string let message: string
let sender: string let sender: string
before(async () => { before(async () => {
target = Mock__TargetContract.address target = Fake__TargetContract.address
message = Mock__TargetContract.interface.encodeFunctionData('setTarget', [ message = Fake__TargetContract.interface.encodeFunctionData('setTarget', [
NON_ZERO_ADDRESS, NON_ZERO_ADDRESS,
]) ])
sender = await signer.getAddress() sender = await signer.getAddress()
...@@ -146,9 +149,9 @@ describe('L2CrossDomainMessenger', () => { ...@@ -146,9 +149,9 @@ describe('L2CrossDomainMessenger', () => {
impersonatedL1CrossDomainMessengerSender impersonatedL1CrossDomainMessengerSender
).relayMessage(target, sender, message, 0) ).relayMessage(target, sender, message, 0)
expect(Mock__TargetContract.smocked.setTarget.calls[0]).to.deep.equal([ expect(Fake__TargetContract.setTarget.getCall(0).args[0]).to.deep.equal(
NON_ZERO_ADDRESS, NON_ZERO_ADDRESS
]) )
}) })
it('the xDomainMessageSender is reset to the original value', async () => { it('the xDomainMessageSender is reset to the original value', async () => {
...@@ -179,7 +182,7 @@ describe('L2CrossDomainMessenger', () => { ...@@ -179,7 +182,7 @@ describe('L2CrossDomainMessenger', () => {
it('should not make a call if the target is the L2 MessagePasser', async () => { it('should not make a call if the target is the L2 MessagePasser', async () => {
target = predeploys.OVM_L2ToL1MessagePasser target = predeploys.OVM_L2ToL1MessagePasser
message = Mock__OVM_L2ToL1MessagePasser.interface.encodeFunctionData( message = Fake__OVM_L2ToL1MessagePasser.interface.encodeFunctionData(
'passMessageToL1(bytes)', 'passMessageToL1(bytes)',
[NON_NULL_BYTES32] [NON_NULL_BYTES32]
) )
...@@ -193,7 +196,7 @@ describe('L2CrossDomainMessenger', () => { ...@@ -193,7 +196,7 @@ describe('L2CrossDomainMessenger', () => {
// There should be no 'relayedMessage' event logged in the receipt. // There should be no 'relayedMessage' event logged in the receipt.
const logs = ( const logs = (
await Mock__OVM_L2ToL1MessagePasser.provider.getTransactionReceipt( await Fake__OVM_L2ToL1MessagePasser.provider.getTransactionReceipt(
( (
await resProm await resProm
).hash ).hash
......
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract } from 'ethers' import { Signer, ContractFactory, Contract } from 'ethers'
import { import { smock, FakeContract, MockContract } from '@defi-wonderland/smock'
smockit,
MockContract,
smoddit,
ModifiableContract,
} from '@eth-optimism/smock'
import { smock } from '@defi-wonderland/smock'
/* Internal Imports */ /* Internal Imports */
import { expect } from '../../../setup' import { expect } from '../../../setup'
...@@ -47,10 +41,10 @@ describe('L2StandardBridge', () => { ...@@ -47,10 +41,10 @@ describe('L2StandardBridge', () => {
let L2StandardBridge: Contract let L2StandardBridge: Contract
let L2ERC20: Contract let L2ERC20: Contract
let Mock__L2CrossDomainMessenger: MockContract let Fake__L2CrossDomainMessenger: FakeContract
beforeEach(async () => { beforeEach(async () => {
// Get a new mock L2 messenger // Get a new mock L2 messenger
Mock__L2CrossDomainMessenger = await smockit( Fake__L2CrossDomainMessenger = await smock.fake<Contract>(
await ethers.getContractFactory('L2CrossDomainMessenger'), await ethers.getContractFactory('L2CrossDomainMessenger'),
// This allows us to use an ethers override {from: Mock__L2CrossDomainMessenger.address} to mock calls // This allows us to use an ethers override {from: Mock__L2CrossDomainMessenger.address} to mock calls
{ address: await l2MessengerImpersonator.getAddress() } { address: await l2MessengerImpersonator.getAddress() }
...@@ -59,7 +53,7 @@ describe('L2StandardBridge', () => { ...@@ -59,7 +53,7 @@ describe('L2StandardBridge', () => {
// Deploy the contract under test // Deploy the contract under test
L2StandardBridge = await ( L2StandardBridge = await (
await ethers.getContractFactory('L2StandardBridge') await ethers.getContractFactory('L2StandardBridge')
).deploy(Mock__L2CrossDomainMessenger.address, DUMMY_L1BRIDGE_ADDRESS) ).deploy(Fake__L2CrossDomainMessenger.address, DUMMY_L1BRIDGE_ADDRESS)
// Deploy an L2 ERC20 // Deploy an L2 ERC20
L2ERC20 = await ( L2ERC20 = await (
...@@ -83,7 +77,7 @@ describe('L2StandardBridge', () => { ...@@ -83,7 +77,7 @@ describe('L2StandardBridge', () => {
}) })
it('onlyFromCrossDomainAccount: should revert on calls from the right crossDomainMessenger, but wrong xDomainMessageSender (ie. not the L1L1StandardBridge)', async () => { it('onlyFromCrossDomainAccount: should revert on calls from the right crossDomainMessenger, but wrong xDomainMessageSender (ie. not the L1L1StandardBridge)', async () => {
Mock__L2CrossDomainMessenger.smocked.xDomainMessageSender.will.return.with( Fake__L2CrossDomainMessenger.xDomainMessageSender.returns(
NON_ZERO_ADDRESS NON_ZERO_ADDRESS
) )
...@@ -96,7 +90,7 @@ describe('L2StandardBridge', () => { ...@@ -96,7 +90,7 @@ describe('L2StandardBridge', () => {
0, 0,
NON_NULL_BYTES32, NON_NULL_BYTES32,
{ {
from: Mock__L2CrossDomainMessenger.address, from: Fake__L2CrossDomainMessenger.address,
} }
) )
).to.be.revertedWith(ERR_INVALID_X_DOMAIN_MSG_SENDER) ).to.be.revertedWith(ERR_INVALID_X_DOMAIN_MSG_SENDER)
...@@ -118,11 +112,11 @@ describe('L2StandardBridge', () => { ...@@ -118,11 +112,11 @@ describe('L2StandardBridge', () => {
0, 0,
NON_NULL_BYTES32, NON_NULL_BYTES32,
{ {
from: Mock__L2CrossDomainMessenger.address, from: Fake__L2CrossDomainMessenger.address,
} }
) )
Mock__L2CrossDomainMessenger.smocked.xDomainMessageSender.will.return.with( Fake__L2CrossDomainMessenger.xDomainMessageSender.returns(
() => DUMMY_L1BRIDGE_ADDRESS () => DUMMY_L1BRIDGE_ADDRESS
) )
...@@ -134,15 +128,15 @@ describe('L2StandardBridge', () => { ...@@ -134,15 +128,15 @@ describe('L2StandardBridge', () => {
100, 100,
NON_NULL_BYTES32, NON_NULL_BYTES32,
{ {
from: Mock__L2CrossDomainMessenger.address, from: Fake__L2CrossDomainMessenger.address,
} }
) )
const withdrawalCallToMessenger = const withdrawalCallToMessenger =
Mock__L2CrossDomainMessenger.smocked.sendMessage.calls[0] Fake__L2CrossDomainMessenger.sendMessage.getCall(1)
expect(withdrawalCallToMessenger._target).to.equal(DUMMY_L1BRIDGE_ADDRESS) expect(withdrawalCallToMessenger.args[0]).to.equal(DUMMY_L1BRIDGE_ADDRESS)
expect(withdrawalCallToMessenger._message).to.equal( expect(withdrawalCallToMessenger.args[1]).to.equal(
Factory__L1StandardBridge.interface.encodeFunctionData( Factory__L1StandardBridge.interface.encodeFunctionData(
'finalizeERC20Withdrawal', 'finalizeERC20Withdrawal',
[ [
...@@ -160,7 +154,7 @@ describe('L2StandardBridge', () => { ...@@ -160,7 +154,7 @@ describe('L2StandardBridge', () => {
it('should credit funds to the depositor', async () => { it('should credit funds to the depositor', async () => {
const depositAmount = 100 const depositAmount = 100
Mock__L2CrossDomainMessenger.smocked.xDomainMessageSender.will.return.with( Fake__L2CrossDomainMessenger.xDomainMessageSender.returns(
() => DUMMY_L1BRIDGE_ADDRESS () => DUMMY_L1BRIDGE_ADDRESS
) )
...@@ -172,7 +166,7 @@ describe('L2StandardBridge', () => { ...@@ -172,7 +166,7 @@ describe('L2StandardBridge', () => {
depositAmount, depositAmount,
NON_NULL_BYTES32, NON_NULL_BYTES32,
{ {
from: Mock__L2CrossDomainMessenger.address, from: Fake__L2CrossDomainMessenger.address,
} }
) )
...@@ -183,7 +177,7 @@ describe('L2StandardBridge', () => { ...@@ -183,7 +177,7 @@ describe('L2StandardBridge', () => {
describe('withdrawals', () => { describe('withdrawals', () => {
const withdrawAmount = 1_000 const withdrawAmount = 1_000
let SmoddedL2Token: ModifiableContract let Mock__L2Token: MockContract<Contract>
let Fake__OVM_ETH let Fake__OVM_ETH
...@@ -195,8 +189,8 @@ describe('L2StandardBridge', () => { ...@@ -195,8 +189,8 @@ describe('L2StandardBridge', () => {
beforeEach(async () => { beforeEach(async () => {
// Deploy a smodded gateway so we can give some balances to withdraw // Deploy a smodded gateway so we can give some balances to withdraw
SmoddedL2Token = await ( Mock__L2Token = await (
await smoddit('L2StandardERC20', alice) await smock.mock('L2StandardERC20')
).deploy( ).deploy(
L2StandardBridge.address, L2StandardBridge.address,
DUMMY_L1TOKEN_ADDRESS, DUMMY_L1TOKEN_ADDRESS,
...@@ -204,14 +198,11 @@ describe('L2StandardBridge', () => { ...@@ -204,14 +198,11 @@ describe('L2StandardBridge', () => {
'L2T' 'L2T'
) )
// Populate the initial state with a total supply and some money in alice's balance await Mock__L2Token.setVariable('_totalSupply', INITIAL_TOTAL_SUPPLY)
SmoddedL2Token.smodify.put({ await Mock__L2Token.setVariable('_balances', {
_totalSupply: INITIAL_TOTAL_SUPPLY,
_balances: {
[aliceAddress]: ALICE_INITIAL_BALANCE, [aliceAddress]: ALICE_INITIAL_BALANCE,
},
l2Bridge: L2StandardBridge.address,
}) })
await Mock__L2Token.setVariable('l2Bridge', L2StandardBridge.address)
}) })
it('withdraw() withdraws and sends the correct withdrawal message for OVM_ETH', async () => { it('withdraw() withdraws and sends the correct withdrawal message for OVM_ETH', async () => {
...@@ -223,14 +214,14 @@ describe('L2StandardBridge', () => { ...@@ -223,14 +214,14 @@ describe('L2StandardBridge', () => {
) )
const withdrawalCallToMessenger = const withdrawalCallToMessenger =
Mock__L2CrossDomainMessenger.smocked.sendMessage.calls[0] Fake__L2CrossDomainMessenger.sendMessage.getCall(0)
// Assert the correct cross-chain call was sent: // Assert the correct cross-chain call was sent:
// Message should be sent to the L1L1StandardBridge on L1 // Message should be sent to the L1L1StandardBridge on L1
expect(withdrawalCallToMessenger._target).to.equal(DUMMY_L1BRIDGE_ADDRESS) expect(withdrawalCallToMessenger.args[0]).to.equal(DUMMY_L1BRIDGE_ADDRESS)
// Message data should be a call telling the L1StandardBridge to finalize the withdrawal // Message data should be a call telling the L1StandardBridge to finalize the withdrawal
expect(withdrawalCallToMessenger._message).to.equal( expect(withdrawalCallToMessenger.args[1]).to.equal(
Factory__L1StandardBridge.interface.encodeFunctionData( Factory__L1StandardBridge.interface.encodeFunctionData(
'finalizeETHWithdrawal', 'finalizeETHWithdrawal',
[ [
...@@ -245,16 +236,16 @@ describe('L2StandardBridge', () => { ...@@ -245,16 +236,16 @@ describe('L2StandardBridge', () => {
it('withdraw() burns and sends the correct withdrawal message', async () => { it('withdraw() burns and sends the correct withdrawal message', async () => {
await L2StandardBridge.withdraw( await L2StandardBridge.withdraw(
SmoddedL2Token.address, Mock__L2Token.address,
withdrawAmount, withdrawAmount,
0, 0,
NON_NULL_BYTES32 NON_NULL_BYTES32
) )
const withdrawalCallToMessenger = const withdrawalCallToMessenger =
Mock__L2CrossDomainMessenger.smocked.sendMessage.calls[0] Fake__L2CrossDomainMessenger.sendMessage.getCall(0)
// Assert Alice's balance went down // Assert Alice's balance went down
const aliceBalance = await SmoddedL2Token.balanceOf( const aliceBalance = await Mock__L2Token.balanceOf(
await alice.getAddress() await alice.getAddress()
) )
expect(aliceBalance).to.deep.equal( expect(aliceBalance).to.deep.equal(
...@@ -262,21 +253,21 @@ describe('L2StandardBridge', () => { ...@@ -262,21 +253,21 @@ describe('L2StandardBridge', () => {
) )
// Assert totalSupply went down // Assert totalSupply went down
const newTotalSupply = await SmoddedL2Token.totalSupply() const newTotalSupply = await Mock__L2Token.totalSupply()
expect(newTotalSupply).to.deep.equal( expect(newTotalSupply).to.deep.equal(
ethers.BigNumber.from(INITIAL_TOTAL_SUPPLY - withdrawAmount) ethers.BigNumber.from(INITIAL_TOTAL_SUPPLY - withdrawAmount)
) )
// Assert the correct cross-chain call was sent: // Assert the correct cross-chain call was sent:
// Message should be sent to the L1L1StandardBridge on L1 // Message should be sent to the L1L1StandardBridge on L1
expect(withdrawalCallToMessenger._target).to.equal(DUMMY_L1BRIDGE_ADDRESS) expect(withdrawalCallToMessenger.args[0]).to.equal(DUMMY_L1BRIDGE_ADDRESS)
// Message data should be a call telling the L1L1StandardBridge to finalize the withdrawal // Message data should be a call telling the L1L1StandardBridge to finalize the withdrawal
expect(withdrawalCallToMessenger._message).to.equal( expect(withdrawalCallToMessenger.args[1]).to.equal(
Factory__L1StandardBridge.interface.encodeFunctionData( Factory__L1StandardBridge.interface.encodeFunctionData(
'finalizeERC20Withdrawal', 'finalizeERC20Withdrawal',
[ [
DUMMY_L1TOKEN_ADDRESS, DUMMY_L1TOKEN_ADDRESS,
SmoddedL2Token.address, Mock__L2Token.address,
await alice.getAddress(), await alice.getAddress(),
await alice.getAddress(), await alice.getAddress(),
withdrawAmount, withdrawAmount,
...@@ -285,22 +276,22 @@ describe('L2StandardBridge', () => { ...@@ -285,22 +276,22 @@ describe('L2StandardBridge', () => {
) )
) )
// gaslimit should be correct // gaslimit should be correct
expect(withdrawalCallToMessenger._gasLimit).to.equal(0) expect(withdrawalCallToMessenger.args[2]).to.equal(0)
}) })
it('withdrawTo() burns and sends the correct withdrawal message', async () => { it('withdrawTo() burns and sends the correct withdrawal message', async () => {
await L2StandardBridge.withdrawTo( await L2StandardBridge.withdrawTo(
SmoddedL2Token.address, Mock__L2Token.address,
await bob.getAddress(), await bob.getAddress(),
withdrawAmount, withdrawAmount,
0, 0,
NON_NULL_BYTES32 NON_NULL_BYTES32
) )
const withdrawalCallToMessenger = const withdrawalCallToMessenger =
Mock__L2CrossDomainMessenger.smocked.sendMessage.calls[0] Fake__L2CrossDomainMessenger.sendMessage.getCall(0)
// Assert Alice's balance went down // Assert Alice's balance went down
const aliceBalance = await SmoddedL2Token.balanceOf( const aliceBalance = await Mock__L2Token.balanceOf(
await alice.getAddress() await alice.getAddress()
) )
expect(aliceBalance).to.deep.equal( expect(aliceBalance).to.deep.equal(
...@@ -308,21 +299,21 @@ describe('L2StandardBridge', () => { ...@@ -308,21 +299,21 @@ describe('L2StandardBridge', () => {
) )
// Assert totalSupply went down // Assert totalSupply went down
const newTotalSupply = await SmoddedL2Token.totalSupply() const newTotalSupply = await Mock__L2Token.totalSupply()
expect(newTotalSupply).to.deep.equal( expect(newTotalSupply).to.deep.equal(
ethers.BigNumber.from(INITIAL_TOTAL_SUPPLY - withdrawAmount) ethers.BigNumber.from(INITIAL_TOTAL_SUPPLY - withdrawAmount)
) )
// Assert the correct cross-chain call was sent. // Assert the correct cross-chain call was sent.
// Message should be sent to the L1L1StandardBridge on L1 // Message should be sent to the L1L1StandardBridge on L1
expect(withdrawalCallToMessenger._target).to.equal(DUMMY_L1BRIDGE_ADDRESS) expect(withdrawalCallToMessenger.args[0]).to.equal(DUMMY_L1BRIDGE_ADDRESS)
// The message data should be a call telling the L1L1StandardBridge to finalize the withdrawal // The message data should be a call telling the L1L1StandardBridge to finalize the withdrawal
expect(withdrawalCallToMessenger._message).to.equal( expect(withdrawalCallToMessenger.args[1]).to.equal(
Factory__L1StandardBridge.interface.encodeFunctionData( Factory__L1StandardBridge.interface.encodeFunctionData(
'finalizeERC20Withdrawal', 'finalizeERC20Withdrawal',
[ [
DUMMY_L1TOKEN_ADDRESS, DUMMY_L1TOKEN_ADDRESS,
SmoddedL2Token.address, Mock__L2Token.address,
await alice.getAddress(), await alice.getAddress(),
await bob.getAddress(), await bob.getAddress(),
withdrawAmount, withdrawAmount,
...@@ -331,7 +322,7 @@ describe('L2StandardBridge', () => { ...@@ -331,7 +322,7 @@ describe('L2StandardBridge', () => {
) )
) )
// gas value is ignored and set to 0. // gas value is ignored and set to 0.
expect(withdrawalCallToMessenger._gasLimit).to.equal(0) expect(withdrawalCallToMessenger.args[2]).to.equal(0)
}) })
}) })
......
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract } from 'ethers' import { Signer, ContractFactory, Contract } from 'ethers'
import { smoddit } from '@eth-optimism/smock' import {
smock,
MockContractFactory,
MockContract,
} from '@defi-wonderland/smock'
/* Internal Imports */ /* Internal Imports */
import { expect } from '../../../setup' import { expect } from '../../../setup'
...@@ -9,13 +13,13 @@ import { predeploys, getContractInterface } from '../../../../src' ...@@ -9,13 +13,13 @@ import { predeploys, getContractInterface } from '../../../../src'
describe('L2StandardTokenFactory', () => { describe('L2StandardTokenFactory', () => {
let signer: Signer let signer: Signer
let Factory__L1ERC20: ContractFactory let Factory__L1ERC20: MockContractFactory<ContractFactory>
let L1ERC20: Contract let L1ERC20: MockContract<Contract>
let L2StandardTokenFactory: Contract let L2StandardTokenFactory: Contract
before(async () => { before(async () => {
;[signer] = await ethers.getSigners() ;[signer] = await ethers.getSigners()
// deploy an ERC20 contract on L1 // deploy an ERC20 contract on L1
Factory__L1ERC20 = await smoddit( Factory__L1ERC20 = await smock.mock(
'@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20' '@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20'
) )
L1ERC20 = await Factory__L1ERC20.deploy('L1ERC20', 'ERC') L1ERC20 = await Factory__L1ERC20.deploy('L1ERC20', 'ERC')
......
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { ContractFactory, Contract } from 'ethers' import { ContractFactory, Contract } from 'ethers'
import { MockContract, smockit } from '@eth-optimism/smock' import { smock, FakeContract } from '@defi-wonderland/smock'
import { remove0x } from '@eth-optimism/core-utils' import { remove0x } from '@eth-optimism/core-utils'
import { keccak256 } from 'ethers/lib/utils' import { keccak256 } from 'ethers/lib/utils'
...@@ -25,9 +25,9 @@ const callPredeploy = async ( ...@@ -25,9 +25,9 @@ const callPredeploy = async (
// TODO: rewrite this test to bypass the execution manager // TODO: rewrite this test to bypass the execution manager
describe.skip('OVM_L2ToL1MessagePasser', () => { describe.skip('OVM_L2ToL1MessagePasser', () => {
let Mock__OVM_ExecutionManager: MockContract let Fake__OVM_ExecutionManager: FakeContract
before(async () => { before(async () => {
Mock__OVM_ExecutionManager = await smockit( Fake__OVM_ExecutionManager = await smock.fake<Contract>(
await ethers.getContractFactory('OVM_ExecutionManager') await ethers.getContractFactory('OVM_ExecutionManager')
) )
}) })
...@@ -38,7 +38,7 @@ describe.skip('OVM_L2ToL1MessagePasser', () => { ...@@ -38,7 +38,7 @@ describe.skip('OVM_L2ToL1MessagePasser', () => {
await ethers.getContractFactory('Helper_PredeployCaller') await ethers.getContractFactory('Helper_PredeployCaller')
).deploy() ).deploy()
Helper_PredeployCaller.setTarget(Mock__OVM_ExecutionManager.address) Helper_PredeployCaller.setTarget(Fake__OVM_ExecutionManager.address)
}) })
let Factory__OVM_L2ToL1MessagePasser: ContractFactory let Factory__OVM_L2ToL1MessagePasser: ContractFactory
...@@ -55,9 +55,7 @@ describe.skip('OVM_L2ToL1MessagePasser', () => { ...@@ -55,9 +55,7 @@ describe.skip('OVM_L2ToL1MessagePasser', () => {
describe('passMessageToL1', () => { describe('passMessageToL1', () => {
before(async () => { before(async () => {
Mock__OVM_ExecutionManager.smocked.ovmCALLER.will.return.with( Fake__OVM_ExecutionManager.ovmCALLER.returns(NON_ZERO_ADDRESS)
NON_ZERO_ADDRESS
)
}) })
for (const size of ELEMENT_TEST_SIZES) { for (const size of ELEMENT_TEST_SIZES) {
......
/* Imports: External */ /* Imports: External */
import hre from 'hardhat' import hre from 'hardhat'
import { MockContract, smockit } from '@eth-optimism/smock' import { smock, FakeContract } from '@defi-wonderland/smock'
import { Contract, Signer } from 'ethers' import { Contract, Signer } from 'ethers'
/* Imports: Internal */ /* Imports: Internal */
...@@ -13,9 +13,9 @@ describe('OVM_SequencerFeeVault', () => { ...@@ -13,9 +13,9 @@ describe('OVM_SequencerFeeVault', () => {
;[signer1] = await hre.ethers.getSigners() ;[signer1] = await hre.ethers.getSigners()
}) })
let Mock__L2StandardBridge: MockContract let Fake__L2StandardBridge: FakeContract
before(async () => { before(async () => {
Mock__L2StandardBridge = await smockit('L2StandardBridge', { Fake__L2StandardBridge = await smock.fake<Contract>('L2StandardBridge', {
address: predeploys.L2StandardBridge, address: predeploys.L2StandardBridge,
}) })
}) })
...@@ -42,13 +42,21 @@ describe('OVM_SequencerFeeVault', () => { ...@@ -42,13 +42,21 @@ describe('OVM_SequencerFeeVault', () => {
await expect(OVM_SequencerFeeVault.withdraw()).to.not.be.reverted await expect(OVM_SequencerFeeVault.withdraw()).to.not.be.reverted
expect(Mock__L2StandardBridge.smocked.withdrawTo.calls[0]).to.deep.equal([ expect(
predeploys.OVM_ETH, Fake__L2StandardBridge.withdrawTo.getCall(0).args[0]
await signer1.getAddress(), ).to.deep.equal(predeploys.OVM_ETH)
amount, expect(
0, Fake__L2StandardBridge.withdrawTo.getCall(0).args[1]
'0x', ).to.deep.equal(await signer1.getAddress())
]) expect(
Fake__L2StandardBridge.withdrawTo.getCall(0).args[2]
).to.deep.equal(amount)
expect(
Fake__L2StandardBridge.withdrawTo.getCall(0).args[3]
).to.deep.equal(0)
expect(
Fake__L2StandardBridge.withdrawTo.getCall(0).args[4]
).to.deep.equal('0x')
}) })
it('should succeed when the contract has more than sufficient balance', async () => { it('should succeed when the contract has more than sufficient balance', async () => {
...@@ -62,14 +70,21 @@ describe('OVM_SequencerFeeVault', () => { ...@@ -62,14 +70,21 @@ describe('OVM_SequencerFeeVault', () => {
}) })
await expect(OVM_SequencerFeeVault.withdraw()).to.not.be.reverted await expect(OVM_SequencerFeeVault.withdraw()).to.not.be.reverted
expect(
expect(Mock__L2StandardBridge.smocked.withdrawTo.calls[0]).to.deep.equal([ Fake__L2StandardBridge.withdrawTo.getCall(1).args[0]
predeploys.OVM_ETH, ).to.deep.equal(predeploys.OVM_ETH)
await signer1.getAddress(), expect(
amount, Fake__L2StandardBridge.withdrawTo.getCall(1).args[1]
0, ).to.deep.equal(await signer1.getAddress())
'0x', expect(
]) Fake__L2StandardBridge.withdrawTo.getCall(1).args[2]
).to.deep.equal(amount)
expect(
Fake__L2StandardBridge.withdrawTo.getCall(1).args[3]
).to.deep.equal(0)
expect(
Fake__L2StandardBridge.withdrawTo.getCall(1).args[4]
).to.deep.equal('0x')
}) })
it('should have an owner in storage slot 0x00...00', async () => { it('should have an owner in storage slot 0x00...00', async () => {
......
/* Imports: External */ /* Imports: External */
import hre from 'hardhat' import hre from 'hardhat'
import { Contract, Signer } from 'ethers' import { Contract, Signer } from 'ethers'
import { smockit } from '@eth-optimism/smock' import { smock } from '@defi-wonderland/smock'
/* Imports: Internal */ /* Imports: Internal */
import { expect } from '../../setup' import { expect } from '../../setup'
...@@ -170,11 +170,13 @@ describe('L1ChugSplashProxy', () => { ...@@ -170,11 +170,13 @@ describe('L1ChugSplashProxy', () => {
}) })
it('should throw an error if the owner has signalled an upgrade', async () => { it('should throw an error if the owner has signalled an upgrade', async () => {
const owner = await smockit(getContractInterface('iL1ChugSplashDeployer')) const owner = await smock.fake<Contract>(
getContractInterface('iL1ChugSplashDeployer')
)
const factory = await hre.ethers.getContractFactory('L1ChugSplashProxy') const factory = await hre.ethers.getContractFactory('L1ChugSplashProxy')
const proxy = await factory.deploy(owner.address) const proxy = await factory.deploy(owner.address)
owner.smocked.isUpgrading.will.return.with(true) owner.isUpgrading.returns(true)
await expect( await expect(
owner.wallet.sendTransaction({ owner.wallet.sendTransaction({
......
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Contract } from 'ethers' import { Contract } from 'ethers'
import { FakeContract } from '@defi-wonderland/smock'
export const setProxyTarget = async ( export const setProxyTarget = async (
AddressManager: Contract, AddressManager: Contract,
name: string, name: string,
target: Contract target: FakeContract
): Promise<void> => { ): Promise<void> => {
const SimpleProxy: Contract = await ( const SimpleProxy: Contract = await (
await ethers.getContractFactory('Helper_SimpleProxy') await ethers.getContractFactory('Helper_SimpleProxy')
......
...@@ -497,23 +497,6 @@ ...@@ -497,23 +497,6 @@
minimatch "^3.0.4" minimatch "^3.0.4"
strip-json-comments "^3.1.1" strip-json-comments "^3.1.1"
"@eth-optimism/core-utils@^0.5.1":
version "0.5.5"
resolved "https://registry.yarnpkg.com/@eth-optimism/core-utils/-/core-utils-0.5.5.tgz#0e2bb95b23965fb51adfb8ba6841c3afd26a6411"
integrity sha512-N/uyZjHltnvnQyBOE498EGlqeYvWRUQTW6BpXhexKljEXZpnria4J4MFO9s1lJOpogLXTaS+lhM1Ic8zUNj8Pg==
dependencies:
"@ethersproject/abstract-provider" "^5.4.1"
ethers "^5.4.5"
lodash "^4.17.21"
"@eth-optimism/smock@1.1.10":
version "1.1.10"
resolved "https://registry.yarnpkg.com/@eth-optimism/smock/-/smock-1.1.10.tgz#98a6eefc994ccf707f52ab06849468f3cc57bdb7"
integrity sha512-XPx1x9odF/noTBHzIhRgL9ihhr769WgUhf9dOm6X7bjSWRAVsII3IqbdB4ssPycaoSuNSmv8HG1xTLgfgcyOYw==
dependencies:
"@eth-optimism/core-utils" "^0.5.1"
bn.js "^5.2.0"
"@ethereum-waffle/chai@^3.4.0": "@ethereum-waffle/chai@^3.4.0":
version "3.4.0" version "3.4.0"
resolved "https://registry.yarnpkg.com/@ethereum-waffle/chai/-/chai-3.4.0.tgz#2477877410a96bf370edd64df905b04fb9aba9d5" resolved "https://registry.yarnpkg.com/@ethereum-waffle/chai/-/chai-3.4.0.tgz#2477877410a96bf370edd64df905b04fb9aba9d5"
...@@ -712,7 +695,7 @@ ...@@ -712,7 +695,7 @@
"@ethersproject/properties" "^5.4.0" "@ethersproject/properties" "^5.4.0"
"@ethersproject/strings" "^5.4.0" "@ethersproject/strings" "^5.4.0"
"@ethersproject/abstract-provider@5.4.1", "@ethersproject/abstract-provider@^5.4.0", "@ethersproject/abstract-provider@^5.4.1": "@ethersproject/abstract-provider@5.4.1", "@ethersproject/abstract-provider@^5.4.0":
version "5.4.1" version "5.4.1"
resolved "https://registry.yarnpkg.com/@ethersproject/abstract-provider/-/abstract-provider-5.4.1.tgz#e404309a29f771bd4d28dbafadcaa184668c2a6e" resolved "https://registry.yarnpkg.com/@ethersproject/abstract-provider/-/abstract-provider-5.4.1.tgz#e404309a29f771bd4d28dbafadcaa184668c2a6e"
integrity sha512-3EedfKI3LVpjSKgAxoUaI+gB27frKsxzm+r21w9G60Ugk+3wVLQwhi1LsEJAKNV7WoZc8CIpNrATlL1QFABjtQ== integrity sha512-3EedfKI3LVpjSKgAxoUaI+gB27frKsxzm+r21w9G60Ugk+3wVLQwhi1LsEJAKNV7WoZc8CIpNrATlL1QFABjtQ==
...@@ -7176,7 +7159,7 @@ ethers@^4.0.32, ethers@^4.0.40: ...@@ -7176,7 +7159,7 @@ ethers@^4.0.32, ethers@^4.0.40:
uuid "2.0.1" uuid "2.0.1"
xmlhttprequest "1.8.0" xmlhttprequest "1.8.0"
ethers@^5.0.0, ethers@^5.0.1, ethers@^5.0.2, ethers@^5.4.5: ethers@^5.0.0, ethers@^5.0.1, ethers@^5.0.2:
version "5.4.5" version "5.4.5"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.4.5.tgz#cec133b9f5b514dc55e2561ee7aa7218c33affd7" resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.4.5.tgz#cec133b9f5b514dc55e2561ee7aa7218c33affd7"
integrity sha512-PPZ6flOAj230sXEWf/r/It6ZZ5c7EOVWx+PU87Glkbg79OtT7pLE1WgL4MRdwx6iF7HzSOvUUI+8cAmcdzo12w== integrity sha512-PPZ6flOAj230sXEWf/r/It6ZZ5c7EOVWx+PU87Glkbg79OtT7pLE1WgL4MRdwx6iF7HzSOvUUI+8cAmcdzo12w==
......
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