Skip to content
Draft
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"prepare": "npm run build",
"pretty": "prettier --config ./.prettierrc.json --check \"**/*.{ts,json}\"",
"pretty:fix": "prettier --config ./.prettierrc.json --write \"**/*.{ts,json}\"",
"lint": "eslint . --ext .ts"
"lint": "eslint . --ext .ts",
"test": "ts-node ./test/nonceUtils.test.ts"
}
}
30 changes: 30 additions & 0 deletions test/nonceUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import assert from 'assert';
import { NonceUtils } from '../lib/utils/nonceUtils';
import { NonceType } from '../lib/interfaces';

// Mock Query object with only getAnchorNonce implemented
const mockQuery = {
getAnchorNonce: async (chainId: string): Promise<string> => `anchor-${chainId}`
} as any;

(async () => {
// Expect error when chainId is missing
let threw = false;
try {
NonceUtils.createNonceFetcher({ nonceType: NonceType.Anchor, nonceParams: {} }, mockQuery);
} catch (err) {
threw = true;
}
assert.ok(threw, 'Expected error when chainId is missing');

// Expect returned function to call getAnchorNonce with provided chainId
const fetcher = NonceUtils.createNonceFetcher(
{ nonceType: NonceType.Anchor, nonceParams: { chainId: '5' } },
mockQuery
);
const value = await fetcher();
assert.strictEqual(value, 'anchor-5');

console.log('All tests passed');
})();