Commit e6e87ae1 authored by smartcontracts's avatar smartcontracts Committed by GitHub

feat[smock]: add support for overloaded functions (#966)

* feat[smock]: add support for overloaded functions

* chore: add changeset
parent c84d3450
---
'@eth-optimism/smock': patch
---
Fix a bug where overloaded functions would not be handled correctly
......@@ -211,7 +211,7 @@ export const smockit = async (
let mockFn: any
if (fn !== null) {
params = this.interface.decodeFunctionData(fn, toHexString(data))
mockFn = this.smocked[fn.name]
mockFn = this.smocked[fn.name] || this.smocked[fn.format()]
} else {
params = toHexString(data)
mockFn = this.smocked.fallback
......
......@@ -131,4 +131,23 @@ contract TestHelpers_BasicReturnContract {
uint256[] memory _out
)
{}
function overloadedFunction(
uint256 _paramA,
uint256 _paramB
)
public
returns (
uint256
)
{}
function overloadedFunction(
uint256
)
public
returns (
uint256
)
{}
}
......@@ -133,6 +133,23 @@ describe('[smock]: function manipulation tests', () => {
// TODO
})
describe('overloaded functions', () => {
it('should be able to modify both versions of an overloaded function', async () => {
const expected1 = 1234
const expected2 = 5678
mock.smocked['overloadedFunction(uint256)'].will.return.with(expected1)
mock.smocked['overloadedFunction(uint256,uint256)'].will.return.with(
expected2
)
expect(
await mock.callStatic['overloadedFunction(uint256)'](0)
).to.equal(expected1)
expect(
await mock.callStatic['overloadedFunction(uint256,uint256)'](0, 0)
).to.equal(expected2)
})
})
describe('returning with data', () => {
describe('fixed data types', () => {
describe('default behaviors', () => {
......
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