From bbb2a41c800397504fa42e0cc7a07f5bb8172d08 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Mon, 31 Dec 2012 16:37:35 -0800 Subject: [PATCH] UT: Add some non-function path tests. --- test/path-test.js | 231 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 228 insertions(+), 3 deletions(-) diff --git a/test/path-test.js b/test/path-test.js index 586de543a1..481c04c145 100644 --- a/test/path-test.js +++ b/test/path-test.js @@ -12,8 +12,7 @@ require("../src/js/remote.js").config = require("./config.js"); buster.testRunner.timeout = 5000; -if (false) -buster.testCase("Basic Path finding", { +buster.testCase("// Basic Path finding", { // 'setUp' : testutils.build_setup({ verbose: true, no_server: true }), // 'setUp' : testutils.build_setup({ verbose: true }), 'setUp' : testutils.build_setup(), @@ -222,7 +221,7 @@ buster.testCase("Basic Path finding", { }, }); -buster.testCase("Extended Path finding", { +buster.testCase("// Extended Path finding", { // 'setUp' : testutils.build_setup({ verbose: true, no_server: true }), // 'setUp' : testutils.build_setup({ verbose: true }), 'setUp' : testutils.build_setup(), @@ -432,6 +431,232 @@ buster.testCase("Extended Path finding", { done(); }); }, + + // Test alternative paths with qualities. }); +buster.testCase("// More Path finding", { + // 'setUp' : testutils.build_setup({ verbose: true, no_server: true }), + // 'setUp' : testutils.build_setup({ verbose: true }), + 'setUp' : testutils.build_setup(), + 'tearDown' : testutils.build_teardown(), + + "alternative paths - limit returned paths to best quality" : + // alice +- bitstamp -+ bob + // |- carol(fee) -| // To be excluded. + // |- dan(issue) -| + // |- mtgox -| + function (done) { + var self = this; + + async.waterfall([ + function (callback) { + self.what = "Create accounts."; + + testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "carol", "dan", "mtgox", "bitstamp"], callback); + }, + function (callback) { + self.what = "Set transfer rate."; + + self.remote.transaction() + .account_set("carol") + .transfer_rate(1e9*1.1) + .once('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Set credit limits."; + + testutils.credit_limits(self.remote, + { + "alice" : [ "800/USD/bitstamp", "800/USD/carol", "800/USD/dan", "800/USD/mtgox", ], + "bob" : [ "800/USD/bitstamp", "800/USD/carol", "800/USD/dan", "800/USD/mtgox", ], + "dan" : [ "800/USD/alice", "800/USD/bob" ], + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; + + testutils.payments(self.remote, + { + "bitstamp" : "100/USD/alice", + "carol" : "100/USD/alice", + "mtgox" : "100/USD/alice", + }, + callback); + }, + function (callback) { + self.what = "Find path from alice to bob"; + + self.remote.request_ripple_path_find("alice", "bob", "5/USD/bob", + [ { 'currency' : "USD" } ]) + .on('success', function (m) { + console.log("proposed: %s", JSON.stringify(m)); + + // 1 alternative. +// buster.assert.equals(1, m.alternatives.length) +// // Path is empty. +// buster.assert.equals(0, m.alternatives[0].paths_canonical.length) + + callback(); + }) + .request(); + }, + ], function (error) { + buster.refute(error, self.what); + done(); + }); + }, + + "alternative paths - consume best transfer" : + function (done) { + var self = this; + + async.waterfall([ + function (callback) { + self.what = "Create accounts."; + + testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "mtgox", "bitstamp"], callback); + }, + function (callback) { + self.what = "Set transfer rate."; + + self.remote.transaction() + .account_set("bitstamp") + .transfer_rate(1e9*1.1) + .once('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Set credit limits."; + + testutils.credit_limits(self.remote, + { + "alice" : [ "600/USD/mtgox", "800/USD/bitstamp" ], + "bob" : [ "700/USD/mtgox", "900/USD/bitstamp" ] + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; + + testutils.payments(self.remote, + { + "bitstamp" : "70/USD/alice", + "mtgox" : "70/USD/alice", + }, + callback); + }, + function (callback) { + self.what = "Payment with auto path"; + + self.remote.transaction() + .payment('alice', 'bob', "70/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" : [ "0/USD/mtgox", "70/USD/bitstamp" ], + "bob" : [ "70/USD/mtgox", "0/USD/bitstamp" ], + "bitstamp" : [ "-70/USD/alice", "0/USD/bob" ], + "mtgox" : [ "0/USD/alice", "-70/USD/bob" ], + }, + callback); + }, + ], function (error) { + buster.refute(error, self.what); + done(); + }); + }, + + "alternative paths - consume best transfer first" : + function (done) { + var self = this; + + async.waterfall([ + function (callback) { + self.what = "Create accounts."; + + testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "mtgox", "bitstamp"], callback); + }, + function (callback) { + self.what = "Set transfer rate."; + + self.remote.transaction() + .account_set("bitstamp") + .transfer_rate(1e9*1.1) + .once('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Set credit limits."; + + testutils.credit_limits(self.remote, + { + "alice" : [ "600/USD/mtgox", "800/USD/bitstamp" ], + "bob" : [ "700/USD/mtgox", "900/USD/bitstamp" ] + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; + + testutils.payments(self.remote, + { + "bitstamp" : "70/USD/alice", + "mtgox" : "70/USD/alice", + }, + callback); + }, + function (callback) { + self.what = "Payment with auto path"; + + self.remote.transaction() + .payment('alice', 'bob', "77/USD/bob") + .build_path(true) + .send_max("100/USD/alice") + .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" : [ "0/USD/mtgox", "62.3/USD/bitstamp" ], + "bob" : [ "70/USD/mtgox", "7/USD/bitstamp" ], + "bitstamp" : [ "-62.3/USD/alice", "-7/USD/bob" ], + "mtgox" : [ "0/USD/alice", "-70/USD/bob" ], + }, + callback); + }, + ], function (error) { + buster.refute(error, self.what); + done(); + }); + }, + + // Test alternative paths with qualities. +}); // vim:sw=2:sts=2:ts=8:et