feat: add deps to deployments, improve rln tests

This commit is contained in:
rymnc
2022-11-25 11:31:06 +05:30
parent 4cbfc0feb0
commit 712b373c92
6 changed files with 62 additions and 53 deletions

View File

@@ -20,4 +20,5 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
});
};
export default func;
func.tags = ['ValidGroupStorage'];
func.tags = ['ValidGroupStorage'];
func.dependencies = ['InterepTest'];

View File

@@ -17,4 +17,5 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
});
};
export default func;
func.tags = ['RLN'];
func.tags = ['RLN'];
func.dependencies = ['PoseidonHasher', 'ValidGroupStorage'];

View File

@@ -1,49 +0,0 @@
import { assert } from "chai";
import { ethers } from "hardhat";
describe.skip("Rln", function () {
it("Deploying", async function () {
const PoseidonHasher = await ethers.getContractFactory("PoseidonHasher");
const poseidonHasher = await PoseidonHasher.deploy();
await poseidonHasher.deployed();
console.log("PoseidonHasher deployed to:", poseidonHasher.address);
const Rln = await ethers.getContractFactory("RLN");
const rln = await Rln.deploy(1000000000000000, 20, poseidonHasher.address);
await rln.deployed();
console.log("Rln deployed to:", rln.address);
const price = await rln.MEMBERSHIP_DEPOSIT();
// A valid pair of (id_secret, id_commitment) generated in rust
const id_secret = "0x2a09a9fd93c590c26b91effbb2499f07e8f7aa12e2b4940a3aed2411cb65e11c"
const id_commitment = "0x0c3ac305f6a4fe9bfeb3eba978bc876e2a99208b8b56c80160cfb54ba8f02368"
const res_register = await rln.register(id_commitment, {value: price});
const txRegisterReceipt = await res_register.wait();
const reg_pubkey = txRegisterReceipt.events[0].args.pubkey;
const reg_tree_index = txRegisterReceipt.events[0].args.index;
// We ensure the registered id_commitment is the one we passed
assert(reg_pubkey.toHexString() === id_commitment, "registered commitment doesn't match passed commitment");
// We withdraw our id_commitment
const receiver_address = "0x000000000000000000000000000000000000dead";
const res_withdraw = await rln.withdraw(id_secret, reg_tree_index, receiver_address);
const txWithdrawReceipt = await res_withdraw.wait();
const wit_pubkey = txWithdrawReceipt.events[0].args.pubkey;
const wit_tree_index = txWithdrawReceipt.events[0].args.index;
// We ensure the registered id_commitment is the one we passed and that the index is the same
assert(wit_pubkey.toHexString() === id_commitment, "withdraw commitment doesn't match registered commitmet");
assert(wit_tree_index.toHexString() === reg_tree_index.toHexString(), "withdraw index doesn't match registered index");
});
});

View File

@@ -1,7 +1,7 @@
import { expect } from "chai";
import { ethers, deployments } from "hardhat";
describe("PoseidonHash", () => {
describe("PoseidonHasher", () => {
beforeEach(async () => {
await deployments.fixture(["PoseidonHasher"]);
});

56
test/rln.ts Normal file
View File

@@ -0,0 +1,56 @@
import { expect } from "chai";
import { ethers, deployments } from "hardhat";
describe("RLN", () => {
beforeEach(async () => {
await deployments.fixture(["RLN"]);
})
it("should register new memberships", async () => {
const rln = await ethers.getContract("RLN", ethers.provider.getSigner(0));
const price = await rln.MEMBERSHIP_DEPOSIT();
// A valid pair of (id_secret, id_commitment) generated in rust
const idCommitment = "0x0c3ac305f6a4fe9bfeb3eba978bc876e2a99208b8b56c80160cfb54ba8f02368"
const registerTx = await rln['register(uint256)'](idCommitment, {value: price});
const txRegisterReceipt = await registerTx.wait();
const pubkey = txRegisterReceipt.events[0].args.pubkey;
// We ensure the registered id_commitment is the one we passed
expect(pubkey.toHexString() === idCommitment, "registered commitment doesn't match passed commitment");
});
it("should withdraw membership", async () => {
const rln = await ethers.getContract("RLN", ethers.provider.getSigner(0));
const price = await rln.MEMBERSHIP_DEPOSIT();
// A valid pair of (id_secret, id_commitment) generated in rust
const idSecret = "0x2a09a9fd93c590c26b91effbb2499f07e8f7aa12e2b4940a3aed2411cb65e11c"
const idCommitment = "0x0c3ac305f6a4fe9bfeb3eba978bc876e2a99208b8b56c80160cfb54ba8f02368"
const registerTx = await rln['register(uint256)'](idCommitment, {value: price});
const txRegisterReceipt = await registerTx.wait();
const treeIndex = txRegisterReceipt.events[0].args.index;
// We withdraw our id_commitment
const receiverAddress = "0x000000000000000000000000000000000000dead";
const withdrawTx = await rln.withdraw(idSecret, treeIndex, receiverAddress);
const txWithdrawReceipt = await withdrawTx.wait();
const withdrawalPk = txWithdrawReceipt.events[0].args.pubkey;
const withdrawalTreeIndex = txWithdrawReceipt.events[0].args.index;
// We ensure the registered id_commitment is the one we passed and that the index is the same
expect(withdrawalPk.toHexString() === idCommitment, "withdraw commitment doesn't match registered commitment");
expect(withdrawalTreeIndex.toHexString() === treeIndex.toHexString(), "withdraw index doesn't match registered index");
})
});

View File

@@ -5,7 +5,7 @@ import {sToBytes32, createGroupId} from '../common';
describe("Valid Group Storage", () => {
beforeEach(async () => {
await deployments.fixture(['InterepTest', 'ValidGroupStorage']);
await deployments.fixture(['ValidGroupStorage']);
})
it('should not deploy if an invalid group is passed in constructor', async () => {