Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions config/eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
];

Expand Down
2 changes: 0 additions & 2 deletions src/operation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-bitwise */

import { Hyper } from "@stellar/js-xdr";
import BigNumber from "./util/bignumber";
import { trimEnd } from "./util/util";
Expand Down
2 changes: 0 additions & 2 deletions src/operations/set_options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-param-reassign */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous eslint config used a stricter rule set


import xdr from "../xdr";
import { Keypair } from "../keypair";
import { StrKey } from "../strkey";
Expand Down
5 changes: 4 additions & 1 deletion src/util/checksum.js → src/util/checksum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export function verifyChecksum(expected, actual) {
export function verifyChecksum(
expected: Uint8Array,
actual: Uint8Array
): boolean {
if (expected.length !== actual.length) {
return false;
}
Expand Down
44 changes: 44 additions & 0 deletions test/unit/util/checksum.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"noUncheckedIndexedAccess": true,

// JavaScript support
"allowJs": true,
"allowJs": false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll have mixed JS and TS files for a while, is it OK to disable it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose to disable this so that it would be easier to review the generation type declaration files. With this flag set to true the tsc compiler will generate declaration files for all js files.

"checkJs": false,

// Interop constraints
Expand Down
4 changes: 3 additions & 1 deletion tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"rootDir": "./src",
"module": "commonjs",
"moduleResolution": "node10",
"esModuleInterop": true
"esModuleInterop": true,
"declaration": true,
"declarationDir": "./type_validation"
}
}
1 change: 1 addition & 0 deletions type_validation/util/checksum.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function verifyChecksum(expected: Uint8Array, actual: Uint8Array): boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to create these manually for every file we migrate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is generated by tsc

Loading