mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
move tests to TypeScript
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
"ws": "^3.3.1"
|
"ws": "^3.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/mocha": "^5.2.7",
|
||||||
"@types/node": "11.13.0",
|
"@types/node": "11.13.0",
|
||||||
"@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",
|
||||||
@@ -61,7 +62,7 @@
|
|||||||
"compile": "mkdir -p dist/npm/common && cp -r src/common/schemas dist/npm/common/ && tsc --build",
|
"compile": "mkdir -p dist/npm/common && cp -r src/common/schemas dist/npm/common/ && tsc --build",
|
||||||
"watch": "tsc -w",
|
"watch": "tsc -w",
|
||||||
"prepublish": "npm run clean && npm run compile && npm run build",
|
"prepublish": "npm run clean && npm run compile && npm run build",
|
||||||
"test": "TS_NODE_PROJECT=src/tsconfig.json nyc mocha --exit",
|
"test": "TS_NODE_PROJECT=test/tsconfig.json nyc mocha --exit",
|
||||||
"lint": "eslint src/**/*.ts 'test/*-test.{ts,js}'",
|
"lint": "eslint src/**/*.ts 'test/*-test.{ts,js}'",
|
||||||
"perf": "./scripts/perf_test.sh",
|
"perf": "./scripts/perf_test.sh",
|
||||||
"start": "node scripts/http.js"
|
"start": "node scripts/http.js"
|
||||||
|
|||||||
@@ -1,29 +1,22 @@
|
|||||||
/* eslint-disable max-nested-callbacks */
|
import assert from 'assert-diff';
|
||||||
'use strict'; // eslint-disable-line
|
import BigNumber from 'bignumber.js';
|
||||||
const _ = require('lodash');
|
import _ from 'lodash';
|
||||||
const assert = require('assert-diff');
|
import { RippleAPI } from 'ripple-api';
|
||||||
const setupAPI = require('./setup-api');
|
import { RecursiveData } from 'ripple-api/ledger/utils';
|
||||||
const RippleAPI = require('ripple-api').RippleAPI;
|
import binary from 'ripple-binary-codec';
|
||||||
const validate = RippleAPI._PRIVATE.validate;
|
import { requests, responses } from './fixtures';
|
||||||
const fixtures = require('./fixtures');
|
import addresses from './fixtures/addresses';
|
||||||
const requests = fixtures.requests;
|
import hashes from './fixtures/hashes';
|
||||||
const responses = fixtures.responses;
|
import ledgerClosed from './fixtures/rippled/ledger-close-newer.json';
|
||||||
const addresses = require('./fixtures/addresses');
|
import setupAPI from './setup-api';
|
||||||
const hashes = require('./fixtures/hashes');
|
const {validate, schemaValidator} = RippleAPI._PRIVATE;
|
||||||
const address = addresses.ACCOUNT;
|
const address = addresses.ACCOUNT;
|
||||||
const utils = RippleAPI._PRIVATE.ledgerUtils;
|
const utils = RippleAPI._PRIVATE.ledgerUtils;
|
||||||
const ledgerClosed = require('./fixtures/rippled/ledger-close-newer');
|
|
||||||
const schemaValidator = RippleAPI._PRIVATE.schemaValidator;
|
|
||||||
const binary = require('ripple-binary-codec');
|
|
||||||
const BigNumber = require('bignumber.js');
|
|
||||||
assert.options.strict = true;
|
assert.options.strict = true;
|
||||||
|
|
||||||
// how long before each test case times out
|
// how long before each test case times out
|
||||||
const TIMEOUT = 20000;
|
const TIMEOUT = 20000;
|
||||||
|
|
||||||
function unused() {
|
|
||||||
}
|
|
||||||
|
|
||||||
function closeLedger(connection) {
|
function closeLedger(connection) {
|
||||||
connection._ws.emit('message', JSON.stringify(ledgerClosed));
|
connection._ws.emit('message', JSON.stringify(ledgerClosed));
|
||||||
}
|
}
|
||||||
@@ -3577,9 +3570,9 @@ describe('RippleAPI', function () {
|
|||||||
taker: address
|
taker: address
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
).then((directOfferResults, reverseOfferResults) => {
|
).then(([directOfferResults, reverseOfferResults]) => {
|
||||||
const directOffers = (directOfferResults ? directOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
|
const directOffers = (directOfferResults ? directOfferResults.offers : []).reduce((acc, res) => acc.concat(res), [])
|
||||||
const reverseOffers = (reverseOfferResults ? reverseOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
|
const reverseOffers = (reverseOfferResults ? reverseOfferResults.offers : []).reduce((acc, res) => acc.concat(res), [])
|
||||||
const orderbook = RippleAPI.formatBidsAndAsks(orderbookInfo, [...directOffers, ...reverseOffers]);
|
const orderbook = RippleAPI.formatBidsAndAsks(orderbookInfo, [...directOffers, ...reverseOffers]);
|
||||||
assert.deepEqual(orderbook, responses.getOrderbook.normal);
|
assert.deepEqual(orderbook, responses.getOrderbook.normal);
|
||||||
});
|
});
|
||||||
@@ -3613,9 +3606,9 @@ describe('RippleAPI', function () {
|
|||||||
taker: address
|
taker: address
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
).then((directOfferResults, reverseOfferResults) => {
|
).then(([directOfferResults, reverseOfferResults]) => {
|
||||||
const directOffers = (directOfferResults ? directOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
|
const directOffers = (directOfferResults ? directOfferResults.offers : []).reduce((acc, res) => acc.concat(res), [])
|
||||||
const reverseOffers = (reverseOfferResults ? reverseOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
|
const reverseOffers = (reverseOfferResults ? reverseOfferResults.offers : []).reduce((acc, res) => acc.concat(res), [])
|
||||||
const orderbook = RippleAPI.formatBidsAndAsks(orderbookInfo, [...directOffers, ...reverseOffers]);
|
const orderbook = RippleAPI.formatBidsAndAsks(orderbookInfo, [...directOffers, ...reverseOffers]);
|
||||||
assert.deepEqual(orderbook, responses.getOrderbook.withXRP);
|
assert.deepEqual(orderbook, responses.getOrderbook.withXRP);
|
||||||
});
|
});
|
||||||
@@ -3681,9 +3674,9 @@ describe('RippleAPI', function () {
|
|||||||
taker: myAddress
|
taker: myAddress
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
).then((directOfferResults, reverseOfferResults) => {
|
).then(([directOfferResults, reverseOfferResults]) => {
|
||||||
const directOffers = (directOfferResults ? directOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
|
const directOffers = (directOfferResults ? directOfferResults.offers : []).reduce((acc, res) => acc.concat(res), [])
|
||||||
const reverseOffers = (reverseOfferResults ? reverseOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
|
const reverseOffers = (reverseOfferResults ? reverseOfferResults.offers : []).reduce((acc, res) => acc.concat(res), [])
|
||||||
const orderbook = RippleAPI.formatBidsAndAsks(orderbookInfo, [...directOffers, ...reverseOffers]);
|
const orderbook = RippleAPI.formatBidsAndAsks(orderbookInfo, [...directOffers, ...reverseOffers]);
|
||||||
assert.deepStrictEqual([], orderbook.bids);
|
assert.deepStrictEqual([], orderbook.bids);
|
||||||
return checkSortingOfOrders(orderbook.asks);
|
return checkSortingOfOrders(orderbook.asks);
|
||||||
@@ -3714,9 +3707,9 @@ describe('RippleAPI', function () {
|
|||||||
taker: myAddress
|
taker: myAddress
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
).then((directOfferResults, reverseOfferResults) => {
|
).then(([directOfferResults, reverseOfferResults]) => {
|
||||||
const directOffers = (directOfferResults ? directOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
|
const directOffers = (directOfferResults ? directOfferResults.offers : []).reduce((acc, res) => acc.concat(res), [])
|
||||||
const reverseOffers = (reverseOfferResults ? reverseOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
|
const reverseOffers = (reverseOfferResults ? reverseOfferResults.offers : []).reduce((acc, res) => acc.concat(res), [])
|
||||||
const orderbook = RippleAPI.formatBidsAndAsks(orderbookInfo, [...directOffers, ...reverseOffers]);
|
const orderbook = RippleAPI.formatBidsAndAsks(orderbookInfo, [...directOffers, ...reverseOffers]);
|
||||||
return checkSortingOfOrders(orderbook.bids) && checkSortingOfOrders(orderbook.asks);
|
return checkSortingOfOrders(orderbook.bids) && checkSortingOfOrders(orderbook.asks);
|
||||||
});
|
});
|
||||||
@@ -3751,9 +3744,9 @@ describe('RippleAPI', function () {
|
|||||||
taker: address
|
taker: address
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
).then((directOfferResults, reverseOfferResults) => {
|
).then(([directOfferResults, reverseOfferResults]) => {
|
||||||
const directOffers = (directOfferResults ? directOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
|
const directOffers = (directOfferResults ? directOfferResults.offers : []).reduce((acc, res) => acc.concat(res), [])
|
||||||
const reverseOffers = (reverseOfferResults ? reverseOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
|
const reverseOffers = (reverseOfferResults ? reverseOfferResults.offers : []).reduce((acc, res) => acc.concat(res), [])
|
||||||
const orderbook = RippleAPI.formatBidsAndAsks(orderbookInfo, [...directOffers, ...reverseOffers]);
|
const orderbook = RippleAPI.formatBidsAndAsks(orderbookInfo, [...directOffers, ...reverseOffers]);
|
||||||
|
|
||||||
const bidRates = orderbook.bids.map(bid => bid.properties.makerExchangeRate);
|
const bidRates = orderbook.bids.map(bid => bid.properties.makerExchangeRate);
|
||||||
@@ -3795,9 +3788,9 @@ describe('RippleAPI', function () {
|
|||||||
taker: address
|
taker: address
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
).then((directOfferResults, reverseOfferResults) => {
|
).then(([directOfferResults, reverseOfferResults]) => {
|
||||||
const directOffers = (directOfferResults ? directOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
|
const directOffers = (directOfferResults ? directOfferResults.offers : []).reduce((acc, res) => acc.concat(res), [])
|
||||||
const reverseOffers = (reverseOfferResults ? reverseOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
|
const reverseOffers = (reverseOfferResults ? reverseOfferResults.offers : []).reduce((acc, res) => acc.concat(res), [])
|
||||||
const orderbook = RippleAPI.formatBidsAndAsks(orderbookInfo, [...directOffers, ...reverseOffers]);
|
const orderbook = RippleAPI.formatBidsAndAsks(orderbookInfo, [...directOffers, ...reverseOffers]);
|
||||||
|
|
||||||
const orders = _.flatten([orderbook.bids, orderbook.asks]);
|
const orders = _.flatten([orderbook.bids, orderbook.asks]);
|
||||||
@@ -3842,9 +3835,9 @@ describe('RippleAPI', function () {
|
|||||||
taker: address
|
taker: address
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
).then((directOfferResults, reverseOfferResults) => {
|
).then(([directOfferResults, reverseOfferResults]) => {
|
||||||
const directOffers = (directOfferResults ? directOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
|
const directOffers = (directOfferResults ? directOfferResults.offers : []).reduce((acc, res) => acc.concat(res), [])
|
||||||
const reverseOffers = (reverseOfferResults ? reverseOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
|
const reverseOffers = (reverseOfferResults ? reverseOfferResults.offers : []).reduce((acc, res) => acc.concat(res), [])
|
||||||
const orderbook = RippleAPI.formatBidsAndAsks(orderbookInfo, [...directOffers, ...reverseOffers]);
|
const orderbook = RippleAPI.formatBidsAndAsks(orderbookInfo, [...directOffers, ...reverseOffers]);
|
||||||
|
|
||||||
assert(
|
assert(
|
||||||
@@ -4549,8 +4542,7 @@ describe('RippleAPI', function () {
|
|||||||
'D9ABF622DA26EEEE48203085D4BC23B0F77DC6F8724AC33D975DA3CA492D2E44'
|
'D9ABF622DA26EEEE48203085D4BC23B0F77DC6F8724AC33D975DA3CA492D2E44'
|
||||||
});
|
});
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
const hash = this.api.computeLedgerHash(ledger);
|
this.api.computeLedgerHash(ledger);
|
||||||
unused(hash);
|
|
||||||
}, /does not match computed hash of state/);
|
}, /does not match computed hash of state/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -4577,20 +4569,21 @@ describe('RippleAPI', function () {
|
|||||||
|
|
||||||
it('ledger utils - renameCounterpartyToIssuerInOrder', function () {
|
it('ledger utils - renameCounterpartyToIssuerInOrder', function () {
|
||||||
const order = {
|
const order = {
|
||||||
taker_gets: { counterparty: '1' },
|
taker_gets: { counterparty: '1', currency: 'XRP' },
|
||||||
taker_pays: { counterparty: '1' }
|
taker_pays: { counterparty: '1', currency: 'XRP' }
|
||||||
};
|
};
|
||||||
const expected = {
|
const expected = {
|
||||||
taker_gets: { issuer: '1' },
|
taker_gets: { issuer: '1', currency: 'XRP' },
|
||||||
taker_pays: { issuer: '1' }
|
taker_pays: { issuer: '1', currency: 'XRP' }
|
||||||
};
|
};
|
||||||
assert.deepEqual(utils.renameCounterpartyToIssuerInOrder(order), expected);
|
assert.deepEqual(utils.renameCounterpartyToIssuerInOrder(order), expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ledger utils - compareTransactions', function () {
|
it('ledger utils - compareTransactions', function () {
|
||||||
|
// @ts-ignore
|
||||||
assert.strictEqual(utils.compareTransactions({}, {}), 0);
|
assert.strictEqual(utils.compareTransactions({}, {}), 0);
|
||||||
let first = { outcome: { ledgerVersion: 1, indexInLedger: 100 } };
|
let first: any = { outcome: { ledgerVersion: 1, indexInLedger: 100 } };
|
||||||
let second = { outcome: { ledgerVersion: 1, indexInLedger: 200 } };
|
let second: any = { outcome: { ledgerVersion: 1, indexInLedger: 200 } };
|
||||||
|
|
||||||
assert.strictEqual(utils.compareTransactions(first, second), -1);
|
assert.strictEqual(utils.compareTransactions(first, second), -1);
|
||||||
|
|
||||||
@@ -4606,17 +4599,17 @@ describe('RippleAPI', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ledger utils - getRecursive', function () {
|
it('ledger utils - getRecursive', function () {
|
||||||
function getter(marker, limit) {
|
function getter(marker) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise<RecursiveData>((resolve, reject) => {
|
||||||
if (marker === undefined) {
|
if (marker !== undefined) {
|
||||||
resolve({ marker: 'A', limit: limit, results: [1] });
|
|
||||||
} else {
|
|
||||||
reject(new Error());
|
reject(new Error());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
resolve({ marker: 'A', results: [1] });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return utils.getRecursive(getter, 10).then(() => {
|
return utils.getRecursive(getter, 10).then(() => {
|
||||||
assert(false, 'Should throw Error');
|
assert(false, 'Should th row Error');
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
assert(error instanceof Error);
|
assert(error instanceof Error);
|
||||||
});
|
});
|
||||||
@@ -4754,18 +4747,18 @@ describe('RippleAPI - offline', function () {
|
|||||||
assert.throws(() => api.computeLedgerHash(header));
|
assert.throws(() => api.computeLedgerHash(header));
|
||||||
});
|
});
|
||||||
|
|
||||||
/* eslint-disable no-unused-vars */
|
|
||||||
it('RippleAPI - implicit server port', function () {
|
it('RippleAPI - implicit server port', function () {
|
||||||
const api = new RippleAPI({ server: 'wss://s1.ripple.com' });
|
new RippleAPI({ server: 'wss://s1.ripple.com' });
|
||||||
});
|
});
|
||||||
/* eslint-enable no-unused-vars */
|
|
||||||
it('RippleAPI invalid options', function () {
|
it('RippleAPI invalid options', function () {
|
||||||
assert.throws(() => new RippleAPI({ invalid: true }));
|
assert.throws(() => new RippleAPI({ invalid: true } as any));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('RippleAPI valid options', function () {
|
it('RippleAPI valid options', function () {
|
||||||
const api = new RippleAPI({ server: 'wss://s:1' });
|
const api = new RippleAPI({ server: 'wss://s:1' });
|
||||||
assert.deepEqual(api.connection._url, 'wss://s:1');
|
const privateConnectionUrl = (api.connection as any)._url;
|
||||||
|
assert.deepEqual(privateConnectionUrl, 'wss://s:1');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('RippleAPI invalid server uri', function () {
|
it('RippleAPI invalid server uri', function () {
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
/* eslint-disable max-nested-callbacks */
|
import _ from 'lodash';
|
||||||
'use strict';
|
import assert from 'assert-diff';
|
||||||
const _ = require('lodash');
|
import setupAPI from './setup-api';
|
||||||
const assert = require('assert-diff');
|
import {responses} from './fixtures';
|
||||||
const setupAPI = require('./setup-api');
|
import ledgerClosed from './fixtures/rippled/ledger-close.json';
|
||||||
const responses = require('./fixtures').responses;
|
import {RippleAPI} from 'ripple-api';
|
||||||
const ledgerClosed = require('./fixtures/rippled/ledger-close');
|
|
||||||
const RippleAPI = require('ripple-api').RippleAPI;
|
|
||||||
const schemaValidator = RippleAPI._PRIVATE.schemaValidator;
|
const schemaValidator = RippleAPI._PRIVATE.schemaValidator;
|
||||||
|
|
||||||
const TIMEOUT = 20000;
|
const TIMEOUT = 20000;
|
||||||
@@ -1,19 +1,14 @@
|
|||||||
'use strict'; // eslint-disable-line
|
import _ from 'lodash';
|
||||||
/* eslint-disable max-nested-callbacks */
|
import net from 'net';
|
||||||
|
import assert from 'assert-diff';
|
||||||
const _ = require('lodash');
|
import setupAPI from './setup-api';
|
||||||
const net = require('net');
|
import {RippleAPI} from 'ripple-api';
|
||||||
const assert = require('assert-diff');
|
import ledgerClose from './fixtures/rippled/ledger-close.json';
|
||||||
const setupAPI = require('./setup-api');
|
|
||||||
const RippleAPI = require('ripple-api').RippleAPI;
|
|
||||||
const utils = RippleAPI._PRIVATE.ledgerUtils;
|
const utils = RippleAPI._PRIVATE.ledgerUtils;
|
||||||
const ledgerClose = require('./fixtures/rippled/ledger-close.json');
|
|
||||||
|
|
||||||
|
|
||||||
const TIMEOUT = 200000; // how long before each test case times out
|
const TIMEOUT = 200000; // how long before each test case times out
|
||||||
|
const isBrowser = (process as any).browser;
|
||||||
function unused() {
|
|
||||||
}
|
|
||||||
|
|
||||||
function createServer() {
|
function createServer() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -34,14 +29,14 @@ describe('Connection', function() {
|
|||||||
afterEach(setupAPI.teardown);
|
afterEach(setupAPI.teardown);
|
||||||
|
|
||||||
it('default options', function() {
|
it('default options', function() {
|
||||||
const connection = new utils.common.Connection('url');
|
const connection: any = new utils.common.Connection('url');
|
||||||
assert.strictEqual(connection._url, 'url');
|
assert.strictEqual(connection._url, 'url');
|
||||||
assert(_.isUndefined(connection._proxyURL));
|
assert(_.isUndefined(connection._proxyURL));
|
||||||
assert(_.isUndefined(connection._authorization));
|
assert(_.isUndefined(connection._authorization));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('trace', function() {
|
it('trace', function() {
|
||||||
const connection = new utils.common.Connection('url', {trace: true});
|
const connection: any = new utils.common.Connection('url', {trace: true});
|
||||||
const message1 = '{"type": "transaction"}';
|
const message1 = '{"type": "transaction"}';
|
||||||
const message2 = '{"type": "path_find"}';
|
const message2 = '{"type": "path_find"}';
|
||||||
const messages = [];
|
const messages = [];
|
||||||
@@ -60,11 +55,11 @@ describe('Connection', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('with proxy', function(done) {
|
it('with proxy', function(done) {
|
||||||
if (process.browser) {
|
if (isBrowser) {
|
||||||
done();
|
done();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
createServer().then(server => {
|
createServer().then((server: any) => {
|
||||||
const port = server.address().port;
|
const port = server.address().port;
|
||||||
const expect = 'CONNECT localhost';
|
const expect = 'CONNECT localhost';
|
||||||
server.on('connection', socket => {
|
server.on('connection', socket => {
|
||||||
@@ -110,7 +105,7 @@ describe('Connection', function() {
|
|||||||
it('should throw NotConnectedError if server not responding ', function(
|
it('should throw NotConnectedError if server not responding ', function(
|
||||||
done
|
done
|
||||||
) {
|
) {
|
||||||
if (process.browser) {
|
if (isBrowser) {
|
||||||
const phantomTest = /PhantomJS/;
|
const phantomTest = /PhantomJS/;
|
||||||
if (phantomTest.test(navigator.userAgent)) {
|
if (phantomTest.test(navigator.userAgent)) {
|
||||||
// inside PhantomJS this one just hangs, so skip as not very relevant
|
// inside PhantomJS this one just hangs, so skip as not very relevant
|
||||||
@@ -155,7 +150,6 @@ describe('Connection', function() {
|
|||||||
|
|
||||||
it('DisconnectedError on send', function() {
|
it('DisconnectedError on send', function() {
|
||||||
this.api.connection._ws.send = function(message, options, callback) {
|
this.api.connection._ws.send = function(message, options, callback) {
|
||||||
unused(message, options);
|
|
||||||
callback({message: 'not connected'});
|
callback({message: 'not connected'});
|
||||||
};
|
};
|
||||||
return this.api.getServerInfo().then(() => {
|
return this.api.getServerInfo().then(() => {
|
||||||
@@ -216,7 +210,7 @@ describe('Connection', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reconnect on several unexpected close', function(done) {
|
it('reconnect on several unexpected close', function(done) {
|
||||||
if (process.browser) {
|
if (isBrowser) {
|
||||||
const phantomTest = /PhantomJS/;
|
const phantomTest = /PhantomJS/;
|
||||||
if (phantomTest.test(navigator.userAgent)) {
|
if (phantomTest.test(navigator.userAgent)) {
|
||||||
// inside PhantomJS this one just hangs, so skip as not very relevant
|
// inside PhantomJS this one just hangs, so skip as not very relevant
|
||||||
@@ -316,21 +310,17 @@ describe('Connection', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Cannot connect because no server', function() {
|
it('Cannot connect because no server', function() {
|
||||||
const connection = new utils.common.Connection();
|
const connection = new utils.common.Connection(undefined as string);
|
||||||
return connection.connect().then(() => {
|
return connection.connect().then(() => {
|
||||||
assert(false, 'Should throw ConnectionError');
|
assert(false, 'Should throw ConnectionError');
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
assert(error instanceof this.api.errors.ConnectionError);
|
assert(error instanceof this.api.errors.ConnectionError, 'Should throw ConnectionError');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('connect multiserver error', function() {
|
it('connect multiserver error', function() {
|
||||||
const options = {
|
|
||||||
servers: ['wss://server1.com', 'wss://server2.com']
|
|
||||||
};
|
|
||||||
assert.throws(function() {
|
assert.throws(function() {
|
||||||
const api = new RippleAPI(options);
|
new RippleAPI({servers: ['wss://server1.com', 'wss://server2.com']} as any);
|
||||||
unused(api);
|
|
||||||
}, this.api.errors.RippleError);
|
}, this.api.errors.RippleError);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1,19 +1,15 @@
|
|||||||
/* eslint-disable max-len, valid-jsdoc */
|
import assert from 'assert';
|
||||||
'use strict';
|
import fs from 'fs';
|
||||||
|
import * as hashes from '../src/common/hashes';
|
||||||
var assert = require('assert');
|
|
||||||
var fs = require('fs');
|
|
||||||
var hashes = require('../src/common/hashes');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ledgerIndex {Number}
|
|
||||||
* Expects a corresponding ledger dump in $repo/test/fixtures/rippled folder
|
* Expects a corresponding ledger dump in $repo/test/fixtures/rippled folder
|
||||||
*/
|
*/
|
||||||
function createLedgerTest(ledgerIndex) {
|
function createLedgerTest(ledgerIndex: number) {
|
||||||
describe(String(ledgerIndex), function() {
|
describe(String(ledgerIndex), function() {
|
||||||
var path = __dirname + '/fixtures/rippled/ledger-full-' + ledgerIndex + '.json';
|
var path = __dirname + '/fixtures/rippled/ledger-full-' + ledgerIndex + '.json';
|
||||||
|
|
||||||
var ledgerRaw = fs.readFileSync(path);
|
var ledgerRaw = fs.readFileSync(path, {encoding: 'utf8'});
|
||||||
var ledgerJSON = JSON.parse(ledgerRaw);
|
var ledgerJSON = JSON.parse(ledgerRaw);
|
||||||
|
|
||||||
var hasAccounts = Array.isArray(ledgerJSON.accountState)
|
var hasAccounts = Array.isArray(ledgerJSON.accountState)
|
||||||
@@ -22,12 +18,12 @@ function createLedgerTest(ledgerIndex) {
|
|||||||
if (hasAccounts) {
|
if (hasAccounts) {
|
||||||
it('has account_hash of ' + ledgerJSON.account_hash, function() {
|
it('has account_hash of ' + ledgerJSON.account_hash, function() {
|
||||||
assert.equal(ledgerJSON.account_hash,
|
assert.equal(ledgerJSON.account_hash,
|
||||||
hashes.computeStateTreeHash(ledgerJSON.accountState, 1));
|
hashes.computeStateTreeHash(ledgerJSON.accountState));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
it('has transaction_hash of ' + ledgerJSON.transaction_hash, function() {
|
it('has transaction_hash of ' + ledgerJSON.transaction_hash, function() {
|
||||||
assert.equal(ledgerJSON.transaction_hash,
|
assert.equal(ledgerJSON.transaction_hash,
|
||||||
hashes.computeTransactionTreeHash(ledgerJSON.transactions, 1));
|
hashes.computeTransactionTreeHash(ledgerJSON.transactions));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,3 +3,4 @@
|
|||||||
--slow 500
|
--slow 500
|
||||||
--require ts-node/register
|
--require ts-node/register
|
||||||
--require source-map-support/register
|
--require source-map-support/register
|
||||||
|
./test/*.{ts,js}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
import assert from 'assert';
|
||||||
const assert = require('assert');
|
import {RippleAPI} from 'ripple-api';
|
||||||
const RangeSet = require('ripple-api').RippleAPI._PRIVATE.RangeSet;
|
const RangeSet = RippleAPI._PRIVATE.RangeSet;
|
||||||
|
|
||||||
describe('RangeSet', function() {
|
describe('RangeSet', function() {
|
||||||
it('addRange()/addValue()', function() {
|
it('addRange()/addValue()', function() {
|
||||||
@@ -1,19 +1,14 @@
|
|||||||
/* eslint-disable max-len, valid-jsdoc */
|
import assert from 'assert';
|
||||||
'use strict';
|
import {SHAMap, NodeType} from '../src/common/hashes/shamap';
|
||||||
|
const TYPE_TRANSACTION_NO_METADATA = NodeType.TRANSACTION_NO_METADATA
|
||||||
var assert = require('assert');
|
|
||||||
var SHAMap = require('../src/common/hashes/shamap').SHAMap;
|
|
||||||
var TYPE_TRANSACTION_NO_METADATA = require('../src/common/hashes/shamap').NodeType.TRANSACTION_NO_METADATA
|
|
||||||
|
|
||||||
var HEX_ZERO = '00000000000000000000000000000000' +
|
var HEX_ZERO = '00000000000000000000000000000000' +
|
||||||
'00000000000000000000000000000000';
|
'00000000000000000000000000000000';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates data to hash for testing
|
* Generates data to hash for testing
|
||||||
* @param {number} v int value
|
|
||||||
* @returns {string} 64 length hex string
|
|
||||||
*/
|
*/
|
||||||
function intToVuc(v) {
|
function intToVuc(v: number): string {
|
||||||
var ret = '';
|
var ret = '';
|
||||||
|
|
||||||
for (var i = 0; i < 32; i++) {
|
for (var i = 0; i < 32; i++) {
|
||||||
@@ -23,12 +18,7 @@ function intToVuc(v) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function fillShamapTest(shamap: any, keys: string[], hashes: string[]) {
|
||||||
* @param shamap {Object}
|
|
||||||
* @param keys {Array}
|
|
||||||
* @param hashes {Array}
|
|
||||||
*/
|
|
||||||
function fillShamapTest(shamap, keys, hashes) {
|
|
||||||
for (var i = 0; i < keys.length; i++) {
|
for (var i = 0; i < keys.length; i++) {
|
||||||
var data = intToVuc(i);
|
var data = intToVuc(i);
|
||||||
shamap.addItem(keys[i].toUpperCase(), data, TYPE_TRANSACTION_NO_METADATA);
|
shamap.addItem(keys[i].toUpperCase(), data, TYPE_TRANSACTION_NO_METADATA);
|
||||||
6
test/tsconfig.json
Normal file
6
test/tsconfig.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"extends": "../tsconfig-base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"noEmit": true,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,10 +13,12 @@
|
|||||||
"strictNullChecks": false,
|
"strictNullChecks": false,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"noUnusedParameters": true,
|
|
||||||
"removeComments": true,
|
"removeComments": true,
|
||||||
"preserveConstEnums": false,
|
"preserveConstEnums": false,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"suppressImplicitAnyIndexErrors": false
|
"suppressImplicitAnyIndexErrors": false,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"preserveSymlinks": true
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,6 +111,11 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.144.tgz#12e57fc99064bce45e5ab3c8bc4783feb75eab8e"
|
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.144.tgz#12e57fc99064bce45e5ab3c8bc4783feb75eab8e"
|
||||||
integrity sha512-ogI4g9W5qIQQUhXAclq6zhqgqNUr7UlFaqDHbch7WLSLeeM/7d3CRaw7GLajxvyFvhJqw4Rpcz5bhoaYtIx6Tg==
|
integrity sha512-ogI4g9W5qIQQUhXAclq6zhqgqNUr7UlFaqDHbch7WLSLeeM/7d3CRaw7GLajxvyFvhJqw4Rpcz5bhoaYtIx6Tg==
|
||||||
|
|
||||||
|
"@types/mocha@^5.2.7":
|
||||||
|
version "5.2.7"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.7.tgz#315d570ccb56c53452ff8638738df60726d5b6ea"
|
||||||
|
integrity sha512-NYrtPht0wGzhwe9+/idPaBB+TqkY9AhTvOLMkThm0IoEfLaiVQZwBwyJ5puCkO3AUCWrmcoePjp2mbFocKy4SQ==
|
||||||
|
|
||||||
"@types/node@*":
|
"@types/node@*":
|
||||||
version "12.7.12"
|
version "12.7.12"
|
||||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.12.tgz#7c6c571cc2f3f3ac4a59a5f2bd48f5bdbc8653cc"
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.12.tgz#7c6c571cc2f3f3ac4a59a5f2bd48f5bdbc8653cc"
|
||||||
|
|||||||
Reference in New Issue
Block a user