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
b107a032
Commit
b107a032
authored
Jun 26, 2021
by
Reggie Gomez
Committed by
smartcontracts
Jun 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(integration): Add clarity to the expectApprox function signature
parent
70c89129
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
13 deletions
+22
-13
ninety-cheetahs-love.md
.changeset/ninety-cheetahs-love.md
+5
-0
native-eth.spec.ts
integration-tests/test/native-eth.spec.ts
+2
-2
rpc.spec.ts
integration-tests/test/rpc.spec.ts
+1
-1
utils.ts
integration-tests/test/shared/utils.ts
+14
-10
No files found.
.changeset/ninety-cheetahs-love.md
0 → 100644
View file @
b107a032
---
'
@eth-optimism/integration-tests'
:
patch
---
Make expectApprox more readable by passing optional args as an object with well named keys
integration-tests/test/native-eth.spec.ts
View file @
b107a032
...
@@ -57,7 +57,7 @@ describe('Native ETH Integration Tests', async () => {
...
@@ -57,7 +57,7 @@ describe('Native ETH Integration Tests', async () => {
const
addr
=
'
0x
'
+
'
1234
'
.
repeat
(
10
)
const
addr
=
'
0x
'
+
'
1234
'
.
repeat
(
10
)
const
gas
=
await
env
.
ovmEth
.
estimateGas
.
transfer
(
addr
,
amount
)
const
gas
=
await
env
.
ovmEth
.
estimateGas
.
transfer
(
addr
,
amount
)
// Expect gas to be less than or equal to the target plus 1%
// Expect gas to be less than or equal to the target plus 1%
expectApprox
(
gas
,
6430020
,
1
)
expectApprox
(
gas
,
6430020
,
{
upperPercentDeviation
:
1
}
)
})
})
it
(
'
Should estimate gas for ETH withdraw
'
,
async
()
=>
{
it
(
'
Should estimate gas for ETH withdraw
'
,
async
()
=>
{
...
@@ -69,7 +69,7 @@ describe('Native ETH Integration Tests', async () => {
...
@@ -69,7 +69,7 @@ describe('Native ETH Integration Tests', async () => {
'
0xFFFF
'
'
0xFFFF
'
)
)
// Expect gas to be less than or equal to the target plus 1%
// Expect gas to be less than or equal to the target plus 1%
expectApprox
(
gas
,
6700060
,
1
)
expectApprox
(
gas
,
6700060
,
{
upperPercentDeviation
:
1
}
)
})
})
})
})
...
...
integration-tests/test/rpc.spec.ts
View file @
b107a032
...
@@ -376,7 +376,7 @@ describe('Basic RPC tests', () => {
...
@@ -376,7 +376,7 @@ describe('Basic RPC tests', () => {
value
:
0
,
value
:
0
,
})
})
// Expect gas to be less than or equal to the target plus 1%
// Expect gas to be less than or equal to the target plus 1%
expectApprox
(
estimate
,
5920012
,
1
)
expectApprox
(
estimate
,
5920012
,
{
upperPercentDeviation
:
1
}
)
})
})
it
(
'
should return a gas estimate that grows with the size of data
'
,
async
()
=>
{
it
(
'
should return a gas estimate that grows with the size of data
'
,
async
()
=>
{
...
...
integration-tests/test/shared/utils.ts
View file @
b107a032
...
@@ -142,35 +142,39 @@ export const DEFAULT_TRANSACTION = {
...
@@ -142,35 +142,39 @@ export const DEFAULT_TRANSACTION = {
value
:
0
,
value
:
0
,
}
}
interface
percentDeviationRange
{
upperPercentDeviation
:
number
lowerPercentDeviation
?:
number
}
export
const
expectApprox
=
(
export
const
expectApprox
=
(
actual
:
BigNumber
|
number
,
actual
:
BigNumber
|
number
,
target
:
BigNumber
|
number
,
target
:
BigNumber
|
number
,
upperDeviation
:
number
,
{
upperPercentDeviation
,
lowerPercentDeviation
=
100
}:
percentDeviationRange
lowerDeviation
:
number
=
100
)
=>
{
)
=>
{
actual
=
BigNumber
.
from
(
actual
)
actual
=
BigNumber
.
from
(
actual
)
target
=
BigNumber
.
from
(
target
)
target
=
BigNumber
.
from
(
target
)
const
validDeviations
=
const
validDeviations
=
upperDeviation
>=
0
&&
upper
Percent
Deviation
>=
0
&&
upperDeviation
<=
100
&&
upper
Percent
Deviation
<=
100
&&
lowerDeviation
>=
0
&&
lower
Percent
Deviation
>=
0
&&
lowerDeviation
<=
100
lower
Percent
Deviation
<=
100
if
(
!
validDeviations
)
{
if
(
!
validDeviations
)
{
throw
new
Error
(
throw
new
Error
(
'
Upper and lower deviation percentage arguments should be between 0 and 100
'
'
Upper and lower deviation percentage arguments should be between 0 and 100
'
)
)
}
}
const
upper
=
target
.
mul
(
100
+
upperDeviation
).
div
(
100
)
const
upper
=
target
.
mul
(
100
+
upper
Percent
Deviation
).
div
(
100
)
const
lower
=
target
.
mul
(
100
-
lowerDeviation
).
div
(
100
)
const
lower
=
target
.
mul
(
100
-
lower
Percent
Deviation
).
div
(
100
)
expect
(
expect
(
actual
.
lte
(
upper
),
actual
.
lte
(
upper
),
`Actual value is more than
${
upperDeviation
}
% greater than target`
`Actual value is more than
${
upper
Percent
Deviation
}
% greater than target`
).
to
.
be
.
true
).
to
.
be
.
true
expect
(
expect
(
actual
.
gte
(
lower
),
actual
.
gte
(
lower
),
`Actual value is more than
${
lowerDeviation
}
% less than target`
`Actual value is more than
${
lower
Percent
Deviation
}
% less than target`
).
to
.
be
.
true
).
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