mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +00:00
Merge pull request #612 from clark800/delete-core
BREAKING CHANGE: Remove dependency of src/api on src/core, removes multiserver support
This commit is contained in:
@@ -4,12 +4,6 @@ const _ = require('lodash');
|
||||
const assert = require('assert');
|
||||
const Account = require('ripple-lib').Account;
|
||||
|
||||
const addresses = require('./fixtures/addresses');
|
||||
const fixtures = require('./fixtures/api');
|
||||
const accountLinesResponse = require('./fixtures/api/rippled/account-lines');
|
||||
|
||||
const setupAPI = require('./setup-api');
|
||||
|
||||
|
||||
function createRemote(remoteOptions = {}) {
|
||||
return {
|
||||
@@ -58,150 +52,6 @@ function createRemote(remoteOptions = {}) {
|
||||
|
||||
describe('Account', function() {
|
||||
|
||||
describe('mocked', function() {
|
||||
beforeEach(setupAPI.setup);
|
||||
afterEach(setupAPI.teardown);
|
||||
|
||||
// this test is artificial, just to increase coverage
|
||||
// because code inside listenerRemoved function in Account object
|
||||
// will never be called in normal situation
|
||||
// (Account object is subscribed to own events, so _subs counter never
|
||||
// reach zero)
|
||||
it('unsubscribe ', function(done) {
|
||||
const account = new Account(this.api.remote, addresses.ACCOUNT);
|
||||
this.mockRippled.expect({
|
||||
request_subscribe: 1,
|
||||
request_unsubscribe: 1,
|
||||
request_account_info: 1
|
||||
});
|
||||
function dumb() {}
|
||||
account.on('entry', dumb);
|
||||
account._subs -= 1;
|
||||
account.removeListener('entry', dumb);
|
||||
setTimeout(() => {
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('toJson', function() {
|
||||
const account = new Account(this.api.remote, addresses.ACCOUNT);
|
||||
const json = account.toJson();
|
||||
assert.strictEqual(json, addresses.ACCOUNT);
|
||||
});
|
||||
|
||||
it('entry', function(done) {
|
||||
const account = new Account(this.api.remote, addresses.ACCOUNT);
|
||||
account.entry((error, info) => {
|
||||
assert.deepEqual(info, fixtures.rippled.account_info.normal.result);
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
|
||||
it('entry error', function(done) {
|
||||
const account = new Account(this.api.remote, addresses.NOTFOUND);
|
||||
account.entry((error) => {
|
||||
assert(error);
|
||||
error.remote.id = 0;
|
||||
assert.deepEqual(error.remote, fixtures.rippled.account_info.notfound);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('getNextSequence not found', function(done) {
|
||||
const account = new Account(this.api.remote, addresses.NOTFOUND);
|
||||
account.getNextSequence((error, sequence) => {
|
||||
assert.strictEqual(sequence, 1);
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
|
||||
it('lines', function(done) {
|
||||
const account = new Account(this.api.remote, addresses.ACCOUNT);
|
||||
account.lines((error, lines) => {
|
||||
assert(lines);
|
||||
const expected = JSON.parse(accountLinesResponse.normal({}))
|
||||
.result.lines;
|
||||
assert.deepEqual(lines.lines, expected);
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
|
||||
it('line', function(done) {
|
||||
const account = new Account(this.api.remote, addresses.ACCOUNT);
|
||||
account.line('015841551A748AD2C1F76FF6ECB0CCCD00000000',
|
||||
'rs9M85karFkCRjvc6KMWn8Coigm9cbcgcx', (error, line) => {
|
||||
const expected = JSON.parse(accountLinesResponse.normal({}))
|
||||
.result.lines[22];
|
||||
assert.deepEqual(line, expected);
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
|
||||
it('line when account not found', function(done) {
|
||||
const account = new Account(this.api.remote, addresses.NOTFOUND);
|
||||
account.line('', 'rs9M85karFkCRjvc6KMWn8Coigm9cbcgcx', (error) => {
|
||||
assert(error);
|
||||
error.remote.id = 0;
|
||||
assert.deepEqual(error.remote, fixtures.rippled.account_info.notfound);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('submit ', function(done) {
|
||||
const account = new Account(this.api.remote, addresses.ACCOUNT);
|
||||
account._transactionManager.submit = function() {
|
||||
done();
|
||||
};
|
||||
account.submit({});
|
||||
});
|
||||
|
||||
// this one just for coverage - _subs can't be zero
|
||||
it('notify - no subscribers ', function(done) {
|
||||
const account = new Account(this.api.remote, addresses.ACCOUNT);
|
||||
let fired = false;
|
||||
account.on('transaction', function() {
|
||||
fired = true;
|
||||
});
|
||||
account._subs = 0;
|
||||
account.notify({});
|
||||
|
||||
setTimeout(() => {
|
||||
assert(!fired);
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('notify - transaction without account field ', function(done) {
|
||||
const account = new Account(this.api.remote, addresses.ACCOUNT);
|
||||
let transactionFired;
|
||||
let transactionInboundFired = false;
|
||||
account.on('transaction', function(transaction) {
|
||||
transactionFired = transaction;
|
||||
});
|
||||
account.on('transaction-inbound', function() {
|
||||
transactionInboundFired = true;
|
||||
});
|
||||
account.notify({transaction: {}});
|
||||
|
||||
setTimeout(() => {
|
||||
assert.deepEqual(transactionFired, {transaction: {}});
|
||||
assert(!transactionInboundFired);
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('notify - transaction-inbound', function(done) {
|
||||
const account = new Account(this.api.remote, addresses.ACCOUNT);
|
||||
account.on('transaction-inbound', function(transaction) {
|
||||
assert.deepEqual(transaction,
|
||||
{transaction: {Account: addresses.NOTFOUND}});
|
||||
done();
|
||||
});
|
||||
account.notify({transaction: {Account: addresses.NOTFOUND}});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#_publicKeyToAddress()', function() {
|
||||
|
||||
it('should throw an error if the key is invalid', function() {
|
||||
@@ -249,35 +99,34 @@ describe('Account', function() {
|
||||
it('should respond true if the public key corresponds to the account ' +
|
||||
' address and the master key IS NOT disabled', function(done) {
|
||||
|
||||
const options = {Flags: 65536};
|
||||
const account = new Account(createRemote(options),
|
||||
'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz');
|
||||
account.publicKeyIsActive(
|
||||
'025B32A54BFA33FB781581F49B235C0E2820C929FF41E677ADA5D3E53CFBA46332',
|
||||
function(err, is_valid) {
|
||||
const options = {Flags: 65536};
|
||||
const account = new Account(createRemote(options),
|
||||
'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz');
|
||||
account.publicKeyIsActive(
|
||||
'025B32A54BFA33FB781581F49B235C0E2820C929FF41E677ADA5D3E53CFBA46332',
|
||||
function(err, is_valid) {
|
||||
|
||||
assert(err === null);
|
||||
assert(is_valid === true);
|
||||
done();
|
||||
});
|
||||
assert(err === null);
|
||||
assert(is_valid === true);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('should respond false if the public key corresponds to the account ' +
|
||||
' address and the master key IS disabled', function(done) {
|
||||
|
||||
const account = new Account(createRemote(),
|
||||
'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz');
|
||||
account.publicKeyIsActive(
|
||||
'025B32A54BFA33FB781581F49B235C0E2820C929FF41E677ADA5D3E53CFBA46332',
|
||||
function(err, is_valid) {
|
||||
const account = new Account(createRemote(),
|
||||
'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz');
|
||||
account.publicKeyIsActive(
|
||||
'025B32A54BFA33FB781581F49B235C0E2820C929FF41E677ADA5D3E53CFBA46332',
|
||||
function(err, is_valid) {
|
||||
assert(err === null);
|
||||
assert(is_valid === false);
|
||||
done();
|
||||
});
|
||||
|
||||
assert(err === null);
|
||||
assert(is_valid === false);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('should respond true if the public key corresponds to the regular key',
|
||||
function(done) {
|
||||
@@ -299,17 +148,17 @@ describe('Account', function() {
|
||||
it('should respond false if the public key does not correspond to an ' +
|
||||
' active public key for the account', function(done) {
|
||||
|
||||
const account = new Account(createRemote(),
|
||||
'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz');
|
||||
account.publicKeyIsActive(
|
||||
'032ECDA93970BC7E8872EF6582CB52A5557F117244A949EB4FA8AC7688CF24FBC8',
|
||||
function(err, is_valid) {
|
||||
assert(err === null);
|
||||
assert(is_valid === false);
|
||||
done();
|
||||
});
|
||||
const account = new Account(createRemote(),
|
||||
'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz');
|
||||
account.publicKeyIsActive(
|
||||
'032ECDA93970BC7E8872EF6582CB52A5557F117244A949EB4FA8AC7688CF24FBC8',
|
||||
function(err, is_valid) {
|
||||
assert(err === null);
|
||||
assert(is_valid === false);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('should respond false if the public key is invalid', function(done) {
|
||||
|
||||
@@ -339,17 +188,17 @@ describe('Account', function() {
|
||||
it('should respond false if the public key does not correspond to an ' +
|
||||
' active public key for the unfunded account', function(done) {
|
||||
|
||||
const account = new Account(createRemote(),
|
||||
'rLdfp6eoR948KVxfn6EpaaNTKwfwXhzSeQ');
|
||||
account.publicKeyIsActive(
|
||||
'032ECDA93970BC7E8872EF6582CB52A5557F117244A949EB4FA8AC7688CF24FBC8',
|
||||
function(err, is_valid) {
|
||||
assert(err === null);
|
||||
assert(is_valid === false);
|
||||
done();
|
||||
});
|
||||
const account = new Account(createRemote(),
|
||||
'rLdfp6eoR948KVxfn6EpaaNTKwfwXhzSeQ');
|
||||
account.publicKeyIsActive(
|
||||
'032ECDA93970BC7E8872EF6582CB52A5557F117244A949EB4FA8AC7688CF24FBC8',
|
||||
function(err, is_valid) {
|
||||
assert(err === null);
|
||||
assert(is_valid === false);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -193,10 +193,9 @@ describe('RippleAPI', function() {
|
||||
|
||||
it('submit - failure', function() {
|
||||
return this.api.submit('BAD').then(() => {
|
||||
assert(false, 'Should throw RippleError');
|
||||
assert(false, 'Should throw RippledError');
|
||||
}).catch(error => {
|
||||
assert(error instanceof this.api.errors.RippleError);
|
||||
assert(error.data);
|
||||
assert(error instanceof this.api.errors.RippledError);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -361,7 +360,7 @@ describe('RippleAPI', function() {
|
||||
it('getTransaction - missing ledger history', function() {
|
||||
const hash = hashes.NOTFOUND_TRANSACTION_HASH;
|
||||
// make gaps in history
|
||||
this.api.remote.getServer().emit('message', ledgerClosed);
|
||||
this.api.connection._ws.emit('message', JSON.stringify(ledgerClosed));
|
||||
return this.api.getTransaction(hash).then(() => {
|
||||
assert(false, 'Should throw MissingLedgerHistoryError');
|
||||
}).catch(error => {
|
||||
@@ -601,8 +600,8 @@ describe('RippleAPI', function() {
|
||||
return this.api.getServerInfo().then(() => {
|
||||
assert(false, 'Should throw NetworkError');
|
||||
}).catch(error => {
|
||||
assert(error instanceof this.api.errors.NetworkError);
|
||||
assert(error.message.indexOf('too much load') !== -1);
|
||||
assert(error instanceof this.api.errors.RippledError);
|
||||
assert(_.includes(error.message, 'slowDown'));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -759,17 +758,20 @@ describe('RippleAPI', function() {
|
||||
assert.deepEqual(utils.renameCounterpartyToIssuer(amountArg), amountArg);
|
||||
});
|
||||
|
||||
it('ledger utils - getRecursive', function(done) {
|
||||
function getter(marker, limit, callback) {
|
||||
if (marker === undefined) {
|
||||
callback(null, {marker: 'A', limit: limit, results: [1]});
|
||||
} else {
|
||||
callback(new Error(), null);
|
||||
}
|
||||
it('ledger utils - getRecursive', function() {
|
||||
function getter(marker, limit) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (marker === undefined) {
|
||||
resolve({marker: 'A', limit: limit, results: [1]});
|
||||
} else {
|
||||
reject(new Error());
|
||||
}
|
||||
});
|
||||
}
|
||||
utils.getRecursive(getter, 10, (error) => {
|
||||
return utils.getRecursive(getter, 10).then(() => {
|
||||
assert(false, 'Should throw Error');
|
||||
}).catch(error => {
|
||||
assert(error instanceof Error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -852,28 +854,6 @@ describe('RippleAPI', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('common utils', function() {
|
||||
|
||||
it('wrapCatch', function(done) {
|
||||
common.wrapCatch(function() {
|
||||
throw new Error('error');
|
||||
})(function(error) {
|
||||
assert(error instanceof Error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('convertExceptions', function() {
|
||||
assert.throws(common.convertExceptions(function() {
|
||||
throw new Error('fall through');
|
||||
}), this.api.errors.ApiError);
|
||||
assert.throws(common.convertExceptions(function() {
|
||||
throw new Error('fall through');
|
||||
}), /fall through/);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('common errors', function() {
|
||||
|
||||
it('TransactionError', function() {
|
||||
@@ -909,7 +889,7 @@ describe('RippleAPI', function() {
|
||||
checkResult(responses.ledgerClosed, 'ledgerClosed', message);
|
||||
done();
|
||||
});
|
||||
this.api.remote.getServer().emit('message', ledgerClosed);
|
||||
this.api.connection._ws.emit('message', JSON.stringify(ledgerClosed));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -965,9 +945,8 @@ describe('RippleAPI - offline', function() {
|
||||
});
|
||||
|
||||
it('RippleAPI valid options', function() {
|
||||
const api = new RippleAPI({trace: true, servers: ['wss://s:1']});
|
||||
assert(api.remote.trace);
|
||||
assert.deepEqual(api.remote.servers, ['wss://s:1']);
|
||||
const api = new RippleAPI({servers: ['wss://s:1']});
|
||||
assert.deepEqual(api.connection._url, 'wss://s:1');
|
||||
});
|
||||
|
||||
it('RippleAPI invalid server uri', function() {
|
||||
|
||||
@@ -107,8 +107,6 @@ module.exports = function(port) {
|
||||
assert.strictEqual(request.command, 'subscribe');
|
||||
if (request.accounts) {
|
||||
assert(_.indexOf(_.values(addresses), request.accounts[0]) !== -1);
|
||||
} else {
|
||||
assert.deepEqual(request.streams, ['ledger', 'server']);
|
||||
}
|
||||
conn.send(createResponse(request, fixtures.subscribe));
|
||||
});
|
||||
|
||||
@@ -25,8 +25,8 @@ function setupMockRippledConnection(testcase, port, done) {
|
||||
testcase.mockRippled = createMockRippled(port);
|
||||
testcase.api = new RippleAPI({servers: ['ws://localhost:' + port]});
|
||||
testcase.api.connect().then(() => {
|
||||
testcase.api.remote.getServer().once('ledger_closed', () => done());
|
||||
testcase.api.remote.getServer().emit('message', ledgerClosed);
|
||||
testcase.api.once('ledgerClosed', () => done());
|
||||
testcase.api.connection._ws.emit('message', JSON.stringify(ledgerClosed));
|
||||
}).catch(done);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user