mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-29 15:35:50 +00:00
Work on testing indirect ripple.
- WS: Make ripple_state more strict. - UT: Add an indirect ripple test. - UT: Add more testutils functions.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user