Commit 7aec0958 authored by Maurelian's avatar Maurelian Committed by Kelvin Fichter

test(contracts): Add logs to calculate gas savings

The cost of running benchmarks was determined by running them on the contracts at regenesis/0.4.0 (98e02cfa/ PR #1148), then applied to the benchmarks here to calculate both absolute and relative amounts saed
parent 66bf56a6
......@@ -143,7 +143,18 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge', () => {
)
const receipt = await res.wait()
console.log(' - Gas used:', receipt.gasUsed.toNumber())
const gasUsed = receipt.gasUsed.toNumber()
const regenesis040Cost = 196_128
console.log(' - Gas used:', gasUsed)
console.log(
' - Absolute savings vs regenesis/0.4.0:',
regenesis040Cost - gasUsed
)
console.log(
' - Relative savings vs regenesis/0.4.0:',
(((regenesis040Cost - gasUsed) / regenesis040Cost) * 100).toFixed(2) +
'%'
)
// Sanity check that the message was enqueued.
expect(await CanonicalTransactionChain.getQueueLength()).to.equal(2)
})
......@@ -163,7 +174,19 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge', () => {
)
const receipt = await res.wait()
console.log(' - Gas used:', receipt.gasUsed.toNumber())
const gasUsed = receipt.gasUsed.toNumber()
const regenesis040Cost = 244_358
console.log(' - Gas used:', gasUsed)
console.log(
' - Absolute savings vs regenesis/0.4.0:',
regenesis040Cost - gasUsed
)
console.log(
' - Relative savings vs regenesis/0.4.0:',
(((regenesis040Cost - gasUsed) / regenesis040Cost) * 100).toFixed(2) +
'%'
)
// Sanity check that the message was enqueued.
expect(await CanonicalTransactionChain.getQueueLength()).to.equal(3)
})
......
......@@ -41,6 +41,19 @@ const appendSequencerBatch = async (
})
}
const printGasSavings = (gasUsed:number, regenesis040Cost:number):void => {
console.log(' - Gas used:', gasUsed)
console.log(
' - Absolute savings vs regenesis/0.4.0:',
regenesis040Cost - gasUsed
)
console.log(
' - Relative savings vs regenesis/0.4.0:',
(((regenesis040Cost - gasUsed) / regenesis040Cost) * 100).toFixed(2) +
'%'
)
}
describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
let sequencer: Signer
before(async () => {
......@@ -151,7 +164,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
const gasUsed = receipt.gasUsed.toNumber()
console.log('Benchmark complete.')
console.log('Gas used:', gasUsed)
printGasSavings(gasUsed, 1_616_390)
console.log('Fixed calldata cost:', fixedCalldataCost)
console.log(
......@@ -199,7 +212,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
const gasUsed = receipt.gasUsed.toNumber()
console.log('Benchmark complete.')
console.log('Gas used:', gasUsed)
printGasSavings(gasUsed, 1_787_052)
console.log('Fixed calldata cost:', fixedCalldataCost)
console.log(
......@@ -257,7 +270,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
const gasUsed = receipt.gasUsed.toNumber()
console.log('Benchmark complete.')
console.log('Gas used:', gasUsed)
printGasSavings(gasUsed, 2_099_387)
console.log('Fixed calldata cost:', fixedCalldataCost)
console.log(
......
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