mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
convert the rest of the helper files to ts
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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,17 @@ function createLedgerResponse(request, response) {
|
|||||||
return JSON.stringify(newResponse);
|
return JSON.stringify(newResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function createMockRippled(port) {
|
interface CustomWebSocketServer extends WebSocketServer, EventEmitter2 {
|
||||||
const mock = new WebSocketServer({ port: port });
|
expectedRequests: any
|
||||||
|
expect: any
|
||||||
|
config: any
|
||||||
|
socket: any
|
||||||
|
onAny: any
|
||||||
|
event: any
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createMockRippled(port) {
|
||||||
|
const mock = new WebSocketServer({ port: port }) as CustomWebSocketServer;
|
||||||
_.assign(mock, EventEmitter2.prototype);
|
_.assign(mock, EventEmitter2.prototype);
|
||||||
|
|
||||||
const close = mock.close;
|
const close = mock.close;
|
||||||
@@ -73,7 +81,7 @@ module.exports = function createMockRippled(port) {
|
|||||||
mock.expectedRequests = expectedRequests;
|
mock.expectedRequests = expectedRequests;
|
||||||
};
|
};
|
||||||
|
|
||||||
mock.on('connection', function (conn) {
|
mock.on('connection', function (this: CustomWebSocketServer, conn: any) {
|
||||||
if (mock.config.breakNextConnection) {
|
if (mock.config.breakNextConnection) {
|
||||||
mock.config.breakNextConnection = false;
|
mock.config.breakNextConnection = false;
|
||||||
conn.terminate();
|
conn.terminate();
|
||||||
@@ -94,7 +102,7 @@ module.exports = function createMockRippled(port) {
|
|||||||
|
|
||||||
mock.config = {};
|
mock.config = {};
|
||||||
|
|
||||||
mock.onAny(function () {
|
mock.onAny(function (this: CustomWebSocketServer) {
|
||||||
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
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user