mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-23 07:15:35 +01:00
REF: electrum
This commit is contained in:
parent
92c7743deb
commit
71c589c2de
4 changed files with 30 additions and 19 deletions
|
@ -21,7 +21,7 @@ it('bip38 decodes', async () => {
|
|||
});
|
||||
|
||||
it('bip38 decodes slow', async () => {
|
||||
if (process.env.USER === 'burn' || process.env.USER === 'igor') {
|
||||
if (process.env.USER === 'burn' || process.env.USER === 'igor' || process.env.USER === 'overtorment') {
|
||||
// run only on circleCI
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@ async function connectMain() {
|
|||
mainClient = new ElectrumClient(usingPeer.tcp, usingPeer.host, 'tcp');
|
||||
await mainClient.connect();
|
||||
const ver = await mainClient.server_version('2.7.11', '1.2');
|
||||
console.log('connected to ', ver);
|
||||
let peers = await mainClient.serverPeers_subscribe();
|
||||
if (peers && peers.length > 0) {
|
||||
console.log('connected to ', ver);
|
||||
mainConnected = true;
|
||||
AsyncStorage.setItem(storageKey, JSON.stringify(peers));
|
||||
}
|
||||
|
@ -29,6 +29,9 @@ async function connectMain() {
|
|||
|
||||
if (!mainConnected) {
|
||||
console.log('retry');
|
||||
mainClient.keepAlive = () => {}; // dirty hack to make it stop reconnecting
|
||||
mainClient.reconnect = () => {}; // dirty hack to make it stop reconnecting
|
||||
mainClient.close();
|
||||
setTimeout(connectMain, 5000);
|
||||
}
|
||||
}
|
||||
|
@ -44,13 +47,7 @@ connectMain();
|
|||
async function getRandomHardcodedPeer() {
|
||||
let hardcodedPeers = [
|
||||
{ host: 'node.ispol.sk', tcp: '50001' },
|
||||
{ host: 'electrum.vom-stausee.de', tcp: '50001' },
|
||||
{ host: 'orannis.com', tcp: '50001' },
|
||||
{ host: '139.162.14.142', tcp: '50001' },
|
||||
{ host: 'daedalus.bauerj.eu', tcp: '50001' },
|
||||
{ host: 'electrum.eff.ro', tcp: '50001' },
|
||||
{ host: 'electrum.anduck.net', tcp: '50001' },
|
||||
{ host: 'mooo.not.fyi', tcp: '50011' },
|
||||
{ host: 'electrum.coinucopia.io', tcp: '50001' },
|
||||
];
|
||||
return hardcodedPeers[(hardcodedPeers.length * Math.random()) | 0];
|
||||
|
|
|
@ -1,11 +1,27 @@
|
|||
/* global it, describe, jasmine */
|
||||
/* global it, describe, afterAll, beforeAll, jasmine */
|
||||
global.net = require('net');
|
||||
let BlueElectrum = require('./BlueElectrum');
|
||||
let assert = require('assert');
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100 * 1000;
|
||||
|
||||
afterAll(() => {
|
||||
// after all tests we close socket so the test suite can actually terminate
|
||||
return 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 {
|
||||
await BlueElectrum.waitTillConnected();
|
||||
} catch (Err) {
|
||||
console.log('failed to connect to Electrum:', Err);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
describe('Electrum', () => {
|
||||
it('ElectrumClient can connect and query', async () => {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100 * 1000;
|
||||
const ElectrumClient = require('electrum-client');
|
||||
let bitcoin = require('bitcoinjs-lib');
|
||||
// let bitcoin = require('bitcoinjs-lib');
|
||||
|
@ -47,7 +63,6 @@ describe('Electrum', () => {
|
|||
|
||||
it('BlueElectrum works', async function() {
|
||||
let address = '3GCvDBAktgQQtsbN6x5DYiQCMmgZ9Yk8BK';
|
||||
await BlueElectrum.waitTillConnected();
|
||||
let balance = await BlueElectrum.getBalanceByAddress(address);
|
||||
assert.strictEqual(balance.confirmed, 51432);
|
||||
assert.strictEqual(balance.unconfirmed, 0);
|
||||
|
@ -59,7 +74,5 @@ describe('Electrum', () => {
|
|||
assert.ok(tx.tx_hash);
|
||||
assert.ok(tx.height);
|
||||
}
|
||||
|
||||
BlueElectrum.forceDisconnect();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,6 +5,7 @@ let assert = require('assert');
|
|||
let bitcoin = require('bitcoinjs-lib');
|
||||
global.net = require('net'); // needed by Electrum client. For RN it is proviced in shim.js
|
||||
let BlueElectrum = require('./BlueElectrum'); // so it connects ASAP
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100 * 1000;
|
||||
|
||||
afterAll(() => {
|
||||
// after all tests we close socket so the test suite can actually terminate
|
||||
|
@ -14,7 +15,12 @@ afterAll(() => {
|
|||
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 {
|
||||
await BlueElectrum.waitTillConnected();
|
||||
} catch (Err) {
|
||||
console.log('failed to connect to Electrum:', Err);
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
|
||||
it('can convert witness to address', () => {
|
||||
|
@ -29,7 +35,6 @@ it('can convert witness to address', () => {
|
|||
});
|
||||
|
||||
it('can create a Segwit HD (BIP49)', async function() {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30 * 1000;
|
||||
let mnemonic =
|
||||
'honey risk juice trip orient galaxy win situate shoot anchor bounce remind horse traffic exotic since escape mimic ramp skin judge owner topple erode';
|
||||
let hd = new HDSegwitP2SHWallet();
|
||||
|
@ -124,7 +129,6 @@ it('HD (BIP49) can create TX', async () => {
|
|||
console.error('process.env.HD_MNEMONIC not set, skipped');
|
||||
return;
|
||||
}
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90 * 1000;
|
||||
let hd = new HDSegwitP2SHWallet();
|
||||
hd.setSecret(process.env.HD_MNEMONIC);
|
||||
assert.ok(hd.validateMnemonic());
|
||||
|
@ -199,7 +203,6 @@ it('Segwit HD (BIP49) can fetch balance with many used addresses in hierarchy',
|
|||
return;
|
||||
}
|
||||
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90 * 1000;
|
||||
let hd = new HDSegwitP2SHWallet();
|
||||
hd.setSecret(process.env.HD_MNEMONIC_BIP49_MANY_TX);
|
||||
assert.ok(hd.validateMnemonic());
|
||||
|
@ -247,7 +250,6 @@ it('can create a Legacy HD (BIP44)', async function() {
|
|||
return;
|
||||
}
|
||||
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30 * 1000;
|
||||
let mnemonic = process.env.HD_MNEMONIC_BREAD;
|
||||
let hd = new HDLegacyP2PKHWallet();
|
||||
hd.setSecret(mnemonic);
|
||||
|
@ -298,7 +300,6 @@ it('Legacy HD (BIP44) can create TX', async () => {
|
|||
console.error('process.env.HD_MNEMONIC not set, skipped');
|
||||
return;
|
||||
}
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90 * 1000;
|
||||
let hd = new HDLegacyP2PKHWallet();
|
||||
hd.setSecret(process.env.HD_MNEMONIC);
|
||||
assert.ok(hd.validateMnemonic());
|
||||
|
|
Loading…
Add table
Reference in a new issue