Add new sjcl export for code coverage convenience

This commit is contained in:
wltsmrz
2013-09-10 17:13:55 -07:00
parent 3f2afdc39d
commit 40eccdb2fd
15 changed files with 47 additions and 33 deletions

View File

@@ -1,4 +1,10 @@
test:
./node_modules/.bin/mocha test/*-test.js
mocha test/*-test.js
coverage:
rm -rf lib-cov
jscoverage src/js/ripple lib-cov
RIPPLE_LIB_COV=1 mocha --reporter html-cov test/*-test.js > coverage.html
rm -rf lib-cov
.PHONY: test

View File

@@ -1,9 +1,10 @@
// Represent Ripple amounts and currencies.
// - Numbers in hex are big-endian.
var sjcl = require('../../../build/sjcl');
var bn = sjcl.bn;
var utils = require('./utils');
var sjcl = utils.sjcl;
var bn = sjcl.bn;
var jsbn = require('./jsbn');
var BigInteger = jsbn.BigInteger;

View File

@@ -1,4 +1,4 @@
var sjcl = require('../../../build/sjcl');
var sjcl = require('./utils').sjcl;
var utils = require('./utils');
var jsbn = require('./jsbn');
var extend = require('extend');

View File

@@ -19,7 +19,7 @@ exports.Server = require('./server').Server;
// However, for programs that are tied to a specific version of ripple.js like
// the official client, it makes sense to expose the SJCL instance so we don't
// have to include it twice.
exports.sjcl = require('../../../build/sjcl');
exports.sjcl = require('./utils').sjcl;
exports.config = require('./config');

View File

@@ -1,4 +1,4 @@
var sjcl = require('../../../build/sjcl');
var sjcl = require('./utils').sjcl;
var UInt256 = require('./uint256').UInt256;

View File

@@ -32,7 +32,7 @@ var RippleError = require('./rippleerror').RippleError;
var utils = require('./utils');
var config = require('./config');
var sjcl = require('../../../build/sjcl');
var sjcl = require('./utils').sjcl;
/**
Interface to manage the connection to a Ripple server.
@@ -762,8 +762,9 @@ Remote.prototype.request_tx = function (hash, callback) {
Remote.prototype.request_account_info = function (accountID, callback) {
var request = new Request(this, 'account_info');
request.message.ident = UInt160.json_rewrite(accountID); // DEPRECATED
request.message.account = UInt160.json_rewrite(accountID);
var account = UInt160.json_rewrite(accountID);
request.message.ident = account; //DEPRECATED;
request.message.account = account;
request.callback(callback);
return request;
};

View File

@@ -2,17 +2,17 @@
// Seed support
//
var sjcl = require('../../../build/sjcl');
var sjcl = require('./utils').sjcl;
var utils = require('./utils');
var jsbn = require('./jsbn');
var extend = require('extend');
var BigInteger = jsbn.BigInteger;
var Base = require('./base').Base,
UInt = require('./uint').UInt,
UInt256 = require('./uint256').UInt256,
KeyPair = require('./keypair').KeyPair;
var Base = require('./base').Base;
var UInt = require('./uint').UInt;
var UInt256 = require('./uint256').UInt256;
var KeyPair = require('./keypair').KeyPair;
var Seed = extend(function () {
// Internal form: NaN or BigInteger
@@ -27,7 +27,7 @@ Seed.prototype.constructor = Seed;
// value = NaN on error.
// One day this will support rfc1751 too.
Seed.prototype.parse_json = function (j) {
if ('string' === typeof j) {
if (typeof j === 'string') {
if (!j.length) {
this._value = NaN;
// XXX Should actually always try and continue if it failed.
@@ -47,7 +47,7 @@ Seed.prototype.parse_json = function (j) {
};
Seed.prototype.parse_passphrase = function (j) {
if ("string" !== typeof j) {
if (typeof j !== 'string') {
throw new Error("Passphrase must be a string");
}
@@ -60,8 +60,9 @@ Seed.prototype.parse_passphrase = function (j) {
};
Seed.prototype.to_json = function () {
if (!(this._value instanceof BigInteger))
if (!(this._value instanceof BigInteger)) {
return NaN;
}
var output = Base.encode_check(Base.VER_FAMILY_SEED, this.to_bytes());
@@ -70,18 +71,18 @@ Seed.prototype.to_json = function () {
function append_int(a, i) {
return [].concat(a, i >> 24, (i >> 16) & 0xff, (i >> 8) & 0xff, i & 0xff);
}
};
function firstHalfOfSHA512(bytes) {
return sjcl.bitArray.bitSlice(
sjcl.hash.sha512.hash(sjcl.codec.bytes.toBits(bytes)),
0, 256
);
}
};
function SHA256_RIPEMD160(bits) {
return sjcl.hash.ripemd160.hash(sjcl.hash.sha256.hash(bits));
}
};
Seed.prototype.get_key = function (account_id) {
if (!this.is_valid()) {
@@ -89,11 +90,10 @@ Seed.prototype.get_key = function (account_id) {
}
// XXX Should loop over keys until we find the right one
var private_gen, public_gen;
var curve = this._curve;
var seq = 0, i = 0;
var seq = 0;
var private_gen, public_gen, i = 0;
do {
private_gen = sjcl.bn.fromBits(firstHalfOfSHA512(append_int(this.to_bytes(), i)));
i++;
@@ -103,6 +103,7 @@ Seed.prototype.get_key = function (account_id) {
var sec;
i = 0;
do {
sec = sjcl.bn.fromBits(firstHalfOfSHA512(append_int(append_int(public_gen.toBytesCompressed(), seq), i)));
i++;

View File

@@ -1,5 +1,5 @@
var binformat = require('./binformat');
var sjcl = require('../../../build/sjcl');
var sjcl = require('./utils').sjcl;
var extend = require('extend');
var stypes = require('./serializedtypes');

View File

@@ -8,7 +8,7 @@
var extend = require('extend');
var utils = require('./utils');
var sjcl = require('../../../build/sjcl');
var sjcl = require('./utils').sjcl;
var amount = require('./amount');
var UInt128 = require('./uint128').UInt128;

View File

@@ -45,7 +45,7 @@
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var sjcl = require('../../../build/sjcl');
var sjcl = require('./utils').sjcl;
var Amount = require('./amount').Amount;
var Currency = require('./amount').Currency;

View File

@@ -1,5 +1,4 @@
var sjcl = require('../../../build/sjcl');
var sjcl = require('./utils').sjcl;
var utils = require('./utils');
var config = require('./config');
var jsbn = require('./jsbn');

View File

@@ -1,5 +1,4 @@
var sjcl = require('../../../build/sjcl');
var sjcl = require('./utils').sjcl;
var utils = require('./utils');
var config = require('./config');
var jsbn = require('./jsbn');

View File

@@ -1,4 +1,4 @@
var sjcl = require('../../../build/sjcl');
var sjcl = require('./utils').sjcl;
var utils = require('./utils');
var config = require('./config');
var jsbn = require('./jsbn');

View File

@@ -1,5 +1,4 @@
var sjcl = require('../../../build/sjcl');
var sjcl = require('./utils').sjcl;
var utils = require('./utils');
var config = require('./config');
var jsbn = require('./jsbn');

View File

@@ -140,5 +140,13 @@ exports.logObject = logObject;
exports.assert = assert;
exports.arrayUnique = arrayUnique;
exports.toTimestamp = toTimestamp;
exports.sjcl = (function() {
try {
var sjcl = require('../../../build/sjcl');
} catch(e) {
var sjcl = require('../build/sjcl');
}
return sjcl;
})();
// vim:sw=2:sts=2:ts=8:et