-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into kelvin/remove-spreadsheet-mode
- Loading branch information
Showing
4 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@eth-optimism/smock': patch | ||
--- | ||
|
||
Fixes a bug that would break call assertions for overloaded smocked functions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.7.0; | ||
|
||
contract TestHelpers_MockCaller { | ||
function callMock(address _target, bytes memory _data) public { | ||
_target.call(_data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* Imports: External */ | ||
import hre from 'hardhat' | ||
import { expect } from 'chai' | ||
import { Contract } from 'ethers' | ||
|
||
/* Imports: Internal */ | ||
import { MockContract, smockit } from '../../src' | ||
|
||
describe('[smock]: call assertion tests', () => { | ||
const ethers = (hre as any).ethers | ||
|
||
let mock: MockContract | ||
beforeEach(async () => { | ||
mock = await smockit('TestHelpers_BasicReturnContract') | ||
}) | ||
|
||
let mockCaller: Contract | ||
before(async () => { | ||
const mockCallerFactory = await ethers.getContractFactory( | ||
'TestHelpers_MockCaller' | ||
) | ||
mockCaller = await mockCallerFactory.deploy() | ||
}) | ||
|
||
describe('call assertions for functions', () => { | ||
it('should be able to make assertions about a non-overloaded function', async () => { | ||
mock.smocked.getInputtedUint256.will.return.with(0) | ||
|
||
const expected1 = ethers.BigNumber.from(1234) | ||
await mockCaller.callMock( | ||
mock.address, | ||
mock.interface.encodeFunctionData('getInputtedUint256(uint256)', [ | ||
expected1, | ||
]) | ||
) | ||
|
||
expect(mock.smocked.getInputtedUint256.calls[0]).to.deep.equal([ | ||
expected1, | ||
]) | ||
}) | ||
|
||
it('should be able to make assertions about both versions of an overloaded function', async () => { | ||
mock.smocked['overloadedFunction(uint256)'].will.return.with(0) | ||
mock.smocked['overloadedFunction(uint256,uint256)'].will.return.with(0) | ||
|
||
const expected1 = ethers.BigNumber.from(1234) | ||
await mockCaller.callMock( | ||
mock.address, | ||
mock.interface.encodeFunctionData('overloadedFunction(uint256)', [ | ||
expected1, | ||
]) | ||
) | ||
|
||
expect( | ||
mock.smocked['overloadedFunction(uint256)'].calls[0] | ||
).to.deep.equal([expected1]) | ||
|
||
const expected2 = ethers.BigNumber.from(5678) | ||
await mockCaller.callMock( | ||
mock.address, | ||
mock.interface.encodeFunctionData( | ||
'overloadedFunction(uint256,uint256)', | ||
[expected2, expected2] | ||
) | ||
) | ||
|
||
expect( | ||
mock.smocked['overloadedFunction(uint256,uint256)'].calls[0] | ||
).to.deep.equal([expected2, expected2]) | ||
}) | ||
}) | ||
}) |