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
8c70da44
Unverified
Commit
8c70da44
authored
May 27, 2021
by
Kelvin Fichter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat[integration-tests]: add new basic stress tests
parent
0d6ec566
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
465 additions
and
0 deletions
+465
-0
SimpleStorage.sol
integration-tests/contracts/SimpleStorage.sol
+6
-0
env.ts
integration-tests/test/shared/env.ts
+2
-0
stress-test-helpers.ts
integration-tests/test/shared/stress-test-helpers.ts
+215
-0
stress-tests.spec.ts
integration-tests/test/stress-tests.spec.ts
+242
-0
No files found.
integration-tests/contracts/SimpleStorage.sol
View file @
8c70da44
...
@@ -18,6 +18,12 @@ contract SimpleStorage {
...
@@ -18,6 +18,12 @@ contract SimpleStorage {
totalCount++;
totalCount++;
}
}
function setValueNotXDomain(bytes32 newValue) public {
msgSender = msg.sender;
value = newValue;
totalCount++;
}
function dumbSetValue(bytes32 newValue) public {
function dumbSetValue(bytes32 newValue) public {
value = newValue;
value = newValue;
}
}
...
...
integration-tests/test/shared/env.ts
View file @
8c70da44
...
@@ -170,6 +170,8 @@ export class OptimismEnv {
...
@@ -170,6 +170,8 @@ export class OptimismEnv {
}
catch
(
err
)
{
}
catch
(
err
)
{
if
(
err
.
message
.
includes
(
'
execution failed due to an exception
'
))
{
if
(
err
.
message
.
includes
(
'
execution failed due to an exception
'
))
{
await
sleep
(
5000
)
await
sleep
(
5000
)
}
else
if
(
err
.
message
.
includes
(
'
Nonce too low
'
))
{
await
sleep
(
5000
)
}
else
if
(
}
else
if
(
err
.
message
.
includes
(
'
message has already been received
'
)
err
.
message
.
includes
(
'
message has already been received
'
)
)
{
)
{
...
...
integration-tests/test/shared/stress-test-helpers.ts
0 → 100644
View file @
8c70da44
/* Imports: External */
import
{
ethers
}
from
'
ethers
'
/* Imports: Internal */
import
{
OptimismEnv
}
from
'
./env
'
import
{
Direction
}
from
'
./watcher-utils
'
interface
TransactionParams
{
contract
:
ethers
.
Contract
functionName
:
string
functionParams
:
any
[]
}
// Arbitrary big amount of gas for the L1<>L2 messages.
const
MESSAGE_GAS
=
8
_000_000
export
const
executeL1ToL2Transactions
=
async
(
env
:
OptimismEnv
,
txs
:
TransactionParams
[]
)
=>
{
for
(
const
tx
of
txs
)
{
const
signer
=
ethers
.
Wallet
.
createRandom
().
connect
(
env
.
l1Wallet
.
provider
)
const
receipt
=
await
env
.
l1Messenger
.
connect
(
signer
)
.
sendMessage
(
tx
.
contract
.
address
,
tx
.
contract
.
interface
.
encodeFunctionData
(
tx
.
functionName
,
tx
.
functionParams
),
MESSAGE_GAS
,
{
gasPrice
:
0
,
}
)
await
env
.
waitForXDomainTransaction
(
receipt
,
Direction
.
L1ToL2
)
}
}
export
const
executeL2ToL1Transactions
=
async
(
env
:
OptimismEnv
,
txs
:
TransactionParams
[]
)
=>
{
for
(
const
tx
of
txs
)
{
const
signer
=
ethers
.
Wallet
.
createRandom
().
connect
(
env
.
l2Wallet
.
provider
)
const
receipt
=
await
env
.
l2Messenger
.
connect
(
signer
)
.
sendMessage
(
tx
.
contract
.
address
,
tx
.
contract
.
interface
.
encodeFunctionData
(
tx
.
functionName
,
tx
.
functionParams
),
MESSAGE_GAS
,
{
gasPrice
:
0
,
}
)
await
env
.
relayXDomainMessages
(
receipt
)
await
env
.
waitForXDomainTransaction
(
receipt
,
Direction
.
L2ToL1
)
}
}
export
const
executeL2Transactions
=
async
(
env
:
OptimismEnv
,
txs
:
TransactionParams
[]
)
=>
{
for
(
const
tx
of
txs
)
{
const
signer
=
ethers
.
Wallet
.
createRandom
().
connect
(
env
.
l2Wallet
.
provider
)
const
result
=
await
tx
.
contract
.
connect
(
signer
)
.
functions
[
tx
.
functionName
](...
tx
.
functionParams
,
{
gasPrice
:
0
,
})
await
result
.
wait
()
}
}
export
const
executeRepeatedL1ToL2Transactions
=
async
(
env
:
OptimismEnv
,
tx
:
TransactionParams
,
count
:
number
)
=>
{
await
executeL1ToL2Transactions
(
env
,
[...
Array
(
count
).
keys
()].
map
(()
=>
tx
)
)
}
export
const
executeRepeatedL2ToL1Transactions
=
async
(
env
:
OptimismEnv
,
tx
:
TransactionParams
,
count
:
number
)
=>
{
await
executeL2ToL1Transactions
(
env
,
[...
Array
(
count
).
keys
()].
map
(()
=>
tx
)
)
}
export
const
executeRepeatedL2Transactions
=
async
(
env
:
OptimismEnv
,
tx
:
TransactionParams
,
count
:
number
)
=>
{
await
executeL2Transactions
(
env
,
[...
Array
(
count
).
keys
()].
map
(()
=>
tx
)
)
}
export
const
executeL1ToL2TransactionsParallel
=
async
(
env
:
OptimismEnv
,
txs
:
TransactionParams
[]
)
=>
{
await
Promise
.
all
(
txs
.
map
(
async
(
tx
)
=>
{
const
signer
=
ethers
.
Wallet
.
createRandom
().
connect
(
env
.
l1Wallet
.
provider
)
const
receipt
=
await
env
.
l1Messenger
.
connect
(
signer
)
.
sendMessage
(
tx
.
contract
.
address
,
tx
.
contract
.
interface
.
encodeFunctionData
(
tx
.
functionName
,
tx
.
functionParams
),
MESSAGE_GAS
,
{
gasPrice
:
0
,
}
)
await
env
.
waitForXDomainTransaction
(
receipt
,
Direction
.
L1ToL2
)
})
)
}
export
const
executeL2ToL1TransactionsParallel
=
async
(
env
:
OptimismEnv
,
txs
:
TransactionParams
[]
)
=>
{
await
Promise
.
all
(
txs
.
map
(
async
(
tx
)
=>
{
const
signer
=
ethers
.
Wallet
.
createRandom
().
connect
(
env
.
l2Wallet
.
provider
)
const
receipt
=
await
env
.
l2Messenger
.
connect
(
signer
)
.
sendMessage
(
tx
.
contract
.
address
,
tx
.
contract
.
interface
.
encodeFunctionData
(
tx
.
functionName
,
tx
.
functionParams
),
MESSAGE_GAS
,
{
gasPrice
:
0
,
}
)
await
env
.
relayXDomainMessages
(
receipt
)
await
env
.
waitForXDomainTransaction
(
receipt
,
Direction
.
L2ToL1
)
})
)
}
export
const
executeL2TransactionsParallel
=
async
(
env
:
OptimismEnv
,
txs
:
TransactionParams
[]
)
=>
{
await
Promise
.
all
(
txs
.
map
(
async
(
tx
)
=>
{
const
signer
=
ethers
.
Wallet
.
createRandom
().
connect
(
env
.
l2Wallet
.
provider
)
const
result
=
await
tx
.
contract
.
connect
(
signer
)
.
functions
[
tx
.
functionName
](...
tx
.
functionParams
,
{
gasPrice
:
0
,
})
await
result
.
wait
()
})
)
}
export
const
executeRepeatedL1ToL2TransactionsParallel
=
async
(
env
:
OptimismEnv
,
tx
:
TransactionParams
,
count
:
number
)
=>
{
await
executeL1ToL2TransactionsParallel
(
env
,
[...
Array
(
count
).
keys
()].
map
(()
=>
tx
)
)
}
export
const
executeRepeatedL2ToL1TransactionsParallel
=
async
(
env
:
OptimismEnv
,
tx
:
TransactionParams
,
count
:
number
)
=>
{
await
executeL2ToL1TransactionsParallel
(
env
,
[...
Array
(
count
).
keys
()].
map
(()
=>
tx
)
)
}
export
const
executeRepeatedL2TransactionsParallel
=
async
(
env
:
OptimismEnv
,
tx
:
TransactionParams
,
count
:
number
)
=>
{
await
executeL2TransactionsParallel
(
env
,
[...
Array
(
count
).
keys
()].
map
(()
=>
tx
)
)
}
integration-tests/test/stress-tests.spec.ts
0 → 100644
View file @
8c70da44
import
{
expect
}
from
'
chai
'
/* Imports: External */
import
{
Contract
,
ContractFactory
}
from
'
ethers
'
/* Imports: Internal */
import
{
OptimismEnv
}
from
'
./shared/env
'
import
{
executeRepeatedL1ToL2Transactions
,
executeRepeatedL2ToL1Transactions
,
executeRepeatedL2Transactions
,
executeRepeatedL1ToL2TransactionsParallel
,
executeRepeatedL2ToL1TransactionsParallel
,
executeRepeatedL2TransactionsParallel
,
}
from
'
./shared/stress-test-helpers
'
/* Imports: Artifacts */
import
l1SimpleStorageJson
from
'
../artifacts/contracts/SimpleStorage.sol/SimpleStorage.json
'
import
l2SimpleStorageJson
from
'
../artifacts-ovm/contracts/SimpleStorage.sol/SimpleStorage.json
'
// Need a big timeout to allow for all transactions to be processed.
// For some reason I can't figure out how to set the timeout on a per-suite basis
// so I'm instead setting it for every test.
const
STRESS_TEST_TIMEOUT
=
300
_000
describe
(
'
stress tests
'
,
()
=>
{
let
env
:
OptimismEnv
before
(
async
()
=>
{
env
=
await
OptimismEnv
.
new
()
})
let
L2SimpleStorage
:
Contract
let
L1SimpleStorage
:
Contract
beforeEach
(
async
()
=>
{
const
factory__L1SimpleStorage
=
new
ContractFactory
(
l1SimpleStorageJson
.
abi
,
l1SimpleStorageJson
.
bytecode
,
env
.
l1Wallet
)
const
factory__L2SimpleStorage
=
new
ContractFactory
(
l2SimpleStorageJson
.
abi
,
l2SimpleStorageJson
.
bytecode
,
env
.
l2Wallet
)
L1SimpleStorage
=
await
factory__L1SimpleStorage
.
deploy
()
await
L1SimpleStorage
.
deployTransaction
.
wait
()
L2SimpleStorage
=
await
factory__L2SimpleStorage
.
deploy
()
await
L2SimpleStorage
.
deployTransaction
.
wait
()
})
describe
(
'
L1 => L2 stress tests
'
,
()
=>
{
const
numTransactions
=
10
it
(
`
${
numTransactions
}
L1 => L2 transactions (serial)`
,
async
()
=>
{
await
executeRepeatedL1ToL2Transactions
(
env
,
{
contract
:
L2SimpleStorage
,
functionName
:
'
setValue
'
,
functionParams
:
[
`0x
${
'
42
'
.
repeat
(
32
)}
`
],
},
numTransactions
)
expect
((
await
L2SimpleStorage
.
totalCount
()).
toNumber
()).
to
.
equal
(
numTransactions
)
}).
timeout
(
STRESS_TEST_TIMEOUT
)
it
(
`
${
numTransactions
}
L1 => L2 transactions (parallel)`
,
async
()
=>
{
await
executeRepeatedL1ToL2TransactionsParallel
(
env
,
{
contract
:
L2SimpleStorage
,
functionName
:
'
setValue
'
,
functionParams
:
[
`0x
${
'
42
'
.
repeat
(
32
)}
`
],
},
numTransactions
)
expect
((
await
L2SimpleStorage
.
totalCount
()).
toNumber
()).
to
.
equal
(
numTransactions
)
}).
timeout
(
STRESS_TEST_TIMEOUT
)
})
describe
(
'
L2 => L1 stress tests
'
,
()
=>
{
const
numTransactions
=
10
it
(
`
${
numTransactions
}
L2 => L1 transactions (serial)`
,
async
()
=>
{
await
executeRepeatedL2ToL1Transactions
(
env
,
{
contract
:
L1SimpleStorage
,
functionName
:
'
setValue
'
,
functionParams
:
[
`0x
${
'
42
'
.
repeat
(
32
)}
`
],
},
numTransactions
)
expect
((
await
L1SimpleStorage
.
totalCount
()).
toNumber
()).
to
.
equal
(
numTransactions
)
}).
timeout
(
STRESS_TEST_TIMEOUT
)
it
(
`
${
numTransactions
}
L2 => L1 transactions (parallel)`
,
async
()
=>
{
await
executeRepeatedL2ToL1TransactionsParallel
(
env
,
{
contract
:
L1SimpleStorage
,
functionName
:
'
setValue
'
,
functionParams
:
[
`0x
${
'
42
'
.
repeat
(
32
)}
`
],
},
numTransactions
)
expect
((
await
L1SimpleStorage
.
totalCount
()).
toNumber
()).
to
.
equal
(
numTransactions
)
}).
timeout
(
STRESS_TEST_TIMEOUT
)
})
describe
(
'
L2 transaction stress tests
'
,
()
=>
{
const
numTransactions
=
10
it
(
`
${
numTransactions
}
L2 transactions (serial)`
,
async
()
=>
{
await
executeRepeatedL2Transactions
(
env
,
{
contract
:
L2SimpleStorage
,
functionName
:
'
setValueNotXDomain
'
,
functionParams
:
[
`0x
${
'
42
'
.
repeat
(
32
)}
`
],
},
numTransactions
)
expect
((
await
L2SimpleStorage
.
totalCount
()).
toNumber
()).
to
.
equal
(
numTransactions
)
}).
timeout
(
STRESS_TEST_TIMEOUT
)
it
(
`
${
numTransactions
}
L2 transactions (parallel)`
,
async
()
=>
{
await
executeRepeatedL2TransactionsParallel
(
env
,
{
contract
:
L2SimpleStorage
,
functionName
:
'
setValueNotXDomain
'
,
functionParams
:
[
`0x
${
'
42
'
.
repeat
(
32
)}
`
],
},
numTransactions
)
expect
((
await
L2SimpleStorage
.
totalCount
()).
toNumber
()).
to
.
equal
(
numTransactions
)
}).
timeout
(
STRESS_TEST_TIMEOUT
)
})
describe
(
'
C-C-C-Combo breakers
'
,
()
=>
{
const
numTransactions
=
10
it
(
`
${
numTransactions
}
L2 transactions, L1 => L2 transactions, L2 => L1 transactions (txs serial, suites parallel)`
,
async
()
=>
{
await
Promise
.
all
([
executeRepeatedL1ToL2Transactions
(
env
,
{
contract
:
L2SimpleStorage
,
functionName
:
'
setValue
'
,
functionParams
:
[
`0x
${
'
42
'
.
repeat
(
32
)}
`
],
},
numTransactions
),
executeRepeatedL2ToL1Transactions
(
env
,
{
contract
:
L1SimpleStorage
,
functionName
:
'
setValue
'
,
functionParams
:
[
`0x
${
'
42
'
.
repeat
(
32
)}
`
],
},
numTransactions
),
executeRepeatedL2Transactions
(
env
,
{
contract
:
L2SimpleStorage
,
functionName
:
'
setValueNotXDomain
'
,
functionParams
:
[
`0x
${
'
42
'
.
repeat
(
32
)}
`
],
},
numTransactions
),
])
expect
((
await
L2SimpleStorage
.
totalCount
()).
toNumber
()).
to
.
equal
(
numTransactions
*
2
)
expect
((
await
L1SimpleStorage
.
totalCount
()).
toNumber
()).
to
.
equal
(
numTransactions
)
}).
timeout
(
STRESS_TEST_TIMEOUT
)
it
(
`
${
numTransactions
}
L2 transactions, L1 => L2 transactions, L2 => L1 transactions (all parallel)`
,
async
()
=>
{
await
Promise
.
all
([
executeRepeatedL1ToL2TransactionsParallel
(
env
,
{
contract
:
L2SimpleStorage
,
functionName
:
'
setValue
'
,
functionParams
:
[
`0x
${
'
42
'
.
repeat
(
32
)}
`
],
},
numTransactions
),
executeRepeatedL2ToL1TransactionsParallel
(
env
,
{
contract
:
L1SimpleStorage
,
functionName
:
'
setValue
'
,
functionParams
:
[
`0x
${
'
42
'
.
repeat
(
32
)}
`
],
},
numTransactions
),
executeRepeatedL2TransactionsParallel
(
env
,
{
contract
:
L2SimpleStorage
,
functionName
:
'
setValueNotXDomain
'
,
functionParams
:
[
`0x
${
'
42
'
.
repeat
(
32
)}
`
],
},
numTransactions
),
])
expect
((
await
L2SimpleStorage
.
totalCount
()).
toNumber
()).
to
.
equal
(
numTransactions
*
2
)
expect
((
await
L1SimpleStorage
.
totalCount
()).
toNumber
()).
to
.
equal
(
numTransactions
)
}).
timeout
(
STRESS_TEST_TIMEOUT
)
})
})
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