2020-10-05 22:25:14 +01:00
|
|
|
import assert from 'assert';
|
2024-05-20 10:54:13 +01:00
|
|
|
|
2021-08-04 22:23:57 +02:00
|
|
|
import * as BlueElectrum from '../../blue_modules/BlueElectrum';
|
2024-05-20 10:54:13 +01:00
|
|
|
import { MultisigHDWallet } from '../../class/';
|
2021-08-04 22:23:57 +02:00
|
|
|
|
2022-06-03 17:54:05 +01:00
|
|
|
jest.setTimeout(300 * 1000);
|
2020-10-05 22:25:14 +01:00
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
// after all tests we close socket so the test suite can actually terminate
|
|
|
|
BlueElectrum.forceDisconnect();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
// awaiting for Electrum to be connected. For RN Electrum would naturally connect
|
|
|
|
// while app starts up, but for tests we need to wait for it
|
|
|
|
try {
|
2021-08-10 21:53:02 +02:00
|
|
|
await BlueElectrum.connectMain();
|
2020-10-05 22:25:14 +01:00
|
|
|
} catch (Err) {
|
|
|
|
console.log('failed to connect to Electrum:', Err);
|
|
|
|
process.exit(2);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('multisig-hd-wallet', () => {
|
|
|
|
it('can fetch balance & transactions', async () => {
|
|
|
|
const path = "m/48'/0'/0'/2'";
|
|
|
|
const fp1 = 'D37EAD88';
|
|
|
|
const fp2 = '168DD603';
|
|
|
|
const Zpub1 = 'Zpub74ijpfhERJNjhCKXRspTdLJV5eoEmSRZdHqDvp9kVtdVEyiXk7pXxRbfZzQvsDFpfDHEHVtVpx4Dz9DGUWGn2Xk5zG5u45QTMsYS2vjohNQ';
|
|
|
|
const Zpub2 = 'Zpub75mAE8EjyxSzoyPmGnd5E6MyD7ALGNndruWv52xpzimZQKukwvEfXTHqmH8nbbc6ccP5t2aM3mws3pKYSnKpKMMytdbNEZFUxKzztYFM8Pn';
|
|
|
|
|
|
|
|
const w = new MultisigHDWallet();
|
|
|
|
w.addCosigner(Zpub1, fp1);
|
|
|
|
w.addCosigner(Zpub2, fp2);
|
|
|
|
w.setDerivationPath(path);
|
|
|
|
w.setM(2);
|
|
|
|
|
|
|
|
assert.strictEqual(w.getM(), 2);
|
|
|
|
assert.strictEqual(w.getN(), 2);
|
|
|
|
assert.strictEqual(w.getDerivationPath(), path);
|
|
|
|
assert.strictEqual(w.getCosigner(1), Zpub1);
|
|
|
|
assert.strictEqual(w.getCosigner(2), Zpub2);
|
|
|
|
assert.strictEqual(w.getCosignerForFingerprint(fp1), Zpub1);
|
|
|
|
assert.strictEqual(w.getCosignerForFingerprint(fp2), Zpub2);
|
|
|
|
|
|
|
|
await w.fetchBalance();
|
|
|
|
await w.fetchTransactions();
|
2020-11-04 19:46:31 +00:00
|
|
|
assert.ok(w.getTransactions().length >= 6);
|
2020-10-05 22:25:14 +01:00
|
|
|
});
|
|
|
|
});
|