Commit 24523e52 authored by Kevin Chen's avatar Kevin Chen

Update fault detector tests to use L2OutputOracle.

parent fc64f875
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
}, },
"dependencies": { "dependencies": {
"@eth-optimism/common-ts": "^0.8.2", "@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/core-utils": "^0.12.1",
"@eth-optimism/sdk": "^3.0.0", "@eth-optimism/sdk": "^3.0.0",
"@ethersproject/abstract-provider": "^5.7.0" "@ethersproject/abstract-provider": "^5.7.0"
......
import hre from 'hardhat' import hre from 'hardhat'
import { Contract } from 'ethers' import { Contract, utils } from 'ethers'
import { toRpcHexString } from '@eth-optimism/core-utils' import { toRpcHexString } from '@eth-optimism/core-utils'
import { import {
getContractFactory, getContractFactory,
getContractInterface, getContractInterface,
} from '@eth-optimism/contracts' } from '@eth-optimism/contracts-bedrock'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { smock, FakeContract } from '@defi-wonderland/smock' import { smock, FakeContract } from '@defi-wonderland/smock'
...@@ -16,81 +16,67 @@ import { ...@@ -16,81 +16,67 @@ import {
} from '../src' } from '../src'
describe('helpers', () => { describe('helpers', () => {
// Can be any non-zero value, 1000 is fine. const deployConfig = {
const challengeWindowSeconds = 1000 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 let signer: SignerWithAddress
before(async () => { before(async () => {
;[signer] = await hre.ethers.getSigners() ;[signer] = await hre.ethers.getSigners()
}) })
let FakeBondManager: FakeContract<Contract> let L2OutputOracle: Contract
let FakeCanonicalTransactionChain: FakeContract<Contract>
let AddressManager: Contract
let ChainStorageContainer: Contract
let StateCommitmentChain: Contract
let oracle: OutputOracle let oracle: OutputOracle
beforeEach(async () => { beforeEach(async () => {
// Set up fakes L2OutputOracle = await getContractFactory(
FakeBondManager = await smock.fake(getContractInterface('BondManager')) 'L2OutputOracle',
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',
signer signer
).deploy(AddressManager.address, challengeWindowSeconds, 10000000) ).deploy(deployConfig.l2OutputOracleSubmissionInterval,
deployConfig.l2BlockTime,
// Set addresses in manager deployConfig.l2OutputOracleStartingBlockNumber,
await AddressManager.setAddress( deployConfig.l2OutputOracleStartingTimestamp,
'ChainStorageContainer-SCC-batches', deployConfig.l2OutputOracleProposer,
ChainStorageContainer.address deployConfig.l2OutputOracleChallenger,
) deployConfig.finalizationPeriodSeconds
await AddressManager.setAddress(
'StateCommitmentChain',
StateCommitmentChain.address
) )
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 = { oracle = {
contract: StateCommitmentChain, contract: L2OutputOracle,
filter: StateCommitmentChain.filters.StateBatchAppended(), filter: L2OutputOracle.filters.OutputProposed(),
getTotalElements: async () => StateCommitmentChain.getTotalBatches(), getTotalElements: async () => L2OutputOracle.nextOutputIndex(),
getEventIndex: (args: any) => args._batchIndex, getEventIndex: (args: any) => args.l2OutputIndex,
} }
}) })
describe('findEventForStateBatch', () => { describe('findEventForStateBatch', () => {
describe('when the event exists once', () => { describe('when the event exists once', () => {
beforeEach(async () => { beforeEach(async () => {
await StateCommitmentChain.appendStateBatch( const latestBlock = await hre.ethers.provider.getBlock('latest')
[hre.ethers.constants.HashZero], const params = {
0 _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 () => { it('should return the event', async () => {
const event = await findEventForStateBatch(oracle, 0) const event = await findEventForStateBatch(oracle, 0)
expect(event.args._batchIndex).to.equal(0) expect(event.args.l2OutputIndex).to.equal(0)
}) })
}) })
...@@ -106,30 +92,43 @@ describe('helpers', () => { ...@@ -106,30 +92,43 @@ describe('helpers', () => {
describe('findFirstUnfinalizedIndex', () => { describe('findFirstUnfinalizedIndex', () => {
describe('when the chain is more then FPW seconds old', () => { describe('when the chain is more then FPW seconds old', () => {
beforeEach(async () => { beforeEach(async () => {
await StateCommitmentChain.appendStateBatch( const latestBlock = await hre.ethers.provider.getBlock('latest')
[hre.ethers.constants.HashZero], const params = {
0 _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 // Simulate FPW passing
await hre.ethers.provider.send('evm_increaseTime', [ await hre.ethers.provider.send('evm_increaseTime', [
toRpcHexString(challengeWindowSeconds * 2), toRpcHexString(deployConfig.finalizationPeriodSeconds * 2),
]) ])
await StateCommitmentChain.appendStateBatch( await L2OutputOracle.proposeL2Output(
[hre.ethers.constants.HashZero], params._outputRoot,
1 params._l2BlockNumber + deployConfig.l2OutputOracleSubmissionInterval,
params._l1BlockHash,
params._l1BlockNumber
) )
await StateCommitmentChain.appendStateBatch( await L2OutputOracle.proposeL2Output(
[hre.ethers.constants.HashZero], params._outputRoot,
2 params._l2BlockNumber + deployConfig.l2OutputOracleSubmissionInterval * 2,
params._l1BlockHash,
params._l1BlockNumber
) )
}) })
it('should find the first batch older than the FPW', async () => { it('should find the first batch older than the FPW', async () => {
const first = await findFirstUnfinalizedStateBatchIndex( const first = await findFirstUnfinalizedStateBatchIndex(
oracle, oracle,
challengeWindowSeconds deployConfig.finalizationPeriodSeconds
) )
expect(first).to.equal(1) expect(first).to.equal(1)
...@@ -138,24 +137,37 @@ describe('helpers', () => { ...@@ -138,24 +137,37 @@ describe('helpers', () => {
describe('when the chain is less than FPW seconds old', () => { describe('when the chain is less than FPW seconds old', () => {
beforeEach(async () => { beforeEach(async () => {
await StateCommitmentChain.appendStateBatch( const latestBlock = await hre.ethers.provider.getBlock('latest')
[hre.ethers.constants.HashZero], const params = {
0 _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( await L2OutputOracle.proposeL2Output(
[hre.ethers.constants.HashZero], params._outputRoot,
1 params._l2BlockNumber + deployConfig.l2OutputOracleSubmissionInterval,
params._l1BlockHash,
params._l1BlockNumber
) )
await StateCommitmentChain.appendStateBatch( await L2OutputOracle.proposeL2Output(
[hre.ethers.constants.HashZero], params._outputRoot,
2 params._l2BlockNumber + deployConfig.l2OutputOracleSubmissionInterval * 2,
params._l1BlockHash,
params._l1BlockNumber
) )
}) })
it('should return zero', async () => { it('should return zero', async () => {
const first = await findFirstUnfinalizedStateBatchIndex( const first = await findFirstUnfinalizedStateBatchIndex(
oracle, oracle,
challengeWindowSeconds deployConfig.finalizationPeriodSeconds
) )
expect(first).to.equal(0) expect(first).to.equal(0)
...@@ -164,22 +176,35 @@ describe('helpers', () => { ...@@ -164,22 +176,35 @@ describe('helpers', () => {
describe('when no batches submitted for the entire FPW', () => { describe('when no batches submitted for the entire FPW', () => {
beforeEach(async () => { beforeEach(async () => {
await StateCommitmentChain.appendStateBatch( const latestBlock = await hre.ethers.provider.getBlock('latest')
[hre.ethers.constants.HashZero], const params = {
0 _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( await L2OutputOracle.proposeL2Output(
[hre.ethers.constants.HashZero], params._outputRoot,
1 params._l2BlockNumber + deployConfig.l2OutputOracleSubmissionInterval,
params._l1BlockHash,
params._l1BlockNumber
) )
await StateCommitmentChain.appendStateBatch( await L2OutputOracle.proposeL2Output(
[hre.ethers.constants.HashZero], params._outputRoot,
2 params._l2BlockNumber + deployConfig.l2OutputOracleSubmissionInterval * 2,
params._l1BlockHash,
params._l1BlockNumber
) )
// Simulate FPW passing and no new batches // Simulate FPW passing and no new batches
await hre.ethers.provider.send('evm_increaseTime', [ await hre.ethers.provider.send('evm_increaseTime', [
toRpcHexString(challengeWindowSeconds * 2), toRpcHexString(deployConfig.finalizationPeriodSeconds * 2),
]) ])
// Mine a block to force timestamp to update // Mine a block to force timestamp to update
...@@ -189,7 +214,7 @@ describe('helpers', () => { ...@@ -189,7 +214,7 @@ describe('helpers', () => {
it('should return undefined', async () => { it('should return undefined', async () => {
const first = await findFirstUnfinalizedStateBatchIndex( const first = await findFirstUnfinalizedStateBatchIndex(
oracle, oracle,
challengeWindowSeconds deployConfig.finalizationPeriodSeconds
) )
expect(first).to.equal(undefined) expect(first).to.equal(undefined)
......
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