Skip to content

Commit

Permalink
chore: increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fedealconada committed Jan 27, 2024
1 parent 2c1a6c7 commit a54f039
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 7 deletions.
62 changes: 62 additions & 0 deletions test/wallet/executeBatch/ExecuteBatch.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,66 @@ contract ExecuteBatchTest is SharedSetup {
_entryPoint.handleOps(userOps, payable(_owner));
assertRevertReasonEq("KW: contract not whitelisted");
}

function testExecuteBatch_RevertWhen_LenghtMismatch() public {
// remove app from whitelist
whitelistApp(address(counter), false);

// prep batch
address[] memory targets = new address[](2);
targets[0] = address(_kintoWallet);
targets[1] = address(counter);

uint256[] memory values = new uint256[](2);
values[0] = 0;
values[1] = 0;

bytes[] memory calls = new bytes[](1);
calls[0] = abi.encodeWithSignature("recoverer()");

OperationParamsBatch memory opParams = OperationParamsBatch({targets: targets, values: values, bytesOps: calls});
UserOperation[] memory userOps = new UserOperation[](1);
userOps[0] = _createUserOperation(
address(_kintoWallet), _kintoWallet.getNonce(), privateKeys, opParams, address(_paymaster)
);

vm.expectEmit(true, true, true, false);
emit UserOperationRevertReason(
_entryPoint.getUserOpHash(userOps[0]), userOps[0].sender, userOps[0].nonce, bytes("")
);
vm.recordLogs();
_entryPoint.handleOps(userOps, payable(_owner));
assertRevertReasonEq("KW-eb: wrong array length");
}

function testExecuteBatch_RevertWhen_LenghtMismatch2() public {
// remove app from whitelist
whitelistApp(address(counter), false);

// prep batch
address[] memory targets = new address[](1);
targets[0] = address(_kintoWallet);

uint256[] memory values = new uint256[](2);
values[0] = 0;
values[1] = 0;

bytes[] memory calls = new bytes[](2);
calls[0] = abi.encodeWithSignature("recoverer()");
calls[1] = abi.encodeWithSignature("increment()");

OperationParamsBatch memory opParams = OperationParamsBatch({targets: targets, values: values, bytesOps: calls});
UserOperation[] memory userOps = new UserOperation[](1);
userOps[0] = _createUserOperation(
address(_kintoWallet), _kintoWallet.getNonce(), privateKeys, opParams, address(_paymaster)
);

vm.expectEmit(true, true, true, false);
emit UserOperationRevertReason(
_entryPoint.getUserOpHash(userOps[0]), userOps[0].sender, userOps[0].nonce, bytes("")
);
vm.recordLogs();
_entryPoint.handleOps(userOps, payable(_owner));
assertRevertReasonEq("KW-eb: wrong array length");
}
}
40 changes: 33 additions & 7 deletions test/wallet/funder/Funder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,50 @@ contract FunderTest is SharedSetup {
}

function testSetFunderWhitelist() public {
vm.startPrank(_owner);
address[] memory funders = new address[](1);
funders[0] = address(23);
uint256 nonce = _kintoWallet.getNonce();

bool[] memory flags = new bool[](1);
flags[0] = true;
UserOperation memory userOp = _createUserOperation(

UserOperation[] memory userOps = new UserOperation[](1);
userOps[0] = _createUserOperation(
address(_kintoWallet),
address(_kintoWallet),
nonce,
_kintoWallet.getNonce(),
privateKeys,
abi.encodeWithSignature("setFunderWhitelist(address[],bool[])", funders, flags),
address(_paymaster)
);
UserOperation[] memory userOps = new UserOperation[](1);
userOps[0] = userOp;

_entryPoint.handleOps(userOps, payable(_owner));
assertEq(_kintoWallet.isFunderWhitelisted(address(23)), true);
vm.stopPrank();
}

function testSetFunderWhitelist_RevertWhen_LengthMismatch() public {
address[] memory funders = new address[](2);
funders[0] = address(23);
funders[1] = address(24);

bool[] memory flags = new bool[](1);
flags[0] = true;

UserOperation[] memory userOps = new UserOperation[](1);
userOps[0] = _createUserOperation(
address(_kintoWallet),
address(_kintoWallet),
_kintoWallet.getNonce(),
privateKeys,
abi.encodeWithSignature("setFunderWhitelist(address[],bool[])", funders, flags),
address(_paymaster)
);

vm.expectEmit(true, true, true, false);
emit UserOperationRevertReason(
_entryPoint.getUserOpHash(userOps[0]), userOps[0].sender, userOps[0].nonce, bytes("")
);
vm.recordLogs();
_entryPoint.handleOps(userOps, payable(_owner));
assertRevertReasonEq("KW-sfw: invalid array");
}
}

0 comments on commit a54f039

Please sign in to comment.