Skip to content

Commit

Permalink
Add tests for decodeRecoveryKey
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Sep 12, 2024
1 parent 6a59684 commit 02be024
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions spec/unit/rust-crypto/recovery-key.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,26 @@ import { decodeRecoveryKey, encodeRecoveryKey } from "../../../src/crypto-api";

describe("recovery key", () => {
describe("decodeRecoveryKey", () => {
it("should thrown an incorrect parity", () => {
expect(() => decodeRecoveryKey("alice")).toThrow("Incorrect parity");
});

it("should thrown an incorrect length error", () => {
const key = [0, 1];
const encodedKey = encodeRecoveryKey(key);
const encodedKey = encodeRecoveryKey(key)!;

expect(() => decodeRecoveryKey(encodedKey)).toThrow("Incorrect length");
});

it("should thrown an incorrect parity", () => {
const key = Array.from({ length: 32 }, (_, i) => i);
let encodedKey = encodeRecoveryKey(key)!;
encodedKey = encodedKey.replace("EsSz", "EsSZ");

expect(() => decodeRecoveryKey(encodedKey!)).toThrow("Incorrect length");
expect(() => decodeRecoveryKey(encodedKey!)).toThrow("Incorrect parity");
});

it("should decode a valid encoded key", () => {
const key = Array.from({ length: 32 }, (_, i) => i);
const encodedKey = encodeRecoveryKey(key);
const encodedKey = encodeRecoveryKey(key)!;

expect(decodeRecoveryKey(encodedKey!)).toEqual(new Uint8Array(key));
expect(decodeRecoveryKey(encodedKey)).toEqual(new Uint8Array(key));
});
});
});

0 comments on commit 02be024

Please sign in to comment.