Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
51ee302a
Commit
51ee302a
authored
Oct 15, 2020
by
Kelvin Fichter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Linted files
parent
d37dc769
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
146 additions
and
117 deletions
+146
-117
OVM_CanonicalTransactionChain.spec.ts
...contracts/OVM/chain/OVM_CanonicalTransactionChain.spec.ts
+146
-117
No files found.
packages/contracts/test/contracts/OVM/chain/OVM_CanonicalTransactionChain.spec.ts
View file @
51ee302a
...
@@ -3,7 +3,7 @@ import { expect } from '../../../setup'
...
@@ -3,7 +3,7 @@ import { expect } from '../../../setup'
/* External Imports */
/* External Imports */
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
Signer
,
ContractFactory
,
Contract
,
BigNumber
}
from
'
ethers
'
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
{
smockit
,
MockContract
}
from
'
@eth-optimism/smock
'
import
_
from
'
lodash
'
import
_
from
'
lodash
'
...
@@ -59,25 +59,34 @@ interface BatchContext {
...
@@ -59,25 +59,34 @@ interface BatchContext {
}
}
interface
AppendSequencerBatchParams
{
interface
AppendSequencerBatchParams
{
shouldStartAtBatch
:
number
,
// 5 bytes -- starts at batch
shouldStartAtBatch
:
number
// 5 bytes -- starts at batch
totalElementsToAppend
:
number
,
// 3 bytes -- total_elements_to_append
totalElementsToAppend
:
number
// 3 bytes -- total_elements_to_append
contexts
:
BatchContext
[]
,
// total_elements[fixed_size[]]
contexts
:
BatchContext
[]
// total_elements[fixed_size[]]
transactions
:
string
[]
// total_size_bytes[],total_size_bytes[]
transactions
:
string
[]
// total_size_bytes[],total_size_bytes[]
}
}
const
encodeAppendSequencerBatch
=
(
const
encodeAppendSequencerBatch
=
(
b
:
AppendSequencerBatchParams
):
string
=>
{
b
:
AppendSequencerBatchParams
):
string
=>
{
let
encoding
:
string
let
encoding
:
string
const
encodedShouldStartAtBatch
=
remove0x
(
BigNumber
.
from
(
b
.
shouldStartAtBatch
).
toHexString
()).
padStart
(
10
,
'
0
'
)
const
encodedShouldStartAtBatch
=
remove0x
(
const
encodedTotalElementsToAppend
=
remove0x
(
BigNumber
.
from
(
b
.
totalElementsToAppend
).
toHexString
()).
padStart
(
6
,
'
0
'
)
BigNumber
.
from
(
b
.
shouldStartAtBatch
).
toHexString
()
).
padStart
(
10
,
'
0
'
)
const
encodedContextsHeader
=
remove0x
(
BigNumber
.
from
(
b
.
contexts
.
length
).
toHexString
()).
padStart
(
6
,
'
0
'
)
const
encodedTotalElementsToAppend
=
remove0x
(
const
encodedContexts
=
encodedContextsHeader
+
b
.
contexts
.
reduce
((
acc
,
cur
)
=>
acc
+
encodeBatchContext
(
cur
),
''
)
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
)
=>
{
const
encodedTransactionData
=
b
.
transactions
.
reduce
((
acc
,
cur
)
=>
{
if
(
cur
.
length
%
2
!==
0
)
throw
new
Error
(
'
Unexpected uneven hex string value!
'
)
if
(
cur
.
length
%
2
!==
0
)
const
encodedTxDataHeader
=
remove0x
(
BigNumber
.
from
(
remove0x
(
cur
).
length
/
2
).
toHexString
()).
padStart
(
6
,
'
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
acc
+
encodedTxDataHeader
+
remove0x
(
cur
)
},
''
)
},
''
)
return
(
return
(
...
@@ -92,20 +101,30 @@ const appendSequencerBatch = async (
...
@@ -92,20 +101,30 @@ const appendSequencerBatch = async (
OVM_CanonicalTransactionChain
:
Contract
,
OVM_CanonicalTransactionChain
:
Contract
,
batch
:
AppendSequencerBatchParams
batch
:
AppendSequencerBatchParams
):
Promise
<
TransactionResponse
>
=>
{
):
Promise
<
TransactionResponse
>
=>
{
const
methodId
=
keccak256
(
Buffer
.
from
(
'
appendSequencerBatch()
'
)).
slice
(
2
,
10
)
const
methodId
=
keccak256
(
Buffer
.
from
(
'
appendSequencerBatch()
'
)).
slice
(
2
,
10
)
const
calldata
=
encodeAppendSequencerBatch
(
batch
)
const
calldata
=
encodeAppendSequencerBatch
(
batch
)
return
OVM_CanonicalTransactionChain
.
signer
.
sendTransaction
({
return
OVM_CanonicalTransactionChain
.
signer
.
sendTransaction
({
to
:
OVM_CanonicalTransactionChain
.
address
,
to
:
OVM_CanonicalTransactionChain
.
address
,
data
:
'
0x
'
+
methodId
+
calldata
,
data
:
'
0x
'
+
methodId
+
calldata
,
})
})
}
}
const
encodeBatchContext
=
(
context
:
BatchContext
):
string
=>
{
const
encodeBatchContext
=
(
context
:
BatchContext
):
string
=>
{
return
(
return
(
remove0x
(
BigNumber
.
from
(
context
.
numSequencedTransactions
).
toHexString
()).
padStart
(
6
,
'
0
'
)
+
remove0x
(
remove0x
(
BigNumber
.
from
(
context
.
numSubsequentQueueTransactions
).
toHexString
()).
padStart
(
6
,
'
0
'
)
+
BigNumber
.
from
(
context
.
numSequencedTransactions
).
toHexString
()
remove0x
(
BigNumber
.
from
(
context
.
timestamp
).
toHexString
()).
padStart
(
10
,
'
0
'
)
+
).
padStart
(
6
,
'
0
'
)
+
remove0x
(
BigNumber
.
from
(
context
.
blockNumber
).
toHexString
()).
padStart
(
10
,
'
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', () => {
...
@@ -193,8 +212,7 @@ describe('OVM_CanonicalTransactionChain', () => {
await
expect
(
await
expect
(
OVM_CanonicalTransactionChain
.
enqueue
(
target
,
gasLimit
,
data
)
OVM_CanonicalTransactionChain
.
enqueue
(
target
,
gasLimit
,
data
)
)
).
to
.
emit
(
OVM_CanonicalTransactionChain
,
'
TransactionEnqueued
'
)
.
to
.
emit
(
OVM_CanonicalTransactionChain
,
'
TransactionEnqueued
'
)
})
})
describe
(
'
when enqueing multiple times
'
,
()
=>
{
describe
(
'
when enqueing multiple times
'
,
()
=>
{
...
@@ -447,7 +465,9 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -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
timestamp
=
(
await
getEthTime
(
ethers
.
provider
))
-
100
const
blockNumber
=
(
await
getNextBlockNumber
(
ethers
.
provider
))
+
100
const
blockNumber
=
(
await
getNextBlockNumber
(
ethers
.
provider
))
+
100
...
@@ -483,7 +503,9 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -483,7 +503,9 @@ describe('OVM_CanonicalTransactionChain', () => {
const
transactions
=
[]
const
transactions
=
[]
const
numTxs
=
200
const
numTxs
=
200
for
(
let
i
=
0
;
i
<
numTxs
;
i
++
)
{
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
,
{
const
res
=
await
appendSequencerBatch
(
OVM_CanonicalTransactionChain
,
{
shouldStartAtBatch
:
2
,
shouldStartAtBatch
:
2
,
...
@@ -499,8 +521,9 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -499,8 +521,9 @@ describe('OVM_CanonicalTransactionChain', () => {
transactions
,
transactions
,
})
})
const
receipt
=
await
res
.
wait
()
const
receipt
=
await
res
.
wait
()
console
.
log
(
"
Benchmark complete. Gas used:
"
,
receipt
.
gasUsed
)
console
.
log
(
'
Benchmark complete. Gas used:
'
,
receipt
.
gasUsed
)
}).
timeout
(
100000000
)
}
).
timeout
(
100000000
)
it
(
'
should revert if expected start does not match current total batches
'
,
async
()
=>
{
it
(
'
should revert if expected start does not match current total batches
'
,
async
()
=>
{
await
expect
(
await
expect
(
...
@@ -515,9 +538,9 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -515,9 +538,9 @@ describe('OVM_CanonicalTransactionChain', () => {
},
},
],
],
shouldStartAtBatch
:
1234
,
shouldStartAtBatch
:
1234
,
totalElementsToAppend
:
1
totalElementsToAppend
:
1
,
}
}
)
)
)
.
to
.
be
.
revertedWith
(
).
to
.
be
.
revertedWith
(
'
Actual batch start index does not match expected start index.
'
'
Actual batch start index does not match expected start index.
'
)
)
})
})
...
@@ -535,11 +558,9 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -535,11 +558,9 @@ describe('OVM_CanonicalTransactionChain', () => {
},
},
],
],
shouldStartAtBatch
:
0
,
shouldStartAtBatch
:
0
,
totalElementsToAppend
:
1
totalElementsToAppend
:
1
,
}
})
)).
to
.
be
.
revertedWith
(
).
to
.
be
.
revertedWith
(
'
Not all sequencer transactions were processed.
'
)
'
Not all sequencer transactions were processed.
'
)
})
})
it
(
'
should revert if not called by the sequencer
'
,
async
()
=>
{
it
(
'
should revert if not called by the sequencer
'
,
async
()
=>
{
...
@@ -555,9 +576,9 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -555,9 +576,9 @@ describe('OVM_CanonicalTransactionChain', () => {
},
},
],
],
shouldStartAtBatch
:
0
,
shouldStartAtBatch
:
0
,
totalElementsToAppend
:
1
totalElementsToAppend
:
1
,
}
}
)
)
)
.
to
.
be
.
revertedWith
(
'
Function can only be called by the Sequencer.
'
)
).
to
.
be
.
revertedWith
(
'
Function can only be called by the Sequencer.
'
)
})
})
it
(
'
should revert if no contexts are provided
'
,
async
()
=>
{
it
(
'
should revert if no contexts are provided
'
,
async
()
=>
{
...
@@ -566,7 +587,7 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -566,7 +587,7 @@ describe('OVM_CanonicalTransactionChain', () => {
transactions
:
[
'
0x1234
'
],
transactions
:
[
'
0x1234
'
],
contexts
:
[],
contexts
:
[],
shouldStartAtBatch
:
0
,
shouldStartAtBatch
:
0
,
totalElementsToAppend
:
1
totalElementsToAppend
:
1
,
})
})
).
to
.
be
.
revertedWith
(
'
Must provide at least one batch context.
'
)
).
to
.
be
.
revertedWith
(
'
Must provide at least one batch context.
'
)
})
})
...
@@ -575,16 +596,18 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -575,16 +596,18 @@ describe('OVM_CanonicalTransactionChain', () => {
await
expect
(
await
expect
(
appendSequencerBatch
(
OVM_CanonicalTransactionChain
,
{
appendSequencerBatch
(
OVM_CanonicalTransactionChain
,
{
transactions
:
[
'
0x1234
'
],
transactions
:
[
'
0x1234
'
],
contexts
:
[{
contexts
:
[
{
numSequencedTransactions
:
0
,
numSequencedTransactions
:
0
,
numSubsequentQueueTransactions
:
0
,
numSubsequentQueueTransactions
:
0
,
timestamp
:
0
,
timestamp
:
0
,
blockNumber
:
0
,
blockNumber
:
0
,
}],
},
],
shouldStartAtBatch
:
0
,
shouldStartAtBatch
:
0
,
totalElementsToAppend
:
0
totalElementsToAppend
:
0
,
}
}
)
)
)
.
to
.
be
.
revertedWith
(
'
Must append at least one element.
'
)
).
to
.
be
.
revertedWith
(
'
Must append at least one element.
'
)
})
})
for
(
const
size
of
ELEMENT_TEST_SIZES
)
{
for
(
const
size
of
ELEMENT_TEST_SIZES
)
{
...
@@ -604,7 +627,6 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -604,7 +627,6 @@ describe('OVM_CanonicalTransactionChain', () => {
await
expect
(
await
expect
(
appendSequencerBatch
(
OVM_CanonicalTransactionChain
,
{
appendSequencerBatch
(
OVM_CanonicalTransactionChain
,
{
transactions
:
[
'
0x1234
'
],
transactions
:
[
'
0x1234
'
],
contexts
:
[
contexts
:
[
{
{
...
@@ -615,7 +637,7 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -615,7 +637,7 @@ describe('OVM_CanonicalTransactionChain', () => {
},
},
],
],
shouldStartAtBatch
:
0
,
shouldStartAtBatch
:
0
,
totalElementsToAppend
:
1
totalElementsToAppend
:
1
,
})
})
).
to
.
be
.
revertedWith
(
).
to
.
be
.
revertedWith
(
'
Older queue batches must be processed before a new sequencer batch.
'
'
Older queue batches must be processed before a new sequencer batch.
'
...
@@ -637,9 +659,8 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -637,9 +659,8 @@ describe('OVM_CanonicalTransactionChain', () => {
},
},
],
],
shouldStartAtBatch
:
0
,
shouldStartAtBatch
:
0
,
totalElementsToAppend
:
1
totalElementsToAppend
:
1
,
}
})
)
).
to
.
be
.
revertedWith
(
'
Sequencer transactions timestamp too high.
'
)
).
to
.
be
.
revertedWith
(
'
Sequencer transactions timestamp too high.
'
)
})
})
...
@@ -659,9 +680,8 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -659,9 +680,8 @@ describe('OVM_CanonicalTransactionChain', () => {
},
},
],
],
shouldStartAtBatch
:
0
,
shouldStartAtBatch
:
0
,
totalElementsToAppend
:
1
totalElementsToAppend
:
1
,
}
})
)
).
to
.
be
.
revertedWith
(
'
Sequencer transactions blockNumber too high.
'
)
).
to
.
be
.
revertedWith
(
'
Sequencer transactions blockNumber too high.
'
)
})
})
...
@@ -694,10 +714,13 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -694,10 +714,13 @@ describe('OVM_CanonicalTransactionChain', () => {
transactions
,
transactions
,
contexts
,
contexts
,
shouldStartAtBatch
:
0
,
shouldStartAtBatch
:
0
,
totalElementsToAppend
:
size
totalElementsToAppend
:
size
,
})
})
)
)
.
to
.
emit
(
OVM_CanonicalTransactionChain
,
'
SequencerBatchAppended
'
)
.
to
.
emit
(
OVM_CanonicalTransactionChain
,
'
SequencerBatchAppended
'
)
.
withArgs
(
0
,
0
)
.
withArgs
(
0
,
0
)
})
})
})
})
...
@@ -742,11 +765,13 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -742,11 +765,13 @@ describe('OVM_CanonicalTransactionChain', () => {
transactions
,
transactions
,
contexts
,
contexts
,
shouldStartAtBatch
:
0
,
shouldStartAtBatch
:
0
,
totalElementsToAppend
:
size
*
2
totalElementsToAppend
:
size
*
2
,
}
}
)
)
)
.
to
.
emit
(
OVM_CanonicalTransactionChain
,
'
SequencerBatchAppended
'
)
)
.
to
.
emit
(
OVM_CanonicalTransactionChain
,
'
SequencerBatchAppended
'
)
.
withArgs
(
0
,
size
)
.
withArgs
(
0
,
size
)
})
})
})
})
...
@@ -783,10 +808,13 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -783,10 +808,13 @@ describe('OVM_CanonicalTransactionChain', () => {
transactions
,
transactions
,
contexts
,
contexts
,
shouldStartAtBatch
:
0
,
shouldStartAtBatch
:
0
,
totalElementsToAppend
:
size
+
spacing
totalElementsToAppend
:
size
+
spacing
,
})
})
)
)
.
to
.
emit
(
OVM_CanonicalTransactionChain
,
'
SequencerBatchAppended
'
)
.
to
.
emit
(
OVM_CanonicalTransactionChain
,
'
SequencerBatchAppended
'
)
.
withArgs
(
0
,
spacing
)
.
withArgs
(
0
,
spacing
)
})
})
})
})
...
@@ -819,14 +847,15 @@ describe('OVM_CanonicalTransactionChain', () => {
...
@@ -819,14 +847,15 @@ describe('OVM_CanonicalTransactionChain', () => {
return
'
0x
'
+
'
12
'
+
'
34
'
.
repeat
(
idx
)
return
'
0x
'
+
'
12
'
+
'
34
'
.
repeat
(
idx
)
})
})
await
appendSequencerBatch
(
OVM_CanonicalTransactionChain
.
connect
(
await
appendSequencerBatch
(
sequencer
OVM_CanonicalTransactionChain
.
connect
(
sequencer
),
),
{
{
transactions
,
transactions
,
contexts
,
contexts
,
shouldStartAtBatch
:
0
,
shouldStartAtBatch
:
0
,
totalElementsToAppend
:
size
totalElementsToAppend
:
size
,
})
}
)
})
})
it
(
`should return
${
size
}
`
,
async
()
=>
{
it
(
`should return
${
size
}
`
,
async
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment