Skip to content

Commit

Permalink
Tests should at least run
Browse files Browse the repository at this point in the history
  • Loading branch information
rastajpa committed Aug 15, 2019
1 parent 05cbb01 commit b9d3ce3
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 338 deletions.
13 changes: 0 additions & 13 deletions packages/bitcore-wallet-client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,19 @@ build/Release
# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

# Users Environment Variables
.lock-wscript

*.swp
out/
db/*

docs

# VIM ignore
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist
*~

# OSX
.DS_Store
.AppleDouble
.LSOverride

ts_build

*debug.log
node_modules/
Expand All @@ -65,4 +53,3 @@ Session.vim
.netrwhist
*~
ts_build
built/
4 changes: 2 additions & 2 deletions packages/bitcore-wallet-client/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var Client = require('./src/lib');
var Client = require('./ts_build');
module.exports = Client;

// Errors thrown by the library
Client.errors = require('./src/lib/errors');
Client.errors = require('./ts_build/errors');
3 changes: 1 addition & 2 deletions packages/bitcore-wallet-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@
"typescript-eslint-parser": "^22.0.0"
},
"scripts": {
"start": "npm run clean && npm run tsc && ./start.sh",
"start": "npm run clean && npm run tsc && node app.js",
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --reporter spec test",
"test": "./node_modules/.bin/mocha --exit",
"test:ci": "npm run test",
"stop": "./stop.sh",
"docs": "./node_modules/.bin/jsdox lib/* lib/common lib/errors -o docs && cat README.header.md docs/*.md LICENSE > README.md",
"coveralls": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"compile": "npm run tsc",
Expand Down
134 changes: 0 additions & 134 deletions packages/bitcore-wallet-client/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,140 +324,6 @@ export class API extends EventEmitter {
this.request.setCredentials(this.credentials);
}

/**
* Import from Mnemonics (language autodetected)
* Can throw an error if mnemonic is invalid
* Will try compilant and non-compliantDerivation
*
* @param {String} BIP39 words
* @param {Object} opts
* @param {String} opts.coin - default 'btc'
* @param {String} opts.network - default 'livenet'
* @param {String} opts.passphrase
* @param {Number} opts.account - default 0
* @param {String} opts.derivationStrategy - default 'BIP44'
* @param {String} opts.entropySourcePath - Only used if the wallet was created on a HW wallet, in which that private keys was not available for all the needed derivations
* @param {String} opts.walletPrivKey - if available, walletPrivKey for encrypting metadata
*/
importFromMnemonic(words, opts, cb) {
$.checkState(false, 'not supported');

log.debug('Importing from Mnemonic');

opts = opts || {};
opts.coin = opts.coin || 'btc';

function derive(nonCompliantDerivation?, useLegacyCoinType?) {
return Credentials.fromMnemonic(opts.coin, opts.network || 'livenet', words, opts.passphrase, opts.account || 0, opts.derivationStrategy || Constants.DERIVATION_STRATEGIES.BIP44, {
nonCompliantDerivation,
entropySourcePath: opts.entropySourcePath,
walletPrivKey: opts.walletPrivKey,
useLegacyCoinType,
});
}

try {
this.credentials = derive();
} catch (e) {
log.info('Mnemonic error:', e);
return cb(new Errors.INVALID_BACKUP);
}
this.request.setCredentials(this.credentials);
// TODO BWC => ts
_import(function (err, ret) {
if (!err) return cb(null, ret);
if (err instanceof Errors.INVALID_BACKUP) return cb(err);
if (err instanceof Errors.NOT_AUTHORIZED || err instanceof Errors.WALLET_DOES_NOT_EXIST) {

var altCredentials;
// Only BTC wallets can be nonCompliantDerivation
switch (opts.coin) {
case 'btc':
// try using nonCompliantDerivation
altCredentials = derive(true);
break;
case 'bch':
// try using 0 as coin for BCH (old wallets)
altCredentials = derive(false, true);
break;
default:
return cb(err);
}

if (altCredentials.xPubKey.toString() == this.credentials.xPubKey.toString())
return cb(err);

this.credentials = altCredentials;
this.request.setCredentials(this.credentials);
return this._import(cb);
}
return cb(err);
});
}

/*
* Import from extended private key
*
* @param {String} xPrivKey
* @param {String} opts.coin - default 'btc'
* @param {Number} opts.account - default 0
* @param {String} opts.derivationStrategy - default 'BIP44'
* @param {String} opts.compliantDerivation - default 'true'
* @param {String} opts.walletPrivKey - if available, walletPrivKey for encrypting metadata
* @param {Callback} cb - The callback that handles the response. It returns a flag indicating that the wallet is imported.
*/
importFromExtendedPrivateKey(xPrivKey, opts, cb) {
$.checkState(false, 'not supported');
log.debug('Importing from Extended Private Key');

if (!cb) {
cb = opts;
opts = {};
log.warn('DEPRECATED WARN: importFromExtendedPrivateKey should receive 3 parameters.');
}

try {
this.credentials = Credentials.fromExtendedPrivateKey(opts.coin || 'btc', xPrivKey, opts.account || 0, opts.derivationStrategy || Constants.DERIVATION_STRATEGIES.BIP44, opts);
} catch (e) {
log.info('xPriv error:', e);
return cb(new Errors.INVALID_BACKUP);
}

this.request.setCredentials(this.credentials);
this._import(cb);
}

/**
* Import from Extended Public Key
*
* @param {String} xPubKey
* @param {String} source - A name identifying the source of the xPrivKey
* @param {String} entropySourceHex - A HEX string containing pseudo-random data, that can be deterministically derived from the xPrivKey, and should not be derived from xPubKey.
* @param {Object} opts
* @param {String} opts.coin - default 'btc'
* @param {Number} opts.account - default 0
* @param {String} opts.derivationStrategy - default 'BIP44'
* @param {String} opts.compliantDerivation - default 'true'
*/
importFromExtendedPublicKey(xPubKey, source, entropySourceHex, opts, cb) {
$.checkState(false, 'not supported');
$.checkArgument(arguments.length == 5, 'DEPRECATED: should receive 5 arguments');
$.checkArgument(_.isUndefined(opts) || _.isObject(opts));
$.shouldBeFunction(cb);

opts = opts || {};
log.debug('Importing from Extended Private Key');
try {
this.credentials = Credentials.fromExtendedPublicKey(opts.coin || 'btc', xPubKey, source, entropySourceHex, opts.account || 0, opts.derivationStrategy || Constants.DERIVATION_STRATEGIES.BIP44, opts);
} catch (e) {
log.info('xPriv error:', e);
return cb(new Errors.INVALID_BACKUP);
}

this.request.setCredentials(this.credentials);
this._import(cb);
}

decryptBIP38PrivateKey(encryptedPrivateKeyBase58, passphrase, opts, cb) {
var Bip38 = require('bip38');
var bip38 = new Bip38();
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcore-wallet-client/src/lib/paypro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class PayPro {
}

if (!_.isNumber(data.outputs[0].amount)) {
return cb(new Error('Bad output amount ' + e));
return cb(new Error('Bad output amount'));
}
ret.amount = data.outputs[0].amount;

Expand Down
10 changes: 5 additions & 5 deletions packages/bitcore-wallet-client/test/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var async = require('async');
var request = require('supertest');
var Uuid = require('uuid');
var sjcl = require('sjcl');
var log = require('../src/lib/log');
var log = require('../ts_build/log');
var mongodb = require('mongodb');
var config = require('./test-config');
var oldCredentials = require('./legacyCredentialsExports');
Expand All @@ -23,16 +23,16 @@ var Bitcore_ = {

var BWS = require('bitcore-wallet-service');

var Common = require('../src/lib/common');
var Common = require('../ts_build/common');
var Constants = Common.Constants;
var Utils = Common.Utils;
var Client = require('../src/lib');
var Client = require('../ts_build');
var Key = Client.Key;
var Request = require('../src/lib/request.js');
var Request = require('../ts_build/request.js');
var ExpressApp = BWS.ExpressApp;
var Storage = BWS.Storage;
var TestData = require('./testdata');
var Errors = require('../src/lib/errors');
var Errors = require('../ts_build/errors');

var helpers = {};

Expand Down
Loading

0 comments on commit b9d3ce3

Please sign in to comment.