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
652c2cf6
Unverified
Commit
652c2cf6
authored
Jul 09, 2021
by
Kelvin Fichter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
maintance[smock]: add test and docs for returning multiple arrays
parent
b9584538
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
0 deletions
+46
-0
README.md
packages/smock/README.md
+19
-0
TestHelpers_BasicReturnContract.sol
.../smock/test/contracts/TestHelpers_BasicReturnContract.sol
+8
-0
function-manipulation.spec.ts
packages/smock/test/smockit/function-manipulation.spec.ts
+19
-0
No files found.
packages/smock/README.md
View file @
652c2cf6
...
...
@@ -240,6 +240,25 @@ MyMockContract.smocked.myFunction.will.return.with({
console
.
log
(
await
MyMockContract
.
myFunction
())
// ['Some value', 1234, true]
```
### Returning a Multiple Arrays
```
typescript
import
{
ethers
}
from
'
hardhat
'
import
{
smockit
}
from
'
@eth-optimism/smock
'
const
MyContractFactory
=
await
ethers
.
getContractFactory
(
'
MyContract
'
)
const
MyContract
=
await
MyContractFactory
.
deploy
(...)
// Smockit!
const
MyMockContract
=
await
smockit
(
MyContract
)
MyMockContract
.
smocked
.
myFunction
.
will
.
return
.
with
([
[
1234
,
5678
],
[
4321
,
8765
]
])
console
.
log
(
await
MyMockContract
.
myFunction
())
// [ [1234, 5678], [4321, 8765] ]
```
### Returning a Function
```
typescript
import
{
ethers
}
from
'
hardhat
'
...
...
packages/smock/test/contracts/TestHelpers_BasicReturnContract.sol
View file @
652c2cf6
...
...
@@ -132,6 +132,14 @@ contract TestHelpers_BasicReturnContract {
)
{}
function getMultipleUint256Arrays()
public
returns (
uint256[] memory,
uint256[] memory
)
{}
function overloadedFunction(
uint256 _paramA,
uint256 _paramB
...
...
packages/smock/test/smockit/function-manipulation.spec.ts
View file @
652c2cf6
...
...
@@ -533,6 +533,25 @@ describe('[smock]: function manipulation tests', () => {
expect
(
result
[
i
]).
to
.
deep
.
equal
(
expected
[
i
])
}
})
it
(
'
should be able to return multiple arrays of uint256 values
'
,
async
()
=>
{
const
expected
=
[
[
1234
,
2345
,
3456
,
4567
,
5678
,
6789
].
map
((
n
)
=>
{
return
BigNumber
.
from
(
n
)
}),
[
1234
,
2345
,
3456
,
4567
,
5678
,
6789
].
map
((
n
)
=>
{
return
BigNumber
.
from
(
n
)
}),
]
mock
.
smocked
.
getMultipleUint256Arrays
.
will
.
return
.
with
(
expected
)
const
result
=
await
mock
.
callStatic
.
getMultipleUint256Arrays
()
for
(
let
i
=
0
;
i
<
result
.
length
;
i
++
)
{
for
(
let
j
=
0
;
j
<
result
[
i
].
length
;
j
++
)
{
expect
(
result
[
i
][
j
]).
to
.
deep
.
equal
(
expected
[
i
][
j
])
}
}
})
})
})
})
...
...
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