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
9142149a
Unverified
Commit
9142149a
authored
Sep 23, 2021
by
Maurelian
Committed by
Kelvin Fichter
Nov 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: Move expectApprox to core-utils
parent
9c1443a4
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
78 additions
and
82 deletions
+78
-82
native-eth.spec.ts
integration-tests/test/native-eth.spec.ts
+2
-5
rpc.spec.ts
integration-tests/test/rpc.spec.ts
+1
-2
utils.ts
integration-tests/test/shared/utils.ts
+0
-36
CanonicalTransactionChain.gas.spec.ts
...contracts/L1/rollup/CanonicalTransactionChain.gas.spec.ts
+1
-1
gas.ts
packages/contracts/test/helpers/gas/gas.ts
+1
-38
index.ts
packages/core-utils/src/common/index.ts
+1
-0
test-utils.ts
packages/core-utils/src/common/test-utils.ts
+41
-0
test-utils.spec.ts
packages/core-utils/test/common/test-utils.spec.ts
+31
-0
No files found.
integration-tests/test/native-eth.spec.ts
View file @
9142149a
...
@@ -4,15 +4,12 @@ import { expect } from 'chai'
...
@@ -4,15 +4,12 @@ import { expect } from 'chai'
import
{
Wallet
,
utils
,
BigNumber
}
from
'
ethers
'
import
{
Wallet
,
utils
,
BigNumber
}
from
'
ethers
'
import
{
serialize
}
from
'
@ethersproject/transactions
'
import
{
serialize
}
from
'
@ethersproject/transactions
'
import
{
predeploys
}
from
'
@eth-optimism/contracts
'
import
{
predeploys
}
from
'
@eth-optimism/contracts
'
import
{
expectApprox
}
from
'
@eth-optimism/core-utils
'
/* Imports: Internal */
/* Imports: Internal */
import
{
Direction
}
from
'
./shared/watcher-utils
'
import
{
Direction
}
from
'
./shared/watcher-utils
'
import
{
import
{
fundUser
,
PROXY_SEQUENCER_ENTRYPOINT_ADDRESS
}
from
'
./shared/utils
'
expectApprox
,
fundUser
,
PROXY_SEQUENCER_ENTRYPOINT_ADDRESS
,
}
from
'
./shared/utils
'
import
{
OptimismEnv
,
useDynamicTimeoutForWithdrawals
}
from
'
./shared/env
'
import
{
OptimismEnv
,
useDynamicTimeoutForWithdrawals
}
from
'
./shared/env
'
const
DEFAULT_TEST_GAS_L1
=
330
_000
const
DEFAULT_TEST_GAS_L1
=
330
_000
...
...
integration-tests/test/rpc.spec.ts
View file @
9142149a
import
{
injectL2Context
}
from
'
@eth-optimism/core-utils
'
import
{
expectApprox
,
injectL2Context
}
from
'
@eth-optimism/core-utils
'
import
{
Wallet
,
BigNumber
,
Contract
,
ContractFactory
}
from
'
ethers
'
import
{
Wallet
,
BigNumber
,
Contract
,
ContractFactory
}
from
'
ethers
'
import
{
serialize
}
from
'
@ethersproject/transactions
'
import
{
serialize
}
from
'
@ethersproject/transactions
'
import
{
ethers
}
from
'
hardhat
'
import
{
ethers
}
from
'
hardhat
'
...
@@ -8,7 +8,6 @@ import {
...
@@ -8,7 +8,6 @@ import {
l2Provider
,
l2Provider
,
DEFAULT_TRANSACTION
,
DEFAULT_TRANSACTION
,
fundUser
,
fundUser
,
expectApprox
,
L2_CHAINID
,
L2_CHAINID
,
IS_LIVE_NETWORK
,
IS_LIVE_NETWORK
,
}
from
'
./shared/utils
'
}
from
'
./shared/utils
'
...
...
integration-tests/test/shared/utils.ts
View file @
9142149a
...
@@ -154,42 +154,6 @@ export const DEFAULT_TRANSACTION = {
...
@@ -154,42 +154,6 @@ export const DEFAULT_TRANSACTION = {
value
:
0
,
value
:
0
,
}
}
interface
percentDeviationRange
{
upperPercentDeviation
:
number
lowerPercentDeviation
?:
number
}
export
const
expectApprox
=
(
actual
:
BigNumber
|
number
,
target
:
BigNumber
|
number
,
{
upperPercentDeviation
,
lowerPercentDeviation
=
100
}:
percentDeviationRange
)
=>
{
actual
=
BigNumber
.
from
(
actual
)
target
=
BigNumber
.
from
(
target
)
const
validDeviations
=
upperPercentDeviation
>=
0
&&
upperPercentDeviation
<=
100
&&
lowerPercentDeviation
>=
0
&&
lowerPercentDeviation
<=
100
if
(
!
validDeviations
)
{
throw
new
Error
(
'
Upper and lower deviation percentage arguments should be between 0 and 100
'
)
}
const
upper
=
target
.
mul
(
100
+
upperPercentDeviation
).
div
(
100
)
const
lower
=
target
.
mul
(
100
-
lowerPercentDeviation
).
div
(
100
)
expect
(
actual
.
lte
(
upper
),
`Actual value (
${
actual
}
) is more than
${
upperPercentDeviation
}
% greater than target (
${
target
}
)`
).
to
.
be
.
true
expect
(
actual
.
gte
(
lower
),
`Actual value (
${
actual
}
) is more than
${
lowerPercentDeviation
}
% less than target (
${
target
}
)`
).
to
.
be
.
true
}
export
const
waitForL2Geth
=
async
(
export
const
waitForL2Geth
=
async
(
provider
:
providers
.
JsonRpcProvider
provider
:
providers
.
JsonRpcProvider
):
Promise
<
providers
.
JsonRpcProvider
>
=>
{
):
Promise
<
providers
.
JsonRpcProvider
>
=>
{
...
...
packages/contracts/test/contracts/L1/rollup/CanonicalTransactionChain.gas.spec.ts
View file @
9142149a
...
@@ -6,6 +6,7 @@ import {
...
@@ -6,6 +6,7 @@ import {
AppendSequencerBatchParams
,
AppendSequencerBatchParams
,
BatchContext
,
BatchContext
,
encodeAppendSequencerBatch
,
encodeAppendSequencerBatch
,
expectApprox
,
}
from
'
@eth-optimism/core-utils
'
}
from
'
@eth-optimism/core-utils
'
import
{
TransactionResponse
}
from
'
@ethersproject/abstract-provider
'
import
{
TransactionResponse
}
from
'
@ethersproject/abstract-provider
'
import
{
keccak256
}
from
'
ethers/lib/utils
'
import
{
keccak256
}
from
'
ethers/lib/utils
'
...
@@ -21,7 +22,6 @@ import {
...
@@ -21,7 +22,6 @@ import {
getEthTime
,
getEthTime
,
getNextBlockNumber
,
getNextBlockNumber
,
NON_ZERO_ADDRESS
,
NON_ZERO_ADDRESS
,
expectApprox
,
}
from
'
../../../helpers
'
}
from
'
../../../helpers
'
// Still have some duplication from CanonicalTransactionChain.spec.ts, but it's so minimal that
// Still have some duplication from CanonicalTransactionChain.spec.ts, but it's so minimal that
...
...
packages/contracts/test/helpers/gas/gas.ts
View file @
9142149a
import
{
expect
}
from
'
chai
'
import
{
ethers
}
from
'
hardhat
'
import
{
ethers
}
from
'
hardhat
'
import
{
BigNumber
,
Contract
,
Signer
}
from
'
ethers
'
import
{
Contract
,
Signer
}
from
'
ethers
'
export
class
GasMeasurement
{
export
class
GasMeasurement
{
GasMeasurementContract
:
Contract
GasMeasurementContract
:
Contract
...
@@ -25,39 +24,3 @@ export class GasMeasurement {
...
@@ -25,39 +24,3 @@ export class GasMeasurement {
return
gasCost
return
gasCost
}
}
}
}
interface
percentDeviationRange
{
upperPercentDeviation
:
number
lowerPercentDeviation
?:
number
}
export
const
expectApprox
=
(
actual
:
BigNumber
|
number
,
target
:
BigNumber
|
number
,
{
upperPercentDeviation
,
lowerPercentDeviation
=
100
}:
percentDeviationRange
):
void
=>
{
actual
=
BigNumber
.
from
(
actual
)
target
=
BigNumber
.
from
(
target
)
const
validDeviations
=
upperPercentDeviation
>=
0
&&
upperPercentDeviation
<=
100
&&
lowerPercentDeviation
>=
0
&&
lowerPercentDeviation
<=
100
if
(
!
validDeviations
)
{
throw
new
Error
(
'
Upper and lower deviation percentage arguments should be between 0 and 100
'
)
}
const
upper
=
target
.
mul
(
100
+
upperPercentDeviation
).
div
(
100
)
const
lower
=
target
.
mul
(
100
-
lowerPercentDeviation
).
div
(
100
)
expect
(
actual
.
lte
(
upper
),
`Actual value (
${
actual
}
) is more than
${
upperPercentDeviation
}
% greater than target (
${
target
}
)`
).
to
.
be
.
true
expect
(
actual
.
gte
(
lower
),
`Actual value (
${
actual
}
) is more than
${
lowerPercentDeviation
}
% less than target (
${
target
}
)`
).
to
.
be
.
true
}
packages/core-utils/src/common/index.ts
View file @
9142149a
export
*
from
'
./hex-strings
'
export
*
from
'
./hex-strings
'
export
*
from
'
./misc
'
export
*
from
'
./misc
'
export
*
from
'
./test-utils
'
packages/core-utils/src/common/test-utils.ts
0 → 100644
View file @
9142149a
import
{
expect
}
from
'
chai
'
import
{
BigNumber
}
from
'
ethers
'
interface
percentDeviationRange
{
upperPercentDeviation
:
number
lowerPercentDeviation
?:
number
}
/**
* Assert that a number lies within a custom defined range of the target.
*/
export
const
expectApprox
=
(
actual
:
BigNumber
|
number
,
target
:
BigNumber
|
number
,
{
upperPercentDeviation
,
lowerPercentDeviation
=
100
}:
percentDeviationRange
):
void
=>
{
actual
=
BigNumber
.
from
(
actual
)
target
=
BigNumber
.
from
(
target
)
const
validDeviations
=
upperPercentDeviation
>=
0
&&
upperPercentDeviation
<=
100
&&
lowerPercentDeviation
>=
0
&&
lowerPercentDeviation
<=
100
if
(
!
validDeviations
)
{
throw
new
Error
(
'
Upper and lower deviation percentage arguments should be between 0 and 100
'
)
}
const
upper
=
target
.
mul
(
100
+
upperPercentDeviation
).
div
(
100
)
const
lower
=
target
.
mul
(
100
-
lowerPercentDeviation
).
div
(
100
)
expect
(
actual
.
lte
(
upper
),
`Actual value (
${
actual
}
) is more than
${
upperPercentDeviation
}
% greater than target (
${
target
}
)`
).
to
.
be
.
true
expect
(
actual
.
gte
(
lower
),
`Actual value (
${
actual
}
) is more than
${
lowerPercentDeviation
}
% less than target (
${
target
}
)`
).
to
.
be
.
true
}
packages/core-utils/test/common/test-utils.spec.ts
0 → 100644
View file @
9142149a
import
{
expect
}
from
'
../setup
'
/* Imports: Internal */
import
{
expectApprox
}
from
'
../../src
'
describe
(
'
expectApprox
'
,
async
()
=>
{
it
(
'
should throw an error if the actual value is higher than expected
'
,
async
()
=>
{
try
{
expectApprox
(
121
,
100
,
{
upperPercentDeviation
:
20
,
})
}
catch
(
error
)
{
expect
(
error
.
message
).
to
.
equal
(
'
Actual value (121) is more than 20% greater than target (100): expected false to be true
'
)
}
})
it
(
'
should throw an error if the actual value is lower than expected
'
,
async
()
=>
{
try
{
expectApprox
(
79
,
100
,
{
upperPercentDeviation
:
0
,
lowerPercentDeviation
:
20
,
})
}
catch
(
error
)
{
expect
(
error
.
message
).
to
.
equal
(
'
Actual value (79) is more than 20% less than target (100): expected false to be true
'
)
}
})
})
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