diff --git a/__mocks__/@react-native-async-storage/async-storage.js b/__mocks__/@react-native-async-storage/async-storage.ts similarity index 100% rename from __mocks__/@react-native-async-storage/async-storage.js rename to __mocks__/@react-native-async-storage/async-storage.ts diff --git a/__mocks__/react-native-image-picker.js b/__mocks__/react-native-image-picker.ts similarity index 100% rename from __mocks__/react-native-image-picker.js rename to __mocks__/react-native-image-picker.ts diff --git a/__mocks__/react-native-localize.js b/__mocks__/react-native-localize.ts similarity index 100% rename from __mocks__/react-native-localize.js rename to __mocks__/react-native-localize.ts diff --git a/__mocks__/react-native-tor.js b/__mocks__/react-native-tor.ts similarity index 95% rename from __mocks__/react-native-tor.js rename to __mocks__/react-native-tor.ts index d4bf7deed..e8e933d02 100644 --- a/__mocks__/react-native-tor.js +++ b/__mocks__/react-native-tor.ts @@ -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; \ No newline at end of file +export default mock; diff --git a/tests/unit/addresses.test.js b/tests/unit/addresses.test.ts similarity index 94% rename from tests/unit/addresses.test.js rename to tests/unit/addresses.test.ts index a2c4fee26..c613ad704 100644 --- a/tests/unit/addresses.test.js +++ b/tests/unit/addresses.test.ts @@ -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: [{}] }, diff --git a/tests/unit/bip38.test.js b/tests/unit/bip38.test.ts similarity index 100% rename from tests/unit/bip38.test.js rename to tests/unit/bip38.test.ts diff --git a/tests/unit/checksumWords.test.js b/tests/unit/checksumWords.test.ts similarity index 90% rename from tests/unit/checksumWords.test.js rename to tests/unit/checksumWords.test.ts index e7d5f7a4a..07edb8464 100644 --- a/tests/unit/checksumWords.test.js +++ b/tests/unit/checksumWords.test.ts @@ -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); diff --git a/tests/unit/currency.test.js b/tests/unit/currency.test.ts similarity index 98% rename from tests/unit/currency.test.js rename to tests/unit/currency.test.ts index 29e1627d1..5a1c07432 100644 --- a/tests/unit/currency.test.js +++ b/tests/unit/currency.test.ts @@ -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 () => { diff --git a/tests/unit/ecc.test.js b/tests/unit/ecc.test.ts similarity index 95% rename from tests/unit/ecc.test.js rename to tests/unit/ecc.test.ts index 0c97eabe8..c698fb24d 100644 --- a/tests/unit/ecc.test.js +++ b/tests/unit/ecc.test.ts @@ -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', () => { diff --git a/tests/unit/encryption.test.js b/tests/unit/encryption.test.ts similarity index 95% rename from tests/unit/encryption.test.js rename to tests/unit/encryption.test.ts index bac202242..566e97c47 100644 --- a/tests/unit/encryption.test.js +++ b/tests/unit/encryption.test.ts @@ -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 () { diff --git a/tests/unit/hd-legacy-electrum-seed-p2pkh-wallet.test.js b/tests/unit/hd-legacy-electrum-seed-p2pkh-wallet.test.ts similarity index 100% rename from tests/unit/hd-legacy-electrum-seed-p2pkh-wallet.test.js rename to tests/unit/hd-legacy-electrum-seed-p2pkh-wallet.test.ts diff --git a/tests/unit/hd-segwit-electrum-seed-p2wpkh-wallet.test.js b/tests/unit/hd-segwit-electrum-seed-p2wpkh-wallet.test.ts similarity index 99% rename from tests/unit/hd-segwit-electrum-seed-p2wpkh-wallet.test.js rename to tests/unit/hd-segwit-electrum-seed-p2wpkh-wallet.test.ts index 95a056e11..218a1026d 100644 --- a/tests/unit/hd-segwit-electrum-seed-p2wpkh-wallet.test.js +++ b/tests/unit/hd-segwit-electrum-seed-p2wpkh-wallet.test.ts @@ -1,5 +1,5 @@ import { HDSegwitElectrumSeedP2WPKHWallet } from '../../class'; -const assert = require('assert'); +import assert from 'assert'; describe('HDSegwitElectrumSeedP2WPKHWallet', () => { it('wont accept BIP39 seed', () => { diff --git a/tests/unit/hd-segwit-p2sh-wallet.test.js b/tests/unit/hd-segwit-p2sh-wallet.test.ts similarity index 94% rename from tests/unit/hd-segwit-p2sh-wallet.test.js rename to tests/unit/hd-segwit-p2sh-wallet.test.ts index 5d1141f44..de9ce3297 100644 --- a/tests/unit/hd-segwit-p2sh-wallet.test.js +++ b/tests/unit/hd-segwit-p2sh-wallet.test.ts @@ -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 = {}; 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, ); diff --git a/tests/unit/lightning-ldk-wallet.test.js b/tests/unit/lightning-ldk-wallet.test.ts similarity index 97% rename from tests/unit/lightning-ldk-wallet.test.js rename to tests/unit/lightning-ldk-wallet.test.ts index 0aa848083..6635e230d 100644 --- a/tests/unit/lightning-ldk-wallet.test.js +++ b/tests/unit/lightning-ldk-wallet.test.ts @@ -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); } diff --git a/tests/unit/taproot-wallet.test.js b/tests/unit/taproot-wallet.test.ts similarity index 85% rename from tests/unit/taproot-wallet.test.js rename to tests/unit/taproot-wallet.test.ts index ba9a58989..d37de6278 100644 --- a/tests/unit/taproot-wallet.test.js +++ b/tests/unit/taproot-wallet.test.ts @@ -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);