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

feat: add call to internal functions in mock #70

Merged
merged 3 commits into from
Apr 24, 2024
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
6 changes: 6 additions & 0 deletions solidity/contracts/utils/ContractG.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ contract ContractG {
mapping(bytes32 _disputeId => NestedStruct _nestedStruct) public _nestedStructs;

NestedStruct public nestedStruct;

// CommonStruct[][] public multidimensionalStruct;

function setNestedStruct(NestedStruct memory _nestedStruct) public {
nestedStruct = _nestedStruct;
}
}
6 changes: 0 additions & 6 deletions solidity/contracts/utils/ContractJ.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,4 @@ contract ContractJ {
myUserTypeVariable = add(a, b);
return myUserTypeVariable;
}

// =============== virtual call ===============

function callInternalAdd(MyUserType a, MyUserType b) public returns (MyUserType) {
return internalAdd(a, b);
}
}
39 changes: 39 additions & 0 deletions solidity/test/ContractTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,19 @@ contract E2EMockContractTest_Mock_call_Internal_Func is CommonE2EBase {
assertEq(_res3, 'test');
}

function test_call_InternalVirtualFunction() public {
_contractTest.mock_call_internalVirtualFunction(10, false, 12, 'TEST');
(bool _res1, uint256 _res2, string memory _res3) = _contractTest.call_internalVirtualFunction(10);
assertEq(_res1, false);
assertEq(_res2, 12);
assertEq(_res3, 'TEST');

(_res1, _res2, _res3) = _contractTest.call_internalVirtualFunction(11);
assertEq(_res1, true);
assertEq(_res2, 1);
assertEq(_res3, 'test');
}

function test_MockCall_InternalViewVirtualFunction() public {
_contractTest.mock_call_internalViewVirtualFunction(10, false, 12, 'TEST');
(bool _res1, uint256 _res2, string memory _res3) = _contractTest.callInternalViewVirtualFunction(10);
Expand All @@ -353,6 +366,19 @@ contract E2EMockContractTest_Mock_call_Internal_Func is CommonE2EBase {
assertEq(_res3, 'test');
}

function test_call_InternalViewVirtualFunction() public {
_contractTest.mock_call_internalViewVirtualFunction(10, false, 12, 'TEST');
(bool _res1, uint256 _res2, string memory _res3) = _contractTest.call_internalViewVirtualFunction(10);
assertEq(_res1, false);
assertEq(_res2, 12);
assertEq(_res3, 'TEST');

(_res1, _res2, _res3) = _contractTest.call_internalViewVirtualFunction(11);
assertEq(_res1, true);
assertEq(_res2, 1);
assertEq(_res3, 'test');
}

function test_MockCall_InternalPureVirtualFunction() public {
_contractTest.mock_call_internalPureVirtualFunction(10, false, 12, 'TEST');
(bool _res1, uint256 _res2, string memory _res3) = _contractTest.callInternalPureVirtualFunction(10);
Expand All @@ -365,4 +391,17 @@ contract E2EMockContractTest_Mock_call_Internal_Func is CommonE2EBase {
assertEq(_res2, 11);
assertEq(_res3, 'test');
}

function test_call_InternalPureVirtualFunction() public {
_contractTest.mock_call_internalPureVirtualFunction(10, false, 12, 'TEST');
(bool _res1, uint256 _res2, string memory _res3) = _contractTest.call_internalPureVirtualFunction(10);
assertEq(_res1, false);
assertEq(_res2, 12);
assertEq(_res3, 'TEST');

(_res1, _res2, _res3) = _contractTest.call_internalPureVirtualFunction(11);
assertEq(_res1, true);
assertEq(_res2, 11);
assertEq(_res3, 'test');
}
}
2 changes: 1 addition & 1 deletion solidity/test/utils/ContractJ.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ contract UnitMockContractJ is Test, SmockHelper {

function test_InternalAdd() public {
_contractTest.mock_call_internalAdd(_myUserTypeA, _myUserTypeB, _myUserTypeResult);
assertEq(ContractJ.MyUserType.unwrap(_contractTest.callInternalAdd(_myUserTypeA, _myUserTypeB)), _result);
assertEq(ContractJ.MyUserType.unwrap(_contractTest.call_internalAdd(_myUserTypeA, _myUserTypeB)), _result);
}

function test_ExternalAdd() public {
Expand Down
5 changes: 5 additions & 0 deletions src/templates/partials/internal-function.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ function {{functionName}}({{inputs}}) internal override {{#if outputs}}returns (
else return super.{{functionName}}({{#each inputNames}}{{this}}{{#unless @last}}, {{/unless}}{{/each}});
{{/if}}
}


function call_{{functionName}}({{inputs}}) public {{#if outputs}}returns ({{outputs}}){{/if}} {
return {{functionName}}({{#each inputNames}}{{this}}{{#unless @last}}, {{/unless}}{{/each}});
}
6 changes: 5 additions & 1 deletion src/templates/partials/internal-view-function.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ function {{functionName}}{{#if isPure}}Helper{{/if}}({{inputs}}) internal view {
return _{{functionName}}CastToPure({{functionName}}Helper)({{#each inputNames}}{{this}}{{#unless @last}}, {{/unless}}{{/each}});
}

{{/if}}
{{/if}}

function call_{{functionName}}({{inputs}}) public {{#if isView}}view{{else}}pure{{/if}} {{#if outputs}}returns ({{outputs}}){{/if}} {
return {{functionName}}({{#each inputNames}}{{this}}{{#unless @last}}, {{/unless}}{{/each}});
}
Loading