diff --git a/contracts/test/TestCaptcha.sol b/contracts/test/TestCaptcha.sol index 2819091..03b5e30 100644 --- a/contracts/test/TestCaptcha.sol +++ b/contracts/test/TestCaptcha.sol @@ -7,8 +7,12 @@ import "../samples/HybridAccount.sol"; contract TestCaptcha is Ownable { address payable immutable helperAddr; + uint256 constant public nativeFaucetAmount = 0.01 ether; + uint256 constant public waitingPeriod = 1 days; IERC20 public token; + mapping(address => uint256) public claimRecords; + uint256 private constant SAFE_GAS_STIPEND = 6000; constructor(address payable _helperAddr) { @@ -30,17 +34,17 @@ contract TestCaptcha is Ownable { } function verifycaptcha( - string calldata userAddress, - string calldata uuid, - string calldata captchaInput - ) public returns (bool) { + address _to, + bytes32 _uuid, + string memory _key + ) private returns (bool) { HybridAccount ha = HybridAccount(helperAddr); bytes memory req = abi.encodeWithSignature( "verifyCaptcha(string,string,string)", - userAddress, - uuid, - captchaInput + _to, + _uuid, + _key ); bytes32 userKey = bytes32(abi.encode(msg.sender)); (uint32 error, bytes memory ret) = ha.CallOffchain(userKey, req); @@ -54,11 +58,15 @@ contract TestCaptcha is Ownable { return isVerified; } - function getBalances() - public - view - returns (uint256 nativeBalance) - { - nativeBalance = address(this).balance; + function getTestnetETH( + bytes32 _uuid, + string memory _key, + address _to) external { + require(claimRecords[_to] + waitingPeriod <= block.timestamp, 'Invalid request'); + require(verifyCaptcha(_to, _uuid, _key), "Invalid captcha"); + claimRecords[_to] = block.timestamp; + + (bool sent,) = (_to).call{gas: SAFE_GAS_STIPEND, value: nativeFaucetAmount}(""); + require(sent, "Failed to send native"); } }