REF: few unit tests to TS

This commit is contained in:
abhishandy 2024-03-05 19:30:47 -05:00 committed by Overtorment
parent bdc0df4c43
commit 40e7577117
15 changed files with 25 additions and 26 deletions

View File

@ -4,7 +4,6 @@ export const startIfNotStarted = jest.fn(async (key, value, callback) => {
return 666;
});
export const get = jest.fn();
export const post = jest.fn();
export const deleteMock = jest.fn();
@ -15,4 +14,4 @@ const mock = jest.fn().mockImplementation(() => {
return { startIfNotStarted, get, post, delete: deleteMock, stopIfRunning, getDaemonStatus };
});
export default mock;
export default mock;

View File

@ -70,8 +70,8 @@ describe('Addresses', () => {
it('Returns AddressItem object', () => {
const fakeWallet = {
_getExternalAddressByIndex: index => `external_address_${index}`,
_getInternalAddressByIndex: index => `internal_address_${index}`,
_getExternalAddressByIndex: (index: number) => `external_address_${index}`,
_getInternalAddressByIndex: (index: number) => `internal_address_${index}`,
_balances_by_external_index: [{ c: 0, u: 0 }],
_balances_by_internal_index: [{ c: 0, u: 0 }],
_txs_by_external_index: { 0: [{}] },

View File

@ -1,11 +1,11 @@
import { generateChecksumWords } from '../../blue_modules/checksumWords';
import { validateMnemonic } from '../../blue_modules/bip39';
const assert = require('assert');
import assert from 'assert';
describe('generateChecksumWords', () => {
it('generates 128 valid words for an 11 word input', () => {
const input = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon';
const result = generateChecksumWords(input);
const result = generateChecksumWords(input) as string[];
assert.ok(result);
assert.strictEqual(result.length, 128);
@ -18,7 +18,7 @@ describe('generateChecksumWords', () => {
const input =
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon ' +
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon';
const result = generateChecksumWords(input);
const result = generateChecksumWords(input) as string[];
assert.ok(result);
assert.strictEqual(result.length, 8);

View File

@ -6,7 +6,7 @@ import {
satoshiToLocalCurrency,
} from '../../blue_modules/currency';
import { FiatUnit } from '../../models/fiatUnit';
const assert = require('assert');
import assert from 'assert';
describe('currency', () => {
it('formats everything correctly', async () => {

View File

@ -1,8 +1,8 @@
import ecc from '../../blue_modules/noble_ecc';
import { ECPairFactory } from 'ecpair';
const assert = require('assert');
import assert from 'assert';
const h = hex => Buffer.from(hex, 'hex');
const h = (hex: string) => Buffer.from(hex, 'hex');
describe('ecc', () => {
it('ECPair accepts noble', () => {

View File

@ -1,5 +1,5 @@
const assert = require('assert');
const c = require('../../blue_modules/encryption');
import assert from 'assert';
import * as c from '../../blue_modules/encryption';
describe('unit - encryption', function () {
it('encrypts and decrypts', function () {

View File

@ -1,5 +1,5 @@
import { HDSegwitElectrumSeedP2WPKHWallet } from '../../class';
const assert = require('assert');
import assert from 'assert';
describe('HDSegwitElectrumSeedP2WPKHWallet', () => {
it('wont accept BIP39 seed', () => {

View File

@ -38,35 +38,35 @@ describe('P2SH Segwit HD (BIP49)', () => {
it('can convert witness to address', () => {
let address = SegwitP2SHWallet.witnessToAddress('035c618df829af694cb99e664ce1b34f80ad2c3b49bcd0d9c0b1836c66b2d25fd8');
assert.strictEqual(address, '34ZVGb3gT8xMLT6fpqC6dNVqJtJmvdjbD7');
address = SegwitP2SHWallet.witnessToAddress();
address = SegwitP2SHWallet.witnessToAddress('');
assert.strictEqual(address, false);
address = SegwitP2SHWallet.witnessToAddress('trololo');
assert.strictEqual(address, false);
address = SegwitP2SHWallet.scriptPubKeyToAddress('a914e286d58e53f9247a4710e51232cce0686f16873c87');
assert.strictEqual(address, '3NLnALo49CFEF4tCRhCvz45ySSfz3UktZC');
address = SegwitP2SHWallet.scriptPubKeyToAddress();
address = SegwitP2SHWallet.scriptPubKeyToAddress('');
assert.strictEqual(address, false);
address = SegwitP2SHWallet.scriptPubKeyToAddress('trololo');
assert.strictEqual(address, false);
address = SegwitBech32Wallet.witnessToAddress('035c618df829af694cb99e664ce1b34f80ad2c3b49bcd0d9c0b1836c66b2d25fd8');
assert.strictEqual(address, 'bc1quhnve8q4tk3unhmjts7ymxv8cd6w9xv8wy29uv');
address = SegwitBech32Wallet.witnessToAddress();
address = SegwitBech32Wallet.witnessToAddress('');
assert.strictEqual(address, false);
address = SegwitBech32Wallet.witnessToAddress('trololo');
assert.strictEqual(address, false);
address = SegwitBech32Wallet.scriptPubKeyToAddress('00144d757460da5fcaf84cc22f3847faaa1078e84f6a');
assert.strictEqual(address, 'bc1qf46hgcx6tl90snxz9uuy0742zpuwsnm27ysdh7');
address = SegwitBech32Wallet.scriptPubKeyToAddress();
address = SegwitBech32Wallet.scriptPubKeyToAddress('');
assert.strictEqual(address, false);
address = SegwitBech32Wallet.scriptPubKeyToAddress('trololo');
assert.strictEqual(address, false);
address = LegacyWallet.scriptPubKeyToAddress('76a914d0b77eb1502c81c4093da9aa6eccfdf560cdd6b288ac');
assert.strictEqual(address, '1L2bNMGRQQLT2AVUek4K9L7sn3SSMioMgE');
address = LegacyWallet.scriptPubKeyToAddress();
address = LegacyWallet.scriptPubKeyToAddress('');
assert.strictEqual(address, false);
address = LegacyWallet.scriptPubKeyToAddress('trololo');
assert.strictEqual(address, false);
@ -86,7 +86,7 @@ describe('P2SH Segwit HD (BIP49)', () => {
it('can generate Segwit HD (BIP49)', async () => {
const hd = new HDSegwitP2SHWallet();
const hashmap = {};
const hashmap: Record<string, number> = {};
for (let c = 0; c < 1000; c++) {
await hd.generate();
const secret = hd.getSecret();
@ -156,11 +156,11 @@ describe('P2SH Segwit HD (BIP49)', () => {
const secret = hd.getSecret();
assert.strictEqual(secret.startsWith('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon'), true);
let secretWithoutChecksum = secret.split(' ');
const secretWithoutChecksum = secret.split(' ');
secretWithoutChecksum.pop();
secretWithoutChecksum = secretWithoutChecksum.join(' ');
const secretWithoutChecksumString = secretWithoutChecksum.join(' ');
assert.strictEqual(
secretWithoutChecksum.endsWith('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon'),
secretWithoutChecksumString.endsWith('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon'),
false,
);

View File

@ -1,8 +1,8 @@
import { HDSegwitBech32Wallet, LightningLdkWallet } from '../../class';
const assert = require('assert');
import assert from 'assert';
describe('', () => {
function isHex(h) {
function isHex(h: string) {
const re = /[0-9A-Fa-f]{6}/g;
return re.test(h);
}

View File

@ -1,11 +1,11 @@
import { TaprootWallet } from '../../class';
const assert = require('assert');
import assert from 'assert';
describe('Taproot wallet', () => {
it('can convert scriptPubKey to address', () => {
let address = TaprootWallet.scriptPubKeyToAddress('512040ef293a8a0ebaf8b351a27d89ff4b5b3822a635e4afdca77a30170c363bafa3');
assert.strictEqual(address, 'bc1pgrhjjw52p6a03v635f7cnl6ttvuz9f34ujhaefm6xqtscd3m473szkl92g');
address = TaprootWallet.scriptPubKeyToAddress();
address = TaprootWallet.scriptPubKeyToAddress('');
assert.strictEqual(address, false);
address = TaprootWallet.scriptPubKeyToAddress('trololo');
assert.strictEqual(address, false);