diff --git a/test/SMv2SessionValidationModule.t.sol b/test/SMv2SessionValidationModule.t.sol index cf1ea82..5ab3d47 100644 --- a/test/SMv2SessionValidationModule.t.sol +++ b/test/SMv2SessionValidationModule.t.sol @@ -1,25 +1,179 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.18; -import {Bootstrap} from "test/utils/Bootstrap.sol"; +import { + Bootstrap, SMv2SessionValidationModule +} from "test/utils/Bootstrap.sol"; +import {IAccount} from "src/kwenta/smv2/IAccount.sol"; contract SMv2SessionValidationModuleTest is Bootstrap { + address sessionKey; + address smv2ProxyAccount; + bytes4 smv2ExecuteSelector; + address destinationContract; + uint256 callValue; + bytes funcCallData; + bytes sessionKeyData; + bytes callSpecificData; + function setUp() public { initializeOptimismGoerli(); + + // session key data + sessionKey = address(0x1); + smv2ProxyAccount = address(0x2); + smv2ExecuteSelector = IAccount.execute.selector; + + // params + destinationContract = smv2ProxyAccount; + callValue = 0; + funcCallData = abi.encode(smv2ExecuteSelector, bytes4("")); + sessionKeyData = + abi.encode(sessionKey, smv2ProxyAccount, smv2ExecuteSelector); + callSpecificData = ""; } } contract ValidateSessionParams is SMv2SessionValidationModuleTest { - function test_validateSessionParams_destinationContract() public {} - function test_validateSessionParams_callValue() public {} - function test_validateSessionParams_funcCallData() public {} - function test_validateSessionParams_sessionKeyData() public {} - function test_validateSessionParams_callSpecificData() public {} + function test_validateSessionParams() public { + address retSessionKey = smv2SessionValidationModule + .validateSessionParams( + destinationContract, + callValue, + funcCallData, + sessionKeyData, + callSpecificData + ); + + assertEq(sessionKey, retSessionKey); + } + + function test_validateSessionParams_destinationContract_invalid() public { + destinationContract = address(0); + + vm.expectRevert( + abi.encodeWithSelector( + SMv2SessionValidationModule.InvalidDestinationContract.selector + ) + ); + + smv2SessionValidationModule.validateSessionParams( + destinationContract, + callValue, + funcCallData, + sessionKeyData, + callSpecificData + ); + } + + function test_validateSessionParams_callValue_invalid() public { + callValue = 1; + + vm.expectRevert( + abi.encodeWithSelector( + SMv2SessionValidationModule.InvalidCallValue.selector + ) + ); + + smv2SessionValidationModule.validateSessionParams( + destinationContract, + callValue, + funcCallData, + sessionKeyData, + callSpecificData + ); + } + + function test_validateSessionParams_funcCallData_invalid() public { + funcCallData = abi.encode(bytes4(""), bytes4("")); + + vm.expectRevert( + abi.encodeWithSelector( + SMv2SessionValidationModule.InvalidSMv2Selector.selector + ) + ); + + smv2SessionValidationModule.validateSessionParams( + destinationContract, + callValue, + funcCallData, + sessionKeyData, + callSpecificData + ); + } + + function test_validateSessionParams_sessionKeyData_invalid() public { + address invalidSessionKey = address(0); + sessionKeyData = + abi.encode(invalidSessionKey, smv2ProxyAccount, smv2ExecuteSelector); + + address retSessionKey = smv2SessionValidationModule + .validateSessionParams( + destinationContract, + callValue, + funcCallData, + sessionKeyData, + callSpecificData + ); + + assertFalse(retSessionKey == sessionKey); + + address invalidSmv2ProxyAccount = address(0); + sessionKeyData = + abi.encode(sessionKey, invalidSmv2ProxyAccount, smv2ExecuteSelector); + + vm.expectRevert( + abi.encodeWithSelector( + SMv2SessionValidationModule.InvalidDestinationContract.selector + ) + ); + + smv2SessionValidationModule.validateSessionParams( + destinationContract, + callValue, + funcCallData, + sessionKeyData, + callSpecificData + ); + + bytes4 invalidSmv2ExecuteSelector = bytes4(""); + sessionKeyData = + abi.encode(sessionKey, smv2ProxyAccount, invalidSmv2ExecuteSelector); + + vm.expectRevert( + abi.encodeWithSelector( + SMv2SessionValidationModule.InvalidSMv2Selector.selector + ) + ); + + smv2SessionValidationModule.validateSessionParams( + destinationContract, + callValue, + funcCallData, + sessionKeyData, + callSpecificData + ); + } } contract ValidateSessionUserOp is SMv2SessionValidationModuleTest { - function test_validateSessionUserOp_op() public {} - function test_validateSessionUserOp_userOpHash() public {} - function test_validateSessionUserOp_sessionKeyData() public {} - function test_validateSessionUserOp_sessionKeySignature() public {} + function test_validateSessionUserOp() public { + assertTrue(false); + } + + function test_validateSessionUserOp_op_invalid() public { + assertTrue(false); + } + + function test_validateSessionUserOp_userOpHash_invalid() public { + assertTrue(false); + } + + function test_validateSessionUserOp_sessionKeyData_invalid() public { + assertTrue(false); + } + + function test_validateSessionUserOp_sessionKeySignature_invalid() public { + assertTrue(false); + } } diff --git a/test/SMv3SessionValidationModule.t.sol b/test/SMv3SessionValidationModule.t.sol index 10b9f46..350d459 100644 --- a/test/SMv3SessionValidationModule.t.sol +++ b/test/SMv3SessionValidationModule.t.sol @@ -10,16 +10,49 @@ contract SMv3SessionValidationModuleTest is Bootstrap { } contract ValidateSessionParams is SMv3SessionValidationModuleTest { - function test_validateSessionParams_destinationContract() public {} - function test_validateSessionParams_callValue() public {} - function test_validateSessionParams_funcCallData() public {} - function test_validateSessionParams_sessionKeyData() public {} - function test_validateSessionParams_callSpecificData() public {} + function test_validateSessionParams() public { + assertTrue(false); + } + + function test_validateSessionParams_destinationContract() public { + assertTrue(false); + } + + function test_validateSessionParams_callValue() public { + assertTrue(false); + } + + function test_validateSessionParams_funcCallData() public { + assertTrue(false); + } + + function test_validateSessionParams_sessionKeyData() public { + assertTrue(false); + } + + function test_validateSessionParams_callSpecificData() public { + assertTrue(false); + } } contract ValidateSessionUserOp is SMv3SessionValidationModuleTest { - function test_validateSessionUserOp_op() public {} - function test_validateSessionUserOp_userOpHash() public {} - function test_validateSessionUserOp_sessionKeyData() public {} - function test_validateSessionUserOp_sessionKeySignature() public {} + function test_validateSessionUserOp() public { + assertTrue(false); + } + + function test_validateSessionUserOp_op() public { + assertTrue(false); + } + + function test_validateSessionUserOp_userOpHash() public { + assertTrue(false); + } + + function test_validateSessionUserOp_sessionKeyData() public { + assertTrue(false); + } + + function test_validateSessionUserOp_sessionKeySignature() public { + assertTrue(false); + } }