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
24523e52
Commit
24523e52
authored
Jun 21, 2023
by
Kevin Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update fault detector tests to use L2OutputOracle.
parent
fc64f875
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
86 deletions
+111
-86
package.json
packages/fault-detector/package.json
+1
-1
helpers.spec.ts
packages/fault-detector/test/helpers.spec.ts
+110
-85
No files found.
packages/fault-detector/package.json
View file @
24523e52
...
...
@@ -51,7 +51,7 @@
},
"dependencies"
:
{
"@eth-optimism/common-ts"
:
"^0.8.2"
,
"@eth-optimism/contracts
"
:
"^0.6
.0"
,
"@eth-optimism/contracts
-bedrock"
:
"^0.14
.0"
,
"@eth-optimism/core-utils"
:
"^0.12.1"
,
"@eth-optimism/sdk"
:
"^3.0.0"
,
"@ethersproject/abstract-provider"
:
"^5.7.0"
...
...
packages/fault-detector/test/helpers.spec.ts
View file @
24523e52
import
hre
from
'
hardhat
'
import
{
Contract
}
from
'
ethers
'
import
{
Contract
,
utils
}
from
'
ethers
'
import
{
toRpcHexString
}
from
'
@eth-optimism/core-utils
'
import
{
getContractFactory
,
getContractInterface
,
}
from
'
@eth-optimism/contracts
'
}
from
'
@eth-optimism/contracts
-bedrock
'
import
{
SignerWithAddress
}
from
'
@nomiclabs/hardhat-ethers/signers
'
import
{
smock
,
FakeContract
}
from
'
@defi-wonderland/smock
'
...
...
@@ -16,81 +16,67 @@ import {
}
from
'
../src
'
describe
(
'
helpers
'
,
()
=>
{
// Can be any non-zero value, 1000 is fine.
const
challengeWindowSeconds
=
1000
const
deployConfig
=
{
l2OutputOracleSubmissionInterval
:
6
,
l2BlockTime
:
2
,
l2OutputOracleStartingBlockNumber
:
0
,
l2OutputOracleStartingTimestamp
:
0
,
l2OutputOracleProposer
:
"
0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
"
,
l2OutputOracleChallenger
:
"
0x6925B8704Ff96DEe942623d6FB5e946EF5884b63
"
,
// Can be any non-zero value, 1000 is fine.
finalizationPeriodSeconds
:
1000
,
}
let
signer
:
SignerWithAddress
before
(
async
()
=>
{
;[
signer
]
=
await
hre
.
ethers
.
getSigners
()
})
let
FakeBondManager
:
FakeContract
<
Contract
>
let
FakeCanonicalTransactionChain
:
FakeContract
<
Contract
>
let
AddressManager
:
Contract
let
ChainStorageContainer
:
Contract
let
StateCommitmentChain
:
Contract
let
L2OutputOracle
:
Contract
let
oracle
:
OutputOracle
beforeEach
(
async
()
=>
{
// Set up fakes
FakeBondManager
=
await
smock
.
fake
(
getContractInterface
(
'
BondManager
'
))
FakeCanonicalTransactionChain
=
await
smock
.
fake
(
getContractInterface
(
'
CanonicalTransactionChain
'
)
)
// Set up contracts
AddressManager
=
await
getContractFactory
(
'
Lib_AddressManager
'
,
signer
).
deploy
()
ChainStorageContainer
=
await
getContractFactory
(
'
ChainStorageContainer
'
,
signer
).
deploy
(
AddressManager
.
address
,
'
StateCommitmentChain
'
)
StateCommitmentChain
=
await
getContractFactory
(
'
StateCommitmentChain
'
,
L2OutputOracle
=
await
getContractFactory
(
'
L2OutputOracle
'
,
signer
).
deploy
(
AddressManager
.
address
,
challengeWindowSeconds
,
10000000
)
// Set addresses in manager
await
AddressManager
.
setAddress
(
'
ChainStorageContainer-SCC-batches
'
,
ChainStorageContainer
.
address
)
await
AddressManager
.
setAddress
(
'
StateCommitmentChain
'
,
StateCommitmentChain
.
address
).
deploy
(
deployConfig
.
l2OutputOracleSubmissionInterval
,
deployConfig
.
l2BlockTime
,
deployConfig
.
l2OutputOracleStartingBlockNumber
,
deployConfig
.
l2OutputOracleStartingTimestamp
,
deployConfig
.
l2OutputOracleProposer
,
deployConfig
.
l2OutputOracleChallenger
,
deployConfig
.
finalizationPeriodSeconds
)
await
AddressManager
.
setAddress
(
'
CanonicalTransactionChain
'
,
FakeCanonicalTransactionChain
.
address
)
await
AddressManager
.
setAddress
(
'
BondManager
'
,
FakeBondManager
.
address
)
// Set up mock returns
FakeCanonicalTransactionChain
.
getTotalElements
.
returns
(
1000000000
)
// just needs to be large
FakeBondManager
.
isCollateralized
.
returns
(
true
)
oracle
=
{
contract
:
StateCommitmentChain
,
filter
:
StateCommitmentChain
.
filters
.
StateBatchAppend
ed
(),
getTotalElements
:
async
()
=>
StateCommitmentChain
.
getTotalBatches
(),
getEventIndex
:
(
args
:
any
)
=>
args
.
_batch
Index
,
contract
:
L2OutputOracle
,
filter
:
L2OutputOracle
.
filters
.
OutputPropos
ed
(),
getTotalElements
:
async
()
=>
L2OutputOracle
.
nextOutputIndex
(),
getEventIndex
:
(
args
:
any
)
=>
args
.
l2Output
Index
,
}
})
describe
(
'
findEventForStateBatch
'
,
()
=>
{
describe
(
'
when the event exists once
'
,
()
=>
{
beforeEach
(
async
()
=>
{
await
StateCommitmentChain
.
appendStateBatch
(
[
hre
.
ethers
.
constants
.
HashZero
],
0
const
latestBlock
=
await
hre
.
ethers
.
provider
.
getBlock
(
'
latest
'
)
const
params
=
{
_outputRoot
:
utils
.
formatBytes32String
(
'
testhash
'
),
_l2BlockNumber
:
deployConfig
.
l2OutputOracleStartingBlockNumber
+
deployConfig
.
l2OutputOracleSubmissionInterval
,
_l1BlockHash
:
latestBlock
.
hash
,
_l1BlockNumber
:
latestBlock
.
number
}
await
L2OutputOracle
.
proposeL2Output
(
params
.
_outputRoot
,
params
.
_l2BlockNumber
,
params
.
_l1BlockHash
,
params
.
_l1BlockNumber
)
})
it
(
'
should return the event
'
,
async
()
=>
{
const
event
=
await
findEventForStateBatch
(
oracle
,
0
)
expect
(
event
.
args
.
_batch
Index
).
to
.
equal
(
0
)
expect
(
event
.
args
.
l2Output
Index
).
to
.
equal
(
0
)
})
})
...
...
@@ -106,30 +92,43 @@ describe('helpers', () => {
describe
(
'
findFirstUnfinalizedIndex
'
,
()
=>
{
describe
(
'
when the chain is more then FPW seconds old
'
,
()
=>
{
beforeEach
(
async
()
=>
{
await
StateCommitmentChain
.
appendStateBatch
(
[
hre
.
ethers
.
constants
.
HashZero
],
0
const
latestBlock
=
await
hre
.
ethers
.
provider
.
getBlock
(
'
latest
'
)
const
params
=
{
_outputRoot
:
utils
.
formatBytes32String
(
'
testhash
'
),
_l2BlockNumber
:
deployConfig
.
l2OutputOracleStartingBlockNumber
+
deployConfig
.
l2OutputOracleSubmissionInterval
,
_l1BlockHash
:
latestBlock
.
hash
,
_l1BlockNumber
:
latestBlock
.
number
}
await
L2OutputOracle
.
proposeL2Output
(
params
.
_outputRoot
,
params
.
_l2BlockNumber
,
params
.
_l1BlockHash
,
params
.
_l1BlockNumber
)
// Simulate FPW passing
await
hre
.
ethers
.
provider
.
send
(
'
evm_increaseTime
'
,
[
toRpcHexString
(
challengeWindow
Seconds
*
2
),
toRpcHexString
(
deployConfig
.
finalizationPeriod
Seconds
*
2
),
])
await
StateCommitmentChain
.
appendStateBatch
(
[
hre
.
ethers
.
constants
.
HashZero
],
1
await
L2OutputOracle
.
proposeL2Output
(
params
.
_outputRoot
,
params
.
_l2BlockNumber
+
deployConfig
.
l2OutputOracleSubmissionInterval
,
params
.
_l1BlockHash
,
params
.
_l1BlockNumber
)
await
StateCommitmentChain
.
appendStateBatch
(
[
hre
.
ethers
.
constants
.
HashZero
],
2
await
L2OutputOracle
.
proposeL2Output
(
params
.
_outputRoot
,
params
.
_l2BlockNumber
+
deployConfig
.
l2OutputOracleSubmissionInterval
*
2
,
params
.
_l1BlockHash
,
params
.
_l1BlockNumber
)
})
it
(
'
should find the first batch older than the FPW
'
,
async
()
=>
{
const
first
=
await
findFirstUnfinalizedStateBatchIndex
(
oracle
,
challengeWindow
Seconds
deployConfig
.
finalizationPeriod
Seconds
)
expect
(
first
).
to
.
equal
(
1
)
...
...
@@ -138,24 +137,37 @@ describe('helpers', () => {
describe
(
'
when the chain is less than FPW seconds old
'
,
()
=>
{
beforeEach
(
async
()
=>
{
await
StateCommitmentChain
.
appendStateBatch
(
[
hre
.
ethers
.
constants
.
HashZero
],
0
const
latestBlock
=
await
hre
.
ethers
.
provider
.
getBlock
(
'
latest
'
)
const
params
=
{
_outputRoot
:
utils
.
formatBytes32String
(
'
testhash
'
),
_l2BlockNumber
:
deployConfig
.
l2OutputOracleStartingBlockNumber
+
deployConfig
.
l2OutputOracleSubmissionInterval
,
_l1BlockHash
:
latestBlock
.
hash
,
_l1BlockNumber
:
latestBlock
.
number
}
await
L2OutputOracle
.
proposeL2Output
(
params
.
_outputRoot
,
params
.
_l2BlockNumber
,
params
.
_l1BlockHash
,
params
.
_l1BlockNumber
)
await
StateCommitmentChain
.
appendStateBatch
(
[
hre
.
ethers
.
constants
.
HashZero
],
1
await
L2OutputOracle
.
proposeL2Output
(
params
.
_outputRoot
,
params
.
_l2BlockNumber
+
deployConfig
.
l2OutputOracleSubmissionInterval
,
params
.
_l1BlockHash
,
params
.
_l1BlockNumber
)
await
StateCommitmentChain
.
appendStateBatch
(
[
hre
.
ethers
.
constants
.
HashZero
],
2
await
L2OutputOracle
.
proposeL2Output
(
params
.
_outputRoot
,
params
.
_l2BlockNumber
+
deployConfig
.
l2OutputOracleSubmissionInterval
*
2
,
params
.
_l1BlockHash
,
params
.
_l1BlockNumber
)
})
it
(
'
should return zero
'
,
async
()
=>
{
const
first
=
await
findFirstUnfinalizedStateBatchIndex
(
oracle
,
challengeWindow
Seconds
deployConfig
.
finalizationPeriod
Seconds
)
expect
(
first
).
to
.
equal
(
0
)
...
...
@@ -164,22 +176,35 @@ describe('helpers', () => {
describe
(
'
when no batches submitted for the entire FPW
'
,
()
=>
{
beforeEach
(
async
()
=>
{
await
StateCommitmentChain
.
appendStateBatch
(
[
hre
.
ethers
.
constants
.
HashZero
],
0
const
latestBlock
=
await
hre
.
ethers
.
provider
.
getBlock
(
'
latest
'
)
const
params
=
{
_outputRoot
:
utils
.
formatBytes32String
(
'
testhash
'
),
_l2BlockNumber
:
deployConfig
.
l2OutputOracleStartingBlockNumber
+
deployConfig
.
l2OutputOracleSubmissionInterval
,
_l1BlockHash
:
latestBlock
.
hash
,
_l1BlockNumber
:
latestBlock
.
number
}
await
L2OutputOracle
.
proposeL2Output
(
params
.
_outputRoot
,
params
.
_l2BlockNumber
,
params
.
_l1BlockHash
,
params
.
_l1BlockNumber
)
await
StateCommitmentChain
.
appendStateBatch
(
[
hre
.
ethers
.
constants
.
HashZero
],
1
await
L2OutputOracle
.
proposeL2Output
(
params
.
_outputRoot
,
params
.
_l2BlockNumber
+
deployConfig
.
l2OutputOracleSubmissionInterval
,
params
.
_l1BlockHash
,
params
.
_l1BlockNumber
)
await
StateCommitmentChain
.
appendStateBatch
(
[
hre
.
ethers
.
constants
.
HashZero
],
2
await
L2OutputOracle
.
proposeL2Output
(
params
.
_outputRoot
,
params
.
_l2BlockNumber
+
deployConfig
.
l2OutputOracleSubmissionInterval
*
2
,
params
.
_l1BlockHash
,
params
.
_l1BlockNumber
)
// Simulate FPW passing and no new batches
await
hre
.
ethers
.
provider
.
send
(
'
evm_increaseTime
'
,
[
toRpcHexString
(
challengeWindow
Seconds
*
2
),
toRpcHexString
(
deployConfig
.
finalizationPeriod
Seconds
*
2
),
])
// Mine a block to force timestamp to update
...
...
@@ -189,7 +214,7 @@ describe('helpers', () => {
it
(
'
should return undefined
'
,
async
()
=>
{
const
first
=
await
findFirstUnfinalizedStateBatchIndex
(
oracle
,
challengeWindow
Seconds
deployConfig
.
finalizationPeriod
Seconds
)
expect
(
first
).
to
.
equal
(
undefined
)
...
...
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