Skip to content

Commit 02be024

Browse files
committed
Add tests for decodeRecoveryKey
1 parent 6a59684 commit 02be024

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

spec/unit/rust-crypto/recovery-key.spec.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,26 @@ import { decodeRecoveryKey, encodeRecoveryKey } from "../../../src/crypto-api";
1818

1919
describe("recovery key", () => {
2020
describe("decodeRecoveryKey", () => {
21-
it("should thrown an incorrect parity", () => {
22-
expect(() => decodeRecoveryKey("alice")).toThrow("Incorrect parity");
23-
});
24-
2521
it("should thrown an incorrect length error", () => {
2622
const key = [0, 1];
27-
const encodedKey = encodeRecoveryKey(key);
23+
const encodedKey = encodeRecoveryKey(key)!;
24+
25+
expect(() => decodeRecoveryKey(encodedKey)).toThrow("Incorrect length");
26+
});
27+
28+
it("should thrown an incorrect parity", () => {
29+
const key = Array.from({ length: 32 }, (_, i) => i);
30+
let encodedKey = encodeRecoveryKey(key)!;
31+
encodedKey = encodedKey.replace("EsSz", "EsSZ");
2832

29-
expect(() => decodeRecoveryKey(encodedKey!)).toThrow("Incorrect length");
33+
expect(() => decodeRecoveryKey(encodedKey!)).toThrow("Incorrect parity");
3034
});
3135

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

36-
expect(decodeRecoveryKey(encodedKey!)).toEqual(new Uint8Array(key));
40+
expect(decodeRecoveryKey(encodedKey)).toEqual(new Uint8Array(key));
3741
});
3842
});
3943
});

0 commit comments

Comments
 (0)