Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
Fix SendMax bug. Improve testing clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Cohen committed Apr 15, 2015
1 parent 0f8babf commit 3746dae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
4 changes: 1 addition & 3 deletions api/lib/rest-to-tx-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ RestToTxConverter.prototype.convert = function(payment, callback) {
// - source amount and destination issuers are different
//
if (srcAmt.currency === dstAmt.currency) {
if (srcAmt.issuer !== src) {
if (srcAmt.issuer !== src && srcAmt.issuer !== dstAmt.issuer) {
return true;
}
} else if (srcAmt.issuer !== dstAmt.issuer) {
return true;
}
return false;
}
Expand Down
35 changes: 28 additions & 7 deletions test/unit/rest-converter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ suite('unit - converter - Rest to Tx', function() {

test('convert() -- payment with currency that has same issuer for source and destination amount', function(done) {
restToTxConverter.convert(fixtures.exportsPaymentRestIssuers({
sourceIssuer: addresses.VALID,
destinationIssuer: addresses.VALID
sourceAccount: addresses.VALID,
destinationAccount: addresses.COUNTERPARTY,
sourceIssuer: addresses.ISSUER,
destinationIssuer: addresses.ISSUER
}), function(err, transaction) {
assert.strictEqual(err, null);
assert.strictEqual(transaction.tx_json.SendMax, undefined);
Expand Down Expand Up @@ -92,9 +94,10 @@ suite('unit - converter - Rest to Tx', function() {

test('convert() -- payment with same currency for source and destination, no issuer for source amount', function(done) {
restToTxConverter.convert(fixtures.exportsPaymentRestIssuers({
sourceIssuer: '',
sourceAccount: addresses.VALID,
destinationAccount: addresses.COUNTERPARTY,
destinationIssuer: addresses.COUNTERPARTY
sourceIssuer: '',
destinationIssuer: addresses.ISSUER2
}), function(err, transaction) {
assert.strictEqual(err, null);
assert.strictEqual(transaction.tx_json.SendMax, undefined);
Expand All @@ -104,6 +107,7 @@ suite('unit - converter - Rest to Tx', function() {

test('convert() -- payment with same currency for source and destination, no issuer for source and destination amount', function(done) {
restToTxConverter.convert(fixtures.exportsPaymentRestIssuers({
sourceAccount: addresses.VALID,
sourceIssuer: '',
destinationAccount: addresses.COUNTERPARTY,
destinationIssuer: ''
Expand All @@ -116,14 +120,31 @@ suite('unit - converter - Rest to Tx', function() {

test('convert() -- payment with same currency for source and destination, no issuer for destination amount', function(done) {
restToTxConverter.convert(fixtures.exportsPaymentRestIssuers({
sourceIssuer: addresses.VALID,
sourceAccount: addresses.VALID,
sourceIssuer: addresses.VALID, // source account is source issuer
destinationAccount: addresses.COUNTERPARTY,
destinationIssuer: ''
}), function(err, transaction) {
if (err) {
return done(err);
}
assert.strictEqual(transaction.tx_json.SendMax, undefined);
done(err);
done();
});
});


test('convert() -- payment with same currency for source and destination, issuers are source and destination', function(done) {
restToTxConverter.convert(fixtures.exportsPaymentRestIssuers({
sourceAccount: addresses.VALID,
sourceIssuer: addresses.VALID, // source account is source issuer
destinationAccount: addresses.COUNTERPARTY,
destinationIssuer: addresses.COUNTERPARTY // destination account is destination issuer
}), function(err, transaction) {
if (err) {
return done(err);
}
assert.strictEqual(transaction.tx_json.SendMax, undefined);
done();
});
});
});

0 comments on commit 3746dae

Please sign in to comment.