feat(rln): add test for registration/withdraw

This commit is contained in:
s1fr0 2022-10-04 02:35:29 +02:00
parent 8a70eb7c28
commit 5a49736ee4
No known key found for this signature in database
GPG Key ID: 2C041D60117BFF46
1 changed files with 27 additions and 4 deletions

View File

@ -1,4 +1,3 @@
import { expect } from "chai";
import { ethers } from "hardhat"; import { ethers } from "hardhat";
describe("Rln", function () { describe("Rln", function () {
@ -9,12 +8,36 @@ describe("Rln", function () {
await poseidonHasher.deployed(); await poseidonHasher.deployed();
console.log("PoseidonHasher deployed to:", poseidonHasher.address); console.log("PoseidonHasher deployed to:", poseidonHasher.address);
const Rln = await ethers.getContractFactory("RLN"); const Rln = await ethers.getContractFactory("RLN");
const rln = await Rln.deploy(1000000000000000,20,poseidonHasher.address); const rln = await Rln.deploy(1000000000000000, 20, poseidonHasher.address);
await rln.deployed(); await rln.deployed();
console.log("Rln deployed to:", rln.address); console.log("Rln deployed to:", rln.address);
const price = await rln.MEMBERSHIP_DEPOSIT();
// A valid pair of (id_secret, id_commitment)
const id_secret = "0x2a09a9fd93c590c26b91effbb2499f07e8f7aa12e2b4940a3aed2411cb65e11c"
const id_commitment = "0x0c3ac305f6a4fe9bfeb3eba978bc876e2a99208b8b56c80160cfb54ba8f02368"
// We attempt to register and withdraw the commitment (tree index is 0 since the tree is empty)
await rln.register(id_commitment, {value: price});
await rln.withdraw(id_secret, "0", "0x000000000000000000000000000000000000dead");
rln.on('MemberRegistered', function (id_commitment, tree_index) {
console.log(`A new member registered:`);
console.log(`- id_commitment: ${id_commitment}`);
console.log(`- tree_index: ${tree_index}`);
});
rln.on('MemberWithdrawn', function (id_commitment, tree_index) {
console.log(`A member withdrawn its membership fee:`);
console.log(`- id_commitment: ${id_commitment}`);
console.log(`- tree_index: ${tree_index}`);
});
}); });
}); });