mirror of
https://github.com/logos-messaging/logos-delivery-js.git
synced 2026-03-13 13:13:08 +00:00
* chore: update ABI * chore: update contract address and chain ID to Linea Sepolia * chore: improve error handling * fix: bigint conversion * chore: update tests * chore: clean comments * chore: export keystore types * chore: update README with contract address * tests: add reusable mock functions * chore: LINEA_CONTRACT instead of SEPOLIA_CONTRACT * chore: add linea to cspell * chore: add rateLimit to MembershipInfo * fix: determine start options * feat: RLNLight * chore: fix * chore: export * fix: returns for ratelimit * chore: big number conversions * chore: rename RLNLight to CredentialsManager, add logs * chore: setup and use rln_base_contract * chore: use CredentialsManager for rln.ts * chore: public methods written above private methods * fix: rate limit getter * chore: simplify getters/setters * chore: insert empty line
91 lines
2.4 KiB
TypeScript
91 lines
2.4 KiB
TypeScript
import { hexToBytes } from "@waku/utils/bytes";
|
|
import { expect, use } from "chai";
|
|
import chaiAsPromised from "chai-as-promised";
|
|
import * as ethers from "ethers";
|
|
import sinon, { SinonSandbox } from "sinon";
|
|
|
|
import { createTestRLNInstance, initializeRLNContract } from "./test-setup.js";
|
|
import {
|
|
createMockRegistryContract,
|
|
createRegisterStub,
|
|
mockRLNRegisteredEvent,
|
|
verifyRegistration
|
|
} from "./test-utils.js";
|
|
|
|
use(chaiAsPromised);
|
|
|
|
describe("RLN Contract abstraction - RLN", () => {
|
|
let sandbox: SinonSandbox;
|
|
|
|
beforeEach(async () => {
|
|
sandbox = sinon.createSandbox();
|
|
});
|
|
|
|
afterEach(() => {
|
|
sandbox.restore();
|
|
});
|
|
|
|
describe("Member Registration", () => {
|
|
it("should fetch members from events and store them in the RLN instance", async () => {
|
|
const { rlnInstance, insertMemberSpy } = await createTestRLNInstance();
|
|
const membershipRegisteredEvent = mockRLNRegisteredEvent();
|
|
const queryFilterStub = sinon.stub().returns([membershipRegisteredEvent]);
|
|
|
|
const mockedRegistryContract = createMockRegistryContract({
|
|
queryFilter: queryFilterStub
|
|
});
|
|
|
|
const rlnContract = await initializeRLNContract(
|
|
rlnInstance,
|
|
mockedRegistryContract
|
|
);
|
|
|
|
await rlnContract.fetchMembers({
|
|
fromBlock: 0,
|
|
fetchRange: 1000,
|
|
fetchChunks: 2
|
|
});
|
|
|
|
expect(
|
|
insertMemberSpy.calledWith(
|
|
ethers.utils.zeroPad(
|
|
hexToBytes(membershipRegisteredEvent.args!.idCommitment),
|
|
32
|
|
)
|
|
)
|
|
).to.be.true;
|
|
expect(queryFilterStub.called).to.be.true;
|
|
});
|
|
|
|
it("should register a member", async () => {
|
|
const { rlnInstance, identity, insertMemberSpy } =
|
|
await createTestRLNInstance();
|
|
|
|
const registerStub = createRegisterStub(identity);
|
|
const mockedRegistryContract = createMockRegistryContract({
|
|
register: registerStub,
|
|
queryFilter: () => []
|
|
});
|
|
|
|
const rlnContract = await initializeRLNContract(
|
|
rlnInstance,
|
|
mockedRegistryContract
|
|
);
|
|
|
|
const decryptedCredentials =
|
|
await rlnContract.registerWithIdentity(identity);
|
|
|
|
if (!decryptedCredentials) {
|
|
throw new Error("Failed to retrieve credentials");
|
|
}
|
|
|
|
verifyRegistration(
|
|
decryptedCredentials,
|
|
identity,
|
|
registerStub,
|
|
insertMemberSpy
|
|
);
|
|
});
|
|
});
|
|
});
|