Skip to content

Commit

Permalink
Merge pull request #63 from KintoXYZ/send-money-account
Browse files Browse the repository at this point in the history
Send money to account check
  • Loading branch information
rrecuero authored Jan 31, 2024
2 parents 39d9086 + 4fa310c commit 88a2a95
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/wallet/KintoWalletFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,16 @@ contract KintoWalletFactory is Initializable, UUPSUpgradeable, OwnableUpgradeabl
}

/**
* @dev Send money to an account from privileged accounts
* @dev Send money to an account from privileged accounts or from kyc accounts to kyc accounts or contracts.
* @param target The target address
*/
function sendMoneyToAccount(address target) external payable override {
require(
owner() == msg.sender || kintoID.isKYC(msg.sender)
|| IAccessControl(address(kintoID)).hasRole(kintoID.KYC_PROVIDER_ROLE(), msg.sender),
"KYC or Provider role required"
);
require(target != address(0), "Invalid target: zero address");
bool isPrivileged =
owner() == msg.sender || IAccessControl(address(kintoID)).hasRole(kintoID.KYC_PROVIDER_ROLE(), msg.sender);
require(isPrivileged || kintoID.isKYC(msg.sender), "KYC or Provider role required");
bool isValidTarget = kintoID.isKYC(target) || target.code.length > 0;
require(isValidTarget || isPrivileged, "Target is not valid");
(bool sent,) = target.call{value: msg.value}("");
require(sent, "Failed to send Ether");
}
Expand Down
38 changes: 36 additions & 2 deletions test/KintoWalletFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,20 @@ contract KintoWalletFactoryTest is SharedSetup {

function testSendMoneyToAccount_WhenCallerIsKYCd() public {
approveKYC(_kycProvider, _user, _userPk);
approveKYC(_kycProvider, _user2, _user2Pk);

vm.deal(_user, 1 ether);
vm.prank(_user);
_walletFactory.sendMoneyToAccount{value: 1e18}(address(123));
assertEq(address(123).balance, 1e18);
_walletFactory.sendMoneyToAccount{value: 1e18}(address(_user2));
assertEq(address(_user2).balance, 1e18);
}

function testSendMoneyToAccount_WhenCallerIsKYCdAndTargetIsContract() public {
approveKYC(_kycProvider, _user, _userPk);
vm.deal(_user, 1 ether);
vm.prank(_user);
_walletFactory.sendMoneyToAccount{value: 1e18}(address(_kintoWallet));
assertEq(address(_kintoWallet).balance, 1e18);
}

function testSendMoneyToAccount_WhenCallerIsOwner() public {
Expand All @@ -334,6 +344,14 @@ contract KintoWalletFactoryTest is SharedSetup {
assertEq(address(123).balance, 1e18);
}

function testSendMoneyToAccount_WhenCallerIsOwner_WhenTargetIsKYC() public {
approveKYC(_kycProvider, _user, _userPk);
revokeKYC(_kycProvider, _owner, _ownerPk);
vm.prank(_owner);
_walletFactory.sendMoneyToAccount{value: 1e18}(address(_user));
assertEq(address(_user).balance, 1e18);
}

function testSendMoneyToAccount_WhenCallerIsKYCProvider() public {
vm.deal(_kycProvider, 1 ether);
vm.prank(_kycProvider);
Expand All @@ -353,13 +371,29 @@ contract KintoWalletFactoryTest is SharedSetup {
assertEq(address(123).balance, 1e18);
}

function testSendMoneyToAccount_WhenCallerIsKYCd_WhenTargetIsContract() public {
vm.deal(_kycProvider, 1 ether);
vm.prank(_kycProvider);
uint256 beforeBalance = address(_kintoWallet).balance;
_walletFactory.sendMoneyToAccount{value: 1e18}(address(_kintoWallet));
assertEq(address(_kintoWallet).balance, beforeBalance + 1e18);
}

function testSendMoneyToAccount_RevertWhen_CallerIsNotAllowed() public {
vm.deal(address(123), 1 ether);
vm.prank(address(123));
vm.expectRevert("KYC or Provider role required");
_walletFactory.sendMoneyToAccount{value: 1e18}(address(123));
}

function testSendMoneyToAccount_RevertWhen_CallerIsKYCd_WhenTargetisNotKYCd() public {
approveKYC(_kycProvider, _user, _userPk);
vm.deal(_user, 1 ether);
vm.prank(_user);
vm.expectRevert("Target is not valid");
_walletFactory.sendMoneyToAccount{value: 1e18}(address(123));
}

/* ============ Claim From Faucet tests ============ */

function testClaimFromFaucet_WhenCallerIsKYCd() public {
Expand Down

0 comments on commit 88a2a95

Please sign in to comment.