From 252a81f3e29b8a8cb442e5b46388ecce92fd3c6f Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sat, 3 Nov 2012 14:52:33 -0700 Subject: [PATCH] UT: Add payments helper. --- test/testutils.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/testutils.js b/test/testutils.js index 09703287..a3a03466 100644 --- a/test/testutils.js +++ b/test/testutils.js @@ -171,6 +171,33 @@ var payment = function (remote, src, dst, amount, callback) { .submit(); }; +var payments = function (remote, balances, callback) { + assert(3 === arguments.length); + + var sends = []; + + for (var src in balances) { + var values_src = balances[src]; + var values = 'string' === typeof values_src ? [ values_src ] : values_src; + + for (var index in values) { + var amount_json = values[index]; + var amount = Amount.from_json(amount_json); + + sends.push( { "source" : src, "destination" : amount.issuer.to_json(), "amount" : amount_json } ); + } + } + + async.every(sends, + function (send, callback) { + payment(remote, send.source, send.destination, send.amount, + function (mismatch) { callback(!mismatch); }); + }, + function (every) { + callback(!every); + }); +}; + var transfer_rate = function (remote, src, billionths, callback) { assert(4 === arguments.length); @@ -238,6 +265,7 @@ exports.create_accounts = create_accounts; exports.credit_limit = credit_limit; exports.credit_limits = credit_limits; exports.payment = payment; +exports.payments = payments; exports.build_teardown = build_teardown; exports.transfer_rate = transfer_rate; exports.verify_balance = verify_balance;