-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reactive): provide deterministic randomness
- Loading branch information
Showing
4 changed files
with
41 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions
18
...l-stream/src/test/mocks/crypto-context.ts → ...eactive/src/mocks/deterministic-crypto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/lib-reactive/src/test/deterministic-crypto.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { uint8ArrayToHex } from "uint8array-extras" | ||
import { describe, test } from "vitest" | ||
|
||
import { createMockDeterministicCrypto } from "../mocks/deterministic-crypto" | ||
import type { Crypto } from "../types/base-modules/crypto" | ||
|
||
describe("Deterministic Crypto", () => { | ||
test("should generate (not so) random bytes", ({ expect }) => { | ||
const crypto = createMockDeterministicCrypto({} as Crypto) | ||
const randomNumber = crypto.getRandomBytes(32) | ||
expect(uint8ArrayToHex(randomNumber)).toMatchInlineSnapshot( | ||
`"1f0796160c164e1fdcc306caed8497f7c424a4e4d66f5653f50d1f35e47638d9"`, | ||
) | ||
}) | ||
|
||
test("should generate (not so) random bytes of a length that is not a multiple of 4", ({ | ||
expect, | ||
}) => { | ||
const crypto = createMockDeterministicCrypto({} as Crypto) | ||
const randomNumber = crypto.getRandomBytes(31) | ||
expect(uint8ArrayToHex(randomNumber)).toMatchInlineSnapshot( | ||
`"1f0796160c164e1fdcc306caed8497f7c424a4e4d66f5653f50d1f35e47638"`, | ||
) | ||
}) | ||
}) |