Skip to content

Commit

Permalink
Exclude SendMax from XRP to XRP payments (#957)
Browse files Browse the repository at this point in the history
Fix #954
  • Loading branch information
intelliot authored Oct 16, 2018
1 parent 6474501 commit f4ad04d
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/transaction/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function isXRPToXRPPayment(payment: Payment): boolean {
? source.maxAmount.currency : source.amount.currency
const destinationCurrency = isMinAdjustment(destination)
? destination.minAmount.currency : destination.amount.currency
return sourceCurrency === 'XRP' && destinationCurrency === 'XRP'
return (sourceCurrency === 'XRP' || sourceCurrency === 'drops') &&
(destinationCurrency === 'XRP' || destinationCurrency === 'drops')
}

function isIOUWithoutCounterparty(amount: Amount): boolean {
Expand Down
120 changes: 120 additions & 0 deletions test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,126 @@ describe('RippleAPI', function () {
responses.preparePayment.minAmountXRPXRP, 'prepare'));
});

it('preparePayment - XRP to XRP', function () {
const payment = {
"source": {
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"maxAmount": {
"value": "1",
"currency": "XRP"
}
},
"destination": {
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"amount": {
"value": "1",
"currency": "XRP"
}
}
}
return this.api.preparePayment(address, payment, instructions).then(response => {
const expected = {
txJSON: '{"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":"1000000","Flags":2147483648,"LastLedgerSequence":8820051,"Sequence":23,"Fee":"12"}',
instructions: {
fee: '0.000012',
sequence: 23,
maxLedgerVersion: 8820051
}
}
return checkResult(expected, 'prepare', response)
})
});

it('preparePayment - XRP drops to XRP drops', function () {
const payment = {
"source": {
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"maxAmount": {
"value": "1000000",
"currency": "drops"
}
},
"destination": {
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"amount": {
"value": "1000000",
"currency": "drops"
}
}
}
return this.api.preparePayment(address, payment, instructions).then(response => {
const expected = {
txJSON: '{"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":"1000000","Flags":2147483648,"LastLedgerSequence":8820051,"Sequence":23,"Fee":"12"}',
instructions: {
fee: '0.000012',
sequence: 23,
maxLedgerVersion: 8820051
}
}
return checkResult(expected, 'prepare', response)
})
});

it('preparePayment - XRP drops to XRP', function () {
const payment = {
"source": {
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"maxAmount": {
"value": "1000000",
"currency": "drops"
}
},
"destination": {
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"amount": {
"value": "1",
"currency": "XRP"
}
}
}
return this.api.preparePayment(address, payment, instructions).then(response => {
const expected = {
txJSON: '{"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":"1000000","Flags":2147483648,"LastLedgerSequence":8820051,"Sequence":23,"Fee":"12"}',
instructions: {
fee: '0.000012',
sequence: 23,
maxLedgerVersion: 8820051
}
}
return checkResult(expected, 'prepare', response)
})
});

it('preparePayment - XRP to XRP drops', function () {
const payment = {
"source": {
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"maxAmount": {
"value": "1",
"currency": "XRP"
}
},
"destination": {
"address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
"amount": {
"value": "1000000",
"currency": "drops"
}
}
}
return this.api.preparePayment(address, payment, instructions).then(response => {
const expected = {
txJSON: '{"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":"1000000","Flags":2147483648,"LastLedgerSequence":8820051,"Sequence":23,"Fee":"12"}',
instructions: {
fee: '0.000012',
sequence: 23,
maxLedgerVersion: 8820051
}
}
return checkResult(expected, 'prepare', response)
})
});

it('preparePayment - XRP to XRP no partial', function () {
assert.throws(() => {
this.api.preparePayment(address, requests.preparePayment.wrongPartial);
Expand Down

0 comments on commit f4ad04d

Please sign in to comment.