mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 20:25:48 +00:00
Add test of getTrustlines with multiple pages of results (#850)
This commit is contained in:
@@ -995,6 +995,12 @@ describe('RippleAPI', function() {
|
|||||||
responses.getTrustlines.filtered, 'getTrustlines'));
|
responses.getTrustlines.filtered, 'getTrustlines'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getTrustlines - more than 400 items', function() {
|
||||||
|
const options = {limit: 401};
|
||||||
|
return this.api.getTrustlines(addresses.THIRD_ACCOUNT, options).then(
|
||||||
|
_.partial(checkResult, responses.getTrustlines.moreThan400Items, 'getTrustlines'));
|
||||||
|
});
|
||||||
|
|
||||||
it('getTrustlines - no options', function() {
|
it('getTrustlines - no options', function() {
|
||||||
return this.api.getTrustlines(address).then(
|
return this.api.getTrustlines(address).then(
|
||||||
_.partial(checkResult, responses.getTrustlines.all, 'getTrustlines'));
|
_.partial(checkResult, responses.getTrustlines.all, 'getTrustlines'));
|
||||||
|
|||||||
8
test/fixtures/responses/index.js
vendored
8
test/fixtures/responses/index.js
vendored
@@ -1,5 +1,9 @@
|
|||||||
'use strict'; // eslint-disable-line strict
|
'use strict'; // eslint-disable-line strict
|
||||||
|
|
||||||
|
function buildList(options) {
|
||||||
|
return new Array(options.count).fill(options.item);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
generateAddress: require('./generate-address.json'),
|
generateAddress: require('./generate-address.json'),
|
||||||
getAccountInfo: require('./get-account-info.json'),
|
getAccountInfo: require('./get-account-info.json'),
|
||||||
@@ -61,6 +65,10 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
getTrustlines: {
|
getTrustlines: {
|
||||||
filtered: require('./get-trustlines.json'),
|
filtered: require('./get-trustlines.json'),
|
||||||
|
moreThan400Items: buildList({
|
||||||
|
item: require('./trustline-item.json'),
|
||||||
|
count: 401
|
||||||
|
}),
|
||||||
all: require('./get-trustlines-all.json')
|
all: require('./get-trustlines-all.json')
|
||||||
},
|
},
|
||||||
getLedger: {
|
getLedger: {
|
||||||
|
|||||||
13
test/fixtures/responses/trustline-item.json
vendored
Normal file
13
test/fixtures/responses/trustline-item.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"specification": {
|
||||||
|
"limit": "0",
|
||||||
|
"currency": "CHF",
|
||||||
|
"counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
|
||||||
|
},
|
||||||
|
"counterparty": {
|
||||||
|
"limit": "0"
|
||||||
|
},
|
||||||
|
"state": {
|
||||||
|
"balance": "0.3488146605801446"
|
||||||
|
}
|
||||||
|
}
|
||||||
49
test/fixtures/rippled/account-lines.js
vendored
49
test/fixtures/rippled/account-lines.js
vendored
@@ -2,6 +2,34 @@
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const BASE_LEDGER_INDEX = 8819951;
|
const BASE_LEDGER_INDEX = 8819951;
|
||||||
|
|
||||||
|
function getMarkerAndLinesFromRequest(request) {
|
||||||
|
const itemCount = 401; // Items on the ledger
|
||||||
|
const perRequestLimit = 400;
|
||||||
|
const pageCount = Math.ceil(itemCount / perRequestLimit);
|
||||||
|
|
||||||
|
// marker is the index of the next item to return
|
||||||
|
const startIndex = request.marker ? Number(request.marker) : 0;
|
||||||
|
|
||||||
|
// No minimum: there are only a certain number of results on the ledger.
|
||||||
|
// Maximum: the lowest of (perRequestLimit, itemCount - startIndex, request.limit).
|
||||||
|
const lineCount = Math.min(perRequestLimit, itemCount - startIndex, request.limit);
|
||||||
|
|
||||||
|
const trustline = {
|
||||||
|
account: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
|
||||||
|
balance: '0.3488146605801446',
|
||||||
|
currency: 'CHF',
|
||||||
|
limit: '0',
|
||||||
|
limit_peer: '0',
|
||||||
|
quality_in: 0,
|
||||||
|
quality_out: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
marker: itemCount - lineCount > 0 ? startIndex + lineCount : undefined,
|
||||||
|
lines: new Array(lineCount).fill(trustline)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.normal = function(request, options = {}) {
|
module.exports.normal = function(request, options = {}) {
|
||||||
_.defaults(options, {
|
_.defaults(options, {
|
||||||
ledger: BASE_LEDGER_INDEX
|
ledger: BASE_LEDGER_INDEX
|
||||||
@@ -321,3 +349,24 @@ module.exports.counterparty = function(request, options = {}) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.manyItems = function(request, options = {}) {
|
||||||
|
_.defaults(options, {
|
||||||
|
ledger: BASE_LEDGER_INDEX
|
||||||
|
});
|
||||||
|
|
||||||
|
const {marker, lines} = getMarkerAndLinesFromRequest(request);
|
||||||
|
|
||||||
|
return JSON.stringify({
|
||||||
|
id: request.id,
|
||||||
|
status: 'success',
|
||||||
|
type: 'response',
|
||||||
|
result: {
|
||||||
|
account: request.account,
|
||||||
|
marker,
|
||||||
|
limit: request.limit,
|
||||||
|
ledger_index: options.ledger,
|
||||||
|
lines
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -348,6 +348,8 @@ module.exports = function createMockRippled(port) {
|
|||||||
conn.send(accountLinesResponse.normal(request));
|
conn.send(accountLinesResponse.normal(request));
|
||||||
} else if (request.account === addresses.OTHER_ACCOUNT) {
|
} else if (request.account === addresses.OTHER_ACCOUNT) {
|
||||||
conn.send(accountLinesResponse.counterparty(request));
|
conn.send(accountLinesResponse.counterparty(request));
|
||||||
|
} else if (request.account === addresses.THIRD_ACCOUNT) {
|
||||||
|
conn.send(accountLinesResponse.manyItems(request));
|
||||||
} else if (request.account === addresses.NOTFOUND) {
|
} else if (request.account === addresses.NOTFOUND) {
|
||||||
conn.send(createResponse(request, fixtures.account_info.notfound));
|
conn.send(createResponse(request, fixtures.account_info.notfound));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user