Commit 51ee302a authored by Kelvin Fichter's avatar Kelvin Fichter

Linted files

parent d37dc769
......@@ -3,7 +3,7 @@ import { expect } from '../../../setup'
/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { Signer, ContractFactory, Contract, BigNumber } from 'ethers'
import { TransactionResponse } from "@ethersproject/abstract-provider";
import { TransactionResponse } from '@ethersproject/abstract-provider'
import { smockit, MockContract } from '@eth-optimism/smock'
import _ from 'lodash'
......@@ -59,25 +59,34 @@ interface BatchContext {
}
interface AppendSequencerBatchParams {
shouldStartAtBatch: number, // 5 bytes -- starts at batch
totalElementsToAppend: number, // 3 bytes -- total_elements_to_append
contexts: BatchContext[], // total_elements[fixed_size[]]
shouldStartAtBatch: number // 5 bytes -- starts at batch
totalElementsToAppend: number // 3 bytes -- total_elements_to_append
contexts: BatchContext[] // total_elements[fixed_size[]]
transactions: string[] // total_size_bytes[],total_size_bytes[]
}
const encodeAppendSequencerBatch = (
b: AppendSequencerBatchParams
): string => {
const encodeAppendSequencerBatch = (b: AppendSequencerBatchParams): string => {
let encoding: string
const encodedShouldStartAtBatch = remove0x(BigNumber.from(b.shouldStartAtBatch).toHexString()).padStart(10, '0')
const encodedTotalElementsToAppend = remove0x(BigNumber.from(b.totalElementsToAppend).toHexString()).padStart(6, '0')
const encodedContextsHeader = remove0x(BigNumber.from(b.contexts.length).toHexString()).padStart(6, '0')
const encodedContexts = encodedContextsHeader + b.contexts.reduce((acc, cur) => acc + encodeBatchContext(cur), '')
const encodedShouldStartAtBatch = remove0x(
BigNumber.from(b.shouldStartAtBatch).toHexString()
).padStart(10, '0')
const encodedTotalElementsToAppend = remove0x(
BigNumber.from(b.totalElementsToAppend).toHexString()
).padStart(6, '0')
const encodedContextsHeader = remove0x(
BigNumber.from(b.contexts.length).toHexString()
).padStart(6, '0')
const encodedContexts =
encodedContextsHeader +
b.contexts.reduce((acc, cur) => acc + encodeBatchContext(cur), '')
const encodedTransactionData = b.transactions.reduce((acc, cur) => {
if (cur.length % 2 !== 0) throw new Error('Unexpected uneven hex string value!')
const encodedTxDataHeader = remove0x(BigNumber.from(remove0x(cur).length/2).toHexString()).padStart(6, '0')
if (cur.length % 2 !== 0)
throw new Error('Unexpected uneven hex string value!')
const encodedTxDataHeader = remove0x(
BigNumber.from(remove0x(cur).length / 2).toHexString()
).padStart(6, '0')
return acc + encodedTxDataHeader + remove0x(cur)
}, '')
return (
......@@ -92,20 +101,30 @@ const appendSequencerBatch = async (
OVM_CanonicalTransactionChain: Contract,
batch: AppendSequencerBatchParams
): Promise<TransactionResponse> => {
const methodId = keccak256(Buffer.from('appendSequencerBatch()')).slice(2,10)
const methodId = keccak256(Buffer.from('appendSequencerBatch()')).slice(2, 10)
const calldata = encodeAppendSequencerBatch(batch)
return OVM_CanonicalTransactionChain.signer.sendTransaction({
to: OVM_CanonicalTransactionChain.address,
data:'0x' + methodId + calldata,
data: '0x' + methodId + calldata,
})
}
const encodeBatchContext = (context: BatchContext): string => {
return (
remove0x(BigNumber.from(context.numSequencedTransactions).toHexString()).padStart(6, '0') +
remove0x(BigNumber.from(context.numSubsequentQueueTransactions).toHexString()).padStart(6, '0') +
remove0x(BigNumber.from(context.timestamp).toHexString()).padStart(10, '0') +
remove0x(BigNumber.from(context.blockNumber).toHexString()).padStart(10, '0')
remove0x(
BigNumber.from(context.numSequencedTransactions).toHexString()
).padStart(6, '0') +
remove0x(
BigNumber.from(context.numSubsequentQueueTransactions).toHexString()
).padStart(6, '0') +
remove0x(BigNumber.from(context.timestamp).toHexString()).padStart(
10,
'0'
) +
remove0x(BigNumber.from(context.blockNumber).toHexString()).padStart(
10,
'0'
)
)
}
......@@ -193,8 +212,7 @@ describe('OVM_CanonicalTransactionChain', () => {
await expect(
OVM_CanonicalTransactionChain.enqueue(target, gasLimit, data)
)
.to.emit(OVM_CanonicalTransactionChain, 'TransactionEnqueued')
).to.emit(OVM_CanonicalTransactionChain, 'TransactionEnqueued')
})
describe('when enqueing multiple times', () => {
......@@ -447,7 +465,9 @@ describe('OVM_CanonicalTransactionChain', () => {
)
})
it.skip('should allow for a lower bound per-tx gas usage of <400 gas [GAS BENCHMARK]', async () => {
it.skip(
'should allow for a lower bound per-tx gas usage of <400 gas [GAS BENCHMARK]',
async () => {
const timestamp = (await getEthTime(ethers.provider)) - 100
const blockNumber = (await getNextBlockNumber(ethers.provider)) + 100
......@@ -483,7 +503,9 @@ describe('OVM_CanonicalTransactionChain', () => {
const transactions = []
const numTxs = 200
for (let i = 0; i < numTxs; i++) {
transactions.push('0x' + '1080111111111111111111111111111111111111111111'.repeat(20))
transactions.push(
'0x' + '1080111111111111111111111111111111111111111111'.repeat(20)
)
}
const res = await appendSequencerBatch(OVM_CanonicalTransactionChain, {
shouldStartAtBatch: 2,
......@@ -499,8 +521,9 @@ describe('OVM_CanonicalTransactionChain', () => {
transactions,
})
const receipt = await res.wait()
console.log("Benchmark complete. Gas used:", receipt.gasUsed)
}).timeout(100000000)
console.log('Benchmark complete. Gas used:', receipt.gasUsed)
}
).timeout(100000000)
it('should revert if expected start does not match current total batches', async () => {
await expect(
......@@ -515,9 +538,9 @@ describe('OVM_CanonicalTransactionChain', () => {
},
],
shouldStartAtBatch: 1234,
totalElementsToAppend: 1
}
)).to.be.revertedWith(
totalElementsToAppend: 1,
})
).to.be.revertedWith(
'Actual batch start index does not match expected start index.'
)
})
......@@ -535,11 +558,9 @@ describe('OVM_CanonicalTransactionChain', () => {
},
],
shouldStartAtBatch: 0,
totalElementsToAppend: 1
}
)).to.be.revertedWith(
'Not all sequencer transactions were processed.'
)
totalElementsToAppend: 1,
})
).to.be.revertedWith('Not all sequencer transactions were processed.')
})
it('should revert if not called by the sequencer', async () => {
......@@ -555,9 +576,9 @@ describe('OVM_CanonicalTransactionChain', () => {
},
],
shouldStartAtBatch: 0,
totalElementsToAppend: 1
}
)).to.be.revertedWith('Function can only be called by the Sequencer.')
totalElementsToAppend: 1,
})
).to.be.revertedWith('Function can only be called by the Sequencer.')
})
it('should revert if no contexts are provided', async () => {
......@@ -566,7 +587,7 @@ describe('OVM_CanonicalTransactionChain', () => {
transactions: ['0x1234'],
contexts: [],
shouldStartAtBatch: 0,
totalElementsToAppend: 1
totalElementsToAppend: 1,
})
).to.be.revertedWith('Must provide at least one batch context.')
})
......@@ -575,16 +596,18 @@ describe('OVM_CanonicalTransactionChain', () => {
await expect(
appendSequencerBatch(OVM_CanonicalTransactionChain, {
transactions: ['0x1234'],
contexts: [{
contexts: [
{
numSequencedTransactions: 0,
numSubsequentQueueTransactions: 0,
timestamp: 0,
blockNumber: 0,
}],
},
],
shouldStartAtBatch: 0,
totalElementsToAppend: 0
}
)).to.be.revertedWith('Must append at least one element.')
totalElementsToAppend: 0,
})
).to.be.revertedWith('Must append at least one element.')
})
for (const size of ELEMENT_TEST_SIZES) {
......@@ -604,7 +627,6 @@ describe('OVM_CanonicalTransactionChain', () => {
await expect(
appendSequencerBatch(OVM_CanonicalTransactionChain, {
transactions: ['0x1234'],
contexts: [
{
......@@ -615,7 +637,7 @@ describe('OVM_CanonicalTransactionChain', () => {
},
],
shouldStartAtBatch: 0,
totalElementsToAppend: 1
totalElementsToAppend: 1,
})
).to.be.revertedWith(
'Older queue batches must be processed before a new sequencer batch.'
......@@ -637,9 +659,8 @@ describe('OVM_CanonicalTransactionChain', () => {
},
],
shouldStartAtBatch: 0,
totalElementsToAppend: 1
}
)
totalElementsToAppend: 1,
})
).to.be.revertedWith('Sequencer transactions timestamp too high.')
})
......@@ -659,9 +680,8 @@ describe('OVM_CanonicalTransactionChain', () => {
},
],
shouldStartAtBatch: 0,
totalElementsToAppend: 1
}
)
totalElementsToAppend: 1,
})
).to.be.revertedWith('Sequencer transactions blockNumber too high.')
})
......@@ -694,10 +714,13 @@ describe('OVM_CanonicalTransactionChain', () => {
transactions,
contexts,
shouldStartAtBatch: 0,
totalElementsToAppend: size
totalElementsToAppend: size,
})
)
.to.emit(OVM_CanonicalTransactionChain, 'SequencerBatchAppended')
.to.emit(
OVM_CanonicalTransactionChain,
'SequencerBatchAppended'
)
.withArgs(0, 0)
})
})
......@@ -742,11 +765,13 @@ describe('OVM_CanonicalTransactionChain', () => {
transactions,
contexts,
shouldStartAtBatch: 0,
totalElementsToAppend: size * 2
}
totalElementsToAppend: size * 2,
})
)
.to.emit(
OVM_CanonicalTransactionChain,
'SequencerBatchAppended'
)
.to.emit(OVM_CanonicalTransactionChain, 'SequencerBatchAppended')
.withArgs(0, size)
})
})
......@@ -783,10 +808,13 @@ describe('OVM_CanonicalTransactionChain', () => {
transactions,
contexts,
shouldStartAtBatch: 0,
totalElementsToAppend: size + spacing
totalElementsToAppend: size + spacing,
})
)
.to.emit(OVM_CanonicalTransactionChain, 'SequencerBatchAppended')
.to.emit(
OVM_CanonicalTransactionChain,
'SequencerBatchAppended'
)
.withArgs(0, spacing)
})
})
......@@ -819,14 +847,15 @@ describe('OVM_CanonicalTransactionChain', () => {
return '0x' + '12' + '34'.repeat(idx)
})
await appendSequencerBatch(OVM_CanonicalTransactionChain.connect(
sequencer
), {
await appendSequencerBatch(
OVM_CanonicalTransactionChain.connect(sequencer),
{
transactions,
contexts,
shouldStartAtBatch: 0,
totalElementsToAppend: size
})
totalElementsToAppend: size,
}
)
})
it(`should return ${size}`, async () => {
......
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