rln-contract/test/RLNApp.t.sol

71 lines
2.4 KiB
Solidity
Raw Normal View History

// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.15;
import "../contracts/RlnBase.sol";
import "./Verifier.sol";
import "forge-std/Test.sol";
import "forge-std/StdCheats.sol";
import "forge-std/console.sol";
contract RlnApp is RlnBase {
uint256 public constant allowedIdCommitment =
19014214495641488759237505126948346942972912379615652741039992445865937985820;
2023-07-27 11:52:29 +00:00
uint256 private membershipDeposit = 1000000000000000;
uint256 private depth = 20;
2023-12-01 07:13:59 +00:00
constructor(address _verifier) RlnBase(membershipDeposit, depth, _verifier) {}
function _validateRegistration(uint256 idCommitment) internal pure override {
if (idCommitment != allowedIdCommitment) revert FailedValidation();
}
function _validateSlash(uint256 idCommitment, address payable receiver, uint256[8] calldata proof)
internal
pure
override
{
if (idCommitment == allowedIdCommitment) revert FailedValidation();
}
}
contract RLNAppTest is Test {
RlnApp public rlnApp;
TrueVerifier public trueVerifier;
uint256 public constant MEMBERSHIP_DEPOSIT = 1000000000000000;
uint256 public constant DEPTH = 20;
uint256 public constant SET_SIZE = 1048576;
uint256[8] public zeroedProof = [0, 0, 0, 0, 0, 0, 0, 0];
function setUp() public {
trueVerifier = new TrueVerifier();
2023-12-01 07:13:59 +00:00
rlnApp = new RlnApp(address(trueVerifier));
}
function test__Constants() public {
// sanity checking
assertEq(rlnApp.MEMBERSHIP_DEPOSIT(), MEMBERSHIP_DEPOSIT);
assertEq(rlnApp.DEPTH(), DEPTH);
assertEq(rlnApp.SET_SIZE(), SET_SIZE);
}
function test__InvalidRegistration(uint256 idCommitment) public {
vm.assume(idCommitment != rlnApp.allowedIdCommitment());
vm.assume(rlnApp.isValidCommitment(idCommitment));
vm.expectRevert(FailedValidation.selector);
rlnApp.register{value: MEMBERSHIP_DEPOSIT}(idCommitment);
}
function test__ValidRegistration() public {
rlnApp.register{value: MEMBERSHIP_DEPOSIT}(rlnApp.allowedIdCommitment());
}
function test__InvalidSlash() public {
uint256 allowedIdCommitment = rlnApp.allowedIdCommitment();
rlnApp.register{value: MEMBERSHIP_DEPOSIT}(allowedIdCommitment);
vm.expectRevert(FailedValidation.selector);
rlnApp.slash(allowedIdCommitment, payable(address(this)), zeroedProof);
}
}