Commit 6ede0241 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #1247 from ethereum-optimism/sc/smock-multiple-arrays

maintance[smock]: add test and docs for returning multiple arrays
parents 5c936e53 d1da05be
---
'@eth-optimism/smock': patch
---
Add a test and a doc section for returning multiple uint256 arrays
...@@ -240,6 +240,25 @@ MyMockContract.smocked.myFunction.will.return.with({ ...@@ -240,6 +240,25 @@ MyMockContract.smocked.myFunction.will.return.with({
console.log(await MyMockContract.myFunction()) // ['Some value', 1234, true] 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 ### Returning a Function
```typescript ```typescript
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
......
...@@ -132,6 +132,14 @@ contract TestHelpers_BasicReturnContract { ...@@ -132,6 +132,14 @@ contract TestHelpers_BasicReturnContract {
) )
{} {}
function getMultipleUint256Arrays()
public
returns (
uint256[] memory,
uint256[] memory
)
{}
function overloadedFunction( function overloadedFunction(
uint256 _paramA, uint256 _paramA,
uint256 _paramB uint256 _paramB
......
...@@ -533,6 +533,25 @@ describe('[smock]: function manipulation tests', () => { ...@@ -533,6 +533,25 @@ describe('[smock]: function manipulation tests', () => {
expect(result[i]).to.deep.equal(expected[i]) 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])
}
}
})
}) })
}) })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment