From fe2ffafb10cc9abde93082895d1b2a98675dc029 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sat, 19 Jan 2013 18:53:42 -0800 Subject: [PATCH] UT: Tests for ripple-client issue #23. --- src/cpp/ripple/RPCHandler.cpp | 12 ++--- test/path-test.js | 89 ++++++++++++++++++++++++++++++----- test/send-test.js | 2 +- 3 files changed, 84 insertions(+), 19 deletions(-) diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index c7dbbfaec9..846e51a8fa 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -77,9 +77,7 @@ Json::Value RPCHandler::transactionSign(Json::Value jvRequest, bool bSubmit) RippleAddress naSeed; RippleAddress raSrcAddressID; - cLog(lsDEBUG) - << boost::str(boost::format("transactionSign: %s") - % jvRequest); + cLog(lsDEBUG) << boost::str(boost::format("transactionSign: %s") % jvRequest); if (!jvRequest.isMember("secret") || !jvRequest.isMember("tx_json")) { @@ -177,15 +175,15 @@ Json::Value RPCHandler::transactionSign(Json::Value jvRequest, bool bSubmit) Pathfinder pf(raSrcAddressID, dstAccountID, saSendMax.getCurrency(), saSendMax.getIssuer(), saSend); - if (!pf.findPaths(5, 3, spsPaths)) + if (!pf.findPaths(7, 3, spsPaths)) { - cLog(lsDEBUG) << "payment: build_path: No paths found."; + cLog(lsDEBUG) << "transactionSign: build_path: No paths found."; return rpcError(rpcNO_PATH); } else { - cLog(lsDEBUG) << "payment: build_path: " << spsPaths.getJson(0); + cLog(lsDEBUG) << "transactionSign: build_path: " << spsPaths.getJson(0); } if (!spsPaths.isEmpty()) @@ -1146,7 +1144,7 @@ Json::Value RPCHandler::doRipplePathFind(Json::Value jvRequest) STPathSet spsComputed; Pathfinder pf(raSrc, raDst, uSrcCurrencyID, uSrcIssuerID, saDstAmount); - if (!pf.findPaths(5, 3, spsComputed)) + if (!pf.findPaths(7, 3, spsComputed)) { cLog(lsDEBUG) << "ripple_path_find: No paths found."; } diff --git a/test/path-test.js b/test/path-test.js index d10a97e3bd..9cc0d7f82f 100644 --- a/test/path-test.js +++ b/test/path-test.js @@ -769,9 +769,7 @@ buster.testCase("Issues", { }); }, - "//Path negative: Issue #23: smaller" : - // alice -120 USD-> michael -25 USD-> amy - // alice -25 USD-> Bill -75 USD -> Sam -100 USD-> Amy + "Path negative: ripple-client issue #23: smaller" : // // alice -- limit 40 --> bob // alice --> carol --> dan --> bob @@ -792,20 +790,22 @@ buster.testCase("Issues", { testutils.credit_limits(self.remote, { "bob" : [ "40/USD/alice", "20/USD/dan" ], - "dan" : [ "20/USD/carol" ], "carol" : [ "20/USD/alice" ], + "dan" : [ "20/USD/carol" ], }, callback); }, function (callback) { - self.what = "Distribute funds."; + self.what = "Payment."; - testutils.payments(self.remote, - { - // 4. acct 2 sent acct 3 a 75 iou - "alice" : "55/USD/bob", - }, - callback); + self.remote.transaction() + .payment('alice', 'bob', "55/USD/bob") + .build_path(true) + .once('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); + }) + .submit(); }, function (callback) { self.what = "Verify balances."; @@ -826,6 +826,73 @@ buster.testCase("Issues", { // callback(); // }) // .request(); +// }, + ], function (error) { + buster.refute(error, self.what); + done(); + }); + }, + + "Path negative: ripple-client issue #23: larger" : + // + // alice -120 USD-> amazon -25 USD-> bob + // alice -25 USD-> carol -75 USD -> dan -100 USD-> bob + // + function (done) { + var self = this; + + async.waterfall([ + function (callback) { + self.what = "Create accounts."; + + testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "carol", "dan", "amazon"], callback); + }, + function (callback) { + self.what = "Set credit limits."; + + testutils.credit_limits(self.remote, + { + "amazon" : [ "120/USD/alice" ], + "bob" : [ "25/USD/amazon", "100/USD/dan" ], + "carol" : [ "25/USD/alice" ], + "dan" : [ "75/USD/carol" ], + }, + callback); + }, + function (callback) { + self.what = "Payment."; + + self.remote.transaction() + .payment('alice', 'bob', "50/USD/bob") + .build_path(true) + .once('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balances."; + + testutils.verify_balances(self.remote, + { + "alice" : [ "-25/USD/amazon", "-25/USD/carol" ], + "bob" : [ "25/USD/amazon", "25/USD/dan" ], + "carol" : [ "25/USD/alice", "-25/USD/dan" ], + "dan" : [ "25/USD/carol", "-25/USD/bob" ], + }, + callback); + }, +// function (callback) { +// self.what = "Display ledger"; +// +// self.remote.request_ledger('current', true) +// .on('success', function (m) { +// console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); +// +// callback(); +// }) +// .request(); // }, ], function (error) { buster.refute(error, self.what); diff --git a/test/send-test.js b/test/send-test.js index ca50273cb4..e414943dba 100644 --- a/test/send-test.js +++ b/test/send-test.js @@ -495,7 +495,7 @@ buster.testCase("Sending future", { // Ripple with one-way credit path. }); -buster.testCase("Nexus", { +buster.testCase("Gateway", { // 'setUp' : testutils.build_setup({ verbose: true }), 'setUp' : testutils.build_setup(), 'tearDown' : testutils.build_teardown(),