REF: tests to ts

This commit is contained in:
overtorment 2024-02-25 13:13:45 +00:00 committed by Overtorment
parent 0aa390acae
commit 2ebf7d8147
2 changed files with 15 additions and 6 deletions

View file

@ -3,9 +3,10 @@ import * as bitcoin from 'bitcoinjs-lib';
import { HDLegacyBreadwalletWallet } from '../../class';
import * as BlueElectrum from '../../blue_modules/BlueElectrum';
import { AbstractHDElectrumWallet } from '../../class/wallets/abstract-hd-electrum-wallet';
jest.setTimeout(300 * 1000);
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
afterAll(async () => {
// after all tests we close socket so the test suite can actually terminate
@ -52,8 +53,12 @@ it('Legacy HD Breadwallet can fetch utxo, balance, and create transaction', asyn
[{ address: 'bc1q47efz9aav8g4mnnz9r6ql4pf48phy3g509p7gx' }],
1,
'bc1qk9hvkxqsqmps6ex3qawr79rvtg8es4ecjfu5v0',
AbstractHDElectrumWallet.defaultRBFSequence,
false,
0,
);
assert.ok(tx);
const transaction = bitcoin.Transaction.fromHex(tx.toHex());
assert.ok(transaction.ins.length === 4);
assert.strictEqual(transaction.outs.length, 1);

View file

@ -32,6 +32,7 @@ describe('LegacyWallet', function () {
w._address = '115fUy41sZkAG14CmdP1VbEKcNRZJWkUWG'; // hack internals
assert.ok(w.weOwnAddress('115fUy41sZkAG14CmdP1VbEKcNRZJWkUWG'));
assert.ok(!w.weOwnAddress('aaa'));
// @ts-ignore wrong type on purpose
assert.ok(!w.weOwnAddress(false));
assert.ok(w.getBalance() === 0);
assert.ok(w.getUnconfirmedBalance() === 0);
@ -52,7 +53,7 @@ describe('LegacyWallet', function () {
assert.ok(tx.hash);
assert.ok(tx.value);
assert.ok(tx.received);
assert.ok(tx.confirmations > 1);
assert.ok(tx.confirmations! > 1);
}
assert.ok(w.weOwnTransaction('b2ac59bc282083498d1e87805d89bef9d3f3bc216c1d2c4dfaa2e2911b547100'));
@ -66,7 +67,7 @@ describe('LegacyWallet', function () {
assert.strictEqual(tx.address, '3GCvDBAktgQQtsbN6x5DYiQCMmgZ9Yk8BK');
assert.strictEqual(tx.value, 51432);
assert.strictEqual(tx.value, tx.amount);
assert.ok(tx.confirmations > 0);
assert.ok(tx.confirmations! > 0);
}
});
@ -88,7 +89,7 @@ describe('LegacyWallet', function () {
assert.ok(tx.hash);
assert.ok(tx.value);
assert.ok(tx.received);
assert.ok(tx.confirmations > 1);
assert.ok(tx.confirmations! > 1);
}
},
240000,
@ -117,6 +118,7 @@ describe('SegwitP2SHWallet', function () {
assert.ok(l.getAddress() === (await l.getAddressAsync()));
assert.ok(l.weOwnAddress('34AgLJhwXrvmkZS1o5TrcdeevMt22Nar53'));
assert.ok(!l.weOwnAddress('garbage'));
// @ts-ignore wrong type on purpose
assert.ok(!l.weOwnAddress(false));
});
});
@ -128,6 +130,7 @@ describe('SegwitBech32Wallet', function () {
assert.ok(w.weOwnAddress('bc1q063ctu6jhe5k4v8ka99qac8rcm2tzjjnuktyrl'));
assert.ok(w.weOwnAddress('BC1Q063CTU6JHE5K4V8KA99QAC8RCM2TZJJNUKTYRL'));
assert.ok(!w.weOwnAddress('garbage'));
// @ts-ignore wrong type on purpose
assert.ok(!w.weOwnAddress(false));
await w.fetchBalance();
assert.strictEqual(w.getBalance(), 69909);
@ -160,7 +163,7 @@ describe('SegwitBech32Wallet', function () {
assert.ok(tx.hash);
assert.ok(tx.value);
assert.ok(tx.received);
assert.ok(tx.confirmations > 1);
assert.ok(tx.confirmations! > 1);
}
assert.strictEqual(w.getTransactions()[0].value, -892111);
@ -173,6 +176,7 @@ describe('SegwitBech32Wallet', function () {
assert.ok(w.weOwnAddress('bc1qn887fmetaytw4vj68vsh529ft408q8j9x3dndc'));
assert.ok(w.weOwnAddress('BC1QN887FMETAYTW4VJ68VSH529FT408Q8J9X3DNDC'));
assert.ok(!w.weOwnAddress('garbage'));
// @ts-ignore wrong type on purpose
assert.ok(!w.weOwnAddress(false));
await w.fetchTransactions();
assert.strictEqual(w.getTransactions().length, 2);
@ -180,7 +184,7 @@ describe('SegwitBech32Wallet', function () {
assert.ok(tx.hash);
assert.strictEqual(tx.value, 100000);
assert.ok(tx.received);
assert.ok(tx.confirmations > 1);
assert.ok(tx.confirmations! > 1);
const tx0 = w.getTransactions()[0];
assert.ok(tx0.inputs);