add: hello_rln

This commit is contained in:
rymnc
2023-08-07 12:41:06 +05:30
parent 4041fbdfa6
commit bce5d8e4c7
3 changed files with 52 additions and 0 deletions

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"solidity.compileUsingRemoteVersion": "v0.8.15+commit.e14f2714"
}

24
src/HelloRln.sol Normal file
View File

@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import "rln-contract/RlnBase.sol";
import {Ownable} from "openzeppelin-contracts/contracts/access/Ownable.sol";
contract HelloRln is Ownable, RlnBase {
bytes2 public constant start = 0xdead;
uint256 private membershipDeposit = 0;
uint256 private depth = 20;
constructor(address _poseidonHasher) Ownable() RlnBase(membershipDeposit, depth, _poseidonHasher, address(0)) {}
function _validateRegistration(uint256 idCommitment) internal pure override {
if (bytes2(bytes32(idCommitment)) != start) revert FailedValidation();
}
function _validateSlash(uint256 idCommitment, address payable receiver, uint256[8] calldata proof)
internal
view
override
onlyOwner
{}
}

25
test/HelloRln.t.sol Normal file
View File

@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import "../src/HelloRln.sol";
import {FailedValidation} from "rln-contract/RlnBase.sol";
contract HelloRlnTest is Test {
HelloRln public helloRln;
function setUp() public {
helloRln = new HelloRln(address(0));
}
function test__InvalidRegistration(uint256 idCommitment) public {
vm.assume(bytes2(bytes32(idCommitment)) != helloRln.start());
vm.expectRevert(FailedValidation.selector);
helloRln.register(idCommitment);
}
function test__ValidRegistration() public {
bytes32 idCommitment = 0xdead000000000000000000000000000000000000000000000000000000000000;
helloRln.register(uint256(idCommitment));
}
}