From 99cec677a9f453895cc0b69ba69ad641fb087b48 Mon Sep 17 00:00:00 2001 From: 0xJabberwock <102967621+0xJabberwock@users.noreply.github.com> Date: Wed, 29 Nov 2023 06:37:48 -0300 Subject: [PATCH] docs: nested mappings not supported (#20) --- README.md | 2 ++ solidity/test/ContractTest.t.sol | 9 ++++++++- src/get-variables-functions.ts | 6 ++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 847aae5..ee4d79f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/solidity/test/ContractTest.t.sol b/solidity/test/ContractTest.t.sol index ee80584..80653d8 100644 --- a/solidity/test/ContractTest.t.sol +++ b/solidity/test/ContractTest.t.sol @@ -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'; @@ -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); diff --git a/src/get-variables-functions.ts b/src/get-variables-functions.ts index 8ecd7b2..1247d6d 100644 --- a/src/get-variables-functions.ts +++ b/src/get-variables-functions.ts @@ -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('[]')) {