Skip to content
This repository was archived by the owner on Dec 9, 2023. It is now read-only.

Commit 4f71c98

Browse files
committed
fix hash mocking method
1 parent 6f625c8 commit 4f71c98

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/store_mocks.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ export const scheduler = (t) => {
4444

4545
// @see https://crates.io/crates/holo_hash
4646
const HOLOCHAIN_RAW_IDENTIFIER_LEN = 36
47+
const HOLOCHAIN_FULL_IDENTIFIER_LEN = 39
4748
// @see holo_hash::hash_type::primitive
4849
const HOLOHASH_PREFIX_DNA = Uint8Array.of(0x84, 0x2d, 0x24) // uhC0k
4950
const HOLOHASH_PREFIX_ENTRY = Uint8Array.of(0x84, 0x21, 0x24) // uhCEk
5051
// const HOLOHASH_PREFIX_HEADER = Uint8Array.of(0x84, 0x29, 0x24) // uhCkk
5152
const HOLOHASH_PREFIX_AGENT = Uint8Array.of(0x84, 0x20, 0x24) // uhCAk
5253

53-
function concatenate(...arrays) {
54+
function concatenate(...arrays): Uint8Array {
5455
// Calculate byteSize from all arrays
5556
let size = arrays.reduce((a, b) => a + b.byteLength, 0)
5657
// Allcolate a new buffer
@@ -66,13 +67,12 @@ function concatenate(...arrays) {
6667
return result
6768
}
6869

69-
const mockHash = (prefix) =>
70-
Buffer.from(
71-
concatenate(
72-
prefix,
73-
randomBytes(HOLOCHAIN_RAW_IDENTIFIER_LEN).buffer,
74-
),
75-
) as Uint8Array
70+
const mockHash = (prefix) => {
71+
let result = new Uint8Array(HOLOCHAIN_FULL_IDENTIFIER_LEN)
72+
result.set(prefix, 0)
73+
result.set(Buffer.from(randomBytes(HOLOCHAIN_RAW_IDENTIFIER_LEN).buffer, 3))
74+
return result
75+
}
7676

7777
export const mockEh = () => mockHash(HOLOHASH_PREFIX_ENTRY)
7878
export const mockAgentKey = () => mockHash(HOLOHASH_PREFIX_AGENT)

0 commit comments

Comments
 (0)