Skip to content

Commit 00342c4

Browse files
committed
Merge pull request #446 from darkdarkdragon/develop-RLJS-370-8
Increase tests coverage
2 parents 2e12dc6 + 6ade0f6 commit 00342c4

17 files changed

+366
-26
lines changed

src/api/common/schemas/pathfind.json

+26-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,32 @@
2424
"additionalProperties": false,
2525
"required": ["address"]
2626
},
27-
"destination": {"$ref": "adjustment"}
27+
"destination": {
28+
"type": "object",
29+
"properties": {
30+
"address": {"$ref": "address"},
31+
"amount": {
32+
"type": "object",
33+
"properties": {
34+
"value": {
35+
"description": "The quantity of the currency, denoted as a string to retain floating point precision",
36+
"$ref": "value"
37+
},
38+
"currency": {
39+
"description": "The three-character code or hex string used to denote currencies",
40+
"$ref": "currency"
41+
},
42+
"counterparty": {
43+
"description": "The Ripple account address of the currency's issuer or gateway",
44+
"$ref": "address"
45+
},
46+
"required": ["currency", "value"]
47+
},
48+
"additionalProperties": false
49+
}
50+
},
51+
"required": ["address", "amount"]
52+
}
2853
},
2954
"required": ["source", "destination"],
3055
"additionalProperties": false

test/api-test.js

+59-19
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,29 @@ describe('RippleAPI', function() {
4646
afterEach(setupAPI.teardown);
4747

4848
it('preparePayment', function(done) {
49-
this.api.preparePayment(address, requests.preparePayment, instructions,
49+
const localInstructions = _.defaults({
50+
maxFee: '0.000012'
51+
}, instructions);
52+
this.api.preparePayment(address, requests.preparePayment, localInstructions,
5053
_.partial(checkResult, responses.preparePayment, done));
5154
});
5255

5356
it('preparePayment with all options specified', function(done) {
57+
const localInstructions = {
58+
maxLedgerVersion: this.api.getLedgerVersion() + 100,
59+
fee: '0.000012'
60+
};
5461
this.api.preparePayment(address, requests.preparePaymentAllOptions,
55-
instructions,
62+
localInstructions,
5663
_.partial(checkResult, responses.preparePaymentAllOptions, done));
5764
});
5865

5966
it('preparePayment without counterparty set', function(done) {
67+
const localInstructions = _.defaults({
68+
sequence: 23
69+
}, instructions);
6070
this.api.preparePayment(address, requests.preparePaymentNoCounterparty,
61-
instructions,
71+
localInstructions,
6272
_.partial(checkResult, responses.preparePaymentNoCounterparty, done));
6373
});
6474

@@ -258,7 +268,8 @@ describe('RippleAPI', function() {
258268
it('getOrderbook - direction is correct for bids and asks', function(done) {
259269
this.api.getOrderbook(address, orderbook, {}, (error, data) => {
260270
assert(_.every(data.bids, bid => bid.specification.direction === 'buy'));
261-
assert(_.every(data.asks, ask => ask.specification.direction === 'sell'));
271+
assert(
272+
_.every(data.asks, ask => ask.specification.direction === 'sell'));
262273
done();
263274
});
264275
});
@@ -281,21 +292,50 @@ describe('RippleAPI', function() {
281292
});
282293

283294
it('getPaths', function(done) {
284-
const pathfind = {
285-
source: {
286-
address: address
287-
},
288-
destination: {
289-
address: addresses.OTHER_ACCOUNT,
290-
amount: {
291-
currency: 'USD',
292-
counterparty: addresses.ISSUER,
293-
value: '100'
294-
}
295-
}
296-
};
297-
this.api.getPaths(pathfind,
298-
_.partial(checkResult, responses.getPaths, done));
295+
this.api.getPaths(requests.getPaths.normal,
296+
_.partial(checkResult, responses.getPaths.XrpToUsd, done));
297+
});
298+
299+
// @TODO
300+
// need decide what to do with currencies/XRP:
301+
// if add 'XRP' in currencies, then there will be exception in
302+
// xrpToDrops function (called from toRippledAmount)
303+
it('getPaths USD 2 USD', function(done) {
304+
this.api.getPaths(requests.getPaths.UsdToUsd,
305+
_.partial(checkResult, responses.getPaths.UsdToUsd, done));
306+
});
307+
308+
it('getPaths XRP 2 XRP', function(done) {
309+
this.api.getPaths(requests.getPaths.XrpToXrp,
310+
_.partial(checkResult, responses.getPaths.XrpToXrp, done));
311+
});
312+
313+
it('getPaths - XRP 2 XRP - not enough', function(done) {
314+
this.api.getPaths(requests.getPaths.XrpToXrpNotEnough, (error) => {
315+
assert(error instanceof this.api.errors.NotFoundError);
316+
done();
317+
});
318+
});
319+
320+
it('getPaths - does not accept currency', function(done) {
321+
this.api.getPaths(requests.getPaths.NotAcceptCurrency, (error) => {
322+
assert(error instanceof this.api.errors.NotFoundError);
323+
done();
324+
});
325+
});
326+
327+
it('getPaths - no paths', function(done) {
328+
this.api.getPaths(requests.getPaths.NoPaths, (error) => {
329+
assert(error instanceof this.api.errors.NotFoundError);
330+
done();
331+
});
332+
});
333+
334+
it('getPaths - no paths with source currencies', function(done) {
335+
this.api.getPaths(requests.getPaths.NoPathsWithCurrencies, (error) => {
336+
assert(error instanceof this.api.errors.NotFoundError);
337+
done();
338+
});
299339
});
300340

301341
it('getLedgerVersion', function() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"source": {
3+
"address": "rwBYyfufTzk77zUSKEu4MvixfarC35av1J",
4+
"currencies": [
5+
{
6+
"currency": "USD"
7+
}
8+
]
9+
},
10+
"destination": {
11+
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
12+
"amount": {
13+
"value": "1000002",
14+
"currency": "USD"
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"source": {
3+
"address": "rwBYyfufTzk77zUSKEu4MvixfarC35av1J"
4+
},
5+
"destination": {
6+
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
7+
"amount": {
8+
"value": "1000002",
9+
"currency": "USD"
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"source": {
3+
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59"
4+
},
5+
"destination": {
6+
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
7+
"amount": {
8+
"currency": "USD",
9+
"counterparty": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM",
10+
"value": "100"
11+
}
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"source": {
3+
"address": "rwBYyfufTzk77zUSKEu4MvixfarC35av1J"
4+
},
5+
"destination": {
6+
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
7+
"amount": {
8+
"value": "0.000002",
9+
"currency": "GBP"
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"source": {
3+
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
4+
"currencies": [
5+
{
6+
"currency": "LTC"
7+
},
8+
{
9+
"currency": "USD"
10+
}
11+
]
12+
},
13+
"destination": {
14+
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
15+
"amount": {
16+
"currency": "USD",
17+
"value": "0.000001"
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"source": {
3+
"address": "rwBYyfufTzk77zUSKEu4MvixfarC35av1J"
4+
},
5+
"destination": {
6+
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
7+
"amount": {
8+
"value": "1000002",
9+
"currency": "XRP"
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"source": {
3+
"address": "rwBYyfufTzk77zUSKEu4MvixfarC35av1J"
4+
},
5+
"destination": {
6+
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
7+
"amount": {
8+
"value": "0.000002",
9+
"currency": "XRP"
10+
}
11+
}
12+
}

test/fixtures/api/requests/index.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,14 @@ module.exports = {
88
preparePaymentNoCounterparty: require('./prepare-payment-no-counterparty'),
99
prepareSettings: require('./prepare-settings'),
1010
prepareTrustline: require('./prepare-trustline'),
11-
sign: require('./sign')
11+
sign: require('./sign'),
12+
getPaths: {
13+
normal: require('./getpaths/normal'),
14+
UsdToUsd: require('./getpaths/usd2usd'),
15+
XrpToXrp: require('./getpaths/xrp2xrp'),
16+
XrpToXrpNotEnough: require('./getpaths/xrp2xrp-not-enough'),
17+
NotAcceptCurrency: require('./getpaths/not-accept-currency'),
18+
NoPaths: require('./getpaths/no-paths'),
19+
NoPathsWithCurrencies: require('./getpaths/no-paths-with-currencies')
20+
}
1221
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"source": {
4+
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
5+
"amount": {
6+
"currency": "USD",
7+
"value": "0.000001002",
8+
"counterparty": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo"
9+
}
10+
},
11+
"destination": {
12+
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
13+
"amount": {
14+
"value": "0.000001",
15+
"currency": "USD"
16+
}
17+
},
18+
"paths": "[[{\"account\":\"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B\"}],[{\"account\":\"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B\"},{\"account\":\"rLMJ4db4uwHcd6NHg6jvTaYb8sH5Gy4tg5\"},{\"account\":\"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun\"}],[{\"account\":\"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B\"},{\"currency\":\"USD\",\"issuer\":\"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun\"},{\"account\":\"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun\"}],[{\"account\":\"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B\"},{\"account\":\"rLMJ4db4uwHcd6NHg6jvTaYb8sH5Gy4tg5\"},{\"account\":\"r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X\"}]]"
19+
}
20+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[
2+
{
3+
"source": {
4+
"address": "rwBYyfufTzk77zUSKEu4MvixfarC35av1J",
5+
"amount": {
6+
"currency": "XRP",
7+
"value": "0.000002"
8+
}
9+
},
10+
"destination": {
11+
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
12+
"amount": {
13+
"value": "0.000002",
14+
"currency": "XRP"
15+
}
16+
},
17+
"paths": "[]"
18+
}
19+
]

test/fixtures/api/responses/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ module.exports = {
66
getBalances: require('./get-balances.json'),
77
getOrderbook: require('./get-orderbook.json'),
88
getOrders: require('./get-orders.json'),
9-
getPaths: require('./get-paths.json'),
9+
getPaths: {
10+
XrpToUsd: require('./get-paths.json'),
11+
UsdToUsd: require('./get-paths-send-usd.json'),
12+
XrpToXrp: require('./get-paths-xrp-to-xrp.json')
13+
},
1014
getServerInfo: require('./get-server-info.json'),
1115
getSettings: require('./get-settings.json'),
1216
getTransaction: {

test/fixtures/api/rippled/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ module.exports = {
1313
account_tx: require('./account-tx'),
1414
book_offers: require('./book-offers'),
1515
server_info: require('./server-info'),
16-
ripple_path_find: require('./ripple-path-find'),
16+
ripple_path_find: {
17+
generate: require('./ripple-path-find'),
18+
sendUSD: require('./ripple-path-find-send-usd'),
19+
XrpToXrp: require('./ripple-path-find-xrp-to-xrp')
20+
},
1721
tx: {
1822
Payment: require('./tx/payment.json'),
1923
AccountSet: require('./tx/account-set.json'),

0 commit comments

Comments
 (0)