Browse Source

remove "(classname): " from tests

...to reduce the burden on writing new code
patch-2
Ryan X. Charles 11 years ago
parent
commit
4cff6a41f4
  1. 8
      lib/address.js
  2. 8
      lib/base58check.js
  3. 30
      lib/bip32.js
  4. 2
      lib/ecdsa.js
  5. 4
      lib/hash.js
  6. 6
      lib/point.js
  7. 10
      lib/privkey.js
  8. 10
      lib/pubkey.js
  9. 4
      lib/random.js
  10. 24
      lib/signature.js
  11. 4
      test/test.address.js
  12. 8
      test/test.base58check.js
  13. 2
      test/test.point.js
  14. 4
      test/test.pubkey.js

8
lib/address.js

@ -21,7 +21,7 @@ Address.prototype.fromPubkey = function(pubkey, network, compressed) {
Address.prototype.fromString = function(str) {
var buf = base58check.decode(str);
if (buf.length !== 1 + 20)
throw new Error('address: Address buffers must be exactly 21 bytes');
throw new Error('Address buffers must be exactly 21 bytes');
var version = buf[0];
if (version === constants['mainnet']['pubkeyhash']) {
this.network = 'mainnet';
@ -64,11 +64,11 @@ Address.prototype.toString = function() {
Address.prototype.validate = function() {
if (!Buffer.isBuffer(this.hash) || this.hash.length !== 20)
throw new Error('address: hash must be a buffer of 20 bytes');
throw new Error('hash must be a buffer of 20 bytes');
if (this.network !== 'mainnet' && this.network !== 'testnet')
throw new Error('address: network must be "mainnet" or "testnet"');
throw new Error('network must be "mainnet" or "testnet"');
if (this.type !== 'pubkeyhash' && this.type !== 'p2sh')
throw new Error('address: type must be "pubkeyhash" or "p2sh"');
throw new Error('type must be "pubkeyhash" or "p2sh"');
return this;
};

8
lib/base58check.js

@ -9,12 +9,12 @@ var Base58Check = function Base58Check(buf) {
Base58Check.decode = function(s) {
if (typeof s !== 'string')
throw new Error('Base58Check: Input must be a string');
throw new Error('Input must be a string');
var buf = base58.decode(s);
if (buf.length < 4)
throw new Error("Base58Check: Input string too short");
throw new Error("Input string too short");
var data = buf.slice(0, -4);
var csum = buf.slice(-4);
@ -23,14 +23,14 @@ Base58Check.decode = function(s) {
var hash4 = hash.slice(0, 4);
if (csum.toString('hex') !== hash4.toString('hex'))
throw new Error("Base58Check: Checksum mismatch");
throw new Error("Checksum mismatch");
return data;
};
Base58Check.encode = function(buf) {
if (!Buffer.isBuffer(buf))
throw new Error('Base58Check: Input must be a buffer');
throw new Error('Input must be a buffer');
var checkedBuf = new Buffer(buf.length + 4);
var hash = sha256sha256(buf);
buf.copy(checkedBuf);

30
lib/bip32.js

@ -37,14 +37,14 @@ BIP32.prototype.fromRandom = function(network) {
BIP32.prototype.fromString = function(str) {
var decoded = base58.decode(str);
if (decoded.length != 82)
throw new Error('bip32: Not enough data, expected 82 and received ' + decoded.length);
throw new Error('gcNot enough data, expected 82 and received ' + decoded.length);
var checksum = decoded.slice(78, 82);
var bytes = decoded.slice(0, 78);
var hash = Hash.sha256sha256(bytes);
if (hash[0] != checksum[0] || hash[1] != checksum[1] || hash[2] != checksum[2] || hash[3] != checksum[3])
throw new Error('bip32: Invalid checksum');
throw new Error('gcInvalid checksum');
if (bytes !== undefined && bytes !== null)
this.initFromBytes(bytes);
@ -55,11 +55,11 @@ BIP32.prototype.fromSeed = function(bytes, network) {
network = 'mainnet';
if (!Buffer.isBuffer(bytes))
throw new Error('bip32: bytes must be a buffer');
throw new Error('gcbytes must be a buffer');
if (bytes.length < 128 / 8)
throw new Error('bip32: Need more than 128 bytes of entropy');
throw new Error('gcNeed more than 128 bytes of entropy');
if (bytes.length > 512 / 8)
throw new Error('bip32: More than 512 bytes of entropy is nonstandard');
throw new Error('gcMore than 512 bytes of entropy is nonstandard');
var hash = Hash.sha512hmac(bytes, new Buffer('Bitcoin seed'));
this.depth = 0x00;
@ -82,7 +82,7 @@ BIP32.prototype.fromSeed = function(bytes, network) {
BIP32.prototype.initFromBytes = function(bytes) {
// Both pub and private extended keys are 78 bytes
if (bytes.length != 78)
throw new Error('bip32: not enough data');
throw new Error('gcnot enough data');
this.version = u32(bytes.slice(0, 4));
this.depth = u8(bytes.slice(4, 5));
@ -112,7 +112,7 @@ BIP32.prototype.initFromBytes = function(bytes) {
this.pubKeyHash = Hash.sha256ripemd160(this.key.pubkey.toBuffer());
this.hasPrivateKey = false;
} else {
throw new Error('bip32: Invalid key');
throw new Error('gcInvalid key');
}
this.buildExtendedPublicKey();
@ -133,7 +133,7 @@ BIP32.prototype.buildExtendedPublicKey = function() {
v = constants.testnet.bip32pubkey;
break;
default:
throw new Error('bip32: Unknown version');
throw new Error('gcUnknown version');
}
// Version
@ -164,7 +164,7 @@ BIP32.prototype.extendedPublicKeyString = function(format) {
} else if (format === 'hex') {
return this.extendedPublicKey.toString('hex');;
} else {
throw new Error('bip32: bad format');
throw new Error('gcbad format');
}
}
@ -200,7 +200,7 @@ BIP32.prototype.extendedPrivateKeyString = function(format) {
} else if (format === 'hex') {
return this.extendedPrivateKey.toString('hex');
} else {
throw new Error('bip32: bad format');
throw new Error('gcbad format');
}
}
@ -217,12 +217,12 @@ BIP32.prototype.derive = function(path) {
var c = e[i];
if (i == 0) {
if (c != 'm') throw new Error('bip32: invalid path');
if (c != 'm') throw new Error('gcinvalid path');
continue;
}
if (parseInt(c.replace("'", "")).toString() !== c.replace("'", ""))
throw new Error('bip32: invalid path');
throw new Error('gcinvalid path');
var usePrivate = (c.length > 1) && (c[c.length - 1] == '\'');
var childIndex = parseInt(usePrivate ? c.slice(0, c.length - 1) : c) & 0x7fffffff;
@ -238,7 +238,7 @@ BIP32.prototype.derive = function(path) {
BIP32.prototype.deriveChild = function(i) {
if (typeof i !== 'number')
throw new Error('bip32: i must be a number');
throw new Error('gci must be a number');
var ib = [];
ib.push((i >> 24) & 0xff);
@ -254,7 +254,7 @@ BIP32.prototype.deriveChild = function(i) {
this.version == constants.testnet.bip32privkey);
if (usePrivate && (!this.hasPrivateKey || !isPrivate))
throw new Error('bip32: Cannot do private key derivation without private key');
throw new Error('gcCannot do private key derivation without private key');
var ret = null;
if (this.hasPrivateKey) {
@ -329,7 +329,7 @@ BIP32.prototype.toString = function() {
function uint(f, size) {
if (f.length < size)
throw new Error('bip32: not enough data');
throw new Error('gcnot enough data');
var n = 0;
for (var i = 0; i < size; i++) {
n *= 256;

2
lib/ecdsa.js

@ -141,7 +141,7 @@ ECDSA.prototype.sign = function() {
var d = privkey.bn;
if (!hashbuf || !privkey || !k || !d)
throw new Error('ecdsa: invalid parameters');
throw new Error('invalid parameters');
var N = Point.getN();
var G = Point.getG();

4
lib/hash.js

@ -46,12 +46,12 @@ Hash.sha512.blocksize = 1024;
Hash.hmac = function(hashf, data, key) {
if (!Buffer.isBuffer(data) || !Buffer.isBuffer(key))
throw new Error('hash: data and key must be buffers');
throw new Error('data and key must be buffers');
//http://en.wikipedia.org/wiki/Hash-based_message_authentication_code
//http://tools.ietf.org/html/rfc4868#section-2
if (!hashf.blocksize)
throw new Error('hash: Blocksize for hash function unknown');
throw new Error('Blocksize for hash function unknown');
var blocksize = hashf.blocksize/8;

6
lib/point.js

@ -38,12 +38,12 @@ Point.prototype.getY = function() {
Point.prototype.validate = function() {
var p2 = Point.fromX(this.getY().isOdd(), this.getX());
if (!(p2.y.cmp(this.y) === 0))
throw new Error('point: Invalid y value of public key');
throw new Error('Invalid y value of public key');
if (!(this.getX().gt(-1) && this.getX().lt(Point.getN()))
||!(this.getY().gt(-1) && this.getY().lt(Point.getN())))
throw new Error('point: Point does not lie on the curve');
throw new Error('Point does not lie on the curve');
if (!(this.mul(Point.getN()).isInfinity()))
throw new Error('point: Point times N must be infinity');
throw new Error('Point times N must be infinity');
return this;
};

10
lib/privkey.js

@ -13,11 +13,11 @@ var Privkey = function Privkey(bn, network, compressed) {
Privkey.prototype.validate = function() {
if (!this.bn.lt(point.getN()))
throw new Error('privkey: Number must be less than N');
throw new Error('Number must be less than N');
if (typeof constants[this.network] === undefined)
throw new Error('privkey: Must specify the network ("mainnet" or "testnet")');
throw new Error('Must specify the network ("mainnet" or "testnet")');
if (typeof this.compressed !== 'boolean')
throw new Error('privkey: Must specify whether the corresponding public key is compressed or not (true or false)');
throw new Error('Must specify whether the corresponding public key is compressed or not (true or false)');
};
Privkey.prototype.toWIF = function() {
@ -47,14 +47,14 @@ Privkey.prototype.fromWIF = function(str) {
else if (buf.length === 1 + 32)
this.compressed = false;
else
throw new Error('privkey: Length of buffer must be 33 (uncompressed) or 34 (compressed)');
throw new Error('Length of buffer must be 33 (uncompressed) or 34 (compressed)');
if (buf[0] === constants.mainnet.privkey)
this.network = 'mainnet';
else if (buf[0] === constants.testnet.privkey)
this.network = 'testnet';
else
throw new Error('privkey: Invalid network');
throw new Error('Invalid network');
this.bn = Bn.fromBuffer(buf.slice(1, 32 + 1));
};

10
lib/pubkey.js

@ -5,7 +5,7 @@ var Pubkey = function Pubkey(point) {
if (!(this instanceof Pubkey))
return new Pubkey(point);
if (point && !point.getX() && !point.getY())
throw new Error('pubkey: Invalid point');
throw new Error('Invalid point');
this.point = point;
};
@ -14,7 +14,7 @@ Pubkey.prototype.fromDER = function(buf) {
var xbuf = buf.slice(1, 33);
var ybuf = buf.slice(33, 65);
if (xbuf.length !== 32 || ybuf.length !== 32 || buf.length !== 65)
throw new Error('pubkey: Length of x and y must be 32 bytes');
throw new Error('Length of x and y must be 32 bytes');
var x = bn(xbuf);
var y = bn(ybuf);
this.point = Point(x, y);
@ -27,7 +27,7 @@ Pubkey.prototype.fromDER = function(buf) {
var x = bn(xbuf);
this.fromX(false, x);
} else {
throw new Error('pubkey: Invalid DER format pubkey');
throw new Error('Invalid DER format pubkey');
}
return this;
};
@ -38,7 +38,7 @@ Pubkey.prototype.fromString = function(str) {
Pubkey.prototype.fromX = function(odd, x) {
if (typeof odd !== 'boolean')
throw new Error('pubkey: Must specify whether y is odd or not (true or false)');
throw new Error('Must specify whether y is odd or not (true or false)');
this.point = Point.fromX(odd, x);
};
@ -48,7 +48,7 @@ Pubkey.prototype.toBuffer = function() {
Pubkey.prototype.toDER = function(compressed) {
if (typeof compressed !== 'boolean')
throw new Error('pubkey: Must specify whether the public key is compressed or not (true or false)');
throw new Error('Must specify whether the public key is compressed or not (true or false)');
var x = this.point.getX();
var y = this.point.getY();

4
lib/random.js

@ -16,14 +16,14 @@ Random.getRandomBufferNode = function(size) {
Random.getRandomBufferBrowser = function(size) {
if (!window.crypto && !window.msCrypto)
throw new Error('random: window.crypto not available');
throw new Error('window.crypto not available');
if (window.crypto && window.crypto.getRandomValues)
var crypto = window.crypto;
else if (window.msCrypto && window.msCrypto.getRandomValues) //internet explorer
var crypto = window.msCrypto;
else
throw new Error('random: window.crypto.getRandomValues not available');
throw new Error('window.crypto.getRandomValues not available');
var bbuf = new Uint8Array(size);
crypto.getRandomValues(bbuf);

24
lib/signature.js

@ -17,11 +17,11 @@ Signature.prototype.fromCompressed = function(buf) {
var b3 = buf.slice(33, 65);
if (!(i === 0 || i === 1 || i === 2 || i === 3))
throw new Error('signature: i must be 0, 1, 2, or 3');
throw new Error('i must be 0, 1, 2, or 3');
if (b2.length !== 32)
throw new Error('signature: r must be 32 bytes');
throw new Error('r must be 32 bytes');
if (b3.length !== 32)
throw new Error('signature: s must be 32 bytes');
throw new Error('s must be 32 bytes');
this.i = i;
this.r = BN().fromBuffer(b2);
@ -41,42 +41,42 @@ Signature.prototype.fromString = function(str) {
Signature.parseDER = function(buf) {
if (!Buffer.isBuffer(buf))
throw new Error('signature: DER formatted signature should be a buffer');
throw new Error('DER formatted signature should be a buffer');
var header = buf[0];
if (header !== 0x30)
throw new Error('signature: Header byte should be 0x30');
throw new Error('Header byte should be 0x30');
var length = buf[1];
if (length !== buf.slice(2).length)
throw new Error('signature: Length byte should length of what follows');
throw new Error('Length byte should length of what follows');
var rheader = buf[2 + 0];
if (rheader !== 0x02)
throw new Error('signature: Integer byte for r should be 0x02');
throw new Error('Integer byte for r should be 0x02');
var rlength = buf[2 + 1];
var rbuf = buf.slice(2 + 2, 2 + 2 + rlength);
var r = BN().fromBuffer(rbuf);
var rneg = buf[2 + 1 + 1] === 0x00 ? true : false;
if (rlength !== rbuf.length)
throw new Error('signature: Length of r incorrect');
throw new Error('Length of r incorrect');
var sheader = buf[2 + 2 + rlength + 0];
if (sheader !== 0x02)
throw new Error('signature: Integer byte for s should be 0x02');
throw new Error('Integer byte for s should be 0x02');
var slength = buf[2 + 2 + rlength + 1];
var sbuf = buf.slice(2 + 2 + rlength + 2, 2 + 2 + rlength + 2 + slength);
var s = BN().fromBuffer(sbuf);
var sneg = buf[2 + 2 + rlength + 2 + 2] === 0x00 ? true : false;
if (slength !== sbuf.length)
throw new Error('signature: Length of s incorrect');
throw new Error('Length of s incorrect');
var sumlength = 2 + 2 + rlength + 2 + slength;
if (length !== sumlength - 2)
throw new Error('signature: Length of signature incorrect');
throw new Error('Length of signature incorrect');
var obj = {
header: header,
@ -99,7 +99,7 @@ Signature.parseDER = function(buf) {
Signature.prototype.toCompressed = function(i) {
i = typeof i === 'number' ? i : this.i;
if (!(i === 0 || i === 1 || i === 2 || i === 3))
throw new Error('signature: i must be equal to 0, 1, 2, or 3');
throw new Error('i must be equal to 0, 1, 2, or 3');
var b1 = new Buffer([i]);
var b2 = this.r.toBuffer({size: 32});

4
test/test.address.js

@ -126,7 +126,7 @@ describe('Address', function() {
address.network = 'unknown';
(function() {
address.validate();
}).should.throw('address: network must be "mainnet" or "testnet"');
}).should.throw('network must be "mainnet" or "testnet"');
});
it('should throw an error on this invalid type', function() {
@ -135,7 +135,7 @@ describe('Address', function() {
address.type = 'unknown';
(function() {
address.validate();
}).should.throw('address: type must be "pubkeyhash" or "p2sh"');
}).should.throw('type must be "pubkeyhash" or "p2sh"');
});
});

8
test/test.base58check.js

@ -25,7 +25,7 @@ describe('Base58Check', function() {
it('should throw an error when the input is not a buffer', function() {
(function() {
Base58Check.encode("string")
}).should.throw('Base58Check: Input must be a buffer');
}).should.throw('Input must be a buffer');
});
});
@ -39,13 +39,13 @@ describe('Base58Check', function() {
it('should throw an error when input is not a string', function() {
(function() {
Base58Check.decode(5);
}).should.throw('Base58Check: Input must be a string');
}).should.throw('Input must be a string');
});
it('should throw an error when input is too short', function() {
(function() {
Base58Check.decode(enc.slice(0, 1));
}).should.throw('Base58Check: Input string too short');
}).should.throw('Input string too short');
});
it('should throw an error when there is a checksum mismatch', function() {
@ -54,7 +54,7 @@ describe('Base58Check', function() {
var enc2 = base58.encode(buf2);
(function() {
Base58Check.decode(enc2);
}).should.throw('Base58Check: Checksum mismatch');
}).should.throw('Checksum mismatch');
});
});

2
test/test.point.js

@ -109,7 +109,7 @@ describe('Point', function() {
var p = point(x, y);
(function() {
p.validate();
}).should.throw('point: Invalid y value of public key');
}).should.throw('Invalid y value of public key');
});
});

4
test/test.pubkey.js

@ -119,7 +119,7 @@ describe('Pubkey', function() {
pk.fromString(hex);
(function() {
pk.validate();
}).should.throw('point: Invalid y value of public key');
}).should.throw('Invalid y value of public key');
});
it('should not throw an error if pubkey is infinity', function() {
@ -127,7 +127,7 @@ describe('Pubkey', function() {
pk.point = Point.getG().mul(Point.getN());
(function() {
pk.validate();
}).should.throw('point: Point cannot be equal to Infinity');
}).should.throw('Point cannot be equal to Infinity');
});
});

Loading…
Cancel
Save