mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
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() {
|
||||
|
||||
Reference in New Issue
Block a user