From 3746dae4556cb8e1e93303467d2e39233e41b0db Mon Sep 17 00:00:00 2001 From: Alan Cohen Date: Tue, 14 Apr 2015 21:47:24 -0700 Subject: [PATCH] Fix SendMax bug. Improve testing clarity --- api/lib/rest-to-tx-converter.js | 4 +--- test/unit/rest-converter-test.js | 35 +++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/api/lib/rest-to-tx-converter.js b/api/lib/rest-to-tx-converter.js index 0651876f..964bcda5 100644 --- a/api/lib/rest-to-tx-converter.js +++ b/api/lib/rest-to-tx-converter.js @@ -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; } diff --git a/test/unit/rest-converter-test.js b/test/unit/rest-converter-test.js index dae5127b..107504ee 100644 --- a/test/unit/rest-converter-test.js +++ b/test/unit/rest-converter-test.js @@ -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); @@ -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); @@ -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: '' @@ -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(); + }); + }); });