mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Merge pull request #1084 from ripple/tests-to-ts-04
Complete move of tests to TS
This commit is contained in:
@@ -35,7 +35,7 @@
|
|||||||
"@types/node": "^12.12.5",
|
"@types/node": "^12.12.5",
|
||||||
"@typescript-eslint/eslint-plugin": "^2.3.3",
|
"@typescript-eslint/eslint-plugin": "^2.3.3",
|
||||||
"@typescript-eslint/parser": "^2.3.3",
|
"@typescript-eslint/parser": "^2.3.3",
|
||||||
"assert-diff": "^1.0.1",
|
"assert-diff": "^2.0.3",
|
||||||
"doctoc": "^0.15.0",
|
"doctoc": "^0.15.0",
|
||||||
"ejs": "^2.3.4",
|
"ejs": "^2.3.4",
|
||||||
"eslint": "^6.5.1",
|
"eslint": "^6.5.1",
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
|
|
||||||
import * as _ from 'lodash'
|
import * as _ from 'lodash'
|
||||||
import {RippleAPI} from './api'
|
import {RippleAPI, APIOptions} from './api'
|
||||||
|
|
||||||
class RippleAPIBroadcast extends RippleAPI {
|
class RippleAPIBroadcast extends RippleAPI {
|
||||||
|
|
||||||
ledgerVersion: number | undefined = undefined
|
ledgerVersion: number | undefined = undefined
|
||||||
private _apis: RippleAPI[]
|
private _apis: RippleAPI[]
|
||||||
|
|
||||||
constructor(servers, options) {
|
constructor(servers, options: APIOptions = {}) {
|
||||||
super(options)
|
super(options)
|
||||||
|
|
||||||
const apis: RippleAPI[] = servers.map(server => new RippleAPI(
|
const apis: RippleAPI[] = servers.map(server => new RippleAPI(
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ import _ from 'lodash';
|
|||||||
import {RippleAPI} from 'ripple-api';
|
import {RippleAPI} from 'ripple-api';
|
||||||
import {RecursiveData} from 'ripple-api/ledger/utils';
|
import {RecursiveData} from 'ripple-api/ledger/utils';
|
||||||
import binary from 'ripple-binary-codec';
|
import binary from 'ripple-binary-codec';
|
||||||
import { requests, responses } from './fixtures';
|
import requests from './fixtures/requests';
|
||||||
import addresses from './fixtures/addresses';
|
import responses from './fixtures/responses';
|
||||||
import hashes from './fixtures/hashes';
|
import addresses from './fixtures/addresses.json';
|
||||||
|
import hashes from './fixtures/hashes.json';
|
||||||
import ledgerClosed from './fixtures/rippled/ledger-close-newer.json';
|
import ledgerClosed from './fixtures/rippled/ledger-close-newer.json';
|
||||||
import setupAPI from './setup-api';
|
import setupAPI from './setup-api';
|
||||||
const {validate, schemaValidator} = RippleAPI._PRIVATE;
|
const {validate, schemaValidator} = RippleAPI._PRIVATE;
|
||||||
@@ -268,13 +269,18 @@ describe('RippleAPI', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
describe('isValidAddress', function () {
|
describe('isValidAddress', function () {
|
||||||
it('returns true for valid address', function () {
|
it('returns true for valid address', function () {
|
||||||
assert(this.api.isValidAddress('rLczgQHxPhWtjkaQqn3Q6UM8AbRbbRvs5K'));
|
assert(this.api.isValidAddress('rLczgQHxPhWtjkaQqn3Q6UM8AbRbbRvs5K'));
|
||||||
|
assert(this.api.isValidAddress(addresses.ACCOUNT_X));
|
||||||
|
assert(this.api.isValidAddress(addresses.ACCOUNT_T));
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns false for invalid address', function () {
|
it('returns false for invalid address', function () {
|
||||||
assert(!this.api.isValidAddress('foobar'));
|
assert(!this.api.isValidAddress('foobar'));
|
||||||
|
assert(!this.api.isValidAddress(addresses.ACCOUNT_X.slice(0, -1)));
|
||||||
|
assert(!this.api.isValidAddress(addresses.ACCOUNT_T.slice(1)));
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -315,6 +321,21 @@ describe('RippleAPI', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('deriveXAddress', function () {
|
||||||
|
it('returns address for public key', function () {
|
||||||
|
assert.equal(RippleAPI.deriveXAddress({
|
||||||
|
publicKey: '035332FBA71D705BD5D97014A833BE2BBB25BEFCD3506198E14AFEA241B98C2D06',
|
||||||
|
tag: false,
|
||||||
|
test: false
|
||||||
|
}), 'XVZVpQj8YSVpNyiwXYSqvQoQqgBttTxAZwMcuJd4xteQHyt');
|
||||||
|
assert.equal(RippleAPI.deriveXAddress({
|
||||||
|
publicKey: '035332FBA71D705BD5D97014A833BE2BBB25BEFCD3506198E14AFEA241B98C2D06',
|
||||||
|
tag: false,
|
||||||
|
test: true
|
||||||
|
}), 'TVVrSWtmQQssgVcmoMBcFQZKKf56QscyWLKnUyiuZW8ALU4');
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('pagination', function () {
|
describe('pagination', function () {
|
||||||
|
|
||||||
describe('hasNextPage', function () {
|
describe('hasNextPage', function () {
|
||||||
@@ -3440,7 +3461,6 @@ describe('RippleAPI', function () {
|
|||||||
_.partial(checkResult, responses.getTrustlines.all, 'getTrustlines'));
|
_.partial(checkResult, responses.getTrustlines.all, 'getTrustlines'));
|
||||||
});
|
});
|
||||||
|
|
||||||
// @deprecated See corresponding test in `x-address-api-test.js`
|
|
||||||
it('generateAddress', function () {
|
it('generateAddress', function () {
|
||||||
function random() {
|
function random() {
|
||||||
return _.fill(Array(16), 0);
|
return _.fill(Array(16), 0);
|
||||||
@@ -3458,6 +3478,23 @@ describe('RippleAPI', function () {
|
|||||||
}, this.api.errors.UnexpectedError);
|
}, this.api.errors.UnexpectedError);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('generateXAddress', function () {
|
||||||
|
function random() {
|
||||||
|
return _.fill(Array(16), 0);
|
||||||
|
}
|
||||||
|
assert.deepEqual(this.api.generateXAddress({ entropy: random() }),
|
||||||
|
responses.generateXAddress);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('generateXAddress invalid', function () {
|
||||||
|
assert.throws(() => {
|
||||||
|
function random() {
|
||||||
|
return _.fill(Array(1), 0);
|
||||||
|
}
|
||||||
|
this.api.generateXAddress({ entropy: random() });
|
||||||
|
}, this.api.errors.UnexpectedError);
|
||||||
|
});
|
||||||
|
|
||||||
it('getSettings', function () {
|
it('getSettings', function () {
|
||||||
return this.api.getSettings(address).then(
|
return this.api.getSettings(address).then(
|
||||||
_.partial(checkResult, responses.getSettings, 'getSettings'));
|
_.partial(checkResult, responses.getSettings, 'getSettings'));
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import assert from 'assert-diff';
|
import assert from 'assert-diff';
|
||||||
import setupAPI from './setup-api';
|
import setupAPI from './setup-api';
|
||||||
import {responses} from './fixtures';
|
import responses from './fixtures/responses';
|
||||||
import ledgerClosed from './fixtures/rippled/ledger-close.json';
|
import ledgerClosed from './fixtures/rippled/ledger-close.json';
|
||||||
import {RippleAPI} from 'ripple-api';
|
import {RippleAPI} from 'ripple-api';
|
||||||
const schemaValidator = RippleAPI._PRIVATE.schemaValidator;
|
const schemaValidator = RippleAPI._PRIVATE.schemaValidator;
|
||||||
|
|||||||
13
test/fixtures/addresses.js
vendored
13
test/fixtures/addresses.js
vendored
@@ -1,13 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
module.exports = {
|
|
||||||
ACCOUNT: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
|
||||||
ACCOUNT_X: 'X7AcgcsBL6XDcUb289X4mJ8djcdyKaB5hJDWMArnXr61cqZ',
|
|
||||||
ACCOUNT_T: 'T719a5UwUCnEs54UsxG9CJYYDhwmFCqkr7wxCcNcfZ6p5GZ',
|
|
||||||
OTHER_ACCOUNT: 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo',
|
|
||||||
THIRD_ACCOUNT: 'rwBYyfufTzk77zUSKEu4MvixfarC35av1J',
|
|
||||||
FOURTH_ACCOUNT: 'rJnZ4YHCUsHvQu7R6mZohevKJDHFzVD6Zr',
|
|
||||||
ISSUER: 'rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM',
|
|
||||||
NOTFOUND: 'rajTAg3hon5Lcu1RxQQPxTgHvqfhc1EaUS',
|
|
||||||
SECRET: 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV',
|
|
||||||
SOURCE_LOW_FUNDS: 'rhVgDEfS1r1fLyRUZCpab4TdowZcAJwHy2'
|
|
||||||
};
|
|
||||||
12
test/fixtures/addresses.json
vendored
Normal file
12
test/fixtures/addresses.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"ACCOUNT": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
|
||||||
|
"ACCOUNT_X": "X7AcgcsBL6XDcUb289X4mJ8djcdyKaB5hJDWMArnXr61cqZ",
|
||||||
|
"ACCOUNT_T": "T719a5UwUCnEs54UsxG9CJYYDhwmFCqkr7wxCcNcfZ6p5GZ",
|
||||||
|
"OTHER_ACCOUNT": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
|
||||||
|
"THIRD_ACCOUNT": "rwBYyfufTzk77zUSKEu4MvixfarC35av1J",
|
||||||
|
"FOURTH_ACCOUNT": "rJnZ4YHCUsHvQu7R6mZohevKJDHFzVD6Zr",
|
||||||
|
"ISSUER": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM",
|
||||||
|
"NOTFOUND": "rajTAg3hon5Lcu1RxQQPxTgHvqfhc1EaUS",
|
||||||
|
"SECRET": "shsWGZcmZz6YsWWmcnpfr6fLTdtFV",
|
||||||
|
"SOURCE_LOW_FUNDS": "rhVgDEfS1r1fLyRUZCpab4TdowZcAJwHy2"
|
||||||
|
}
|
||||||
12
test/fixtures/hashes.js
vendored
12
test/fixtures/hashes.js
vendored
@@ -1,12 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
VALID_TRANSACTION_HASH:
|
|
||||||
'F4AB442A6D4CBB935D66E1DA7309A5FC71C7143ED4049053EC14E3875B0CF9BF',
|
|
||||||
NOTFOUND_TRANSACTION_HASH:
|
|
||||||
'D7FA4BBD23FAA88FC208BD194EC435D7A1FD9E2E8887B9C17A811A0739AA4AE4',
|
|
||||||
INVALID_TRANSACTION_HASH:
|
|
||||||
'XF4AB442A6D4CBB935D66E1DA7309A5FC71C7143ED4049053EC14E3875B0CF9BF',
|
|
||||||
ORDER_HASH:
|
|
||||||
'71AE74B03DE3B9A06C559AD4D173A362D96B7D2A5AA35F56B9EF21543D627F34'
|
|
||||||
};
|
|
||||||
10
test/fixtures/hashes.json
vendored
Normal file
10
test/fixtures/hashes.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"VALID_TRANSACTION_HASH":
|
||||||
|
"F4AB442A6D4CBB935D66E1DA7309A5FC71C7143ED4049053EC14E3875B0CF9BF",
|
||||||
|
"NOTFOUND_TRANSACTION_HASH":
|
||||||
|
"D7FA4BBD23FAA88FC208BD194EC435D7A1FD9E2E8887B9C17A811A0739AA4AE4",
|
||||||
|
"INVALID_TRANSACTION_HASH":
|
||||||
|
"XF4AB442A6D4CBB935D66E1DA7309A5FC71C7143ED4049053EC14E3875B0CF9BF",
|
||||||
|
"ORDER_HASH":
|
||||||
|
"71AE74B03DE3B9A06C559AD4D173A362D96B7D2A5AA35F56B9EF21543D627F34"
|
||||||
|
}
|
||||||
7
test/fixtures/index.js
vendored
7
test/fixtures/index.js
vendored
@@ -1,7 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
responses: require('./responses'),
|
|
||||||
requests: require('./requests'),
|
|
||||||
rippled: require('./rippled')
|
|
||||||
};
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
'use strict';
|
import {RippleAPIBroadcast} from '../../src';
|
||||||
const {RippleAPIBroadcast} = require('../../src');
|
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
const servers = ['wss://s1.ripple.com', 'wss://s2.ripple.com'];
|
const servers = ['wss://s1.ripple.com', 'wss://s2.ripple.com'];
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
'use strict';
|
import Connection from '../../src/common/connection';
|
||||||
const Connection = require('../../src/common/connection');
|
|
||||||
|
|
||||||
const request1 = {
|
const request1 = {
|
||||||
command: 'server_info'
|
command: 'server_info'
|
||||||
@@ -1,15 +1,12 @@
|
|||||||
/* eslint-disable max-nested-callbacks */
|
import _ from 'lodash';
|
||||||
/* eslint-disable max-params */
|
import assert from 'assert';
|
||||||
'use strict';
|
import wallet from './wallet';
|
||||||
const _ = require('lodash');
|
import requests from '../fixtures/requests';
|
||||||
const assert = require('assert');
|
import {RippleAPI} from 'ripple-api';
|
||||||
const errors = require('../../src/common/errors');
|
import {isValidAddress} from 'ripple-address-codec';
|
||||||
const wallet = require('./wallet');
|
import {payTo, ledgerAccept} from './utils';
|
||||||
const requests = require('../fixtures/requests');
|
import {errors} from 'ripple-api/common';
|
||||||
const RippleAPI = require('ripple-api').RippleAPI;
|
import {isValidSecret} from 'ripple-api/common/utils';
|
||||||
const {isValidAddress} = require('ripple-address-codec');
|
|
||||||
const {isValidSecret} = require('../../src/common');
|
|
||||||
const {payTo, ledgerAccept} = require('./utils');
|
|
||||||
|
|
||||||
|
|
||||||
// how long before each test case times out
|
// how long before each test case times out
|
||||||
@@ -71,7 +68,7 @@ function testTransaction(testcase, type, lastClosedLedgerVersion, prepared,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup(server = 'wss://s1.ripple.com') {
|
function setup(this: any, server = 'wss://s1.ripple.com') {
|
||||||
this.api = new RippleAPI({server});
|
this.api = new RippleAPI({server});
|
||||||
console.log('CONNECTING...');
|
console.log('CONNECTING...');
|
||||||
return this.api.connect().then(() => {
|
return this.api.connect().then(() => {
|
||||||
@@ -167,11 +164,11 @@ function setupAccounts(testcase) {
|
|||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function teardown() {
|
function teardown(this: any) {
|
||||||
return this.api.disconnect();
|
return this.api.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
function suiteSetup() {
|
function suiteSetup(this: any) {
|
||||||
this.transactions = [];
|
this.transactions = [];
|
||||||
|
|
||||||
return setup.bind(this)(serverUrl)
|
return setup.bind(this)(serverUrl)
|
||||||
@@ -1,17 +1,16 @@
|
|||||||
'use strict'; // eslint-disable-line
|
import _ from 'lodash';
|
||||||
const _ = require('lodash');
|
import fs from 'fs';
|
||||||
const assert = require('assert');
|
import assert from 'assert';
|
||||||
const WebSocketServer = require('ws').Server;
|
import {Server as WebSocketServer} from 'ws';
|
||||||
const EventEmitter2 = require('eventemitter2').EventEmitter2;
|
import {EventEmitter2} from 'eventemitter2';
|
||||||
const fixtures = require('./fixtures/rippled');
|
import fixtures from './fixtures/rippled';
|
||||||
const addresses = require('./fixtures/addresses');
|
import addresses from './fixtures/addresses.json';
|
||||||
const hashes = require('./fixtures/hashes');
|
import hashes from './fixtures/hashes.json';
|
||||||
const transactionsResponse = require('./fixtures/rippled/account-tx');
|
import transactionsResponse from './fixtures/rippled/account-tx';
|
||||||
const accountLinesResponse = require('./fixtures/rippled/account-lines');
|
import accountLinesResponse from './fixtures/rippled/account-lines';
|
||||||
const accountObjectsResponse = require('./fixtures/rippled/account-objects');
|
import accountObjectsResponse from './fixtures/rippled/account-objects';
|
||||||
const fullLedger = require('./fixtures/rippled/ledger-full-38129.json');
|
import fullLedger from './fixtures/rippled/ledger-full-38129.json';
|
||||||
const { getFreePort } = require('./utils/net-utils');
|
import {getFreePort} from './utils/net-utils';
|
||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
function isUSD(json) {
|
function isUSD(json) {
|
||||||
return json === 'USD' || json === '0000000000000000000000005553440000000000';
|
return json === 'USD' || json === '0000000000000000000000005553440000000000';
|
||||||
@@ -49,8 +48,12 @@ function createLedgerResponse(request, response) {
|
|||||||
return JSON.stringify(newResponse);
|
return JSON.stringify(newResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function createMockRippled(port) {
|
// We mock out WebSocketServer in these tests and add a lot of custom
|
||||||
const mock = new WebSocketServer({ port: port });
|
// properties not defined on the normal WebSocketServer object.
|
||||||
|
type MockedWebSocketServer = any;
|
||||||
|
|
||||||
|
export function createMockRippled(port) {
|
||||||
|
const mock = new WebSocketServer({ port: port }) as MockedWebSocketServer;
|
||||||
_.assign(mock, EventEmitter2.prototype);
|
_.assign(mock, EventEmitter2.prototype);
|
||||||
|
|
||||||
const close = mock.close;
|
const close = mock.close;
|
||||||
@@ -73,7 +76,7 @@ module.exports = function createMockRippled(port) {
|
|||||||
mock.expectedRequests = expectedRequests;
|
mock.expectedRequests = expectedRequests;
|
||||||
};
|
};
|
||||||
|
|
||||||
mock.on('connection', function (conn) {
|
mock.on('connection', function (this: MockedWebSocketServer, conn: any) {
|
||||||
if (mock.config.breakNextConnection) {
|
if (mock.config.breakNextConnection) {
|
||||||
mock.config.breakNextConnection = false;
|
mock.config.breakNextConnection = false;
|
||||||
conn.terminate();
|
conn.terminate();
|
||||||
@@ -94,7 +97,7 @@ module.exports = function createMockRippled(port) {
|
|||||||
|
|
||||||
mock.config = {};
|
mock.config = {};
|
||||||
|
|
||||||
mock.onAny(function () {
|
mock.onAny(function (this: MockedWebSocketServer) {
|
||||||
if (this.event.indexOf('request_') !== 0) {
|
if (this.event.indexOf('request_') !== 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
|
|
||||||
const port = 34371;
|
const port = 34371;
|
||||||
|
import {createMockRippled} from './mock-rippled';
|
||||||
const createMockRippled = require('./mock-rippled');
|
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
if (global.describe) {
|
if (global.describe) {
|
||||||
@@ -1,13 +1,10 @@
|
|||||||
/* eslint-disable max-nested-callbacks */
|
import {RippleAPI, RippleAPIBroadcast} from 'ripple-api';
|
||||||
'use strict'; // eslint-disable-line
|
import ledgerClosed from './fixtures/rippled/ledger-close.json';
|
||||||
|
|
||||||
const {RippleAPI, RippleAPIBroadcast} = require('ripple-api');
|
|
||||||
const ledgerClosed = require('./fixtures/rippled/ledger-close');
|
|
||||||
|
|
||||||
const port = 34371;
|
const port = 34371;
|
||||||
const baseUrl = 'ws://testripple.circleci.com:';
|
const baseUrl = 'ws://testripple.circleci.com:';
|
||||||
|
|
||||||
function setup(port_ = port) {
|
function setup(this: any, port_ = port) {
|
||||||
const tapi = new RippleAPI({server: baseUrl + port_});
|
const tapi = new RippleAPI({server: baseUrl + port_});
|
||||||
return tapi.connect().then(() => {
|
return tapi.connect().then(() => {
|
||||||
return tapi.connection.request({
|
return tapi.connection.request({
|
||||||
@@ -27,7 +24,7 @@ function setup(port_ = port) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupBroadcast() {
|
function setupBroadcast(this: any) {
|
||||||
const servers = [port, port + 1].map(port_ => baseUrl + port_);
|
const servers = [port, port + 1].map(port_ => baseUrl + port_);
|
||||||
this.api = new RippleAPIBroadcast(servers);
|
this.api = new RippleAPIBroadcast(servers);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -39,14 +36,14 @@ function setupBroadcast() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function teardown() {
|
function teardown(this: any) {
|
||||||
if (this.api.isConnected()) {
|
if (this.api.isConnected()) {
|
||||||
return this.api.disconnect();
|
return this.api.disconnect();
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
setup: setup,
|
setup: setup,
|
||||||
teardown: teardown,
|
teardown: teardown,
|
||||||
setupBroadcast: setupBroadcast
|
setupBroadcast: setupBroadcast
|
||||||
@@ -1,11 +1,7 @@
|
|||||||
'use strict'; // eslint-disable-line
|
import {RippleAPI, RippleAPIBroadcast} from 'ripple-api';
|
||||||
|
import ledgerClosed from './fixtures/rippled/ledger-close.json';
|
||||||
const RippleAPI = require('ripple-api').RippleAPI;
|
import {createMockRippled} from './mock-rippled';
|
||||||
const RippleAPIBroadcast = require('ripple-api').RippleAPIBroadcast;
|
import {getFreePort} from './utils/net-utils';
|
||||||
const ledgerClosed = require('./fixtures/rippled/ledger-close');
|
|
||||||
const createMockRippled = require('./mock-rippled');
|
|
||||||
const {getFreePort} = require('./utils/net-utils');
|
|
||||||
|
|
||||||
|
|
||||||
function setupMockRippledConnection(testcase, port) {
|
function setupMockRippledConnection(testcase, port) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -31,19 +27,19 @@ function setupMockRippledConnectionForBroadcast(testcase, ports) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup() {
|
function setup(this: any) {
|
||||||
return getFreePort().then(port => {
|
return getFreePort().then(port => {
|
||||||
return setupMockRippledConnection(this, port);
|
return setupMockRippledConnection(this, port);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupBroadcast() {
|
function setupBroadcast(this: any) {
|
||||||
return Promise.all([getFreePort(), getFreePort()]).then(ports => {
|
return Promise.all([getFreePort(), getFreePort()]).then(ports => {
|
||||||
return setupMockRippledConnectionForBroadcast(this, ports);
|
return setupMockRippledConnectionForBroadcast(this, ports);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function teardown(done) {
|
function teardown(this: any, done) {
|
||||||
this.api.disconnect().then(() => {
|
this.api.disconnect().then(() => {
|
||||||
if (this.mockRippled !== undefined) {
|
if (this.mockRippled !== undefined) {
|
||||||
this.mockRippled.close();
|
this.mockRippled.close();
|
||||||
@@ -54,7 +50,7 @@ function teardown(done) {
|
|||||||
}).catch(done);
|
}).catch(done);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
setup: setup,
|
setup: setup,
|
||||||
teardown: teardown,
|
teardown: teardown,
|
||||||
setupBroadcast: setupBroadcast,
|
setupBroadcast: setupBroadcast,
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
'use strict'; // eslint-disable-line
|
import net from 'net';
|
||||||
|
|
||||||
const net = require('net');
|
|
||||||
|
|
||||||
// using a free port instead of a constant port enables parallelization
|
// using a free port instead of a constant port enables parallelization
|
||||||
function getFreePort() {
|
export function getFreePort() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const server = net.createServer();
|
const server = net.createServer();
|
||||||
let port;
|
let port;
|
||||||
server.on('listening', function() {
|
server.on('listening', function() {
|
||||||
port = server.address().port;
|
port = (server.address() as any).port;
|
||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
server.on('close', function() {
|
server.on('close', function() {
|
||||||
@@ -20,7 +18,3 @@ function getFreePort() {
|
|||||||
server.listen(0);
|
server.listen(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
getFreePort
|
|
||||||
};
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -508,10 +508,10 @@ asn1.js@^4.0.0:
|
|||||||
inherits "^2.0.1"
|
inherits "^2.0.1"
|
||||||
minimalistic-assert "^1.0.0"
|
minimalistic-assert "^1.0.0"
|
||||||
|
|
||||||
assert-diff@^1.0.1:
|
assert-diff@^2.0.3:
|
||||||
version "1.2.6"
|
version "2.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/assert-diff/-/assert-diff-1.2.6.tgz#1b44d6f24a7e3018f557768ee350ae9a732c2fc6"
|
resolved "https://registry.yarnpkg.com/assert-diff/-/assert-diff-2.0.3.tgz#f7a5ab51f8da1bf2dbc9afd3f0b9ea6919808a74"
|
||||||
integrity sha512-cKyCfCQrLsHubcvDo4n5lGJPxN5gwpm4Hmsjs9/DJCFs4a5jiNvhKRxKP2DZGxNxOf9Iv3pxOoBSCQ+8eiNIKA==
|
integrity sha512-TAPT9BmNP3384kP9jdkgRIYdddSO2hG3oG8B5+hoTd2khGC0XrM8ZT+FEkTr4kFFhzDuUveGtvNGcXD63qP6Mw==
|
||||||
dependencies:
|
dependencies:
|
||||||
assert-plus "1.0.0"
|
assert-plus "1.0.0"
|
||||||
json-diff "0.5.2"
|
json-diff "0.5.2"
|
||||||
|
|||||||
Reference in New Issue
Block a user