Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2. refactor: increase coverage and refactor tests structure #46

Merged
merged 5 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 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 @@ -190,9 +191,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,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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove console logs

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 @@ -357,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 @@ -370,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);
_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
Loading