mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 01:08:02 +00:00
cover api/ledger/transactions.js with unit tests
This commit is contained in:
@@ -11,6 +11,8 @@ const hashes = require('./fixtures/hashes');
|
|||||||
const MockPRNG = require('./mock-prng');
|
const MockPRNG = require('./mock-prng');
|
||||||
const sjcl = require('../src').sjcl;
|
const sjcl = require('../src').sjcl;
|
||||||
const address = addresses.ACCOUNT;
|
const address = addresses.ACCOUNT;
|
||||||
|
const RippleError = require('../src/core/rippleerror').RippleError;
|
||||||
|
const utils = require('../src/api/ledger/utils');
|
||||||
const schemaValidate = require('../src/api/common/schema-validator');
|
const schemaValidate = require('../src/api/common/schema-validator');
|
||||||
|
|
||||||
const orderbook = {
|
const orderbook = {
|
||||||
@@ -209,6 +211,83 @@ describe('RippleAPI', function() {
|
|||||||
'getTransactions', done));
|
'getTransactions', done));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getTransactions - earliest first', function(done) {
|
||||||
|
const options = {types: ['payment', 'order'], initiated: true, limit: 2,
|
||||||
|
earliestFirst: true
|
||||||
|
};
|
||||||
|
const expected = _.cloneDeep(responses.getTransactions)
|
||||||
|
.sort(utils.compareTransactions);
|
||||||
|
this.api.getTransactions(address, options,
|
||||||
|
_.partial(checkResult, expected, done));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransactions - earliest first with start option', function(done) {
|
||||||
|
const options = {types: ['payment', 'order'], initiated: true, limit: 2,
|
||||||
|
start: hashes.VALID_TRANSACTION_HASH,
|
||||||
|
earliestFirst: true
|
||||||
|
};
|
||||||
|
this.api.getTransactions(address, options, (error, data) => {
|
||||||
|
assert.strictEqual(data.length, 0);
|
||||||
|
done(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransactions - gap', function(done) {
|
||||||
|
const options = {types: ['payment', 'order'], initiated: true, limit: 2,
|
||||||
|
maxLedgerVersion: 348858000
|
||||||
|
};
|
||||||
|
this.api.getTransactions(address, options, (error) => {
|
||||||
|
assert.ok(error instanceof this.errors.MissingLedgerHistoryError);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransactions - tx not found', function(done) {
|
||||||
|
const options = {types: ['payment', 'order'], initiated: true, limit: 2,
|
||||||
|
start: hashes.NOTFOUND_TRANSACTION_HASH,
|
||||||
|
counterparty: address
|
||||||
|
};
|
||||||
|
this.api.getTransactions(address, options, (error) => {
|
||||||
|
assert.ok(error instanceof RippleError);
|
||||||
|
assert.strictEqual(error.remote.error, 'txnNotFound');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransactions - filters', function(done) {
|
||||||
|
const options = {types: ['payment', 'order'], initiated: true, limit: 10,
|
||||||
|
excludeFailures: true,
|
||||||
|
counterparty: addresses.ISSUER
|
||||||
|
};
|
||||||
|
this.api.getTransactions(address, options, (error, data) => {
|
||||||
|
assert.strictEqual(data.length, 10);
|
||||||
|
assert.ok(_.every(data, t => t.type === 'payment' || t.type === 'order'));
|
||||||
|
assert.ok(_.every(data, t => t.outcome.result === 'tesSUCCESS'));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransactions - filters for incoming', function(done) {
|
||||||
|
const options = {types: ['payment', 'order'], initiated: false, limit: 10,
|
||||||
|
excludeFailures: true,
|
||||||
|
counterparty: addresses.ISSUER
|
||||||
|
};
|
||||||
|
this.api.getTransactions(address, options, (error, data) => {
|
||||||
|
assert.strictEqual(data.length, 10);
|
||||||
|
assert.ok(_.every(data, t => t.type === 'payment' || t.type === 'order'));
|
||||||
|
assert.ok(_.every(data, t => t.outcome.result === 'tesSUCCESS'));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransactions - error', function(done) {
|
||||||
|
const options = {types: ['payment', 'order'], initiated: true, limit: 13};
|
||||||
|
this.api.getTransactions(address, options, (error) => {
|
||||||
|
assert.ok(error instanceof RippleError);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: this doesn't test much, just that it doesn't crash
|
// TODO: this doesn't test much, just that it doesn't crash
|
||||||
it('getTransactions with start option', function(done) {
|
it('getTransactions with start option', function(done) {
|
||||||
const options = {
|
const options = {
|
||||||
|
|||||||
@@ -86,7 +86,7 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"ledgerVersion": 348860,
|
"ledgerVersion": 348859,
|
||||||
"indexInLedger": 0
|
"indexInLedger": 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -177,7 +177,7 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"ledgerVersion": 348860,
|
"ledgerVersion": 348858,
|
||||||
"indexInLedger": 0
|
"indexInLedger": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
test/fixtures/api/rippled/account-tx.js
vendored
32
test/fixtures/api/rippled/account-tx.js
vendored
@@ -4,6 +4,8 @@ const _ = require('lodash');
|
|||||||
const hashes = require('../../hashes');
|
const hashes = require('../../hashes');
|
||||||
const addresses = require('../../addresses');
|
const addresses = require('../../addresses');
|
||||||
const SerializedObject = require('../../../../src/core').SerializedObject;
|
const SerializedObject = require('../../../../src/core').SerializedObject;
|
||||||
|
const AccountSet = require('./tx/account-set.json');
|
||||||
|
const NotFound = require('./tx/not-found.json');
|
||||||
|
|
||||||
module.exports = function(request, options={}) {
|
module.exports = function(request, options={}) {
|
||||||
_.defaults(options, {
|
_.defaults(options, {
|
||||||
@@ -17,7 +19,7 @@ module.exports = function(request, options={}) {
|
|||||||
validated: true
|
validated: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const tx = {
|
let tx = {
|
||||||
Account: addresses.ACCOUNT,
|
Account: addresses.ACCOUNT,
|
||||||
Amount: {
|
Amount: {
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
@@ -52,7 +54,7 @@ module.exports = function(request, options={}) {
|
|||||||
TxnSignature: '304502204EE3E9D1B01D8959B08450FCA9E22025AF503DEF310E34A93863A85CAB3C0BC5022100B61F5B567F77026E8DEED89EED0B7CAF0E6C96C228A2A65216F0DC2D04D52083'
|
TxnSignature: '304502204EE3E9D1B01D8959B08450FCA9E22025AF503DEF310E34A93863A85CAB3C0BC5022100B61F5B567F77026E8DEED89EED0B7CAF0E6C96C228A2A65216F0DC2D04D52083'
|
||||||
};
|
};
|
||||||
|
|
||||||
const meta = {
|
let meta = {
|
||||||
AffectedNodes: [
|
AffectedNodes: [
|
||||||
{
|
{
|
||||||
ModifiedNode: {
|
ModifiedNode: {
|
||||||
@@ -196,15 +198,37 @@ module.exports = function(request, options={}) {
|
|||||||
TransactionResult: 'tesSUCCESS'
|
TransactionResult: 'tesSUCCESS'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let marker = +request.marker || 0;
|
||||||
|
marker += 1;
|
||||||
|
if (marker === 5) {
|
||||||
|
meta.TransactionResult = 'tecINSUFFICIENT_RESERVE';
|
||||||
|
} else if (marker === 6) {
|
||||||
|
tx = _.cloneDeep(AccountSet.result);
|
||||||
|
meta = tx.meta;
|
||||||
|
delete tx.meta;
|
||||||
|
} else if (marker === 7) {
|
||||||
|
tx.Account = addresses.OTHER_ACCOUNT;
|
||||||
|
} else if (marker === 8) {
|
||||||
|
tx.Destination = addresses.THIRD_ACCOUNT;
|
||||||
|
} else if (marker > 25) {
|
||||||
|
marker = undefined;
|
||||||
|
} else if (marker > 15) {
|
||||||
|
tx.Account = addresses.ISSUER;
|
||||||
|
tx.Destination = addresses.ACCOUNT;
|
||||||
|
}
|
||||||
|
if (request.limit === 13) {
|
||||||
|
const res = _.assign({}, NotFound, {id: request.id});
|
||||||
|
return JSON.stringify(res);
|
||||||
|
}
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
id: request.id,
|
id: request.id,
|
||||||
status: 'success',
|
status: 'success',
|
||||||
type: 'response',
|
type: 'response',
|
||||||
result: {
|
result: {
|
||||||
marker: request.marker === undefined ? 'ABC' : undefined,
|
marker: marker === undefined ? undefined : String(marker),
|
||||||
transactions: [
|
transactions: [
|
||||||
{
|
{
|
||||||
ledger_index: 348860,
|
ledger_index: 348860 - +marker,
|
||||||
tx_blob: SerializedObject.from_json(tx).to_hex(),
|
tx_blob: SerializedObject.from_json(tx).to_hex(),
|
||||||
meta: SerializedObject.from_json(meta).to_hex(),
|
meta: SerializedObject.from_json(meta).to_hex(),
|
||||||
validated: options.validated
|
validated: options.validated
|
||||||
|
|||||||
Reference in New Issue
Block a user