Commit a0235ecb authored by Mark Tyneway's avatar Mark Tyneway

integration-tests: fix timestamp assertion

Update the assertion to not expect that the timestamps are
exactly equal but instead assert that the values are within
5%. This is because now the timestamps in L2 no longer
correspond to L1 timestamps and may be updated arbitrarily
by the sequencer.
parent 3a77bbcc
......@@ -2,7 +2,7 @@ import { expect } from './shared/setup'
/* Imports: External */
import { ethers } from 'hardhat'
import { injectL2Context } from '@eth-optimism/core-utils'
import { injectL2Context, expectApprox } from '@eth-optimism/core-utils'
import { predeploys } from '@eth-optimism/contracts'
import { Contract, BigNumber } from 'ethers'
......@@ -74,9 +74,11 @@ describe('OVM Context: Layer 2 EVM Context', () => {
const l1BlockNumber = await OVMContextStorage.l1BlockNumbers(i)
expect(l1BlockNumber.toNumber()).to.deep.equal(l1Block.number)
// L1 and L2 blocks will have the same timestamp.
// L1 and L2 blocks will have approximately the same timestamp.
const timestamp = await OVMContextStorage.timestamps(i)
expect(timestamp.toNumber()).to.deep.equal(l1Block.timestamp)
expectApprox(timestamp.toNumber(), l1Block.timestamp, {
percentUpperDeviation: 5,
})
expect(timestamp.toNumber()).to.deep.equal(l2Block.timestamp)
// Difficulty should always be zero.
......
......@@ -33,6 +33,7 @@ export class OptimismEnv {
addressManager: Contract
l1Bridge: Contract
l1Messenger: Contract
l1BlockNumber: Contract
ctc: Contract
scc: Contract
......@@ -59,6 +60,7 @@ export class OptimismEnv {
this.addressManager = args.addressManager
this.l1Bridge = args.l1Bridge
this.l1Messenger = args.l1Messenger
this.l1BlockNumber = args.l1BlockNumber
this.ovmEth = args.ovmEth
this.l2Bridge = args.l2Bridge
this.l2Messenger = args.l2Messenger
......@@ -113,12 +115,17 @@ export class OptimismEnv {
.connect(l2Wallet)
.attach(predeploys.OVM_SequencerFeeVault)
const l1BlockNumber = getContractFactory('iOVM_L1BlockNumber')
.connect(l2Wallet)
.attach(predeploys.OVM_L1BlockNumber)
return new OptimismEnv({
addressManager,
l1Bridge,
ctc,
scc,
l1Messenger,
l1BlockNumber,
ovmEth,
gasPriceOracle,
sequencerFeeVault,
......
......@@ -211,4 +211,29 @@ describe('stress tests', () => {
)
}).timeout(STRESS_TEST_TIMEOUT)
})
// These tests depend on an archive node due to the historical `eth_call`s
describe('Monotonicity Checks', () => {
it('should have monotonic timestamps and l1 blocknumbers', async () => {
const tip = await env.l2Provider.getBlock('latest')
const prev = {
block: await env.l2Provider.getBlock(0),
l1BlockNumber: await env.l1BlockNumber.getL1BlockNumber({
blockTag: 0,
}),
}
for (let i = 1; i < tip.number; i++) {
const block = await env.l2Provider.getBlock(i)
expect(block.timestamp).to.be.gte(prev.block.timestamp)
const l1BlockNumber = await env.l1BlockNumber.getL1BlockNumber({
blockTag: i,
})
expect(l1BlockNumber.gt(prev.l1BlockNumber))
prev.block = block
prev.l1BlockNumber = l1BlockNumber
}
})
})
})
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