Skip to content

Commit

Permalink
fix: allow mocks to override reverting functions (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcontracts authored Sep 30, 2021
1 parent 277378d commit 7b6894b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/logic/programmable-function-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class ProgrammableFunctionLogic extends WatchableFunctionLogic {
result.execResult.exceptionError = new VmError('smock revert' as any);
result.execResult.returnValue = this.encodeRevertReason(answer.value);
} else {
result.execResult.exceptionError = undefined;
result.execResult.returnValue = await this.encodeValue(answer.value, call);
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/contracts/mock/Counter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ contract Counter {
function add(uint256 _amount) external {
count += _amount;
}

function doRevert() external pure returns (bool) {
revert('doing a revert');
}
}
5 changes: 5 additions & 0 deletions test/unit/mock/call-through.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ describe('Mock: Call through', () => {
expect(await mock.count()).to.equal(123);
});

it('should be able to override a function that reverts', async () => {
mock.doRevert.returns(true);
expect(await mock.doRevert()).to.equal(true);
});

it('should be able to check function calls', async () => {
await mock.add(10);
expect(mock.add).to.be.calledOnceWith(10);
Expand Down

0 comments on commit 7b6894b

Please sign in to comment.