mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-19 11:45:49 +00:00
fix handling memos in prepareSettings
boost coverage back to 99.88% move connection tests to separate file group test fixtures into namespaces
This commit is contained in:
@@ -348,7 +348,14 @@ ripplingDisabled | boolean | *Optional* If true, payments cannot ripple through
|
|||||||
"qualityIn": 0.91,
|
"qualityIn": 0.91,
|
||||||
"qualityOut": 0.87,
|
"qualityOut": 0.87,
|
||||||
"ripplingDisabled": true,
|
"ripplingDisabled": true,
|
||||||
"frozen": false
|
"frozen": false,
|
||||||
|
"memos": [
|
||||||
|
{
|
||||||
|
"type": "test",
|
||||||
|
"format": "plain/text",
|
||||||
|
"data": "texted data"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -435,7 +442,14 @@ transferRate | number,null | *Optional* The fee to charge when users transfer t
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"domain": "ripple.com"
|
"domain": "ripple.com",
|
||||||
|
"memos": [
|
||||||
|
{
|
||||||
|
"type": "test",
|
||||||
|
"format": "plain/text",
|
||||||
|
"data": "texted data"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -2826,7 +2840,14 @@ const trustline = {
|
|||||||
"qualityIn": 0.91,
|
"qualityIn": 0.91,
|
||||||
"qualityOut": 0.87,
|
"qualityOut": 0.87,
|
||||||
"ripplingDisabled": true,
|
"ripplingDisabled": true,
|
||||||
"frozen": false
|
"frozen": false,
|
||||||
|
"memos": [
|
||||||
|
{
|
||||||
|
"type": "test",
|
||||||
|
"format": "plain/text",
|
||||||
|
"data": "texted data"
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
return api.preparePayment(address, trustline).then(prepared =>
|
return api.preparePayment(address, trustline).then(prepared =>
|
||||||
{/* ... */});
|
{/* ... */});
|
||||||
@@ -2835,7 +2856,7 @@ return api.preparePayment(address, trustline).then(prepared =>
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"txJSON": "{\"Flags\":2149711872,\"TransactionType\":\"TrustSet\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"LimitAmount\":{\"value\":\"10000\",\"currency\":\"USD\",\"issuer\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"},\"QualityIn\":910000000,\"QualityOut\":870000000,\"LastLedgerSequence\":8820051,\"Fee\":\"12\",\"Sequence\":23}",
|
"txJSON": "{\"TransactionType\":\"TrustSet\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"LimitAmount\":{\"currency\":\"USD\",\"issuer\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\",\"value\":\"10000\"},\"Flags\":2149711872,\"QualityIn\":910000000,\"QualityOut\":870000000,\"Memos\":[{\"Memo\":{\"MemoData\":\"7465787465642064617461\",\"MemoType\":\"74657374\",\"MemoFormat\":\"706C61696E2F74657874\"}}],\"LastLedgerSequence\":8820051,\"Fee\":\"12\",\"Sequence\":23}",
|
||||||
"instructions": {
|
"instructions": {
|
||||||
"fee": "0.000012",
|
"fee": "0.000012",
|
||||||
"sequence": 23,
|
"sequence": 23,
|
||||||
@@ -2997,7 +3018,14 @@ instructions | object | The instructions for how to execute the transaction afte
|
|||||||
```javascript
|
```javascript
|
||||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||||
const settings = {
|
const settings = {
|
||||||
"domain": "ripple.com"
|
"domain": "ripple.com",
|
||||||
|
"memos": [
|
||||||
|
{
|
||||||
|
"type": "test",
|
||||||
|
"format": "plain/text",
|
||||||
|
"data": "texted data"
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
return api.prepareSettings(address, settings)
|
return api.prepareSettings(address, settings)
|
||||||
.then(prepared => {/* ... */});
|
.then(prepared => {/* ... */});
|
||||||
@@ -3006,7 +3034,14 @@ return api.prepareSettings(address, settings)
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"domain": "ripple.com"
|
"domain": "ripple.com",
|
||||||
|
"memos": [
|
||||||
|
{
|
||||||
|
"type": "test",
|
||||||
|
"format": "plain/text",
|
||||||
|
"data": "texted data"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ class Connection extends EventEmitter {
|
|||||||
super();
|
super();
|
||||||
this._url = url;
|
this._url = url;
|
||||||
this._trace = options.trace;
|
this._trace = options.trace;
|
||||||
|
if (this._trace) {
|
||||||
|
// for easier unit testing
|
||||||
|
this._console = console;
|
||||||
|
}
|
||||||
this._proxyURL = options.proxy;
|
this._proxyURL = options.proxy;
|
||||||
this._proxyAuthorization = options.proxyAuthorization;
|
this._proxyAuthorization = options.proxyAuthorization;
|
||||||
this._authorization = options.authorization;
|
this._authorization = options.authorization;
|
||||||
@@ -54,7 +58,7 @@ class Connection extends EventEmitter {
|
|||||||
_onMessage(message) {
|
_onMessage(message) {
|
||||||
let parameters;
|
let parameters;
|
||||||
if (this._trace) {
|
if (this._trace) {
|
||||||
console.log(message);
|
this._console.log(message);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
parameters = this._parseMessage(message);
|
parameters = this._parseMessage(message);
|
||||||
@@ -198,7 +202,7 @@ class Connection extends EventEmitter {
|
|||||||
|
|
||||||
_send(message) {
|
_send(message) {
|
||||||
if (this._trace) {
|
if (this._trace) {
|
||||||
console.log(message);
|
this._console.log(message);
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._ws.send(message, undefined, (error, result) => {
|
this._ws.send(message, undefined, (error, result) => {
|
||||||
|
|||||||
@@ -87,15 +87,17 @@ function createSettingsTransaction(account: string, settings: Settings
|
|||||||
TransactionType: 'AccountSet',
|
TransactionType: 'AccountSet',
|
||||||
Account: account
|
Account: account
|
||||||
};
|
};
|
||||||
setTransactionFlags(txJSON, settings);
|
|
||||||
|
if (settings.memos !== undefined) {
|
||||||
|
txJSON.Memos = _.map(settings.memos, utils.convertMemo);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTransactionFlags(txJSON, _.omit(settings, 'memos'));
|
||||||
setTransactionFields(txJSON, settings);
|
setTransactionFields(txJSON, settings);
|
||||||
|
|
||||||
if (txJSON.TransferRate !== undefined) {
|
if (txJSON.TransferRate !== undefined) {
|
||||||
txJSON.TransferRate = convertTransferRate(txJSON.TransferRate);
|
txJSON.TransferRate = convertTransferRate(txJSON.TransferRate);
|
||||||
}
|
}
|
||||||
if (settings.memos !== undefined) {
|
|
||||||
txJSON.Memos = _.map(settings.memos, utils.convertMemo);
|
|
||||||
}
|
|
||||||
return txJSON;
|
return txJSON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
547
test/api-test.js
547
test/api-test.js
@@ -1,7 +1,6 @@
|
|||||||
/* eslint-disable max-nested-callbacks */
|
/* eslint-disable max-nested-callbacks */
|
||||||
'use strict';
|
'use strict';
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const net = require('net');
|
|
||||||
const assert = require('assert-diff');
|
const assert = require('assert-diff');
|
||||||
const setupAPI = require('./setup-api');
|
const setupAPI = require('./setup-api');
|
||||||
const RippleAPI = require('ripple-api').RippleAPI;
|
const RippleAPI = require('ripple-api').RippleAPI;
|
||||||
@@ -35,314 +34,90 @@ function checkResult(expected, schemaName, response) {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createServer() {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const server = net.createServer();
|
|
||||||
server.on('listening', function() {
|
|
||||||
resolve(server);
|
|
||||||
});
|
|
||||||
server.on('error', function(error) {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
server.listen(0, '0.0.0.0');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
describe('RippleAPI', function() {
|
describe('RippleAPI', function() {
|
||||||
const instructions = {maxLedgerVersionOffset: 100};
|
const instructions = {maxLedgerVersionOffset: 100};
|
||||||
beforeEach(setupAPI.setup);
|
beforeEach(setupAPI.setup);
|
||||||
afterEach(setupAPI.teardown);
|
afterEach(setupAPI.teardown);
|
||||||
|
|
||||||
describe('Connection', function() {
|
|
||||||
|
|
||||||
it('connection default options', function() {
|
|
||||||
const connection = new utils.common.Connection('url');
|
|
||||||
assert.strictEqual(connection._url, 'url');
|
|
||||||
assert(_.isUndefined(connection._proxyURL));
|
|
||||||
assert(_.isUndefined(connection._authorization));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('with proxy', function(done) {
|
|
||||||
createServer().then((server) => {
|
|
||||||
const port = server.address().port;
|
|
||||||
const expect = 'CONNECT localhost';
|
|
||||||
server.on('connection', (socket) => {
|
|
||||||
socket.on('data', (data) => {
|
|
||||||
const got = data.toString('ascii', 0, expect.length);
|
|
||||||
assert.strictEqual(got, expect);
|
|
||||||
server.close();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
proxy: 'ws://localhost:' + port,
|
|
||||||
authorization: 'authorization',
|
|
||||||
trustedCertificates: 'something'
|
|
||||||
};
|
|
||||||
const connection =
|
|
||||||
new utils.common.Connection(this.api.connection._url, options);
|
|
||||||
connection.connect().catch(done);
|
|
||||||
connection.connect().catch(done);
|
|
||||||
}, done);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Multiply disconnect calls', function() {
|
|
||||||
this.api.disconnect();
|
|
||||||
return this.api.disconnect();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('reconnect', function() {
|
|
||||||
return this.api.connection.reconnect();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('NotConnectedError', function() {
|
|
||||||
const connection = new utils.common.Connection('url');
|
|
||||||
return connection.getLedgerVersion().then(() => {
|
|
||||||
assert(false, 'Should throw NotConnectedError');
|
|
||||||
}).catch(error => {
|
|
||||||
assert(error instanceof this.api.errors.NotConnectedError);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('DisconnectedError', function() {
|
|
||||||
this.api.connection._send = function() {
|
|
||||||
this._ws.close();
|
|
||||||
};
|
|
||||||
return this.api.getServerInfo().then(() => {
|
|
||||||
assert(false, 'Should throw DisconnectedError');
|
|
||||||
}).catch(error => {
|
|
||||||
assert(error instanceof this.api.errors.DisconnectedError);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('TimeoutError', function() {
|
|
||||||
this.api.connection._send = function() {
|
|
||||||
return Promise.resolve({});
|
|
||||||
};
|
|
||||||
const request = {command: 'server_info'};
|
|
||||||
return this.api.connection.request(request, 1).then(() => {
|
|
||||||
assert(false, 'Should throw TimeoutError');
|
|
||||||
}).catch(error => {
|
|
||||||
assert(error instanceof this.api.errors.TimeoutError);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('DisconnectedError on send', function() {
|
|
||||||
this.api.connection._ws.send = function(message, options, callback) {
|
|
||||||
unused(message, options);
|
|
||||||
callback({message: 'not connected'});
|
|
||||||
};
|
|
||||||
return this.api.getServerInfo().then(() => {
|
|
||||||
assert(false, 'Should throw DisconnectedError');
|
|
||||||
}).catch(error => {
|
|
||||||
assert(error instanceof this.api.errors.DisconnectedError);
|
|
||||||
assert.strictEqual(error.message, 'not connected');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('ResponseFormatError', function() {
|
|
||||||
this.api.connection._send = function(message) {
|
|
||||||
const parsed = JSON.parse(message);
|
|
||||||
setTimeout(() => {
|
|
||||||
this._ws.emit('message', JSON.stringify({
|
|
||||||
id: parsed.id,
|
|
||||||
type: 'response',
|
|
||||||
status: 'unrecognized'
|
|
||||||
}));
|
|
||||||
}, 2);
|
|
||||||
return new Promise(() => {});
|
|
||||||
};
|
|
||||||
return this.api.getServerInfo().then(() => {
|
|
||||||
assert(false, 'Should throw ResponseFormatError');
|
|
||||||
}).catch(error => {
|
|
||||||
assert(error instanceof this.api.errors.ResponseFormatError);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('reconnect on unexpected close ', function(done) {
|
|
||||||
this.api.connection.on('connected', () => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
this.api.connection._ws.close();
|
|
||||||
}, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Multiply connect calls', function() {
|
|
||||||
return this.api.connect().then(() => {
|
|
||||||
return this.api.connect();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('hasLedgerVersion', function() {
|
|
||||||
return this.api.connection.hasLedgerVersion(8819951).then((result) => {
|
|
||||||
assert(result);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Cannot connect because no server', function() {
|
|
||||||
const connection = new utils.common.Connection();
|
|
||||||
return connection.connect().then(() => {
|
|
||||||
assert(false, 'Should throw ConnectionError');
|
|
||||||
}).catch(error => {
|
|
||||||
assert(error instanceof this.api.errors.ConnectionError);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('connect multiserver error', function() {
|
|
||||||
const options = {
|
|
||||||
servers: ['wss://server1.com', 'wss://server2.com']
|
|
||||||
};
|
|
||||||
assert.throws(function() {
|
|
||||||
const api = new RippleAPI(options);
|
|
||||||
unused(api);
|
|
||||||
}, this.api.errors.RippleError);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('connect throws error', function(done) {
|
|
||||||
this.api.once('error', (type, info) => {
|
|
||||||
assert.strictEqual(type, 'type');
|
|
||||||
assert.strictEqual(info, 'info');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
this.api.connection.emit('error', 'type', 'info');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('connection emit stream messages', function(done) {
|
|
||||||
let transactionCount = 0;
|
|
||||||
let pathFindCount = 0;
|
|
||||||
this.api.connection.on('transaction', () => {
|
|
||||||
transactionCount++;
|
|
||||||
});
|
|
||||||
this.api.connection.on('path_find', () => {
|
|
||||||
pathFindCount++;
|
|
||||||
});
|
|
||||||
this.api.connection.on('1', () => {
|
|
||||||
assert.strictEqual(transactionCount, 1);
|
|
||||||
assert.strictEqual(pathFindCount, 1);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.api.connection._onMessage(JSON.stringify({
|
|
||||||
type: 'transaction'
|
|
||||||
}));
|
|
||||||
this.api.connection._onMessage(JSON.stringify({
|
|
||||||
type: 'path_find'
|
|
||||||
}));
|
|
||||||
this.api.connection._onMessage(JSON.stringify({
|
|
||||||
type: 'response', id: 1
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('connection - invalid message id', function(done) {
|
|
||||||
this.api.on('error', (type, message) => {
|
|
||||||
assert.strictEqual(type, 'badMessage');
|
|
||||||
assert.strictEqual(message,
|
|
||||||
'{"type":"response","id":"must be integer"}');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
this.api.connection._onMessage(JSON.stringify({
|
|
||||||
type: 'response', id: 'must be integer'
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('connection - error message', function(done) {
|
|
||||||
this.api.on('error', (type, message) => {
|
|
||||||
assert.strictEqual(type, 'slowDown');
|
|
||||||
assert.strictEqual(message, 'slow down');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
this.api.connection._onMessage(JSON.stringify({
|
|
||||||
error: 'slowDown', error_message: 'slow down'
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('connection - unrecognized message type', function(done) {
|
|
||||||
this.api.on('error', (type, message) => {
|
|
||||||
assert.strictEqual(type, 'badMessage');
|
|
||||||
assert.strictEqual(message, '{"type":"unknown"}');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.api.connection._onMessage(JSON.stringify({type: 'unknown'}));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('error inspect', function() {
|
it('error inspect', function() {
|
||||||
const error = new this.api.errors.RippleError('mess', {data: 1});
|
const error = new this.api.errors.RippleError('mess', {data: 1});
|
||||||
assert.strictEqual(error.inspect(), '[RippleError(mess, { data: 1 })]');
|
assert.strictEqual(error.inspect(), '[RippleError(mess, { data: 1 })]');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('preparePayment', function() {
|
describe('preparePayment', function() {
|
||||||
const localInstructions = _.defaults({
|
|
||||||
maxFee: '0.000012'
|
|
||||||
}, instructions);
|
|
||||||
return this.api.preparePayment(
|
|
||||||
address, requests.preparePayment, localInstructions).then(
|
|
||||||
_.partial(checkResult, responses.preparePayment.normal, 'prepare'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('preparePayment - min amount xrp', function() {
|
it('normal', function() {
|
||||||
const localInstructions = _.defaults({
|
const localInstructions = _.defaults({
|
||||||
maxFee: '0.000012'
|
maxFee: '0.000012'
|
||||||
}, instructions);
|
}, instructions);
|
||||||
return this.api.preparePayment(
|
|
||||||
address, requests.preparePaymentMinAmountXRP, localInstructions).then(
|
|
||||||
_.partial(checkResult, responses.preparePayment.minAmountXRP, 'prepare'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('preparePayment - min amount xrp2xrp', function() {
|
|
||||||
return this.api.preparePayment(
|
|
||||||
address, requests.preparePaymentMinAmount, instructions).then(
|
|
||||||
_.partial(checkResult,
|
|
||||||
responses.preparePayment.minAmountXRPXRP, 'prepare'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('preparePayment - XRP to XRP no partial', function() {
|
|
||||||
assert.throws(() => {
|
|
||||||
this.api.preparePayment(address, requests.preparePaymentWrongPartial);
|
|
||||||
}, /XRP to XRP payments cannot be partial payments/);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('preparePayment - address must match payment.source.address', function() {
|
|
||||||
assert.throws(() => {
|
|
||||||
this.api.preparePayment(address, requests.preparePaymentWrongAddress);
|
|
||||||
}, /address must match payment.source.address/);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('preparePayment - wrong amount', function() {
|
|
||||||
assert.throws(() => {
|
|
||||||
this.api.preparePayment(address, requests.preparePaymentWrongAmount);
|
|
||||||
}, this.api.errors.ValidationError);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('preparePayment with all options specified', function() {
|
|
||||||
return this.api.getLedgerVersion().then((ver) => {
|
|
||||||
const localInstructions = {
|
|
||||||
maxLedgerVersion: ver + 100,
|
|
||||||
fee: '0.000012'
|
|
||||||
};
|
|
||||||
return this.api.preparePayment(
|
return this.api.preparePayment(
|
||||||
address, requests.preparePaymentAllOptions, localInstructions).then(
|
address, requests.preparePayment.normal, localInstructions).then(
|
||||||
_.partial(checkResult, responses.preparePayment.allOptions, 'prepare'));
|
_.partial(checkResult, responses.preparePayment.normal, 'prepare'));
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('preparePayment without counterparty set', function() {
|
it('preparePayment - min amount xrp', function() {
|
||||||
const localInstructions = _.defaults({sequence: 23}, instructions);
|
const localInstructions = _.defaults({
|
||||||
return this.api.preparePayment(
|
maxFee: '0.000012'
|
||||||
address, requests.preparePaymentNoCounterparty, localInstructions).then(
|
}, instructions);
|
||||||
_.partial(checkResult, responses.preparePayment.noCounterparty,
|
return this.api.preparePayment(
|
||||||
'prepare'));
|
address, requests.preparePayment.minAmountXRP, localInstructions).then(
|
||||||
});
|
_.partial(checkResult,
|
||||||
|
responses.preparePayment.minAmountXRP, 'prepare'));
|
||||||
|
});
|
||||||
|
|
||||||
it('preparePayment - destination.minAmount', function() {
|
it('preparePayment - min amount xrp2xrp', function() {
|
||||||
return this.api.preparePayment(address, responses.getPaths.sendAll[0],
|
return this.api.preparePayment(
|
||||||
instructions).then(_.partial(checkResult,
|
address, requests.preparePayment.minAmount, instructions).then(
|
||||||
responses.preparePayment.minAmount, 'prepare'));
|
_.partial(checkResult,
|
||||||
|
responses.preparePayment.minAmountXRPXRP, 'prepare'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('preparePayment - XRP to XRP no partial', function() {
|
||||||
|
assert.throws(() => {
|
||||||
|
this.api.preparePayment(address, requests.preparePayment.wrongPartial);
|
||||||
|
}, /XRP to XRP payments cannot be partial payments/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('preparePayment - address must match payment.source.address',
|
||||||
|
function() {
|
||||||
|
assert.throws(() => {
|
||||||
|
this.api.preparePayment(address, requests.preparePayment.wrongAddress);
|
||||||
|
}, /address must match payment.source.address/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('preparePayment - wrong amount', function() {
|
||||||
|
assert.throws(() => {
|
||||||
|
this.api.preparePayment(address, requests.preparePayment.wrongAmount);
|
||||||
|
}, this.api.errors.ValidationError);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('preparePayment with all options specified', function() {
|
||||||
|
return this.api.getLedgerVersion().then((ver) => {
|
||||||
|
const localInstructions = {
|
||||||
|
maxLedgerVersion: ver + 100,
|
||||||
|
fee: '0.000012'
|
||||||
|
};
|
||||||
|
return this.api.preparePayment(
|
||||||
|
address, requests.preparePayment.allOptions, localInstructions).then(
|
||||||
|
_.partial(checkResult,
|
||||||
|
responses.preparePayment.allOptions, 'prepare'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('preparePayment without counterparty set', function() {
|
||||||
|
const localInstructions = _.defaults({sequence: 23}, instructions);
|
||||||
|
return this.api.preparePayment(
|
||||||
|
address, requests.preparePayment.noCounterparty, localInstructions)
|
||||||
|
.then(_.partial(checkResult, responses.preparePayment.noCounterparty,
|
||||||
|
'prepare'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('preparePayment - destination.minAmount', function() {
|
||||||
|
return this.api.preparePayment(address, responses.getPaths.sendAll[0],
|
||||||
|
instructions).then(_.partial(checkResult,
|
||||||
|
responses.preparePayment.minAmount, 'prepare'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prepareOrder - buy order', function() {
|
it('prepareOrder - buy order', function() {
|
||||||
@@ -365,17 +140,25 @@ describe('RippleAPI', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('prepareOrderCancellation', function() {
|
it('prepareOrderCancellation', function() {
|
||||||
const request = requests.prepareOrderCancellation;
|
const request = requests.prepareOrderCancellation.simple;
|
||||||
return this.api.prepareOrderCancellation(address, request, instructions)
|
return this.api.prepareOrderCancellation(address, request, instructions)
|
||||||
.then(_.partial(checkResult, responses.prepareOrder.cancellation,
|
.then(_.partial(checkResult, responses.prepareOrderCancellation.normal,
|
||||||
'prepare'));
|
'prepare'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prepareOrderCancellation - no instructions', function() {
|
it('prepareOrderCancellation - no instructions', function() {
|
||||||
const request = requests.prepareOrderCancellation;
|
const request = requests.prepareOrderCancellation.simple;
|
||||||
return this.api.prepareOrderCancellation(address, request)
|
return this.api.prepareOrderCancellation(address, request)
|
||||||
.then(_.partial(checkResult,
|
.then(_.partial(checkResult,
|
||||||
responses.prepareOrder.cancellationNoInstructions,
|
responses.prepareOrderCancellation.noInstructions,
|
||||||
|
'prepare'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('prepareOrderCancellation - with memos', function() {
|
||||||
|
const request = requests.prepareOrderCancellation.withMemos;
|
||||||
|
return this.api.prepareOrderCancellation(address, request)
|
||||||
|
.then(_.partial(checkResult,
|
||||||
|
responses.prepareOrderCancellation.withMemos,
|
||||||
'prepare'));
|
'prepare'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -458,63 +241,71 @@ describe('RippleAPI', function() {
|
|||||||
maxFee: '0.000012'
|
maxFee: '0.000012'
|
||||||
}, instructions);
|
}, instructions);
|
||||||
return this.api.prepareSuspendedPaymentCreation(
|
return this.api.prepareSuspendedPaymentCreation(
|
||||||
address, requests.prepareSuspendedPaymentCreation,
|
address, requests.prepareSuspendedPaymentCreation.normal,
|
||||||
localInstructions).then(
|
localInstructions).then(
|
||||||
_.partial(checkResult, responses.prepareSuspendedPaymentCreation,
|
_.partial(checkResult, responses.prepareSuspendedPaymentCreation.normal,
|
||||||
'prepare'));
|
'prepare'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prepareSuspendedPaymentCreation full', function() {
|
it('prepareSuspendedPaymentCreation full', function() {
|
||||||
return this.api.prepareSuspendedPaymentCreation(
|
return this.api.prepareSuspendedPaymentCreation(
|
||||||
address, requests.prepareSuspendedPaymentCreationFull).then(
|
address, requests.prepareSuspendedPaymentCreation.full).then(
|
||||||
_.partial(checkResult, responses.prepareSuspendedPaymentCreationFull,
|
_.partial(checkResult, responses.prepareSuspendedPaymentCreation.full,
|
||||||
'prepare'));
|
'prepare'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prepareSuspendedPaymentExecution', function() {
|
it('prepareSuspendedPaymentExecution', function() {
|
||||||
return this.api.prepareSuspendedPaymentExecution(
|
return this.api.prepareSuspendedPaymentExecution(
|
||||||
address, requests.prepareSuspendedPaymentExecution, instructions).then(
|
address,
|
||||||
_.partial(checkResult, responses.prepareSuspendedPaymentExecution,
|
requests.prepareSuspendedPaymentExecution.normal, instructions).then(
|
||||||
'prepare'));
|
_.partial(checkResult,
|
||||||
|
responses.prepareSuspendedPaymentExecution.normal,
|
||||||
|
'prepare'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prepareSuspendedPaymentExecution - simple', function() {
|
it('prepareSuspendedPaymentExecution - simple', function() {
|
||||||
return this.api.prepareSuspendedPaymentExecution(
|
return this.api.prepareSuspendedPaymentExecution(
|
||||||
address, requests.prepareSuspendedPaymentExecutionSimple).then(
|
address,
|
||||||
_.partial(checkResult, responses.prepareSuspendedPaymentExecutionSimple,
|
requests.prepareSuspendedPaymentExecution.simple).then(
|
||||||
'prepare'));
|
_.partial(checkResult,
|
||||||
|
responses.prepareSuspendedPaymentExecution.simple,
|
||||||
|
'prepare'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prepareSuspendedPaymentCancellation', function() {
|
it('prepareSuspendedPaymentCancellation', function() {
|
||||||
return this.api.prepareSuspendedPaymentCancellation(
|
return this.api.prepareSuspendedPaymentCancellation(
|
||||||
address, requests.prepareSuspendedPaymentCancellation, instructions).then(
|
address,
|
||||||
_.partial(checkResult, responses.prepareSuspendedPaymentCancellation,
|
requests.prepareSuspendedPaymentCancellation.normal, instructions).then(
|
||||||
'prepare'));
|
_.partial(checkResult,
|
||||||
|
responses.prepareSuspendedPaymentCancellation.normal,
|
||||||
|
'prepare'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prepareSuspendedPaymentCancellation with memos', function() {
|
it('prepareSuspendedPaymentCancellation with memos', function() {
|
||||||
return this.api.prepareSuspendedPaymentCancellation(
|
return this.api.prepareSuspendedPaymentCancellation(
|
||||||
address, requests.prepareSuspendedPaymentCancellationMemos).then(
|
address,
|
||||||
_.partial(checkResult, responses.prepareSuspendedPaymentCancellationMemos,
|
requests.prepareSuspendedPaymentCancellation.memos).then(
|
||||||
'prepare'));
|
_.partial(checkResult,
|
||||||
|
responses.prepareSuspendedPaymentCancellation.memos,
|
||||||
|
'prepare'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sign', function() {
|
it('sign', function() {
|
||||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV';
|
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV';
|
||||||
const result = this.api.sign(requests.sign.txJSON, secret);
|
const result = this.api.sign(requests.sign.normal.txJSON, secret);
|
||||||
assert.deepEqual(result, responses.sign);
|
assert.deepEqual(result, responses.sign.normal);
|
||||||
schemaValidator.schemaValidate('sign', result);
|
schemaValidator.schemaValidate('sign', result);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sign - SuspendedPaymentExecution', function() {
|
it('sign - SuspendedPaymentExecution', function() {
|
||||||
const secret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb';
|
const secret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb';
|
||||||
const result = this.api.sign(requests.signSuspended.txJSON, secret);
|
const result = this.api.sign(requests.sign.suspended.txJSON, secret);
|
||||||
assert.deepEqual(result, responses.signSuspended);
|
assert.deepEqual(result, responses.sign.suspended);
|
||||||
schemaValidator.schemaValidate('sign', result);
|
schemaValidator.schemaValidate('sign', result);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('submit', function() {
|
it('submit', function() {
|
||||||
return this.api.submit(responses.sign.signedTransaction).then(
|
return this.api.submit(responses.sign.normal.signedTransaction).then(
|
||||||
_.partial(checkResult, responses.submit, 'submit'));
|
_.partial(checkResult, responses.submit, 'submit'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -860,7 +651,7 @@ describe('RippleAPI', function() {
|
|||||||
it('getTransactions', function() {
|
it('getTransactions', function() {
|
||||||
const options = {types: ['payment', 'order'], initiated: true, limit: 2};
|
const options = {types: ['payment', 'order'], initiated: true, limit: 2};
|
||||||
return this.api.getTransactions(address, options).then(
|
return this.api.getTransactions(address, options).then(
|
||||||
_.partial(checkResult, responses.getTransactions,
|
_.partial(checkResult, responses.getTransactions.normal,
|
||||||
'getTransactions'));
|
'getTransactions'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -868,7 +659,7 @@ describe('RippleAPI', function() {
|
|||||||
const options = {types: ['payment', 'order'], initiated: true, limit: 2,
|
const options = {types: ['payment', 'order'], initiated: true, limit: 2,
|
||||||
earliestFirst: true
|
earliestFirst: true
|
||||||
};
|
};
|
||||||
const expected = _.cloneDeep(responses.getTransactions)
|
const expected = _.cloneDeep(responses.getTransactions.normal)
|
||||||
.sort(utils.compareTransactions);
|
.sort(utils.compareTransactions);
|
||||||
return this.api.getTransactions(address, options).then(
|
return this.api.getTransactions(address, options).then(
|
||||||
_.partial(checkResult, expected, 'getTransactions'));
|
_.partial(checkResult, expected, 'getTransactions'));
|
||||||
@@ -951,7 +742,8 @@ describe('RippleAPI', function() {
|
|||||||
limit: 2
|
limit: 2
|
||||||
};
|
};
|
||||||
return this.api.getTransactions(address, options).then(
|
return this.api.getTransactions(address, options).then(
|
||||||
_.partial(checkResult, responses.getTransactions, 'getTransactions'));
|
_.partial(checkResult, responses.getTransactions.normal,
|
||||||
|
'getTransactions'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getTransactions - start transaction with zero ledger version', function(
|
it('getTransactions - start transaction with zero ledger version', function(
|
||||||
@@ -966,18 +758,19 @@ describe('RippleAPI', function() {
|
|||||||
|
|
||||||
it('getTransactions - no options', function() {
|
it('getTransactions - no options', function() {
|
||||||
return this.api.getTransactions(addresses.OTHER_ACCOUNT).then(
|
return this.api.getTransactions(addresses.OTHER_ACCOUNT).then(
|
||||||
_.partial(checkResult, responses.getTransactionsOne, 'getTransactions'));
|
_.partial(checkResult, responses.getTransactions.one, 'getTransactions'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getTrustlines', function() {
|
it('getTrustlines - filtered', function() {
|
||||||
const options = {currency: 'USD'};
|
const options = {currency: 'USD'};
|
||||||
return this.api.getTrustlines(address, options).then(
|
return this.api.getTrustlines(address, options).then(
|
||||||
_.partial(checkResult, responses.getTrustlines, 'getTrustlines'));
|
_.partial(checkResult,
|
||||||
|
responses.getTrustlines.filtered, 'getTrustlines'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getTrustlines - ono options', function() {
|
it('getTrustlines - no options', function() {
|
||||||
return this.api.getTrustlines(address).then(
|
return this.api.getTrustlines(address).then(
|
||||||
_.partial(checkResult, responses.getTrustlinesAll, 'getTrustlines'));
|
_.partial(checkResult, responses.getTrustlines.all, 'getTrustlines'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('generateAddress', function() {
|
it('generateAddress', function() {
|
||||||
@@ -1045,59 +838,66 @@ describe('RippleAPI', function() {
|
|||||||
}, this.api.errors.ValidationError);
|
}, this.api.errors.ValidationError);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getOrderbook', function() {
|
describe('getOrderbook', function() {
|
||||||
return this.api.getOrderbook(address, requests.getOrderbook, undefined)
|
|
||||||
.then(
|
|
||||||
_.partial(checkResult, responses.getOrderbook, 'getOrderbook'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getOrderbook - invalid options', function() {
|
it('normal', function() {
|
||||||
assert.throws(() => {
|
return this.api.getOrderbook(address,
|
||||||
this.api.getOrderbook(address, requests.getOrderbook,
|
requests.getOrderbook.normal, undefined).then(
|
||||||
{invalid: 'options'});
|
_.partial(checkResult,
|
||||||
}, this.api.errors.ValidationError);
|
responses.getOrderbook.normal, 'getOrderbook'));
|
||||||
});
|
|
||||||
|
|
||||||
it('getOrderbook with XRP', function() {
|
|
||||||
return this.api.getOrderbook(address, requests.getOrderbookWithXRP).then(
|
|
||||||
_.partial(checkResult, responses.getOrderbookWithXRP, 'getOrderbook'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getOrderbook - sorted so that best deals come first', function() {
|
|
||||||
return this.api.getOrderbook(address, requests.getOrderbook)
|
|
||||||
.then(data => {
|
|
||||||
const bidRates = data.bids.map(bid => bid.properties.makerExchangeRate);
|
|
||||||
const askRates = data.asks.map(ask => ask.properties.makerExchangeRate);
|
|
||||||
// makerExchangeRate = quality = takerPays.value/takerGets.value
|
|
||||||
// so the best deal for the taker is the lowest makerExchangeRate
|
|
||||||
// bids and asks should be sorted so that the best deals come first
|
|
||||||
assert.deepEqual(_.sortBy(bidRates, x => Number(x)), bidRates);
|
|
||||||
assert.deepEqual(_.sortBy(askRates, x => Number(x)), askRates);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('getOrderbook - currency & counterparty are correct', function() {
|
it('invalid options', function() {
|
||||||
return this.api.getOrderbook(address, requests.getOrderbook)
|
assert.throws(() => {
|
||||||
.then(data => {
|
this.api.getOrderbook(address, requests.getOrderbook.normal,
|
||||||
const orders = _.flatten([data.bids, data.asks]);
|
{invalid: 'options'});
|
||||||
_.forEach(orders, order => {
|
}, this.api.errors.ValidationError);
|
||||||
const quantity = order.specification.quantity;
|
});
|
||||||
const totalPrice = order.specification.totalPrice;
|
|
||||||
const {base, counter} = requests.getOrderbook;
|
it('with XRP', function() {
|
||||||
assert.strictEqual(quantity.currency, base.currency);
|
return this.api.getOrderbook(address, requests.getOrderbook.withXRP).then(
|
||||||
assert.strictEqual(quantity.counterparty, base.counterparty);
|
_.partial(checkResult, responses.getOrderbook.withXRP, 'getOrderbook'));
|
||||||
assert.strictEqual(totalPrice.currency, counter.currency);
|
});
|
||||||
assert.strictEqual(totalPrice.counterparty, counter.counterparty);
|
|
||||||
|
it('sorted so that best deals come first', function() {
|
||||||
|
return this.api.getOrderbook(address, requests.getOrderbook.normal)
|
||||||
|
.then(data => {
|
||||||
|
const bidRates = data.bids.map(bid => bid.properties.makerExchangeRate);
|
||||||
|
const askRates = data.asks.map(ask => ask.properties.makerExchangeRate);
|
||||||
|
// makerExchangeRate = quality = takerPays.value/takerGets.value
|
||||||
|
// so the best deal for the taker is the lowest makerExchangeRate
|
||||||
|
// bids and asks should be sorted so that the best deals come first
|
||||||
|
assert.deepEqual(_.sortBy(bidRates, x => Number(x)), bidRates);
|
||||||
|
assert.deepEqual(_.sortBy(askRates, x => Number(x)), askRates);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('getOrderbook - direction is correct for bids and asks', function() {
|
it('currency & counterparty are correct', function() {
|
||||||
return this.api.getOrderbook(address, requests.getOrderbook)
|
return this.api.getOrderbook(address, requests.getOrderbook.normal)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
assert(_.every(data.bids, bid => bid.specification.direction === 'buy'));
|
const orders = _.flatten([data.bids, data.asks]);
|
||||||
assert(_.every(data.asks, ask => ask.specification.direction === 'sell'));
|
_.forEach(orders, order => {
|
||||||
|
const quantity = order.specification.quantity;
|
||||||
|
const totalPrice = order.specification.totalPrice;
|
||||||
|
const {base, counter} = requests.getOrderbook.normal;
|
||||||
|
assert.strictEqual(quantity.currency, base.currency);
|
||||||
|
assert.strictEqual(quantity.counterparty, base.counterparty);
|
||||||
|
assert.strictEqual(totalPrice.currency, counter.currency);
|
||||||
|
assert.strictEqual(totalPrice.counterparty, counter.counterparty);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('direction is correct for bids and asks', function() {
|
||||||
|
return this.api.getOrderbook(address, requests.getOrderbook.normal)
|
||||||
|
.then(data => {
|
||||||
|
assert(
|
||||||
|
_.every(data.bids, bid => bid.specification.direction === 'buy'));
|
||||||
|
assert(
|
||||||
|
_.every(data.asks, ask => ask.specification.direction === 'sell'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getServerInfo', function() {
|
it('getServerInfo', function() {
|
||||||
@@ -1455,7 +1255,8 @@ describe('RippleAPI - offline', function() {
|
|||||||
};
|
};
|
||||||
return api.prepareSettings(address, settings, instructions).then(data => {
|
return api.prepareSettings(address, settings, instructions).then(data => {
|
||||||
checkResult(responses.prepareSettings.flags, 'prepare', data);
|
checkResult(responses.prepareSettings.flags, 'prepare', data);
|
||||||
assert.deepEqual(api.sign(data.txJSON, secret), responses.sign);
|
assert.deepEqual(api.sign(data.txJSON, secret),
|
||||||
|
responses.prepareSettings.signed);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
261
test/connection-test.js
Normal file
261
test/connection-test.js
Normal file
@@ -0,0 +1,261 @@
|
|||||||
|
/* eslint-disable max-nested-callbacks */
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const _ = require('lodash');
|
||||||
|
const net = require('net');
|
||||||
|
const assert = require('assert-diff');
|
||||||
|
const setupAPI = require('./setup-api');
|
||||||
|
const RippleAPI = require('ripple-api').RippleAPI;
|
||||||
|
const utils = RippleAPI._PRIVATE.ledgerUtils;
|
||||||
|
|
||||||
|
|
||||||
|
function unused() {
|
||||||
|
}
|
||||||
|
|
||||||
|
function createServer() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const server = net.createServer();
|
||||||
|
server.on('listening', function() {
|
||||||
|
resolve(server);
|
||||||
|
});
|
||||||
|
server.on('error', function(error) {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
server.listen(0, '0.0.0.0');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Connection', function() {
|
||||||
|
beforeEach(setupAPI.setup);
|
||||||
|
afterEach(setupAPI.teardown);
|
||||||
|
|
||||||
|
it('default options', function() {
|
||||||
|
const connection = new utils.common.Connection('url');
|
||||||
|
assert.strictEqual(connection._url, 'url');
|
||||||
|
assert(_.isUndefined(connection._proxyURL));
|
||||||
|
assert(_.isUndefined(connection._authorization));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('trace', function() {
|
||||||
|
const connection = new utils.common.Connection('url', {trace: true});
|
||||||
|
const message1 = '{"type": "transaction"}';
|
||||||
|
const message2 = '{"type": "path_find"}';
|
||||||
|
const messages = [];
|
||||||
|
connection._console = {
|
||||||
|
log: function(message) {
|
||||||
|
messages.push(message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
connection._onMessage(message1);
|
||||||
|
connection._send(message2);
|
||||||
|
|
||||||
|
assert.deepEqual(messages, [message1, message2]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with proxy', function(done) {
|
||||||
|
createServer().then((server) => {
|
||||||
|
const port = server.address().port;
|
||||||
|
const expect = 'CONNECT localhost';
|
||||||
|
server.on('connection', (socket) => {
|
||||||
|
socket.on('data', (data) => {
|
||||||
|
const got = data.toString('ascii', 0, expect.length);
|
||||||
|
assert.strictEqual(got, expect);
|
||||||
|
server.close();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
proxy: 'ws://localhost:' + port,
|
||||||
|
authorization: 'authorization',
|
||||||
|
trustedCertificates: ['path/to/pem']
|
||||||
|
};
|
||||||
|
const connection =
|
||||||
|
new utils.common.Connection(this.api.connection._url, options);
|
||||||
|
connection.connect().catch(done);
|
||||||
|
connection.connect().catch(done);
|
||||||
|
}, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Multiply disconnect calls', function() {
|
||||||
|
this.api.disconnect();
|
||||||
|
return this.api.disconnect();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reconnect', function() {
|
||||||
|
return this.api.connection.reconnect();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('NotConnectedError', function() {
|
||||||
|
const connection = new utils.common.Connection('url');
|
||||||
|
return connection.getLedgerVersion().then(() => {
|
||||||
|
assert(false, 'Should throw NotConnectedError');
|
||||||
|
}).catch(error => {
|
||||||
|
assert(error instanceof this.api.errors.NotConnectedError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('DisconnectedError', function() {
|
||||||
|
this.api.connection._send = function() {
|
||||||
|
this._ws.close();
|
||||||
|
};
|
||||||
|
return this.api.getServerInfo().then(() => {
|
||||||
|
assert(false, 'Should throw DisconnectedError');
|
||||||
|
}).catch(error => {
|
||||||
|
assert(error instanceof this.api.errors.DisconnectedError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('TimeoutError', function() {
|
||||||
|
this.api.connection._send = function() {
|
||||||
|
return Promise.resolve({});
|
||||||
|
};
|
||||||
|
const request = {command: 'server_info'};
|
||||||
|
return this.api.connection.request(request, 1).then(() => {
|
||||||
|
assert(false, 'Should throw TimeoutError');
|
||||||
|
}).catch(error => {
|
||||||
|
assert(error instanceof this.api.errors.TimeoutError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('DisconnectedError on send', function() {
|
||||||
|
this.api.connection._ws.send = function(message, options, callback) {
|
||||||
|
unused(message, options);
|
||||||
|
callback({message: 'not connected'});
|
||||||
|
};
|
||||||
|
return this.api.getServerInfo().then(() => {
|
||||||
|
assert(false, 'Should throw DisconnectedError');
|
||||||
|
}).catch(error => {
|
||||||
|
assert(error instanceof this.api.errors.DisconnectedError);
|
||||||
|
assert.strictEqual(error.message, 'not connected');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ResponseFormatError', function() {
|
||||||
|
this.api.connection._send = function(message) {
|
||||||
|
const parsed = JSON.parse(message);
|
||||||
|
setTimeout(() => {
|
||||||
|
this._ws.emit('message', JSON.stringify({
|
||||||
|
id: parsed.id,
|
||||||
|
type: 'response',
|
||||||
|
status: 'unrecognized'
|
||||||
|
}));
|
||||||
|
}, 2);
|
||||||
|
return new Promise(() => {});
|
||||||
|
};
|
||||||
|
return this.api.getServerInfo().then(() => {
|
||||||
|
assert(false, 'Should throw ResponseFormatError');
|
||||||
|
}).catch(error => {
|
||||||
|
assert(error instanceof this.api.errors.ResponseFormatError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reconnect on unexpected close ', function(done) {
|
||||||
|
this.api.connection.on('connected', () => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
this.api.connection._ws.close();
|
||||||
|
}, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Multiply connect calls', function() {
|
||||||
|
return this.api.connect().then(() => {
|
||||||
|
return this.api.connect();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('hasLedgerVersion', function() {
|
||||||
|
return this.api.connection.hasLedgerVersion(8819951).then((result) => {
|
||||||
|
assert(result);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Cannot connect because no server', function() {
|
||||||
|
const connection = new utils.common.Connection();
|
||||||
|
return connection.connect().then(() => {
|
||||||
|
assert(false, 'Should throw ConnectionError');
|
||||||
|
}).catch(error => {
|
||||||
|
assert(error instanceof this.api.errors.ConnectionError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('connect multiserver error', function() {
|
||||||
|
const options = {
|
||||||
|
servers: ['wss://server1.com', 'wss://server2.com']
|
||||||
|
};
|
||||||
|
assert.throws(function() {
|
||||||
|
const api = new RippleAPI(options);
|
||||||
|
unused(api);
|
||||||
|
}, this.api.errors.RippleError);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('connect throws error', function(done) {
|
||||||
|
this.api.once('error', (type, info) => {
|
||||||
|
assert.strictEqual(type, 'type');
|
||||||
|
assert.strictEqual(info, 'info');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
this.api.connection.emit('error', 'type', 'info');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('emit stream messages', function(done) {
|
||||||
|
let transactionCount = 0;
|
||||||
|
let pathFindCount = 0;
|
||||||
|
this.api.connection.on('transaction', () => {
|
||||||
|
transactionCount++;
|
||||||
|
});
|
||||||
|
this.api.connection.on('path_find', () => {
|
||||||
|
pathFindCount++;
|
||||||
|
});
|
||||||
|
this.api.connection.on('1', () => {
|
||||||
|
assert.strictEqual(transactionCount, 1);
|
||||||
|
assert.strictEqual(pathFindCount, 1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.api.connection._onMessage(JSON.stringify({
|
||||||
|
type: 'transaction'
|
||||||
|
}));
|
||||||
|
this.api.connection._onMessage(JSON.stringify({
|
||||||
|
type: 'path_find'
|
||||||
|
}));
|
||||||
|
this.api.connection._onMessage(JSON.stringify({
|
||||||
|
type: 'response', id: 1
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('invalid message id', function(done) {
|
||||||
|
this.api.on('error', (type, message) => {
|
||||||
|
assert.strictEqual(type, 'badMessage');
|
||||||
|
assert.strictEqual(message,
|
||||||
|
'{"type":"response","id":"must be integer"}');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
this.api.connection._onMessage(JSON.stringify({
|
||||||
|
type: 'response', id: 'must be integer'
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('propagate error message', function(done) {
|
||||||
|
this.api.on('error', (type, message) => {
|
||||||
|
assert.strictEqual(type, 'slowDown');
|
||||||
|
assert.strictEqual(message, 'slow down');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
this.api.connection._onMessage(JSON.stringify({
|
||||||
|
error: 'slowDown', error_message: 'slow down'
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('unrecognized message type', function(done) {
|
||||||
|
this.api.on('error', (type, message) => {
|
||||||
|
assert.strictEqual(type, 'badMessage');
|
||||||
|
assert.strictEqual(message, '{"type":"unknown"}');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.api.connection._onMessage(JSON.stringify({type: 'unknown'}));
|
||||||
|
});
|
||||||
|
});
|
||||||
59
test/fixtures/requests/index.js
vendored
59
test/fixtures/requests/index.js
vendored
@@ -6,35 +6,42 @@ module.exports = {
|
|||||||
sell: require('./prepare-order-sell'),
|
sell: require('./prepare-order-sell'),
|
||||||
expiration: require('./prepare-order-expiration')
|
expiration: require('./prepare-order-expiration')
|
||||||
},
|
},
|
||||||
prepareOrderCancellation: require('./prepare-order-cancellation'),
|
prepareOrderCancellation: {
|
||||||
preparePayment: require('./prepare-payment'),
|
simple: require('./prepare-order-cancellation'),
|
||||||
preparePaymentMinAmountXRP: require('./prepare-payment-min-xrp'),
|
withMemos: require('./prepare-order-cancellation-memos')
|
||||||
preparePaymentMinAmount: require('./prepare-payment-min'),
|
},
|
||||||
preparePaymentWrongAddress: require('./prepare-payment-wrong-address'),
|
preparePayment: {
|
||||||
preparePaymentWrongAmount: require('./prepare-payment-wrong-amount'),
|
normal: require('./prepare-payment'),
|
||||||
preparePaymentWrongPartial: require('./prepare-payment-wrong-partial'),
|
minAmountXRP: require('./prepare-payment-min-xrp'),
|
||||||
preparePaymentAllOptions: require('./prepare-payment-all-options'),
|
minAmount: require('./prepare-payment-min'),
|
||||||
preparePaymentNoCounterparty: require('./prepare-payment-no-counterparty'),
|
wrongAddress: require('./prepare-payment-wrong-address'),
|
||||||
|
wrongAmount: require('./prepare-payment-wrong-amount'),
|
||||||
|
wrongPartial: require('./prepare-payment-wrong-partial'),
|
||||||
|
allOptions: require('./prepare-payment-all-options'),
|
||||||
|
noCounterparty: require('./prepare-payment-no-counterparty')
|
||||||
|
},
|
||||||
prepareSettings: require('./prepare-settings'),
|
prepareSettings: require('./prepare-settings'),
|
||||||
prepareSuspendedPaymentCreation:
|
prepareSuspendedPaymentCreation: {
|
||||||
require('./prepare-suspended-payment-creation'),
|
normal: require('./prepare-suspended-payment-creation'),
|
||||||
prepareSuspendedPaymentCreationFull:
|
full: require('./prepare-suspended-payment-creation-full')
|
||||||
require('./prepare-suspended-payment-creation-full'),
|
},
|
||||||
prepareSuspendedPaymentExecution:
|
prepareSuspendedPaymentExecution: {
|
||||||
require('./prepare-suspended-payment-execution'),
|
normal: require('./prepare-suspended-payment-execution'),
|
||||||
prepareSuspendedPaymentExecutionSimple:
|
simple: require('./prepare-suspended-payment-execution-simple')
|
||||||
require('./prepare-suspended-payment-execution-simple'),
|
},
|
||||||
prepareSuspendedPaymentCancellation:
|
prepareSuspendedPaymentCancellation: {
|
||||||
require('./prepare-suspended-payment-cancellation'),
|
normal: require('./prepare-suspended-payment-cancellation'),
|
||||||
prepareSuspendedPaymentCancellationMemos:
|
memos: require('./prepare-suspended-payment-cancellation-memos')
|
||||||
require('./prepare-suspended-payment-cancellation-memos'),
|
},
|
||||||
prepareTrustline: {
|
prepareTrustline: {
|
||||||
simple: require('./prepare-trustline-simple'),
|
simple: require('./prepare-trustline-simple'),
|
||||||
complex: require('./prepare-trustline'),
|
complex: require('./prepare-trustline'),
|
||||||
frozen: require('./prepare-trustline-frozen.json')
|
frozen: require('./prepare-trustline-frozen.json')
|
||||||
},
|
},
|
||||||
sign: require('./sign'),
|
sign: {
|
||||||
signSuspended: require('./sign-suspended.json'),
|
normal: require('./sign'),
|
||||||
|
suspended: require('./sign-suspended.json')
|
||||||
|
},
|
||||||
getPaths: {
|
getPaths: {
|
||||||
normal: require('./getpaths/normal'),
|
normal: require('./getpaths/normal'),
|
||||||
UsdToUsd: require('./getpaths/usd2usd'),
|
UsdToUsd: require('./getpaths/usd2usd'),
|
||||||
@@ -47,8 +54,10 @@ module.exports = {
|
|||||||
invalid: require('./getpaths/invalid'),
|
invalid: require('./getpaths/invalid'),
|
||||||
issuer: require('./getpaths/issuer')
|
issuer: require('./getpaths/issuer')
|
||||||
},
|
},
|
||||||
getOrderbook: require('./get-orderbook'),
|
getOrderbook: {
|
||||||
getOrderbookWithXRP: require('./get-orderbook-with-xrp'),
|
normal: require('./get-orderbook'),
|
||||||
|
withXRP: require('./get-orderbook-with-xrp')
|
||||||
|
},
|
||||||
computeLedgerHash: {
|
computeLedgerHash: {
|
||||||
header: require('./compute-ledger-hash'),
|
header: require('./compute-ledger-hash'),
|
||||||
transactions: require('./compute-ledger-hash-transactions')
|
transactions: require('./compute-ledger-hash-transactions')
|
||||||
|
|||||||
10
test/fixtures/requests/prepare-order-cancellation-memos.json
vendored
Normal file
10
test/fixtures/requests/prepare-order-cancellation-memos.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"orderSequence": 23,
|
||||||
|
"memos": [
|
||||||
|
{
|
||||||
|
"type": "test",
|
||||||
|
"format": "plain/text",
|
||||||
|
"data": "texted data"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -9,5 +9,12 @@
|
|||||||
"currency": "XRP",
|
"currency": "XRP",
|
||||||
"value": "2"
|
"value": "2"
|
||||||
},
|
},
|
||||||
"immediateOrCancel": true
|
"immediateOrCancel": true,
|
||||||
|
"memos": [
|
||||||
|
{
|
||||||
|
"type": "test",
|
||||||
|
"format": "plain/text",
|
||||||
|
"data": "texted data"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
9
test/fixtures/requests/prepare-settings.json
vendored
9
test/fixtures/requests/prepare-settings.json
vendored
@@ -1,3 +1,10 @@
|
|||||||
{
|
{
|
||||||
"domain": "ripple.com"
|
"domain": "ripple.com",
|
||||||
|
"memos": [
|
||||||
|
{
|
||||||
|
"type": "test",
|
||||||
|
"format": "plain/text",
|
||||||
|
"data": "texted data"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,12 @@
|
|||||||
"qualityIn": 0.91,
|
"qualityIn": 0.91,
|
||||||
"qualityOut": 0.87,
|
"qualityOut": 0.87,
|
||||||
"ripplingDisabled": true,
|
"ripplingDisabled": true,
|
||||||
"frozen": false
|
"frozen": false,
|
||||||
|
"memos": [
|
||||||
|
{
|
||||||
|
"type": "test",
|
||||||
|
"format": "plain/text",
|
||||||
|
"data": "texted data"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
61
test/fixtures/responses/index.js
vendored
61
test/fixtures/responses/index.js
vendored
@@ -5,8 +5,10 @@ module.exports = {
|
|||||||
getAccountInfo: require('./get-account-info.json'),
|
getAccountInfo: require('./get-account-info.json'),
|
||||||
getBalances: require('./get-balances.json'),
|
getBalances: require('./get-balances.json'),
|
||||||
getBalanceSheet: require('./get-balance-sheet.json'),
|
getBalanceSheet: require('./get-balance-sheet.json'),
|
||||||
getOrderbook: require('./get-orderbook.json'),
|
getOrderbook: {
|
||||||
getOrderbookWithXRP: require('./get-orderbook-with-xrp.json'),
|
normal: require('./get-orderbook.json'),
|
||||||
|
withXRP: require('./get-orderbook-with-xrp.json')
|
||||||
|
},
|
||||||
getOrders: require('./get-orders.json'),
|
getOrders: require('./get-orders.json'),
|
||||||
getPaths: {
|
getPaths: {
|
||||||
XrpToUsd: require('./get-paths.json'),
|
XrpToUsd: require('./get-paths.json'),
|
||||||
@@ -43,10 +45,14 @@ module.exports = {
|
|||||||
suspendedPaymentExecutionSimple:
|
suspendedPaymentExecutionSimple:
|
||||||
require('./get-transaction-suspended-payment-execution-simple.json')
|
require('./get-transaction-suspended-payment-execution-simple.json')
|
||||||
},
|
},
|
||||||
getTransactions: require('./get-transactions.json'),
|
getTransactions: {
|
||||||
getTransactionsOne: require('./get-transactions-one.json'),
|
normal: require('./get-transactions.json'),
|
||||||
getTrustlines: require('./get-trustlines.json'),
|
one: require('./get-transactions-one.json')
|
||||||
getTrustlinesAll: require('./get-trustlines-all.json'),
|
},
|
||||||
|
getTrustlines: {
|
||||||
|
filtered: require('./get-trustlines.json'),
|
||||||
|
all: require('./get-trustlines-all.json')
|
||||||
|
},
|
||||||
getLedger: {
|
getLedger: {
|
||||||
header: require('./get-ledger'),
|
header: require('./get-ledger'),
|
||||||
full: require('./get-ledger-full'),
|
full: require('./get-ledger-full'),
|
||||||
@@ -56,10 +62,12 @@ module.exports = {
|
|||||||
prepareOrder: {
|
prepareOrder: {
|
||||||
buy: require('./prepare-order.json'),
|
buy: require('./prepare-order.json'),
|
||||||
sell: require('./prepare-order-sell.json'),
|
sell: require('./prepare-order-sell.json'),
|
||||||
expiration: require('./prepare-order-expiration'),
|
expiration: require('./prepare-order-expiration')
|
||||||
cancellation: require('./prepare-order-cancellation.json'),
|
},
|
||||||
cancellationNoInstructions:
|
prepareOrderCancellation: {
|
||||||
require('./prepare-order-cancellation-no-instructions.json')
|
normal: require('./prepare-order-cancellation.json'),
|
||||||
|
withMemos: require('./prepare-order-cancellation-memos.json'),
|
||||||
|
noInstructions: require('./prepare-order-cancellation-no-instructions.json')
|
||||||
},
|
},
|
||||||
preparePayment: {
|
preparePayment: {
|
||||||
normal: require('./prepare-payment.json'),
|
normal: require('./prepare-payment.json'),
|
||||||
@@ -77,27 +85,30 @@ module.exports = {
|
|||||||
flagClear: require('./prepare-settings-flag-clear.json'),
|
flagClear: require('./prepare-settings-flag-clear.json'),
|
||||||
setTransferRate: require('./prepare-settings-set-transfer-rate.json'),
|
setTransferRate: require('./prepare-settings-set-transfer-rate.json'),
|
||||||
fieldClear: require('./prepare-settings-field-clear.json'),
|
fieldClear: require('./prepare-settings-field-clear.json'),
|
||||||
noInstructions: require('./prepare-settings-no-instructions.json')
|
noInstructions: require('./prepare-settings-no-instructions.json'),
|
||||||
|
signed: require('./prepare-settings-signed.json')
|
||||||
|
},
|
||||||
|
prepareSuspendedPaymentCreation: {
|
||||||
|
normal: require('./prepare-suspended-payment-creation'),
|
||||||
|
full: require('./prepare-suspended-payment-creation-full')
|
||||||
|
},
|
||||||
|
prepareSuspendedPaymentExecution: {
|
||||||
|
normal: require('./prepare-suspended-payment-execution'),
|
||||||
|
simple: require('./prepare-suspended-payment-execution-simple')
|
||||||
|
},
|
||||||
|
prepareSuspendedPaymentCancellation: {
|
||||||
|
normal: require('./prepare-suspended-payment-cancellation'),
|
||||||
|
memos: require('./prepare-suspended-payment-cancellation-memos')
|
||||||
},
|
},
|
||||||
prepareSuspendedPaymentCreation:
|
|
||||||
require('./prepare-suspended-payment-creation'),
|
|
||||||
prepareSuspendedPaymentCreationFull:
|
|
||||||
require('./prepare-suspended-payment-creation-full'),
|
|
||||||
prepareSuspendedPaymentExecution:
|
|
||||||
require('./prepare-suspended-payment-execution'),
|
|
||||||
prepareSuspendedPaymentExecutionSimple:
|
|
||||||
require('./prepare-suspended-payment-execution-simple'),
|
|
||||||
prepareSuspendedPaymentCancellation:
|
|
||||||
require('./prepare-suspended-payment-cancellation'),
|
|
||||||
prepareSuspendedPaymentCancellationMemos:
|
|
||||||
require('./prepare-suspended-payment-cancellation-memos'),
|
|
||||||
prepareTrustline: {
|
prepareTrustline: {
|
||||||
simple: require('./prepare-trustline-simple.json'),
|
simple: require('./prepare-trustline-simple.json'),
|
||||||
frozen: require('./prepare-trustline-frozen.json'),
|
frozen: require('./prepare-trustline-frozen.json'),
|
||||||
complex: require('./prepare-trustline.json')
|
complex: require('./prepare-trustline.json')
|
||||||
},
|
},
|
||||||
sign: require('./sign.json'),
|
sign: {
|
||||||
signSuspended: require('./sign-suspended.json'),
|
normal: require('./sign.json'),
|
||||||
|
suspended: require('./sign-suspended.json')
|
||||||
|
},
|
||||||
submit: require('./submit.json'),
|
submit: require('./submit.json'),
|
||||||
ledgerEvent: require('./ledger-event.json')
|
ledgerEvent: require('./ledger-event.json')
|
||||||
};
|
};
|
||||||
|
|||||||
8
test/fixtures/responses/prepare-order-cancellation-memos.json
vendored
Normal file
8
test/fixtures/responses/prepare-order-cancellation-memos.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"txJSON": "{\"TransactionType\":\"OfferCancel\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"OfferSequence\":23,\"Memos\":[{\"Memo\":{\"MemoData\":\"7465787465642064617461\",\"MemoType\":\"74657374\",\"MemoFormat\":\"706C61696E2F74657874\"}}],\"Flags\":2147483648,\"LastLedgerSequence\":8819954,\"Fee\":\"12\",\"Sequence\":23}",
|
||||||
|
"instructions": {
|
||||||
|
"fee": "0.000012",
|
||||||
|
"sequence": 23,
|
||||||
|
"maxLedgerVersion": 8819954
|
||||||
|
}
|
||||||
|
}
|
||||||
16
test/fixtures/responses/prepare-order-sell.json
vendored
16
test/fixtures/responses/prepare-order-sell.json
vendored
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"txJSON": "{\"Flags\":2148139008,\"TransactionType\":\"OfferCreate\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"TakerGets\":{\"value\":\"10.1\",\"currency\":\"USD\",\"issuer\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"},\"TakerPays\":\"2000000\",\"LastLedgerSequence\":8820051,\"Fee\":\"12\",\"Sequence\":23}",
|
"txJSON": "{\"TransactionType\":\"OfferCreate\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"TakerGets\":{\"currency\":\"USD\",\"issuer\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\",\"value\":\"10.1\"},\"TakerPays\":\"2000000\",\"Flags\":2148139008,\"Memos\":[{\"Memo\":{\"MemoData\":\"7465787465642064617461\",\"MemoType\":\"74657374\",\"MemoFormat\":\"706C61696E2F74657874\"}}],\"LastLedgerSequence\":8820051,\"Fee\":\"12\",\"Sequence\":23}",
|
||||||
"instructions": {
|
"instructions": {
|
||||||
"fee": "0.000012",
|
"fee": "0.000012",
|
||||||
"sequence": 23,
|
"sequence": 23,
|
||||||
"maxLedgerVersion": 8820051
|
"maxLedgerVersion": 8820051
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,8 @@
|
|||||||
{"txJSON":"{\"TransactionType\":\"AccountSet\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"Domain\":\"726970706C652E636F6D\",\"Flags\":2147483648,\"LastLedgerSequence\":8819954,\"Fee\":\"12\",\"Sequence\":23}","instructions":{"fee":"0.000012","sequence":23,"maxLedgerVersion":8819954}}
|
{
|
||||||
|
"txJSON": "{\"TransactionType\":\"AccountSet\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"Memos\":[{\"Memo\":{\"MemoData\":\"7465787465642064617461\",\"MemoType\":\"74657374\",\"MemoFormat\":\"706C61696E2F74657874\"}}],\"Domain\":\"726970706C652E636F6D\",\"Flags\":2147483648,\"LastLedgerSequence\":8819954,\"Fee\":\"12\",\"Sequence\":23}",
|
||||||
|
"instructions": {
|
||||||
|
"fee": "0.000012",
|
||||||
|
"sequence": 23,
|
||||||
|
"maxLedgerVersion": 8819954
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"signedTransaction": "12000322000000002400000017201B0086955368400000000000000C732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D87446304402207660BDEF67105CE1EBA9AD35DC7156BAB43FF1D47633199EE257D70B6B9AAFBF022045A812486A675750B5A3F37131E9F92299728D37FF6BB7195CA5EE881268CB4C770A726970706C652E636F6D81145E7B112523F68D2F5E879DB4EAC51C6698A69304",
|
"signedTransaction": "12000322800000002400000017201B0086955368400000000000000C732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D87446304402202FBF6A6F74DFDA17C7341D532B66141206BC71A147C08DBDA6A950AA9A1741DC022055859A39F2486A46487F8DA261E3D80B4FDD26178A716A929F26377D1BEC7E43770A726970706C652E636F6D81145E7B112523F68D2F5E879DB4EAC51C6698A69304F9EA7C04746573747D0B74657874656420646174617E0A706C61696E2F74657874E1F1",
|
||||||
"id": "29D23159EBA79170DCA5EF467CBC15114DBD35B7A8C3DBF76809BA354D00D250"
|
"id": "4755D26FAC39E3E477870D4E03CC6783DDDF967FFBE240606755D3D03702FC16"
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"txJSON": "{\"Flags\":2147483648,\"TransactionType\":\"AccountSet\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"Domain\":\"726970706C652E636F6D\",\"LastLedgerSequence\":8820051,\"Fee\":\"12\",\"Sequence\":23}",
|
"txJSON": "{\"TransactionType\":\"AccountSet\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"Memos\":[{\"Memo\":{\"MemoData\":\"7465787465642064617461\",\"MemoType\":\"74657374\",\"MemoFormat\":\"706C61696E2F74657874\"}}],\"Domain\":\"726970706C652E636F6D\",\"Flags\":2147483648,\"LastLedgerSequence\":8820051,\"Fee\":\"12\",\"Sequence\":23}",
|
||||||
"instructions": {
|
"instructions": {
|
||||||
"fee": "0.000012",
|
"fee": "0.000012",
|
||||||
"sequence": 23,
|
"sequence": 23,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"txJSON": "{\"Flags\":2149711872,\"TransactionType\":\"TrustSet\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"LimitAmount\":{\"value\":\"10000\",\"currency\":\"USD\",\"issuer\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"},\"QualityIn\":910000000,\"QualityOut\":870000000,\"LastLedgerSequence\":8820051,\"Fee\":\"12\",\"Sequence\":23}",
|
"txJSON": "{\"TransactionType\":\"TrustSet\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"LimitAmount\":{\"currency\":\"USD\",\"issuer\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\",\"value\":\"10000\"},\"Flags\":2149711872,\"QualityIn\":910000000,\"QualityOut\":870000000,\"Memos\":[{\"Memo\":{\"MemoData\":\"7465787465642064617461\",\"MemoType\":\"74657374\",\"MemoFormat\":\"706C61696E2F74657874\"}}],\"LastLedgerSequence\":8820051,\"Fee\":\"12\",\"Sequence\":23}",
|
||||||
"instructions": {
|
"instructions": {
|
||||||
"fee": "0.000012",
|
"fee": "0.000012",
|
||||||
"sequence": 23,
|
"sequence": 23,
|
||||||
|
|||||||
32
test/fixtures/rippled/index.js
vendored
32
test/fixtures/rippled/index.js
vendored
@@ -5,11 +5,13 @@ module.exports = {
|
|||||||
success: require('./submit'),
|
success: require('./submit'),
|
||||||
failure: require('./submit-failed')
|
failure: require('./submit-failed')
|
||||||
},
|
},
|
||||||
ledger: require('./ledger'),
|
ledger: {
|
||||||
ledgerNotFound: require('./ledger-not-found'),
|
normal: require('./ledger'),
|
||||||
ledgerWithoutCloseTime: require('./ledger-without-close-time'),
|
notFound: require('./ledger-not-found'),
|
||||||
ledgerWithSettingsTx: require('./ledger-with-settings-tx'),
|
withoutCloseTime: require('./ledger-without-close-time'),
|
||||||
ledgerWithStateAsHashes: require('./ledger-with-state-as-hashes'),
|
withSettingsTx: require('./ledger-with-settings-tx'),
|
||||||
|
withStateAsHashes: require('./ledger-with-state-as-hashes')
|
||||||
|
},
|
||||||
subscribe: require('./subscribe'),
|
subscribe: require('./subscribe'),
|
||||||
unsubscribe: require('./unsubscribe'),
|
unsubscribe: require('./unsubscribe'),
|
||||||
account_info: {
|
account_info: {
|
||||||
@@ -17,14 +19,20 @@ module.exports = {
|
|||||||
notfound: require('./account-info-not-found')
|
notfound: require('./account-info-not-found')
|
||||||
},
|
},
|
||||||
account_offers: require('./account-offers'),
|
account_offers: require('./account-offers'),
|
||||||
account_tx: require('./account-tx'),
|
account_tx: {
|
||||||
account_tx_one: require('./get-transactions-one'),
|
normal: require('./account-tx'),
|
||||||
|
one: require('./get-transactions-one')
|
||||||
|
},
|
||||||
gateway_balances: require('./gateway-balances'),
|
gateway_balances: require('./gateway-balances'),
|
||||||
book_offers: require('./book-offers'),
|
book_offers: {
|
||||||
book_offers_1: require('./book-offers-1'),
|
fabric: require('./book-offers'),
|
||||||
book_offers_2: require('./book-offers-2'),
|
usd_xrp: require('./book-offers-usd-xrp'),
|
||||||
server_info: require('./server-info'),
|
xrp_usd: require('./book-offers-xrp-usd')
|
||||||
server_info_error: require('./server-info-error'),
|
},
|
||||||
|
server_info: {
|
||||||
|
normal: require('./server-info'),
|
||||||
|
error: require('./server-info-error')
|
||||||
|
},
|
||||||
path_find: {
|
path_find: {
|
||||||
generate: require('./path-find'),
|
generate: require('./path-find'),
|
||||||
sendUSD: require('./path-find-send-usd'),
|
sendUSD: require('./path-find-send-usd'),
|
||||||
|
|||||||
@@ -97,9 +97,9 @@ module.exports = function(port) {
|
|||||||
mock.on('request_server_info', function(request, conn) {
|
mock.on('request_server_info', function(request, conn) {
|
||||||
assert.strictEqual(request.command, 'server_info');
|
assert.strictEqual(request.command, 'server_info');
|
||||||
if (mock.returnErrorOnServerInfo) {
|
if (mock.returnErrorOnServerInfo) {
|
||||||
conn.send(createResponse(request, fixtures.server_info_error));
|
conn.send(createResponse(request, fixtures.server_info.error));
|
||||||
} else {
|
} else {
|
||||||
conn.send(createResponse(request, fixtures.server_info));
|
conn.send(createResponse(request, fixtures.server_info.normal));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -139,19 +139,20 @@ module.exports = function(port) {
|
|||||||
mock.on('request_ledger', function(request, conn) {
|
mock.on('request_ledger', function(request, conn) {
|
||||||
assert.strictEqual(request.command, 'ledger');
|
assert.strictEqual(request.command, 'ledger');
|
||||||
if (request.ledger_index === 34) {
|
if (request.ledger_index === 34) {
|
||||||
conn.send(createLedgerResponse(request, fixtures.ledgerNotFound));
|
conn.send(createLedgerResponse(request, fixtures.ledger.notFound));
|
||||||
} else if (request.ledger_index === 6) {
|
} else if (request.ledger_index === 6) {
|
||||||
conn.send(createResponse(request, fixtures.ledgerWithStateAsHashes));
|
conn.send(createResponse(request, fixtures.ledger.withStateAsHashes));
|
||||||
} else if (request.ledger_index === 9038215) {
|
} else if (request.ledger_index === 9038215) {
|
||||||
conn.send(createLedgerResponse(request, fixtures.ledgerWithoutCloseTime));
|
conn.send(
|
||||||
|
createLedgerResponse(request, fixtures.ledger.withoutCloseTime));
|
||||||
} else if (request.ledger_index === 4181996) {
|
} else if (request.ledger_index === 4181996) {
|
||||||
conn.send(createLedgerResponse(request, fixtures.ledgerWithSettingsTx));
|
conn.send(createLedgerResponse(request, fixtures.ledger.withSettingsTx));
|
||||||
} else if (request.ledger_index === 38129) {
|
} else if (request.ledger_index === 38129) {
|
||||||
const response = _.assign({}, fixtures.ledger,
|
const response = _.assign({}, fixtures.ledger.normal,
|
||||||
{result: {ledger: fullLedger}});
|
{result: {ledger: fullLedger}});
|
||||||
conn.send(createLedgerResponse(request, response));
|
conn.send(createLedgerResponse(request, response));
|
||||||
} else {
|
} else {
|
||||||
conn.send(createLedgerResponse(request, fixtures.ledger));
|
conn.send(createLedgerResponse(request, fixtures.ledger.normal));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -263,7 +264,7 @@ module.exports = function(port) {
|
|||||||
if (request.account === addresses.ACCOUNT) {
|
if (request.account === addresses.ACCOUNT) {
|
||||||
conn.send(transactionsResponse(request));
|
conn.send(transactionsResponse(request));
|
||||||
} else if (request.account === addresses.OTHER_ACCOUNT) {
|
} else if (request.account === addresses.OTHER_ACCOUNT) {
|
||||||
conn.send(createResponse(request, fixtures.account_tx_one));
|
conn.send(createResponse(request, fixtures.account_tx.one));
|
||||||
} else {
|
} else {
|
||||||
assert(false, 'Unrecognized account address: ' + request.account);
|
assert(false, 'Unrecognized account address: ' + request.account);
|
||||||
}
|
}
|
||||||
@@ -279,16 +280,18 @@ module.exports = function(port) {
|
|||||||
|
|
||||||
mock.on('request_book_offers', function(request, conn) {
|
mock.on('request_book_offers', function(request, conn) {
|
||||||
if (request.taker_pays.issuer === 'rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw') {
|
if (request.taker_pays.issuer === 'rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw') {
|
||||||
conn.send(createResponse(request, fixtures.book_offers_2));
|
conn.send(createResponse(request, fixtures.book_offers.xrp_usd));
|
||||||
} else if (request.taker_gets.issuer
|
} else if (request.taker_gets.issuer
|
||||||
=== 'rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw') {
|
=== 'rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw') {
|
||||||
conn.send(createResponse(request, fixtures.book_offers_1));
|
conn.send(createResponse(request, fixtures.book_offers.usd_xrp));
|
||||||
} else if (isBTC(request.taker_gets.currency)
|
} else if (isBTC(request.taker_gets.currency)
|
||||||
&& isUSD(request.taker_pays.currency)) {
|
&& isUSD(request.taker_pays.currency)) {
|
||||||
conn.send(fixtures.book_offers.requestBookOffersBidsResponse(request));
|
conn.send(
|
||||||
|
fixtures.book_offers.fabric.requestBookOffersBidsResponse(request));
|
||||||
} else if (isUSD(request.taker_gets.currency)
|
} else if (isUSD(request.taker_gets.currency)
|
||||||
&& isBTC(request.taker_pays.currency)) {
|
&& isBTC(request.taker_pays.currency)) {
|
||||||
conn.send(fixtures.book_offers.requestBookOffersAsksResponse(request));
|
conn.send(
|
||||||
|
fixtures.book_offers.fabric.requestBookOffersAsksResponse(request));
|
||||||
} else {
|
} else {
|
||||||
assert(false, 'Unrecognized order book: ' + JSON.stringify(request));
|
assert(false, 'Unrecognized order book: ' + JSON.stringify(request));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user