Skip to content

Commit

Permalink
Merge pull request #46 from KintoXYZ/increase-coverage-2
Browse files Browse the repository at this point in the history
2. refactor: increase coverage and refactor tests structure
  • Loading branch information
fedealconada authored Jan 23, 2024
2 parents 893bd0a + de6a71b commit 0cff01c
Show file tree
Hide file tree
Showing 19 changed files with 1,286 additions and 2,265 deletions.
7 changes: 6 additions & 1 deletion src/wallet/KintoWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,11 @@ contract KintoWallet is Initializable, BaseAccount, TokenCallbackHandler, IKinto
*/
function setAppKey(address app, address signer) external override onlySelf {
// Allow 0 in signer to allow revoking the appkey
require(app != address(0) && appWhitelist[app], "KW-apk: invalid address");
require(app != address(0), "KW-apk: invalid address");
require(appWhitelist[app], "KW-apk: contract not whitelisted"); // todo: i don't think we need to check this here
require(appSigner[app] != signer, "KW-apk: same key");
appSigner[app] = signer;
// todo: emit event
}

/* ============ Recovery Process ============ */
Expand Down Expand Up @@ -270,6 +272,7 @@ contract KintoWallet is Initializable, BaseAccount, TokenCallbackHandler, IKinto
bytes32 hash = userOpHash.toEthSignedMessageHash();
// If there is only one signature and there is an app Key, check it
address app = _getAppContract(userOp.callData);
console.log(userOp.signature.length == 65);
if (userOp.signature.length == 65 && appWhitelist[app] && appSigner[app] != address(0)) {
if (appSigner[app] == hash.recover(userOp.signature)) {
return _packValidationData(false, 0, 0);
Expand Down Expand Up @@ -357,6 +360,8 @@ contract KintoWallet is Initializable, BaseAccount, TokenCallbackHandler, IKinto
}

// Function to extract the first target contract
/// @dev the last op on a batch MUST always be a contract whose sponsor is the one we want to pay
// all other ops
function _getAppContract(bytes calldata callData) private view returns (address) {
// Extract the function selector from the callData
bytes4 selector = bytes4(callData[:4]);
Expand Down
4 changes: 2 additions & 2 deletions test/EngenCredits.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ contract EngenCreditsTest is UserOp, AATestScaffolding {
_owner.transfer(1e18);
vm.stopPrank();
deployAAScaffolding(_owner, 1, _kycProvider, _recoverer);
_fundPaymasterForContract(address(_engenCredits));
_fundPaymasterForContract(address(_kintoWallet));
fundSponsorForApp(address(_engenCredits));
fundSponsorForApp(address(_kintoWallet));
vm.startPrank(_owner);
_kintoAppRegistry.registerApp(
"engen credits", address(_engenCredits), new address[](0), [uint256(0), uint256(0), uint256(0), uint256(0)]
Expand Down
17 changes: 3 additions & 14 deletions test/KintoEntryPoint.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,10 @@ pragma solidity ^0.8.18;
import "forge-std/Test.sol";
import "forge-std/console.sol";

import {UserOp} from "./helpers/UserOp.sol";
import {AATestScaffolding} from "./helpers/AATestScaffolding.sol";
import "./KintoWallet.t.sol";

contract KintoEntryPointTest is AATestScaffolding, UserOp {
uint256 _chainID = 1;

function setUp() public {
vm.chainId(_chainID);
vm.startPrank(address(1));
_owner.transfer(1e18);
vm.stopPrank();
deployAAScaffolding(_owner, 1, _kycProvider, _recoverer);
}

function testUp() public {
contract KintoEntryPointTest is KintoWalletTest {
function testUp() public override {
assertEq(_entryPoint.walletFactory(), address(_walletFactory));
}

Expand Down
Loading

0 comments on commit 0cff01c

Please sign in to comment.