Skip to content

Commit

Permalink
style: mocks structure (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJabberwock authored Dec 19, 2023
1 parent 82f2b32 commit f625b99
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/templates/mockArrayStateVariableTemplate.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ function set_{{setFunction.functionName}}({{setFunction.arrayType}} _{{setFuncti
{{setFunction.functionName}} = _{{setFunction.paramName}};
{{/if}}
}

{{#unless isInternal}}

function mock_call_{{mockFunction.functionName}}(uint256 _index, {{mockFunction.baseType}} _value) public {
vm.mockCall(
address(this),
Expand All @@ -17,4 +17,3 @@ function mock_call_{{mockFunction.functionName}}(uint256 _index, {{mockFunction.
);
}
{{/unless}}
{{nl}}
3 changes: 1 addition & 2 deletions src/templates/mockBasicStateVariableTemplate.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function set_{{setFunction.functionName}}({{setFunction.paramType}} _{{setFunction.paramName}}) public {
{{setFunction.paramName}} = _{{setFunction.paramName}};
}

{{#unless isInternal}}

function mock_call_{{mockFunction.functionName}}({{mockFunction.paramType}} _{{mockFunction.functionName}}) public {
vm.mockCall(
address(this),
Expand All @@ -11,4 +11,3 @@ function mock_call_{{mockFunction.functionName}}({{mockFunction.paramType}} _{{m
);
}
{{/unless}}
{{nl}}
20 changes: 13 additions & 7 deletions src/templates/mockContractTemplate.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,31 @@ import { {{~exportedSymbols~}} } from '{{contractImport}}';
{{/each}}

contract Mock{{contractName}} is {{contractName}}, Test {

{{#if constructor}}
{{constructor}}
{{/if}}
{{#if mockStateVariables}}{{nl}}
/// Mocked State Variables
{{#each mockStateVariables}}
{{#each mockStateVariables}}{{nl}}
{{> mockStateVariable}}
{{/each}}
{{#each mockArrayStateVariables}}
{{#each mockArrayStateVariables}}{{nl}}
{{> mockArrayStateVariable}}
{{/each}}
{{#each mockMappingStateVariables}}
{{#each mockMappingStateVariables}}{{nl}}
{{> mockMappingStateVariable}}
{{/each}}
{{/if}}
{{#if mockExternalFunctions}}{{nl}}
/// Mocked External Functions
{{#each mockExternalFunctions}}
{{#each mockExternalFunctions}}{{nl}}
{{> mockExternalFunction}}
{{/each}}
{{/if}}
{{#if mockInternalFunctions}}{{nl}}
/// Mocked Internal Functions
{{#each mockInternalFunctions}}
{{#each mockInternalFunctions}}{{nl}}
{{> mockInternalFunction}}
{{/each}}

{{/if}}
}
1 change: 0 additions & 1 deletion src/templates/mockExternalFunctionTemplate.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ function mock_call_{{functionName}}({{arguments}}) public {
abi.encode({{outputsStringNames}})
);
}
{{nl}}
3 changes: 1 addition & 2 deletions src/templates/mockInternalFunctionTemplate.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ struct {{functionName}}Output {
mapping(bytes32 => {{functionName}}Output) private {{functionName}}Outputs;
{{/if}}
bytes32[] private {{functionName}}InputHashes;
{{/if}}

{{/if}}
function mock_call_{{functionName}}({{parameters}}) public {
{{#if isView}}
bytes32 _key = keccak256(abi.encode({{#each inputNames}}{{this}}{{#unless @last}}, {{/unless}}{{/each}}));
Expand Down Expand Up @@ -50,4 +50,3 @@ function {{functionName}}({{inputs}}) internal {{#if isView}}view {{/if}}overrid
else return super.{{functionName}}({{#each inputNames}}{{this}}{{#unless @last}}, {{/unless}}{{/each}});
{{/if}}
}
{{nl}}
3 changes: 1 addition & 2 deletions src/templates/mockMappingStateVariableTemplate.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ function set_{{setFunction.functionName}}({{#each setFunction.keyTypes}}{{this}}
{{setFunction.functionName}}{{#each setFunction.keyTypes}}[_key{{@index}}]{{/each}} = _value;
{{/if}}
}

{{#unless isInternal}}

function mock_call_{{mockFunction.functionName}}({{#each mockFunction.keyTypes}}{{this}} _key{{@index}}, {{/each}}{{#if isArray}}uint256 _index, {{mockFunction.baseType}}{{else}}{{mockFunction.valueType}}{{/if}} _value) public {
vm.mockCall(
address(this),
Expand All @@ -17,4 +17,3 @@ function mock_call_{{mockFunction.functionName}}({{#each mockFunction.keyTypes}}
);
}
{{/unless}}
{{nl}}

0 comments on commit f625b99

Please sign in to comment.