diff --git a/src/RippleCalc.cpp b/src/RippleCalc.cpp index 5241ad8241..f5e192d8bf 100644 --- a/src/RippleCalc.cpp +++ b/src/RippleCalc.cpp @@ -1944,7 +1944,7 @@ TER RippleCalc::rippleCalc( terResult = temUNCERTAIN; } - STAmount saInAct; + STAmount saInAct; // XXX Verify don't need to set currency/issuer. STAmount saOutAct; const LedgerEntrySet lesBase = lesActive; // Checkpoint with just fees paid. const uint64 uQualityLimit = bLimitQuality ? STAmount::getRate(saDstAmountReq, saMaxAmountReq) : 0; diff --git a/src/WSDoor.cpp b/src/WSDoor.cpp index 8d418697c9..2721c74195 100644 --- a/src/WSDoor.cpp +++ b/src/WSDoor.cpp @@ -832,17 +832,23 @@ void WSConnection::doLedgerEntry(Json::Value& jvResult, const Json::Value& jvReq uint160 uCurrency; Json::Value jvRippleState = jvRequest["ripple_state"]; - if (!jvRippleState.isMember("accounts") - || !jvRippleState.isMember("currency") + if (!jvRippleState.isMember("currency") + || !jvRippleState.isMember("accounts") || !jvRippleState["accounts"].isArray() - || 2 != jvRippleState["accounts"].size()) { + || 2 != jvRippleState["accounts"].size() + || !jvRippleState["accounts"][0u].isString() + || !jvRippleState["accounts"][1u].isString() + || jvRippleState["accounts"][0u].asString() == jvRippleState["accounts"][1u].asString() + ) { cLog(lsINFO) - << boost::str(boost::format("ledger_entry: ripple_state: accounts: %d currency: %d array=%d, size=%d") + << boost::str(boost::format("ledger_entry: ripple_state: accounts: %d currency: %d array: %d size: %d equal: %d") % jvRippleState.isMember("accounts") % jvRippleState.isMember("currency") % jvRippleState["accounts"].isArray() - % jvRippleState["accounts"].size()); + % jvRippleState["accounts"].size() + % (jvRippleState["accounts"][0u].asString() == jvRippleState["accounts"][1u].asString()) + ); jvResult["error"] = "malformedRequest"; } diff --git a/test/send-test.js b/test/send-test.js index ea1ae94912..8981322098 100644 --- a/test/send-test.js +++ b/test/send-test.js @@ -10,7 +10,7 @@ var testutils = require("./testutils.js"); // How long to wait for server to start. var serverDelay = 1500; -buster.testRunner.timeout = 5000; +buster.testRunner.timeout = 3000; buster.testCase("// Sending", { 'setUp' : testutils.build_setup(), @@ -234,7 +234,7 @@ buster.testCase("// Sending", { }); // XXX In the future add ledger_accept after partial retry is implemented in the server. -buster.testCase("Sending future", { +buster.testCase("// Sending future", { 'setUp' : testutils.build_setup(), 'tearDown' : testutils.build_teardown(), @@ -265,7 +265,7 @@ buster.testCase("Sending future", { self.remote.transaction() .payment('alice', 'bob', "24/USD/alice") - .on('proposed', function (m) { + .once('proposed', function (m) { // console.log("proposed: %s", JSON.stringify(m)); callback(m.result != 'tesSUCCESS'); }) @@ -453,4 +453,59 @@ buster.testCase("Sending future", { // Ripple with one-way credit path. }); +buster.testCase("Indirect ripple", { + 'setUp' : testutils.build_setup({ verbose: true, no_server: false }), + 'tearDown' : testutils.test_teardown, + + "indirect ripple" : + function (done) { + var self = this; + + self.remote.set_trace(); + + async.waterfall([ + function (callback) { + self.what = "Create accounts."; + + testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "mtgox"], callback); + }, + function (callback) { + self.what = "Set alice's limit."; + + testutils.credit_limit(self.remote, "alice", "600/USD/mtgox", callback); + }, + function (callback) { + self.what = "Set bob's limit."; + + testutils.credit_limit(self.remote, "bob", "700/USD/mtgox", callback); + }, + function (callback) { + self.what = "Give alice some mtgox."; + + testutils.payment(self.remote, "mtgox", "alice", "70/USD/mtgox", callback); + }, + function (callback) { + self.what = "Give bob some mtgox."; + + testutils.payment(self.remote, "mtgox", "bob", "50/USD/mtgox", callback); + }, + function (callback) { + self.what = "Verify alice balance with mtgox."; + + testutils.verify_balance(self.remote, "alice", "70/USD/mtgox", callback); + }, + function (callback) { + self.what = "Verify bob balance with mtgox."; + + testutils.verify_balance(self.remote, "bob", "50/USD/mtgox", callback); + }, + ], function (error) { + buster.refute(error, self.what); + done(); + }); + }, + + // Ripple without credit path. + // Ripple with one-way credit path. +}); // vim:sw=2:sts=2:ts=8 diff --git a/test/testutils.js b/test/testutils.js index 26d04551d8..60462790ab 100644 --- a/test/testutils.js +++ b/test/testutils.js @@ -1,6 +1,7 @@ var async = require("async"); // var buster = require("buster"); +var Amount = require("../js/amount.js").Amount; var Remote = require("../js/remote.js").Remote; var Server = require("./server.js").Server; @@ -115,6 +116,24 @@ var credit_limit = function (remote, src, amount, callback) { remote.transaction() .ripple_line_set(src, amount) + .on('proposed', function (m) { + console.log("proposed: %s", JSON.stringify(m)); + + callback(m.result != 'tesSUCCESS'); + }) + .on('error', function (m) { + // console.log("error: %s", JSON.stringify(m)); + + callback(m); + }) + .submit(); +}; + +var payment = function (remote, src, dst, amount, callback) { + assert(5 === arguments.length); + + remote.transaction() + .payment(src, dst, amount) .on('proposed', function (m) { // console.log("proposed: %s", JSON.stringify(m)); @@ -128,9 +147,27 @@ var credit_limit = function (remote, src, amount, callback) { .submit(); }; -exports.create_accounts = create_accounts; -exports.credit_limit = credit_limit; -exports.build_setup = build_setup; -exports.build_teardown = build_teardown; +var verify_balance = function (remote, src, amount_json, callback) { + assert(4 === arguments.length); + var amount = Amount.from_json(amount_json); + + remote.request_ripple_balance(src, amount.issuer.to_json(), amount.currency.to_json(), 'CURRENT') + .once('ripple_state', function (m) { + console.log("BALANCE: %s", JSON.stringify(m)); + console.log("account_balance: %s", m.account_balance.to_text_full()); + console.log("account_limit: %s", m.account_limit.to_text_full()); + console.log("issuer_balance: %s", m.issuer_balance.to_text_full()); + console.log("issuer_limit: %s", m.issuer_limit.to_text_full()); + + callback(!m.account_balance.equals(amount)); + }) + .request(); +}; +exports.build_setup = build_setup; +exports.create_accounts = create_accounts; +exports.credit_limit = credit_limit; +exports.payment = payment; +exports.test_teardown = test_teardown; +exports.verify_balance = verify_balance; // vim:sw=2:sts=2:ts=8