Commit 952b5267 authored by Matthew Slipper's avatar Matthew Slipper

Fix itests

parent 3a726175
import { task } from 'hardhat/config' import { task } from 'hardhat/config'
import { providers } from 'ethers' import { providers } from 'ethers'
import { die, logStderr } from '../test/shared/utils' import { die, logStderr } from '../test/shared/utils'
task( task(
......
import { Contract } from 'ethers'
import { ethers } from 'hardhat'
import { OptimismEnv } from '../shared/env'
import { expect } from '../shared/setup'
import { traceToGasByOpcode } from '../hardfork.spec'
import { envConfig } from '../shared/utils'
describe('Nightly', () => {
before(async function () {
if (!envConfig.RUN_NIGHTLY_TESTS) {
this.skip()
}
})
describe('Berlin Hardfork', () => {
let env: OptimismEnv
let SimpleStorage: Contract
let Precompiles: Contract
before(async () => {
env = await OptimismEnv.new()
SimpleStorage = await ethers.getContractAt(
'SimpleStorage',
'0xE08fFE40748367ddc29B5A154331C73B7FCC13bD',
env.l2Wallet
)
Precompiles = await ethers.getContractAt(
'Precompiles',
'0x32E8Fbfd0C0bd1117112b249e997C27b0EC7cba2',
env.l2Wallet
)
})
describe('EIP-2929', () => {
it('should update the gas schedule', async () => {
const tx = await SimpleStorage.setValueNotXDomain(
`0x${'77'.repeat(32)}`
)
await tx.wait()
const berlinTrace = await env.l2Provider.send(
'debug_traceTransaction',
[tx.hash]
)
const preBerlinTrace = await env.l2Provider.send(
'debug_traceTransaction',
['0x2bb346f53544c5711502fbcbd1d78dc4fb61ca5f9390b9d6d67f1a3a77de7c39']
)
const berlinSstoreCosts = traceToGasByOpcode(
berlinTrace.structLogs,
'SSTORE'
)
const preBerlinSstoreCosts = traceToGasByOpcode(
preBerlinTrace.structLogs,
'SSTORE'
)
expect(preBerlinSstoreCosts).to.eq(80000)
expect(berlinSstoreCosts).to.eq(5300)
})
})
describe('EIP-2565', () => {
it('should become cheaper', async () => {
const tx = await Precompiles.expmod(64, 1, 64, { gasLimit: 5_000_000 })
await tx.wait()
const berlinTrace = await env.l2Provider.send(
'debug_traceTransaction',
[tx.hash]
)
const preBerlinTrace = await env.l2Provider.send(
'debug_traceTransaction',
['0x7ba7d273449b0062448fe5e7426bb169a032ce189d0e3781eb21079e85c2d7d5']
)
expect(berlinTrace.gas).to.be.lt(preBerlinTrace.gas)
})
})
describe('Berlin Additional (L1 London)', () => {
describe('EIP-3529', () => {
it('should remove the refund for selfdestruct', async () => {
const Factory__SelfDestruction = await ethers.getContractFactory(
'SelfDestruction',
env.l2Wallet
)
const SelfDestruction = await Factory__SelfDestruction.deploy()
const tx = await SelfDestruction.destruct({ gasLimit: 5_000_000 })
await tx.wait()
const berlinTrace = await env.l2Provider.send(
'debug_traceTransaction',
[tx.hash]
)
const preBerlinTrace = await env.l2Provider.send(
'debug_traceTransaction',
[
'0x948667349f00e996d9267e5c30d72fe7202a0ecdb88bab191e9a022bba6e4cb3',
]
)
expect(berlinTrace.gas).to.be.gt(preBerlinTrace.gas)
})
})
})
})
})
import { expect } from './shared/setup'
import { Contract, BigNumber } from 'ethers' import { Contract, BigNumber } from 'ethers'
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { expect } from './shared/setup'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
const traceToGasByOpcode = (structLogs, opcode) => { export const traceToGasByOpcode = (structLogs, opcode) => {
let gas = 0 let gas = 0
const opcodes = [] const opcodes = []
for (const log of structLogs) { for (const log of structLogs) {
...@@ -63,7 +63,7 @@ describe('Hard forks', () => { ...@@ -63,7 +63,7 @@ describe('Hard forks', () => {
) )
const preBerlinTrace = await env.l2Provider.send( const preBerlinTrace = await env.l2Provider.send(
'debug_traceTransaction', 'debug_traceTransaction',
[tx.hash, { overrides: { berlinBlock: tip.number + 10 } }] [tx.hash, { overrides: { berlinBlock: tip.number * 2 } }]
) )
expect(berlinTrace.gas).to.not.eq(preBerlinTrace.gas) expect(berlinTrace.gas).to.not.eq(preBerlinTrace.gas)
...@@ -93,7 +93,7 @@ describe('Hard forks', () => { ...@@ -93,7 +93,7 @@ describe('Hard forks', () => {
) )
const preBerlinTrace = await env.l2Provider.send( const preBerlinTrace = await env.l2Provider.send(
'debug_traceTransaction', 'debug_traceTransaction',
[tx.hash, { overrides: { berlinBlock: tip.number + 10 } }] [tx.hash, { overrides: { berlinBlock: tip.number * 2 } }]
) )
expect(berlinTrace.gas).to.be.lt(preBerlinTrace.gas) expect(berlinTrace.gas).to.be.lt(preBerlinTrace.gas)
}) })
...@@ -132,7 +132,7 @@ describe('Hard forks', () => { ...@@ -132,7 +132,7 @@ describe('Hard forks', () => {
) )
const preBerlinTrace = await env.l2Provider.send( const preBerlinTrace = await env.l2Provider.send(
'debug_traceTransaction', 'debug_traceTransaction',
[tx.hash, { overrides: { berlinBlock: tip.number + 10 } }] [tx.hash, { overrides: { berlinBlock: tip.number * 2 } }]
) )
// Updating a non zero value to another non zero value should not change // Updating a non zero value to another non zero value should not change
expect(berlinTrace.gas).to.deep.eq(preBerlinTrace.gas) expect(berlinTrace.gas).to.deep.eq(preBerlinTrace.gas)
...@@ -152,8 +152,9 @@ describe('Hard forks', () => { ...@@ -152,8 +152,9 @@ describe('Hard forks', () => {
) )
const preBerlinTrace = await env.l2Provider.send( const preBerlinTrace = await env.l2Provider.send(
'debug_traceTransaction', 'debug_traceTransaction',
[tx.hash, { overrides: { berlinBlock: tip.number + 10 } }] [tx.hash, { overrides: { berlinBlock: tip.number * 2 } }]
) )
// Updating to a zero value from a non zero value should becomes // Updating to a zero value from a non zero value should becomes
// more expensive due to this change being coupled with EIP-2929 // more expensive due to this change being coupled with EIP-2929
expect(berlinTrace.gas).to.be.gt(preBerlinTrace.gas) expect(berlinTrace.gas).to.be.gt(preBerlinTrace.gas)
...@@ -173,8 +174,9 @@ describe('Hard forks', () => { ...@@ -173,8 +174,9 @@ describe('Hard forks', () => {
) )
const preBerlinTrace = await env.l2Provider.send( const preBerlinTrace = await env.l2Provider.send(
'debug_traceTransaction', 'debug_traceTransaction',
[tx.hash, { overrides: { berlinBlock: tip.number + 10 } }] [tx.hash, { overrides: { berlinBlock: tip.number * 2 } }]
) )
// Updating to a zero value from a non zero value should becomes // Updating to a zero value from a non zero value should becomes
// more expensive due to this change being coupled with EIP-2929 // more expensive due to this change being coupled with EIP-2929
expect(berlinTrace.gas).to.be.gt(preBerlinTrace.gas) expect(berlinTrace.gas).to.be.gt(preBerlinTrace.gas)
...@@ -194,7 +196,7 @@ describe('Hard forks', () => { ...@@ -194,7 +196,7 @@ describe('Hard forks', () => {
) )
const preBerlinTrace = await env.l2Provider.send( const preBerlinTrace = await env.l2Provider.send(
'debug_traceTransaction', 'debug_traceTransaction',
[tx.hash, { overrides: { berlinBlock: tip.number + 10 } }] [tx.hash, { overrides: { berlinBlock: tip.number * 2 } }]
) )
// The berlin execution should use more gas than the pre Berlin // The berlin execution should use more gas than the pre Berlin
......
...@@ -93,6 +93,9 @@ const procEnv = cleanEnv(process.env, { ...@@ -93,6 +93,9 @@ const procEnv = cleanEnv(process.env, {
RUN_STRESS_TESTS: bool({ RUN_STRESS_TESTS: bool({
default: true, default: true,
}), }),
RUN_NIGHTLY_TESTS: bool({
default: false,
}),
MOCHA_TIMEOUT: num({ MOCHA_TIMEOUT: num({
default: 120_000, default: 120_000,
......
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