From 51bbe5ffc84d4f02221c6f5d3d61139610dd54fa Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sat, 19 Jan 2013 12:58:37 -0800 Subject: [PATCH] Add path test for issue #23. --- src/cpp/ripple/LedgerEntrySet.cpp | 5 ++ src/cpp/ripple/LedgerMaster.cpp | 4 -- src/cpp/ripple/OfferCreateTransactor.cpp | 9 +++ test/path-test.js | 85 +++++++++++++++++++++--- 4 files changed, 90 insertions(+), 13 deletions(-) diff --git a/src/cpp/ripple/LedgerEntrySet.cpp b/src/cpp/ripple/LedgerEntrySet.cpp index 5b6b926d63..4bd70f53b2 100644 --- a/src/cpp/ripple/LedgerEntrySet.cpp +++ b/src/cpp/ripple/LedgerEntrySet.cpp @@ -525,6 +525,11 @@ TER LedgerEntrySet::dirAdd( const uint256& uLedgerIndex, boost::function fDescriber) { +cLog(lsDEBUG) + << boost::str(boost::format("dirAdd: uRootIndex=%s uLedgerIndex=%s") + % uRootIndex.ToString() + % uLedgerIndex.ToString()); + SLE::pointer sleNode; STVector256 svIndexes; SLE::pointer sleRoot = entryCache(ltDIR_NODE, uRootIndex); diff --git a/src/cpp/ripple/LedgerMaster.cpp b/src/cpp/ripple/LedgerMaster.cpp index 60b5b464cb..e27c350075 100644 --- a/src/cpp/ripple/LedgerMaster.cpp +++ b/src/cpp/ripple/LedgerMaster.cpp @@ -531,10 +531,6 @@ void LedgerMaster::pubThread() cLog(lsDEBUG) << "Publishing ledger " << l->getLedgerSeq(); setFullLedger(l); // OPTIMIZEME: This is actually more work than we need to do theApp->getOPs().pubLedger(l); - BOOST_FOREACH(callback& c, mOnValidate) - { - c(l); - } } } } diff --git a/src/cpp/ripple/OfferCreateTransactor.cpp b/src/cpp/ripple/OfferCreateTransactor.cpp index aa7929c41f..05a469ebfa 100644 --- a/src/cpp/ripple/OfferCreateTransactor.cpp +++ b/src/cpp/ripple/OfferCreateTransactor.cpp @@ -229,11 +229,16 @@ TER OfferCreateTransactor::takeOffers( } } + cLog(lsINFO) << "takeOffers: " << transToken(terResult); + // On storing meta data, delete offers that were found unfunded to prevent encountering them in future. if (tesSUCCESS == terResult) { BOOST_FOREACH(const uint256& uOfferIndex, usOfferUnfundedFound) { + + cLog(lsINFO) << "takeOffers: found unfunded: " << uOfferIndex.ToString(); + terResult = mEngine->getNodes().offerDelete(uOfferIndex); if (tesSUCCESS != terResult) break; @@ -245,12 +250,16 @@ TER OfferCreateTransactor::takeOffers( // On success, delete offers that became unfunded. BOOST_FOREACH(const uint256& uOfferIndex, usOfferUnfundedBecame) { + cLog(lsINFO) << "takeOffers: became unfunded: " << uOfferIndex.ToString(); + terResult = mEngine->getNodes().offerDelete(uOfferIndex); if (tesSUCCESS != terResult) break; } } + cLog(lsINFO) << "takeOffers< " << transToken(terResult); + return terResult; } diff --git a/test/path-test.js b/test/path-test.js index 692a3940c3..5c6ee0a0f1 100644 --- a/test/path-test.js +++ b/test/path-test.js @@ -661,13 +661,13 @@ buster.testCase("More Path finding", { // Test alternative paths with qualities. }); -buster.testCase("Path negatives", { +buster.testCase("Issues", { // 'setUp' : testutils.build_setup({ verbose: true, no_server: true }), // 'setUp' : testutils.build_setup({ verbose: true }), 'setUp' : testutils.build_setup(), 'tearDown' : testutils.build_teardown(), - "Issue #5" : + "Path negative: Issue #5" : function (done) { var self = this; @@ -691,14 +691,17 @@ buster.testCase("Path negatives", { callback); }, function (callback) { - self.what = "Distribute funds."; + self.what = "Alice sends via a path"; - testutils.payments(self.remote, - { - // 4. acct 2 sent acct 3 a 75 iou - "bob" : "75/USD/carol", - }, - callback); + self.remote.transaction() + .payment("alice", "bob", "55/USD/mtgox") + .path_add( [ { account: "carol" } ]) + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + + callback(m.result !== 'tesSUCCESS'); + }) + .submit(); }, function (callback) { self.what = "Verify balances."; @@ -764,6 +767,70 @@ buster.testCase("Path negatives", { buster.refute(error, self.what); done(); }); + }, + + "//Path negative: Issue #23: smaller" : + // alice -120 USD-> michael -25 USD-> amy + // alice -25 USD-> Bill -75 USD -> Sam -100 USD-> Amy + // + // alice -- limit 40 --> bob + // alice --> carol --> dan --> bob + // Balance of 100 USD Bob - Balance of 37 USD -> Rod + // + 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"], callback); + }, + function (callback) { + self.what = "Set credit limits."; + + testutils.credit_limits(self.remote, + { + "bob" : [ "40/USD/alice", "20/USD/dan" ], + "dan" : [ "20/USD/carol" ], + "carol" : [ "20/USD/alice" ], + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; + + testutils.payments(self.remote, + { + // 4. acct 2 sent acct 3 a 75 iou + "alice" : "55/USD/bob", + }, + callback); + }, + function (callback) { + self.what = "Verify balances."; + + testutils.verify_balances(self.remote, + { + "bob" : [ "40/USD/alice", "15/USD/dan" ], + }, + 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); + done(); + }); } }); // vim:sw=2:sts=2:ts=8:et