Step 5: Testing the Integration
After integration, thoroughly test your contract:
-
Valid Payload:
- Generate a valid payload via the PureFi SDK and ensure the function executes successfully.
-
Invalid Payload:
- Test reverts with expired, reused, or unsigned payloads.
-
Edge Cases:
- Test with zero ETH, invalid addresses, etc.
Full Example Smart Contract
Here’s a complete example of a contract integrated with PureFi:
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {IPureFiVerifier} from "./PureFi/interfaces/IPureFiVerifier.sol";
contract ExampleContract is Ownable, ReentrancyGuard {
IPureFiVerifier public verifier;
event ActionPerformed(address indexed user, uint256 value);
constructor(address _verifier) {
verifier = IPureFiVerifier(_verifier);
}
function setVerifier(address _verifier) external onlyOwner {
require(_verifier != address(0), "Invalid address");
verifier = IPureFiVerifier(_verifier);
}
function performAction(address _to, bytes calldata _purefidata) external payable nonReentrant {
require(msg.value >= 0.01 ether, "Minimum 0.01 ETH required");
verifier.validatePayload(_purefidata);
// Example logic: send ETH
(bool sent, ) = _to.call{value: msg.value}("");
require(sent, "Failed to send ETH");
emit ActionPerformed(_to, msg.value);
}
receive() external payable {}
}