mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-12 08:35:48 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfc21fde8c | ||
|
|
5c06ef547b | ||
|
|
0990ad4a6f | ||
|
|
d8f967d2b8 | ||
|
|
fe1c3e7130 | ||
|
|
062148674c | ||
|
|
11320693fd | ||
|
|
7af7eaccb4 | ||
|
|
5d5cf868a2 | ||
|
|
ddf8fe5b1a |
10
HISTORY.md
10
HISTORY.md
@@ -1,3 +1,13 @@
|
||||
##0.15.2
|
||||
**Changes**
|
||||
+ [Fix support for proxy credentials in proxy URL and fix error when there are more than 10 outstanding requests](https://github.com/ripple/ripple-lib/commit/0990ad4a6f1d59ca9d2cb859b4e2d71693f3fc4b)
|
||||
|
||||
##0.15.1
|
||||
**Changes**
|
||||
+ [Fix babel-polyfill require](https://github.com/ripple/ripple-lib/commit/062148674c3b1293ab82c28e25615ddd530339fa)
|
||||
+ [Fix samples](https://github.com/ripple/ripple-lib/commit/5d5cf868a2ddb1b1cd40e4a4f0a782d0066c2055)
|
||||
+ [add unit tests for RippleAPIBroadcast](https://github.com/ripple/ripple-lib/commit/ddf8fe5b1a9c750490dca98fb9ffaaf8017f87e0)
|
||||
|
||||
##0.15.0
|
||||
**Breaking Changes**
|
||||
+ ["servers" parameter changed to single "server"](https://github.com/ripple/ripple-lib/commit/7061e9afe46f0682254d098adeff3dd7157521a1)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
const RippleAPI = require('../../src').RippleAPI; // require('ripple-lib')
|
||||
|
||||
const api = new RippleAPI({servers: ['wss://s1.ripple.com:443']});
|
||||
const api = new RippleAPI({server: 'wss://s1.ripple.com:443'});
|
||||
const address = 'r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV';
|
||||
|
||||
api.connect().then(() => {
|
||||
|
||||
@@ -4,13 +4,13 @@ const RippleAPI = require('../../src').RippleAPI; // require('ripple-lib')
|
||||
const address = 'INSERT ADDRESS HERE';
|
||||
const secret = 'INSERT SECRET HERE';
|
||||
|
||||
const api = new RippleAPI({servers: ['wss://s1.ripple.com:443']});
|
||||
const api = new RippleAPI({server: 'wss://s1.ripple.com:443'});
|
||||
const instructions = {maxLedgerVersionOffset: 5};
|
||||
|
||||
const payment = {
|
||||
source: {
|
||||
address: address,
|
||||
amount: {
|
||||
maxAmount: {
|
||||
value: '0.01',
|
||||
currency: 'XRP'
|
||||
}
|
||||
|
||||
2
npm-shrinkwrap.json
generated
2
npm-shrinkwrap.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ripple-lib",
|
||||
"version": "0.15.0",
|
||||
"version": "0.15.2",
|
||||
"dependencies": {
|
||||
"ajv": {
|
||||
"version": "1.4.8",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ripple-lib",
|
||||
"version": "0.15.0",
|
||||
"version": "0.15.2",
|
||||
"license": "ISC",
|
||||
"description": "A JavaScript API for interacting with Ripple in Node.js and the browser",
|
||||
"files": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// In node.js env, polyfill might be already loaded (from any npm package),
|
||||
// that's why we do this check.
|
||||
if (!global._babelPolyfill) {
|
||||
require('babel-core/polyfill');
|
||||
require('babel-polyfill');
|
||||
}
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
@@ -15,6 +15,7 @@ function isStreamMessageType(type) {
|
||||
class Connection extends EventEmitter {
|
||||
constructor(url, options = {}) {
|
||||
super();
|
||||
this.setMaxListeners(Infinity);
|
||||
this._url = url;
|
||||
this._trace = options.trace;
|
||||
if (this._trace) {
|
||||
@@ -111,8 +112,10 @@ class Connection extends EventEmitter {
|
||||
const proxyOptions = parseURL(proxyURL);
|
||||
proxyOptions.secureEndpoint = (parsedURL.protocol === 'wss:');
|
||||
proxyOptions.secureProxy = (proxyOptions.protocol === 'https:');
|
||||
proxyOptions.auth = proxyAuthorization;
|
||||
if (trustedCertificates) {
|
||||
if (proxyAuthorization !== undefined) {
|
||||
proxyOptions.auth = proxyAuthorization;
|
||||
}
|
||||
if (trustedCertificates !== undefined) {
|
||||
proxyOptions.ca = trustedCertificates;
|
||||
}
|
||||
let HttpsProxyAgent;
|
||||
@@ -127,7 +130,11 @@ class Connection extends EventEmitter {
|
||||
const base64 = new Buffer(authorization).toString('base64');
|
||||
options.headers = {Authorization: `Basic ${base64}`};
|
||||
}
|
||||
return new WebSocket(url, options);
|
||||
const websocket = new WebSocket(url, options);
|
||||
// we will have a listener for each outstanding request,
|
||||
// so we have to raise the limit (the default is 10)
|
||||
websocket.setMaxListeners(Infinity);
|
||||
return websocket;
|
||||
}
|
||||
|
||||
connect() {
|
||||
|
||||
62
test/broadcast-api-test.js
Normal file
62
test/broadcast-api-test.js
Normal file
@@ -0,0 +1,62 @@
|
||||
/* eslint-disable max-nested-callbacks */
|
||||
'use strict';
|
||||
const _ = require('lodash');
|
||||
const assert = require('assert-diff');
|
||||
const setupAPI = require('./setup-api');
|
||||
const responses = require('./fixtures').responses;
|
||||
const ledgerClosed = require('./fixtures/rippled/ledger-close');
|
||||
const RippleAPI = require('ripple-api').RippleAPI;
|
||||
const schemaValidator = RippleAPI._PRIVATE.schemaValidator;
|
||||
|
||||
function checkResult(expected, schemaName, response) {
|
||||
if (expected.txJSON) {
|
||||
assert(response.txJSON);
|
||||
assert.deepEqual(JSON.parse(response.txJSON), JSON.parse(expected.txJSON));
|
||||
}
|
||||
assert.deepEqual(_.omit(response, 'txJSON'), _.omit(expected, 'txJSON'));
|
||||
if (schemaName) {
|
||||
schemaValidator.schemaValidate(schemaName, response);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
describe('RippleAPIBroadcast', function() {
|
||||
beforeEach(setupAPI.setupBroadcast);
|
||||
afterEach(setupAPI.teardown);
|
||||
|
||||
it('base', function() {
|
||||
const expected = {request_server_info: 1};
|
||||
this.mocks.forEach(mock => mock.expect(_.assign({}, expected)));
|
||||
assert(this.api.isConnected());
|
||||
return this.api.getServerInfo().then(
|
||||
_.partial(checkResult, responses.getServerInfo, 'getServerInfo'));
|
||||
});
|
||||
|
||||
it('ledger', function(done) {
|
||||
let gotLedger = 0;
|
||||
this.api.on('ledger', () => {
|
||||
gotLedger++;
|
||||
});
|
||||
const ledgerNext = _.assign({}, ledgerClosed);
|
||||
ledgerNext.ledger_index++;
|
||||
this.mocks.forEach(mock => mock.socket.send(JSON.stringify(ledgerNext)));
|
||||
|
||||
setTimeout(() => {
|
||||
console.log('-- ledgerVersion', this.api.ledgerVersion);
|
||||
assert.strictEqual(gotLedger, 1);
|
||||
done();
|
||||
}, 50);
|
||||
|
||||
});
|
||||
|
||||
it('error propagation', function(done) {
|
||||
this.api.once('error', (type, info) => {
|
||||
assert.strictEqual(type, 'type');
|
||||
assert.strictEqual(info, 'info');
|
||||
done();
|
||||
});
|
||||
this.mocks[1].socket.send(
|
||||
JSON.stringify({error: 'type', error_message: 'info'}));
|
||||
});
|
||||
|
||||
});
|
||||
@@ -71,6 +71,7 @@ module.exports = function(port) {
|
||||
};
|
||||
|
||||
mock.on('connection', function(conn) {
|
||||
this.socket = conn;
|
||||
conn.on('message', function(requestJSON) {
|
||||
const request = JSON.parse(requestJSON);
|
||||
mock.emit('request_' + request.command, request, conn);
|
||||
|
||||
@@ -1,52 +1,77 @@
|
||||
'use strict';
|
||||
const net = require('net');
|
||||
const RippleAPI = require('ripple-api').RippleAPI;
|
||||
const RippleAPIBroadcast = require('ripple-api').RippleAPIBroadcast;
|
||||
const ledgerClosed = require('./fixtures/rippled/ledger-close');
|
||||
const createMockRippled = require('./mock-rippled');
|
||||
|
||||
// using a free port instead of a constant port enables parallelization
|
||||
function getFreePort(callback) {
|
||||
const server = net.createServer();
|
||||
let port;
|
||||
server.on('listening', function() {
|
||||
port = server.address().port;
|
||||
server.close();
|
||||
function getFreePort() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const server = net.createServer();
|
||||
let port;
|
||||
server.on('listening', function() {
|
||||
port = server.address().port;
|
||||
server.close();
|
||||
});
|
||||
server.on('close', function() {
|
||||
resolve(port);
|
||||
});
|
||||
server.on('error', function(error) {
|
||||
reject(error);
|
||||
});
|
||||
server.listen(0);
|
||||
});
|
||||
server.on('close', function() {
|
||||
callback(null, port);
|
||||
});
|
||||
server.on('error', function(error) {
|
||||
callback(error);
|
||||
});
|
||||
server.listen(0);
|
||||
}
|
||||
|
||||
function setupMockRippledConnection(testcase, port, done) {
|
||||
testcase.mockRippled = createMockRippled(port);
|
||||
testcase.api = new RippleAPI({server: 'ws://localhost:' + port});
|
||||
testcase.api.connect().then(() => {
|
||||
testcase.api.once('ledger', () => done());
|
||||
testcase.api.connection._ws.emit('message', JSON.stringify(ledgerClosed));
|
||||
}).catch(done);
|
||||
function setupMockRippledConnection(testcase, port) {
|
||||
return new Promise((resolve, reject) => {
|
||||
testcase.mockRippled = createMockRippled(port);
|
||||
testcase.api = new RippleAPI({server: 'ws://localhost:' + port});
|
||||
testcase.api.connect().then(() => {
|
||||
testcase.api.once('ledger', () => resolve());
|
||||
testcase.api.connection._ws.emit('message', JSON.stringify(ledgerClosed));
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
function setup(done) {
|
||||
getFreePort((error, port) => {
|
||||
if (error) {
|
||||
throw new Error('Unable to obtain a free port: ' + error);
|
||||
}
|
||||
setupMockRippledConnection(this, port, done);
|
||||
function setupMockRippledConnectionForBroadcast(testcase, ports) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const servers = ports.map(port => 'ws://localhost:' + port);
|
||||
testcase.mocks = ports.map(port => createMockRippled(port));
|
||||
testcase.api = new RippleAPIBroadcast(servers);
|
||||
testcase.api.connect().then(() => {
|
||||
testcase.api.once('ledger', () => resolve());
|
||||
testcase.mocks[0].socket.send(JSON.stringify(ledgerClosed));
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
function setup() {
|
||||
return getFreePort().then(port => {
|
||||
return setupMockRippledConnection(this, port);
|
||||
});
|
||||
}
|
||||
|
||||
function setupBroadcast() {
|
||||
return Promise.all([getFreePort(), getFreePort()]).then(ports => {
|
||||
return setupMockRippledConnectionForBroadcast(this, ports);
|
||||
});
|
||||
}
|
||||
|
||||
function teardown(done) {
|
||||
this.api.disconnect().then(() => {
|
||||
this.mockRippled.close();
|
||||
if (this.mockRippled !== undefined) {
|
||||
this.mockRippled.close();
|
||||
} else {
|
||||
this.mocks.forEach(mock => mock.close());
|
||||
}
|
||||
setImmediate(done);
|
||||
}).catch(done);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
setup: setup,
|
||||
teardown: teardown
|
||||
teardown: teardown,
|
||||
setupBroadcast: setupBroadcast
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user