Skip to content

Commit

Permalink
docs: nested mappings not supported (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJabberwock authored Nov 29, 2023
1 parent 66ce14b commit 99cec67
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ greeter.set__greeting('Holá');

- Please, note that if you want to mock `internal` functions, you **must** make them `virtual`. The tool will not generate mocks for internal functions that are not virtual.
- Cannot `set` private variables and mock private functions.
- Mocking of nested mappings is not supported.
- Mocking of structs containing mappings is not supported.

## Release

Expand Down
9 changes: 8 additions & 1 deletion solidity/test/ContractTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import {Test} from 'forge-std/Test.sol';
import {IERC20} from 'isolmate/interfaces/tokens/IERC20.sol';
import {MockContractTest} from 'test/mocks/contracts/MockContractTest.sol';
import {MockContractTest, IContractTest} from 'test/mocks/contracts/MockContractTest.sol';
import {console} from 'forge-std/console.sol';
import {SmockHelper} from 'test/mocks/SmockHelper.sol';

Expand Down Expand Up @@ -118,6 +118,13 @@ contract E2EMockContractTest_Set_Mapping_Vars is CommonE2EBase {
// _contractTest.set_uint256ToAddressToBytes32(1, _owner, bytes32('4'));
// assertEq(_contractTest.uint256ToAddressToBytes32(1, _owner), bytes32('4'));

function test_Set_Uint256ToMyStructMappings() public {
_contractTest.set_uint256ToMyStruct(1, IContractTest.MyStruct(100, 'hundred'));
(uint256 _value, string memory _name) = _contractTest.uint256ToMyStruct(1);
assertEq(_value, 100);
assertEq(_name, 'hundred');
}

// internal
function test_SetInternalUint256ToAddressMappings() public {
_contractTest.set_internalUint256ToAddress(1, _owner);
Expand Down
6 changes: 2 additions & 4 deletions src/get-variables-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ export const getStateVariables = (contractNode: ContractDefinitionNode): StateVa
// Get the type of the state variable
const stateVariableType: string = stateVariableNode.typeDescriptions.typeString;

// If nested mapping return
if (stateVariableType.includes('=> mapping')) return;

// Check if the state variable is an array or a mapping or a basic type
if (stateVariableType.startsWith('mapping')) {
// If value is of type struct we don't mock it
// If nested mapping return
if (stateVariableType.includes('=> mapping')) return;
const mappingMockFunction: MappingStateVariableOptions = getMappingFunction(stateVariableNode);
mappingFunctions.push(mappingMockFunction);
} else if (stateVariableType.includes('[]')) {
Expand Down

0 comments on commit 99cec67

Please sign in to comment.