Skip to content

Commit e74604e

Browse files
authored
AA-21: gas usage tests for different batch scenarios (eth-infinitism#93)
use with "yarn gas-checker" currently deploys batches of 1,2,20,21, and display the gas diff
1 parent 5fd84aa commit e74604e

File tree

12 files changed

+727
-600
lines changed

12 files changed

+727
-600
lines changed

gascalc/0-init-gas-checker.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { GasCheckCollector, GasChecker } from './GasChecker'
2+
3+
describe('gas calculations', function () {
4+
this.timeout(60000)
5+
const g = new GasChecker()
6+
7+
it('warmup', async function () {
8+
await GasCheckCollector.init()
9+
// dummy run - first run is slower.
10+
await g.runTest({ title: 'simple', count: 1, diffLastGas: false })
11+
})
12+
})

gascalc/1-simple-wallet.gas.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { GasChecker } from './GasChecker'
2+
3+
context('simple wallet', function () {
4+
this.timeout(60000)
5+
const g = new GasChecker()
6+
7+
it('simple 1', async function () {
8+
await g.addTestRow({ title: 'simple', count: 1, diffLastGas: false })
9+
await g.addTestRow({ title: 'simple - diff from previous', count: 2, diffLastGas: true })
10+
})
11+
12+
it('simple 20', async function () {
13+
if (g.skipLong()) this.skip()
14+
await g.addTestRow({ title: 'simple', count: 20, diffLastGas: false })
15+
await g.addTestRow({ title: 'simple - diff from previous', count: 21, diffLastGas: true })
16+
})
17+
})

gascalc/2-paymaster.gas.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { parseEther } from 'ethers/lib/utils'
2+
import { TestPaymasterAcceptAll__factory } from '../typechain'
3+
import { ethers } from 'hardhat'
4+
import { GasChecker } from './GasChecker'
5+
6+
const ethersSigner = ethers.provider.getSigner()
7+
8+
context('Minimal Paymaster', function () {
9+
this.timeout(60000)
10+
const g = new GasChecker()
11+
12+
let paymasterAddress: string
13+
before(async () => {
14+
const paymaster = await new TestPaymasterAcceptAll__factory(ethersSigner).deploy(g.entryPoint().address)
15+
paymasterAddress = paymaster.address
16+
await paymaster.addStake(0, { value: 1 })
17+
await g.entryPoint().depositTo(paymaster.address, { value: parseEther('10') })
18+
})
19+
it('simple paymaster', async function () {
20+
await g.addTestRow({ title: 'simple paymaster', count: 1, paymaster: paymasterAddress, diffLastGas: false })
21+
await g.addTestRow({
22+
title: 'simple paymaster with diff',
23+
count: 2,
24+
paymaster: paymasterAddress,
25+
diffLastGas: true
26+
})
27+
})
28+
29+
it('simple paymaster 20', async function () {
30+
if (g.skipLong()) this.skip()
31+
32+
await g.addTestRow({ title: 'simple paymaster', count: 20, paymaster: paymasterAddress, diffLastGas: false })
33+
await g.addTestRow({
34+
title: 'simple paymaster with diff',
35+
count: 21,
36+
paymaster: paymasterAddress,
37+
diffLastGas: true
38+
})
39+
})
40+
})

gascalc/3-huge-tx-gas.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { DefaultGasTestInfo, GasChecker } from './GasChecker'
2+
3+
context('huge tx', function () {
4+
this.timeout(60000)
5+
const huge = DefaultGasTestInfo.destCallData!.padEnd(20480, 'f')
6+
const g = new GasChecker()
7+
8+
it('big tx', async () => {
9+
await g.addTestRow({ title: 'big tx 10k', count: 1, destCallData: huge, diffLastGas: false })
10+
await g.addTestRow({ title: 'big tx - diff from previous', count: 2, destCallData: huge, diffLastGas: true })
11+
})
12+
it('big tx 20', async function () {
13+
if (g.skipLong()) this.skip()
14+
await g.addTestRow({ title: 'big tx', count: 20, destCallData: huge, diffLastGas: false })
15+
await g.addTestRow({ title: 'big tx - diff from previous', count: 21, destCallData: huge, diffLastGas: true })
16+
})
17+
})

0 commit comments

Comments
 (0)