Drop duplicated code
This commit is contained in:
parent
9c3170cb3a
commit
eb8f59aa27
@ -10,12 +10,48 @@
|
|||||||
/* jshint maxstatements: 100 */
|
/* jshint maxstatements: 100 */
|
||||||
/* jshint unused: false */
|
/* jshint unused: false */
|
||||||
|
|
||||||
|
var _ = require('lodash');
|
||||||
var should = require('chai').should();
|
var should = require('chai').should();
|
||||||
|
var expect = require('chai').expect;
|
||||||
var bitcore = require('..');
|
var bitcore = require('..');
|
||||||
var Networks = bitcore.Networks;
|
var Networks = bitcore.Networks;
|
||||||
var HDPrivateKey = bitcore.HDPrivateKey;
|
var HDPrivateKey = bitcore.HDPrivateKey;
|
||||||
var HDPublicKey = bitcore.HDPublicKey;
|
var HDPublicKey = bitcore.HDPublicKey;
|
||||||
|
|
||||||
|
describe('HDKeys building with static methods', function() {
|
||||||
|
var classes = [HDPublicKey, HDPrivateKey];
|
||||||
|
var clazz, index;
|
||||||
|
|
||||||
|
_.each(classes, function(clazz) {
|
||||||
|
var expectStaticMethodFail = function(staticMethod, argument, message) {
|
||||||
|
expect(clazz[staticMethod].bind(null, argument)).to.throw(message);
|
||||||
|
};
|
||||||
|
it(clazz.name + ' fromJSON checks that a valid JSON is provided', function() {
|
||||||
|
var errorMessage = 'No valid JSON string was provided';
|
||||||
|
var method = 'fromJSON';
|
||||||
|
expectStaticMethodFail(method, undefined, errorMessage);
|
||||||
|
expectStaticMethodFail(method, null, errorMessage);
|
||||||
|
expectStaticMethodFail(method, 'invalid JSON', errorMessage);
|
||||||
|
expectStaticMethodFail(method, '{\'singlequotes\': true}', errorMessage);
|
||||||
|
expectStaticMethodFail(method, {}, errorMessage);
|
||||||
|
});
|
||||||
|
it(clazz.name + ' fromString checks that a string is provided', function() {
|
||||||
|
var errorMessage = 'No valid string was provided';
|
||||||
|
var method = 'fromString';
|
||||||
|
expectStaticMethodFail(method, undefined, errorMessage);
|
||||||
|
expectStaticMethodFail(method, null, errorMessage);
|
||||||
|
expectStaticMethodFail(method, {}, errorMessage);
|
||||||
|
});
|
||||||
|
it(clazz.name + ' fromObject checks that an object is provided', function() {
|
||||||
|
var errorMessage = 'No valid argument was provided';
|
||||||
|
var method = 'fromObject';
|
||||||
|
expectStaticMethodFail(method, undefined, errorMessage);
|
||||||
|
expectStaticMethodFail(method, null, errorMessage);
|
||||||
|
expectStaticMethodFail(method, '', errorMessage);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('BIP32 compliance', function() {
|
describe('BIP32 compliance', function() {
|
||||||
|
|
||||||
it('should initialize test vector 1 from the extended public key', function() {
|
it('should initialize test vector 1 from the extended public key', function() {
|
||||||
|
|||||||
@ -85,32 +85,6 @@ describe('HDPrivate key interface', function() {
|
|||||||
it('allows no-new calling', function() {
|
it('allows no-new calling', function() {
|
||||||
HDPrivateKey(xprivkey).toString().should.equal(xprivkey);
|
HDPrivateKey(xprivkey).toString().should.equal(xprivkey);
|
||||||
});
|
});
|
||||||
var expectStaticMethodFail = function(staticMethod, argument, message) {
|
|
||||||
expect(HDPrivateKey[staticMethod].bind(null, argument)).to.throw(message);
|
|
||||||
};
|
|
||||||
it('fromJSON checks that a valid JSON is provided', function() {
|
|
||||||
var errorMessage = 'No valid JSON string was provided';
|
|
||||||
var method = 'fromJSON';
|
|
||||||
expectStaticMethodFail(method, undefined, errorMessage);
|
|
||||||
expectStaticMethodFail(method, null, errorMessage);
|
|
||||||
expectStaticMethodFail(method, 'invalid JSON', errorMessage);
|
|
||||||
expectStaticMethodFail(method, '{\'singlequotes\': true}', errorMessage);
|
|
||||||
expectStaticMethodFail(method, {}, errorMessage);
|
|
||||||
});
|
|
||||||
it('fromString checks that a string is provided', function() {
|
|
||||||
var errorMessage = 'No valid string was provided';
|
|
||||||
var method = 'fromString';
|
|
||||||
expectStaticMethodFail(method, undefined, errorMessage);
|
|
||||||
expectStaticMethodFail(method, null, errorMessage);
|
|
||||||
expectStaticMethodFail(method, {}, errorMessage);
|
|
||||||
});
|
|
||||||
it('fromObject checks that an object is provided', function() {
|
|
||||||
var errorMessage = 'No valid argument was provided';
|
|
||||||
var method = 'fromObject';
|
|
||||||
expectStaticMethodFail(method, undefined, errorMessage);
|
|
||||||
expectStaticMethodFail(method, null, errorMessage);
|
|
||||||
expectStaticMethodFail(method, '', errorMessage);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('inspect() displays correctly', function() {
|
it('inspect() displays correctly', function() {
|
||||||
|
|||||||
@ -124,35 +124,6 @@ describe('HDPublicKey interface', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('building with static methods', function() {
|
|
||||||
var expectStaticMethodFail = function(staticMethod, argument, message) {
|
|
||||||
expect(HDPublicKey[staticMethod].bind(null, argument)).to.throw(message);
|
|
||||||
};
|
|
||||||
it('fromJSON checks that a valid JSON is provided', function() {
|
|
||||||
var errorMessage = 'No valid JSON string was provided';
|
|
||||||
var method = 'fromJSON';
|
|
||||||
expectStaticMethodFail(method, undefined, errorMessage);
|
|
||||||
expectStaticMethodFail(method, null, errorMessage);
|
|
||||||
expectStaticMethodFail(method, 'invalid JSON', errorMessage);
|
|
||||||
expectStaticMethodFail(method, '{\'singlequotes\': true}', errorMessage);
|
|
||||||
expectStaticMethodFail(method, {}, errorMessage);
|
|
||||||
});
|
|
||||||
it('fromString checks that a string is provided', function() {
|
|
||||||
var errorMessage = 'No valid string was provided';
|
|
||||||
var method = 'fromString';
|
|
||||||
expectStaticMethodFail(method, undefined, errorMessage);
|
|
||||||
expectStaticMethodFail(method, null, errorMessage);
|
|
||||||
expectStaticMethodFail(method, {}, errorMessage);
|
|
||||||
});
|
|
||||||
it('fromObject checks that an object is provided', function() {
|
|
||||||
var errorMessage = 'No valid argument was provided';
|
|
||||||
var method = 'fromObject';
|
|
||||||
expectStaticMethodFail(method, undefined, errorMessage);
|
|
||||||
expectStaticMethodFail(method, null, errorMessage);
|
|
||||||
expectStaticMethodFail(method, '', errorMessage);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('error checking on serialization', function() {
|
describe('error checking on serialization', function() {
|
||||||
var compareType = function(a, b) {
|
var compareType = function(a, b) {
|
||||||
expect(a instanceof b).to.equal(true);
|
expect(a instanceof b).to.equal(true);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user