Skip to content

Commit

Permalink
test: test ilp packet amount = 0
Browse files Browse the repository at this point in the history
  • Loading branch information
justmoon committed Nov 29, 2017
1 parent 7d3b82d commit 1ba272b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/paymentsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,37 @@ describe('Payments', function () {
})
})

it('uses best rate when ilp packet amount = 0', async function () {
const sendSpy = sinon.spy(this.mockPlugin2, 'sendTransfer')
await this.mockPlugin1.emitAsync('incoming_prepare', {
id: '5857d460-2a46-4545-8311-1539d99e78e8',
direction: 'incoming',
ledger: 'mock.test1.',
amount: '100',
executionCondition: 'ni:///sha-256;I3TZF5S3n0-07JWH0s8ArsxPmVP6s-0d0SqxR6C3Ifk?fpt=preimage-sha-256&cost=6',
expiresAt: (new Date(START_DATE + 1000)).toISOString(),
ilp: packet.serializeIlpPayment({
account: 'mock.test2.bob',
amount: '0'
}).toString('base64')
})

sinon.assert.calledOnce(sendSpy)
sinon.assert.calledWithMatch(sendSpy, {
direction: 'outgoing',
ledger: 'mock.test2.',
to: 'mock.test2.bob',
amount: '94',
executionCondition: 'ni:///sha-256;I3TZF5S3n0-07JWH0s8ArsxPmVP6s-0d0SqxR6C3Ifk?fpt=preimage-sha-256&cost=6',
expiresAt: (new Date(START_DATE)).toISOString(),
noteToSelf: {
source_transfer_id: '5857d460-2a46-4545-8311-1539d99e78e8',
source_transfer_ledger: 'mock.test1.',
source_transfer_amount: '100'
}
})
})

it('supports optimistic mode', async function () {
const sendSpy = sinon.spy(this.mockPlugin2, 'sendTransfer')
await this.mockPlugin1.emitAsync('incoming_transfer', {
Expand Down
17 changes: 17 additions & 0 deletions test/routeBuilderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,23 @@ describe('RouteBuilder', function () {
assert.deepEqual(destinationTransfer.ilp, ilpPacket)
})

it('uses best rate when ilp packet amount = 0', async function () {
const ilpPacket = packet.serializeIlpPayment({
account: bobB,
amount: '0'
}).toString('base64')
const destinationTransfer = await this.builder.getDestinationTransfer({
id: 'fd7ecefd-8eb8-4e16-b7c8-b67d9d6995f5',
ledger: ledgerA,
direction: 'incoming',
account: aliceA,
amount: '100',
ilp: ilpPacket
})
assert.deepEqual(destinationTransfer.amount, '50')
assert.deepEqual(destinationTransfer.to, 'eur-ledger.bob')
})

it('throws "Insufficient Source Amount" when the amount is too low', async function () {
const ilpPacket = packet.serializeIlpPayment({
account: bobB,
Expand Down

0 comments on commit 1ba272b

Please sign in to comment.