Skip to content

Commit

Permalink
refactor: improve overall tests structure and increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fedealconada committed Jan 22, 2024
1 parent 304517b commit 8cd0afb
Show file tree
Hide file tree
Showing 18 changed files with 1,170 additions and 2,263 deletions.
11 changes: 10 additions & 1 deletion src/wallet/KintoWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "@openzeppelin/contracts/interfaces/IERC20.sol";

import "@aa/core/BaseAccount.sol";
import "@aa/samples/callback/TokenCallbackHandler.sol";
import "forge-std/console.sol";

import "../interfaces/IKintoID.sol";
import "../interfaces/IKintoEntryPoint.sol";
Expand Down Expand Up @@ -191,7 +192,7 @@ 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), "KW-apk: invalid address");
require(appWhitelist[app], "KW-apk: contract not whitelisted");
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
Expand Down Expand Up @@ -272,8 +273,13 @@ 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("APP", app);
console.log("appWhitelist[app]", appWhitelist[app]);
console.log("appSigner[app]", appSigner[app]);
console.log(userOp.signature.length == 65);
if (userOp.signature.length == 65 && appWhitelist[app] && appSigner[app] != address(0)) {
if (appSigner[app] == hash.recover(userOp.signature)) {
console.log("SIII");
return _packValidationData(false, 0, 0);
}
}
Expand Down Expand Up @@ -359,6 +365,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 All @@ -372,6 +380,7 @@ contract KintoWallet is Initializable, BaseAccount, TokenCallbackHandler, IKinto
// App signer should only be valid for the app itself and its children
// It is important that wallet calls are not allowed through the app signer
if (!appRegistry.isContractSponsored(lastTargetContract, targets[i])) {
console.log("ENTREEEEE");
return address(0);
}
}
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);
_fundSponsorForApp(address(_engenCredits));
_fundSponsorForApp(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 8cd0afb

Please sign in to comment.