mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-30 00:55:49 +00:00
Convert getPathFind and add unit test
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
const _ = require('lodash');
|
||||
const assert = require('assert-diff');
|
||||
const setupAPI = require('./setup-api');
|
||||
const address = require('./fixtures/addresses').ACCOUNT;
|
||||
const addresses = require('./fixtures/addresses');
|
||||
const hashes = require('./fixtures/hashes');
|
||||
const paymentSpecification = require('./fixtures/payment-specification');
|
||||
const paymentResponse = require('./fixtures/payment-response');
|
||||
@@ -30,6 +30,8 @@ const getSettingsResponse = require('./fixtures/get-settings-response');
|
||||
const getOrdersResponse = require('./fixtures/get-orders-response');
|
||||
const getOrderBookResponse = require('./fixtures/get-orderbook-response');
|
||||
const getServerInfoResponse = require('./fixtures/get-server-info-response');
|
||||
const getPathFindResponse = require('./fixtures/get-pathfind-response');
|
||||
const address = addresses.ACCOUNT;
|
||||
|
||||
function checkResult(expected, done, error, response) {
|
||||
if (error) {
|
||||
@@ -170,4 +172,22 @@ describe('RippleAPI', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('getPathFind', function(done) {
|
||||
const pathfind = {
|
||||
source: {
|
||||
address: address
|
||||
},
|
||||
destination: {
|
||||
address: addresses.OTHER_ACCOUNT,
|
||||
amount: {
|
||||
currency: 'USD',
|
||||
counterparty: addresses.ISSUER,
|
||||
value: '100'
|
||||
}
|
||||
}
|
||||
};
|
||||
this.api.getPathFind(pathfind,
|
||||
_.partial(checkResult, getPathFindResponse, done));
|
||||
});
|
||||
});
|
||||
|
||||
58
test/fixtures/get-pathfind-response.json
vendored
Normal file
58
test/fixtures/get-pathfind-response.json
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
[
|
||||
{
|
||||
"source": {
|
||||
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
|
||||
"amount": {
|
||||
"currency": "JPY",
|
||||
"value": "0.1117218827811721",
|
||||
"counterparty": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59"
|
||||
}
|
||||
},
|
||||
"destination": {
|
||||
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
|
||||
"amount": {
|
||||
"currency": "USD",
|
||||
"counterparty": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM",
|
||||
"value": "100"
|
||||
}
|
||||
},
|
||||
"paths": "[[{\"account\":\"rMAz5ZnK73nyNUL4foAvaxdreczCkG3vA6\"},{\"currency\":\"USD\",\"issuer\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"},{\"account\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"}],[{\"account\":\"rMAz5ZnK73nyNUL4foAvaxdreczCkG3vA6\"},{\"currency\":\"XRP\"},{\"currency\":\"USD\",\"issuer\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"},{\"account\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"}],[{\"account\":\"rMAz5ZnK73nyNUL4foAvaxdreczCkG3vA6\"},{\"currency\":\"XRP\"},{\"currency\":\"USD\",\"issuer\":\"rpHgehzdpfWRXKvSv6duKvVuo1aZVimdaT\"},{\"account\":\"rpHgehzdpfWRXKvSv6duKvVuo1aZVimdaT\"},{\"account\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"}],[{\"account\":\"rMAz5ZnK73nyNUL4foAvaxdreczCkG3vA6\"},{\"currency\":\"XRP\"},{\"currency\":\"USD\",\"issuer\":\"rHHa9t2kLQyXRbdLkSzEgkzwf9unmFgZs9\"},{\"account\":\"rHHa9t2kLQyXRbdLkSzEgkzwf9unmFgZs9\"},{\"account\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"}]]"
|
||||
},
|
||||
{
|
||||
"source": {
|
||||
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
|
||||
"amount": {
|
||||
"currency": "USD",
|
||||
"value": "0.001002",
|
||||
"counterparty": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59"
|
||||
}
|
||||
},
|
||||
"destination": {
|
||||
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
|
||||
"amount": {
|
||||
"currency": "USD",
|
||||
"counterparty": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM",
|
||||
"value": "100"
|
||||
}
|
||||
},
|
||||
"paths": "[[{\"account\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"}],[{\"account\":\"rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q\"},{\"currency\":\"USD\",\"issuer\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"},{\"account\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"}],[{\"account\":\"rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q\"},{\"currency\":\"XRP\"},{\"currency\":\"USD\",\"issuer\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"},{\"account\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"}],[{\"account\":\"rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q\"},{\"currency\":\"XRP\"},{\"currency\":\"USD\",\"issuer\":\"rpHgehzdpfWRXKvSv6duKvVuo1aZVimdaT\"},{\"account\":\"rpHgehzdpfWRXKvSv6duKvVuo1aZVimdaT\"},{\"account\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"}]]"
|
||||
},
|
||||
{
|
||||
"source": {
|
||||
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
|
||||
"amount": {
|
||||
"currency": "XRP",
|
||||
"value": "0.207669"
|
||||
}
|
||||
},
|
||||
"destination": {
|
||||
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
|
||||
"amount": {
|
||||
"currency": "USD",
|
||||
"counterparty": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM",
|
||||
"value": "100"
|
||||
}
|
||||
},
|
||||
"paths": "[[{\"currency\":\"USD\",\"issuer\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"},{\"account\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"}],[{\"currency\":\"USD\",\"issuer\":\"rsP3mgGb2tcYUrxiLFiHJiQXhsziegtwBc\"},{\"account\":\"rsP3mgGb2tcYUrxiLFiHJiQXhsziegtwBc\"},{\"account\":\"rf9X8QoYnWLHMHuDfjkmRcD2UE5qX5aYV\"},{\"account\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"}],[{\"currency\":\"USD\",\"issuer\":\"rDVdJ62foD1sn7ZpxtXyptdkBSyhsQGviT\"},{\"account\":\"rDVdJ62foD1sn7ZpxtXyptdkBSyhsQGviT\"},{\"account\":\"rfQPFZ3eLcaSUKjUy7A3LAmDNM4F9Hz9j1\"},{\"account\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"}],[{\"currency\":\"USD\",\"issuer\":\"rpHgehzdpfWRXKvSv6duKvVuo1aZVimdaT\"},{\"account\":\"rpHgehzdpfWRXKvSv6duKvVuo1aZVimdaT\"},{\"account\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"}]]"
|
||||
}
|
||||
]
|
||||
410
test/fixtures/paths.js
vendored
Normal file
410
test/fixtures/paths.js
vendored
Normal file
@@ -0,0 +1,410 @@
|
||||
'use strict';
|
||||
|
||||
module.exports.generateIOUPaymentPaths =
|
||||
function(request_id, sendingAccount, destinationAccount, destinationAmount) {
|
||||
return JSON.stringify({
|
||||
'id': request_id,
|
||||
'status': 'success',
|
||||
'type': 'response',
|
||||
'result': {
|
||||
'alternatives': [
|
||||
{
|
||||
'paths_canonical': [],
|
||||
'paths_computed': [
|
||||
[
|
||||
{
|
||||
'account': 'rMAz5ZnK73nyNUL4foAvaxdreczCkG3vA6',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'currency': destinationAmount.currency,
|
||||
'issuer': destinationAmount.issuer,
|
||||
'type': 48,
|
||||
'type_hex': '0000000000000030'
|
||||
},
|
||||
{
|
||||
'account': destinationAmount.issuer,
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'account': 'rMAz5ZnK73nyNUL4foAvaxdreczCkG3vA6',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'currency': 'XRP',
|
||||
'type': 16,
|
||||
'type_hex': '0000000000000010'
|
||||
},
|
||||
{
|
||||
'currency': destinationAmount.currency,
|
||||
'issuer': destinationAmount.issuer,
|
||||
'type': 48,
|
||||
'type_hex': '0000000000000030'
|
||||
},
|
||||
{
|
||||
'account': destinationAmount.issuer,
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'account': 'rMAz5ZnK73nyNUL4foAvaxdreczCkG3vA6',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'currency': 'XRP',
|
||||
'type': 16,
|
||||
'type_hex': '0000000000000010'
|
||||
},
|
||||
{
|
||||
'currency': destinationAmount.currency,
|
||||
'issuer': 'rpHgehzdpfWRXKvSv6duKvVuo1aZVimdaT',
|
||||
'type': 48,
|
||||
'type_hex': '0000000000000030'
|
||||
},
|
||||
{
|
||||
'account': 'rpHgehzdpfWRXKvSv6duKvVuo1aZVimdaT',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'account': destinationAmount.issuer,
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'account': 'rMAz5ZnK73nyNUL4foAvaxdreczCkG3vA6',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'currency': 'XRP',
|
||||
'type': 16,
|
||||
'type_hex': '0000000000000010'
|
||||
},
|
||||
{
|
||||
'currency': destinationAmount.currency,
|
||||
'issuer': 'rHHa9t2kLQyXRbdLkSzEgkzwf9unmFgZs9',
|
||||
'type': 48,
|
||||
'type_hex': '0000000000000030'
|
||||
},
|
||||
{
|
||||
'account': 'rHHa9t2kLQyXRbdLkSzEgkzwf9unmFgZs9',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'account': destinationAmount.issuer,
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
}
|
||||
]
|
||||
],
|
||||
'source_amount': {
|
||||
'currency': 'JPY',
|
||||
'issuer': sendingAccount,
|
||||
'value': '0.1117218827811721'
|
||||
}
|
||||
},
|
||||
{
|
||||
'paths_canonical': [],
|
||||
'paths_computed': [
|
||||
[
|
||||
{
|
||||
'account': destinationAmount.issuer,
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'account': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'currency': destinationAmount.currency,
|
||||
'issuer': destinationAmount.issuer,
|
||||
'type': 48,
|
||||
'type_hex': '0000000000000030'
|
||||
},
|
||||
{
|
||||
'account': destinationAmount.issuer,
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'account': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'currency': 'XRP',
|
||||
'type': 16,
|
||||
'type_hex': '0000000000000010'
|
||||
},
|
||||
{
|
||||
'currency': destinationAmount.currency,
|
||||
'issuer': destinationAmount.issuer,
|
||||
'type': 48,
|
||||
'type_hex': '0000000000000030'
|
||||
},
|
||||
{
|
||||
'account': destinationAmount.issuer,
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'account': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'currency': 'XRP',
|
||||
'type': 16,
|
||||
'type_hex': '0000000000000010'
|
||||
},
|
||||
{
|
||||
'currency': destinationAmount.currency,
|
||||
'issuer': 'rpHgehzdpfWRXKvSv6duKvVuo1aZVimdaT',
|
||||
'type': 48,
|
||||
'type_hex': '0000000000000030'
|
||||
},
|
||||
{
|
||||
'account': 'rpHgehzdpfWRXKvSv6duKvVuo1aZVimdaT',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'account': destinationAmount.issuer,
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
}
|
||||
]
|
||||
],
|
||||
'source_amount': {
|
||||
'currency': 'USD',
|
||||
'issuer': sendingAccount,
|
||||
'value': '0.001002'
|
||||
}
|
||||
},
|
||||
{
|
||||
'paths_canonical': [],
|
||||
'paths_computed': [
|
||||
[
|
||||
{
|
||||
'currency': destinationAmount.currency,
|
||||
'issuer': destinationAmount.issuer,
|
||||
'type': 48,
|
||||
'type_hex': '0000000000000030'
|
||||
},
|
||||
{
|
||||
'account': destinationAmount.issuer,
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'currency': destinationAmount.currency,
|
||||
'issuer': 'rsP3mgGb2tcYUrxiLFiHJiQXhsziegtwBc',
|
||||
'type': 48,
|
||||
'type_hex': '0000000000000030'
|
||||
},
|
||||
{
|
||||
'account': 'rsP3mgGb2tcYUrxiLFiHJiQXhsziegtwBc',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'account': 'rf9X8QoYnWLHMHuDfjkmRcD2UE5qX5aYV',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'account': destinationAmount.issuer,
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'currency': destinationAmount.currency,
|
||||
'issuer': 'rDVdJ62foD1sn7ZpxtXyptdkBSyhsQGviT',
|
||||
'type': 48,
|
||||
'type_hex': '0000000000000030'
|
||||
},
|
||||
{
|
||||
'account': 'rDVdJ62foD1sn7ZpxtXyptdkBSyhsQGviT',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'account': 'rfQPFZ3eLcaSUKjUy7A3LAmDNM4F9Hz9j1',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'account': destinationAmount.issuer,
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'currency': destinationAmount.currency,
|
||||
'issuer': 'rpHgehzdpfWRXKvSv6duKvVuo1aZVimdaT',
|
||||
'type': 48,
|
||||
'type_hex': '0000000000000030'
|
||||
},
|
||||
{
|
||||
'account': 'rpHgehzdpfWRXKvSv6duKvVuo1aZVimdaT',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'account': destinationAmount.issuer,
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
}
|
||||
]
|
||||
],
|
||||
'source_amount': '207669'
|
||||
}
|
||||
],
|
||||
'destination_account': destinationAccount,
|
||||
'destination_currencies': [
|
||||
'USD',
|
||||
'JOE',
|
||||
'BTC',
|
||||
'DYM',
|
||||
'CNY',
|
||||
'EUR',
|
||||
'015841551A748AD2C1F76FF6ECB0CCCD00000000',
|
||||
'MXN',
|
||||
'XRP'
|
||||
]
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.generateXRPPaymentPaths =
|
||||
function(request_id, sendingAccount, destinationAccount) {
|
||||
return JSON.stringify({
|
||||
'id': request_id,
|
||||
'status': 'success',
|
||||
'type': 'response',
|
||||
'result': {
|
||||
'alternatives': [
|
||||
{
|
||||
'paths_canonical': [],
|
||||
'paths_computed': [
|
||||
[
|
||||
{
|
||||
'account': 'rMAz5ZnK73nyNUL4foAvaxdreczCkG3vA6',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'currency': 'XRP',
|
||||
'type': 16,
|
||||
'type_hex': '0000000000000010'
|
||||
}
|
||||
]
|
||||
],
|
||||
'source_amount': {
|
||||
'currency': 'JPY',
|
||||
'issuer': sendingAccount,
|
||||
'value': '0.00005460001'
|
||||
}
|
||||
},
|
||||
{
|
||||
'paths_canonical': [],
|
||||
'paths_computed': [
|
||||
[
|
||||
{
|
||||
'account': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'currency': 'XRP',
|
||||
'type': 16,
|
||||
'type_hex': '0000000000000010'
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'account': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'currency': 'XRP',
|
||||
'type': 16,
|
||||
'type_hex': '0000000000000010'
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'account': destinationAccount,
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'account': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'currency': 'XRP',
|
||||
'type': 16,
|
||||
'type_hex': '0000000000000010'
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'account': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'account': 'r3MeEnYZY9fAd5pGjAWf4dfJsQBVY9FZRL',
|
||||
'type': 1,
|
||||
'type_hex': '0000000000000001'
|
||||
},
|
||||
{
|
||||
'currency': 'XRP',
|
||||
'type': 16,
|
||||
'type_hex': '0000000000000010'
|
||||
}
|
||||
]
|
||||
],
|
||||
'source_amount': {
|
||||
'currency': 'USD',
|
||||
'issuer': sendingAccount,
|
||||
'value': '0.0000005158508428100899'
|
||||
}
|
||||
}
|
||||
],
|
||||
'destination_account': destinationAccount,
|
||||
'destination_currencies': [
|
||||
'USD',
|
||||
'XRP'
|
||||
]
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -8,6 +8,7 @@ const addresses = require('./fixtures/addresses');
|
||||
const hashes = require('./fixtures/hashes');
|
||||
const accountOffersResponse = require('./fixtures/acct-offers-response');
|
||||
const bookOffers = require('./fixtures/book-offers-response');
|
||||
const paths = require('./fixtures/paths');
|
||||
|
||||
function isUSD(json) {
|
||||
return json === 'USD' || json === '0000000000000000000000005553440000000000';
|
||||
@@ -150,5 +151,12 @@ module.exports = function(port) {
|
||||
}
|
||||
});
|
||||
|
||||
mock.on('request_ripple_path_find', function(request, conn) {
|
||||
const response = paths.generateIOUPaymentPaths(request.id,
|
||||
request.source_account, request.destination_account,
|
||||
request.destination_amount);
|
||||
conn.send(response);
|
||||
});
|
||||
|
||||
return mock;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user