Fix lint errors

This commit is contained in:
Chris Clark
2015-05-14 13:02:39 -07:00
parent 171f8349cb
commit ea24bf0415
7 changed files with 799 additions and 719 deletions

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-var */
'use strict';
var fs = require('fs');
@@ -12,10 +13,10 @@ function parse_options(from, flags) {
// Do we have the flag?
var flag_index = argv.indexOf('--' + f);
// normalize the name of the flag
f = f.replace('-', '_');
var flag = f.replace('-', '_');
// opts_ has Boolean value for normalized flag key
opts_[f] = flag_index !== -1;
if (opts_[f]) {
opts_[flag] = flag_index !== -1;
if (opts_[flag]) {
// remove the flag from the argv
argv.splice(flag_index, 1);
}

View File

@@ -1,10 +1,11 @@
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var async = require('async');
var UInt160 = require('./uint160').UInt160;
var Currency = require('./currency').Currency;
var RippleError = require('./rippleerror').RippleError;
var Server = require('./server').Server;
'use strict';
const EventEmitter = require('events').EventEmitter;
const util = require('util');
const async = require('async');
const UInt160 = require('./uint160').UInt160;
const Currency = require('./currency').Currency;
const RippleError = require('./rippleerror').RippleError;
// Request events emitted:
// 'success' : Request successful.
@@ -30,20 +31,15 @@ function Request(remote, command) {
this.errorEvent = 'error';
this.message = {
command: command,
id: void(0)
};
id: undefined
};
}
util.inherits(Request, EventEmitter);
// Send the request to a remote.
Request.prototype.request = function(servers, callback) {
this.emit('before');
if (typeof servers === 'function') {
callback = servers;
}
this.callback(callback);
if (this.requested) {
@@ -79,8 +75,8 @@ Request.prototype.request = function(servers, callback) {
Request.prototype.filter =
Request.prototype.addFilter =
Request.prototype.broadcast = function(filterFn) {
var self = this;
Request.prototype.broadcast = function(filterFn=Boolean) {
const self = this;
if (!this.requested) {
// Defer until requested, and prevent the normal request() from executing
@@ -91,10 +87,9 @@ Request.prototype.broadcast = function(filterFn) {
return this;
}
var filterFn = typeof filterFn === 'function' ? filterFn : Boolean;
var lastResponse = new Error('No servers available');
var connectTimeouts = { };
var emit = this.emit;
let lastResponse = new Error('No servers available');
let connectTimeouts = { };
const emit = this.emit;
this.emit = function(event, a, b) {
// Proxy success/error events
@@ -123,13 +118,13 @@ Request.prototype.broadcast = function(filterFn) {
// Server is disconnected but should reconnect. Wait for it to reconnect,
// and abort after a timeout
var serverID = server.getServerID();
const serverID = server.getServerID();
function serverReconnected() {
clearTimeout(connectTimeouts[serverID]);
connectTimeouts[serverID] = null;
iterator(server, callback);
};
}
connectTimeouts[serverID] = setTimeout(function() {
server.removeListener('connect', serverReconnected);
@@ -137,16 +132,16 @@ Request.prototype.broadcast = function(filterFn) {
}, self.reconnectTimeout);
server.once('connect', serverReconnected);
};
}
function complete(success) {
// Emit success if the filter is satisfied by any server
// Emit error if the filter is not satisfied by any server
// Include the last response
emit.call(self, success ? 'success' : 'error', lastResponse);
};
}
var servers = this.remote._servers.filter(function(server) {
const servers = this.remote._servers.filter(function(server) {
// Pre-filter servers that are disconnected and should not reconnect
return (server.isConnected() || server._shouldConnect)
// Pre-filter servers that do not contain the ledger in request
@@ -157,7 +152,7 @@ Request.prototype.broadcast = function(filterFn) {
|| server.hasLedger(self.message.ledger_index_min))
&& (!self.message.hasOwnProperty('ledger_index_max')
|| self.message.ledger_index_max === -1
|| server.hasLedger(self.message.ledger_index_max))
|| server.hasLedger(self.message.ledger_index_max));
});
// Apply iterator in parallel to connected servers, complete when the
@@ -191,7 +186,7 @@ Request.prototype.setReconnectTimeout = function(timeout) {
};
Request.prototype.callback = function(callback, successEvent, errorEvent) {
var self = this;
const self = this;
if (typeof callback !== 'function') {
return this;
@@ -204,26 +199,26 @@ Request.prototype.callback = function(callback, successEvent, errorEvent) {
this.errorEvent = errorEvent;
}
var called = false;
let called = false;
function requestSuccess(message) {
if (!called) {
called = true;
callback.call(self, null, message);
}
};
}
function requestError(error) {
if (!called) {
called = true;
if (!(error instanceof RippleError)) {
error = new RippleError(error);
}
callback.call(self, new RippleError(error));
} else {
callback.call(self, error);
}
};
}
}
this.once(this.successEvent, requestSuccess);
this.once(this.errorEvent, requestError);
@@ -233,21 +228,21 @@ Request.prototype.callback = function(callback, successEvent, errorEvent) {
};
Request.prototype.timeout = function(duration, callback) {
var self = this;
const self = this;
function requested() {
self.timeout(duration, callback);
};
}
if (!this.requested) {
// Defer until requested
return this.once('request', requested);
}
var emit = this.emit;
var timed_out = false;
const emit = this.emit;
let timed_out = false;
var timeout = setTimeout(function() {
const timeout = setTimeout(function() {
timed_out = true;
if (typeof callback === 'function') {
@@ -269,7 +264,7 @@ Request.prototype.timeout = function(duration, callback) {
};
Request.prototype.setServer = function(server) {
var selected = null;
let selected = null;
switch (typeof server) {
case 'object':
@@ -278,16 +273,16 @@ Request.prototype.setServer = function(server) {
case 'string':
// Find server by URL
var servers = this.remote._servers;
const servers = this.remote._servers;
for (var i=0, s; (s=servers[i]); i++) {
for (let i = 0, s; (s = servers[i]); i++) {
if (s._url === server) {
selected = s;
break;
}
}
break;
};
}
this.server = selected;
@@ -425,13 +420,11 @@ Request.prototype.rippleState = function(account, issuer, currency) {
};
Request.prototype.setAccounts =
Request.prototype.accounts = function(accounts, proposed) {
if (!Array.isArray(accounts)) {
accounts = [ accounts ];
}
Request.prototype.accounts = function(accountsIn, proposed) {
const accounts = Array.isArray(accountsIn) ? accountsIn : [accountsIn];
// Process accounts parameters
var processedAccounts = accounts.map(function(account) {
const processedAccounts = accounts.map(function(account) {
return UInt160.json_rewrite(account);
});
@@ -450,8 +443,8 @@ Request.prototype.addAccount = function(account, proposed) {
return this;
}
var processedAccount = UInt160.json_rewrite(account);
var prop = proposed === true ? 'accounts_proposed' : 'accounts';
const processedAccount = UInt160.json_rewrite(account);
const prop = proposed === true ? 'accounts_proposed' : 'accounts';
this.message[prop] = (this.message[prop] || []).concat(processedAccount);
return this;
@@ -477,8 +470,8 @@ Request.prototype.books = function(books, snapshot) {
// Reset list of books (this method overwrites the current list)
this.message.books = [];
for (var i=0, l=books.length; i<l; i++) {
var book = books[i];
for (let i = 0, l = books.length; i < l; i++) {
const book = books[i];
this.addBook(book, snapshot);
}
@@ -491,15 +484,17 @@ Request.prototype.addBook = function(book, snapshot) {
return this;
}
var json = { };
const json = { };
function processSide(side) {
if (!book[side]) {
throw new Error('Missing ' + side);
}
var obj = json[side] = {
currency: Currency.json_rewrite(book[side].currency, { force_hex: true })
const obj = json[side] = {
currency: Currency.json_rewrite(book[side].currency, {
force_hex: true
})
};
if (!Currency.from_json(obj.currency).is_native()) {
@@ -527,8 +522,6 @@ Request.prototype.addBook = function(book, snapshot) {
};
Request.prototype.addStream = function(stream, values) {
var self = this;
if (Array.isArray(values)) {
switch (stream) {
case 'accounts':
@@ -542,10 +535,10 @@ Request.prototype.addStream = function(stream, values) {
break;
}
} else if (arguments.length > 1) {
for (var arg in arguments) {
for (let arg in arguments) {
this.addStream(arguments[arg]);
}
return;
return this;
}
if (!Array.isArray(this.message.streams)) {

View File

@@ -1,10 +1,13 @@
var util = require('util');
var url = require('url');
var LRU = require('lru-cache');
var EventEmitter = require('events').EventEmitter;
var Amount = require('./amount').Amount;
var RangeSet = require('./rangeset').RangeSet;
var log = require('./log').internal.sub('server');
'use strict';
const _ = require('lodash');
const util = require('util');
const url = require('url');
const LRU = require('lru-cache');
const EventEmitter = require('events').EventEmitter;
const Amount = require('./amount').Amount;
const RangeSet = require('./rangeset').RangeSet;
const log = require('./log').internal.sub('server');
/**
* @constructor Server
@@ -16,18 +19,20 @@ var log = require('./log').internal.sub('server');
* @param [Boolean] securec
*/
function Server(remote, opts) {
function Server(remote, _opts) {
EventEmitter.call(this);
var self = this;
if (typeof opts === 'string') {
var parsedUrl = url.parse(opts);
const self = this;
let opts;
if (typeof _opts === 'string') {
const parsedUrl = url.parse(_opts);
opts = {
host: parsedUrl.hostname,
port: parsedUrl.port,
secure: (parsedUrl.protocol === 'ws:') ? false : true
};
} else {
opts = _opts;
}
if (typeof opts !== 'object') {
@@ -35,11 +40,14 @@ function Server(remote, opts) {
}
if (!Server.DOMAIN_RE.test(opts.host)) {
throw new Error('Server host is malformed, use "host" and "port" server configuration');
throw new Error(
'Server host is malformed, use "host" and "port" server configuration');
}
// We want to allow integer strings as valid port numbers for backward compatibility
if (!(opts.port = Number(opts.port))) {
// We want to allow integer strings as valid port numbers
// for backward compatibility
opts.port = Number(opts.port);
if (!opts.port) {
throw new TypeError('Server port must be a number');
}
@@ -53,13 +61,15 @@ function Server(remote, opts) {
this._remote = remote;
this._opts = opts;
this._ws = void(0);
this._ws = undefined;
this._connected = false;
this._shouldConnect = false;
this._state = 'offline';
this._ledgerRanges = new RangeSet();
this._ledgerMap = LRU({ max: 200 });
this._ledgerMap = new LRU({
max: 200
});
this._id = 0; // request ID
this._retry = 0;
@@ -71,8 +81,8 @@ function Server(remote, opts) {
this._fee = 10;
this._fee_ref = 10;
this._fee_base = 10;
this._reserve_base = void(0);
this._reserve_inc = void(0);
this._reserve_base = undefined;
this._reserve_inc = undefined;
this._fee_cushion = this._remote.fee_cushion;
this._lastLedgerIndex = NaN;
@@ -98,9 +108,9 @@ function Server(remote, opts) {
});
function setActivityInterval() {
var interval = self._checkActivity.bind(self);
const interval = self._checkActivity.bind(self);
self._activityInterval = setInterval(interval, 1000);
};
}
this.on('disconnect', function onDisconnect() {
clearInterval(self._activityInterval);
@@ -124,11 +134,13 @@ function Server(remote, opts) {
this.on('connect', function() {
self.requestServerID();
});
};
}
util.inherits(Server, EventEmitter);
/* eslint-disable max-len */
Server.DOMAIN_RE = /^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|[-_]){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|[-_]){0,61}[0-9A-Za-z])?)*\.?$/;
/* eslint-enable max-len */
Server.TLS_ERRORS = [
'UNABLE_TO_GET_ISSUER_CERT', 'UNABLE_TO_GET_CRL',
@@ -227,7 +239,7 @@ Server.prototype._checkActivity = function() {
return;
}
var delta = (Date.now() - this._lastLedgerClose);
const delta = (Date.now() - this._lastLedgerClose);
if (delta > (1000 * 25)) {
if (this._remote.trace) {
@@ -244,7 +256,7 @@ Server.prototype._checkActivity = function() {
*/
Server.prototype.requestServerID = function() {
var self = this;
const self = this;
if (this._pubkey_node) {
return;
@@ -254,10 +266,11 @@ Server.prototype.requestServerID = function() {
try {
self._pubkey_node = message.info.pubkey_node;
} catch (e) {
// empty
}
});
var serverInfoRequest = this._remote.requestServerInfo();
const serverInfoRequest = this._remote.requestServerInfo();
serverInfoRequest.on('error', function() {});
this._request(serverInfoRequest);
};
@@ -279,19 +292,20 @@ Server.prototype._updateScore = function(type, data) {
return;
}
var weight = this._scoreWeights[type] || 1;
const weight = this._scoreWeights[type] || 1;
let delta;
switch (type) {
case 'ledgerclose':
// Ledger lag
var delta = data.ledger_index - this._lastLedgerIndex;
delta = data.ledger_index - this._lastLedgerIndex;
if (delta > 0) {
this._score += weight * delta;
}
break;
case 'response':
// Ping lag
var delta = Math.floor((Date.now() - data.time) / 200);
delta = Math.floor((Date.now() - data.time) / 200);
this._score += weight * delta;
break;
case 'loadchange':
@@ -316,20 +330,18 @@ Server.prototype._updateScore = function(type, data) {
Server.prototype.getRemoteAddress =
Server.prototype._remoteAddress = function() {
var address;
try {
address = this._ws._socket.remoteAddress;
return this._ws._socket.remoteAddress;
} catch (e) {
// empty
}
return address;
};
/**
* Get the server's hostid
*/
Server.prototype.getHostID =
Server.prototype.getServerID = function() {
Server.prototype.getHostID = Server.prototype.getServerID = function() {
return this._url + ' (' + (this._pubkey_node ? this._pubkey_node : '') + ')';
};
@@ -340,7 +352,7 @@ Server.prototype.getServerID = function() {
*/
Server.prototype.disconnect = function() {
var self = this;
const self = this;
if (!this.isConnected()) {
this.once('socket_open', function() {
@@ -371,13 +383,13 @@ Server.prototype.disconnect = function() {
*/
Server.prototype.reconnect = function() {
var self = this;
const self = this;
function reconnect() {
self._shouldConnect = true;
self._retry = 0;
self.connect();
};
}
if (this._ws && this._shouldConnect) {
if (this.isConnected()) {
@@ -398,9 +410,9 @@ Server.prototype.reconnect = function() {
*/
Server.prototype.connect = function() {
var self = this;
const self = this;
var WebSocket = Server.websocketConstructor();
const WebSocket = Server.websocketConstructor();
if (!WebSocket) {
throw new Error('No websocket support detected!');
@@ -423,7 +435,7 @@ Server.prototype.connect = function() {
log.info(this.getServerID(), 'connect');
}
var ws = this._ws = new WebSocket(this._opts.url);
const ws = this._ws = new WebSocket(this._opts.url);
this._shouldConnect = true;
@@ -454,11 +466,13 @@ Server.prototype.connect = function() {
throw e;
}
// Most connection errors for WebSockets are conveyed as 'close' events with
// Most connection errors for WebSockets are conveyed as 'close'
// events with
// code 1006. This is done for security purposes and therefore unlikely to
// ever change.
// This means that this handler is hardly ever called in practice. If it is,
// This means that this handler is hardly ever called in practice.
// If it is,
// it probably means the server's WebSocket implementation is corrupt, or
// the connection is somehow producing corrupt data.
@@ -489,11 +503,11 @@ Server.prototype.connect = function() {
*/
Server.prototype._retryConnect = function() {
var self = this;
const self = this;
this._retry += 1;
var retryTimeout = (this._retry < 40)
const retryTimeout = (this._retry < 40)
// First, for 2 seconds: 20 times per second
? (1000 / 20)
: (this._retry < 40 + 60)
@@ -512,7 +526,7 @@ Server.prototype._retryConnect = function() {
}
self.connect();
}
};
}
this._retryTimer = setTimeout(connectionRetry, retryTimeout);
};
@@ -524,13 +538,10 @@ Server.prototype._retryConnect = function() {
*/
Server.prototype._handleClose = function() {
var self = this;
var ws = this._ws;
function noOp(){};
const ws = this._ws;
// Prevent additional events from this socket
ws.onopen = ws.onerror = ws.onclose = ws.onmessage = noOp;
ws.onopen = ws.onerror = ws.onclose = ws.onmessage = _.noop;
this.emit('socket_close');
this._setState('offline');
@@ -548,11 +559,13 @@ Server.prototype._handleClose = function() {
*/
Server.prototype._handleMessage = function(message) {
var self = this;
try {
// this is fixed in Brandon's pull request
/* eslint-disable no-param-reassign */
message = JSON.parse(message);
/* eslint-enable no-param-reassign */
} catch (e) {
// empty
}
if (!Server.isValidMessage(message)) {
@@ -587,7 +600,7 @@ Server.prototype._handleLedgerClosed = function(message) {
Server.prototype._handleServerStatus = function(message) {
// This message is only received when online.
// As we are connected, it is the definitive final state.
var isOnline = ~Server.onlineStates.indexOf(message.server_status);
const isOnline = ~Server.onlineStates.indexOf(message.server_status);
this._setState(isOnline ? 'online' : 'offline');
@@ -598,7 +611,7 @@ Server.prototype._handleServerStatus = function(message) {
this.emit('load', message, this);
this._remote.emit('load', message, this);
var loadChanged = message.load_base !== this._load_base
const loadChanged = message.load_base !== this._load_base
|| message.load_factor !== this._load_factor;
if (loadChanged) {
@@ -611,7 +624,7 @@ Server.prototype._handleServerStatus = function(message) {
Server.prototype._handleResponse = function(message) {
// A response to a request.
var request = this._requests[message.id];
const request = this._requests[message.id];
delete this._requests[message.id];
@@ -627,9 +640,9 @@ Server.prototype._handleResponse = function(message) {
log.info(this.getServerID(), 'response:', message);
}
var command = request.message.command;
var result = message.result;
var responseEvent = 'response_' + command;
const command = request.message.command;
const result = message.result;
const responseEvent = 'response_' + command;
request.emit('success', result);
@@ -675,7 +688,8 @@ Server.prototype._handleResponseSubscribe = function(message) {
&& !Server.hasFullLedgerHistory(message)) {
// Server has partial history and Remote has been configured to disallow
// servers with incomplete history
return this.reconnect();
this.reconnect();
return;
}
if (message.pubkey_node) {
@@ -768,7 +782,7 @@ Server.prototype._sendMessage = function(message) {
*/
Server.prototype._request = function(request) {
var self = this;
const self = this;
// Only bother if we are still connected.
if (!this._ws) {
@@ -789,10 +803,10 @@ Server.prototype._request = function(request) {
function sendRequest() {
self._sendMessage(request.message);
};
}
var isOpen = this._ws.readyState === 1;
var isSubscribeRequest = request && request.message.command === 'subscribe';
const isOpen = this._ws.readyState === 1;
const isSubscribeRequest = request && request.message.command === 'subscribe';
if (this.isConnected() || (isOpen && isSubscribeRequest)) {
sendRequest();
@@ -807,8 +821,7 @@ Server.prototype._request = function(request) {
* @return boolean
*/
Server.prototype.isConnected =
Server.prototype._isConnected = function() {
Server.prototype.isConnected = Server.prototype._isConnected = function() {
return this._connected;
};
@@ -838,7 +851,7 @@ Server.prototype._computeFee = function(feeUnits) {
*/
Server.prototype._feeTx = function(units) {
var fee_unit = this._feeTxUnit();
const fee_unit = this._feeTxUnit();
return Amount.from_json(String(Math.ceil(units * fee_unit)));
};
@@ -852,12 +865,13 @@ Server.prototype._feeTx = function(units) {
*/
Server.prototype._feeTxUnit = function() {
var fee_unit = this._fee_base / this._fee_ref;
let fee_unit = this._fee_base / this._fee_ref;
// Apply load fees
fee_unit *= this._load_factor / this._load_base;
// Apply fee cushion (a safety margin in case fees rise since we were last updated)
// Apply fee cushion (a safety margin in case fees rise since
// we were last updated)
fee_unit *= this._fee_cushion;
return fee_unit;
@@ -870,9 +884,9 @@ Server.prototype._feeTxUnit = function() {
*/
Server.prototype._reserve = function(ownerCount) {
var reserve_base = Amount.from_json(String(this._reserve_base));
var reserve_inc = Amount.from_json(String(this._reserve_inc));
var owner_count = ownerCount || 0;
const reserve_base = Amount.from_json(String(this._reserve_base));
const reserve_inc = Amount.from_json(String(this._reserve_inc));
const owner_count = ownerCount || 0;
if (owner_count < 0) {
throw new Error('Owner count must not be negative.');
@@ -889,11 +903,11 @@ Server.prototype._reserve = function(ownerCount) {
*/
Server.prototype.hasLedger = function(ledger) {
var result = false;
let result = false;
if (typeof ledger === 'string' && /^[A-F0-9]{64}$/.test(ledger)) {
result = this._ledgerMap.has(ledger);
} else if (ledger != null && !isNaN(ledger)) {
} else if (ledger !== null && !isNaN(ledger)) {
result = this._ledgerRanges.has(ledger);
}

View File

@@ -1,8 +1,8 @@
/* eslint-disable max-len */
'use strict';
var assert = require('assert');
var Amount = require('ripple-lib').Amount;
var UInt160 = require('ripple-lib').UInt160;
const assert = require('assert');
const Amount = require('ripple-lib').Amount;
const UInt160 = require('ripple-lib').UInt160;
describe('Amount', function() {
@@ -444,17 +444,17 @@ describe('Amount', function() {
});
describe('Amount to_json', function() {
it('10 USD', function() {
var amount = Amount.from_human('10 USD').to_json();
const amount = Amount.from_human('10 USD').to_json();
assert.strictEqual('10', amount.value);
assert.strictEqual('USD', amount.currency);
});
it('10 0000000000000000000000005553440000000000', function() {
var amount = Amount.from_human('10 0000000000000000000000005553440000000000').to_json();
const amount = Amount.from_human('10 0000000000000000000000005553440000000000').to_json();
assert.strictEqual('10', amount.value);
assert.strictEqual('USD', amount.currency);
});
it('10 015841551A748AD2C1F76FF6ECB0CCCD00000000', function() {
var amount = Amount.from_human('10 015841551A748AD2C1F76FF6ECB0CCCD00000000').to_json();
const amount = Amount.from_human('10 015841551A748AD2C1F76FF6ECB0CCCD00000000').to_json();
assert.strictEqual('10', amount.value);
assert.strictEqual('015841551A748AD2C1F76FF6ECB0CCCD00000000', amount.currency);
});
@@ -766,135 +766,135 @@ describe('Amount', function() {
});
describe('Amount comparisons', function() {
it('0 USD == 0 USD amount.equals string argument', function() {
var a = '0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL';
const a = '0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL';
assert(Amount.from_json(a).equals(a));
});
it('0 USD == 0 USD', function() {
var a = Amount.from_json('0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
var b = Amount.from_json('0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const a = Amount.from_json('0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const b = Amount.from_json('0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
assert(a.equals(b));
assert(!a.not_equals_why(b));
});
it('0 USD == -0 USD', function() {
var a = Amount.from_json('0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
var b = Amount.from_json('-0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const a = Amount.from_json('0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const b = Amount.from_json('-0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
assert(a.equals(b));
assert(!a.not_equals_why(b));
});
it('0 XRP == 0 XRP', function() {
var a = Amount.from_json('0');
var b = Amount.from_json('0');
const a = Amount.from_json('0');
const b = Amount.from_json('0');
assert(a.equals(b));
assert(!a.not_equals_why(b));
});
it('0 XRP == -0 XRP', function() {
var a = Amount.from_json('0');
var b = Amount.from_json('-0');
const a = Amount.from_json('0');
const b = Amount.from_json('-0');
assert(a.equals(b));
assert(!a.not_equals_why(b));
});
it('10 USD == 10 USD', function() {
var a = Amount.from_json('10/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
var b = Amount.from_json('10/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const a = Amount.from_json('10/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const b = Amount.from_json('10/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
assert(a.equals(b));
assert(!a.not_equals_why(b));
});
it('123.4567 USD == 123.4567 USD', function() {
var a = Amount.from_json('123.4567/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
var b = Amount.from_json('123.4567/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const a = Amount.from_json('123.4567/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const b = Amount.from_json('123.4567/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
assert(a.equals(b));
assert(!a.not_equals_why(b));
});
it('10 XRP == 10 XRP', function() {
var a = Amount.from_json('10');
var b = Amount.from_json('10');
const a = Amount.from_json('10');
const b = Amount.from_json('10');
assert(a.equals(b));
assert(!a.not_equals_why(b));
});
it('1.1 XRP == 1.1 XRP', function() {
var a = Amount.from_json('1100000');
var b = Amount.from_json('11000000').ratio_human('10/XRP');
const a = Amount.from_json('1100000');
const b = Amount.from_json('11000000').ratio_human('10/XRP');
assert(a.equals(b));
assert(!a.not_equals_why(b));
});
it('0 USD == 0 USD (ignore issuer)', function() {
var a = Amount.from_json('0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
var b = Amount.from_json('0/USD/rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP');
const a = Amount.from_json('0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const b = Amount.from_json('0/USD/rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP');
assert(a.equals(b, true));
assert(!a.not_equals_why(b, true));
});
it('1.1 USD == 1.10 USD (ignore issuer)', function() {
var a = Amount.from_json('1.1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
var b = Amount.from_json('1.10/USD/rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP');
const a = Amount.from_json('1.1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const b = Amount.from_json('1.10/USD/rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP');
assert(a.equals(b, true));
assert(!a.not_equals_why(b, true));
});
// Exponent mismatch
it('10 USD != 100 USD', function() {
var a = Amount.from_json('10/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
var b = Amount.from_json('100/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const a = Amount.from_json('10/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const b = Amount.from_json('100/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
assert(!a.equals(b));
assert.strictEqual(a.not_equals_why(b), 'Non-XRP value differs.');
});
it('10 XRP != 100 XRP', function() {
var a = Amount.from_json('10');
var b = Amount.from_json('100');
const a = Amount.from_json('10');
const b = Amount.from_json('100');
assert(!a.equals(b));
assert.strictEqual(a.not_equals_why(b), 'XRP value differs.');
});
// Mantissa mismatch
it('1 USD != 2 USD', function() {
var a = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
var b = Amount.from_json('2/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const a = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const b = Amount.from_json('2/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
assert(!a.equals(b));
assert.strictEqual(a.not_equals_why(b), 'Non-XRP value differs.');
});
it('1 XRP != 2 XRP', function() {
var a = Amount.from_json('1');
var b = Amount.from_json('2');
const a = Amount.from_json('1');
const b = Amount.from_json('2');
assert(!a.equals(b));
assert.strictEqual(a.not_equals_why(b), 'XRP value differs.');
});
it('0.1 USD != 0.2 USD', function() {
var a = Amount.from_json('0.1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
var b = Amount.from_json('0.2/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const a = Amount.from_json('0.1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const b = Amount.from_json('0.2/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
assert(!a.equals(b));
assert.strictEqual(a.not_equals_why(b), 'Non-XRP value differs.');
});
// Sign mismatch
it('1 USD != -1 USD', function() {
var a = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
var b = Amount.from_json('-1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const a = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const b = Amount.from_json('-1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
assert(!a.equals(b));
assert.strictEqual(a.not_equals_why(b), 'Non-XRP sign differs.');
});
it('1 XRP != -1 XRP', function() {
var a = Amount.from_json('1');
var b = Amount.from_json('-1');
const a = Amount.from_json('1');
const b = Amount.from_json('-1');
assert(!a.equals(b));
assert.strictEqual(a.not_equals_why(b), 'XRP sign differs.');
});
it('1 USD != 1 USD (issuer mismatch)', function() {
var a = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
var b = Amount.from_json('1/USD/rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP');
const a = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const b = Amount.from_json('1/USD/rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP');
assert(!a.equals(b));
assert.strictEqual(a.not_equals_why(b), 'Non-XRP issuer differs: rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
});
it('1 USD != 1 EUR', function() {
var a = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
var b = Amount.from_json('1/EUR/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const a = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const b = Amount.from_json('1/EUR/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
assert(!a.equals(b));
assert.strictEqual(a.not_equals_why(b), 'Non-XRP currency differs.');
});
it('1 USD != 1 XRP', function() {
var a = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
var b = Amount.from_json('1');
const a = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const b = Amount.from_json('1');
assert(!a.equals(b));
assert.strictEqual(a.not_equals_why(b), 'Native mismatch.');
});
it('1 XRP != 1 USD', function() {
var a = Amount.from_json('1');
var b = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
const a = Amount.from_json('1');
const b = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
assert(!a.equals(b));
assert.strictEqual(a.not_equals_why(b), 'Native mismatch.');
});
@@ -1147,38 +1147,38 @@ describe('Amount', function() {
describe('apply interest', function() {
it('from_json apply interest 10 XAU', function() {
var demAmount = Amount.from_json('10/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
let demAmount = Amount.from_json('10/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(demAmount.to_text_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
demAmount = demAmount.applyInterest(459990264);
assert.strictEqual(demAmount.to_text_full(), '9.294949401870436/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('from_json apply interest XAU', function() {
var demAmount = Amount.from_json('1235.5/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
let demAmount = Amount.from_json('1235.5/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(demAmount.to_text_full(), '1235.5/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
demAmount = demAmount.applyInterest(459990264);
assert.strictEqual(demAmount.to_text_full(), '1148.390998601092/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('from_human with reference date', function() {
var demAmount = Amount.from_human('10 0158415500000000C1F76FF6ECB0BAC600000000', {reference_date: 459990264});
const demAmount = Amount.from_human('10 0158415500000000C1F76FF6ECB0BAC600000000', {reference_date: 459990264});
demAmount.set_issuer('rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(demAmount.to_text_full(), '10.75853086191915/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('from_json apply interest 10 XAU human', function() {
var demAmount = Amount.from_json('10/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
let demAmount = Amount.from_json('10/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(demAmount.to_human_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
demAmount = demAmount.applyInterest(459990264);
assert.strictEqual(demAmount.to_human_full(), '9.294949401870436/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('from_json apply interest XAU human', function() {
var demAmount = Amount.from_json('1235.5/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
let demAmount = Amount.from_json('1235.5/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(demAmount.to_human_full(), '1,235.5/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
demAmount = demAmount.applyInterest(459990264);
assert.strictEqual(demAmount.to_human_full(), '1,148.390998601092/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('from_human with reference date human', function() {
var demAmount = Amount.from_human('10 0158415500000000C1F76FF6ECB0BAC600000000', {reference_date: 459990264});
const demAmount = Amount.from_human('10 0158415500000000C1F76FF6ECB0BAC600000000', {reference_date: 459990264});
demAmount.set_issuer('rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(demAmount.to_human_full(), '10.75853086191915/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
@@ -1202,12 +1202,12 @@ describe('Amount', function() {
});
it('from_json minimum XRP', function() {
var amt = Amount.from_json('-100000000000000000');
const amt = Amount.from_json('-100000000000000000');
assert.strictEqual(amt.to_json(), '-100000000000000000');
});
it('from_json maximum XRP', function() {
var amt = Amount.from_json('100000000000000000');
const amt = Amount.from_json('100000000000000000');
assert.strictEqual(amt.to_json(), '100000000000000000');
});
@@ -1224,7 +1224,7 @@ describe('Amount', function() {
});
it('from_json minimum IOU', function() {
var amt = Amount.from_json('-1e-81/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
const amt = Amount.from_json('-1e-81/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(amt.to_text(), '-1000000000000000e-96');
assert.strictEqual(amt.to_text(), Amount.min_value);
});
@@ -1236,7 +1236,7 @@ describe('Amount', function() {
});
it('from_json maximum IOU', function() {
var amt = Amount.from_json('9999999999999999e80/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
const amt = Amount.from_json('9999999999999999e80/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(amt.to_text(), '9999999999999999e80');
});
@@ -1247,12 +1247,12 @@ describe('Amount', function() {
});
it('from_json normalize mantissa to valid max range, lost significant digits', function() {
var amt = Amount.from_json('99999999999999999999999999999999/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
const amt = Amount.from_json('99999999999999999999999999999999/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(amt.to_text(), '9999999999999999e16');
});
it('from_json normalize mantissa to min valid range, lost significant digits', function() {
var amt = Amount.from_json('-0.0000000000000000000000001/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
const amt = Amount.from_json('-0.0000000000000000000000001/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(amt.to_text(), '-1000000000000000e-40');
});
});

View File

@@ -1,32 +1,37 @@
var assert = require('assert');
var fs = require('fs');
/* eslint-disable max-len */
'use strict';
var Ledger = require('ripple-lib').Ledger;
const assert = require('assert');
const fs = require('fs');
const Ledger = require('ripple-lib').Ledger;
/**
* @param ledger_index {Number}
* Expects a corresponding ledger dump in $repo/test/fixtures/ folder
*/
var create_ledger_test = function (ledger_index) {
function create_ledger_test(ledger_index) {
describe(String(ledger_index), function() {
var path = __dirname + '/fixtures/ledger-full-'+ledger_index+'.json';
const path = __dirname + '/fixtures/ledger-full-' + ledger_index + '.json';
var ledger_raw = fs.readFileSync(path),
ledger_json = JSON.parse(ledger_raw),
ledger = Ledger.from_json(ledger_json);
const ledger_raw = fs.readFileSync(path);
const ledger_json = JSON.parse(ledger_raw);
const ledger = Ledger.from_json(ledger_json);
it('has account_hash of ' + ledger_json.account_hash, function() {
assert.equal(ledger_json.account_hash,
ledger.calc_account_hash({sanity_test:true}).to_hex());
})
ledger.calc_account_hash({
sanity_test: true
}).to_hex());
});
it('has transaction_hash of ' + ledger_json.transaction_hash, function() {
assert.equal(ledger_json.transaction_hash,
ledger.calc_tx_hash().to_hex());
})
})
});
});
}
describe('Ledger', function() {
// This is the first recorded ledger with a non empty transaction set
create_ledger_test(38129);
@@ -35,9 +40,9 @@ describe('Ledger', function() {
describe('#calcAccountRootEntryHash', function() {
it('will calculate the AccountRoot entry hash for rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function() {
var account = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh';
var expectedEntryHash = '2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8';
var actualEntryHash = Ledger.calcAccountRootEntryHash(account);
const account = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh';
const expectedEntryHash = '2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8';
const actualEntryHash = Ledger.calcAccountRootEntryHash(account);
assert.equal(actualEntryHash.to_hex(), expectedEntryHash);
});
@@ -45,26 +50,26 @@ describe('Ledger', function() {
describe('#calcRippleStateEntryHash', function() {
it('will calculate the RippleState entry hash for rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh and rB5TihdPbKgMrkFqrqUC3yLdE8hhv4BdeY in USD', function() {
var account1 = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh';
var account2 = 'rB5TihdPbKgMrkFqrqUC3yLdE8hhv4BdeY';
var currency = 'USD';
const account1 = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh';
const account2 = 'rB5TihdPbKgMrkFqrqUC3yLdE8hhv4BdeY';
const currency = 'USD';
var expectedEntryHash = 'C683B5BB928F025F1E860D9D69D6C554C2202DE0D45877ADB3077DA4CB9E125C';
var actualEntryHash1 = Ledger.calcRippleStateEntryHash(account1, account2, currency);
var actualEntryHash2 = Ledger.calcRippleStateEntryHash(account2, account1, currency);
const expectedEntryHash = 'C683B5BB928F025F1E860D9D69D6C554C2202DE0D45877ADB3077DA4CB9E125C';
const actualEntryHash1 = Ledger.calcRippleStateEntryHash(account1, account2, currency);
const actualEntryHash2 = Ledger.calcRippleStateEntryHash(account2, account1, currency);
assert.equal(actualEntryHash1.to_hex(), expectedEntryHash);
assert.equal(actualEntryHash2.to_hex(), expectedEntryHash);
});
it('will calculate the RippleState entry hash for r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV and rUAMuQTfVhbfqUDuro7zzy4jj4Wq57MPTj in UAM', function() {
var account1 = 'r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV';
var account2 = 'rUAMuQTfVhbfqUDuro7zzy4jj4Wq57MPTj';
var currency = 'UAM';
const account1 = 'r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV';
const account2 = 'rUAMuQTfVhbfqUDuro7zzy4jj4Wq57MPTj';
const currency = 'UAM';
var expectedEntryHash = 'AE9ADDC584358E5847ADFC971834E471436FC3E9DE6EA1773DF49F419DC0F65E';
var actualEntryHash1 = Ledger.calcRippleStateEntryHash(account1, account2, currency);
var actualEntryHash2 = Ledger.calcRippleStateEntryHash(account2, account1, currency);
const expectedEntryHash = 'AE9ADDC584358E5847ADFC971834E471436FC3E9DE6EA1773DF49F419DC0F65E';
const actualEntryHash1 = Ledger.calcRippleStateEntryHash(account1, account2, currency);
const actualEntryHash2 = Ledger.calcRippleStateEntryHash(account2, account1, currency);
assert.equal(actualEntryHash1.to_hex(), expectedEntryHash);
assert.equal(actualEntryHash2.to_hex(), expectedEntryHash);
@@ -73,10 +78,10 @@ describe('Ledger', function() {
describe('#calcOfferEntryHash', function() {
it('will calculate the Offer entry hash for r32UufnaCGL82HubijgJGDmdE5hac7ZvLw, sequence 137', function() {
var account = 'r32UufnaCGL82HubijgJGDmdE5hac7ZvLw';
var sequence = 137
var expectedEntryHash = '03F0AED09DEEE74CEF85CD57A0429D6113507CF759C597BABB4ADB752F734CE3';
var actualEntryHash = Ledger.calcOfferEntryHash(account, sequence);
const account = 'r32UufnaCGL82HubijgJGDmdE5hac7ZvLw';
const sequence = 137;
const expectedEntryHash = '03F0AED09DEEE74CEF85CD57A0429D6113507CF759C597BABB4ADB752F734CE3';
const actualEntryHash = Ledger.calcOfferEntryHash(account, sequence);
assert.equal(actualEntryHash.to_hex(), expectedEntryHash);
});

View File

@@ -1,15 +1,16 @@
var assert = require('assert');
var Request = require('ripple-lib').Request;
var Remote = require('ripple-lib').Remote;
var Server = require('ripple-lib').Server;
var Currency = require('ripple-lib').Currency;
var RippleError = require('ripple-lib').RippleError;
'use strict';
const assert = require('assert');
const Request = require('ripple-lib').Request;
const Remote = require('ripple-lib').Remote;
const Server = require('ripple-lib').Server;
const Currency = require('ripple-lib').Currency;
const RippleError = require('ripple-lib').RippleError;
function makeServer(url) {
var server = new Server(new process.EventEmitter(), url);
const server = new Server(new process.EventEmitter(), url);
server._connected = true;
return server;
};
}
const SERVER_INFO = {
'info': {
@@ -28,7 +29,8 @@ const SERVER_INFO = {
'validated_ledger': {
'age': 0,
'base_fee_xrp': 0.00001,
'hash': 'E43FD49087B18031721D9C3C4743FE1692C326AFF7084A2C01B355CE65A4C699',
'hash':
'E43FD49087B18031721D9C3C4743FE1692C326AFF7084A2C01B355CE65A4C699',
'reserve_base_xrp': 20,
'reserve_inc_xrp': 5,
'seq': 7016339
@@ -39,7 +41,7 @@ const SERVER_INFO = {
describe('Request', function() {
it('Send request', function(done) {
var remote = {
const remote = {
request: function(req) {
assert(req instanceof Request);
assert.strictEqual(typeof req.message, 'object');
@@ -48,7 +50,7 @@ describe('Request', function() {
}
};
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.request();
@@ -57,29 +59,31 @@ describe('Request', function() {
});
it('Send request -- filterRequest', function(done) {
var servers = [
const servers = [
makeServer('wss://localhost:5006'),
makeServer('wss://localhost:5007')
];
var requests = 0;
let requests = 0;
var successResponse = {
const successResponse = {
account_data: {
Account: 'rnoFoLJmqmXe7a7iswk19yfdMHQkbQNrKC',
Balance: '13188802787',
Flags: 0,
LedgerEntryType: 'AccountRoot',
OwnerCount: 17,
PreviousTxnID: 'C6A2313CD9E34FFA3EB42F82B2B30F7FE12A045F1F4FDDAF006B25D7286536DD',
PreviousTxnID:
'C6A2313CD9E34FFA3EB42F82B2B30F7FE12A045F1F4FDDAF006B25D7286536DD',
PreviousTxnLgrSeq: 8828020,
Sequence: 1406,
index: '4F83A2CF7E70F77F79A307E6A472BFC2585B806A70833CCD1C26105BAE0D6E05'
index:
'4F83A2CF7E70F77F79A307E6A472BFC2585B806A70833CCD1C26105BAE0D6E05'
},
ledger_current_index: 9022821,
validated: false
};
var errorResponse = {
const errorResponse = {
error: 'remoteError',
error_message: 'Remote reported an error.',
remote: {
@@ -104,7 +108,7 @@ describe('Request', function() {
assert(req instanceof Request);
assert.strictEqual(typeof req.message, 'object');
assert.strictEqual(req.message.command, 'account_info');
};
}
servers[0]._request = function(req) {
++requests;
@@ -120,11 +124,11 @@ describe('Request', function() {
});
};
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
remote._servers = servers;
var request = new Request(remote, 'account_info');
const request = new Request(remote, 'account_info');
request.message.account = 'rnoFoLJmqmXe7a7iswk19yfdMHQkbQNrKC';
@@ -143,14 +147,14 @@ describe('Request', function() {
});
it('Send request -- filterRequest -- no success', function(done) {
var servers = [
const servers = [
makeServer('wss://localhost:5006'),
makeServer('wss://localhost:5007')
];
var requests = 0;
let requests = 0;
var errorResponse = {
const errorResponse = {
error: 'remoteError',
error_message: 'Remote reported an error.',
remote: {
@@ -175,21 +179,22 @@ describe('Request', function() {
assert(req instanceof Request);
assert.strictEqual(typeof req.message, 'object');
assert.strictEqual(req.message.command, 'account_info');
};
}
function sendError(req) {
++requests;
checkRequest(req);
req.emit('error', errorResponse);
};
}
servers[0]._request = sendError;
servers[1]._request = sendError;
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
remote._servers = servers;
var request = new Request(remote, 'account_info');
const request = new Request(remote, 'account_info');
request.message.account = 'rnoFoLJmqmXe7a7iswk19yfdMHQkbQNrKC';
@@ -199,7 +204,7 @@ describe('Request', function() {
&& !res.hasOwnProperty('error');
});
request.callback(function(err, res) {
request.callback(function(err) {
setImmediate(function() {
assert.strictEqual(requests, 2, 'Failed to broadcast');
assert.deepEqual(err, new RippleError(errorResponse));
@@ -209,24 +214,26 @@ describe('Request', function() {
});
it('Send request -- filterRequest -- ledger prefilter', function(done) {
var servers = [
const servers = [
makeServer('wss://localhost:5006'),
makeServer('wss://localhost:5007')
];
var requests = 0;
let requests = 0;
var successResponse = {
const successResponse = {
account_data: {
Account: 'rnoFoLJmqmXe7a7iswk19yfdMHQkbQNrKC',
Balance: '13188802787',
Flags: 0,
LedgerEntryType: 'AccountRoot',
OwnerCount: 17,
PreviousTxnID: 'C6A2313CD9E34FFA3EB42F82B2B30F7FE12A045F1F4FDDAF006B25D7286536DD',
PreviousTxnID:
'C6A2313CD9E34FFA3EB42F82B2B30F7FE12A045F1F4FDDAF006B25D7286536DD',
PreviousTxnLgrSeq: 8828020,
Sequence: 1406,
index: '4F83A2CF7E70F77F79A307E6A472BFC2585B806A70833CCD1C26105BAE0D6E05'
index:
'4F83A2CF7E70F77F79A307E6A472BFC2585B806A70833CCD1C26105BAE0D6E05'
},
ledger_current_index: 9022821,
validated: false
@@ -236,9 +243,9 @@ describe('Request', function() {
assert(req instanceof Request);
assert.strictEqual(typeof req.message, 'object');
assert.strictEqual(req.message.command, 'account_info');
};
}
servers[0]._request = function(req) {
servers[0]._request = function() {
assert(false, 'Should not request; server does not have ledger');
};
@@ -253,11 +260,11 @@ describe('Request', function() {
servers[0]._ledgerRanges.add('5-6');
servers[1]._ledgerRanges.add('1-4');
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
remote._servers = servers;
var request = new Request(remote, 'account_info');
const request = new Request(remote, 'account_info');
request.message.account = 'rnoFoLJmqmXe7a7iswk19yfdMHQkbQNrKC';
request.selectLedger(4);
@@ -275,29 +282,31 @@ describe('Request', function() {
});
it('Send request -- filterRequest -- server reconnects', function(done) {
var servers = [
const servers = [
makeServer('wss://localhost:5006'),
makeServer('wss://localhost:5007')
];
var requests = 0;
let requests = 0;
var successResponse = {
const successResponse = {
account_data: {
Account: 'rnoFoLJmqmXe7a7iswk19yfdMHQkbQNrKC',
Balance: '13188802787',
Flags: 0,
LedgerEntryType: 'AccountRoot',
OwnerCount: 17,
PreviousTxnID: 'C6A2313CD9E34FFA3EB42F82B2B30F7FE12A045F1F4FDDAF006B25D7286536DD',
PreviousTxnID:
'C6A2313CD9E34FFA3EB42F82B2B30F7FE12A045F1F4FDDAF006B25D7286536DD',
PreviousTxnLgrSeq: 8828020,
Sequence: 1406,
index: '4F83A2CF7E70F77F79A307E6A472BFC2585B806A70833CCD1C26105BAE0D6E05'
index:
'4F83A2CF7E70F77F79A307E6A472BFC2585B806A70833CCD1C26105BAE0D6E05'
},
ledger_current_index: 9022821,
validated: false
};
var errorResponse = {
const errorResponse = {
error: 'remoteError',
error_message: 'Remote reported an error.',
remote: {
@@ -322,7 +331,7 @@ describe('Request', function() {
assert(req instanceof Request);
assert.strictEqual(typeof req.message, 'object');
assert.strictEqual(req.message.command, 'account_info');
};
}
servers[0]._connected = false;
servers[0]._shouldConnect = true;
@@ -343,11 +352,11 @@ describe('Request', function() {
servers[0].emit('connect');
};
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
remote._servers = servers;
var request = new Request(remote, 'account_info');
const request = new Request(remote, 'account_info');
request.message.account = 'rnoFoLJmqmXe7a7iswk19yfdMHQkbQNrKC';
@@ -367,30 +376,33 @@ describe('Request', function() {
});
});
it('Send request -- filterRequest -- server fails to reconnect', function(done) {
var servers = [
it('Send request -- filterRequest -- server fails to reconnect',
function(done) {
const servers = [
makeServer('wss://localhost:5006'),
makeServer('wss://localhost:5007')
];
var requests = 0;
let requests = 0;
var successResponse = {
const successResponse = {
account_data: {
Account: 'rnoFoLJmqmXe7a7iswk19yfdMHQkbQNrKC',
Balance: '13188802787',
Flags: 0,
LedgerEntryType: 'AccountRoot',
OwnerCount: 17,
PreviousTxnID: 'C6A2313CD9E34FFA3EB42F82B2B30F7FE12A045F1F4FDDAF006B25D7286536DD',
PreviousTxnID:
'C6A2313CD9E34FFA3EB42F82B2B30F7FE12A045F1F4FDDAF006B25D7286536DD',
PreviousTxnLgrSeq: 8828020,
Sequence: 1406,
index: '4F83A2CF7E70F77F79A307E6A472BFC2585B806A70833CCD1C26105BAE0D6E05'
index:
'4F83A2CF7E70F77F79A307E6A472BFC2585B806A70833CCD1C26105BAE0D6E05'
},
ledger_current_index: 9022821,
validated: false
};
var errorResponse = {
const errorResponse = {
error: 'remoteError',
error_message: 'Remote reported an error.',
remote: {
@@ -415,7 +427,7 @@ describe('Request', function() {
assert(req instanceof Request);
assert.strictEqual(typeof req.message, 'object');
assert.strictEqual(req.message.command, 'account_info');
};
}
servers[0]._connected = false;
servers[0]._shouldConnect = true;
@@ -437,11 +449,11 @@ describe('Request', function() {
req.emit('error', errorResponse);
};
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
remote._servers = servers;
var request = new Request(remote, 'account_info');
const request = new Request(remote, 'account_info');
request.setReconnectTimeout(10);
request.message.account = 'rnoFoLJmqmXe7a7iswk19yfdMHQkbQNrKC';
@@ -451,7 +463,7 @@ describe('Request', function() {
&& !res.hasOwnProperty('error');
});
request.callback(function(err, res) {
request.callback(function(err) {
setTimeout(function() {
// Wait for the request that would emit 'success' to time out
assert.deepEqual(err, new RippleError(errorResponse));
@@ -462,7 +474,7 @@ describe('Request', function() {
});
it('Events API', function(done) {
var server = makeServer('wss://localhost:5006');
const server = makeServer('wss://localhost:5006');
server._request = function(req) {
assert(req instanceof Request);
@@ -471,11 +483,11 @@ describe('Request', function() {
req.emit('success', SERVER_INFO);
};
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
remote._servers = [server];
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.once('success', function(res) {
assert.deepEqual(res, SERVER_INFO);
@@ -486,7 +498,7 @@ describe('Request', function() {
});
it('Callback API', function(done) {
var server = makeServer('wss://localhost:5006');
const server = makeServer('wss://localhost:5006');
server._request = function(req) {
assert(req instanceof Request);
@@ -495,11 +507,11 @@ describe('Request', function() {
req.emit('success', SERVER_INFO);
};
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
remote._servers = [server];
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.callback(function(err, res) {
assert.ifError(err);
@@ -509,8 +521,8 @@ describe('Request', function() {
});
it('Timeout', function(done) {
var server = makeServer('wss://localhost:5006');
var successEmitted = false;
const server = makeServer('wss://localhost:5006');
let successEmitted = false;
server._request = function(req) {
assert(req instanceof Request);
@@ -522,11 +534,11 @@ describe('Request', function() {
}, 200);
};
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
remote._servers = [server];
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.timeout(10, function() {
setTimeout(function() {
@@ -535,32 +547,30 @@ describe('Request', function() {
}, 200);
});
request.callback(function(err, res) {
request.callback(function() {
assert(false, 'Callback should not be called');
});
});
it('Timeout - satisfied', function(done) {
var server = makeServer('wss://localhost:5006');
var successEmitted = false;
const server = makeServer('wss://localhost:5006');
server._request = function(req) {
assert(req instanceof Request);
assert.strictEqual(typeof req.message, 'object');
assert.strictEqual(req.message.command, 'server_info');
setTimeout(function() {
successEmitted = true;
req.emit('success', SERVER_INFO);
}, 200);
};
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
remote._servers = [server];
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
var timedOut = false;
let timedOut = false;
request.once('timeout', function() {
timedOut = true;
@@ -577,7 +587,7 @@ describe('Request', function() {
});
it('Set server', function(done) {
var servers = [
const servers = [
makeServer('wss://localhost:5006'),
makeServer('wss://localhost:5007')
];
@@ -589,7 +599,7 @@ describe('Request', function() {
done();
};
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
remote._servers = servers;
@@ -597,7 +607,7 @@ describe('Request', function() {
return servers[0];
};
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.setServer(servers[1]);
assert.strictEqual(request.server, servers[1]);
@@ -606,7 +616,7 @@ describe('Request', function() {
});
it('Set server - by URL', function(done) {
var servers = [
const servers = [
makeServer('wss://localhost:5006'),
makeServer('wss://127.0.0.1:5007')
];
@@ -618,7 +628,7 @@ describe('Request', function() {
done();
};
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
remote._servers = servers;
@@ -626,7 +636,7 @@ describe('Request', function() {
return servers[0];
};
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.setServer('wss://127.0.0.1:5007');
assert.strictEqual(request.server, servers[1]);
@@ -635,30 +645,30 @@ describe('Request', function() {
});
it('Set build path', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
remote.local_signing = false;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.buildPath(true);
assert.strictEqual(request.message.build_path, true);
});
it('Remove build path', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
remote.local_signing = false;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.buildPath(false);
assert(!request.message.hasOwnProperty('build_path'));
});
it('Set build path with local signing', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
assert.throws(function() {
request.buildPath(true);
@@ -666,125 +676,133 @@ describe('Request', function() {
});
it('Set ledger hash', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
request.ledgerHash('B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
assert.strictEqual(request.message.ledger_hash, 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
const request = new Request(remote, 'server_info');
request.ledgerHash(
'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
assert.strictEqual(request.message.ledger_hash,
'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
});
it('Set ledger index', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.ledgerIndex(7016915);
assert.strictEqual(request.message.ledger_index, 7016915);
});
it('Select cached ledger - index', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
remote._ledger_current_index = 1;
remote._ledger_hash = 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE';
remote._ledger_hash =
'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE';
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.ledgerChoose(true);
assert.strictEqual(request.message.ledger_index, 1);
});
it('Select cached ledger - hash', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
remote._ledger_current_index = 1;
remote._ledger_hash = 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE';
remote._ledger_hash =
'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE';
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.ledgerChoose();
assert.strictEqual(request.message.ledger_hash, 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
assert.strictEqual(request.message.ledger_index, void(0));
assert.strictEqual(request.message.ledger_hash,
'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
assert.strictEqual(request.message.ledger_index, undefined);
});
it('Select ledger - identifier', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.ledgerSelect('validated');
assert.strictEqual(request.message.ledger_index, 'validated');
assert.strictEqual(request.message.ledger_hash, void(0));
assert.strictEqual(request.message.ledger_hash, undefined);
});
it('Select ledger - index', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.ledgerSelect(7016915);
assert.strictEqual(request.message.ledger_index, 7016915);
assert.strictEqual(request.message.ledger_hash, void(0));
assert.strictEqual(request.message.ledger_hash, undefined);
});
it('Select ledger - index (String)', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.ledgerSelect('7016915');
assert.strictEqual(request.message.ledger_index, 7016915);
assert.strictEqual(request.message.ledger_hash, void(0));
assert.strictEqual(request.message.ledger_hash, undefined);
});
it('Select ledger - hash', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
request.ledgerSelect('B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
assert.strictEqual(request.message.ledger_hash, 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
assert.strictEqual(request.message.ledger_index, void(0));
const request = new Request(remote, 'server_info');
request.ledgerSelect(
'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
assert.strictEqual(request.message.ledger_hash,
'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
assert.strictEqual(request.message.ledger_index, undefined);
});
it('Select ledger - undefined', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.ledgerSelect();
assert.strictEqual(request.message.ledger_hash, void(0));
assert.strictEqual(request.message.ledger_index, void(0));
assert.strictEqual(request.message.ledger_hash, undefined);
assert.strictEqual(request.message.ledger_index, undefined);
request.ledgerSelect(null);
assert.strictEqual(request.message.ledger_hash, void(0));
assert.strictEqual(request.message.ledger_index, void(0));
assert.strictEqual(request.message.ledger_hash, undefined);
assert.strictEqual(request.message.ledger_index, undefined);
request.ledgerSelect(NaN);
assert.strictEqual(request.message.ledger_hash, void(0));
assert.strictEqual(request.message.ledger_index, void(0));
assert.strictEqual(request.message.ledger_hash, undefined);
assert.strictEqual(request.message.ledger_index, undefined);
});
it('Set account_root', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.accountRoot('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59');
assert.strictEqual(request.message.account_root, 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59');
assert.strictEqual(request.message.account_root,
'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59');
});
it('Set index', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.index(1);
assert.strictEqual(request.message.index, 1);
});
it('Set offer ID', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.offerId('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', 1337);
assert.deepEqual(request.message.offer, {
account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
@@ -793,68 +811,74 @@ describe('Request', function() {
});
it('Set offer index', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.offerIndex(1337);
assert.strictEqual(request.message.offer, 1337);
});
it('Set secret', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.secret('mySecret');
assert.strictEqual(request.message.secret, 'mySecret');
});
it('Set transaction hash', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
request.txHash('E08D6E9754025BA2534A78707605E0601F03ACE063687A0CA1BDDACFCD1698C7');
assert.strictEqual(request.message.tx_hash, 'E08D6E9754025BA2534A78707605E0601F03ACE063687A0CA1BDDACFCD1698C7');
const request = new Request(remote, 'server_info');
request.txHash(
'E08D6E9754025BA2534A78707605E0601F03ACE063687A0CA1BDDACFCD1698C7');
assert.strictEqual(request.message.tx_hash,
'E08D6E9754025BA2534A78707605E0601F03ACE063687A0CA1BDDACFCD1698C7');
});
it('Set transaction JSON', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
var txJson = { hash: 'E08D6E9754025BA2534A78707605E0601F03ACE063687A0CA1BDDACFCD1698C7' };
const request = new Request(remote, 'server_info');
const txJson = {
hash: 'E08D6E9754025BA2534A78707605E0601F03ACE063687A0CA1BDDACFCD1698C7'
};
request.txJson(txJson);
assert.deepEqual(request.message.tx_json, txJson);
});
it('Set transaction blob', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.txBlob('asdf');
assert.strictEqual(request.message.tx_blob, 'asdf');
});
it('Set ripple state', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
request.rippleState('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', 'USD');
const request = new Request(remote, 'server_info');
request.rippleState('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', 'USD');
assert.deepEqual(request.message.ripple_state, {
currency: 'USD',
accounts: [ 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59' ]
accounts: ['r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59']
});
});
it('Set accounts', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.accounts([
'rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun',
@@ -868,10 +892,10 @@ describe('Request', function() {
});
it('Set accounts - string', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.accounts('rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun');
@@ -881,10 +905,10 @@ describe('Request', function() {
});
it('Set accounts proposed', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.accountsProposed([
'rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun',
'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
@@ -897,13 +921,13 @@ describe('Request', function() {
});
it('Add account', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.accounts([
'rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun',
'rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun'
]);
request.addAccount('rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B');
@@ -915,13 +939,13 @@ describe('Request', function() {
});
it('Add account proposed', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.accountsProposed([
'rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun',
'rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun'
]);
request.addAccountProposed('rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B');
@@ -933,12 +957,12 @@ describe('Request', function() {
});
it('Set books', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
var books = [
const books = [
{
'taker_gets': {
'currency': 'EUR',
@@ -969,10 +993,10 @@ describe('Request', function() {
});
it('Add book', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.addBook({
'taker_gets': {
@@ -999,7 +1023,7 @@ describe('Request', function() {
}
]);
var books = [
const books = [
{
'taker_gets': {
'currency': 'EUR',
@@ -1025,19 +1049,19 @@ describe('Request', function() {
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
},
'snapshot': true
},
}
]);
});
it('Add book - missing side', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.message.books = void(0);
request.message.books = undefined;
var books = [
const books = [
{
'taker_gets': {
'currency': 'EUR',
@@ -1052,14 +1076,14 @@ describe('Request', function() {
});
it('Add book - without snapshot', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.message.books = void(0);
request.message.books = undefined;
var book = {
const book = {
'taker_gets': {
'currency': 'EUR',
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
@@ -1088,14 +1112,14 @@ describe('Request', function() {
});
it('Add book - no snapshot', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
const request = new Request(remote, 'server_info');
request.message.books = void(0);
request.message.books = undefined;
var book = {
const book = {
'taker_gets': {
'currency': 'EUR',
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
@@ -1123,15 +1147,17 @@ describe('Request', function() {
});
it('Add stream', function() {
var remote = new Remote();
const remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'subscribe');
const request = new Request(remote, 'subscribe');
request.addStream('server', 'ledger');
request.addStream('transactions', 'transactions_proposed');
request.addStream('accounts', ['rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B']);
request.addStream('accounts_proposed', [ 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59' ]);
request.addStream('accounts_proposed', [
'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'
]);
request.addStream('books', [{
'taker_gets': {
'currency': 'EUR',
@@ -1145,7 +1171,7 @@ describe('Request', function() {
assert.deepEqual(request.message, {
'command': 'subscribe',
'id': void(0),
'id': undefined,
'streams': [
'server',
'ledger',

File diff suppressed because it is too large Load Diff