From 610d2da7b38ad327d2c28c325b0eb103ef80c6bf Mon Sep 17 00:00:00 2001 From: Ryan Yang Date: Mon, 9 Feb 2026 15:28:35 -0800 Subject: [PATCH 1/4] Add test globals to ESLint configuration --- config/eslint.config.cjs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/config/eslint.config.cjs b/config/eslint.config.cjs index 48060a321..8eca0ac52 100644 --- a/config/eslint.config.cjs +++ b/config/eslint.config.cjs @@ -44,6 +44,19 @@ const javascriptConfig = [ rules: { "no-unused-vars": ["error", { caughtErrors: "none" }] } + }, + { + name: "test/globals", + files: ["test/**/*.js"], + languageOptions: { + globals: { + ...globals.mocha, + StellarBase: "readonly", + expect: "readonly", + chai: "readonly", + sinon: "readonly" + } + } } ]; From d7453c7c62d0e794ce353d317f686115b24ec7ed Mon Sep 17 00:00:00 2001 From: Ryan Yang Date: Mon, 9 Feb 2026 15:31:07 -0800 Subject: [PATCH 2/4] modify tsconfigs for better reviewing experience --- tsconfig.base.json | 2 +- tsconfig.cjs.json | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tsconfig.base.json b/tsconfig.base.json index 78b812a2a..3a57d47d7 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -19,7 +19,7 @@ "noUncheckedIndexedAccess": true, // JavaScript support - "allowJs": true, + "allowJs": false, "checkJs": false, // Interop constraints diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json index 4af0c5479..77eb6657b 100644 --- a/tsconfig.cjs.json +++ b/tsconfig.cjs.json @@ -10,6 +10,8 @@ "rootDir": "./src", "module": "commonjs", "moduleResolution": "node10", - "esModuleInterop": true + "esModuleInterop": true, + "declaration": true, + "declarationDir": "./type_validation" } } From 21f1d4ed218717d23bd09fce48e40dc2c4b85112 Mon Sep 17 00:00:00 2001 From: Ryan Yang Date: Mon, 9 Feb 2026 15:32:40 -0800 Subject: [PATCH 3/4] migrate util/checksum.js and add typescript testing --- src/util/{checksum.js => checksum.ts} | 5 ++- test/unit/util/checksum.test.ts | 44 +++++++++++++++++++++++++++ type_validation/util/checksum.d.ts | 1 + 3 files changed, 49 insertions(+), 1 deletion(-) rename src/util/{checksum.js => checksum.ts} (73%) create mode 100644 test/unit/util/checksum.test.ts create mode 100644 type_validation/util/checksum.d.ts diff --git a/src/util/checksum.js b/src/util/checksum.ts similarity index 73% rename from src/util/checksum.js rename to src/util/checksum.ts index 4358eb761..8b8d71e35 100644 --- a/src/util/checksum.js +++ b/src/util/checksum.ts @@ -1,4 +1,7 @@ -export function verifyChecksum(expected, actual) { +export function verifyChecksum( + expected: Uint8Array, + actual: Uint8Array +): boolean { if (expected.length !== actual.length) { return false; } diff --git a/test/unit/util/checksum.test.ts b/test/unit/util/checksum.test.ts new file mode 100644 index 000000000..392e8b984 --- /dev/null +++ b/test/unit/util/checksum.test.ts @@ -0,0 +1,44 @@ +import { describe, it, expect } from "vitest"; +import { verifyChecksum } from "../../../src/util/checksum"; + +describe("verifyChecksum", () => { + it("returns true for identical arrays", () => { + const a = new Uint8Array([1, 2, 3]); + const b = new Uint8Array([1, 2, 3]); + expect(verifyChecksum(a, b)).toBe(true); + }); + + it("returns false for different contents", () => { + const a = new Uint8Array([1, 2, 3]); + const b = new Uint8Array([1, 2, 4]); + expect(verifyChecksum(a, b)).toBe(false); + }); + + it("returns false for different lengths", () => { + const a = new Uint8Array([1, 2, 3]); + const b = new Uint8Array([1, 2]); + expect(verifyChecksum(a, b)).toBe(false); + }); + + it("returns true for two empty arrays", () => { + expect(verifyChecksum(new Uint8Array([]), new Uint8Array([]))).toBe(true); + }); + + it("returns true for single matching byte", () => { + expect(verifyChecksum(new Uint8Array([0xff]), new Uint8Array([0xff]))).toBe( + true + ); + }); + + it("returns false when first byte differs", () => { + const a = new Uint8Array([0, 2, 3]); + const b = new Uint8Array([1, 2, 3]); + expect(verifyChecksum(a, b)).toBe(false); + }); + + it("returns false when last byte differs", () => { + const a = new Uint8Array([1, 2, 3]); + const b = new Uint8Array([1, 2, 0]); + expect(verifyChecksum(a, b)).toBe(false); + }); +}); diff --git a/type_validation/util/checksum.d.ts b/type_validation/util/checksum.d.ts new file mode 100644 index 000000000..935cb048d --- /dev/null +++ b/type_validation/util/checksum.d.ts @@ -0,0 +1 @@ +export declare function verifyChecksum(expected: Uint8Array, actual: Uint8Array): boolean; From 062619ca9a36f16c10779cce1604fb1adf4c35a1 Mon Sep 17 00:00:00 2001 From: Ryan Yang Date: Mon, 9 Feb 2026 15:33:00 -0800 Subject: [PATCH 4/4] fix lint warnings --- src/operation.js | 2 -- src/operations/set_options.js | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/operation.js b/src/operation.js index eb85aaa5e..5b4162dda 100644 --- a/src/operation.js +++ b/src/operation.js @@ -1,5 +1,3 @@ -/* eslint-disable no-bitwise */ - import { Hyper } from "@stellar/js-xdr"; import BigNumber from "./util/bignumber"; import { trimEnd } from "./util/util"; diff --git a/src/operations/set_options.js b/src/operations/set_options.js index 8cae8e49c..57e6ed857 100644 --- a/src/operations/set_options.js +++ b/src/operations/set_options.js @@ -1,5 +1,3 @@ -/* eslint-disable no-param-reassign */ - import xdr from "../xdr"; import { Keypair } from "../keypair"; import { StrKey } from "../strkey";