Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
0a082c8e
Unverified
Commit
0a082c8e
authored
Mar 07, 2022
by
Antonis Kogias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(tests): migrate from smock v1 to smock v2
parent
51a527b8
Changes
15
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
233 additions
and
254 deletions
+233
-254
package.json
packages/contracts/package.json
+0
-1
L1CrossDomainMessenger.spec.ts
...est/contracts/L1/messaging/L1CrossDomainMessenger.spec.ts
+22
-27
L1StandardBridge.spec.ts
...acts/test/contracts/L1/messaging/L1StandardBridge.spec.ts
+55
-51
deposit.gas.spec.ts
...contracts/test/contracts/L1/messaging/deposit.gas.spec.ts
+6
-8
CanonicalTransactionChain.gas.spec.ts
...contracts/L1/rollup/CanonicalTransactionChain.gas.spec.ts
+4
-4
CanonicalTransactionChain.spec.ts
...est/contracts/L1/rollup/CanonicalTransactionChain.spec.ts
+4
-4
StateCommitmentChain.spec.ts
...cts/test/contracts/L1/rollup/StateCommitmentChain.spec.ts
+22
-36
L2CrossDomainMessenger.spec.ts
...est/contracts/L2/messaging/L2CrossDomainMessenger.spec.ts
+25
-22
L2StandardBridge.spec.ts
...acts/test/contracts/L2/messaging/L2StandardBridge.spec.ts
+40
-49
L2StandardTokenFactory.spec.ts
...est/contracts/L2/messaging/L2StandardTokenFactory.spec.ts
+8
-4
OVM_L2ToL1MessagePasser.spec.ts
...t/contracts/L2/predeploys/OVM_L2ToL1MessagePasser.spec.ts
+5
-7
OVM_SequencerFeeVault.spec.ts
...est/contracts/L2/predeploys/OVM_SequencerFeeVault.spec.ts
+33
-18
L1ChugSplashProxy.spec.ts
...racts/test/contracts/chugsplash/L1ChugSplashProxy.spec.ts
+5
-3
address-manager.ts
packages/contracts/test/helpers/resolver/address-manager.ts
+2
-1
yarn.lock
yarn.lock
+2
-19
No files found.
packages/contracts/package.json
View file @
0a082c8e
...
...
@@ -66,7 +66,6 @@
"devDependencies"
:
{
"@codechecks/client"
:
"^0.1.11"
,
"@defi-wonderland/smock"
:
"^2.0.2"
,
"@eth-optimism/smock"
:
"1.1.10"
,
"@nomiclabs/ethereumjs-vm"
:
"^4.2.2"
,
"@nomiclabs/hardhat-ethers"
:
"^2.0.2"
,
"@nomiclabs/hardhat-etherscan"
:
"^2.1.6"
,
...
...
packages/contracts/test/contracts/L1/messaging/L1CrossDomainMessenger.spec.ts
View file @
0a082c8e
/* External Imports */
import
{
ethers
}
from
'
hardhat
'
import
{
Signer
,
ContractFactory
,
Contract
,
BigNumber
}
from
'
ethers
'
import
{
smockit
,
MockContract
}
from
'
@eth-optimism/smock
'
import
{
smock
,
MockContractFactory
}
from
'
@defi-wonderland/smock
'
import
{
smock
,
MockContractFactory
,
FakeContract
,
}
from
'
@defi-wonderland/smock
'
import
{
remove0x
,
toHexString
,
...
...
@@ -56,9 +59,9 @@ describe('L1CrossDomainMessenger', () => {
AddressManager
=
await
makeAddressManager
()
})
let
Mock__TargetContract
:
Mock
Contract
let
Mock__L2CrossDomainMessenger
:
Mock
Contract
let
Mock__StateCommitmentChain
:
Mock
Contract
let
Fake__TargetContract
:
Fake
Contract
let
Fake__L2CrossDomainMessenger
:
Fake
Contract
let
Fake__StateCommitmentChain
:
Fake
Contract
let
Factory__CanonicalTransactionChain
:
ContractFactory
let
Factory__ChainStorageContainer
:
ContractFactory
...
...
@@ -66,28 +69,28 @@ describe('L1CrossDomainMessenger', () => {
let
CanonicalTransactionChain
:
Contract
before
(
async
()
=>
{
Mock__TargetContract
=
await
smockit
(
Fake__TargetContract
=
await
smock
.
fake
<
Contract
>
(
await
ethers
.
getContractFactory
(
'
Helper_SimpleProxy
'
)
)
Mock__L2CrossDomainMessenger
=
await
smockit
(
Fake__L2CrossDomainMessenger
=
await
smock
.
fake
<
Contract
>
(
await
ethers
.
getContractFactory
(
'
L2CrossDomainMessenger
'
),
{
address
:
predeploys
.
L2CrossDomainMessenger
,
}
)
Mock__StateCommitmentChain
=
await
smockit
(
Fake__StateCommitmentChain
=
await
smock
.
fake
<
Contract
>
(
await
ethers
.
getContractFactory
(
'
StateCommitmentChain
'
)
)
await
AddressManager
.
setAddress
(
'
L2CrossDomainMessenger
'
,
Mock
__L2CrossDomainMessenger
.
address
Fake
__L2CrossDomainMessenger
.
address
)
await
setProxyTarget
(
AddressManager
,
'
StateCommitmentChain
'
,
Mock
__StateCommitmentChain
Fake
__StateCommitmentChain
)
Factory__CanonicalTransactionChain
=
await
ethers
.
getContractFactory
(
...
...
@@ -178,7 +181,7 @@ describe('L1CrossDomainMessenger', () => {
[
'
address
'
,
'
address
'
,
'
uint256
'
,
'
bytes
'
],
[
applyL1ToL2Alias
(
L1CrossDomainMessenger
.
address
),
Mock
__L2CrossDomainMessenger
.
address
,
Fake
__L2CrossDomainMessenger
.
address
,
gasLimit
,
calldata
,
]
...
...
@@ -322,7 +325,7 @@ describe('L1CrossDomainMessenger', () => {
.
to
.
emit
(
CanonicalTransactionChain
,
'
TransactionEnqueued
'
)
.
withArgs
(
applyL1ToL2Alias
(
L1CrossDomainMessenger
.
address
),
Mock
__L2CrossDomainMessenger
.
address
,
Fake
__L2CrossDomainMessenger
.
address
,
newGasLimit
,
encodeXDomainCalldata
(
target
,
sender
,
message
,
queueIndex
),
newQueueIndex
,
...
...
@@ -388,7 +391,7 @@ describe('L1CrossDomainMessenger', () => {
const
storageKey
=
ethers
.
utils
.
keccak256
(
ethers
.
utils
.
keccak256
(
calldata
+
remove0x
(
Mock
__L2CrossDomainMessenger
.
address
)
calldata
+
remove0x
(
Fake
__L2CrossDomainMessenger
.
address
)
)
+
'
00
'
.
repeat
(
32
)
)
const
storageGenerator
=
await
TrieTestGenerator
.
fromNodes
({
...
...
@@ -439,8 +442,8 @@ describe('L1CrossDomainMessenger', () => {
let
proof
:
any
let
calldata
:
string
before
(
async
()
=>
{
target
=
Mock
__TargetContract
.
address
message
=
Mock
__TargetContract
.
interface
.
encodeFunctionData
(
'
setTarget
'
,
[
target
=
Fake
__TargetContract
.
address
message
=
Fake
__TargetContract
.
interface
.
encodeFunctionData
(
'
setTarget
'
,
[
NON_ZERO_ADDRESS
,
])
sender
=
await
signer
.
getAddress
()
...
...
@@ -455,18 +458,12 @@ describe('L1CrossDomainMessenger', () => {
})
beforeEach
(
async
()
=>
{
Mock__StateCommitmentChain
.
smocked
.
verifyStateCommitment
.
will
.
return
.
with
(
true
)
Mock__StateCommitmentChain
.
smocked
.
insideFraudProofWindow
.
will
.
return
.
with
(
false
)
Fake__StateCommitmentChain
.
verifyStateCommitment
.
returns
(
true
)
Fake__StateCommitmentChain
.
insideFraudProofWindow
.
returns
(
false
)
})
it
(
'
should revert if still inside the fraud proof window
'
,
async
()
=>
{
Mock__StateCommitmentChain
.
smocked
.
insideFraudProofWindow
.
will
.
return
.
with
(
true
)
Fake__StateCommitmentChain
.
insideFraudProofWindow
.
returns
(
true
)
const
proof1
=
{
stateRoot
:
ethers
.
constants
.
HashZero
,
...
...
@@ -502,9 +499,7 @@ describe('L1CrossDomainMessenger', () => {
})
it
(
'
should revert if provided an invalid state root proof
'
,
async
()
=>
{
Mock__StateCommitmentChain
.
smocked
.
verifyStateCommitment
.
will
.
return
.
with
(
false
)
Fake__StateCommitmentChain
.
verifyStateCommitment
.
returns
(
false
)
const
proof1
=
{
stateRoot
:
ethers
.
constants
.
HashZero
,
...
...
packages/contracts/test/contracts/L1/messaging/L1StandardBridge.spec.ts
View file @
0a082c8e
This diff is collapsed.
Click to expand it.
packages/contracts/test/contracts/L1/messaging/deposit.gas.spec.ts
View file @
0a082c8e
/* External Imports */
import
{
ethers
}
from
'
hardhat
'
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
'
/* Internal Imports */
...
...
@@ -92,7 +92,7 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge [ @skip-on-coverage
})
// 4 Bridge
let
L1ERC20
:
Contract
let
L1ERC20
:
MockContract
<
Contract
>
let
L1StandardBridge
:
Contract
before
(
'
Deploy the bridge and setup the token
'
,
async
()
=>
{
// Deploy the Bridge
...
...
@@ -105,14 +105,12 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge [ @skip-on-coverage
)
L1ERC20
=
await
(
await
smo
ddit
(
'
@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20
'
)
await
smo
ck
.
mock
(
'
@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20
'
)
).
deploy
(
'
L1ERC20
'
,
'
ERC
'
)
const
aliceAddress
=
await
alice
.
getAddress
()
await
L1ERC20
.
smodify
.
put
({
_totalSupply
:
INITIAL_TOTAL_L1_SUPPLY
,
_balances
:
{
[
aliceAddress
]:
INITIAL_TOTAL_L1_SUPPLY
,
},
await
L1ERC20
.
setVariable
(
'
_totalSupply
'
,
INITIAL_TOTAL_L1_SUPPLY
)
await
L1ERC20
.
setVariable
(
'
_balances
'
,
{
[
aliceAddress
]:
INITIAL_TOTAL_L1_SUPPLY
,
})
})
...
...
packages/contracts/test/contracts/L1/rollup/CanonicalTransactionChain.gas.spec.ts
View file @
0a082c8e
/* External Imports */
import
{
ethers
}
from
'
hardhat
'
import
{
Signer
,
ContractFactory
,
Contract
}
from
'
ethers
'
import
{
smock
it
,
MockContract
}
from
'
@eth-optimism
/smock
'
import
{
smock
,
FakeContract
}
from
'
@defi-wonderland
/smock
'
import
{
AppendSequencerBatchParams
,
BatchContext
,
...
...
@@ -46,7 +46,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain [ @skip-on-coverage ]', () =
})
let
AddressManager
:
Contract
let
Mock__StateCommitmentChain
:
Mock
Contract
let
Fake__StateCommitmentChain
:
Fake
Contract
before
(
async
()
=>
{
AddressManager
=
await
makeAddressManager
()
await
AddressManager
.
setAddress
(
...
...
@@ -54,14 +54,14 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain [ @skip-on-coverage ]', () =
await
sequencer
.
getAddress
()
)
Mock__StateCommitmentChain
=
await
smockit
(
Fake__StateCommitmentChain
=
await
smock
.
fake
<
Contract
>
(
await
ethers
.
getContractFactory
(
'
StateCommitmentChain
'
)
)
await
setProxyTarget
(
AddressManager
,
'
StateCommitmentChain
'
,
Mock
__StateCommitmentChain
Fake
__StateCommitmentChain
)
})
...
...
packages/contracts/test/contracts/L1/rollup/CanonicalTransactionChain.spec.ts
View file @
0a082c8e
/* External Imports */
import
{
ethers
}
from
'
hardhat
'
import
{
Signer
,
ContractFactory
,
Contract
}
from
'
ethers
'
import
{
smock
it
,
MockContract
}
from
'
@eth-optimism
/smock
'
import
{
smock
,
FakeContract
}
from
'
@defi-wonderland
/smock
'
import
{
AppendSequencerBatchParams
,
encodeAppendSequencerBatch
,
...
...
@@ -69,7 +69,7 @@ describe('CanonicalTransactionChain', () => {
})
let
AddressManager
:
Contract
let
Mock__StateCommitmentChain
:
Mock
Contract
let
Fake__StateCommitmentChain
:
Fake
Contract
before
(
async
()
=>
{
AddressManager
=
await
makeAddressManager
()
await
AddressManager
.
setAddress
(
...
...
@@ -77,14 +77,14 @@ describe('CanonicalTransactionChain', () => {
await
sequencer
.
getAddress
()
)
Mock__StateCommitmentChain
=
await
smockit
(
Fake__StateCommitmentChain
=
await
smock
.
fake
<
Contract
>
(
await
ethers
.
getContractFactory
(
'
StateCommitmentChain
'
)
)
await
setProxyTarget
(
AddressManager
,
'
StateCommitmentChain
'
,
Mock
__StateCommitmentChain
Fake
__StateCommitmentChain
)
})
...
...
packages/contracts/test/contracts/L1/rollup/StateCommitmentChain.spec.ts
View file @
0a082c8e
/* External Imports */
import
{
ethers
}
from
'
hardhat
'
import
{
Signer
,
ContractFactory
,
Contract
,
constants
}
from
'
ethers
'
import
{
smock
it
,
MockContract
}
from
'
@eth-optimism
/smock
'
import
{
smock
,
FakeContract
}
from
'
@defi-wonderland
/smock
'
/* Internal Imports */
import
{
expect
}
from
'
../../../setup
'
...
...
@@ -25,26 +25,26 @@ describe('StateCommitmentChain', () => {
AddressManager
=
await
makeAddressManager
()
})
let
Mock__CanonicalTransactionChain
:
Mock
Contract
let
Mock__BondManager
:
Mock
Contract
let
Fake__CanonicalTransactionChain
:
Fake
Contract
let
Fake__BondManager
:
Fake
Contract
before
(
async
()
=>
{
Mock__CanonicalTransactionChain
=
await
smockit
(
Fake__CanonicalTransactionChain
=
await
smock
.
fake
<
Contract
>
(
await
ethers
.
getContractFactory
(
'
CanonicalTransactionChain
'
)
)
await
setProxyTarget
(
AddressManager
,
'
CanonicalTransactionChain
'
,
Mock
__CanonicalTransactionChain
Fake
__CanonicalTransactionChain
)
Mock__BondManager
=
await
smockit
(
Fake__BondManager
=
await
smock
.
fake
<
Contract
>
(
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
(
'
OVM_Proposer
'
,
...
...
@@ -114,7 +114,7 @@ describe('StateCommitmentChain', () => {
describe
(
'
when submitting more elements than present in the CanonicalTransactionChain
'
,
()
=>
{
before
(()
=>
{
Mock__CanonicalTransactionChain
.
smocked
.
getTotalElements
.
will
.
return
.
with
(
Fake__CanonicalTransactionChain
.
getTotalElements
.
returns
(
batch
.
length
-
1
)
})
...
...
@@ -130,9 +130,7 @@ describe('StateCommitmentChain', () => {
describe
(
'
when not submitting more elements than present in the CanonicalTransactionChain
'
,
()
=>
{
before
(()
=>
{
Mock__CanonicalTransactionChain
.
smocked
.
getTotalElements
.
will
.
return
.
with
(
batch
.
length
)
Fake__CanonicalTransactionChain
.
getTotalElements
.
returns
(
batch
.
length
)
})
it
(
'
should append the state batch
'
,
async
()
=>
{
...
...
@@ -143,7 +141,7 @@ describe('StateCommitmentChain', () => {
describe
(
'
when a sequencer submits
'
,
()
=>
{
beforeEach
(
async
()
=>
{
Mock__CanonicalTransactionChain
.
smocked
.
getTotalElements
.
will
.
return
.
with
(
Fake__CanonicalTransactionChain
.
getTotalElements
.
returns
(
batch
.
length
*
2
)
...
...
@@ -182,7 +180,7 @@ describe('StateCommitmentChain', () => {
})
describe
(
'
when the proposer has not previously staked at the BondManager
'
,
()
=>
{
before
(()
=>
{
Mock__BondManager
.
smocked
.
isCollateralized
.
will
.
return
.
with
(
false
)
Fake__BondManager
.
isCollateralized
.
returns
(
false
)
})
it
(
'
should revert
'
,
async
()
=>
{
...
...
@@ -207,13 +205,11 @@ describe('StateCommitmentChain', () => {
}
before
(()
=>
{
Mock__BondManager
.
smocked
.
isCollateralized
.
will
.
return
.
with
(
true
)
Fake__BondManager
.
isCollateralized
.
returns
(
true
)
})
beforeEach
(
async
()
=>
{
Mock__CanonicalTransactionChain
.
smocked
.
getTotalElements
.
will
.
return
.
with
(
batch
.
length
)
Fake__CanonicalTransactionChain
.
getTotalElements
.
returns
(
batch
.
length
)
await
StateCommitmentChain
.
appendStateBatch
(
batch
,
0
)
batchHeader
.
extraData
=
ethers
.
utils
.
defaultAbiCoder
.
encode
(
[
'
uint256
'
,
'
address
'
],
...
...
@@ -329,9 +325,7 @@ describe('StateCommitmentChain', () => {
describe
(
'
when one batch element has been inserted
'
,
()
=>
{
beforeEach
(
async
()
=>
{
const
batch
=
[
NON_NULL_BYTES32
]
Mock__CanonicalTransactionChain
.
smocked
.
getTotalElements
.
will
.
return
.
with
(
batch
.
length
)
Fake__CanonicalTransactionChain
.
getTotalElements
.
returns
(
batch
.
length
)
await
StateCommitmentChain
.
appendStateBatch
(
batch
,
0
)
})
...
...
@@ -343,9 +337,7 @@ describe('StateCommitmentChain', () => {
describe
(
'
when 64 batch elements have been inserted in one batch
'
,
()
=>
{
beforeEach
(
async
()
=>
{
const
batch
=
Array
(
64
).
fill
(
NON_NULL_BYTES32
)
Mock__CanonicalTransactionChain
.
smocked
.
getTotalElements
.
will
.
return
.
with
(
batch
.
length
)
Fake__CanonicalTransactionChain
.
getTotalElements
.
returns
(
batch
.
length
)
await
StateCommitmentChain
.
appendStateBatch
(
batch
,
0
)
})
...
...
@@ -357,7 +349,7 @@ describe('StateCommitmentChain', () => {
describe
(
'
when 32 batch elements have been inserted in each of two batches
'
,
()
=>
{
beforeEach
(
async
()
=>
{
const
batch
=
Array
(
32
).
fill
(
NON_NULL_BYTES32
)
Mock__CanonicalTransactionChain
.
smocked
.
getTotalElements
.
will
.
return
.
with
(
Fake__CanonicalTransactionChain
.
getTotalElements
.
returns
(
batch
.
length
*
2
)
await
StateCommitmentChain
.
appendStateBatch
(
batch
,
0
)
...
...
@@ -380,9 +372,7 @@ describe('StateCommitmentChain', () => {
describe
(
'
when one batch has been inserted
'
,
()
=>
{
beforeEach
(
async
()
=>
{
const
batch
=
[
NON_NULL_BYTES32
]
Mock__CanonicalTransactionChain
.
smocked
.
getTotalElements
.
will
.
return
.
with
(
batch
.
length
)
Fake__CanonicalTransactionChain
.
getTotalElements
.
returns
(
batch
.
length
)
await
StateCommitmentChain
.
appendStateBatch
(
batch
,
0
)
})
...
...
@@ -394,7 +384,7 @@ describe('StateCommitmentChain', () => {
describe
(
'
when 8 batches have been inserted
'
,
()
=>
{
beforeEach
(
async
()
=>
{
const
batch
=
[
NON_NULL_BYTES32
]
Mock__CanonicalTransactionChain
.
smocked
.
getTotalElements
.
will
.
return
.
with
(
Fake__CanonicalTransactionChain
.
getTotalElements
.
returns
(
batch
.
length
*
8
)
...
...
@@ -422,9 +412,7 @@ describe('StateCommitmentChain', () => {
let
timestamp
beforeEach
(
async
()
=>
{
const
batch
=
[
NON_NULL_BYTES32
]
Mock__CanonicalTransactionChain
.
smocked
.
getTotalElements
.
will
.
return
.
with
(
batch
.
length
)
Fake__CanonicalTransactionChain
.
getTotalElements
.
returns
(
batch
.
length
)
await
StateCommitmentChain
.
appendStateBatch
(
batch
,
0
)
timestamp
=
await
getEthTime
(
ethers
.
provider
)
})
...
...
@@ -455,13 +443,11 @@ describe('StateCommitmentChain', () => {
const
element
=
NON_NULL_BYTES32
before
(
async
()
=>
{
Mock__BondManager
.
smocked
.
isCollateralized
.
will
.
return
.
with
(
true
)
Fake__BondManager
.
isCollateralized
.
returns
(
true
)
})
beforeEach
(
async
()
=>
{
Mock__CanonicalTransactionChain
.
smocked
.
getTotalElements
.
will
.
return
.
with
(
batch
.
length
)
Fake__CanonicalTransactionChain
.
getTotalElements
.
returns
(
batch
.
length
)
await
StateCommitmentChain
.
appendStateBatch
(
batch
,
0
)
batchHeader
.
extraData
=
ethers
.
utils
.
defaultAbiCoder
.
encode
(
[
'
uint256
'
,
'
address
'
],
...
...
packages/contracts/test/contracts/L2/messaging/L2CrossDomainMessenger.spec.ts
View file @
0a082c8e
/* External Imports */
import
hre
,
{
ethers
}
from
'
hardhat
'
import
{
Signer
,
ContractFactory
,
Contract
}
from
'
ethers
'
import
{
smockit
,
MockContract
}
from
'
@eth-optimism/smock
'
import
{
applyL1ToL2Alias
}
from
'
@eth-optimism/core-utils
'
import
{
smock
,
MockContractFactory
}
from
'
@defi-wonderland/smock
'
import
{
smock
,
MockContractFactory
,
FakeContract
,
}
from
'
@defi-wonderland/smock
'
/* Internal Imports */
import
{
expect
}
from
'
../../../setup
'
...
...
@@ -20,17 +23,17 @@ describe('L2CrossDomainMessenger', () => {
;[
signer
]
=
await
ethers
.
getSigners
()
})
let
Mock__TargetContract
:
Mock
Contract
let
Mock__L1CrossDomainMessenger
:
Mock
Contract
let
Mock__OVM_L2ToL1MessagePasser
:
Mock
Contract
let
Fake__TargetContract
:
Fake
Contract
let
Fake__L1CrossDomainMessenger
:
Fake
Contract
let
Fake__OVM_L2ToL1MessagePasser
:
Fake
Contract
before
(
async
()
=>
{
Mock__TargetContract
=
await
smockit
(
Fake__TargetContract
=
await
smock
.
fake
<
Contract
>
(
await
ethers
.
getContractFactory
(
'
Helper_SimpleProxy
'
)
)
Mock__L1CrossDomainMessenger
=
await
smockit
(
Fake__L1CrossDomainMessenger
=
await
smock
.
fake
<
Contract
>
(
await
ethers
.
getContractFactory
(
'
L1CrossDomainMessenger
'
)
)
Mock__OVM_L2ToL1MessagePasser
=
await
smockit
(
Fake__OVM_L2ToL1MessagePasser
=
await
smock
.
fake
<
Contract
>
(
await
ethers
.
getContractFactory
(
'
OVM_L2ToL1MessagePasser
'
),
{
address
:
predeploys
.
OVM_L2ToL1MessagePasser
}
)
...
...
@@ -39,7 +42,7 @@ describe('L2CrossDomainMessenger', () => {
let
impersonatedL1CrossDomainMessengerSender
:
Signer
before
(
async
()
=>
{
const
impersonatedAddress
=
applyL1ToL2Alias
(
Mock
__L1CrossDomainMessenger
.
address
Fake
__L1CrossDomainMessenger
.
address
)
await
hre
.
network
.
provider
.
request
({
method
:
'
hardhat_impersonateAccount
'
,
...
...
@@ -64,7 +67,7 @@ describe('L2CrossDomainMessenger', () => {
let
L2CrossDomainMessenger
:
Contract
beforeEach
(
async
()
=>
{
L2CrossDomainMessenger
=
await
Factory__L2CrossDomainMessenger
.
deploy
(
Mock
__L1CrossDomainMessenger
.
address
Fake
__L1CrossDomainMessenger
.
address
)
})
...
...
@@ -77,7 +80,7 @@ describe('L2CrossDomainMessenger', () => {
)
Mock__L2CrossDomainMessenger
=
await
Mock__Factory__L2CrossDomainMessenger
.
deploy
(
Mock
__L1CrossDomainMessenger
.
address
Fake
__L1CrossDomainMessenger
.
address
)
})
...
...
@@ -103,10 +106,10 @@ describe('L2CrossDomainMessenger', () => {
).
to
.
not
.
be
.
reverted
expect
(
Mock__OVM_L2ToL1MessagePasser
.
smocked
.
passMessageToL1
.
call
s
[
0
]
).
to
.
deep
.
equal
(
[
encodeXDomainCalldata
(
target
,
await
signer
.
getAddress
(),
message
,
0
)
,
]
)
Fake__OVM_L2ToL1MessagePasser
.
passMessageToL1
.
getCall
(
0
).
arg
s
[
0
]
).
to
.
deep
.
equal
(
encodeXDomainCalldata
(
target
,
await
signer
.
getAddress
(),
message
,
0
)
)
})
it
(
'
should be able to send the same message twice
'
,
async
()
=>
{
...
...
@@ -123,8 +126,8 @@ describe('L2CrossDomainMessenger', () => {
let
message
:
string
let
sender
:
string
before
(
async
()
=>
{
target
=
Mock
__TargetContract
.
address
message
=
Mock
__TargetContract
.
interface
.
encodeFunctionData
(
'
setTarget
'
,
[
target
=
Fake
__TargetContract
.
address
message
=
Fake
__TargetContract
.
interface
.
encodeFunctionData
(
'
setTarget
'
,
[
NON_ZERO_ADDRESS
,
])
sender
=
await
signer
.
getAddress
()
...
...
@@ -146,9 +149,9 @@ describe('L2CrossDomainMessenger', () => {
impersonatedL1CrossDomainMessengerSender
).
relayMessage
(
target
,
sender
,
message
,
0
)
expect
(
Mock__TargetContract
.
smocked
.
setTarget
.
calls
[
0
]).
to
.
deep
.
equal
([
NON_ZERO_ADDRESS
,
]
)
expect
(
Fake__TargetContract
.
setTarget
.
getCall
(
0
).
args
[
0
]).
to
.
deep
.
equal
(
NON_ZERO_ADDRESS
)
})
it
(
'
the xDomainMessageSender is reset to the original value
'
,
async
()
=>
{
...
...
@@ -179,7 +182,7 @@ describe('L2CrossDomainMessenger', () => {
it
(
'
should not make a call if the target is the L2 MessagePasser
'
,
async
()
=>
{
target
=
predeploys
.
OVM_L2ToL1MessagePasser
message
=
Mock
__OVM_L2ToL1MessagePasser
.
interface
.
encodeFunctionData
(
message
=
Fake
__OVM_L2ToL1MessagePasser
.
interface
.
encodeFunctionData
(
'
passMessageToL1(bytes)
'
,
[
NON_NULL_BYTES32
]
)
...
...
@@ -193,7 +196,7 @@ describe('L2CrossDomainMessenger', () => {
// There should be no 'relayedMessage' event logged in the receipt.
const
logs
=
(
await
Mock
__OVM_L2ToL1MessagePasser
.
provider
.
getTransactionReceipt
(
await
Fake
__OVM_L2ToL1MessagePasser
.
provider
.
getTransactionReceipt
(
(
await
resProm
).
hash
...
...
packages/contracts/test/contracts/L2/messaging/L2StandardBridge.spec.ts
View file @
0a082c8e
This diff is collapsed.
Click to expand it.
packages/contracts/test/contracts/L2/messaging/L2StandardTokenFactory.spec.ts
View file @
0a082c8e
/* External Imports */
import
{
ethers
}
from
'
hardhat
'
import
{
Signer
,
ContractFactory
,
Contract
}
from
'
ethers
'
import
{
smoddit
}
from
'
@eth-optimism/smock
'
import
{
smock
,
MockContractFactory
,
MockContract
,
}
from
'
@defi-wonderland/smock
'
/* Internal Imports */
import
{
expect
}
from
'
../../../setup
'
...
...
@@ -9,13 +13,13 @@ import { predeploys, getContractInterface } from '../../../../src'
describe
(
'
L2StandardTokenFactory
'
,
()
=>
{
let
signer
:
Signer
let
Factory__L1ERC20
:
ContractFactory
let
L1ERC20
:
Contract
let
Factory__L1ERC20
:
MockContractFactory
<
ContractFactory
>
let
L1ERC20
:
MockContract
<
Contract
>
let
L2StandardTokenFactory
:
Contract
before
(
async
()
=>
{
;[
signer
]
=
await
ethers
.
getSigners
()
// deploy an ERC20 contract on L1
Factory__L1ERC20
=
await
smo
ddit
(
Factory__L1ERC20
=
await
smo
ck
.
mock
(
'
@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20
'
)
L1ERC20
=
await
Factory__L1ERC20
.
deploy
(
'
L1ERC20
'
,
'
ERC
'
)
...
...
packages/contracts/test/contracts/L2/predeploys/OVM_L2ToL1MessagePasser.spec.ts
View file @
0a082c8e
/* External Imports */
import
{
ethers
}
from
'
hardhat
'
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
{
keccak256
}
from
'
ethers/lib/utils
'
...
...
@@ -25,9 +25,9 @@ const callPredeploy = async (
// TODO: rewrite this test to bypass the execution manager
describe
.
skip
(
'
OVM_L2ToL1MessagePasser
'
,
()
=>
{
let
Mock__OVM_ExecutionManager
:
Mock
Contract
let
Fake__OVM_ExecutionManager
:
Fake
Contract
before
(
async
()
=>
{
Mock__OVM_ExecutionManager
=
await
smockit
(
Fake__OVM_ExecutionManager
=
await
smock
.
fake
<
Contract
>
(
await
ethers
.
getContractFactory
(
'
OVM_ExecutionManager
'
)
)
})
...
...
@@ -38,7 +38,7 @@ describe.skip('OVM_L2ToL1MessagePasser', () => {
await
ethers
.
getContractFactory
(
'
Helper_PredeployCaller
'
)
).
deploy
()
Helper_PredeployCaller
.
setTarget
(
Mock
__OVM_ExecutionManager
.
address
)
Helper_PredeployCaller
.
setTarget
(
Fake
__OVM_ExecutionManager
.
address
)
})
let
Factory__OVM_L2ToL1MessagePasser
:
ContractFactory
...
...
@@ -55,9 +55,7 @@ describe.skip('OVM_L2ToL1MessagePasser', () => {
describe
(
'
passMessageToL1
'
,
()
=>
{
before
(
async
()
=>
{
Mock__OVM_ExecutionManager
.
smocked
.
ovmCALLER
.
will
.
return
.
with
(
NON_ZERO_ADDRESS
)
Fake__OVM_ExecutionManager
.
ovmCALLER
.
returns
(
NON_ZERO_ADDRESS
)
})
for
(
const
size
of
ELEMENT_TEST_SIZES
)
{
...
...
packages/contracts/test/contracts/L2/predeploys/OVM_SequencerFeeVault.spec.ts
View file @
0a082c8e
/* Imports: External */
import
hre
from
'
hardhat
'
import
{
MockContract
,
smockit
}
from
'
@eth-optimism
/smock
'
import
{
smock
,
FakeContract
}
from
'
@defi-wonderland
/smock
'
import
{
Contract
,
Signer
}
from
'
ethers
'
/* Imports: Internal */
...
...
@@ -13,9 +13,9 @@ describe('OVM_SequencerFeeVault', () => {
;[
signer1
]
=
await
hre
.
ethers
.
getSigners
()
})
let
Mock__L2StandardBridge
:
Mock
Contract
let
Fake__L2StandardBridge
:
Fake
Contract
before
(
async
()
=>
{
Mock__L2StandardBridge
=
await
smockit
(
'
L2StandardBridge
'
,
{
Fake__L2StandardBridge
=
await
smock
.
fake
<
Contract
>
(
'
L2StandardBridge
'
,
{
address
:
predeploys
.
L2StandardBridge
,
})
})
...
...
@@ -42,13 +42,21 @@ describe('OVM_SequencerFeeVault', () => {
await
expect
(
OVM_SequencerFeeVault
.
withdraw
()).
to
.
not
.
be
.
reverted
expect
(
Mock__L2StandardBridge
.
smocked
.
withdrawTo
.
calls
[
0
]).
to
.
deep
.
equal
([
predeploys
.
OVM_ETH
,
await
signer1
.
getAddress
(),
amount
,
0
,
'
0x
'
,
])
expect
(
Fake__L2StandardBridge
.
withdrawTo
.
getCall
(
0
).
args
[
0
]
).
to
.
deep
.
equal
(
predeploys
.
OVM_ETH
)
expect
(
Fake__L2StandardBridge
.
withdrawTo
.
getCall
(
0
).
args
[
1
]
).
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
()
=>
{
...
...
@@ -62,14 +70,21 @@ describe('OVM_SequencerFeeVault', () => {
})
await
expect
(
OVM_SequencerFeeVault
.
withdraw
()).
to
.
not
.
be
.
reverted
expect
(
Mock__L2StandardBridge
.
smocked
.
withdrawTo
.
calls
[
0
]).
to
.
deep
.
equal
([
predeploys
.
OVM_ETH
,
await
signer1
.
getAddress
(),
amount
,
0
,
'
0x
'
,
])
expect
(
Fake__L2StandardBridge
.
withdrawTo
.
getCall
(
1
).
args
[
0
]
).
to
.
deep
.
equal
(
predeploys
.
OVM_ETH
)
expect
(
Fake__L2StandardBridge
.
withdrawTo
.
getCall
(
1
).
args
[
1
]
).
to
.
deep
.
equal
(
await
signer1
.
getAddress
())
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
()
=>
{
...
...
packages/contracts/test/contracts/chugsplash/L1ChugSplashProxy.spec.ts
View file @
0a082c8e
/* Imports: External */
import
hre
from
'
hardhat
'
import
{
Contract
,
Signer
}
from
'
ethers
'
import
{
smock
it
}
from
'
@eth-optimism
/smock
'
import
{
smock
}
from
'
@defi-wonderland
/smock
'
/* Imports: Internal */
import
{
expect
}
from
'
../../setup
'
...
...
@@ -170,11 +170,13 @@ describe('L1ChugSplashProxy', () => {
})
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
proxy
=
await
factory
.
deploy
(
owner
.
address
)
owner
.
smocked
.
isUpgrading
.
will
.
return
.
with
(
true
)
owner
.
isUpgrading
.
returns
(
true
)
await
expect
(
owner
.
wallet
.
sendTransaction
({
...
...
packages/contracts/test/helpers/resolver/address-manager.ts
View file @
0a082c8e
/* External Imports */
import
{
ethers
}
from
'
hardhat
'
import
{
Contract
}
from
'
ethers
'
import
{
FakeContract
}
from
'
@defi-wonderland/smock
'
export
const
setProxyTarget
=
async
(
AddressManager
:
Contract
,
name
:
string
,
target
:
Contract
target
:
Fake
Contract
):
Promise
<
void
>
=>
{
const
SimpleProxy
:
Contract
=
await
(
await
ethers
.
getContractFactory
(
'
Helper_SimpleProxy
'
)
...
...
yarn.lock
View file @
0a082c8e
...
...
@@ -497,23 +497,6 @@
minimatch "^3.0.4"
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":
version "3.4.0"
resolved "https://registry.yarnpkg.com/@ethereum-waffle/chai/-/chai-3.4.0.tgz#2477877410a96bf370edd64df905b04fb9aba9d5"
...
...
@@ -712,7 +695,7 @@
"@ethersproject/properties" "^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"
resolved "https://registry.yarnpkg.com/@ethersproject/abstract-provider/-/abstract-provider-5.4.1.tgz#e404309a29f771bd4d28dbafadcaa184668c2a6e"
integrity sha512-3EedfKI3LVpjSKgAxoUaI+gB27frKsxzm+r21w9G60Ugk+3wVLQwhi1LsEJAKNV7WoZc8CIpNrATlL1QFABjtQ==
...
...
@@ -7176,7 +7159,7 @@ ethers@^4.0.32, ethers@^4.0.40:
uuid "2.0.1"
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"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.4.5.tgz#cec133b9f5b514dc55e2561ee7aa7218c33affd7"
integrity sha512-PPZ6flOAj230sXEWf/r/It6ZZ5c7EOVWx+PU87Glkbg79OtT7pLE1WgL4MRdwx6iF7HzSOvUUI+8cAmcdzo12w==
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment