|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +import {Test} from 'forge-std/Test.sol'; |
| 5 | +import {MockContractAbstract} from 'test/smock/contracts/utils/MockContractAbstract.sol'; |
| 6 | +import {SmockHelper} from 'test/smock/SmockHelper.sol'; |
| 7 | + |
| 8 | +contract UnitMockContractAbstract is Test, SmockHelper { |
| 9 | + address internal _owner = makeAddr('owner'); |
| 10 | + MockContractAbstract internal _contractTest; |
| 11 | + |
| 12 | + uint256 internal _initialValue = 5; |
| 13 | + uint256 internal _newValue = 10; |
| 14 | + string internal _someText = 'some text'; |
| 15 | + bool internal _result = true; |
| 16 | + |
| 17 | + function setUp() public { |
| 18 | + vm.prank(_owner); |
| 19 | + |
| 20 | + _contractTest = MockContractAbstract( |
| 21 | + deployMock('TestContractAbstract', type(MockContractAbstract).creationCode, abi.encode(_initialValue)) |
| 22 | + ); |
| 23 | + } |
| 24 | + |
| 25 | + function test_Set_UintVariable() public { |
| 26 | + _contractTest.set_uintVariable(_newValue); |
| 27 | + assertEq(_contractTest.uintVariable(), _newValue); |
| 28 | + } |
| 29 | + |
| 30 | + function test_Call_UintVariable() public { |
| 31 | + _contractTest.mock_call_uintVariable(_newValue); |
| 32 | + assertEq(_contractTest.uintVariable(), _newValue); |
| 33 | + } |
| 34 | + |
| 35 | + function test_Call_SetVariablesA() public { |
| 36 | + _contractTest.mock_call_setVariablesA(_newValue, _result); |
| 37 | + assertEq(_contractTest.setVariablesA(_newValue), _result); |
| 38 | + } |
| 39 | + |
| 40 | + function test_Call_UndefinedFunc() public { |
| 41 | + _contractTest.mock_call_undefinedFunc(_someText, _result); |
| 42 | + assertEq(_contractTest.undefinedFunc(_someText), _result); |
| 43 | + } |
| 44 | + |
| 45 | + function test_Call_UndefinedFuncNoInputNoOutput() public { |
| 46 | + vm.expectCall(address(_contractTest), abi.encodeCall(MockContractAbstract.undefinedFuncNoInputNoOutput, ()), 1); |
| 47 | + |
| 48 | + _contractTest.mock_call_undefinedFuncNoInputNoOutput(); |
| 49 | + _contractTest.undefinedFuncNoInputNoOutput(); |
| 50 | + } |
| 51 | + |
| 52 | + function test_Call_UndefinedViewFunc() public { |
| 53 | + _contractTest.mock_call_undefinedViewFunc(_someText, _result); |
| 54 | + assertEq(_contractTest.undefinedViewFunc(_someText), _result); |
| 55 | + } |
| 56 | + |
| 57 | + function test_Call_UndefinedViewFuncNoInputNoOutput() public { |
| 58 | + vm.expectCall(address(_contractTest), abi.encodeCall(MockContractAbstract.undefinedViewFuncNoInputNoOutput, ()), 1); |
| 59 | + |
| 60 | + _contractTest.mock_call_undefinedViewFuncNoInputNoOutput(); |
| 61 | + _contractTest.undefinedViewFuncNoInputNoOutput(); |
| 62 | + } |
| 63 | + |
| 64 | + function test_Call_UndefinedInternalFunc() public { |
| 65 | + _contractTest.expectCall__undefinedInternalFunc(_someText); |
| 66 | + |
| 67 | + _contractTest.mock_call__undefinedInternalFunc(_someText, _result); |
| 68 | + assertEq(_contractTest.call__undefinedInternalFunc(_someText), _result); |
| 69 | + } |
| 70 | + |
| 71 | + function test_Call_UndefinedInternalFuncNoInputNoOutput() public { |
| 72 | + _contractTest.expectCall__undefinedInternalFuncNoInputNoOutput(); |
| 73 | + |
| 74 | + _contractTest.mock_call__undefinedInternalFuncNoInputNoOutput(); |
| 75 | + _contractTest.call__undefinedInternalFuncNoInputNoOutput(); |
| 76 | + } |
| 77 | + |
| 78 | + function test_Call_UndefinedInternalViewFunc() public { |
| 79 | + _contractTest.expectCall__undefinedInternalViewFunc(_someText); |
| 80 | + |
| 81 | + _contractTest.mock_call__undefinedInternalViewFunc(_someText, _result); |
| 82 | + assertEq(_contractTest.call__undefinedInternalViewFunc(_someText), _result); |
| 83 | + } |
| 84 | + |
| 85 | + function test_Call_UndefinedInternalViewFuncNoInputNoOutput() public { |
| 86 | + _contractTest.expectCall__undefinedInternalViewFuncNoInputNoOutput(); |
| 87 | + |
| 88 | + _contractTest.mock_call__undefinedInternalViewFuncNoInputNoOutput(); |
| 89 | + _contractTest.call__undefinedInternalViewFuncNoInputNoOutput(); |
| 90 | + } |
| 91 | +} |
0 commit comments