Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maintance[smock]: add test and docs for returning multiple arrays #1247

Merged
merged 2 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wise-mails-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/smock': patch
---

Add a test and a doc section for returning multiple uint256 arrays
19 changes: 19 additions & 0 deletions packages/smock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ contract TestHelpers_BasicReturnContract {
)
{}

function getMultipleUint256Arrays()
public
returns (
uint256[] memory,
uint256[] memory
)
{}

function overloadedFunction(
uint256 _paramA,
uint256 _paramB
Expand Down
19 changes: 19 additions & 0 deletions packages/smock/test/smockit/function-manipulation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
})
})
})
})
Expand Down