-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from interledger/feature/dj-path-from-source
[FEATURE] Support pathfinding by source amount
- Loading branch information
Showing
6 changed files
with
263 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"quoteArgs23": { | ||
"source_ledger": "http://ledger2.example", | ||
"destination_ledger": "http://ledger3.example", | ||
"destination_account": "http://ledger3.example/accounts/bob", | ||
"destination_amount": "100", | ||
"destination_expiry_duration": 1 | ||
}, | ||
|
||
"quoteArgs12": { | ||
"source_ledger": "http://ledger1.example", | ||
"destination_ledger": "http://ledger2.example", | ||
"destination_account": "http://ledger2.example/accounts/trader23", | ||
"destination_amount": "90", | ||
"destination_expiry_duration": 2 | ||
}, | ||
|
||
"quote23": { | ||
"source_transfers": [{ | ||
"debits": [{"amount": "100"}], | ||
"credits": [{ | ||
"account": "http://ledger2.example/accounts/trader23", | ||
"amount": "90" | ||
}], | ||
"expiry_duration": 2 | ||
}] | ||
}, | ||
|
||
"quote12": { | ||
"source_transfers": [{ | ||
"debits": [{"amount": "90"}], | ||
"credits": [{ | ||
"account": "http://ledger1.example/accounts/trader12", | ||
"amount": "80" | ||
}], | ||
"expiry_duration": 3 | ||
}] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"quoteArgs12": { | ||
"source_ledger": "http://ledger1.example", | ||
"destination_ledger": "http://ledger2.example", | ||
"source_account": "http://ledger1.example/accounts/alice", | ||
"source_amount": "80", | ||
"source_expiry_duration": 3 | ||
}, | ||
|
||
"quoteArgs23": { | ||
"source_ledger": "http://ledger2.example", | ||
"destination_ledger": "http://ledger3.example", | ||
"source_account": "http://ledger2.example/accounts/trader12", | ||
"source_amount": "90", | ||
"source_expiry_duration": 2 | ||
}, | ||
|
||
"quote12": { | ||
"destination_transfers": [{ | ||
"debits": [{ | ||
"account": "http://ledger2.example/accounts/trader12", | ||
"amount": "90" | ||
}], | ||
"credits": [{"amount": "90"}], | ||
"expiry_duration": 2 | ||
}] | ||
}, | ||
|
||
"quote23": { | ||
"destination_transfers": [{ | ||
"debits": [{ | ||
"account": "http://ledger3.example/accounts/trader23", | ||
"amount": "100" | ||
}], | ||
"credits": [{"amount": "90"}], | ||
"expiry_duration": 1 | ||
}] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* eslint-env node, mocha */ | ||
'use strict' | ||
|
||
const assert = require('assert') | ||
const EventEmitter = require('events').EventEmitter | ||
const inherits = require('util').inherits | ||
const nock = require('nock') | ||
const QuotingClient = require('../src/quoting-client').QuotingClient | ||
|
||
function FakeCrawler () { } | ||
inherits(FakeCrawler, EventEmitter) | ||
|
||
const pairs = { | ||
'http://ledger1.example;http://ledger2.example': 'http://trader12.example', | ||
'http://ledger2.example;http://ledger3.example': 'http://trader23.example' | ||
} | ||
|
||
// (alice -> trader12) -> (trader12 -> trader23) -> (trader23 -> bob) | ||
const path = [ | ||
'http://ledger1.example', | ||
'http://ledger2.example', | ||
'http://ledger3.example' | ||
] | ||
|
||
beforeEach(function () { | ||
this.client = new QuotingClient(new FakeCrawler()) | ||
this.client.pairs = pairs | ||
}) | ||
|
||
describe('QuotingClient#quotePathFromDestination', function () { | ||
const fixtures = require('./fixtures/from-destination') | ||
const quoteArgs12 = fixtures.quoteArgs12 | ||
const quoteArgs23 = fixtures.quoteArgs23 | ||
const quote12 = fixtures.quote12 | ||
const quote23 = fixtures.quote23 | ||
|
||
it('returns quotes', function * () { | ||
const quote23Nock = nock('http://trader23.example').get('/quote') | ||
.query(quoteArgs23) | ||
.reply(200, quote23) | ||
const quote12Nock = nock('http://trader12.example').get('/quote') | ||
.query(quoteArgs12) | ||
.reply(200, quote12) | ||
|
||
const quotes = yield this.client.quotePathFromDestination({ | ||
destination_account: 'http://ledger3.example/accounts/bob', | ||
destination_amount: '100', | ||
destination_expiry_duration: 1 | ||
}, path) | ||
|
||
quote23Nock.done() | ||
quote12Nock.done() | ||
|
||
assert.equal(quotes.length, 2) | ||
assert.equal(quotes[0].id.indexOf('http://trader12.example/payments/'), 0) | ||
assert.equal(quotes[1].id.indexOf('http://trader23.example/payments/'), 0) | ||
assert.equal(quotes[0].source_transfers[0].expiry_duration, 3) | ||
assert.equal(quotes[1].source_transfers[0].expiry_duration, 2) | ||
}) | ||
|
||
it('throws on 400', function * () { | ||
const quote23Nock = nock('http://trader23.example').get('/quote') | ||
.query(quoteArgs23) | ||
.reply(400) | ||
|
||
try { | ||
yield this.client.quotePathFromDestination({ | ||
destination_account: 'http://ledger3.example/accounts/bob', | ||
destination_amount: '100', | ||
destination_expiry_duration: 1 | ||
}, path) | ||
} catch (err) { | ||
quote23Nock.done() | ||
return | ||
} | ||
assert(false) | ||
}) | ||
}) | ||
|
||
describe('QuotingClient#quotePathFromSource', function () { | ||
const fixtures = require('./fixtures/from-source') | ||
const quoteArgs12 = fixtures.quoteArgs12 | ||
const quoteArgs23 = fixtures.quoteArgs23 | ||
const quote12 = fixtures.quote12 | ||
const quote23 = fixtures.quote23 | ||
|
||
it('returns quotes', function * () { | ||
const quote12Nock = nock('http://trader12.example').get('/quote') | ||
.query(quoteArgs12) | ||
.reply(200, quote12) | ||
const quote23Nock = nock('http://trader23.example').get('/quote') | ||
.query(quoteArgs23) | ||
.reply(200, quote23) | ||
|
||
const quotes = yield this.client.quotePathFromSource({ | ||
source_account: 'http://ledger1.example/accounts/alice', | ||
source_amount: '80', | ||
source_expiry_duration: 3 | ||
}, path) | ||
|
||
quote23Nock.done() | ||
quote12Nock.done() | ||
|
||
assert.equal(quotes.length, 2) | ||
assert.equal(quotes[0].id.indexOf('http://trader12.example/payments/'), 0) | ||
assert.equal(quotes[1].id.indexOf('http://trader23.example/payments/'), 0) | ||
assert.equal(quotes[0].destination_transfers[0].expiry_duration, 2) | ||
assert.equal(quotes[1].destination_transfers[0].expiry_duration, 1) | ||
}) | ||
}) |