Skip to content

Commit

Permalink
Update TestCaptcha.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
wsdt authored Jun 6, 2024
1 parent bbb3a6b commit aaa2663
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions contracts/test/TestCaptcha.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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");
}
}

0 comments on commit aaa2663

Please sign in to comment.