mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Revert "Revert "Merge pull request #1052 from FredKSchott/tests-to-ts-03""
This reverts commit b648387a57.
This commit is contained in:
@@ -35,7 +35,7 @@
|
||||
"@types/node": "^12.12.5",
|
||||
"@typescript-eslint/eslint-plugin": "^2.3.3",
|
||||
"@typescript-eslint/parser": "^2.3.3",
|
||||
"assert-diff": "^1.0.1",
|
||||
"assert-diff": "^2.0.3",
|
||||
"doctoc": "^0.15.0",
|
||||
"ejs": "^2.3.4",
|
||||
"eslint": "^6.5.1",
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
|
||||
import * as _ from 'lodash'
|
||||
import {RippleAPI} from './api'
|
||||
import {RippleAPI, APIOptions} from './api'
|
||||
|
||||
class RippleAPIBroadcast extends RippleAPI {
|
||||
|
||||
ledgerVersion: number | undefined = undefined
|
||||
private _apis: RippleAPI[]
|
||||
|
||||
constructor(servers, options) {
|
||||
constructor(servers, options: APIOptions = {}) {
|
||||
super(options)
|
||||
|
||||
const apis: RippleAPI[] = servers.map(server => new RippleAPI(
|
||||
|
||||
@@ -4,9 +4,10 @@ import _ from 'lodash';
|
||||
import {RippleAPI} from 'ripple-api';
|
||||
import {RecursiveData} from 'ripple-api/ledger/utils';
|
||||
import binary from 'ripple-binary-codec';
|
||||
import { requests, responses } from './fixtures';
|
||||
import addresses from './fixtures/addresses';
|
||||
import hashes from './fixtures/hashes';
|
||||
import requests from './fixtures/requests';
|
||||
import responses from './fixtures/responses';
|
||||
import addresses from './fixtures/addresses.json';
|
||||
import hashes from './fixtures/hashes.json';
|
||||
import ledgerClosed from './fixtures/rippled/ledger-close-newer.json';
|
||||
import setupAPI from './setup-api';
|
||||
const {validate, schemaValidator} = RippleAPI._PRIVATE;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import _ from 'lodash';
|
||||
import assert from 'assert-diff';
|
||||
import setupAPI from './setup-api';
|
||||
import {responses} from './fixtures';
|
||||
import responses from './fixtures/responses';
|
||||
import ledgerClosed from './fixtures/rippled/ledger-close.json';
|
||||
import {RippleAPI} from 'ripple-api';
|
||||
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';
|
||||
const {RippleAPIBroadcast} = require('../../src');
|
||||
import {RippleAPIBroadcast} from '../../src';
|
||||
|
||||
function main() {
|
||||
const servers = ['wss://s1.ripple.com', 'wss://s2.ripple.com'];
|
||||
@@ -1,5 +1,4 @@
|
||||
'use strict';
|
||||
const Connection = require('../../src/common/connection');
|
||||
import Connection from '../../src/common/connection';
|
||||
|
||||
const request1 = {
|
||||
command: 'server_info'
|
||||
@@ -1,15 +1,12 @@
|
||||
/* eslint-disable max-nested-callbacks */
|
||||
/* eslint-disable max-params */
|
||||
'use strict';
|
||||
const _ = require('lodash');
|
||||
const assert = require('assert');
|
||||
const errors = require('../../src/common/errors');
|
||||
const wallet = require('./wallet');
|
||||
const requests = require('../fixtures/requests');
|
||||
const RippleAPI = require('ripple-api').RippleAPI;
|
||||
const {isValidAddress} = require('ripple-address-codec');
|
||||
const {isValidSecret} = require('../../src/common');
|
||||
const {payTo, ledgerAccept} = require('./utils');
|
||||
import _ from 'lodash';
|
||||
import assert from 'assert';
|
||||
import wallet from './wallet';
|
||||
import requests from '../fixtures/requests';
|
||||
import {RippleAPI} from 'ripple-api';
|
||||
import {isValidAddress} from 'ripple-address-codec';
|
||||
import {payTo, ledgerAccept} from './utils';
|
||||
import {errors} from 'ripple-api/common';
|
||||
import {isValidSecret} from 'ripple-api/common/utils';
|
||||
|
||||
|
||||
// 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});
|
||||
console.log('CONNECTING...');
|
||||
return this.api.connect().then(() => {
|
||||
@@ -167,11 +164,11 @@ function setupAccounts(testcase) {
|
||||
return promise;
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
function teardown(this: any) {
|
||||
return this.api.disconnect();
|
||||
}
|
||||
|
||||
function suiteSetup() {
|
||||
function suiteSetup(this: any) {
|
||||
this.transactions = [];
|
||||
|
||||
return setup.bind(this)(serverUrl)
|
||||
@@ -1,17 +1,16 @@
|
||||
'use strict'; // eslint-disable-line
|
||||
const _ = require('lodash');
|
||||
const assert = require('assert');
|
||||
const WebSocketServer = require('ws').Server;
|
||||
const EventEmitter2 = require('eventemitter2').EventEmitter2;
|
||||
const fixtures = require('./fixtures/rippled');
|
||||
const addresses = require('./fixtures/addresses');
|
||||
const hashes = require('./fixtures/hashes');
|
||||
const transactionsResponse = require('./fixtures/rippled/account-tx');
|
||||
const accountLinesResponse = require('./fixtures/rippled/account-lines');
|
||||
const accountObjectsResponse = require('./fixtures/rippled/account-objects');
|
||||
const fullLedger = require('./fixtures/rippled/ledger-full-38129.json');
|
||||
const { getFreePort } = require('./utils/net-utils');
|
||||
const fs = require('fs');
|
||||
import _ from 'lodash';
|
||||
import fs from 'fs';
|
||||
import assert from 'assert';
|
||||
import {Server as WebSocketServer} from 'ws';
|
||||
import {EventEmitter2} from 'eventemitter2';
|
||||
import fixtures from './fixtures/rippled';
|
||||
import addresses from './fixtures/addresses.json';
|
||||
import hashes from './fixtures/hashes.json';
|
||||
import transactionsResponse from './fixtures/rippled/account-tx';
|
||||
import accountLinesResponse from './fixtures/rippled/account-lines';
|
||||
import accountObjectsResponse from './fixtures/rippled/account-objects';
|
||||
import fullLedger from './fixtures/rippled/ledger-full-38129.json';
|
||||
import {getFreePort} from './utils/net-utils';
|
||||
|
||||
function isUSD(json) {
|
||||
return json === 'USD' || json === '0000000000000000000000005553440000000000';
|
||||
@@ -49,8 +48,12 @@ function createLedgerResponse(request, response) {
|
||||
return JSON.stringify(newResponse);
|
||||
}
|
||||
|
||||
module.exports = function createMockRippled(port) {
|
||||
const mock = new WebSocketServer({ port: port });
|
||||
// We mock out WebSocketServer in these tests and add a lot of custom
|
||||
// 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);
|
||||
|
||||
const close = mock.close;
|
||||
@@ -73,7 +76,7 @@ module.exports = function createMockRippled(port) {
|
||||
mock.expectedRequests = expectedRequests;
|
||||
};
|
||||
|
||||
mock.on('connection', function (conn) {
|
||||
mock.on('connection', function (this: MockedWebSocketServer, conn: any) {
|
||||
if (mock.config.breakNextConnection) {
|
||||
mock.config.breakNextConnection = false;
|
||||
conn.terminate();
|
||||
@@ -94,7 +97,7 @@ module.exports = function createMockRippled(port) {
|
||||
|
||||
mock.config = {};
|
||||
|
||||
mock.onAny(function () {
|
||||
mock.onAny(function (this: MockedWebSocketServer) {
|
||||
if (this.event.indexOf('request_') !== 0) {
|
||||
return;
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
const port = 34371;
|
||||
|
||||
const createMockRippled = require('./mock-rippled');
|
||||
import {createMockRippled} from './mock-rippled';
|
||||
|
||||
function main() {
|
||||
if (global.describe) {
|
||||
@@ -1,13 +1,10 @@
|
||||
/* eslint-disable max-nested-callbacks */
|
||||
'use strict'; // eslint-disable-line
|
||||
|
||||
const {RippleAPI, RippleAPIBroadcast} = require('ripple-api');
|
||||
const ledgerClosed = require('./fixtures/rippled/ledger-close');
|
||||
import {RippleAPI, RippleAPIBroadcast} from 'ripple-api';
|
||||
import ledgerClosed from './fixtures/rippled/ledger-close.json';
|
||||
|
||||
const port = 34371;
|
||||
const baseUrl = 'ws://testripple.circleci.com:';
|
||||
|
||||
function setup(port_ = port) {
|
||||
function setup(this: any, port_ = port) {
|
||||
const tapi = new RippleAPI({server: baseUrl + port_});
|
||||
return tapi.connect().then(() => {
|
||||
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_);
|
||||
this.api = new RippleAPIBroadcast(servers);
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -39,14 +36,14 @@ function setupBroadcast() {
|
||||
});
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
function teardown(this: any) {
|
||||
if (this.api.isConnected()) {
|
||||
return this.api.disconnect();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
setup: setup,
|
||||
teardown: teardown,
|
||||
setupBroadcast: setupBroadcast
|
||||
@@ -1,11 +1,7 @@
|
||||
'use strict'; // eslint-disable-line
|
||||
|
||||
const RippleAPI = require('ripple-api').RippleAPI;
|
||||
const RippleAPIBroadcast = require('ripple-api').RippleAPIBroadcast;
|
||||
const ledgerClosed = require('./fixtures/rippled/ledger-close');
|
||||
const createMockRippled = require('./mock-rippled');
|
||||
const {getFreePort} = require('./utils/net-utils');
|
||||
|
||||
import {RippleAPI, RippleAPIBroadcast} from 'ripple-api';
|
||||
import ledgerClosed from './fixtures/rippled/ledger-close.json';
|
||||
import {createMockRippled} from './mock-rippled';
|
||||
import {getFreePort} from './utils/net-utils';
|
||||
|
||||
function setupMockRippledConnection(testcase, port) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -31,19 +27,19 @@ function setupMockRippledConnectionForBroadcast(testcase, ports) {
|
||||
});
|
||||
}
|
||||
|
||||
function setup() {
|
||||
function setup(this: any) {
|
||||
return getFreePort().then(port => {
|
||||
return setupMockRippledConnection(this, port);
|
||||
});
|
||||
}
|
||||
|
||||
function setupBroadcast() {
|
||||
function setupBroadcast(this: any) {
|
||||
return Promise.all([getFreePort(), getFreePort()]).then(ports => {
|
||||
return setupMockRippledConnectionForBroadcast(this, ports);
|
||||
});
|
||||
}
|
||||
|
||||
function teardown(done) {
|
||||
function teardown(this: any, done) {
|
||||
this.api.disconnect().then(() => {
|
||||
if (this.mockRippled !== undefined) {
|
||||
this.mockRippled.close();
|
||||
@@ -54,7 +50,7 @@ function teardown(done) {
|
||||
}).catch(done);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
setup: setup,
|
||||
teardown: teardown,
|
||||
setupBroadcast: setupBroadcast,
|
||||
@@ -1,14 +1,12 @@
|
||||
'use strict'; // eslint-disable-line
|
||||
|
||||
const net = require('net');
|
||||
import net from 'net';
|
||||
|
||||
// using a free port instead of a constant port enables parallelization
|
||||
function getFreePort() {
|
||||
export function getFreePort() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const server = net.createServer();
|
||||
let port;
|
||||
server.on('listening', function() {
|
||||
port = server.address().port;
|
||||
port = (server.address() as any).port;
|
||||
server.close();
|
||||
});
|
||||
server.on('close', function() {
|
||||
@@ -20,7 +18,3 @@ function getFreePort() {
|
||||
server.listen(0);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getFreePort
|
||||
};
|
||||
@@ -508,10 +508,10 @@ asn1.js@^4.0.0:
|
||||
inherits "^2.0.1"
|
||||
minimalistic-assert "^1.0.0"
|
||||
|
||||
assert-diff@^1.0.1:
|
||||
version "1.2.6"
|
||||
resolved "https://registry.yarnpkg.com/assert-diff/-/assert-diff-1.2.6.tgz#1b44d6f24a7e3018f557768ee350ae9a732c2fc6"
|
||||
integrity sha512-cKyCfCQrLsHubcvDo4n5lGJPxN5gwpm4Hmsjs9/DJCFs4a5jiNvhKRxKP2DZGxNxOf9Iv3pxOoBSCQ+8eiNIKA==
|
||||
assert-diff@^2.0.3:
|
||||
version "2.0.3"
|
||||
resolved "https://registry.yarnpkg.com/assert-diff/-/assert-diff-2.0.3.tgz#f7a5ab51f8da1bf2dbc9afd3f0b9ea6919808a74"
|
||||
integrity sha512-TAPT9BmNP3384kP9jdkgRIYdddSO2hG3oG8B5+hoTd2khGC0XrM8ZT+FEkTr4kFFhzDuUveGtvNGcXD63qP6Mw==
|
||||
dependencies:
|
||||
assert-plus "1.0.0"
|
||||
json-diff "0.5.2"
|
||||
|
||||
Reference in New Issue
Block a user