From c76e2b54a911b6273d9d08a94468f02fc56c8e99 Mon Sep 17 00:00:00 2001 From: wltsmrz Date: Wed, 4 Sep 2013 16:29:32 -0700 Subject: [PATCH] Update system tests for mocha and new ripple-lib transaction submission --- package.json | 5 +- test/account_set-test.js | 354 ++++--- test/account_tx-test.js | 605 +++++++---- test/buster.js | 11 - test/jsonrpc-test.js | 286 +++-- test/monitor-test.js | 73 +- test/offer-test.js | 592 ++++++----- test/path-test.js | 1734 +++++++++++++++---------------- test/remote-test.js | 372 +++---- test/send-test.js | 2122 +++++++++++++++++++------------------- test/server-test.js | 39 +- test/server.js | 112 +- test/testutils.js | 73 +- test/websocket-test.js | 77 +- 14 files changed, 3287 insertions(+), 3168 deletions(-) delete mode 100644 test/buster.js diff --git a/package.json b/package.json index 7e259d036..42c6d4f61 100644 --- a/package.json +++ b/package.json @@ -16,12 +16,11 @@ "simple-jsonrpc": "~0.0.2" }, "devDependencies": { - "buster": "~0.6.12", - "mocha": "~1.12.0" + "mocha": "~1.13.0" }, "scripts": { - "test": "./node_modules/buster/bin/buster-test --reporter specification" + "test": "mocha --reporter spec --ui tdd --timeout 10000 --slow 600 test/*-test.js" }, "repository": { diff --git a/test/account_set-test.js b/test/account_set-test.js index c08ea538e..32006ef2c 100644 --- a/test/account_set-test.js +++ b/test/account_set-test.js @@ -1,217 +1,235 @@ -var async = require("async"); -var buster = require("buster"); +var async = require("async"); +var assert = require('assert'); +var Remote = require("ripple-lib").Remote; +var testutils = require("./testutils"); +var config = testutils.init_config(); -var Amount = require("ripple-lib").Amount; -var Remote = require("ripple-lib").Remote; -var Request = require("ripple-lib").Request; -var Server = require("./server").Server; +suite('Account set', function() { + var $ = { }; -var testutils = require("./testutils"); -var config = testutils.init_config(); + setup(function(done) { + testutils.build_setup().call($, done); + }); -// How long to wait for server to start. -var serverDelay = 1500; + teardown(function(done) { + testutils.build_teardown().call($, done); + }); -buster.testRunner.timeout = 5000; - -buster.testCase("AccountSet", { - 'setUp' : testutils.build_setup(), - // 'setUp' : testutils.build_setup({verbose: true , no_server: false}), - 'tearDown' : testutils.build_teardown(), - - "RequireDestTag" : function (done) { + test('set RequireDestTag', function(done) { var self = this; - async.waterfall([ - function (callback) { - self.what = "Set RequireDestTag."; + var steps = [ + function (callback) { + self.what = "Set RequireDestTag."; - self.remote.transaction() - .account_set("root") - .set_flags('RequireDestTag') - .on('submitted', function (m) { - //console.log("proposed: %s", JSON.stringify(m)); + $.remote.transaction() + .account_set("root") + .set_flags('RequireDestTag') + .on('submitted', function (m) { + //console.log("proposed: %s", JSON.stringify(m)); + if (m.engine_result === 'tesSUCCESS') { + callback(null); + } else { + callback(new Error(m.engine_result)); + } + }) + .submit(); + }, - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Check RequireDestTag"; + function (callback) { + self.what = "Check RequireDestTag"; - self.remote.request_account_flags('root', 'CURRENT') - .on('success', function (m) { - var wrong = !(m.node.Flags & Remote.flags.account_root.RequireDestTag); + $.remote.request_account_flags('root', 'CURRENT') + .on('success', function (m) { + var wrong = !(m.node.Flags & Remote.flags.account_root.RequireDestTag); - if (wrong) - console.log("Set RequireDestTag: failed: %s", JSON.stringify(m)); + if (wrong) { + console.log("Set RequireDestTag: failed: %s", JSON.stringify(m)); + } - callback(wrong); - }) - .request(); - }, - function (callback) { - self.what = "Clear RequireDestTag."; + callback(wrong ? new Error(wrong) : null); + }) + .request(); + }, - self.remote.transaction() - .account_set("root") - .set_flags('OptionalDestTag') - .on('submitted', function (m) { - //console.log("proposed: %s", JSON.stringify(m)); + function (callback) { + self.what = "Clear RequireDestTag."; - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Check No RequireDestTag"; + $.remote.transaction() + .account_set("root") + .set_flags('OptionalDestTag') + .on('submitted', function (m) { + //console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result === 'tesSUCCESS' ? null : new Error()); + }) + .submit(); + }, - self.remote.request_account_flags('root', 'CURRENT') - .on('success', function (m) { - var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireDestTag); + function (callback) { + self.what = "Check No RequireDestTag"; - if (wrong) - console.log("Clear RequireDestTag: failed: %s", JSON.stringify(m)); + $.remote.request_account_flags('root', 'CURRENT') + .on('success', function (m) { + var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireDestTag); - callback(wrong); - }) - .request(); - }, - ], function (error) { - buster.refute(error, self.what); + if (wrong) { + console.log("Clear RequireDestTag: failed: %s", JSON.stringify(m)); + } + + callback(wrong ? new Error(m) : null); + }) + .request(); + } + ] + + async.waterfall(steps,function (error) { + assert(!error, self.what); done(); }); - }, + }); - "RequireAuth" : function (done) { + test("set RequireAuth", function (done) { var self = this; - async.waterfall([ - function (callback) { - self.what = "Set RequireAuth."; + var steps = [ + function (callback) { + self.what = "Set RequireAuth."; - self.remote.transaction() - .account_set("root") - .set_flags('RequireAuth') - .on('submitted', function (m) { - //console.log("proposed: %s", JSON.stringify(m)); + $.remote.transaction() + .account_set("root") + .set_flags('RequireAuth') + .on('submitted', function (m) { + //console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result === 'tesSUCCESS' ? null : new Error(m)); + }) + .submit(); + }, - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Check RequireAuth"; + function (callback) { + self.what = "Check RequireAuth"; - self.remote.request_account_flags('root', 'CURRENT') - .on('success', function (m) { - var wrong = !(m.node.Flags & Remote.flags.account_root.RequireAuth); + $.remote.request_account_flags('root', 'CURRENT') + .on('error', callback) + .on('success', function (m) { + var wrong = !(m.node.Flags & Remote.flags.account_root.RequireAuth); - if (wrong) - console.log("Set RequireAuth: failed: %s", JSON.stringify(m)); + if (wrong) { + console.log("Set RequireAuth: failed: %s", JSON.stringify(m)); + } - callback(wrong); - }) - .request(); - }, - function (callback) { - self.what = "Clear RequireAuth."; + callback(wrong ? new Error(m) : null); + }) + .request(); + }, - self.remote.transaction() - .account_set("root") - .set_flags('OptionalAuth') - .on('submitted', function (m) { - //console.log("proposed: %s", JSON.stringify(m)); + function (callback) { + self.what = "Clear RequireAuth."; - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Check No RequireAuth"; + $.remote.transaction() + .account_set("root") + .set_flags('OptionalAuth') + .on('submitted', function (m) { + //console.log("proposed: %s", JSON.stringify(m)); - self.remote.request_account_flags('root', 'CURRENT') - .on('success', function (m) { - var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireAuth); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, - if (wrong) - console.log("Clear RequireAuth: failed: %s", JSON.stringify(m)); + function (callback) { + self.what = "Check No RequireAuth"; - callback(wrong); - }) - .request(); - }, - // XXX Also check fails if something is owned. - ], function (error) { - buster.refute(error, self.what); + $.remote.request_account_flags('root', 'CURRENT') + .on('error', callback) + .on('success', function (m) { + var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireAuth); + + if (wrong) { + console.log("Clear RequireAuth: failed: %s", JSON.stringify(m)); + } + + callback(wrong ? new Error(m) : null); + }) + .request(); + } + // XXX Also check fails if something is owned. + ] + + async.waterfall(steps, function(error) { + assert(!error, self.what); done(); }); - }, + }); - "DisallowXRP" : function (done) { + test('set DisallowXRP', function(done) { var self = this; - async.waterfall([ - function (callback) { - self.what = "Set DisallowXRP."; + var steps = [ + function (callback) { + self.what = "Set DisallowXRP."; - self.remote.transaction() - .account_set("root") - .set_flags('DisallowXRP') - .on('submitted', function (m) { - //console.log("proposed: %s", JSON.stringify(m)); + $.remote.transaction() + .account_set("root") + .set_flags('DisallowXRP') + .on('submitted', function (m) { + //console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result === 'tesSUCCESS' ? null : new Error(m)); + }) + .submit(); + }, - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Check DisallowXRP"; + function (callback) { + self.what = "Check DisallowXRP"; - self.remote.request_account_flags('root', 'CURRENT') - .on('success', function (m) { - var wrong = !(m.node.Flags & Remote.flags.account_root.DisallowXRP); + $.remote.request_account_flags('root', 'CURRENT') + .on('error', callback) + .on('success', function (m) { + var wrong = !(m.node.Flags & Remote.flags.account_root.DisallowXRP); - if (wrong) - console.log("Set RequireDestTag: failed: %s", JSON.stringify(m)); + if (wrong) { + console.log("Set RequireDestTag: failed: %s", JSON.stringify(m)); + } - callback(wrong); - }) - .request(); - }, - function (callback) { - self.what = "Clear DisallowXRP."; + callback(wrong ? new Error(m) : null); + }) + .request(); + }, - self.remote.transaction() - .account_set("root") - .set_flags('AllowXRP') - .on('submitted', function (m) { - //console.log("proposed: %s", JSON.stringify(m)); + function (callback) { + self.what = "Clear DisallowXRP."; - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Check AllowXRP"; + $.remote.transaction() + .account_set("root") + .set_flags('AllowXRP') + .on('submitted', function (m) { + //console.log("proposed: %s", JSON.stringify(m)); - self.remote.request_account_flags('root', 'CURRENT') - .on('success', function (m) { - var wrong = !!(m.node.Flags & Remote.flags.account_root.DisallowXRP); + callback(m.engine_result === 'tesSUCCESS' ? null : new Error(m)); + }) + .submit(); + }, - if (wrong) - console.log("Clear DisallowXRP: failed: %s", JSON.stringify(m)); + function (callback) { + self.what = "Check AllowXRP"; - callback(wrong); - }) - .request(); - }, - ], function (error) { - buster.refute(error, self.what); + $.remote.request_account_flags('root', 'CURRENT') + .on('error', callback) + .on('success', function (m) { + var wrong = !!(m.node.Flags & Remote.flags.account_root.DisallowXRP); + + if (wrong) { + console.log("Clear DisallowXRP: failed: %s", JSON.stringify(m)); + } + + callback(wrong ? new Error(m) : null); + }) + .request(); + } + ] + + async.waterfall(steps, function(err) { + assert(!err); done(); }); - }, - + }); }); - -// vim:sw=2:sts=2:ts=8:et \ No newline at end of file diff --git a/test/account_tx-test.js b/test/account_tx-test.js index e34d3f49b..585a0acb1 100644 --- a/test/account_tx-test.js +++ b/test/account_tx-test.js @@ -1,210 +1,395 @@ -var async = require("async"); -var buster = require("buster"); - -var Amount = require("ripple-lib").Amount; -var Remote = require("ripple-lib").Remote; -var Transaction = require("ripple-lib").Transaction; -var Server = require("./server").Server; - -var testutils = require("./testutils"); -var config = testutils.init_config(); - -buster.testRunner.timeout = 350000; //This is a very long test! - - -// Hard-coded limits we'll be testing: -var BINARY_LIMIT = 500; -var NONBINARY_LIMIT = 200; - -var ACCOUNT = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"; -var FIRST_BATCH = 199; // Within both limits -var OFFSET = 180; -var LIMIT = 170; -var SECOND_BATCH = 10; // Between NONBINARY_LIMIT and BINARY_LIMIT -var THIRD_BATCH = 295; // Exceeds both limits -var VERBOSE = false; - -buster.testCase("//Account_tx tests", { - 'setUp' : testutils.build_setup(), - 'tearDown' : testutils.build_teardown(), - - "make a lot of transactions and query using account_tx" : function (done) { - var self = this; - var final_create; - var transactionCounter = 0; - var f = 0; - var functionHolder; - var createOfferFunction = function (callback) { - self.remote.transaction() - .offer_create("root", "500", "100/USD/root") - .on('proposed', function (m) { - transactionCounter++; - if (VERBOSE) console.log('Submitted transaction', transactionCounter); - - callback(m.result !== 'tesSUCCESS'); - }) - .on('final', function (m) { - f++; - if (VERBOSE) console.log("Finalized transaction", f); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); - buster.assert(final_create); - if ( f == transactionCounter ) { - if (VERBOSE) console.log("All transactions have been finalized."); - functionHolder(); - } - }) - .submit(); - }; - - function lotsOfTransactions(number, whenDone) { - var bunchOfOffers = []; - for (var i=0; it2.inLedger || (t1.inLedger==t2.inLedger && t1.Sequence > t2.Sequence ), - // "Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence); - buster.assert(t1.inLedger>=t2.inLedger, - "Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence); - } - } else { - buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit); - } - - - callback(false); - }) - .on('error', standardErrorHandler(callback)) - .request(); - }, - - - ], function (error) { - buster.refute(error); - finalCallback(); - } - ); - } - } -}); - - - -// TODO: -// Test the "count" feature. +////var assert = require('assert'); +////var async = require("async"); +////var extend = require('extend'); +////var Amount = require("ripple-lib").Amount; +////var Remote = require("ripple-lib").Remote; +////var Transaction = require("ripple-lib").Transaction; +////var RippleError = require("ripple-lib").RippleError; +////var Server = require("./server").Server; +////var testutils = require("./testutils"); +////var config = testutils.init_config(); +//// +////// Hard-coded limits we'll be testing: +////var BINARY_LIMIT = 500; +////var NONBINARY_LIMIT = 200; +//// +////var ACCOUNT = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"; +////var OFFSET = 180; +////var LIMIT = 170; +//// +////var FIRST_BATCH = 199; // Within both limits +////var SECOND_BATCH = 10; // Between NONBINARY_LIMIT and BINARY_LIMIT +////var THIRD_BATCH = 295; // Exceeds both limits +////var VERBOSE = false; +//// +//// +////suite('Account_tx tests', function() { +//// var $ = { }; +//// +//// setup(function(done) { +//// testutils.build_setup().call($, done); +//// }); +//// +//// teardown(function(done) { +//// testutils.build_teardown().call($, done); +//// }); +//// +//// test('make many transactions and query using account_tx', function(done) { +//// var root_id = $.remote.account('root')._account_id; +//// $.remote.request_subscribe().accounts(root_id).request(); +//// +//// var self = this; +//// var transactionCounter = 0; +//// var final_create; +//// +//// function createOffer(callback) { +//// var tx = $.remote.transaction(); +//// tx.offer_create("root", "500", "100/USD/root"); +//// +//// tx.once('proposed', function(m) { +//// $.remote.ledger_accept(); +//// }); +//// +//// tx.once('error', callback); +//// +//// tx.once('final', function(m) { +//// callback(); +//// }); +//// +//// tx.submit(); +//// }; +//// +//// function lotsOfTransactions(count, callback) { +//// ;(function nextOffer(i) { +//// createOffer(function(err) { +//// console.log(i, count); +//// if (err) callback(err); +//// else if (++i === count) callback(null); +//// else nextOffer(i); +//// }); +//// })(0); +//// }; +//// +//// function firstBatch() { +//// lotsOfTransactions(FIRST_BATCH, function(a, b) { +//// runTests(self, FIRST_BATCH, 0, void(0), function() { +//// console.log('2'); +//// runTests(self, FIRST_BATCH, OFFSET, void(0), function() { +//// console.log('3'); +//// runTests(self, FIRST_BATCH, -1, LIMIT, secondBatch); +//// }) +//// })}); +//// } +//// +//// function secondBatch() { +//// lotsOfTransactions(SECOND_BATCH, function() { +//// runTests(self, FIRST_BATCH+SECOND_BATCH, 0, void(0), function() { +//// runTests(self, FIRST_BATCH+SECOND_BATCH, OFFSET, void(0), thirdBatch); +//// })}); +//// } +//// +//// function thirdBatch() { +//// lotsOfTransactions(THIRD_BATCH, function() { +//// runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, 0, void(0), function() { +//// runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, OFFSET, void(0), done); +//// })}); +//// } +//// +//// firstBatch(); +//// +//// function errorHandler(callback) { +//// return function(r) { +//// if (VERBOSE) console.log("ERROR!"); +//// if (VERBOSE) console.log(r); +//// callback(r); +//// } +//// } +//// +//// function txOptions(ext) { +//// var defaults = { +//// account: ACCOUNT, +//// ledger_index_min: -1, +//// ledger_index_max: -1 +//// } +//// return extend(defaults, ext); +//// }; +//// +//// function sortByLedger(a, b) { +//// assert(a.tx, 'Transaction missing'); +//// assert(b.tx, 'Transaction missing'); +//// if (a.tx.inLedger > b.tx.inLedger) { +//// return 1; +//// } else if (a.tx.inLedger < b.tx.inLedger) { +//// return -1; +//// } else { +//// return 0; +//// } +//// }; +//// +//// function runTests(self, transactionCount, offset, limit, callback) { +//// var steps = [ +//// function(callback) { +//// if (VERBOSE) console.log('nonbinary'); +//// +//// var req = $.remote.request_account_tx(txOptions({ offset: offset, limit: limit })); +//// +//// req.callback(function(err, r) { +//// if (err) return callback(err); +//// assert(r && r.transactions); +//// var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit, transactionCount - offset) : transactionCount - offset); +//// assert.strictEqual(r.transactions.length, targetLength, 'Transactions unexpected length'); +//// //assert.deepEqual(r.transactions.sort(sortByLedger), r.transactions, 'Transactions out of order'); +//// callback(); +//// }); +//// }, +//// +//// function(callback) { +//// if (VERBOSE) console.log('binary'); +//// +//// var req = $.remote.request_account_tx(txOptions({ binary: true, offset: offset, limit: limit })); +//// +//// req.callback(function(err, r) { +//// if (err) return callback(err); +//// assert(r && r.transactions); +//// var targetLength = Math.min(BINARY_LIMIT, limit ? Math.min(limit, transactionCount-offset) : transactionCount-offset); +//// assert.strictEqual(r.transactions.length, targetLength, 'Transactions unexpected length'); +//// //assert.deepEqual(r.transactions.sort(sortByLedger), r.transactions, 'Transactions out of order'); +//// callback(); +//// }); +//// }, +//// +//// function(callback) { +//// if (VERBOSE) console.log('nonbinary+offset'); +//// +//// var req = $.remote.request_account_tx(txOptions({ descending: true, offset: offset, limit: limit })); +//// +//// req.callback(function(err, r) { +//// if (err) return callback(err); +//// assert(r && r.transactions); +//// var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit,transactionCount-offset) : transactionCount-offset ); +//// assert.strictEqual(r.transactions.length, targetLength, 'Transactions unexpected length'); +//// //assert.deepEqual(r.transactions.sort(sortByLedger), r.transactions, 'Transactions out of order'); +//// callback(); +//// }); +//// } +//// ] +//// +//// async.series(steps, function(error) { +//// console.log(error); +//// assert.ifError(error); +//// callback(); +//// }); +//// } +//// }); +////}); +//======= +//var async = require("async"); +//var buster = require("buster"); +// +//var Amount = require("ripple-lib").Amount; +//var Remote = require("ripple-lib").Remote; +//var Transaction = require("ripple-lib").Transaction; +//var Server = require("./server").Server; +// +//var testutils = require("./testutils"); +//var config = testutils.init_config(); +// +//buster.testRunner.timeout = 350000; //This is a very long test! +// +// +//// Hard-coded limits we'll be testing: +//var BINARY_LIMIT = 500; +//var NONBINARY_LIMIT = 200; +// +//var ACCOUNT = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"; +//var FIRST_BATCH = 199; // Within both limits +//var OFFSET = 180; +//var LIMIT = 170; +//var SECOND_BATCH = 10; // Between NONBINARY_LIMIT and BINARY_LIMIT +//var THIRD_BATCH = 295; // Exceeds both limits +//var VERBOSE = false; +// +//buster.testCase("//Account_tx tests", { +// 'setUp' : testutils.build_setup(), +// 'tearDown' : testutils.build_teardown(), +// +// "make a lot of transactions and query using account_tx" : function (done) { +// var self = this; +// var final_create; +// var transactionCounter = 0; +// var f = 0; +// var functionHolder; +// var createOfferFunction = function (callback) { +// self.remote.transaction() +// .offer_create("root", "500", "100/USD/root") +// .on('proposed', function (m) { +// transactionCounter++; +// if (VERBOSE) console.log('Submitted transaction', transactionCounter); +// +// callback(m.result !== 'tesSUCCESS'); +// }) +// .on('final', function (m) { +// f++; +// if (VERBOSE) console.log("Finalized transaction", f); +// buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); +// buster.assert(final_create); +// if ( f == transactionCounter ) { +// if (VERBOSE) console.log("All transactions have been finalized."); +// functionHolder(); +// } +// }) +// .submit(); +// }; +// +// function lotsOfTransactions(number, whenDone) { +// var bunchOfOffers = []; +// for (var i=0; it2.inLedger || (t1.inLedger==t2.inLedger && t1.Sequence > t2.Sequence ), +// // "Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence); +// buster.assert(t1.inLedger>=t2.inLedger, +// "Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence); +// } +// } else { +// buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit); +// } +// +// +// callback(false); +// }) +// .on('error', standardErrorHandler(callback)) +// .request(); +// }, +// +// +// ], function (error) { +// buster.refute(error); +// finalCallback(); +// } +// ); +// } +// } +//}); +// +// +// +//// TODO: +//// Test the "count" feature. diff --git a/test/buster.js b/test/buster.js deleted file mode 100644 index a62cd49dc..000000000 --- a/test/buster.js +++ /dev/null @@ -1,11 +0,0 @@ -var config = module.exports; - -config["Ripple tests"] = { - rootPath: "../", - environment: "node", - tests: [ - "test/*-test.js" - ] -} - -// vim:sw=2:sts=2:ts=8:et diff --git a/test/jsonrpc-test.js b/test/jsonrpc-test.js index 7a6b9d61d..abd6922a5 100644 --- a/test/jsonrpc-test.js +++ b/test/jsonrpc-test.js @@ -1,188 +1,172 @@ -var async = require("async"); -var buster = require("buster"); -var http = require("http"); -var jsonrpc = require("simple-jsonrpc"); -var EventEmitter = require('events').EventEmitter; +var async = require("async"); +var assert = require('assert'); +var http = require("http"); +var jsonrpc = require("simple-jsonrpc"); +var EventEmitter = require('events').EventEmitter; +var Remote = require("ripple-lib").Remote; +var testutils = require("./testutils"); +var config = testutils.init_config(); -var Amount = require("ripple-lib").Amount; -var Remote = require("ripple-lib").Remote; -var Server = require("./server").Server; - -var testutils = require("./testutils"); - -var config = testutils.init_config(); - -// How long to wait for server to start. -var serverDelay = 1500; - -buster.testRunner.timeout = 5000; - -var server; -var server_events; - -var build_setup = function (options) { +function build_setup(options) { var setup = testutils.build_setup(options); return function (done) { - var self = this; + var self = this; - var http_config = config.http_servers["zed"]; + var http_config = config.http_servers["zed"]; - server_events = new EventEmitter; - server = http.createServer(function (req, res) { - // console.log("REQUEST"); - var input = ""; + self.server_events = new EventEmitter; - req.setEncoding(); + self.server = http.createServer(function (req, res) { + // console.log("REQUEST"); + var input = ""; - req.on('data', function (buffer) { - // console.log("DATA: %s", buffer); + req.setEncoding('utf8'); - input = input + buffer; - }); + req.on('data', function (buffer) { + // console.log("DATA: %s", buffer); + input = input + buffer; + }); - req.on('end', function () { - // console.log("END"); - var request = JSON.parse(input); + req.on('end', function () { + var request = JSON.parse(input); + // console.log("REQ: %s", JSON.stringify(request, undefined, 2)); + self.server_events.emit('request', request, res); + }); - // console.log("REQ: %s", JSON.stringify(request, undefined, 2)); + req.on('close', function () { }); + }); - server_events.emit('request', request, res); - }); - - req.on('close', function () { - // console.log("CLOSE"); - }); - }); - - server.listen(http_config.port, http_config.ip, undefined, - function () { - // console.log("server up: %s %d", http_config.ip, http_config.port); - - setup.call(self, done); - }); - }; + self.server.listen(http_config.port, http_config.ip, void(0), function () { + // console.log("server up: %s %d", http_config.ip, http_config.port); + setup.call(self, done); + }); + }; }; -var build_teardown = function () { +function build_teardown() { var teardown = testutils.build_teardown(); return function (done) { var self = this; - server.close(function () { - // console.log("server closed"); - - teardown.call(self, done); - }); + self.server.close(function () { + // console.log("server closed"); + + teardown.call(self, done); + }); }; }; -buster.testCase("JSON-RPC", { - setUp : build_setup(), - // setUp : build_setup({ verbose: true }), - // setUp : build_setup({verbose: true , no_server: true}), - tearDown : build_teardown(), +suite('JSON-RPC', function() { + var $ = { }; - "server_info" : - function (done) { - var rippled_config = config.servers.alpha; - var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port); + setup(function(done) { + build_setup().call($, done); + }); - client.call('server_info', [], function (result) { - // console.log(JSON.stringify(result, undefined, 2)); - buster.assert('info' in result); + teardown(function(done) { + build_teardown().call($, done); + }); - done(); - }); - }, + test('server info', function(done) { + var rippled_config = config.servers.alpha; + var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port); - "subscribe server" : - function (done) { - var rippled_config = config.servers.alpha; - var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port); - var http_config = config.http_servers["zed"]; + client.call('server_info', [ ], function (result) { + // console.log(JSON.stringify(result, undefined, 2)); + assert(typeof result === 'object'); + assert('info' in result); + done(); + }); + }); - client.call('subscribe', [{ + test('subscribe server', function(done) { + var rippled_config = config.servers.alpha; + var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port); + var http_config = config.http_servers["zed"]; + + client.call('subscribe', [{ + 'url' : "http://" + http_config.ip + ":" + http_config.port, + 'streams' : [ 'server' ], + }], function (result) { + // console.log(JSON.stringify(result, undefined, 2)); + assert(typeof result === 'object'); + assert('random' in result); + done(); + }); + }); + + test('subscribe ledger', function(done) { + var self = this; + + var rippled_config = config.servers.alpha; + var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port); + var http_config = config.http_servers["zed"]; + + var steps = [ + function (callback) { + self.what = "Subscribe."; + + client.call('subscribe', [{ 'url' : "http://" + http_config.ip + ":" + http_config.port, - 'streams' : [ 'server' ], + 'streams' : [ 'ledger' ], }], function (result) { - // console.log(JSON.stringify(result, undefined, 2)); - - buster.assert('random' in result); - - done(); + //console.log(JSON.stringify(result, undefined, 2)); + assert(typeof result === 'object'); + assert('ledger_index' in result); + callback(); }); - }, + }, - "subscribe ledger" : - function (done) { - var self = this; + function (callback) { + self.what = "Accept a ledger."; - var rippled_config = config.servers.alpha; - var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port); - var http_config = config.http_servers["zed"]; + $.server_events.once('request', function (request, response) { + // console.log("GOT: %s", JSON.stringify(request, undefined, 2)); - async.waterfall([ - function (callback) { - self.what = "Subscribe."; + assert.strictEqual(1, request.params.seq); + assert.strictEqual(3, request.params.ledger_index); - client.call('subscribe', [{ - 'url' : "http://" + http_config.ip + ":" + http_config.port, - 'streams' : [ 'ledger' ], - }], function (result) { - //console.log(JSON.stringify(result, undefined, 2)); + response.statusCode = 200; + response.end(JSON.stringify({ + jsonrpc: "2.0", + result: {}, + id: request.id + })); - buster.assert('ledger_index' in result); - - callback(); - }); - }, - function (callback) { - self.what = "Accept a ledger."; - - server_events.once('request', function (request, response) { - // console.log("GOT: %s", JSON.stringify(request, undefined, 2)); - - buster.assert.equals(1, request.params.seq); - buster.assert.equals(3, request.params.ledger_index); - - response.statusCode = 200; - response.end(JSON.stringify({ - jsonrpc: "2.0", - result: {}, - id: request.id - })); - - callback(); - }); - - self.remote.ledger_accept(); - }, - function (callback) { - self.what = "Accept another ledger."; - - server_events.once('request', function (request, response) { - // console.log("GOT: %s", JSON.stringify(request, undefined, 2)); - - buster.assert.equals(2, request.params.seq); - buster.assert.equals(4, request.params.ledger_index); - - response.statusCode = 200; - response.end(JSON.stringify({ - jsonrpc: "2.0", - result: {}, - id: request.id - })); - - callback(); - }); - - self.remote.ledger_accept(); - }, - ], function (error) { - buster.refute(error, self.what); - done(); + callback(); }); - } + + $.remote.ledger_accept(); + }, + + function (callback) { + self.what = "Accept another ledger."; + + $.server_events.once('request', function (request, response) { + // console.log("GOT: %s", JSON.stringify(request, undefined, 2)); + + assert.strictEqual(2, request.params.seq); + assert.strictEqual(4, request.params.ledger_index); + + response.statusCode = 200; + response.end(JSON.stringify({ + jsonrpc: "2.0", + result: {}, + id: request.id + })); + + callback(); + }); + + $.remote.ledger_accept(); + } + ] + + async.waterfall(steps, function(error) { + assert(!error, self.what); + done(); + }); + }); }); diff --git a/test/monitor-test.js b/test/monitor-test.js index e2ef06a73..8ed07617a 100644 --- a/test/monitor-test.js +++ b/test/monitor-test.js @@ -1,52 +1,53 @@ var async = require("async"); -var buster = require("buster"); - -var Amount = require("ripple-lib").Amount; +var assert = require('assert'); var Remote = require("ripple-lib").Remote; -var Server = require("./server").Server; - var testutils = require("./testutils"); var config = testutils.init_config(); -buster.testRunner.timeout = 5000; +suite('Monitor account', function() { + var $ = { }; -buster.testCase("//Monitor account", { - 'setUp' : testutils.build_setup({ verbose: true }), - 'tearDown' : testutils.build_teardown(), + setup(function(done) { + testutils.build_setup().call($, done); + }); - "monitor root" : - function (done) { - var self = this; + teardown(function(done) { + testutils.build_teardown().call($, done); + }); - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + test('monitor root', function() { - testutils.create_accounts(self.remote, "root", "10000", ["alice"], callback); - }, - function (callback) { - self.what = "Close ledger."; + var self = this; - self.remote.once('ledger_closed', function () { - callback(); - }); + var steps = [ + function (callback) { + self.what = "Create accounts."; + testutils.create_accounts($.remote, "root", "10000", ["alice"], callback); + }, - self.remote.ledger_accept(); - }, - function (callback) { - self.what = "Dumping root."; + function (callback) { + self.what = "Close ledger."; + $.remote.once('ledger_closed', function () { + callback(); + }); + $.remote.ledger_accept(); + }, - testutils.account_dump(self.remote, "root", function (error) { - buster.refute(error); + function (callback) { + self.what = "Dumping root."; - callback(); - }); - }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); - }, + testutils.account_dump($.remote, "root", function (error) { + assert.ifError(error); + callback(); + }); + } + ] + + async.waterfall(steps, function(error) { + assert(!effor, self.what); + done(); + }); + }); }); // vim:sw=2:sts=2:ts=8:et diff --git a/test/offer-test.js b/test/offer-test.js index e81637b71..02a4c3d6c 100644 --- a/test/offer-test.js +++ b/test/offer-test.js @@ -1,30 +1,30 @@ - var async = require("async"); -var buster = require("buster"); - +var assert = require('assert'); var Amount = require("ripple-lib").Amount; var Remote = require("ripple-lib").Remote; var Transaction = require("ripple-lib").Transaction; var Server = require("./server").Server; - var testutils = require("./testutils"); var config = testutils.init_config(); -buster.testRunner.timeout = 5000; +suite("Offer tests", function() { + var $ = { }; -buster.testCase("Offer tests", { - 'setUp' : testutils.build_setup(), - // 'setUp' : testutils.build_setup({ verbose: true }), - // 'setUp' : testutils.build_setup({ verbose: true, standalone: true }), - 'tearDown' : testutils.build_teardown(), + setup(function(done) { + testutils.build_setup().call($, done); + }); - "offer create then cancel in one ledger" : function (done) { + teardown(function(done) { + testutils.build_teardown().call($, done); + }); + + test("offer create then cancel in one ledger", function (done) { var self = this; var final_create; async.waterfall([ function (callback) { - self.remote.transaction() + $.remote.transaction() .offer_create("root", "500", "100/USD/root") .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -33,14 +33,14 @@ buster.testCase("Offer tests", { .on('final', function (m) { // console.log("FINAL: offer_create: %s", JSON.stringify(m)); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); + assert.strictEqual('tesSUCCESS', m.metadata.TransactionResult); - buster.assert(final_create); + assert(final_create); }) .submit(); }, function (m, callback) { - self.remote.transaction() + $.remote.transaction() .offer_cancel("root", m.tx_json.Sequence) .on('submitted', function (m) { // console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m)); @@ -49,14 +49,14 @@ buster.testCase("Offer tests", { .on('final', function (m) { // console.log("FINAL: offer_cancel: %s", JSON.stringify(m, undefined, 2)); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); - buster.assert(final_create); + assert.strictEqual('tesSUCCESS', m.metadata.TransactionResult); + assert(final_create); done(); }) .submit(); }, function (m, callback) { - self.remote + $.remote .once('ledger_closed', function (message) { // console.log("LEDGER_CLOSED: %d: %s", ledger_index, ledger_hash); final_create = message; @@ -65,13 +65,13 @@ buster.testCase("Offer tests", { } ], function (error) { // console.log("result: error=%s", error); - buster.refute(error, self.what || "Unspecifide Error"); + assert(!error, self.what || "Unspecifide Error"); done(); }); - }, + }); - "offer create then offer create with cancel in one ledger" : function (done) { + test("offer create then offer create with cancel in one ledger", function (done) { var self = this; var final_create; var sequence_first; @@ -80,7 +80,7 @@ buster.testCase("Offer tests", { async.waterfall([ function (callback) { - self.remote.transaction() + $.remote.transaction() .offer_create("root", "500", "100/USD/root") .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -89,8 +89,8 @@ buster.testCase("Offer tests", { .on('final', function (m) { // console.log("FINAL: offer_create: %s", JSON.stringify(m)); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); - buster.assert(final_create); + assert.strictEqual('tesSUCCESS', m.metadata.TransactionResult); + assert(final_create); if (3 === ++dones) done(); @@ -101,7 +101,7 @@ buster.testCase("Offer tests", { sequence_first = m.tx_json.Sequence; // Test canceling existant offer. - self.remote.transaction() + $.remote.transaction() .offer_create("root", "300", "100/USD/root", undefined, sequence_first) .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -110,8 +110,8 @@ buster.testCase("Offer tests", { .on('final', function (m) { // console.log("FINAL: offer_create: %s", JSON.stringify(m)); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); - buster.assert(final_create); + assert.strictEqual('tesSUCCESS', m.metadata.TransactionResult); + assert(final_create); if (3 === ++dones) done(); @@ -122,16 +122,16 @@ buster.testCase("Offer tests", { sequence_second = m.tx_json.Sequence; self.what = "Verify offer canceled."; - testutils.verify_offer_not_found(self.remote, "root", sequence_first, callback); + testutils.verify_offer_not_found($.remote, "root", sequence_first, callback); }, function (callback) { self.what = "Verify offer replaced."; - testutils.verify_offer(self.remote, "root", sequence_second, "300", "100/USD/root", callback); + testutils.verify_offer($.remote, "root", sequence_second, "300", "100/USD/root", callback); }, function (callback) { // Test canceling non-existant offer. - self.remote.transaction() + $.remote.transaction() .offer_create("root", "400", "200/USD/root", undefined, sequence_first) .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -140,8 +140,8 @@ buster.testCase("Offer tests", { .on('final', function (m) { // console.log("FINAL: offer_create: %s", JSON.stringify(m)); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); - buster.assert(final_create); + assert.strictEqual('tesSUCCESS', m.metadata.TransactionResult); + assert(final_create); if (3 === ++dones) done(); @@ -149,7 +149,7 @@ buster.testCase("Offer tests", { .submit(); }, function (callback) { - self.remote + $.remote .once('ledger_closed', function (message) { // console.log("LEDGER_CLOSED: %d: %s", ledger_index, ledger_hash); final_create = message; @@ -158,20 +158,20 @@ buster.testCase("Offer tests", { } ], function (error) { // console.log("result: error=%s", error); - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "Offer create then self crossing offer, no trust lines with self" : function (done) { + test("offer create then self crossing offer, no trust lines with self", function (done) { var self = this; async.waterfall([ function (callback) { self.what = "Create first offer."; - self.remote.transaction() + $.remote.transaction() .offer_create("root", "500/BTC/root", "100/USD/root") .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -183,7 +183,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Create crossing offer."; - self.remote.transaction() + $.remote.transaction() .offer_create("root", "100/USD/root", "500/BTC/root") .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -194,12 +194,12 @@ buster.testCase("Offer tests", { } ], function (error) { // console.log("result: error=%s", error); - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "Offer create then crossing offer with XRP. Negative balance." : function (done) { + test("offer create then crossing offer with XRP. Negative balance.", function (done) { var self = this; var alices_initial_balance = 499946999680; @@ -208,22 +208,22 @@ buster.testCase("Offer tests", { async.waterfall([ function (callback) { self.what = "Create mtgox account."; - testutils.payment(self.remote, "root", "mtgox", 1149999730, callback); + testutils.payment($.remote, "root", "mtgox", 1149999730, callback); }, function (callback) { self.what = "Create alice account."; - testutils.payment(self.remote, "root", "alice", alices_initial_balance, callback); + testutils.payment($.remote, "root", "alice", alices_initial_balance, callback); }, function (callback) { self.what = "Create bob account."; - testutils.payment(self.remote, "root", "bob", bobs_initial_balance, callback); + testutils.payment($.remote, "root", "bob", bobs_initial_balance, callback); }, function (callback) { self.what = "Set transfer rate."; - self.remote.transaction() + $.remote.transaction() .account_set("mtgox") .transfer_rate(1005000000) .once('proposed', function (m) { @@ -235,7 +235,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Set limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "500/USD/mtgox", "bob" : "50/USD/mtgox", @@ -246,7 +246,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "mtgox" : [ "50/USD/alice", "2710505431213761e-33/USD/bob" ] }, @@ -255,7 +255,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Create first offer."; - self.remote.transaction() + $.remote.transaction() .offer_create("alice", "50/USD/mtgox", "150000.0") // get 50/USD pay 150000/XRP .once('proposed', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -267,7 +267,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Unfund offer."; - testutils.payments(self.remote, + testutils.payments($.remote, { "alice" : "100/USD/mtgox" }, @@ -276,7 +276,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Set limits 2."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "mtgox" : "0/USD/alice", }, @@ -285,7 +285,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Verify balances. 1"; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { "alice" : [ "-50/USD/mtgox" ], "bob" : [ "2710505431213761e-33/USD/mtgox" ], @@ -295,7 +295,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Create crossing offer."; - self.remote.transaction() + $.remote.transaction() .offer_create("bob", "2000.0", "1/USD/mtgox") // get 2,000/XRP pay 1/USD (has insufficient USD) .once('proposed', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -315,24 +315,24 @@ buster.testCase("Offer tests", { alices_num_transactions = 3; alices_tx_fee_units_total = alices_num_transactions * Transaction.fee_units["default"] - alices_tx_fees_total = self.remote.fee_tx(alices_tx_fee_units_total); + alices_tx_fees_total = $.remote.fee_tx(alices_tx_fee_units_total); alices_final_balance = Amount.from_json(alices_initial_balance) .subtract(alices_tx_fees_total); bobs_num_transactions = 2; bobs_tx_fee_units_total = bobs_num_transactions * Transaction.fee_units["default"] - bobs_tx_fees_total = self.remote.fee_tx(bobs_tx_fee_units_total); + bobs_tx_fees_total = $.remote.fee_tx(bobs_tx_fee_units_total); bobs_final_balance = Amount.from_json(bobs_initial_balance) .subtract(bobs_tx_fees_total); - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { "alice" : [ "-50/USD/mtgox", alices_final_balance.to_json()], "bob" : [ "2710505431213761e-33/USD/mtgox", bobs_final_balance.to_json() // bobs_final_balance.to_json() - // String(10199999920-(self.remote.fee_tx(2*(Transaction.fee_units['default'])))).to_number() + // String(10199999920-($.remote.fee_tx(2*(Transaction.fee_units['default'])))).to_number() ], }, callback); @@ -340,7 +340,7 @@ buster.testCase("Offer tests", { // function (callback) { // self.what = "Display ledger"; // -// self.remote.request_ledger('current', true) +// $.remote.request_ledger('current', true) // .on('success', function (m) { // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); // @@ -350,24 +350,24 @@ buster.testCase("Offer tests", { // }, ], function (error) { // console.log("result: error=%s", error); - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "Offer create then crossing offer with XRP. Reverse order." : function (done) { + test("offer create then crossing offer with XRP. Reverse order." , function (done) { var self = this; async.waterfall([ function (callback) { self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "100000.0", ["alice", "bob", "mtgox"], callback); + testutils.create_accounts($.remote, "root", "100000.0", ["alice", "bob", "mtgox"], callback); }, function (callback) { self.what = "Set limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "1000/USD/mtgox", "bob" : "1000/USD/mtgox" @@ -377,7 +377,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "mtgox" : "500/USD/alice" }, @@ -386,7 +386,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Create first offer."; - self.remote.transaction() + $.remote.transaction() .offer_create("bob", "1/USD/mtgox", "4000.0") // get 1/USD pay 4000/XRP : offer pays 4000 XRP for 1 USD .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -402,7 +402,7 @@ buster.testCase("Offer tests", { // Fully consume existing offer. // Pay 1 USD, get 4000 XRP. - self.remote.transaction() + $.remote.transaction() .offer_create("alice", "150000.0", "50/USD/mtgox") // get 150,000/XRP pay 50/USD : offer pays 1 USD for 3000 XRP .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -414,18 +414,18 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { - // "bob" : [ "1/USD/mtgox", String(100000000000-4000000000-(Number(self.remote.fee_tx(Transaction.fee_units['default'] * 2).to_json()))) ], - "bob" : [ "1/USD/mtgox", String(100000000000-4000000000-(self.remote.fee_tx(Transaction.fee_units['default'] * 2).to_number())) ], - "alice" : [ "499/USD/mtgox", String(100000000000+4000000000-(self.remote.fee_tx(Transaction.fee_units['default'] * 2).to_number())) ], + // "bob" : [ "1/USD/mtgox", String(100000000000-4000000000-(Number($.remote.fee_tx(Transaction.fee_units['default'] * 2).to_json()))) ], + "bob" : [ "1/USD/mtgox", String(100000000000-4000000000-($.remote.fee_tx(Transaction.fee_units['default'] * 2).to_number())) ], + "alice" : [ "499/USD/mtgox", String(100000000000+4000000000-($.remote.fee_tx(Transaction.fee_units['default'] * 2).to_number())) ], }, callback); }, // function (callback) { // self.what = "Display ledger"; // -// self.remote.request_ledger('current', true) +// $.remote.request_ledger('current', true) // .on('success', function (m) { // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); // @@ -435,24 +435,24 @@ buster.testCase("Offer tests", { // }, ], function (error) { // console.log("result: error=%s", error); - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "Offer create then crossing offer with XRP." : function (done) { + test("offer create then crossing offer with XRP.", function (done) { var self = this; async.waterfall([ function (callback) { self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "100000.0", ["alice", "bob", "mtgox"], callback); + testutils.create_accounts($.remote, "root", "100000.0", ["alice", "bob", "mtgox"], callback); }, function (callback) { self.what = "Set limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "1000/USD/mtgox", "bob" : "1000/USD/mtgox" @@ -462,7 +462,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "mtgox" : "500/USD/alice" }, @@ -471,7 +471,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Create first offer."; - self.remote.transaction() + $.remote.transaction() .offer_create("alice", "150000.0", "50/USD/mtgox") // pays 1 USD for 3000 XRP .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -483,7 +483,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Create crossing offer."; - self.remote.transaction() + $.remote.transaction() .offer_create("bob", "1/USD/mtgox", "4000.0") // pays 4000 XRP for 1 USD .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -499,17 +499,17 @@ buster.testCase("Offer tests", { // Fully consume new offer. // Pay 1 USD, get 3000 XRP. - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { - "alice" : [ "499/USD/mtgox", String(100000000000+3000000000-(self.remote.fee_tx(2*(Transaction.fee_units['default'])).to_number())) ], - "bob" : [ "1/USD/mtgox", String(100000000000-3000000000-(self.remote.fee_tx(2*(Transaction.fee_units['default'])).to_number())) ], + "alice" : [ "499/USD/mtgox", String(100000000000+3000000000-($.remote.fee_tx(2*(Transaction.fee_units['default'])).to_number())) ], + "bob" : [ "1/USD/mtgox", String(100000000000-3000000000-($.remote.fee_tx(2*(Transaction.fee_units['default'])).to_number())) ], }, callback); }, // function (callback) { // self.what = "Display ledger"; // -// self.remote.request_ledger('current', true) +// $.remote.request_ledger('current', true) // .on('success', function (m) { // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); // @@ -519,24 +519,24 @@ buster.testCase("Offer tests", { // }, ], function (error) { // console.log("result: error=%s", error); - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "Offer create then crossing offer with XRP with limit override." : function (done) { + test("offer create then crossing offer with XRP with limit override.", function (done) { var self = this; async.waterfall([ function (callback) { self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "100000.0", ["alice", "bob", "mtgox"], callback); + testutils.create_accounts($.remote, "root", "100000.0", ["alice", "bob", "mtgox"], callback); }, function (callback) { self.what = "Set limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "1000/USD/mtgox", // "bob" : "1000/USD/mtgox" @@ -546,7 +546,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "mtgox" : "500/USD/alice" }, @@ -555,7 +555,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Create first offer."; - self.remote.transaction() + $.remote.transaction() .offer_create("alice", "150000.0", "50/USD/mtgox") // 300 XRP = 1 USD .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -567,7 +567,7 @@ buster.testCase("Offer tests", { // function (callback) { // self.what = "Display ledger"; // -// self.remote.request_ledger('current', true) +// $.remote.request_ledger('current', true) // .on('success', function (m) { // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); // @@ -578,7 +578,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Create crossing offer."; - self.remote.transaction() + $.remote.transaction() .offer_create("bob", "1/USD/mtgox", "3000.0") // .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -590,17 +590,17 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { - "alice" : [ "499/USD/mtgox", String(100000000000+3000000000-(self.remote.fee_tx(2*(Transaction.fee_units['default'])).to_number())) ], - "bob" : [ "1/USD/mtgox", String(100000000000-3000000000-(self.remote.fee_tx(1*(Transaction.fee_units['default'])).to_number())) ], + "alice" : [ "499/USD/mtgox", String(100000000000+3000000000-($.remote.fee_tx(2*(Transaction.fee_units['default'])).to_number())) ], + "bob" : [ "1/USD/mtgox", String(100000000000-3000000000-($.remote.fee_tx(1*(Transaction.fee_units['default'])).to_number())) ], }, callback); }, // function (callback) { // self.what = "Display ledger"; // -// self.remote.request_ledger('current', true) +// $.remote.request_ledger('current', true) // .on('success', function (m) { // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); // @@ -610,19 +610,19 @@ buster.testCase("Offer tests", { // }, ], function (error) { // console.log("result: error=%s", error); - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "offer_create then ledger_accept then offer_cancel then ledger_accept." : function (done) { + test("offer_create then ledger_accept then offer_cancel then ledger_accept.", function (done) { var self = this; var final_create; var offer_seq; async.waterfall([ function (callback) { - self.remote.transaction() + $.remote.transaction() .offer_create("root", "500", "100/USD/root") .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -634,7 +634,7 @@ buster.testCase("Offer tests", { .on('final', function (m) { // console.log("FINAL: offer_create: %s", JSON.stringify(m)); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); + assert.strictEqual('tesSUCCESS', m.metadata.TransactionResult); final_create = m; @@ -644,7 +644,7 @@ buster.testCase("Offer tests", { }, function (callback) { if (!final_create) { - self.remote + $.remote .once('ledger_closed', function (mesage) { // console.log("LEDGER_CLOSED: %d: %s", ledger_index, ledger_hash); @@ -658,7 +658,7 @@ buster.testCase("Offer tests", { function (callback) { // console.log("CANCEL: offer_cancel: %d", offer_seq); - self.remote.transaction() + $.remote.transaction() .offer_cancel("root", offer_seq) .on('submitted', function (m) { // console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m)); @@ -667,8 +667,8 @@ buster.testCase("Offer tests", { .on('final', function (m) { // console.log("FINAL: offer_cancel: %s", JSON.stringify(m)); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); - buster.assert(final_create); + assert.strictEqual('tesSUCCESS', m.metadata.TransactionResult); + assert(final_create); done(); }) @@ -676,7 +676,7 @@ buster.testCase("Offer tests", { }, // See if ledger_accept will crash. function (callback) { - self.remote + $.remote .once('ledger_closed', function (mesage) { // console.log("LEDGER_CLOSED: A: %d: %s", ledger_index, ledger_hash); callback(); @@ -684,7 +684,7 @@ buster.testCase("Offer tests", { .ledger_accept(); }, function (callback) { - self.remote + $.remote .once('ledger_closed', function (mesage) { // console.log("LEDGER_CLOSED: B: %d: %s", ledger_index, ledger_hash); callback(); @@ -693,30 +693,32 @@ buster.testCase("Offer tests", { }, ], function (error) { // console.log("result: error=%s", error); - buster.refute(error, self.what); + assert(!error, self.what); if (error) done(); }); - }, + }); + + test("//new user offer_create then ledger_accept then offer_cancel then ledger_accept.", function (done) { + return done(); - "//new user offer_create then ledger_accept then offer_cancel then ledger_accept." : function (done) { var self = this; var final_create; var offer_seq; async.waterfall([ function (callback) { - self.remote.transaction() + $.remote.transaction() .payment('root', 'alice', "1000") .on('submitted', function (m) { // console.log("proposed: %s", JSON.stringify(m)); - buster.assert.equals(m.engine_result, 'tesSUCCESS'); + assert.strictEqual(m.engine_result, 'tesSUCCESS'); callback(); }) .submit() }, function (callback) { - self.remote.transaction() + $.remote.transaction() .offer_create("alice", "500", "100/USD/alice") .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -728,7 +730,7 @@ buster.testCase("Offer tests", { .on('final', function (m) { // console.log("FINAL: offer_create: %s", JSON.stringify(m)); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); + assert.strictEqual('tesSUCCESS', m.metadata.TransactionResult); final_create = m; @@ -738,7 +740,7 @@ buster.testCase("Offer tests", { }, function (callback) { if (!final_create) { - self.remote + $.remote .once('ledger_closed', function (mesage) { // console.log("LEDGER_CLOSED: %d: %s", ledger_index, ledger_hash); @@ -752,7 +754,7 @@ buster.testCase("Offer tests", { function (callback) { // console.log("CANCEL: offer_cancel: %d", offer_seq); - self.remote.transaction() + $.remote.transaction() .offer_cancel("alice", offer_seq) .on('submitted', function (m) { // console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m)); @@ -761,8 +763,8 @@ buster.testCase("Offer tests", { .on('final', function (m) { // console.log("FINAL: offer_cancel: %s", JSON.stringify(m)); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); - buster.assert(final_create); + assert.strictEqual('tesSUCCESS', m.metadata.TransactionResult); + assert(final_create); done(); }) @@ -770,7 +772,7 @@ buster.testCase("Offer tests", { }, // See if ledger_accept will crash. function (callback) { - self.remote + $.remote .once('ledger_closed', function (mesage) { // console.log("LEDGER_CLOSED: A: %d: %s", ledger_index, ledger_hash); callback(); @@ -778,7 +780,7 @@ buster.testCase("Offer tests", { .ledger_accept(); }, function (callback) { - self.remote + $.remote .once('ledger_closed', function (mesage) { // console.log("LEDGER_CLOSED: B: %d: %s", ledger_index, ledger_hash); callback(); @@ -787,18 +789,18 @@ buster.testCase("Offer tests", { }, ], function (error) { // console.log("result: error=%s", error); - buster.refute(error, self.what); + assert(!error, self.what); if (error) done(); }); - }, + }); - "offer cancel past and future sequence" : function (done) { + test("offer cancel past and future sequence", function (done) { var self = this; var final_create; async.waterfall([ function (callback) { - self.remote.transaction() + $.remote.transaction() .payment('root', 'alice', Amount.from_json("10000.0")) .once('submitted', function (m) { //console.log("PROPOSED: CreateAccount: %s", JSON.stringify(m)); @@ -806,14 +808,14 @@ buster.testCase("Offer tests", { }) .once('error', function(m) { //console.log("error: %s", m); - buster.assert(false); + assert(false); callback(m); }) .submit(); }, // Past sequence but wrong function (m, callback) { - self.remote.transaction() + $.remote.transaction() .offer_cancel("root", m.tx_json.Sequence) .once('submitted', function (m) { //console.log("PROPOSED: offer_cancel past: %s", JSON.stringify(m)); @@ -823,7 +825,7 @@ buster.testCase("Offer tests", { }, // Same sequence function (m, callback) { - self.remote.transaction() + $.remote.transaction() .offer_cancel("root", m.tx_json.Sequence+1) .once('submitted', function (m) { //console.log("PROPOSED: offer_cancel same: %s", JSON.stringify(m)); @@ -833,7 +835,7 @@ buster.testCase("Offer tests", { }, // Future sequence function (m, callback) { - self.remote.transaction() + $.remote.transaction() .offer_cancel("root", m.tx_json.Sequence+2) .once('submitted', function (m) { //console.log("ERROR: offer_cancel future: %s", JSON.stringify(m)); @@ -843,7 +845,7 @@ buster.testCase("Offer tests", { }, // See if ledger_accept will crash. function (callback) { - self.remote + $.remote .once('ledger_closed', function (message) { //console.log("LEDGER_CLOSED: A: %d: %s", message.ledger_index, message.ledger_hash); callback(); @@ -851,7 +853,7 @@ buster.testCase("Offer tests", { .ledger_accept(); }, function (callback) { - self.remote + $.remote .once('ledger_closed', function (mesage) { //console.log("LEDGER_CLOSED: B: %d: %s", message.ledger_index, message.ledger_hash); callback(); @@ -863,12 +865,12 @@ buster.testCase("Offer tests", { } ], function (error) { //console.log("result: error=%s", error); - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "ripple currency conversion : entire offer" : function (done) { + test("ripple currency conversion : entire offer", function (done) { // mtgox in, XRP out var self = this; var seq; @@ -877,17 +879,17 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); }, function (callback) { self.what = "Owner count 0."; - testutils.verify_owner_count(self.remote, "bob", 0, callback); + testutils.verify_owner_count($.remote, "bob", 0, callback); }, function (callback) { self.what = "Set limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "100/USD/mtgox", "bob" : "1000/USD/mtgox" @@ -897,7 +899,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Owner counts after trust."; - testutils.verify_owner_counts(self.remote, + testutils.verify_owner_counts($.remote, { "alice" : 1, "bob" : 1, @@ -907,7 +909,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "mtgox" : "100/USD/alice" }, @@ -916,7 +918,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Create offer."; - self.remote.transaction() + $.remote.transaction() .offer_create("bob", "100/USD/mtgox", "500") .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -929,7 +931,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Owner counts after offer create."; - testutils.verify_owner_counts(self.remote, + testutils.verify_owner_counts($.remote, { "alice" : 1, "bob" : 2, @@ -939,12 +941,12 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Verify offer balance."; - testutils.verify_offer(self.remote, "bob", seq, "100/USD/mtgox", "500", callback); + testutils.verify_offer($.remote, "bob", seq, "100/USD/mtgox", "500", callback); }, function (callback) { self.what = "Alice converts USD to XRP."; - self.remote.transaction() + $.remote.transaction() .payment("alice", "alice", "500") .send_max("100/USD/mtgox") .on('submitted', function (m) { @@ -957,9 +959,9 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { - "alice" : [ "0/USD/mtgox", String(10000000000+500-(self.remote.fee_tx(2*(Transaction.fee_units['default'])).to_number())) ], + "alice" : [ "0/USD/mtgox", String(10000000000+500-($.remote.fee_tx(2*(Transaction.fee_units['default'])).to_number())) ], "bob" : "100/USD/mtgox", }, callback); @@ -967,12 +969,12 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Verify offer consumed."; - testutils.verify_offer_not_found(self.remote, "bob", seq, callback); + testutils.verify_offer_not_found($.remote, "bob", seq, callback); }, function (callback) { self.what = "Owner counts after consumed."; - testutils.verify_owner_counts(self.remote, + testutils.verify_owner_counts($.remote, { "alice" : 1, "bob" : 1, @@ -980,12 +982,12 @@ buster.testCase("Offer tests", { callback); }, ], function (error) { - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "ripple currency conversion : offerer into debt" : function (done) { + test("ripple currency conversion : offerer into debt", function (done) { // alice in, carol out var self = this; var seq; @@ -994,12 +996,12 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "carol"], callback); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "carol"], callback); }, function (callback) { self.what = "Set limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "2000/EUR/carol", "bob" : "100/USD/alice", @@ -1010,7 +1012,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Create offer to exchange."; - self.remote.transaction() + $.remote.transaction() .offer_create("bob", "50/USD/alice", "200/EUR/carol") .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -1023,7 +1025,7 @@ buster.testCase("Offer tests", { // function (callback) { // self.what = "Alice converts USD to EUR via offer."; // -// self.remote.transaction() +// $.remote.transaction() // .offer_create("alice", "200/EUR/carol", "50/USD/alice") // .on('submitted', function (m) { // // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -1036,7 +1038,7 @@ buster.testCase("Offer tests", { // function (callback) { // self.what = "Verify balances."; // -// testutils.verify_balances(self.remote, +// testutils.verify_balances($.remote, // { // "alice" : [ "-50/USD/bob", "200/EUR/carol" ], // "bob" : [ "50/USD/alice", "-200/EUR/carol" ], @@ -1047,15 +1049,15 @@ buster.testCase("Offer tests", { // function (callback) { // self.what = "Verify offer consumed."; // -// testutils.verify_offer_not_found(self.remote, "bob", seq, callback); +// testutils.verify_offer_not_found($.remote, "bob", seq, callback); // }, ], function (error) { - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "ripple currency conversion : in parts" : function (done) { + test("ripple currency conversion : in parts", function (done) { var self = this; var seq; @@ -1063,12 +1065,12 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); }, function (callback) { self.what = "Set limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "200/USD/mtgox", "bob" : "1000/USD/mtgox" @@ -1078,7 +1080,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "mtgox" : "200/USD/alice" }, @@ -1087,7 +1089,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Create offer."; - self.remote.transaction() + $.remote.transaction() .offer_create("bob", "100/USD/mtgox", "500") .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -1100,7 +1102,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Alice converts USD to XRP."; - self.remote.transaction() + $.remote.transaction() .payment("alice", "alice", "200") .send_max("100/USD/mtgox") .on('submitted', function (m) { @@ -1113,14 +1115,14 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Verify offer balance."; - testutils.verify_offer(self.remote, "bob", seq, "60/USD/mtgox", "300", callback); + testutils.verify_offer($.remote, "bob", seq, "60/USD/mtgox", "300", callback); }, function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { - "alice" : [ "160/USD/mtgox", String(10000000000+200-(self.remote.fee_tx(2*(Transaction.fee_units['default'])).to_number())) ], + "alice" : [ "160/USD/mtgox", String(10000000000+200-($.remote.fee_tx(2*(Transaction.fee_units['default'])).to_number())) ], "bob" : "40/USD/mtgox", }, callback); @@ -1128,7 +1130,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Alice converts USD to XRP should fail due to PartialPayment."; - self.remote.transaction() + $.remote.transaction() .payment("alice", "alice", "600") .send_max("100/USD/mtgox") .on('submitted', function (m) { @@ -1141,7 +1143,7 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Alice converts USD to XRP."; - self.remote.transaction() + $.remote.transaction() .payment("alice", "alice", "600") .send_max("100/USD/mtgox") .set_flags('PartialPayment') @@ -1155,47 +1157,53 @@ buster.testCase("Offer tests", { function (callback) { self.what = "Verify offer consumed."; - testutils.verify_offer_not_found(self.remote, "bob", seq, callback); + testutils.verify_offer_not_found($.remote, "bob", seq, callback); }, function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { - "alice" : [ "100/USD/mtgox", String(10000000000+200+300-(self.remote.fee_tx(4*(Transaction.fee_units['default'])).to_number())) ], + "alice" : [ "100/USD/mtgox", String(10000000000+200+300-($.remote.fee_tx(4*(Transaction.fee_units['default'])).to_number())) ], "bob" : "100/USD/mtgox", }, callback); }, ], function (error) { - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); }); -buster.testCase("Offer cross currency", { - 'setUp' : testutils.build_setup(), - // 'setUp' : testutils.build_setup({ verbose: true }), - 'tearDown' : testutils.build_teardown(), +suite("Offer cross currency", function() { + var $ = { }; - "ripple cross currency payment - start with XRP" : function (done) { + setup(function(done) { + testutils.build_setup().call($, done); + }); + + teardown(function(done) { + testutils.build_teardown().call($, done); + }); + + test("ripple cross currency payment - start with XRP", function (done) { // alice --> [XRP --> carol --> USD/mtgox] --> bob var self = this; var seq; - // self.remote.set_trace(); + // $.remote.set_trace(); async.waterfall([ function (callback) { self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "carol", "mtgox"], callback); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "carol", "mtgox"], callback); }, function (callback) { self.what = "Set limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "carol" : "1000/USD/mtgox", "bob" : "2000/USD/mtgox" @@ -1205,7 +1213,7 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "mtgox" : "500/USD/carol" }, @@ -1214,7 +1222,7 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Create offer."; - self.remote.transaction() + $.remote.transaction() .offer_create("carol", "500.0", "50/USD/mtgox") .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -1227,7 +1235,7 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Alice send USD/mtgox converting from XRP."; - self.remote.transaction() + $.remote.transaction() .payment("alice", "bob", "25/USD/mtgox") .send_max("333.0") .on('submitted', function (m) { @@ -1240,7 +1248,7 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { // "alice" : [ "500" ], "bob" : "25/USD/mtgox", @@ -1251,31 +1259,31 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Verify offer consumed."; - testutils.verify_offer_not_found(self.remote, "bob", seq, callback); + testutils.verify_offer_not_found($.remote, "bob", seq, callback); }, ], function (error) { - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "ripple cross currency payment - end with XRP" : function (done) { + test("ripple cross currency payment - end with XRP", function (done) { // alice --> [USD/mtgox --> carol --> XRP] --> bob var self = this; var seq; - // self.remote.set_trace(); + // $.remote.set_trace(); async.waterfall([ function (callback) { self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "carol", "mtgox"], callback); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "carol", "mtgox"], callback); }, function (callback) { self.what = "Set limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "1000/USD/mtgox", "carol" : "2000/USD/mtgox" @@ -1285,7 +1293,7 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "mtgox" : "500/USD/alice" }, @@ -1294,7 +1302,7 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Create offer."; - self.remote.transaction() + $.remote.transaction() .offer_create("carol", "50/USD/mtgox", "500") .on('submitted', function (m) { // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -1307,7 +1315,7 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Alice send XRP to bob converting from USD/mtgox."; - self.remote.transaction() + $.remote.transaction() .payment("alice", "bob", "250") .send_max("333/USD/mtgox") .on('submitted', function (m) { @@ -1320,7 +1328,7 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { "alice" : "475/USD/mtgox", "bob" : "10000000250", @@ -1331,32 +1339,32 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Verify offer partially consumed."; - testutils.verify_offer(self.remote, "carol", seq, "25/USD/mtgox", "250", callback); + testutils.verify_offer($.remote, "carol", seq, "25/USD/mtgox", "250", callback); }, ], function (error) { - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "ripple cross currency bridged payment" : function (done) { + test("ripple cross currency bridged payment", function (done) { // alice --> [USD/mtgox --> carol --> XRP] --> [XRP --> dan --> EUR/bitstamp] --> bob var self = this; var seq_carol; var seq_dan; - //self.remote.set_trace(); + //$.remote.set_trace(); async.waterfall([ function (callback) { self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "carol", "dan", "bitstamp", "mtgox"], callback); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "carol", "dan", "bitstamp", "mtgox"], callback); }, function (callback) { self.what = "Set limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "1000/USD/mtgox", "bob" : "1000/EUR/bitstamp", @@ -1368,7 +1376,7 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "bitstamp" : "400/EUR/dan", "mtgox" : "500/USD/alice", @@ -1378,7 +1386,7 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Create offer carol."; - self.remote.transaction() + $.remote.transaction() .offer_create("carol", "50/USD/mtgox", "500") .once('proposed', function (m) { //console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -1391,7 +1399,7 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Create offer dan."; - self.remote.transaction() + $.remote.transaction() .offer_create("dan", "500", "50/EUR/bitstamp") .once('proposed', function (m) { //console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); @@ -1404,7 +1412,7 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Alice send EUR/bitstamp to bob converting from USD/mtgox."; - self.remote.transaction() + $.remote.transaction() .payment("alice", "bob", "30/EUR/bitstamp") .send_max("333/USD/mtgox") .path_add( [ { currency: "XRP" } ]) @@ -1418,7 +1426,7 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { "alice" : "470/USD/mtgox", "bob" : "30/EUR/bitstamp", @@ -1430,27 +1438,32 @@ buster.testCase("Offer cross currency", { function (callback) { self.what = "Verify carol offer partially consumed."; - testutils.verify_offer(self.remote, "carol", seq_carol, "20/USD/mtgox", "200", callback); + testutils.verify_offer($.remote, "carol", seq_carol, "20/USD/mtgox", "200", callback); }, function (callback) { self.what = "Verify dan offer partially consumed."; - testutils.verify_offer(self.remote, "dan", seq_dan, "200", "20/EUR/mtgox", callback); + testutils.verify_offer($.remote, "dan", seq_dan, "200", "20/EUR/mtgox", callback); }, ], function (error) { - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); }); -buster.testCase("Offer tests 3", { - 'setUp' : testutils.build_setup(), - // 'setUp' : testutils.build_setup({ verbose: true }), - // 'setUp' : testutils.build_setup({ verbose: true, standalone: true }), - 'tearDown' : testutils.build_teardown(), +suite("Offer tests 3", function() { + var $ = { }; - "offer fee consumes funds" : function (done) { + setup(function(done) { + testutils.build_setup().call($, done); + }); + + teardown(function(done) { + testutils.build_teardown().call($, done); + }); + + test("offer fee consumes funds", function (done) { var self = this; var final_create; @@ -1462,7 +1475,7 @@ buster.testCase("Offer tests 3", { // Alice has 3 entries in the ledger, via trust lines var max_owner_count = 3; // // We start off with a - var reserve_amount = self.remote.reserve(max_owner_count); + var reserve_amount = $.remote.reserve(max_owner_count); // console.log("\n"); // console.log("reserve_amount reserve(max_owner_count=%s): %s", max_owner_count, reserve_amount.to_human()); @@ -1477,13 +1490,13 @@ buster.testCase("Offer tests 3", { var fee_units_for_all_txs = ( Transaction.fee_units["default"] * max_txs_per_user ); - starting_xrp = reserve_amount.add(self.remote.fee_tx(fee_units_for_all_txs)) + starting_xrp = reserve_amount.add($.remote.fee_tx(fee_units_for_all_txs)) // console.log("starting_xrp after %s fee units: ", fee_units_for_all_txs, starting_xrp.to_human()); starting_xrp = starting_xrp.add(Amount.from_json('100.0')); // console.log("starting_xrp adding 100 xrp to sell", starting_xrp.to_human()); - testutils.create_accounts(self.remote, + testutils.create_accounts($.remote, "root", starting_xrp.to_json(), ["alice", "bob", "mtgox", "amazon", "bitstamp"], @@ -1492,7 +1505,7 @@ buster.testCase("Offer tests 3", { function (callback) { self.what = "Set limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : ["1000/USD/mtgox", "1000/USD/amazon","1000/USD/bitstamp"], "bob" : ["1000/USD/mtgox", "1000/USD/amazon"], @@ -1502,7 +1515,7 @@ buster.testCase("Offer tests 3", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "mtgox" : [ "500/USD/bob" ], }, @@ -1511,7 +1524,7 @@ buster.testCase("Offer tests 3", { function (callback) { self.what = "Create offer bob."; - self.remote.transaction() + $.remote.transaction() .offer_create("bob", "200.0", "200/USD/mtgox") .on('submitted', function (m) { // console.log("proposed: offer_create: %s", json.stringify(m)); @@ -1525,7 +1538,7 @@ buster.testCase("Offer tests 3", { // Ask for more than available to prove reserve works. self.what = "Create offer alice."; - self.remote.transaction() + $.remote.transaction() .offer_create("alice", "200/USD/mtgox", "200.0") .on('submitted', function (m) { // console.log("proposed: offer_create: %s", json.stringify(m)); @@ -1538,7 +1551,7 @@ buster.testCase("Offer tests 3", { // function (callback) { // self.what = "Display ledger"; // -// self.remote.request_ledger('current', true) +// $.remote.request_ledger('current', true) // .on('success', function (m) { // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); // @@ -1549,7 +1562,7 @@ buster.testCase("Offer tests 3", { function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { "alice" : [ "100/USD/mtgox", "350.0"], "bob" : ["400/USD/mtgox", ], @@ -1558,12 +1571,13 @@ buster.testCase("Offer tests 3", { }, ], function (error) { // console.log("result: error=%s", error); - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, - "offer create then cross offer" : function (done) { + }); + + test("offer create then cross offer", function (done) { var self = this; var final_create; @@ -1571,12 +1585,12 @@ buster.testCase("Offer tests 3", { function (callback) { self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); }, function (callback) { self.what = "Set transfer rate."; - self.remote.transaction() + $.remote.transaction() .account_set("mtgox") .transfer_rate(1005000000) .once('proposed', function (m) { @@ -1588,7 +1602,7 @@ buster.testCase("Offer tests 3", { function (callback) { self.what = "Set limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "1000/USD/mtgox", "bob" : "1000/USD/mtgox", @@ -1599,7 +1613,7 @@ buster.testCase("Offer tests 3", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "mtgox" : [ "1/USD/bob" ], "alice" : [ "50/USD/mtgox" ] @@ -1609,7 +1623,7 @@ buster.testCase("Offer tests 3", { function (callback) { self.what = "Set limits 2."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "mtgox" : "0/USD/alice", }, @@ -1618,7 +1632,7 @@ buster.testCase("Offer tests 3", { function (callback) { self.what = "Create offer alice."; - self.remote.transaction() + $.remote.transaction() .offer_create("alice", "50/USD/mtgox", "150000.0") .once('submitted', function (m) { // console.log("proposed: offer_create: %s", json.stringify(m)); @@ -1631,7 +1645,7 @@ buster.testCase("Offer tests 3", { function (callback) { self.what = "Create offer bob."; - self.remote.transaction() + $.remote.transaction() .offer_create("bob", "100.0", ".1/USD/mtgox") .once('submitted', function (m) { // console.log("proposed: offer_create: %s", json.stringify(m)); @@ -1644,7 +1658,7 @@ buster.testCase("Offer tests 3", { // function (callback) { // self.what = "Display ledger"; // -// self.remote.request_ledger('current', true) +// $.remote.request_ledger('current', true) // .on('success', function (m) { // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); // @@ -1655,7 +1669,7 @@ buster.testCase("Offer tests 3", { function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { "alice" : "-49.96666666666667/USD/mtgox", "bob" : "0.9665/USD/mtgox", @@ -1664,19 +1678,24 @@ buster.testCase("Offer tests 3", { }, ], function (error) { // console.log("result: error=%s", error); - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); }); -buster.testCase("Offer tfSell", { - 'setUp' : testutils.build_setup(), - // 'setUp' : testutils.build_setup({ verbose: true }), - // 'setUp' : testutils.build_setup({ verbose: true, standalone: true }), - 'tearDown' : testutils.build_teardown(), +suite("Offer tfSell", function() { + var $ = { }; - "basic sell" : function (done) { + setup(function(done) { + testutils.build_setup().call($, done); + }); + + teardown(function(done) { + testutils.build_teardown().call($, done); + }); + + test("basic sell", function (done) { var self = this; var final_create, seq_carol; @@ -1685,14 +1704,14 @@ buster.testCase("Offer tfSell", { // Provide micro amounts to compensate for fees to make results round nice. self.what = "Create accounts."; - var req_amount = self.remote.reserve(1).add(self.remote.fee_tx(20)).add(100000000); - testutils.create_accounts(self.remote, "root", req_amount.to_json(), + var req_amount = $.remote.reserve(1).add($.remote.fee_tx(20)).add(100000000); + testutils.create_accounts($.remote, "root", req_amount.to_json(), ["alice", "bob", "mtgox"], callback); }, function (callback) { self.what = "Set limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "1000/USD/mtgox", "bob" : "1000/USD/mtgox", @@ -1702,7 +1721,7 @@ buster.testCase("Offer tfSell", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "mtgox" : [ "500/USD/bob" ], }, @@ -1711,7 +1730,7 @@ buster.testCase("Offer tfSell", { function (callback) { self.what = "Create offer bob."; - self.remote.transaction() + $.remote.transaction() .offer_create("bob", "200.0", "200/USD/mtgox") .set_flags('Sell') // Should not matter at all. .on('submitted', function (m) { @@ -1729,7 +1748,7 @@ buster.testCase("Offer tfSell", { // Ask for more than available to prove reserve works. self.what = "Create offer alice."; - self.remote.transaction() + $.remote.transaction() .offer_create("alice", "200/USD/mtgox", "200.0") .set_flags('Sell') // Should not matter at all. .on('submitted', function (m) { @@ -1743,7 +1762,7 @@ buster.testCase("Offer tfSell", { // function (callback) { // self.what = "Display ledger"; // -// self.remote.request_ledger('current', true) +// $.remote.request_ledger('current', true) // .on('success', function (m) { // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); // @@ -1754,7 +1773,7 @@ buster.testCase("Offer tfSell", { function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { "alice" : [ "100/USD/mtgox", "250.0" ], "bob" : "400/USD/mtgox", @@ -1763,13 +1782,13 @@ buster.testCase("Offer tfSell", { }, ], function (error) { // console.log("result: error=%s", error); - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "2x sell exceed limit" : function (done) { + test("2x sell exceed limit", function (done) { var self = this; var final_create, seq_carol; @@ -1777,17 +1796,17 @@ buster.testCase("Offer tfSell", { function (callback) { // Provide micro amounts to compensate for fees to make results round nice. self.what = "Create accounts."; - var starting_xrp = self.amount_for({ + var starting_xrp = $.amount_for({ ledger_entries: 1, default_transactions: 2, extra: '100.0' }); - testutils.create_accounts(self.remote, "root", starting_xrp, ["alice", "bob", "mtgox"], callback); + testutils.create_accounts($.remote, "root", starting_xrp, ["alice", "bob", "mtgox"], callback); }, function (callback) { self.what = "Set limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "150/USD/mtgox", "bob" : "1000/USD/mtgox", @@ -1797,7 +1816,7 @@ buster.testCase("Offer tfSell", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "mtgox" : [ "500/USD/bob" ], }, @@ -1808,7 +1827,7 @@ buster.testCase("Offer tfSell", { // Taker pays 200 XRP for 100 USD. // Selling USD. - self.remote.transaction() + $.remote.transaction() .offer_create("bob", "100.0", "200/USD/mtgox") .on('submitted', function (m) { // console.log("proposed: offer_create: %s", json.stringify(m)); @@ -1825,7 +1844,7 @@ buster.testCase("Offer tfSell", { // Taker pays 100 USD for 100 XRP. // Selling XRP. // Will sell all 100 XRP and get more USD than asked for. - self.remote.transaction() + $.remote.transaction() .offer_create("alice", "100/USD/mtgox", "100.0") .set_flags('Sell') .on('submitted', function (m) { @@ -1841,7 +1860,7 @@ buster.testCase("Offer tfSell", { // function (callback) { // self.what = "Display ledger"; // -// self.remote.request_ledger('current', true) +// $.remote.request_ledger('current', true) // .on('success', function (m) { // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); // @@ -1852,7 +1871,7 @@ buster.testCase("Offer tfSell", { function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { "alice" : [ "200/USD/mtgox", "250.0" ], "bob" : "300/USD/mtgox", @@ -1861,20 +1880,25 @@ buster.testCase("Offer tfSell", { }, ], function (error) { // console.log("result: error=%s", error); - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); }); -buster.testCase("Client Issue #535", { - 'setUp' : testutils.build_setup(), - // 'setUp' : testutils.build_setup({ verbose: true }), - // 'setUp' : testutils.build_setup({ verbose: true, standalone: true }), - 'tearDown' : testutils.build_teardown(), +suite("Client Issue #535", function() { + var $ = { }; - "gateway cross currency" : function (done) { + setup(function(done) { + testutils.build_setup().call($, done); + }); + + teardown(function(done) { + testutils.build_teardown().call($, done); + }); + + test("gateway cross currency", function (done) { var self = this; var final_create; @@ -1883,18 +1907,18 @@ buster.testCase("Client Issue #535", { // Provide micro amounts to compensate for fees to make results round nice. self.what = "Create accounts."; - var starting_xrp = self.amount_for({ + var starting_xrp = $.amount_for({ ledger_entries: 1, default_transactions: 2, extra: '100.0' }); - testutils.create_accounts(self.remote, "root", starting_xrp, ["alice", "bob", "mtgox"], callback); + testutils.create_accounts($.remote, "root", starting_xrp, ["alice", "bob", "mtgox"], callback); }, function (callback) { self.what = "Set limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : [ "1000/XTS/mtgox", "1000/XXX/mtgox" ], "bob" : [ "1000/XTS/mtgox", "1000/XXX/mtgox" ], @@ -1904,7 +1928,7 @@ buster.testCase("Client Issue #535", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "mtgox" : [ "100/XTS/alice", "100/XXX/alice", "100/XTS/bob", "100/XXX/bob", ], }, @@ -1913,7 +1937,7 @@ buster.testCase("Client Issue #535", { function (callback) { self.what = "Create offer alice."; - self.remote.transaction() + $.remote.transaction() .offer_create("alice", "100/XTS/mtgox", "100/XXX/mtgox") .on('submitted', function (m) { // console.log("proposed: offer_create: %s", json.stringify(m)); @@ -1926,7 +1950,7 @@ buster.testCase("Client Issue #535", { function (callback) { self.what = "Bob converts XTS to XXX."; - self.remote.transaction() + $.remote.transaction() .payment("bob", "bob", "1/XXX/bob") .send_max("1.5/XTS/bob") .build_path(true) @@ -1941,7 +1965,7 @@ buster.testCase("Client Issue #535", { // function (callback) { // self.what = "Display ledger"; // -// self.remote.request_ledger('current', true) +// $.remote.request_ledger('current', true) // .on('success', function (m) { // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); // @@ -1952,7 +1976,7 @@ buster.testCase("Client Issue #535", { function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { "alice" : [ "101/XTS/mtgox", "99/XXX/mtgox", ], "bob" : [ "99/XTS/mtgox", "101/XXX/mtgox", ], @@ -1962,10 +1986,10 @@ buster.testCase("Client Issue #535", { ], function (error) { if (error) //console.log("result: %s: error=%s", self.what, error); - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - } + }); }); -// vim:sw=2:sts=2:ts=8:et \ No newline at end of file +// vim:sw=2:sts=2:ts=8:et diff --git a/test/path-test.js b/test/path-test.js index bf89d9bec..411657120 100644 --- a/test/path-test.js +++ b/test/path-test.js @@ -1,72 +1,71 @@ var async = require("async"); -var buster = require("buster"); - +var assert = require('assert'); var Amount = require("ripple-lib").Amount; var Remote = require("ripple-lib").Remote; var Transaction = require("ripple-lib").Transaction; var Server = require("./server").Server; - var testutils = require("./testutils"); var config = testutils.init_config(); +suite('Basic path finding', function() { + var $ = { }; -buster.testRunner.timeout = 5000; + setup(function(done) { + testutils.build_setup().call($, done); + }); -buster.testCase("Basic Path finding", { - 'setUp' : testutils.build_setup(), - // 'setUp' : testutils.build_setup({ verbose: true }), - // 'setUp' : testutils.build_setup({ verbose: true, no_server: true }), - 'tearDown' : testutils.build_teardown(), + teardown(function(done) { + testutils.build_teardown().call($, done); + }); - "no direct path, no intermediary -> no alternatives" : function (done) { + test("no direct path, no intermediary -> no alternatives", function (done) { var self = this; - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + var steps = [ + function (callback) { + self.what = "Create accounts."; + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob"], callback); + }, - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob"], callback); - }, - function (callback) { - self.what = "Find path from alice to bob"; + function (callback) { + self.what = "Find path from alice to bob"; + var request = $.remote.request_ripple_path_find("alice", "bob", "5/USD/bob", [ { 'currency' : "USD" } ]); + request.callback(function(err, m) { + if (m.alternatives.length) { + callback(new Error(m)); + } else { + callback(null); + } + }); + } + ] - self.remote.request_ripple_path_find("alice", "bob", "5/USD/bob", - [ { 'currency' : "USD" } ]) - .on('success', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + async.waterfall(steps, function (error) { + assert(!error, self.what); + done(); + }); + }); - callback(m.alternatives.length); - }) - .request(); - }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); - }, - - "direct path, no intermediary" : function (done) { + test("direct path, no intermediary", function (done) { var self = this; - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + var steps = [ + function (callback) { + self.what = "Create accounts."; + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob"], callback); + }, + function (callback) { + self.what = "Set credit limits."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob"], callback); - }, - function (callback) { - self.what = "Set credit limits."; - - testutils.credit_limits(self.remote, - { - "bob" : "700/USD/alice", - }, - callback); + testutils.credit_limits($.remote, { + "bob" : "700/USD/alice", }, + callback); + }, // function (callback) { // self.what = "Display ledger"; // -// self.remote.request_ledger('current', true) +// $.remote.request_ledger('current', true) // .on('success', function (m) { // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); // @@ -77,7 +76,7 @@ buster.testCase("Basic Path finding", { // function (callback) { // self.what = "Display available lines from alice"; // -// self.remote.request_account_lines("alice", undefined, 'CURRENT') +// $.remote.request_account_lines("alice", undefined, 'CURRENT') // .on('success', function (m) { // console.log("LINES: %s", JSON.stringify(m, undefined, 2)); // @@ -85,160 +84,155 @@ buster.testCase("Basic Path finding", { // }) // .request(); // }, - function (callback) { - self.what = "Find path from alice to bob"; + function (callback) { + self.what = "Find path from alice to bob"; + $.remote.request_ripple_path_find("alice", "bob", "5/USD/bob", + [ { 'currency' : "USD" } ]) + .on('success', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - 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. + assert.strictEqual(1, m.alternatives.length) + // Path is empty. + assert.strictEqual(0, m.alternatives[0].paths_canonical.length) - // 1 alternative. - buster.assert.equals(1, m.alternatives.length) - // Path is empty. - buster.assert.equals(0, m.alternatives[0].paths_canonical.length) + callback(); + }) + .request(); + }, + ] - callback(); - }) - .request(); - }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); - }, + async.waterfall(steps, function(error) { + assert(!error); + done(); + }); + }); - "payment auto path find (using build_path)" : function (done) { + test("payment auto path find (using build_path)", function (done) { + var self = this; + + var steps = [ + function (callback) { + self.what = "Create accounts."; + + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); + }, + function (callback) { + self.what = "Set credit limits."; + + testutils.credit_limits($.remote, + { + "alice" : "600/USD/mtgox", + "bob" : "700/USD/mtgox", + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; + + testutils.payments($.remote, + { + "mtgox" : [ "70/USD/alice" ], + }, + callback); + }, + function (callback) { + self.what = "Payment with auto path"; + + $.remote.transaction() + .payment('alice', 'bob', "24/USD/bob") + .build_path(true) + .once('submitted', function (m) { + //console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balances."; + + testutils.verify_balances($.remote, + { + "alice" : "46/USD/mtgox", + "mtgox" : [ "-46/USD/alice", "-24/USD/bob" ], + "bob" : "24/USD/mtgox", + }, + callback); + }, + ] + + async.waterfall(steps, function(error) { + assert(!error, self.what); + done(); + }); + }); + + test("path find", function (done) { + var self = this; + + var steps = [ + function (callback) { + self.what = "Create accounts."; + + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); + }, + function (callback) { + self.what = "Set credit limits."; + + testutils.credit_limits($.remote, + { + "alice" : "600/USD/mtgox", + "bob" : "700/USD/mtgox", + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; + + testutils.payments($.remote, + { + "mtgox" : [ "70/USD/alice", "50/USD/bob" ], + }, + callback); + }, + function (callback) { + self.what = "Find path from alice to mtgox"; + + $.remote.request_ripple_path_find("alice", "bob", "5/USD/mtgox", + [ { 'currency' : "USD" } ]) + .on('success', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + + // 1 alternative. + assert.strictEqual(1, m.alternatives.length) + // Path is empty. + assert.strictEqual(0, m.alternatives[0].paths_canonical.length) + + callback(); + }) + .request(); + } + ] + + async.waterfall(steps, function (error) { + assert(!error, self.what); + done(); + }); + }); + + test("alternative paths - consume both", function (done) { var self = this; async.waterfall([ function (callback) { self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox", "bitstamp"], callback); }, function (callback) { self.what = "Set credit limits."; - testutils.credit_limits(self.remote, - { - "alice" : "600/USD/mtgox", - "bob" : "700/USD/mtgox", - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; - - testutils.payments(self.remote, - { - "mtgox" : [ "70/USD/alice" ], - }, - callback); - }, - function (callback) { - self.what = "Payment with auto path"; - - self.remote.transaction() - .payment('alice', 'bob', "24/USD/bob") - .build_path(true) - .once('submitted', function (m) { - //console.log("proposed: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances."; - - testutils.verify_balances(self.remote, - { - "alice" : "46/USD/mtgox", - "mtgox" : [ "-46/USD/alice", "-24/USD/bob" ], - "bob" : "24/USD/mtgox", - }, - callback); - }, - ], function (error) { - //console.log(error); - buster.refute(error, self.what); - done(); - }); - }, - - "path find" : function (done) { - var self = this; - - async.waterfall([ - function (callback) { - self.what = "Create accounts."; - - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); - }, - function (callback) { - self.what = "Set credit limits."; - - testutils.credit_limits(self.remote, - { - "alice" : "600/USD/mtgox", - "bob" : "700/USD/mtgox", - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; - - testutils.payments(self.remote, - { - "mtgox" : [ "70/USD/alice", "50/USD/bob" ], - }, - callback); - }, - function (callback) { - self.what = "Find path from alice to mtgox"; - - self.remote.request_ripple_path_find("alice", "bob", "5/USD/mtgox", - [ { '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(); - }); - }, -}); - - - -buster.testCase("Extended 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 - consume both" : function (done) { - var self = this; - - async.waterfall([ - function (callback) { - self.what = "Create accounts."; - - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "mtgox", "bitstamp"], callback); - }, - function (callback) { - self.what = "Set credit limits."; - - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : [ "600/USD/mtgox", "800/USD/bitstamp" ], "bob" : [ "700/USD/mtgox", "900/USD/bitstamp" ] @@ -248,7 +242,7 @@ buster.testCase("Extended Path finding", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "bitstamp" : "70/USD/alice", "mtgox" : "70/USD/alice", @@ -258,19 +252,19 @@ buster.testCase("Extended Path finding", { function (callback) { self.what = "Payment with auto path"; - self.remote.transaction() + $.remote.transaction() .payment('alice', 'bob', "140/USD/bob") .build_path(true) .once('submitted', function (m) { // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); + callback(m.engine_result !== 'tesSUCCESS'); }) .submit(); }, function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { "alice" : [ "0/USD/mtgox", "0/USD/bitstamp" ], "bob" : [ "70/USD/mtgox", "70/USD/bitstamp" ], @@ -280,36 +274,36 @@ buster.testCase("Extended Path finding", { callback); }, ], function (error) { - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "alternative paths - consume best transfer" : function (done) { + test("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.0", ["alice", "bob", "mtgox", "bitstamp"], callback); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox", "bitstamp"], callback); }, function (callback) { self.what = "Set transfer rate."; - self.remote.transaction() + $.remote.transaction() .account_set("bitstamp") .transfer_rate(1e9*1.1) .once('submitted', function (m) { // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); + callback(m.engine_result !== 'tesSUCCESS'); }) .submit(); }, function (callback) { self.what = "Set credit limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : [ "600/USD/mtgox", "800/USD/bitstamp" ], "bob" : [ "700/USD/mtgox", "900/USD/bitstamp" ] @@ -319,7 +313,7 @@ buster.testCase("Extended Path finding", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "bitstamp" : "70/USD/alice", "mtgox" : "70/USD/alice", @@ -329,19 +323,19 @@ buster.testCase("Extended Path finding", { function (callback) { self.what = "Payment with auto path"; - self.remote.transaction() + $.remote.transaction() .payment('alice', 'bob', "70/USD/bob") .build_path(true) .once('submitted', function (m) { // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); + callback(m.engine_result !== 'tesSUCCESS'); }) .submit(); }, function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { "alice" : [ "0/USD/mtgox", "70/USD/bitstamp" ], "bob" : [ "70/USD/mtgox", "0/USD/bitstamp" ], @@ -351,36 +345,36 @@ buster.testCase("Extended Path finding", { callback); }, ], function (error) { - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "alternative paths - consume best transfer first" : function (done) { + test("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.0", ["alice", "bob", "mtgox", "bitstamp"], callback); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox", "bitstamp"], callback); }, function (callback) { self.what = "Set transfer rate."; - self.remote.transaction() + $.remote.transaction() .account_set("bitstamp") .transfer_rate(1e9*1.1) .once('submitted', function (m) { // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); + callback(m.engine_result !== 'tesSUCCESS'); }) .submit(); }, function (callback) { self.what = "Set credit limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : [ "600/USD/mtgox", "800/USD/bitstamp" ], "bob" : [ "700/USD/mtgox", "900/USD/bitstamp" ] @@ -390,7 +384,7 @@ buster.testCase("Extended Path finding", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "bitstamp" : "70/USD/alice", "mtgox" : "70/USD/alice", @@ -400,20 +394,20 @@ buster.testCase("Extended Path finding", { function (callback) { self.what = "Payment with auto path"; - self.remote.transaction() + $.remote.transaction() .payment('alice', 'bob', "77/USD/bob") .build_path(true) .send_max("100/USD/alice") .once('submitted', function (m) { // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); + callback(m.engine_result !== 'tesSUCCESS'); }) .submit(); }, function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { "alice" : [ "0/USD/mtgox", "62.3/USD/bitstamp" ], "bob" : [ "70/USD/mtgox", "7/USD/bitstamp" ], @@ -423,116 +417,115 @@ buster.testCase("Extended Path finding", { callback); }, ], function (error) { - buster.refute(error, self.what); + assert(!error, self.what); 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(), +suite('More path finding', function() { + var $ = { }; - // alice +- bitstamp -+ bob - // |- carol(fee) -| // To be excluded. - // |- dan(issue) -| - // |- mtgox -| - "// alternative paths - limit returned paths to best quality" : function (done) { - var self = this; + setup(function(done) { + testutils.build_setup().call($, done); + }); - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + teardown(function(done) { + testutils.build_teardown().call($, done); + }); - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "carol", "dan", "mtgox", "bitstamp"], callback); - }, - function (callback) { - self.what = "Set transfer rate."; + test("alternative paths - limit returned paths to best quality", function (done) { + var self = this; - self.remote.transaction() - .account_set("carol") - .transfer_rate(1e9*1.1) - .once('submitted', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Set credit limits."; + async.waterfall([ + function (callback) { + self.what = "Create accounts."; - 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); - }, -// XXX What should this check? - 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(); - }); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "carol", "dan", "mtgox", "bitstamp"], callback); }, + function (callback) { + self.what = "Set transfer rate."; - "alternative paths - consume best transfer" : function (done) { + $.remote.transaction() + .account_set("carol") + .transfer_rate(1e9*1.1) + .once('submitted', function (m) { + //console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Set credit limits."; + + testutils.credit_limits($.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($.remote, + { + "bitstamp" : "100/USD/alice", + "carol" : "100/USD/alice", + "mtgox" : "100/USD/alice", + }, + callback); + }, + // XXX What should this check? + function (callback) { + self.what = "Find path from alice to bob"; + + $.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) { + assert(!error, self.what); + done(); + }); + }); + + test("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.0", ["alice", "bob", "mtgox", "bitstamp"], callback); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox", "bitstamp"], callback); }, function (callback) { self.what = "Set transfer rate."; - self.remote.transaction() + $.remote.transaction() .account_set("bitstamp") .transfer_rate(1e9*1.1) .once('submitted', function (m) { // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); + callback(m.engine_result !== 'tesSUCCESS'); }) .submit(); }, function (callback) { self.what = "Set credit limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : [ "600/USD/mtgox", "800/USD/bitstamp" ], "bob" : [ "700/USD/mtgox", "900/USD/bitstamp" ] @@ -542,7 +535,7 @@ buster.testCase("More Path finding", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "bitstamp" : "70/USD/alice", "mtgox" : "70/USD/alice", @@ -552,19 +545,19 @@ buster.testCase("More Path finding", { function (callback) { self.what = "Payment with auto path"; - self.remote.transaction() + $.remote.transaction() .payment('alice', 'bob', "70/USD/bob") .build_path(true) .once('submitted', function (m) { // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); + callback(m.engine_result !== 'tesSUCCESS'); }) .submit(); }, function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { "alice" : [ "0/USD/mtgox", "70/USD/bitstamp" ], "bob" : [ "70/USD/mtgox", "0/USD/bitstamp" ], @@ -574,36 +567,36 @@ buster.testCase("More Path finding", { callback); }, ], function (error) { - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "alternative paths - consume best transfer first" : function (done) { + test("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.0", ["alice", "bob", "mtgox", "bitstamp"], callback); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox", "bitstamp"], callback); }, function (callback) { self.what = "Set transfer rate."; - self.remote.transaction() + $.remote.transaction() .account_set("bitstamp") .transfer_rate(1e9*1.1) .once('submitted', function (m) { // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); + callback(m.engine_result !== 'tesSUCCESS'); }) .submit(); }, function (callback) { self.what = "Set credit limits."; - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : [ "600/USD/mtgox", "800/USD/bitstamp" ], "bob" : [ "700/USD/mtgox", "900/USD/bitstamp" ] @@ -613,7 +606,7 @@ buster.testCase("More Path finding", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "bitstamp" : "70/USD/alice", "mtgox" : "70/USD/alice", @@ -623,20 +616,20 @@ buster.testCase("More Path finding", { function (callback) { self.what = "Payment with auto path"; - self.remote.transaction() + $.remote.transaction() .payment('alice', 'bob', "77/USD/bob") .build_path(true) .send_max("100/USD/alice") .once('submitted', function (m) { // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); + callback(m.engine_result !== 'tesSUCCESS'); }) .submit(); }, function (callback) { self.what = "Verify balances."; - testutils.verify_balances(self.remote, + testutils.verify_balances($.remote, { "alice" : [ "0/USD/mtgox", "62.3/USD/bitstamp" ], "bob" : [ "70/USD/mtgox", "7/USD/bitstamp" ], @@ -646,510 +639,518 @@ buster.testCase("More Path finding", { callback); }, ], function (error) { - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); + }); - // Test alternative paths with qualities. -}); + suite('Issues', function() { + var $ = { }; -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(), + setup(function(done) { + testutils.build_setup().call($, done); + }); - "Path negative: Issue #5" : function (done) { - var self = this; + teardown(function(done) { + testutils.build_teardown().call($, done); + }); - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + test("path negative: Issue #5", function (done) { + var self = this; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "carol", "dan"], callback); - }, - function (callback) { - self.what = "Set credit limits."; + async.waterfall([ + function (callback) { + self.what = "Create accounts."; - testutils.credit_limits(self.remote, - { - // 2. acct 4 trusted all the other accts for 100 usd - "dan" : [ "100/USD/alice", "100/USD/bob", "100/USD/carol" ], - // 3. acct 2 acted as a nexus for acct 1 and 3, was trusted by 1 and 3 for 100 usd - "alice" : [ "100/USD/bob" ], - "carol" : [ "100/USD/bob" ], - }, - callback); - }, - function (callback) { - // 4. acct 2 sent acct 3 a 75 iou - self.what = "Bob sends Carol 75."; + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "carol", "dan"], callback); + }, + function (callback) { + self.what = "Set credit limits."; - self.remote.transaction() - .payment("bob", "carol", "75/USD/bob") - .once('submitted', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + testutils.credit_limits($.remote, + { + // 2. acct 4 trusted all the other accts for 100 usd + "dan" : [ "100/USD/alice", "100/USD/bob", "100/USD/carol" ], + // 3. acct 2 acted as a nexus for acct 1 and 3, was trusted by 1 and 3 for 100 usd + "alice" : [ "100/USD/bob" ], + "carol" : [ "100/USD/bob" ], + }, + callback); + }, + function (callback) { + // 4. acct 2 sent acct 3 a 75 iou + self.what = "Bob sends Carol 75."; - callback(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances."; + $.remote.transaction() + .payment("bob", "carol", "75/USD/bob") + .once('submitted', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - testutils.verify_balances(self.remote, - { - "bob" : [ "-75/USD/carol" ], - "carol" : "75/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 (callback) { - self.what = "Find path from alice to bob"; + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balances."; - // 5. acct 1 sent a 25 usd iou to acct 2 - self.remote.request_ripple_path_find("alice", "bob", "25/USD/bob", - [ { 'currency' : "USD" } ]) - .on('success', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + testutils.verify_balances($.remote, + { + "bob" : [ "-75/USD/carol" ], + "carol" : "75/USD/bob", + }, + callback); + }, + // function (callback) { + // self.what = "Display ledger"; + // + // $.remote.request_ledger('current', true) + // .on('success', function (m) { + // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); + // + // callback(); + // }) + // .request(); + // }, + function (callback) { + self.what = "Find path from alice to bob"; - // 0 alternatives. - buster.assert.equals(0, m.alternatives.length) + // 5. acct 1 sent a 25 usd iou to acct 2 + $.remote.request_ripple_path_find("alice", "bob", "25/USD/bob", + [ { 'currency' : "USD" } ]) + .on('success', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - callback(); - }) - .request(); - }, - function (callback) { - self.what = "alice fails to send to bob."; + // 0 alternatives. + //assert.strictEqual(0, m.alternatives.length) - self.remote.transaction() - .payment('alice', 'bob', "25/USD/alice") - .once('submitted', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tecPATH_DRY'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances final."; + callback(m.alternatives.length !== 0); + }) + .request(); + }, + function (callback) { + self.what = "alice fails to send to bob."; - testutils.verify_balances(self.remote, - { - "alice" : [ "0/USD/bob", "0/USD/dan"], - "bob" : [ "0/USD/alice", "-75/USD/carol", "0/USD/dan" ], - "carol" : [ "75/USD/bob", "0/USD/dan" ], - "dan" : [ "0/USD/alice", "0/USD/bob", "0/USD/carol" ], - }, - callback); - }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); - }, + $.remote.transaction() + .payment('alice', 'bob', "25/USD/alice") + .once('submitted', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tecPATH_DRY'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balances final."; + + testutils.verify_balances($.remote, + { + "alice" : [ "0/USD/bob", "0/USD/dan"], + "bob" : [ "0/USD/alice", "-75/USD/carol", "0/USD/dan" ], + "carol" : [ "75/USD/bob", "0/USD/dan" ], + "dan" : [ "0/USD/alice", "0/USD/bob", "0/USD/carol" ], + }, + callback); + }, + ], function (error) { + assert(!error, self.what); + done(); + }); + }); - "Path negative: ripple-client issue #23: smaller" : // // alice -- limit 40 --> bob // alice --> carol --> dan --> bob // Balance of 100 USD Bob - Balance of 37 USD -> Rod // - function (done) { - var self = this; + test("path negative: ripple-client issue #23: smaller", function (done) { + var self = this; - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + 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.create_accounts($.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" ], - "carol" : [ "20/USD/alice" ], - "dan" : [ "20/USD/carol" ], - }, - callback); - }, - function (callback) { - self.what = "Payment."; + testutils.credit_limits($.remote, + { + "bob" : [ "40/USD/alice", "20/USD/dan" ], + "carol" : [ "20/USD/alice" ], + "dan" : [ "20/USD/carol" ], + }, + callback); + }, + function (callback) { + self.what = "Payment."; - self.remote.transaction() - .payment('alice', 'bob', "55/USD/bob") - .build_path(true) - .once('submitted', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances."; + $.remote.transaction() + .payment('alice', 'bob', "55/USD/bob") + .build_path(true) + .once('submitted', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + 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(); - }); - }, + testutils.verify_balances($.remote, + { + "bob" : [ "40/USD/alice", "15/USD/dan" ], + }, + callback); + }, + // function (callback) { + // self.what = "Display ledger"; + // + // $.remote.request_ledger('current', true) + // .on('success', function (m) { + // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); + // + // callback(); + // }) + // .request(); + // }, + ], function (error) { + assert(!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) { + test("path negative: ripple-client issue #23: larger", function (done) { + var self = this; + + async.waterfall([ + function (callback) { + self.what = "Create accounts."; + + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "carol", "dan", "amazon"], callback); + }, + function (callback) { + self.what = "Set credit limits."; + + testutils.credit_limits($.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."; + + $.remote.transaction() + .payment('alice', 'bob', "50/USD/bob") + .build_path(true) + .once('submitted', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balances."; + + testutils.verify_balances($.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"; + // + // $.remote.request_ledger('current', true) + // .on('success', function (m) { + // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); + // + // callback(); + // }) + // .request(); + // }, + ], function (error) { + assert(!error, self.what); + done(); + }); + }); + }); + + suite('Via offers', function() { + var $ = { }; + + setup(function(done) { + testutils.build_setup().call($, done); + }); + + teardown(function(done) { + testutils.build_teardown().call($, done); + }); + + //carol holds mtgoxAUD, sells mtgoxAUD for XRP + //bob will hold mtgoxAUD + //alice pays bob mtgoxAUD using XRP + test("via gateway", function (done) { var self = this; async.waterfall([ - function (callback) { - self.what = "Create accounts."; + 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.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "carol", "mtgox"], callback); + }, + function (callback) { + self.what = "Set transfer rate."; - 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."; + $.remote.transaction() + .account_set("mtgox") + .transfer_rate(1005000000) + .once('submitted', function (m) { + //console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Set credit limits."; - self.remote.transaction() - .payment('alice', 'bob', "50/USD/bob") - .build_path(true) - .once('submitted', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances."; + testutils.credit_limits($.remote, + { + "bob" : [ "100/AUD/mtgox" ], + "carol" : [ "100/AUD/mtgox" ], + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; - 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); - done(); - }); - } + testutils.payments($.remote, + { + "mtgox" : "50/AUD/carol", + }, + callback); + }, + function (callback) { + self.what = "Carol create offer."; + + $.remote.transaction() + .offer_create("carol", "50.0", "50/AUD/mtgox") + .once('submitted', function (m) { + //console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + + seq_carol = m.tx_json.Sequence; + }) + .submit(); + }, + function (callback) { + self.what = "Alice sends bob 10/AUD/mtgox using XRP."; + + //XXX Also try sending 10/AUX/bob + $.remote.transaction() + .payment("alice", "bob", "10/AUD/mtgox") + .build_path(true) + .send_max("100.0") + .once('submitted', function (m) { + //console.log("proposed: %s", JSON.stringify(m)); + + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balances."; + + testutils.verify_balances($.remote, + { + "bob" : "10/AUD/mtgox", + "carol" : "39.95/AUD/mtgox", + }, + callback); + }, + function (callback) { + self.what = "Display ledger"; + + $.remote.request_ledger('current', true) + .on('success', function (m) { + //console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); + + callback(); + }) + .request(); + }, + function (callback) { + self.what = "Find path from alice to bob"; + + // 5. acct 1 sent a 25 usd iou to acct 2 + $.remote.request_ripple_path_find("alice", "bob", "25/USD/bob", + [ { 'currency' : "USD" } ]) + .on('success', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + // 0 alternatives. + assert.strictEqual(0, m.alternatives.length) + callback(); + }) + .request(); + } + ], function (error) { + assert(!error, self.what); + done(); + }); + }); + + //carol holds mtgoxAUD, sells mtgoxAUD for XRP + //bob will hold mtgoxAUD + //alice pays bob mtgoxAUD using XRP + test("via gateway : FIX ME fails due to XRP rounding and not properly handling dry.", function (done) { + return done(); + + var self = this; + + async.waterfall([ + function (callback) { + self.what = "Create accounts."; + + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "carol", "mtgox"], callback); + }, + function (callback) { + self.what = "Set transfer rate."; + + $.remote.transaction() + .account_set("mtgox") + .transfer_rate(1005000000) + .once('submitted', function (m) { + //console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Set credit limits."; + + testutils.credit_limits($.remote, + { + "bob" : [ "100/AUD/mtgox" ], + "carol" : [ "100/AUD/mtgox" ], + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; + + testutils.payments($.remote, + { + "mtgox" : "50/AUD/carol", + }, + callback); + }, + function (callback) { + self.what = "Carol create offer."; + + $.remote.transaction() + .offer_create("carol", "50", "50/AUD/mtgox") + .once('submitted', function (m) { + // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + + seq_carol = m.tx_json.Sequence; + }) + .submit(); + }, + function (callback) { + self.what = "Alice sends bob 10/AUD/mtgox using XRP."; + + // XXX Also try sending 10/AUX/bob + $.remote.transaction() + .payment("alice", "bob", "10/AUD/mtgox") + .build_path(true) + .send_max("100") + .once('submitted', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balances."; + + testutils.verify_balances($.remote, + { + "bob" : "10/AUD/mtgox", + "carol" : "39.95/AUD/mtgox", + }, + callback); + }, + // function (callback) { + // self.what = "Display ledger"; + // + // $.remote.request_ledger('current', true) + // .on('success', function (m) { + // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); + // + // callback(); + // }) + // .request(); + // }, + // function (callback) { + // self.what = "Find path from alice to bob"; + // + // // 5. acct 1 sent a 25 usd iou to acct 2 + // $.remote.request_ripple_path_find("alice", "bob", "25/USD/bob", + // [ { 'currency' : "USD" } ]) + // .on('success', function (m) { + // // console.log("proposed: %s", JSON.stringify(m)); + // + // // 0 alternatives. + // assert.strictEqual(0, m.alternatives.length) + // + // callback(); + // }) + // .request(); + // }, + ], function (error) { + assert(!error, self.what); + done(); + }); + }); }); -buster.testCase("Via offers", { - 'setUp' : testutils.build_setup(), - // 'setUp' : testutils.build_setup({ verbose: true }), - // 'setUp' : testutils.build_setup({ verbose: true, no_server: true }), - 'tearDown' : testutils.build_teardown(), +suite('Indirect paths', function() { + var $ = { }; - "Via gateway" : - // carol holds mtgoxAUD, sells mtgoxAUD for XRP - // bob will hold mtgoxAUD - // alice pays bob mtgoxAUD using XRP - function (done) { + setup(function(done) { + testutils.build_setup().call($, done); + }); + + teardown(function(done) { + testutils.build_teardown().call($, done); + }); + + test("path find", function (done) { var self = this; async.waterfall([ function (callback) { self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "carol", "mtgox"], callback); - }, - function (callback) { - self.what = "Set transfer rate."; - - self.remote.transaction() - .account_set("mtgox") - .transfer_rate(1005000000) - .once('submitted', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .submit(); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "carol"], callback); }, function (callback) { self.what = "Set credit limits."; - testutils.credit_limits(self.remote, - { - "bob" : [ "100/AUD/mtgox" ], - "carol" : [ "100/AUD/mtgox" ], - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; - - testutils.payments(self.remote, - { - "mtgox" : "50/AUD/carol", - }, - callback); - }, - function (callback) { - self.what = "Carol create offer."; - - self.remote.transaction() - .offer_create("carol", "50.0", "50/AUD/mtgox") - .once('submitted', function (m) { - // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - - seq_carol = m.tx_json.Sequence; - }) - .submit(); - }, - function (callback) { - self.what = "Alice sends bob 10/AUD/mtgox using XRP."; - - // XXX Also try sending 10/AUX/bob - self.remote.transaction() - .payment("alice", "bob", "10/AUD/mtgox") - .build_path(true) - .send_max("100.0") - .once('submitted', 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, - { - "bob" : "10/AUD/mtgox", - "carol" : "39.95/AUD/mtgox", - }, - 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 (callback) { -// self.what = "Find path from alice to bob"; -// -// // 5. acct 1 sent a 25 usd iou to acct 2 -// self.remote.request_ripple_path_find("alice", "bob", "25/USD/bob", -// [ { 'currency' : "USD" } ]) -// .on('success', function (m) { -// // console.log("proposed: %s", JSON.stringify(m)); -// -// // 0 alternatives. -// buster.assert.equals(0, m.alternatives.length) -// -// callback(); -// }) -// .request(); -// }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); - }, - - "// Via gateway : FIX ME fails due to XRP rounding and not properly handling dry." : - // carol holds mtgoxAUD, sells mtgoxAUD for XRP - // bob will hold mtgoxAUD - // alice pays bob mtgoxAUD using XRP - function (done) { - var self = this; - - async.waterfall([ - function (callback) { - self.what = "Create accounts."; - - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "carol", "mtgox"], callback); - }, - function (callback) { - self.what = "Set transfer rate."; - - self.remote.transaction() - .account_set("mtgox") - .transfer_rate(1005000000) - .once('submitted', 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, - { - "bob" : [ "100/AUD/mtgox" ], - "carol" : [ "100/AUD/mtgox" ], - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; - - testutils.payments(self.remote, - { - "mtgox" : "50/AUD/carol", - }, - callback); - }, - function (callback) { - self.what = "Carol create offer."; - - self.remote.transaction() - .offer_create("carol", "50", "50/AUD/mtgox") - .once('submitted', function (m) { - // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - - seq_carol = m.tx_json.Sequence; - }) - .submit(); - }, - function (callback) { - self.what = "Alice sends bob 10/AUD/mtgox using XRP."; - - // XXX Also try sending 10/AUX/bob - self.remote.transaction() - .payment("alice", "bob", "10/AUD/mtgox") - .build_path(true) - .send_max("100") - .once('submitted', 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, - { - "bob" : "10/AUD/mtgox", - "carol" : "39.95/AUD/mtgox", - }, - 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 (callback) { -// self.what = "Find path from alice to bob"; -// -// // 5. acct 1 sent a 25 usd iou to acct 2 -// self.remote.request_ripple_path_find("alice", "bob", "25/USD/bob", -// [ { 'currency' : "USD" } ]) -// .on('success', function (m) { -// // console.log("proposed: %s", JSON.stringify(m)); -// -// // 0 alternatives. -// buster.assert.equals(0, m.alternatives.length) -// -// callback(); -// }) -// .request(); -// }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); - }, -}); - -buster.testCase("Indirect paths", { - 'setUp' : testutils.build_setup(), - // 'setUp' : testutils.build_setup({ verbose: true }), - // 'setUp' : testutils.build_setup({ verbose: true, no_server: true }), - 'tearDown' : testutils.build_teardown(), - - "path find" : - function (done) { - var self = this; - - async.waterfall([ - function (callback) { - self.what = "Create accounts."; - - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "carol"], callback); - }, - function (callback) { - self.what = "Set credit limits."; - - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "bob" : "1000/USD/alice", "carol" : "2000/USD/bob", @@ -1159,137 +1160,145 @@ buster.testCase("Indirect paths", { function (callback) { self.what = "Find path from alice to carol"; - self.remote.request_ripple_path_find("alice", "carol", "5/USD/carol", + $.remote.request_ripple_path_find("alice", "carol", "5/USD/carol", [ { 'currency' : "USD" } ]) .on('success', function (m) { // console.log("proposed: %s", JSON.stringify(m)); // 1 alternative. - buster.assert.equals(1, m.alternatives.length) + assert.strictEqual(1, m.alternatives.length) // Path is empty. - buster.assert.equals(0, m.alternatives[0].paths_canonical.length) + assert.strictEqual(0, m.alternatives[0].paths_canonical.length) callback(); }) .request(); - }, - ], function (error) { - buster.refute(error, self.what); + } ], function (error) { + assert(!error, self.what); done(); }); - }, + }); }); -buster.testCase("Quality paths", { - 'setUp' : testutils.build_setup(), - // 'setUp' : testutils.build_setup({ verbose: true }), - // 'setUp' : testutils.build_setup({ verbose: true, no_server: true }), - 'tearDown' : testutils.build_teardown(), +suite('Quality paths', function() { + var $ = { }; - "quality set and test" : - function (done) { - var self = this; + setup(function(done) { + testutils.build_setup().call($, done); + }); - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + teardown(function(done) { + testutils.build_teardown().call($, done); + }); - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob"], callback); - }, - function (callback) { - self.what = "Set credit limits extended."; + test("quality set and test", function (done) { + var self = this; - testutils.credit_limits(self.remote, - { - "bob" : "1000/USD/alice:2000,1400000000", - }, - callback); - }, - function (callback) { - self.what = "Verify credit limits extended."; + async.waterfall([ + function (callback) { + self.what = "Create accounts."; - testutils.verify_limit(self.remote, "bob", "1000/USD/alice:2000,1400000000", callback); - }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); - }, + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob"], callback); + }, + function (callback) { + self.what = "Set credit limits extended."; - "// quality payment (BROKEN DUE TO ROUNDING)" : - function (done) { - var self = this; + testutils.credit_limits($.remote, + { + "bob" : "1000/USD/alice:2000,1400000000", + }, + callback); + }, + function (callback) { + self.what = "Verify credit limits extended."; - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + testutils.verify_limit($.remote, "bob", "1000/USD/alice:2000,1400000000", callback); + }, + ], function (error) { + assert(!error, self.what); + done(); + }); + }); - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob"], callback); - }, - function (callback) { - self.what = "Set credit limits extended."; + test("// quality payment (BROKEN DUE TO ROUNDING)", function (done) { + var self = this; - testutils.credit_limits(self.remote, - { - "bob" : "1000/USD/alice:" + .9*1e9 + "," + 1e9, - }, - callback); - }, - function (callback) { - self.what = "Payment with auto path"; + return done(); - self.remote.trace = true; + async.waterfall([ + function (callback) { + self.what = "Create accounts."; - self.remote.transaction() - .payment('alice', 'bob', "100/USD/bob") - .send_max("120/USD/alice") + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob"], callback); + }, + function (callback) { + self.what = "Set credit limits extended."; + + testutils.credit_limits($.remote, + { + "bob" : "1000/USD/alice:" + .9*1e9 + "," + 1e9, + }, + callback); + }, + function (callback) { + self.what = "Payment with auto path"; + + $.remote.trace = true; + + $.remote.transaction() + .payment('alice', 'bob', "100/USD/bob") + .send_max("120/USD/alice") // .set_flags('PartialPayment') // .build_path(true) - .once('submitted', function (m) { - console.log("proposed: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Display ledger"; + .once('submitted', function (m) { + //console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Display ledger"; - self.remote.request_ledger('current', { accounts: true, expand: true }) - .on('success', function (m) { - console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); + $.remote.request_ledger('current', { accounts: true, expand: true }) + .on('success', function (m) { + //console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); - callback(); - }) - .request(); - }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); - }, + callback(); + }) + .request(); + }, + ], function (error) { + assert(!error, self.what); + done(); + }); + }); }); -buster.testCase("Trust auto clear", { - 'setUp' : testutils.build_setup(), - // 'setUp' : testutils.build_setup({ verbose: true }), - // 'setUp' : testutils.build_setup({ verbose: true, no_server: true }), - 'tearDown' : testutils.build_teardown(), +suite("Trust auto clear", function() { + var $ = { }; - "trust normal clear" : - function (done) { + setup(function(done) { + testutils.build_setup().call($, done); + }); + + teardown(function(done) { + testutils.build_teardown().call($, done); + }); + + test("trust normal clear", function (done) { var self = this; async.waterfall([ function (callback) { self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob"], callback); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob"], callback); }, function (callback) { self.what = "Set credit limits."; // Mutual trust. - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "1000/USD/bob", "bob" : "1000/USD/alice", @@ -1299,13 +1308,13 @@ buster.testCase("Trust auto clear", { function (callback) { self.what = "Verify credit limits."; - testutils.verify_limit(self.remote, "bob", "1000/USD/alice", callback); + testutils.verify_limit($.remote, "bob", "1000/USD/alice", callback); }, function (callback) { self.what = "Clear credit limits."; // Mutual trust. - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "0/USD/bob", "bob" : "0/USD/alice", @@ -1315,7 +1324,7 @@ buster.testCase("Trust auto clear", { function (callback) { self.what = "Verify credit limits."; - testutils.verify_limit(self.remote, "bob", "0/USD/alice", function (m) { + testutils.verify_limit($.remote, "bob", "0/USD/alice", function (m) { var success = m && 'remoteError' === m.error && 'entryNotFound' === m.remote.error; callback(!success); @@ -1323,26 +1332,25 @@ buster.testCase("Trust auto clear", { }, // YYY Could verify owner counts are zero. ], function (error) { - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); - "trust auto clear" : - function (done) { + test("trust auto clear", function (done) { var self = this; async.waterfall([ function (callback) { self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob"], callback); + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob"], callback); }, function (callback) { self.what = "Set credit limits."; // Mutual trust. - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "1000/USD/bob", }, @@ -1351,7 +1359,7 @@ buster.testCase("Trust auto clear", { function (callback) { self.what = "Distribute funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "bob" : [ "50/USD/alice" ], }, @@ -1361,7 +1369,7 @@ buster.testCase("Trust auto clear", { self.what = "Clear credit limits."; // Mutual trust. - testutils.credit_limits(self.remote, + testutils.credit_limits($.remote, { "alice" : "0/USD/bob", }, @@ -1370,12 +1378,12 @@ buster.testCase("Trust auto clear", { function (callback) { self.what = "Verify credit limits."; - testutils.verify_limit(self.remote, "alice", "0/USD/bob", callback); + testutils.verify_limit($.remote, "alice", "0/USD/bob", callback); }, function (callback) { self.what = "Return funds."; - testutils.payments(self.remote, + testutils.payments($.remote, { "alice" : [ "50/USD/bob" ], }, @@ -1384,16 +1392,16 @@ buster.testCase("Trust auto clear", { function (callback) { self.what = "Verify credit limit gone."; - testutils.verify_limit(self.remote, "bob", "0/USD/alice", function (m) { + testutils.verify_limit($.remote, "bob", "0/USD/alice", function (m) { var success = m && 'remoteError' === m.error && 'entryNotFound' === m.remote.error; callback(!success); }); }, ], function (error) { - buster.refute(error, self.what); + assert(!error, self.what); done(); }); - }, + }); }); // vim:sw=2:sts=2:ts=8:et diff --git a/test/remote-test.js b/test/remote-test.js index 37bec11e6..2b51151f4 100644 --- a/test/remote-test.js +++ b/test/remote-test.js @@ -1,233 +1,173 @@ -var buster = require("buster"); - -var Amount = require("ripple-lib").Amount; +var assert = require('assert'); var Remote = require("ripple-lib").Remote; -var Server = require("./server.js").Server; - var testutils = require("./testutils.js"); var config = testutils.init_config(); -// How long to wait for server to start. -var serverDelay = 1500; // XXX Not implemented. +suite('Remote functions', function() { + var $ = { }; -buster.testRunner.timeout = 5000 * 10; + setup(function(done) { + testutils.build_setup().call($, done); + }); -buster.testCase("Remote functions", { - 'setUp' : testutils.build_setup(), - 'tearDown' : testutils.build_teardown(), + teardown(function(done) { + testutils.build_teardown().call($, done); + }); - "request_ledger_current" : function (done) { - this.remote.request_ledger_current().on('success', function (m) { - buster.assert.equals(m.ledger_current_index, 3); - done(); - }) - .on('error', function(m) { - buster.assert(false); - }) + test('request_ledger_current', function(done) { + $.remote.request_ledger_current(function(err, m) { + assert(!err); + assert.strictEqual(m.ledger_current_index, 3); + done(); + }); + }); - .request(); - }, + test('request_ledger_hash', function(done) { + $.remote.request_ledger_hash(function(err, m) { + // console.log("result: %s", JSON.stringify(m)); + assert(!err); + assert.strictEqual(m.ledger_index, 2); + done(); + }) + }); - "request_ledger_hash" : function (done) { - this.remote.request_ledger_hash().on('success', function (m) { - // console.log("result: %s", JSON.stringify(m)); - - buster.assert.equals(m.ledger_index, 2); - done(); - }) - .on('error', function(m) { - // console.log("error: %s", m); - - buster.assert(false); - }) - .request(); - }, - - "manual account_root success" : function (done) { - var self = this; - - this.remote.request_ledger_hash().on('success', function (r) { - // console.log("result: %s", JSON.stringify(r)); - - self.remote - .request_ledger_entry('account_root') - .ledger_hash(r.ledger_hash) - .account_root("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh") - .on('success', function (r) { - // console.log("account_root: %s", JSON.stringify(r)); - - buster.assert('node' in r); - done(); - }) - .on('error', function(m) { - // console.log("error: %s", m); - - buster.assert(false); - }) - .request(); - }) - .on('error', function(m) { - // console.log("error: %s", m); - - buster.assert(false); - }) - .request(); - }, - - // XXX This should be detected locally. - "account_root remote malformedAddress" : function (done) { - var self = this; - - this.remote.request_ledger_hash().on('success', function (r) { - // console.log("result: %s", JSON.stringify(r)); - - self.remote - .request_ledger_entry('account_root') - .ledger_hash(r.ledger_hash) - .account_root("zHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh") - .on('success', function (r) { - // console.log("account_root: %s", JSON.stringify(r)); - buster.assert(false); - }) - .on('error', function(m) { - // console.log("error: %s", m); - buster.assert.equals(m.error, 'remoteError'); - buster.assert.equals(m.remote.error, 'malformedAddress'); - done(); - }) - .request(); - }) - .on('error', function(m) { - // console.log("error: %s", m); - - buster.assert(false); - }) - .request(); - }, - - "account_root entryNotFound" : function (done) { - var self = this; - - this.remote.request_ledger_hash().on('success', function (r) { - // console.log("result: %s", JSON.stringify(r)); - - self.remote - .request_ledger_entry('account_root') - .ledger_hash(r.ledger_hash) - .account_root("alice") - .on('success', function (r) { - // console.log("account_root: %s", JSON.stringify(r)); - - buster.assert(false); - }) - .on('error', function(m) { - // console.log("error: %s", m); - - buster.assert.equals(m.error, 'remoteError'); - buster.assert.equals(m.remote.error, 'entryNotFound'); - done(); - }) - .request(); - }) - .on('error', function(m) { - // console.log("error: %s", m); - - buster.assert(false); - }).request(); - }, - - "ledger_entry index" : function (done) { - var self = this; - - this.remote.request_ledger_hash().on('success', function (r) { - // console.log("result: %s", JSON.stringify(r)); - - self.remote - .request_ledger_entry('index') - .ledger_hash(r.ledger_hash) - .account_root("alice") - .index("2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8") - .on('success', function (r) { - // console.log("account_root: %s", JSON.stringify(r)); - - buster.assert('node_binary' in r); - done(); - }) - .on('error', function(m) { - // console.log("error: %s", m); - - buster.assert(false); - }). - request(); - }) - .on('error', function(m) { - // console.log(m); - - buster.assert(false); - }) - .request(); - }, - - "create account" : function (done) { + test('manual account_root success', function(done) { var self = this; - var root_id = this.remote.account('root')._account_id; - this.remote.request_subscribe().accounts(root_id).request(); + $.remote.request_ledger_hash(function(err, r) { + //console.log("result: %s", JSON.stringify(r)); + assert(!err); + assert('ledger_hash' in r); - this.remote.transaction() - .payment('root', 'alice', "10000.0") - .on('proposed', function(res) { - //console.log('Submitted', res); - self.remote.ledger_accept(); - }) - .on('success', function (r) { - //console.log("account_root: %s", JSON.stringify(r)); - // Need to verify account and balance. - buster.assert(true); - done(); - }) - .on('error', function(m) { - console.log('Error'); - console.log("error: %s", m); - buster.assert(false); - }) - .submit(); - }, + var request = $.remote.request_ledger_entry('account_root') + .ledger_hash(r.ledger_hash) + .account_root("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"); - "create account final" : function (done) { - var self = this; - var got_proposed; - var got_success; + request.callback(function(err, r) { + // console.log("account_root: %s", JSON.stringify(r)); + assert(!err); + assert('node' in r); + done(); + }); + }); + }); - var root_id = this.remote.account('root')._account_id; - this.remote.request_subscribe().accounts(root_id).request(); + test('account_root remote malformedAddress', function(done) { + var self = this; - this.remote.transaction() - .payment('root', 'alice', "10000.0") - .on('success', function (r) { - // console.log("create_account: %s", JSON.stringify(r)); - got_success = true; - }) - .on('error', function (m) { - // console.log("error: %s", m); - buster.assert(false); - }) - .on('final', function (m) { - // console.log("final: %s", JSON.stringify(m)); - buster.assert(got_success && got_proposed); - done(); - }) - .on('proposed', function() { - got_proposed = true; - self.remote.ledger_accept(); - }) - .on('submitted', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - // buster.assert.equals(m.result, 'terNO_DST_INSUF_XRP'); - buster.assert.equals(m.engine_result, 'tesSUCCESS'); - }) - .submit(); - }, + $.remote.request_ledger_hash(function(err, r) { + // console.log("result: %s", JSON.stringify(r)); + assert(!err); + + var request = $.remote.request_ledger_entry('account_root') + .ledger_hash(r.ledger_hash) + .account_root("zHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"); + + request.callback(function(err, r) { + // console.log("account_root: %s", JSON.stringify(r)); + assert(err); + assert.strictEqual(err.error, 'remoteError'); + assert.strictEqual(err.remote.error, 'malformedAddress'); + done(); + }); + }) + }); + + test('account_root entryNotFound', function(done) { + var self = this; + + $.remote.request_ledger_hash(function(err, r) { + // console.log("result: %s", JSON.stringify(r)); + assert(!err); + + var request = $.remote.request_ledger_entry('account_root') + .ledger_hash(r.ledger_hash) + .account_root("alice"); + + request.callback(function(err, r) { + // console.log("error: %s", m); + assert(err); + assert.strictEqual(err.error, 'remoteError'); + assert.strictEqual(err.remote.error, 'entryNotFound'); + done(); + }); + }) + }); + + test('ledger_entry index', function(done) { + var self = this; + + $.remote.request_ledger_hash(function(err, r) { + assert(!err); + + var request = $.remote.request_ledger_entry('index') + .ledger_hash(r.ledger_hash) + .account_root("alice") + .index("2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8"); + + request.callback(function(err, r) { + assert(!err); + assert('node_binary' in r); + done(); + }); + }) + }); + + test('create account', function(done) { + var self = this; + + var root_id = $.remote.account('root')._account_id; + + $.remote.request_subscribe().accounts(root_id).request(); + + $.remote.transaction() + .payment('root', 'alice', "10000.0") + .once('error', done) + .once('proposed', function(res) { + //console.log('Submitted', res); + $.remote.ledger_accept(); + }) + .once('success', function (r) { + //console.log("account_root: %s", JSON.stringify(r)); + // Need to verify account and balance. + done(); + }) + .submit(); + }); + + test('create account final', function(done) { + var self = this; + var got_proposed; + var got_success; + + var root_id = $.remote.account('root')._account_id; + + $.remote.request_subscribe().accounts(root_id).request(); + + var transaction = $.remote.transaction() + .payment('root', 'alice', "10000.0") + .once('error', done) + .once('submitted', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + // buster.assert.equals(m.result, 'terNO_DST_INSUF_XRP'); + assert.strictEqual(m.engine_result, 'tesSUCCESS'); + }) + .once('proposed', function() { + got_proposed = true; + $.remote.ledger_accept(); + }) + .once('success', function (r) { + // console.log("create_account: %s", JSON.stringify(r)); + got_success = true; + }) + .once('final', function (m) { + // console.log("final: %s", JSON.stringify(m)); + assert(got_success); + assert(got_proposed); + done(); + }); + transaction.submit(); + }); }); -// vim:sw=2:sts=2:ts=8:et +//vim:sw=2:sts=2:ts=8:et diff --git a/test/send-test.js b/test/send-test.js index 60b437810..1f6737fba 100644 --- a/test/send-test.js +++ b/test/send-test.js @@ -1,1280 +1,1296 @@ var async = require("async"); -var buster = require("buster"); - +var assert = require('assert'); var Amount = require("ripple-lib").Amount; var Remote = require("ripple-lib").Remote; var Server = require("./server").Server; - var testutils = require("./testutils"); var config = testutils.init_config(); -// How long to wait for server to start. -var serverDelay = 1500; +suite('Sending', function() { + var $ = { }; -buster.testRunner.timeout = 5000; + setup(function(done) { + testutils.build_setup().call($, done); + }); -/* - buster.testCase("Fee Changes", { - 'setUp' : testutils.build_setup({no_server: true}), // - 'tearDown' : testutils.build_teardown(), + teardown(function(done) { + testutils.build_teardown().call($, done); + }); - "varying the fee for Payment" : - function (done) { - - this.remote.transaction() - .payment('root', 'alice', "10000") - .on('success', function (r) { - done(); - }).submit(); - - this.remote.transaction() - .payment('root', 'alice', "20000") - .on('success', function (r) { - done(); - }).submit(); - - } - }); - */ - -buster.testCase("Sending", { - 'setUp' : testutils.build_setup(), - //'setUp' : testutils.build_setup({verbose: true , no_server: true}), - 'tearDown' : testutils.build_teardown(), - - "send XRP to non-existent account with insufficent fee" : function (done) { + test("send XRP to non-existent account with insufficent fee", function (done) { var self = this; var ledgers = 20; var got_proposed; - this.remote.transaction() + $.remote.transaction() .payment('root', 'alice', "1") .once('submitted', function (m) { // Transaction got an error. // console.log("proposed: %s", JSON.stringify(m)); - buster.assert.equals(m.engine_result, 'tecNO_DST_INSUF_XRP'); + assert.strictEqual(m.engine_result, 'tecNO_DST_INSUF_XRP'); got_proposed = true; - self.remote.ledger_accept(); // Move it along. + $.remote.ledger_accept(); // Move it along. }) .once('final', function (m) { // console.log("final: %s", JSON.stringify(m, undefined, 2)); - buster.assert.equals(m.engine_result, 'tecNO_DST_INSUF_XRP'); + assert.strictEqual(m.engine_result, 'tecNO_DST_INSUF_XRP'); done(); }) .submit(); - }, + }); // Also test transaction becomes lost after tecNO_DST. - "credit_limit to non-existent account = tecNO_DST" : function (done) { - this.remote.transaction() + test("credit_limit to non-existent account = tecNO_DST", function (done) { + $.remote.transaction() .ripple_line_set("root", "100/USD/alice") .once('submitted', function (m) { //console.log("proposed: %s", JSON.stringify(m)); - - buster.assert.equals(m.engine_result, 'tecNO_DST'); - + assert.strictEqual(m.engine_result, 'tecNO_DST'); done(); }) .submit(); - }, + }); - "credit_limit" : function (done) { + test("credit_limit", function (done) { var self = this; - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + var steps = [ + function (callback) { + self.what = "Create accounts."; + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); + }, - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); - }, - function (callback) { - self.what = "Check a non-existent credit limit."; + function (callback) { + self.what = "Check a non-existent credit limit."; - self.remote.request_ripple_balance("alice", "mtgox", "USD", 'CURRENT') - .on('ripple_state', function (m) { - callback(true); - }) - .on('error', function(m) { - // console.log("error: %s", JSON.stringify(m)); + $.remote.request_ripple_balance("alice", "mtgox", "USD", 'CURRENT') + .on('ripple_state', function (m) { + callback(new Error(m)); + }) + .on('error', function(m) { + // console.log("error: %s", JSON.stringify(m)); - buster.assert.equals('remoteError', m.error); - buster.assert.equals('entryNotFound', m.remote.error); - callback(); - }) - .request(); - }, - function (callback) { - self.what = "Create a credit limit."; + assert.strictEqual('remoteError', m.error); + assert.strictEqual('entryNotFound', m.remote.error); + callback(); + }) + .request(); + }, - testutils.credit_limit(self.remote, "alice", "800/USD/mtgox", callback); - }, - function (callback) { - self.remote.request_ripple_balance("alice", "mtgox", "USD", 'CURRENT') - .on('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("peer_balance: %s", m.peer_balance.to_text_full()); - // console.log("peer_limit: %s", m.peer_limit.to_text_full()); - buster.assert(m.account_balance.equals("0/USD/alice")); - buster.assert(m.account_limit.equals("800/USD/mtgox")); - buster.assert(m.peer_balance.equals("0/USD/mtgox")); - buster.assert(m.peer_limit.equals("0/USD/alice")); + function (callback) { + self.what = "Create a credit limit."; + testutils.credit_limit($.remote, "alice", "800/USD/mtgox", callback); + }, - callback(); - }) - .request(); - }, - function (callback) { - self.what = "Modify a credit limit."; + function (callback) { + $.remote.request_ripple_balance("alice", "mtgox", "USD", 'CURRENT') + .on('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("peer_balance: %s", m.peer_balance.to_text_full()); + // console.log("peer_limit: %s", m.peer_limit.to_text_full()); + assert(m.account_balance.equals("0/USD/alice")); + assert(m.account_limit.equals("800/USD/mtgox")); + assert(m.peer_balance.equals("0/USD/mtgox")); + assert(m.peer_limit.equals("0/USD/alice")); - testutils.credit_limit(self.remote, "alice", "700/USD/mtgox", callback); - }, - function (callback) { - self.remote.request_ripple_balance("alice", "mtgox", "USD", 'CURRENT') - .on('ripple_state', function (m) { - buster.assert(m.account_balance.equals("0/USD/alice")); - buster.assert(m.account_limit.equals("700/USD/mtgox")); - buster.assert(m.peer_balance.equals("0/USD/mtgox")); - buster.assert(m.peer_limit.equals("0/USD/alice")); + callback(); + }) + .request(); + }, - callback(); - }) - .request(); - }, - // Set negative limit. - function (callback) { - self.remote.transaction() - .ripple_line_set("alice", "-1/USD/mtgox") - .once('submitted', function (m) { - buster.assert.equals('temBAD_LIMIT', m.engine_result); - callback(); - }) - .submit(); - }, - // 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 (callback) { - self.what = "Zero a credit limit."; + function (callback) { + self.what = "Modify a credit limit."; + testutils.credit_limit($.remote, "alice", "700/USD/mtgox", callback); + }, - testutils.credit_limit(self.remote, "alice", "0/USD/mtgox", callback); - }, - function (callback) { - self.what = "Make sure line is deleted."; + function (callback) { + $.remote.request_ripple_balance("alice", "mtgox", "USD", 'CURRENT') + .on('ripple_state', function (m) { + assert(m.account_balance.equals("0/USD/alice")); + assert(m.account_limit.equals("700/USD/mtgox")); + assert(m.peer_balance.equals("0/USD/mtgox")); + assert(m.peer_limit.equals("0/USD/alice")); - self.remote.request_ripple_balance("alice", "mtgox", "USD", 'CURRENT') - .on('ripple_state', function (m) { - // Used to keep lines. - // buster.assert(m.account_balance.equals("0/USD/alice")); - // buster.assert(m.account_limit.equals("0/USD/alice")); - // buster.assert(m.peer_balance.equals("0/USD/mtgox")); - // buster.assert(m.peer_limit.equals("0/USD/mtgox")); + callback(); + }) + .request(); + }, + // Set negative limit. + function (callback) { + $.remote.transaction() + .ripple_line_set("alice", "-1/USD/mtgox") + .once('submitted', function (m) { + assert.strictEqual('temBAD_LIMIT', m.engine_result); + callback(); + }) + .submit(); + }, - buster.assert(false); - }) - .on('error', function (m) { - // console.log("error: %s", JSON.stringify(m)); - buster.assert.equals('remoteError', m.error); - buster.assert.equals('entryNotFound', m.remote.error); + // function (callback) { + // self.what = "Display ledger"; + // + // $.remote.request_ledger('current', true) + // .on('success', function (m) { + // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); + // + // callback(); + // }) + // .request(); + // }, - callback(); - }) - .request(); - }, - // TODO Check in both owner books. - function (callback) { - self.what = "Set another limit."; + function (callback) { + self.what = "Zero a credit limit."; + testutils.credit_limit($.remote, "alice", "0/USD/mtgox", callback); + }, - testutils.credit_limit(self.remote, "alice", "600/USD/bob", callback); - }, - function (callback) { - self.what = "Set limit on other side."; + function (callback) { + self.what = "Make sure line is deleted."; - testutils.credit_limit(self.remote, "bob", "500/USD/alice", callback); - }, - function (callback) { - self.what = "Check ripple_line's state from alice's pov."; + $.remote.request_ripple_balance("alice", "mtgox", "USD", 'CURRENT') + .on('ripple_state', function (m) { + // Used to keep lines. + // assert(m.account_balance.equals("0/USD/alice")); + // assert(m.account_limit.equals("0/USD/alice")); + // assert(m.peer_balance.equals("0/USD/mtgox")); + // assert(m.peer_limit.equals("0/USD/mtgox")); + callback(new Error(m)); + }) + .on('error', function (m) { + // console.log("error: %s", JSON.stringify(m)); + assert.strictEqual('remoteError', m.error); + assert.strictEqual('entryNotFound', m.remote.error); - self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') - .on('ripple_state', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + callback(); + }) + .request(); + }, + // TODO Check in both owner books. + function (callback) { + self.what = "Set another limit."; + testutils.credit_limit($.remote, "alice", "600/USD/bob", callback); + }, - buster.assert(m.account_balance.equals("0/USD/alice")); - buster.assert(m.account_limit.equals("600/USD/bob")); - buster.assert(m.peer_balance.equals("0/USD/bob")); - buster.assert(m.peer_limit.equals("500/USD/alice")); + function (callback) { + self.what = "Set limit on other side."; + testutils.credit_limit($.remote, "bob", "500/USD/alice", callback); + }, - callback(); - }) - .request(); - }, - function (callback) { - self.what = "Check ripple_line's state from bob's pov."; + function (callback) { + self.what = "Check ripple_line's state from alice's pov."; - self.remote.request_ripple_balance("bob", "alice", "USD", 'CURRENT') - .on('ripple_state', function (m) { - buster.assert(m.account_balance.equals("0/USD/bob")); - buster.assert(m.account_limit.equals("500/USD/alice")); - buster.assert(m.peer_balance.equals("0/USD/alice")); - buster.assert(m.peer_limit.equals("600/USD/bob")); + $.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + .on('ripple_state', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - callback(); - }) - .request(); - }, - ], function (error) { - buster.refute(error, self.what); + assert(m.account_balance.equals("0/USD/alice")); + assert(m.account_limit.equals("600/USD/bob")); + assert(m.peer_balance.equals("0/USD/bob")); + assert(m.peer_limit.equals("500/USD/alice")); + + callback(); + }) + .request(); + }, + + function (callback) { + self.what = "Check ripple_line's state from bob's pov."; + + $.remote.request_ripple_balance("bob", "alice", "USD", 'CURRENT') + .on('ripple_state', function (m) { + assert(m.account_balance.equals("0/USD/bob")); + assert(m.account_limit.equals("500/USD/alice")); + assert(m.peer_balance.equals("0/USD/alice")); + assert(m.peer_limit.equals("600/USD/bob")); + + callback(); + }) + .request(); + } + ] + + async.waterfall(steps, function(error) { + assert(!error, self.what); done(); }); - }, + }); }); -// XXX In the future add ledger_accept after partial retry is implemented in the server. -buster.testCase("Sending future", { - 'setUp' : testutils.build_setup(), - // 'setUp' : testutils.build_setup({ verbose : true }), - 'tearDown' : testutils.build_teardown(), +suite('Sending future', function() { + var $ = { }; - "direct ripple" : function (done) { + setup(function(done) { + testutils.build_setup().call($, done); + }); + + teardown(function(done) { + testutils.build_teardown().call($, done); + }); + + test('direct ripple', function(done) { var self = this; - // self.remote.set_trace(); + // $.remote.set_trace(); - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + var steps = [ + function (callback) { + self.what = "Create accounts."; + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob"], callback); + }, - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob"], callback); - }, - function (callback) { - self.what = "Set alice's limit."; + function (callback) { + self.what = "Set alice's limit."; + testutils.credit_limit($.remote, "alice", "600/USD/bob", callback); + }, - testutils.credit_limit(self.remote, "alice", "600/USD/bob", callback); - }, - function (callback) { - self.what = "Set bob's limit."; + function (callback) { + self.what = "Set bob's limit."; + testutils.credit_limit($.remote, "bob", "700/USD/alice", callback); + }, - testutils.credit_limit(self.remote, "bob", "700/USD/alice", callback); - }, - function (callback) { - self.what = "Set alice send bob partial with alice as issuer."; + function (callback) { + self.what = "Set alice send bob partial with alice as issuer."; - self.remote.transaction() - .payment('alice', 'bob', "24/USD/alice") - .once('submitted', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tesSUCCESS'); - }) - .once('final', function (m) { - buster.assert(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balance."; + $.remote.transaction() + .payment('alice', 'bob', "24/USD/alice") + .once('submitted', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .once('final', function (m) { + assert(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, - self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') - .once('ripple_state', function (m) { - buster.assert(m.account_balance.equals("-24/USD/alice")); - buster.assert(m.peer_balance.equals("24/USD/bob")); + function (callback) { + self.what = "Verify balance."; - callback(); - }) - .request(); - }, - function (callback) { - self.what = "Set alice send bob more with bob as issuer."; + $.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + .once('ripple_state', function (m) { + assert(m.account_balance.equals("-24/USD/alice")); + assert(m.peer_balance.equals("24/USD/bob")); - self.remote.transaction() - .payment('alice', 'bob', "33/USD/bob") - .once('submitted', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tesSUCCESS'); - }) - .once('final', function (m) { - buster.assert(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balance from bob's pov."; + callback(); + }) + .request(); + }, - self.remote.request_ripple_balance("bob", "alice", "USD", 'CURRENT') - .once('ripple_state', function (m) { - buster.assert(m.account_balance.equals("57/USD/bob")); - buster.assert(m.peer_balance.equals("-57/USD/alice")); + function (callback) { + self.what = "Set alice send bob more with bob as issuer."; - callback(); - }) - .request(); - }, - function (callback) { - self.what = "Bob send back more than sent."; + $.remote.transaction() + .payment('alice', 'bob', "33/USD/bob") + .once('submitted', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .once('final', function (m) { + assert(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, - self.remote.transaction() - .payment('bob', 'alice', "90/USD/bob") - .once('submitted', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tesSUCCESS'); - }) - .once('final', function (m) { - buster.assert(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balance from alice's pov: 1"; + function (callback) { + self.what = "Verify balance from bob's pov."; - self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') - .once('ripple_state', function (m) { - buster.assert(m.account_balance.equals("33/USD/alice")); + $.remote.request_ripple_balance("bob", "alice", "USD", 'CURRENT') + .once('ripple_state', function (m) { + assert(m.account_balance.equals("57/USD/bob")); + assert(m.peer_balance.equals("-57/USD/alice")); - callback(); - }) - .request(); - }, - function (callback) { - self.what = "Alice send to limit."; + callback(); + }) + .request(); + }, - self.remote.transaction() - .payment('alice', 'bob', "733/USD/bob") - .once('submitted', function (m) { - // console.log("submitted: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tesSUCCESS'); - }) - .once('final', function (m) { - buster.assert(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balance from alice's pov: 2"; + function (callback) { + self.what = "Bob send back more than sent."; - self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') - .once('ripple_state', function (m) { - buster.assert(m.account_balance.equals("-700/USD/alice")); + $.remote.transaction() + .payment('bob', 'alice', "90/USD/bob") + .once('submitted', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .once('final', function (m) { + assert(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, - callback(); - }) - .request(); - }, - function (callback) { - self.what = "Bob send to limit."; + function (callback) { + self.what = "Verify balance from alice's pov: 1"; - self.remote.transaction() - .payment('bob', 'alice', "1300/USD/bob") - .once('submitted', function (m) { - // console.log("submitted: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tesSUCCESS'); - }) - .once('final', function (m) { - buster.assert(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balance from alice's pov: 3"; + $.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + .once('ripple_state', function (m) { + assert(m.account_balance.equals("33/USD/alice")); - self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') - .once('ripple_state', function (m) { - buster.assert(m.account_balance.equals("600/USD/alice")); + callback(); + }) + .request(); + }, - callback(); - }) - .request(); - }, - function (callback) { - // If this gets applied out of order, it could stop the big payment. - self.what = "Bob send past limit."; + function (callback) { + self.what = "Alice send to limit."; - self.remote.transaction() - .payment('bob', 'alice', "1/USD/bob") - .once('submitted', function (m) { - // console.log("submitted: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tecPATH_DRY'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balance from alice's pov: 4"; + $.remote.transaction() + .payment('alice', 'bob', "733/USD/bob") + .once('submitted', function (m) { + // console.log("submitted: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .once('final', function (m) { + assert(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, - self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') - .once('ripple_state', function (m) { - buster.assert(m.account_balance.equals("600/USD/alice")); + function (callback) { + self.what = "Verify balance from alice's pov: 2"; - callback(); - }) - .request(); - }, - // function (callback) { - // // Make sure all is good after canonical ordering. - // self.what = "Close the ledger and check balance."; - // - // self.remote - // .once('ledger_closed', function (message) { - // // console.log("LEDGER_CLOSED: A: %d: %s", ledger_closed_index, ledger_closed); - // callback(); - // }) - // .ledger_accept(); - // }, - // function (callback) { - // self.what = "Verify balance from alice's pov: 5"; - // - // self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') - // .once('ripple_state', function (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("peer_balance: %s", m.peer_balance.to_text_full()); - // console.log("peer_limit: %s", m.peer_limit.to_text_full()); - // - // buster.assert(m.account_balance.equals("600/USD/alice")); - // - // callback(); - // }) - // .request(); - // }, - ], function (error) { - buster.refute(error, self.what); + $.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + .once('ripple_state', function (m) { + assert(m.account_balance.equals("-700/USD/alice")); + + callback(); + }) + .request(); + }, + + function (callback) { + self.what = "Bob send to limit."; + + $.remote.transaction() + .payment('bob', 'alice', "1300/USD/bob") + .once('submitted', function (m) { + // console.log("submitted: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .once('final', function (m) { + assert(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + + function (callback) { + self.what = "Verify balance from alice's pov: 3"; + + $.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + .once('ripple_state', function (m) { + assert(m.account_balance.equals("600/USD/alice")); + + callback(); + }) + .request(); + }, + + function (callback) { + // If this gets applied out of order, it could stop the big payment. + self.what = "Bob send past limit."; + + $.remote.transaction() + .payment('bob', 'alice', "1/USD/bob") + .once('submitted', function (m) { + // console.log("submitted: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tecPATH_DRY'); + }) + .submit(); + }, + + function (callback) { + self.what = "Verify balance from alice's pov: 4"; + + $.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + .once('ripple_state', function (m) { + assert(m.account_balance.equals("600/USD/alice")); + + callback(); + }) + .request(); + }, + + // function (callback) { + // // Make sure all is good after canonical ordering. + // self.what = "Close the ledger and check balance."; + // + // $.remote + // .once('ledger_closed', function (message) { + // // console.log("LEDGER_CLOSED: A: %d: %s", ledger_closed_index, ledger_closed); + // callback(); + // }) + // .ledger_accept(); + // }, + // function (callback) { + // self.what = "Verify balance from alice's pov: 5"; + // + // $.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + // .once('ripple_state', function (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("peer_balance: %s", m.peer_balance.to_text_full()); + // console.log("peer_limit: %s", m.peer_limit.to_text_full()); + // + // assert(m.account_balance.equals("600/USD/alice")); + // + // callback(); + // }) + // .request(); + // }, + ] + + async.waterfall(steps, function(error) { + assert(!error, self.what); done(); }); - }, - - // Ripple without credit path. - // Ripple with one-way credit path. + }); }); -buster.testCase("Gateway", { - 'setUp' : testutils.build_setup(), - // 'setUp' : testutils.build_setup({ verbose: true }), - 'tearDown' : testutils.build_teardown(), +suite('Gateway', function() { + var $ = { }; - "customer to customer with and without transfer fee" : function (done) { + setup(function(done) { + testutils.build_setup().call($, done); + }); + + teardown(function(done) { + testutils.build_teardown().call($, done); + }); + + test("customer to customer with and without transfer fee", function (done) { var self = this; - // self.remote.set_trace(); + // $.remote.set_trace(); - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + var steps = [ + function (callback) { + self.what = "Create accounts."; + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); + }, - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); - }, - function (callback) { - self.what = "Set credit limits."; + function (callback) { + self.what = "Set credit limits."; - testutils.credit_limits(self.remote, - { - "alice" : "100/AUD/mtgox", - "bob" : "100/AUD/mtgox", - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; + testutils.credit_limits($.remote, { + "alice" : "100/AUD/mtgox", + "bob" : "100/AUD/mtgox", + }, + callback); + }, - testutils.payments(self.remote, - { - "mtgox" : [ "1/AUD/alice" ], - }, - callback); - }, - function (callback) { - self.what = "Verify balances."; + function (callback) { + self.what = "Distribute funds."; - testutils.verify_balances(self.remote, - { - "alice" : "1/AUD/mtgox", - "mtgox" : "-1/AUD/alice", - }, - callback); - }, - function (callback) { - self.what = "Alice sends Bob 1 AUD"; + testutils.payments($.remote, { + "mtgox" : [ "1/AUD/alice" ], + }, + callback); + }, - self.remote.transaction() - .payment("alice", "bob", "1/AUD/mtgox") - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + function (callback) { + self.what = "Verify balances."; - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances 2."; + testutils.verify_balances($.remote, { + "alice" : "1/AUD/mtgox", + "mtgox" : "-1/AUD/alice", + }, + callback); + }, - testutils.verify_balances(self.remote, - { - "alice" : "0/AUD/mtgox", - "bob" : "1/AUD/mtgox", - "mtgox" : "-1/AUD/bob", - }, - callback); - }, - function (callback) { - self.what = "Set transfer rate."; + function (callback) { + self.what = "Alice sends Bob 1 AUD"; - self.remote.transaction() - .account_set("mtgox") - .transfer_rate(1e9*1.1) - .once('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Bob sends Alice 0.5 AUD"; + $.remote.transaction() + .payment("alice", "bob", "1/AUD/mtgox") + .once('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - self.remote.transaction() - .payment("bob", "alice", "0.5/AUD/mtgox") - .send_max("0.55/AUD/mtgox") // !!! Very important. - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances 3."; + function (callback) { + self.what = "Verify balances 2."; - testutils.verify_balances(self.remote, - { - "alice" : "0.5/AUD/mtgox", - "bob" : "0.45/AUD/mtgox", - "mtgox" : [ "-0.5/AUD/alice","-0.45/AUD/bob" ], - }, - callback); - }, - ], function (error) { - buster.refute(error, self.what); + testutils.verify_balances($.remote, { + "alice" : "0/AUD/mtgox", + "bob" : "1/AUD/mtgox", + "mtgox" : "-1/AUD/bob", + }, + callback); + }, + + function (callback) { + self.what = "Set transfer rate."; + + $.remote.transaction() + .account_set("mtgox") + .transfer_rate(1e9*1.1) + .once('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + + function (callback) { + self.what = "Bob sends Alice 0.5 AUD"; + + $.remote.transaction() + .payment("bob", "alice", "0.5/AUD/mtgox") + .send_max("0.55/AUD/mtgox") // !!! Very important. + .once('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + + function (callback) { + self.what = "Verify balances 3."; + + testutils.verify_balances($.remote, { + "alice" : "0.5/AUD/mtgox", + "bob" : "0.45/AUD/mtgox", + "mtgox" : [ "-0.5/AUD/alice","-0.45/AUD/bob" ], + }, + callback); + }, + ] + + async.waterfall(steps, function(error) { + assert(!error, self.what); done(); }); - }, + }); + + test("customer to customer, transfer fee, default path with and without specific issuer for Amount and SendMax", function (done) { - "customer to customer, transfer fee, default path with and without specific issuer for Amount and SendMax" : function (done) { var self = this; - // self.remote.set_trace(); + // $.remote.set_trace(); - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + var steps = [ + function (callback) { + self.what = "Create accounts."; + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); + }, - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); - }, - function (callback) { - self.what = "Set transfer rate."; + function (callback) { + self.what = "Set transfer rate."; - self.remote.transaction() - .account_set("mtgox") - .transfer_rate(1e9*1.1) - .once('submitted', function (m) { - // console.log("submitted: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Set credit limits."; + $.remote.transaction() + .account_set("mtgox") + .transfer_rate(1e9*1.1) + .once('submitted', function (m) { + // console.log("submitted: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, - testutils.credit_limits(self.remote, - { - "alice" : "100/AUD/mtgox", - "bob" : "100/AUD/mtgox", - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; + function (callback) { + self.what = "Set credit limits."; - testutils.payments(self.remote, - { - "mtgox" : [ "4.4/AUD/alice" ], - }, - callback); - }, - function (callback) { - self.what = "Verify balances."; + testutils.credit_limits($.remote, { + "alice" : "100/AUD/mtgox", + "bob" : "100/AUD/mtgox", + }, + callback); + }, - testutils.verify_balances(self.remote, - { - "alice" : "4.4/AUD/mtgox", - }, - callback); - }, - function (callback) { - self.what = "Alice sends 1.1/AUD/mtgox Bob 1/AUD/mtgox"; + function (callback) { + self.what = "Distribute funds."; - self.remote.transaction() - .payment("alice", "bob", "1/AUD/mtgox") - .send_max("1.1/AUD/mtgox") - .once('submitted', function (m) { - // console.log("submitted: %s", JSON.stringify(m)); + testutils.payments($.remote, { + "mtgox" : [ "4.4/AUD/alice" ], + }, + callback); + }, - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances 2."; + function (callback) { + self.what = "Verify balances."; - testutils.verify_balances(self.remote, - { - "alice" : "3.3/AUD/mtgox", - "bob" : "1/AUD/mtgox", - }, - callback); - }, - function (callback) { - self.what = "Alice sends 1.1/AUD/mtgox Bob 1/AUD/bob"; + testutils.verify_balances($.remote, { + "alice" : "4.4/AUD/mtgox", + }, + callback); + }, - self.remote.transaction() - .payment("alice", "bob", "1/AUD/bob") - .send_max("1.1/AUD/mtgox") - .once('submitted', function (m) { - // console.log("submitted: %s", JSON.stringify(m)); + function (callback) { + self.what = "Alice sends 1.1/AUD/mtgox Bob 1/AUD/mtgox"; - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances 3."; + $.remote.transaction() + .payment("alice", "bob", "1/AUD/mtgox") + .send_max("1.1/AUD/mtgox") + .once('submitted', function (m) { + // console.log("submitted: %s", JSON.stringify(m)); - testutils.verify_balances(self.remote, - { - "alice" : "2.2/AUD/mtgox", - "bob" : "2/AUD/mtgox", - }, - callback); - }, - function (callback) { - self.what = "Alice sends 1.1/AUD/alice Bob 1/AUD/mtgox"; + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, - self.remote.transaction() - .payment("alice", "bob", "1/AUD/mtgox") - .send_max("1.1/AUD/alice") - .once('submitted', function (m) { - // console.log("submitted: %s", JSON.stringify(m)); + function (callback) { + self.what = "Verify balances 2."; - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances 4."; + testutils.verify_balances($.remote, { + "alice" : "3.3/AUD/mtgox", + "bob" : "1/AUD/mtgox", + }, + callback); + }, - testutils.verify_balances(self.remote, - { - "alice" : "1.1/AUD/mtgox", - "bob" : "3/AUD/mtgox", - }, - callback); - }, - function (callback) { - // Must fail, doesn't know to use the mtgox - self.what = "Alice sends 1.1/AUD/alice Bob 1/AUD/bob"; + function (callback) { + self.what = "Alice sends 1.1/AUD/mtgox Bob 1/AUD/bob"; - self.remote.transaction() - .payment("alice", "bob", "1/AUD/bob") - .send_max("1.1/AUD/alice") - .once('submitted', function (m) { - // console.log("submitted: %s", JSON.stringify(m)); + $.remote.transaction() + .payment("alice", "bob", "1/AUD/bob") + .send_max("1.1/AUD/mtgox") + .once('submitted', function (m) { + // console.log("submitted: %s", JSON.stringify(m)); - callback(m.engine_result !== 'terNO_LINE'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances 5."; + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, - testutils.verify_balances(self.remote, - { - "alice" : "1.1/AUD/mtgox", - "bob" : "3/AUD/mtgox", - }, - callback); - }, - ], function (error) { - buster.refute(error, self.what); + function (callback) { + self.what = "Verify balances 3."; + + testutils.verify_balances($.remote, { + "alice" : "2.2/AUD/mtgox", + "bob" : "2/AUD/mtgox", + }, + callback); + }, + + function (callback) { + self.what = "Alice sends 1.1/AUD/alice Bob 1/AUD/mtgox"; + + $.remote.transaction() + .payment("alice", "bob", "1/AUD/mtgox") + .send_max("1.1/AUD/alice") + .once('submitted', function (m) { + // console.log("submitted: %s", JSON.stringify(m)); + + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + + function (callback) { + self.what = "Verify balances 4."; + + testutils.verify_balances($.remote, { + "alice" : "1.1/AUD/mtgox", + "bob" : "3/AUD/mtgox", + }, + callback); + }, + + function (callback) { + // Must fail, doesn't know to use the mtgox + self.what = "Alice sends 1.1/AUD/alice Bob 1/AUD/bob"; + + $.remote.transaction() + .payment("alice", "bob", "1/AUD/bob") + .send_max("1.1/AUD/alice") + .once('submitted', function (m) { + // console.log("submitted: %s", JSON.stringify(m)); + + callback(m.engine_result !== 'terNO_LINE'); + }) + .submit(); + }, + + function (callback) { + self.what = "Verify balances 5."; + + testutils.verify_balances($.remote, { + "alice" : "1.1/AUD/mtgox", + "bob" : "3/AUD/mtgox", + }, + callback); + } + ] + + async.waterfall(steps, function(error) { + assert(!error, self.what); done(); }); - }, + }); - "subscribe test: customer to customer with and without transfer fee" : function (done) { + test("subscribe test customer to customer with and without transfer fee", function (done) { var self = this; - // self.remote.set_trace(); + // $.remote.set_trace(); - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + var steps = [ + function (callback) { + self.what = "Create accounts."; + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); + }, - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); - }, - function (callback) { testutils.ledger_close(self.remote, callback); }, - function (callback) { - self.what = "Set credit limits."; + function (callback) { testutils.ledger_close($.remote, callback); }, - testutils.credit_limits(self.remote, - { - "alice" : "100/AUD/mtgox", - "bob" : "100/AUD/mtgox", - }, - callback); - }, - function (callback) { testutils.ledger_close(self.remote, callback); }, - function (callback) { - self.what = "Distribute funds."; + function (callback) { + self.what = "Set credit limits."; - testutils.payments(self.remote, - { - "mtgox" : [ "1/AUD/alice" ], - }, - callback); - }, - function (callback) { testutils.ledger_close(self.remote, callback); }, - function (callback) { - self.what = "Verify balances."; + testutils.credit_limits($.remote, { + "alice" : "100/AUD/mtgox", + "bob" : "100/AUD/mtgox", + }, + callback); + }, - testutils.verify_balances(self.remote, - { - "alice" : "1/AUD/mtgox", - "mtgox" : "-1/AUD/alice", - }, - callback); - }, - function (callback) { - self.what = "Alice sends Bob 1 AUD"; + function (callback) { testutils.ledger_close($.remote, callback); }, - self.remote.transaction() - .payment("alice", "bob", "1/AUD/mtgox") - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + function (callback) { + self.what = "Distribute funds."; - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { testutils.ledger_close(self.remote, callback); }, - function (callback) { - self.what = "Verify balances 2."; + testutils.payments($.remote, { + "mtgox" : [ "1/AUD/alice" ], + }, + callback); + }, - testutils.verify_balances(self.remote, - { - "alice" : "0/AUD/mtgox", - "bob" : "1/AUD/mtgox", - "mtgox" : "-1/AUD/bob", - }, - callback); - }, - function (callback) { - self.what = "Set transfer rate."; + function (callback) { testutils.ledger_close($.remote, callback); }, - self.remote.transaction() - .account_set("mtgox") - .transfer_rate(1e9*1.1) - .once('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { testutils.ledger_close(self.remote, callback); }, - function (callback) { - self.what = "Bob sends Alice 0.5 AUD"; + function (callback) { + self.what = "Verify balances."; - self.remote.transaction() - .payment("bob", "alice", "0.5/AUD/mtgox") - .send_max("0.55/AUD/mtgox") // !!! Very important. - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + testutils.verify_balances($.remote, { + "alice" : "1/AUD/mtgox", + "mtgox" : "-1/AUD/alice", + }, + callback); + }, - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances 3."; + function (callback) { + self.what = "Alice sends Bob 1 AUD"; - testutils.verify_balances(self.remote, - { - "alice" : "0.5/AUD/mtgox", - "bob" : "0.45/AUD/mtgox", - "mtgox" : [ "-0.5/AUD/alice","-0.45/AUD/bob" ], - }, - callback); - }, - function (callback) { - self.what = "Subscribe and accept."; + $.remote.transaction() + .payment("alice", "bob", "1/AUD/mtgox") + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - self.count = 0; - self.found = 0; + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, - self.remote.on('ledger_closed', function (m) { - // console.log("#### LEDGER_CLOSE: %s", JSON.stringify(m)); - }); + function (callback) { testutils.ledger_close($.remote, callback); }, - self.remote - .on('transaction', function (m) { - // console.log("ACCOUNT: %s", JSON.stringify(m)); - self.found = 1; - }) - .on('ledger_closed', function (m) { - // console.log("LEDGER_CLOSE: %d: %s", self.count, JSON.stringify(m)); + function (callback) { + self.what = "Verify balances 2."; - if (self.count) { - callback(!self.found); - } - else { - self.count = 1; + testutils.verify_balances($.remote, { + "alice" : "0/AUD/mtgox", + "bob" : "1/AUD/mtgox", + "mtgox" : "-1/AUD/bob", + }, + callback); + }, - self.remote.ledger_accept(); - } - }) - .request_subscribe().accounts("mtgox") - .request(); + function (callback) { + self.what = "Set transfer rate."; - self.remote.ledger_accept(); - }, - ], function (error) { - buster.refute(error, self.what); + $.remote.transaction() + .account_set("mtgox") + .transfer_rate(1e9*1.1) + .once('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + + function (callback) { testutils.ledger_close($.remote, callback); }, + + function (callback) { + self.what = "Bob sends Alice 0.5 AUD"; + + $.remote.transaction() + .payment("bob", "alice", "0.5/AUD/mtgox") + .send_max("0.55/AUD/mtgox") // !!! Very important. + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + + function (callback) { + self.what = "Verify balances 3."; + + testutils.verify_balances($.remote, { + "alice" : "0.5/AUD/mtgox", + "bob" : "0.45/AUD/mtgox", + "mtgox" : [ "-0.5/AUD/alice","-0.45/AUD/bob" ], + }, + callback); + }, + + function (callback) { + self.what = "Subscribe and accept."; + self.count = 0; + self.found = 0; + + $.remote + .on('transaction', function (m) { + // console.log("ACCOUNT: %s", JSON.stringify(m)); + self.found = 1; + }) + .on('ledger_closed', function (m) { + // console.log("LEDGER_CLOSE: %d: %s", self.count, JSON.stringify(m)); + if (self.count) { + callback(!self.found); + } else { + self.count = 1; + $.remote.ledger_accept(); + } + }) + .request_subscribe().accounts("mtgox") + .request(); + + $.remote.ledger_accept(); + } + ] + + async.waterfall(steps, function(error) { + assert(!error, self.what); done(); }); - }, + }); + + test("subscribe test: customer to customer with and without transfer fee: transaction retry logic", function (done) { - "subscribe test: customer to customer with and without transfer fee: transaction retry logic" : function (done) { var self = this; - // self.remote.set_trace(); + // $.remote.set_trace(); - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + var steps = [ + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); - }, - function (callback) { - self.what = "Set credit limits."; + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); + }, - testutils.credit_limits(self.remote, - { - "alice" : "100/AUD/mtgox", - "bob" : "100/AUD/mtgox", - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; + function (callback) { + self.what = "Set credit limits."; - testutils.payments(self.remote, - { - "mtgox" : [ "1/AUD/alice" ], - }, - callback); - }, - function (callback) { - self.what = "Verify balances."; - - testutils.verify_balances(self.remote, + testutils.credit_limits($.remote, { - "alice" : "1/AUD/mtgox", - "mtgox" : "-1/AUD/alice", + "alice" : "100/AUD/mtgox", + "bob" : "100/AUD/mtgox", }, callback); - }, - function (callback) { - self.what = "Alice sends Bob 1 AUD"; + }, - self.remote.transaction() - .payment("alice", "bob", "1/AUD/mtgox") - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + function (callback) { + self.what = "Distribute funds."; - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances 2."; + testutils.payments($.remote, { + "mtgox" : [ "1/AUD/alice" ], + }, + callback); + }, - testutils.verify_balances(self.remote, - { - "alice" : "0/AUD/mtgox", - "bob" : "1/AUD/mtgox", - "mtgox" : "-1/AUD/bob", - }, - callback); - }, - // function (callback) { - // self.what = "Set transfer rate."; - // - // self.remote.transaction() - // .account_set("mtgox") - // .transfer_rate(1e9*1.1) - // .once('proposed', function (m) { - // // console.log("proposed: %s", JSON.stringify(m)); - // callback(m.engine_result !== 'tesSUCCESS'); - // }) - // .submit(); - // }, - function (callback) { - self.what = "Bob sends Alice 0.5 AUD"; + function (callback) { + self.what = "Verify balances."; - self.remote.transaction() - .payment("bob", "alice", "0.5/AUD/mtgox") - // .send_max("0.55/AUD/mtgox") // !!! Very important. - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + testutils.verify_balances($.remote, { + "alice" : "1/AUD/mtgox", + "mtgox" : "-1/AUD/alice", + }, + callback); + }, - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances 3."; + function (callback) { + self.what = "Alice sends Bob 1 AUD"; - testutils.verify_balances(self.remote, - { - "alice" : "0.5/AUD/mtgox", - "bob" : "0.5/AUD/mtgox", - "mtgox" : [ "-0.5/AUD/alice","-0.5/AUD/bob" ], - }, - callback); - }, - function (callback) { - self.what = "Subscribe and accept."; + $.remote.transaction() + .payment("alice", "bob", "1/AUD/mtgox") + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - self.count = 0; - self.found = 0; + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, - self.remote.on('ledger_closed', function (m) { - // console.log("#### LEDGER_CLOSE: %s", JSON.stringify(m)); - }); + function (callback) { + self.what = "Verify balances 2."; - self.remote - .on('transaction', function (m) { - // console.log("ACCOUNT: %s", JSON.stringify(m)); - self.found = 1; - }) - .on('ledger_closed', function (m) { - // console.log("LEDGER_CLOSE: %d: %s", self.count, JSON.stringify(m)); + testutils.verify_balances($.remote, { + "alice" : "0/AUD/mtgox", + "bob" : "1/AUD/mtgox", + "mtgox" : "-1/AUD/bob", + }, + callback); + }, - if (self.count) { - callback(!self.found); - } - else { - self.count = 1; + // function (callback) { + // self.what = "Set transfer rate."; + // + // $.remote.transaction() + // .account_set("mtgox") + // .transfer_rate(1e9*1.1) + // .once('proposed', function (m) { + // // console.log("proposed: %s", JSON.stringify(m)); + // callback(m.engine_result !== 'tesSUCCESS'); + // }) + // .submit(); + // }, - self.remote.ledger_accept(); - } - }) - .request_subscribe().accounts("mtgox") - .request(); + function (callback) { + self.what = "Bob sends Alice 0.5 AUD"; - self.remote.ledger_accept(); - }, - function (callback) { - self.what = "Verify balances 4."; + $.remote.transaction() + .payment("bob", "alice", "0.5/AUD/mtgox") + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - testutils.verify_balances(self.remote, - { - "alice" : "0.5/AUD/mtgox", - "bob" : "0.5/AUD/mtgox", - "mtgox" : [ "-0.5/AUD/alice","-0.5/AUD/bob" ], - }, - callback); - }, - ], function (error) { - buster.refute(error, self.what); + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + + function (callback) { + self.what = "Verify balances 3."; + + testutils.verify_balances($.remote, { + "alice" : "0.5/AUD/mtgox", + "bob" : "0.5/AUD/mtgox", + "mtgox" : [ "-0.5/AUD/alice","-0.5/AUD/bob" ], + }, + callback); + }, + + function (callback) { + self.what = "Subscribe and accept."; + self.count = 0; + self.found = 0; + + $.remote + .on('transaction', function (m) { + // console.log("ACCOUNT: %s", JSON.stringify(m)); + self.found = 1; + }) + .on('ledger_closed', function (m) { + // console.log("LEDGER_CLOSE: %d: %s", self.count, JSON.stringify(m)); + + if (self.count) { + callback(!self.found); + } else { + self.count = 1; + $.remote.ledger_accept(); + } + }) + .request_subscribe().accounts("mtgox") + .request(); + + $.remote.ledger_accept(); + }, + function (callback) { + self.what = "Verify balances 4."; + + testutils.verify_balances($.remote, { + "alice" : "0.5/AUD/mtgox", + "bob" : "0.5/AUD/mtgox", + "mtgox" : [ "-0.5/AUD/alice","-0.5/AUD/bob" ], + }, + callback); + }, + ] + + async.waterfall(steps, function (error) { + assert(!error, self.what); done(); }); - }, + }); }); -buster.testCase("Indirect ripple", { - 'setUp' : testutils.build_setup(), - // 'setUp' : testutils.build_setup({ verbose: true }), - 'tearDown' : testutils.build_teardown(), - "indirect ripple" : function (done) { +suite('Indirect ripple', function() { + var $ = { }; + + setup(function(done) { + testutils.build_setup().call($, done); + }); + + teardown(function(done) { + testutils.build_teardown().call($, done); + }); + + test("indirect ripple", function (done) { var self = this; - // self.remote.set_trace(); + // $.remote.set_trace(); - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + var steps = [ + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); - }, - function (callback) { - self.what = "Set credit limits."; + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); + }, + function (callback) { + self.what = "Set credit limits."; - testutils.credit_limits(self.remote, - { - "alice" : "600/USD/mtgox", - "bob" : "700/USD/mtgox", - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; + testutils.credit_limits($.remote, { + "alice" : "600/USD/mtgox", + "bob" : "700/USD/mtgox", + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; - testutils.payments(self.remote, - { - "mtgox" : [ "70/USD/alice", "50/USD/bob" ], - }, - callback); - }, - function (callback) { - self.what = "Verify alice balance with mtgox."; + testutils.payments($.remote, { + "mtgox" : [ "70/USD/alice", "50/USD/bob" ], + }, + 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($.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 (callback) { - self.what = "Alice sends more than has to issuer: 100 out of 70"; + testutils.verify_balance($.remote, "bob", "50/USD/mtgox", callback); + }, + function (callback) { + self.what = "Alice sends more than has to issuer: 100 out of 70"; - self.remote.transaction() - .payment("alice", "mtgox", "100/USD/mtgox") - .once('submitted', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tecPATH_PARTIAL'); - }) - .submit(); - }, - function (callback) { - self.what = "Alice sends more than has to bob: 100 out of 70"; + $.remote.transaction() + .payment("alice", "mtgox", "100/USD/mtgox") + .once('submitted', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tecPATH_PARTIAL'); + }) + .submit(); + }, + function (callback) { + self.what = "Alice sends more than has to bob: 100 out of 70"; - self.remote.transaction() - .payment("alice", "bob", "100/USD/mtgox") - .once('submitted', function (m) { - //console.log("proposed: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tecPATH_PARTIAL'); - }) - .submit(); - }, - ], function (error) { - buster.refute(error, self.what); + $.remote.transaction() + .payment("alice", "bob", "100/USD/mtgox") + .once('submitted', function (m) { + //console.log("proposed: %s", JSON.stringify(m)); + callback(m.engine_result !== 'tecPATH_PARTIAL'); + }) + .submit(); + } + ] + + async.waterfall(steps, function(error) { + assert(!error, self.what); done(); }); - }, + }); - "indirect ripple with path" : function (done) { + test("indirect ripple with path", function (done) { var self = this; - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + var steps = [ + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); - }, - function (callback) { - self.what = "Set credit limits."; + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback); + }, + function (callback) { + self.what = "Set credit limits."; - testutils.credit_limits(self.remote, - { - "alice" : "600/USD/mtgox", - "bob" : "700/USD/mtgox", - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; + testutils.credit_limits($.remote, { + "alice" : "600/USD/mtgox", + "bob" : "700/USD/mtgox", + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; - testutils.payments(self.remote, - { - "mtgox" : [ "70/USD/alice", "50/USD/bob" ], - }, - callback); - }, - function (callback) { - self.what = "Alice sends via a path"; + testutils.payments($.remote, { + "mtgox" : [ "70/USD/alice", "50/USD/bob" ], + }, + callback); + }, + function (callback) { + self.what = "Alice sends via a path"; - self.remote.transaction() - .payment("alice", "bob", "5/USD/mtgox") - .path_add( [ { account: "mtgox" } ]) - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + $.remote.transaction() + .payment("alice", "bob", "5/USD/mtgox") + .path_add( [ { account: "mtgox" } ]) + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify alice balance with mtgox."; + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify alice balance with mtgox."; - testutils.verify_balance(self.remote, "alice", "65/USD/mtgox", callback); - }, - function (callback) { - self.what = "Verify bob balance with mtgox."; + testutils.verify_balance($.remote, "alice", "65/USD/mtgox", callback); + }, + function (callback) { + self.what = "Verify bob balance with mtgox."; - testutils.verify_balance(self.remote, "bob", "55/USD/mtgox", callback); - }, - ], function (error) { - buster.refute(error, self.what); + testutils.verify_balance($.remote, "bob", "55/USD/mtgox", callback); + } + ] + + async.waterfall(steps, function(error) { + assert(!error, self.what); done(); }); - }, + }); - "indirect ripple with multi path" : function (done) { + test("indirect ripple with multi path", function (done) { var self = this; - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + var steps = [ + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "carol", "amazon", "mtgox"], callback); - }, - function (callback) { - self.what = "Set credit limits."; + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "carol", "amazon", "mtgox"], callback); + }, + function (callback) { + self.what = "Set credit limits."; - testutils.credit_limits(self.remote, - { - "amazon" : "2000/USD/mtgox", - "bob" : [ "600/USD/alice", "1000/USD/mtgox" ], - "carol" : [ "700/USD/alice", "1000/USD/mtgox" ], - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; + testutils.credit_limits($.remote, { + "amazon" : "2000/USD/mtgox", + "bob" : [ "600/USD/alice", "1000/USD/mtgox" ], + "carol" : [ "700/USD/alice", "1000/USD/mtgox" ], + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; - testutils.payments(self.remote, - { - "mtgox" : [ "100/USD/bob", "100/USD/carol" ], - }, - callback); - }, - function (callback) { - self.what = "Alice pays amazon via multiple paths"; + testutils.payments($.remote, { + "mtgox" : [ "100/USD/bob", "100/USD/carol" ], + }, + callback); + }, + function (callback) { + self.what = "Alice pays amazon via multiple paths"; - self.remote.transaction() - .payment("alice", "amazon", "150/USD/mtgox") - .path_add( [ { account: "bob" } ]) - .path_add( [ { account: "carol" } ]) - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + $.remote.transaction() + .payment("alice", "amazon", "150/USD/mtgox") + .path_add( [ { account: "bob" } ]) + .path_add( [ { account: "carol" } ]) + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances."; + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balances."; - testutils.verify_balances(self.remote, - { - "alice" : [ "-100/USD/bob", "-50/USD/carol" ], - "amazon" : "150/USD/mtgox", - "bob" : "0/USD/mtgox", - "carol" : "50/USD/mtgox", - }, - callback); - }, - ], function (error) { - buster.refute(error, self.what); + testutils.verify_balances($.remote, { + "alice" : [ "-100/USD/bob", "-50/USD/carol" ], + "amazon" : "150/USD/mtgox", + "bob" : "0/USD/mtgox", + "carol" : "50/USD/mtgox", + }, + callback); + }, + ] + + async.waterfall(steps, function(error) { + assert(!error, self.what); done(); }); - }, + }); - "indirect ripple with path and transfer fee" : function (done) { + test("indirect ripple with path and transfer fee", function (done) { var self = this; - async.waterfall([ - function (callback) { - self.what = "Create accounts."; + var steps = [ + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "carol", "amazon", "mtgox"], callback); - }, - function (callback) { - self.what = "Set mtgox transfer rate."; + testutils.create_accounts($.remote, "root", "10000.0", ["alice", "bob", "carol", "amazon", "mtgox"], callback); + }, + function (callback) { + self.what = "Set mtgox transfer rate."; - testutils.transfer_rate(self.remote, "mtgox", 1.1e9, callback); - }, - function (callback) { - self.what = "Set credit limits."; + testutils.transfer_rate($.remote, "mtgox", 1.1e9, callback); + }, + function (callback) { + self.what = "Set credit limits."; - testutils.credit_limits(self.remote, - { - "amazon" : "2000/USD/mtgox", - "bob" : [ "600/USD/alice", "1000/USD/mtgox" ], - "carol" : [ "700/USD/alice", "1000/USD/mtgox" ], - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; + testutils.credit_limits($.remote, { + "amazon" : "2000/USD/mtgox", + "bob" : [ "600/USD/alice", "1000/USD/mtgox" ], + "carol" : [ "700/USD/alice", "1000/USD/mtgox" ], + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; - testutils.payments(self.remote, - { - "mtgox" : [ "100/USD/bob", "100/USD/carol" ], - }, - callback); - }, - function (callback) { - self.what = "Alice pays amazon via multiple paths"; + testutils.payments($.remote, { + "mtgox" : [ "100/USD/bob", "100/USD/carol" ], + }, + callback); + }, + function (callback) { + self.what = "Alice pays amazon via multiple paths"; - self.remote.transaction() - .payment("alice", "amazon", "150/USD/mtgox") - .send_max("200/USD/alice") - .path_add( [ { account: "bob" } ]) - .path_add( [ { account: "carol" } ]) - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + $.remote.transaction() + .payment("alice", "amazon", "150/USD/mtgox") + .send_max("200/USD/alice") + .path_add( [ { account: "bob" } ]) + .path_add( [ { account: "carol" } ]) + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.engine_result !== 'tesSUCCESS'); - }) - .submit(); - }, - // 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 (callback) { - self.what = "Verify balances."; + callback(m.engine_result !== 'tesSUCCESS'); + }) + .submit(); + }, + // function (callback) { + // self.what = "Display ledger"; + // + // $.remote.request_ledger('current', true) + // .on('success', function (m) { + // console.log("Ledger: %s", JSON.stringify(m, undefined, 2)); + // + // callback(); + // }) + // .request(); + // }, + function (callback) { + self.what = "Verify balances."; - // 65.00000000000001 is correct. - // This is result of limited precision. - testutils.verify_balances(self.remote, - { - "alice" : [ "-100/USD/bob", "-65.00000000000001/USD/carol" ], - "amazon" : "150/USD/mtgox", - "bob" : "0/USD/mtgox", - "carol" : "35/USD/mtgox", - }, - callback); - }, - ], function (error) { - buster.refute(error, self.what); + // 65.00000000000001 is correct. + // This is result of limited precision. + testutils.verify_balances($.remote, { + "alice" : [ "-100/USD/bob", "-65.00000000000001/USD/carol" ], + "amazon" : "150/USD/mtgox", + "bob" : "0/USD/mtgox", + "carol" : "35/USD/mtgox", + }, + callback); + } + ] + + async.waterfall(steps, function(error) { + assert(!error, self.what); done(); }); - }, - // Direct ripple without no liqudity. - // Test with XRP at start and end. + }) }); -// vim:sw=2:sts=2:ts=8:et \ No newline at end of file +// vim:sw=2:sts=2:ts=8:et diff --git a/test/server-test.js b/test/server-test.js index ed12027b8..41191f367 100644 --- a/test/server-test.js +++ b/test/server-test.js @@ -1,34 +1,19 @@ -var buster = require("buster"); +var assert = require('assert'); var extend = require("extend"); var Server = require("./server").Server; - var testutils = require("./testutils"); var config = testutils.init_config(); -// How long to wait for server to start. -// var serverDelay = 1500; - -var alpha; - -buster.testCase("Standalone server startup", { - "server start and stop" : function (done) { - var cfg = extend({}, config.default_server_config, - config.servers.alpha); - - alpha = Server.from_config("alpha", cfg); - - alpha - .on('started', function () { - alpha - .on('stopped', function () { - buster.assert(true); - - done(); - }) - .stop(); +suite('Standalone server startup', function() { + test('server start and stop', function(done) { + var cfg = extend({}, config.default_server_config, config.servers.alpha); + var alpha = Server.from_config("alpha", cfg); + alpha.on('started', function () { + alpha.on('stopped', function () { + done(); }) - .start(); - } + alpha.stop(); + }) + alpha.start(); + }); }); - -// vim:sw=2:sts=2:ts=8:et \ No newline at end of file diff --git a/test/server.js b/test/server.js index cbdf68475..4b694677f 100644 --- a/test/server.js +++ b/test/server.js @@ -15,17 +15,16 @@ // Servers are created in tmp/server/$server // -var buster = require("buster"); -var child = require("child_process"); -var fs = require("fs"); -var path = require("path"); -var util = require("util"); -var EventEmitter = require('events').EventEmitter; - +var child = require("child_process"); +var fs = require("fs"); +var path = require("path"); +var util = require("util"); +var assert = require('assert'); +var EventEmitter = require('events').EventEmitter; var nodeutils = require("./nodeutils"); // Create a server object -var Server = function (name, config, verbose) { +function Server(name, config, verbose) { this.name = name; this.config = config; this.started = false; @@ -47,10 +46,8 @@ var Server = function (name, config, verbose) { ? nodejs_version[0] - wanted_version[0] : -1; - if (sgn < 0) - { + if (sgn < 0) { console.log("\n*** Node.js version is too low."); - throw "Nodejs version is too low."; } }; @@ -61,18 +58,6 @@ Server.from_config = function (name, config, verbose) { return new Server(name, config, verbose); }; -Server.prototype.on = function (e, c) { - EventEmitter.prototype.on.call(this, e, c); - - return this; -}; - -Server.prototype.once = function (e, c) { - EventEmitter.prototype.once.call(this, e, c); - - return this; -}; - Server.prototype.serverPath = function() { return path.resolve("tmp/server", this.name); }; @@ -98,20 +83,19 @@ Server.prototype._serverSpawnSync = function() { var self = this; var args = [ - "-a", - "-v", - "--conf=rippled.cfg" - ]; + "-a", + "-v", + "--conf=rippled.cfg" + ]; + + var options = { + cwd: this.serverPath(), + env: process.env, + stdio: this.quiet ? 'ignore' : 'inherit' + }; // Spawn in standalone mode for now. - this.child = child.spawn( - this.config.rippled_path, - args, - { - cwd: this.serverPath(), - env: process.env, - stdio: this.quiet ? 'ignore' : 'inherit' - }); + this.child = child.spawn(this.config.rippled_path, args, options); if (!this.quiet) console.log("server: start %s: %s --conf=%s", @@ -126,16 +110,10 @@ Server.prototype._serverSpawnSync = function() { self.emit('exited'); - // Workaround for - // https://github.com/busterjs/buster/issues/266 - if (!self.stopping) { - buster.assertions.throwOnFailure = true; - } - // If could not exec: code=127, signal=null // If regular exit: code=0, signal=null // Fail the test if the server has not called "stop". - buster.assert(self.stopping, 'Server died with signal '+signal); + assert(self.stopping, 'Server died with signal '+signal); }); }; @@ -146,13 +124,9 @@ Server.prototype._makeBase = function (done) { // Reset the server directory, build it if needed. nodeutils.resetPath(path, '0777', function (e) { - if (e) { - throw e; - } - else { - self._writeConfig(done); - } - }); + if (e) throw e; + self._writeConfig(done); + }); }; Server.prototype.verbose = function () { @@ -169,14 +143,10 @@ Server.prototype.start = function () { if (!this.quiet) console.log("server: start: %s: %s", this.name, JSON.stringify(this.config)); this._makeBase(function (e) { - if (e) { - throw e; - } - else { - self._serverSpawnSync(); - self.emit('started'); - } - }); + if (e) throw e; + self._serverSpawnSync(); + self.emit('started'); + }); return this; }; @@ -187,24 +157,20 @@ Server.prototype.stop = function () { self.stopping = true; - if (this.child) { - // Update the on exit to invoke done. - this.child.on('exit', function (code, signal) { - - if (!self.quiet) console.log("server: stop: server exited"); - - self.emit('stopped'); - - delete self.child; - }); - - this.child.kill(); - } - else - { - buster.log("server: stop: can't stop"); + if (!this.child) { + console.log("server: stop: can't stop"); + return; } + // Update the on exit to invoke done. + this.child.on('exit', function (code, signal) { + if (!self.quiet) console.log("server: stop: server exited"); + self.emit('stopped'); + delete self.child; + }); + + this.child.kill(); + return this; }; diff --git a/test/testutils.js b/test/testutils.js index f6b193e69..db3eee8fa 100644 --- a/test/testutils.js +++ b/test/testutils.js @@ -1,18 +1,19 @@ var async = require('async'); +var assert = require('assert'); var extend = require('extend'); - var Amount = require('ripple-lib').Amount; var Remote = require('ripple-lib').Remote; -var Server = require('./server').Server; var Transaction = require('ripple-lib').Transaction; +var Server = require('./server').Server; +var server = { }; function get_config() { - var cfg = require('./config-example'); + var cfg = require(__dirname + '/config-example'); // See if the person testing wants to override the configuration by creating a // file called test/config.js. try { - cfg = extend({}, cfg, require('./config')); + cfg = extend({}, cfg, require(__dirname + '/config')); } catch (e) { } return cfg; @@ -40,7 +41,7 @@ function account_dump(remote, account, callback) { request.ledger_hash(remote.ledger_hash()); request.account_root('root'); request.callback(function(err, r) { - buster.isNull(err); + assert(!err, self.what); if (err) { //console.log('error: %s', m); callback(err); @@ -119,7 +120,10 @@ function build_setup(opts, host) { data.server = Server.from_config(host, server_config, !!opts.verbose_server); - data.server.once('started', callback); + data.server.once('started', function() { + callback(); + }); + data.server.once('exited', function () { // If know the remote, tell it server is gone. if (self.remote) { @@ -127,12 +131,15 @@ function build_setup(opts, host) { } }); + server[host] = data.server; data.server.start(); }, function connect_websocket(callback) { self.remote = data.remote = Remote.from_config(host, !!opts.verbose_ws); - self.remote.once('ledger_closed', callback); + self.remote.once('ledger_closed', function(ledger) { + callback(); + }); self.remote.connect(); } ]; @@ -158,21 +165,22 @@ function build_teardown(host) { var series = [ function disconnect_websocket(callback) { - data.remote.once('disconnected', callback) - data.remote.once('error', function (m) { - console.log('server error: ', m); - }) - data.remote.connect(false); - }, + data.remote.once('disconnected', callback) + data.remote.once('error', function (m) { + //console.log('server error: ', m); + }) + data.remote.connect(false); + }, - function stop_server(callback) { - if (opts.no_server) { - callback(); - } else { - data.server.once('stopped', callback) - data.server.stop(); + function stop_server(callback) { + if (opts.no_server) { + callback(); + } else { + data.server.once('stopped', callback) + data.server.stop(); + delete server[host]; + } } - } ]; async.series(series, done); @@ -196,12 +204,12 @@ function create_accounts(remote, src, amount, accounts, callback) { tx.payment(src, account, amount); tx.once('proposed', function (m) { - // console.log('proposed: %s', JSON.stringify(m)); + //console.log('proposed: %s', JSON.stringify(m)); callback(m.engine_result === 'tesSUCCESS' ? null : new Error()); }); tx.once('error', function (m) { - // console.log('error: %s', JSON.stringify(m)); + //console.log('error: %s', JSON.stringify(m)); callback(m); }); @@ -220,9 +228,9 @@ function credit_limit(remote, src, amount, callback) { } // console.log('credit_limit: parsed: %s', JSON.stringify(_m, undefined, 2)); - var account_limit = _m[1]; - var quality_in = _m[2]; - var quality_out = _m[3]; + var account_limit = _m[1]; + var quality_in = _m[2]; + var quality_out = _m[3]; var tx = remote.transaction() @@ -269,9 +277,9 @@ function verify_limit(remote, src, amount, callback) { if (err) { callback(err); } else { - buster.assert(m.account_limit.equals(limit)); - buster.assert(isNaN(quality_in) || m.account_quality_in === quality_in); - buster.assert(isNaN(quality_out) || m.account_quality_out === quality_out); + assert(m.account_limit.equals(limit)); + assert(isNaN(quality_in) || m.account_quality_in === quality_in); + assert(isNaN(quality_out) || m.account_quality_out === quality_out); callback(null); } }); @@ -321,7 +329,6 @@ function payment(remote, src, dst, amount, callback) { // console.log('error: %s', JSON.stringify(m)); callback(m); }); - tx.submit(); }; @@ -348,7 +355,7 @@ function payments(remote, balances, callback) { }; function transfer_rate(remote, src, billionths, callback) { - assert(arguments.length === 4); + assert.strictEqual(arguments.length, 4); var tx = remote.transaction(); tx.account_set(src); @@ -518,4 +525,10 @@ exports.verify_offer_not_found = verify_offer_not_found; exports.verify_owner_count = verify_owner_count; exports.verify_owner_counts = verify_owner_counts; +process.on('uncaughtException', function() { + Object.keys(server).forEach(function(host) { + server[host].stop(); + }); +}); + // vim:sw=2:sts=2:ts=8:et diff --git a/test/websocket-test.js b/test/websocket-test.js index 2415288f0..d0070700f 100644 --- a/test/websocket-test.js +++ b/test/websocket-test.js @@ -1,55 +1,46 @@ -var buster = require("buster"); +var assert = require('assert'); var extend = require("extend"); - var Server = require("./server").Server; var Remote = require("ripple-lib").Remote; - var testutils = require('./testutils'); var config = testutils.init_config(); -buster.testRunner.timeout = 5000; +suite('WebSocket connection', function() { + var server; -var server; -buster.testCase("WebSocket connection", { - 'setUp' : - function (done) { - var cfg = extend({}, config.default_server_config, - config.servers.alpha); - if (cfg.no_server) { + setup(function(done) { + var cfg = extend({}, config.default_server_config, config.servers.alpha); + if (cfg.no_server) { + done(); + } else { + server = Server.from_config("alpha", cfg); + server.once('started', done) + server.start(); + } + }); + + teardown(function(done) { + if (config.servers.alpha.no_server) { + done(); + } else { + server.on('stopped', done); + server.stop(); + } + }); + + test('WebSocket connect and disconnect', function() { + var alpha = Remote.from_config("alpha"); + + alpha.on('connected', function () { + alpha.on('disconnected', function () { + // CLOSED done(); - } else { - server = Server.from_config("alpha", cfg).on('started', done).start(); - } - }, + }); + alpha.connect(false); + }) - 'tearDown' : - function (done) { - if (config.servers.alpha.no_server) { - done(); - } else { - server.on('stopped', done).stop(); - } - }, - - "websocket connect and disconnect" : - function (done) { - var alpha = Remote.from_config("alpha"); - - alpha - .on('connected', function () { - // OPEN - buster.assert(true); - - alpha - .on('disconnected', function () { - // CLOSED - buster.assert(true); - done(); - }) - .connect(false); - }) - .connect(); - }, + alpha.connect(); + }); }); // vim:sw=2:sts=2:ts=8:et