refactor(test): improve poseidon/rln register/withdraw test
This commit is contained in:
parent
5a49736ee4
commit
77467a06ac
|
@ -1,3 +1,4 @@
|
|||
import { assert } from "chai";
|
||||
import { ethers } from "hardhat";
|
||||
|
||||
describe("Rln", function () {
|
||||
|
@ -18,26 +19,31 @@ describe("Rln", function () {
|
|||
|
||||
const price = await rln.MEMBERSHIP_DEPOSIT();
|
||||
|
||||
// A valid pair of (id_secret, id_commitment)
|
||||
// A valid pair of (id_secret, id_commitment) generated in rust
|
||||
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");
|
||||
const res_register = await rln.register(id_commitment, {value: price});
|
||||
const txRegisterReceipt = await res_register.wait();
|
||||
|
||||
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}`);
|
||||
});
|
||||
const reg_pubkey = txRegisterReceipt.events[0].args.pubkey;
|
||||
const reg_tree_index = txRegisterReceipt.events[0].args.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}`);
|
||||
});
|
||||
// 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");
|
||||
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue