From d672499d7cf7c9862ebdbc6331f574deee81e6d9 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 31 Aug 2026 23:11:12 -0700 Subject: [PATCH] Migrate build tests to their own file. --- src/assembly/index.ts | 1 + src/assembly/tests.ts | 21 +++++++++++++++++++++ src/assembly/utils.ts | 13 ------------- 3 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 src/assembly/tests.ts diff --git a/src/assembly/index.ts b/src/assembly/index.ts index 278d5a1..83fc5f7 100644 --- a/src/assembly/index.ts +++ b/src/assembly/index.ts @@ -5,6 +5,7 @@ import { crypto_derive } from './crypto_derive' import { crypto_sign } from './crypto_sign' import { crypto_verify_decodepubkey, crypto_verify_relaxed, crypto_verify_strict } from './crypto_verify' import { errors } from './errors' +import './tests' export const BLOCKHASH_BYTELENGTH: i32 = 32 export const KEY_BYTELENGTH: i32 = 32 diff --git a/src/assembly/tests.ts b/src/assembly/tests.ts new file mode 100644 index 0000000..fef7ee7 --- /dev/null +++ b/src/assembly/tests.ts @@ -0,0 +1,21 @@ +//! SPDX-FileCopyrightText: 2026 Chris Duncan +//! SPDX-License-Identifier: GPL-3.0-or-later + +import { equalbytes } from './utils' + +/** + * Tests run on initialization to ensure build is correct. + */ +const testbytesA = new StaticArray(32).fill(0) +const testbytesB = new StaticArray(32).fill(0) + +/** equalbytes */ +for (let i = 0; i < 32; i++) { + for (let j: u8 = 0; j < 8; j++) { + testbytesA[i] = 1 << j + if (equalbytes(testbytesA, testbytesB, 32)) { + throw new Error('equalbytes failed build test') + } + testbytesA[i] = 0 + } +} diff --git a/src/assembly/utils.ts b/src/assembly/utils.ts index 91140a0..16ff44f 100644 --- a/src/assembly/utils.ts +++ b/src/assembly/utils.ts @@ -76,16 +76,3 @@ export function sodium_is_zero (n: StaticArray, nlen: i32): u8 { d &= 255 return u8(((d - 1) >> 8) & 1) } - -/** Unit tests on initialization */ -const testbytesA = new StaticArray(32).fill(0) -const testbytesB = new StaticArray(32).fill(0) -for (let i = 0; i < 32; i++) { - for (let j: u8 = 0; j < 8; j++) { - testbytesA[i] = 1 << j - if (equalbytes(testbytesA, testbytesB, 32)) { - throw new Error('equalbytes failed unit test') - } - testbytesA[i] = 0 - } -} -- 2.52.0