From 49e6ca70ba9b2e6f0ca9562d8f54dfc4ea559d08 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sat, 24 Nov 2012 14:07:21 -0800 Subject: [PATCH] JS & UT: add et to vim setting. --- src/js/account.js | 2 +- src/js/amount.js | 2 +- src/js/jsbn.js | 2 +- src/js/network.js | 2 +- src/js/nodeutils.js | 2 +- src/js/remote.js | 2 +- src/js/serializer.js | 2 +- src/js/utils.js | 2 +- test/amount-test.js | 16 +- test/buster.js | 4 +- test/config-example.js | 4 +- test/monitor-test.js | 58 +- test/offer-test.js | 1253 ++++++++++++++++++++-------------------- test/path-test.js | 85 +-- test/remote-test.js | 280 ++++----- test/send-test.js | 1129 ++++++++++++++++++------------------ test/server-test.js | 20 +- test/server.js | 50 +- test/testutils.js | 187 +++--- test/utils-test.js | 4 +- test/websocket-test.js | 28 +- 21 files changed, 1569 insertions(+), 1565 deletions(-) diff --git a/src/js/account.js b/src/js/account.js index 4c84eb6cf8..b126435229 100644 --- a/src/js/account.js +++ b/src/js/account.js @@ -22,4 +22,4 @@ var Account = function (network, account) { exports.Account = Account; -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et diff --git a/src/js/amount.js b/src/js/amount.js index 1ea582d471..6ac0b627bd 100644 --- a/src/js/amount.js +++ b/src/js/amount.js @@ -704,4 +704,4 @@ exports.UInt160 = UInt160; exports.config = {}; -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et diff --git a/src/js/jsbn.js b/src/js/jsbn.js index 61325fcbd1..772ae15fc7 100644 --- a/src/js/jsbn.js +++ b/src/js/jsbn.js @@ -1216,4 +1216,4 @@ BigInteger.ONE = nbv(1); exports.nbi = nbi; exports.BigInteger = BigInteger; -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et diff --git a/src/js/network.js b/src/js/network.js index a98cee302f..714aa335f1 100644 --- a/src/js/network.js +++ b/src/js/network.js @@ -55,4 +55,4 @@ Network.protocol.stop = function () { exports.Network = Network; -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et diff --git a/src/js/nodeutils.js b/src/js/nodeutils.js index 1959ef87ac..f57334699c 100644 --- a/src/js/nodeutils.js +++ b/src/js/nodeutils.js @@ -88,4 +88,4 @@ exports.mkPath = mkPath; exports.resetPath = resetPath; exports.rmPath = rmPath; -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et diff --git a/src/js/remote.js b/src/js/remote.js index a298f6e92c..d832e9e863 100644 --- a/src/js/remote.js +++ b/src/js/remote.js @@ -1489,4 +1489,4 @@ Transaction.prototype.wallet_add = function (src, amount, authorized_key, public exports.config = {}; exports.Remote = Remote; -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et diff --git a/src/js/serializer.js b/src/js/serializer.js index 00f9e070b5..6a75e84ef7 100644 --- a/src/js/serializer.js +++ b/src/js/serializer.js @@ -41,4 +41,4 @@ serializer.addUInt160 = function(value) { serializer.getSHA512Half = function() { }; -// vim:ts=4 +// vim:sw=2:sts=2:ts=8:et diff --git a/src/js/utils.js b/src/js/utils.js index e51ca76ede..34131e9408 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -76,4 +76,4 @@ exports.hexToString = hexToString; exports.stringToArray = stringToArray; exports.stringToHex = stringToHex; -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et diff --git a/test/amount-test.js b/test/amount-test.js index 98eff5b02f..5450f9f428 100644 --- a/test/amount-test.js +++ b/test/amount-test.js @@ -1,12 +1,12 @@ -var buster = require("buster"); +var buster = require("buster"); -var jsbn = require('../src/js/jsbn.js'); -var BigInteger = jsbn.BigInteger; -var nbi = jsbn.nbi; +var jsbn = require('../src/js/jsbn.js'); +var BigInteger = jsbn.BigInteger; +var nbi = jsbn.nbi; -var amount = require("../src/js/amount.js"); -var Amount = require("../src/js/amount.js").Amount; -var UInt160 = require("../src/js/amount.js").UInt160; +var amount = require("../src/js/amount.js"); +var Amount = require("../src/js/amount.js").Amount; +var UInt160 = require("../src/js/amount.js").UInt160; require("../src/js/amount.js").config = require("./config.js"); @@ -107,4 +107,4 @@ buster.testCase("Amount", { } }); -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et diff --git a/test/buster.js b/test/buster.js index 5dd49ec7cc..c445406541 100644 --- a/test/buster.js +++ b/test/buster.js @@ -4,6 +4,8 @@ config["Newcoin tests"] = { rootPath: "../", environment: "node", tests: [ - "test/*-test.js" + "test/*-test.js" ] } + +// vim:sw=2:sts=2:ts=8:et diff --git a/test/config-example.js b/test/config-example.js index 7bbff3a0d5..403b91d482 100644 --- a/test/config-example.js +++ b/test/config-example.js @@ -7,7 +7,7 @@ var path = require("path"); // Where to find the binary. exports.rippled = path.resolve("build/rippled"); -exports.server_default = "alpha"; +exports.server_default = "alpha"; // Configuration for servers. exports.servers = { @@ -66,4 +66,4 @@ exports.accounts = { }, }; -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et diff --git a/test/monitor-test.js b/test/monitor-test.js index aa8c385b49..6e4abc5a3e 100644 --- a/test/monitor-test.js +++ b/test/monitor-test.js @@ -1,17 +1,17 @@ -var async = require("async"); -var buster = require("buster"); +var async = require("async"); +var buster = require("buster"); -var Amount = require("../src/js/amount.js").Amount; -var Remote = require("../src/js/remote.js").Remote; -var Server = require("./server.js").Server; +var Amount = require("../src/js/amount.js").Amount; +var Remote = require("../src/js/remote.js").Remote; +var Server = require("./server.js").Server; -var testutils = require("./testutils.js"); +var testutils = require("./testutils.js"); require("../src/js/amount.js").config = require("./config.js"); require("../src/js/remote.js").config = require("./config.js"); buster.testRunner.timeout = 5000; - + buster.testCase("//Monitor account", { 'setUp' : testutils.build_setup({ verbose: true }), 'tearDown' : testutils.build_teardown(), @@ -21,34 +21,34 @@ buster.testCase("//Monitor account", { var self = this; async.waterfall([ - function (callback) { - self.what = "Create accounts."; + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000", ["alice"], callback); - }, - function (callback) { - self.what = "Close ledger."; + testutils.create_accounts(self.remote, "root", "10000", ["alice"], callback); + }, + function (callback) { + self.what = "Close ledger."; - self.remote.once('ledger_closed', function (ledger_closed, ledger_index) { - callback(); - }); + self.remote.once('ledger_closed', function (ledger_closed, ledger_index) { + callback(); + }); - self.remote.ledger_accept(); - }, - function (callback) { - self.what = "Dumping root."; + self.remote.ledger_accept(); + }, + function (callback) { + self.what = "Dumping root."; - testutils.account_dump(self.remote, "root", function (error) { - buster.refute(error); - - callback(); - }); - }, + testutils.account_dump(self.remote, "root", function (error) { + buster.refute(error); + + callback(); + }); + }, ], function (error) { - buster.refute(error, self.what); - done(); + buster.refute(error, self.what); + done(); }); }, }); -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et diff --git a/test/offer-test.js b/test/offer-test.js index 0c12c48013..ccdfa31b6e 100644 --- a/test/offer-test.js +++ b/test/offer-test.js @@ -1,12 +1,12 @@ -var async = require("async"); -var buster = require("buster"); +var async = require("async"); +var buster = require("buster"); -var Amount = require("../src/js/amount.js").Amount; -var Remote = require("../src/js/remote.js").Remote; -var Server = require("./server.js").Server; +var Amount = require("../src/js/amount.js").Amount; +var Remote = require("../src/js/remote.js").Remote; +var Server = require("./server.js").Server; -var testutils = require("./testutils.js"); +var testutils = require("./testutils.js"); require("../src/js/amount.js").config = require("./config.js"); require("../src/js/remote.js").config = require("./config.js"); @@ -23,51 +23,51 @@ buster.testCase("Offer tests", { var final_create; async.waterfall([ - function (callback) { - self.remote.transaction() - .offer_create("root", "500", "100/USD/root") - .on('proposed', function (m) { - // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS', m); - }) - .on('final', function (m) { - // console.log("FINAL: offer_create: %s", JSON.stringify(m)); + function (callback) { + self.remote.transaction() + .offer_create("root", "500", "100/USD/root") + .on('proposed', function (m) { + // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS', m); + }) + .on('final', function (m) { + // console.log("FINAL: offer_create: %s", JSON.stringify(m)); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); + buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); - final_create = m; - }) - .submit(); - }, - function (m, callback) { - self.remote.transaction() - .offer_cancel("root", m.tx_json.Sequence) - .on('proposed', function (m) { - // console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS', m); - }) - .on('final', function (m) { - // console.log("FINAL: offer_cancel: %s", JSON.stringify(m)); + final_create = m; + }) + .submit(); + }, + function (m, callback) { + self.remote.transaction() + .offer_cancel("root", m.tx_json.Sequence) + .on('proposed', function (m) { + // console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS', m); + }) + .on('final', function (m) { + // console.log("FINAL: offer_cancel: %s", JSON.stringify(m)); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); - buster.assert(final_create); - done(); - }) - .submit(); - }, - function (m, callback) { - self.remote - .once('ledger_closed', function (ledger_hash, ledger_index) { - // console.log("LEDGER_CLOSED: %d: %s", ledger_index, ledger_hash); - }) - .ledger_accept(); - } - ], function (error) { - // console.log("result: error=%s", error); - buster.refute(error); + buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); + buster.assert(final_create); + done(); + }) + .submit(); + }, + function (m, callback) { + self.remote + .once('ledger_closed', function (ledger_hash, ledger_index) { + // console.log("LEDGER_CLOSED: %d: %s", ledger_index, ledger_hash); + }) + .ledger_accept(); + } + ], function (error) { + // console.log("result: error=%s", error); + buster.refute(error); - if (error) done(); - }); + if (error) done(); + }); }, "offer_create then ledger_accept then offer_cancel then ledger_accept." : @@ -77,82 +77,82 @@ buster.testCase("Offer tests", { var offer_seq; async.waterfall([ - function (callback) { - self.remote.transaction() - .offer_create("root", "500", "100/USD/root") - .on('proposed', function (m) { - // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); + function (callback) { + self.remote.transaction() + .offer_create("root", "500", "100/USD/root") + .on('proposed', function (m) { + // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); - offer_seq = m.tx_json.Sequence; + offer_seq = m.tx_json.Sequence; - callback(m.result !== 'tesSUCCESS'); - }) - .on('final', function (m) { - // console.log("FINAL: offer_create: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); + }) + .on('final', function (m) { + // console.log("FINAL: offer_create: %s", JSON.stringify(m)); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); + buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); - final_create = m; + final_create = m; - callback(); - }) - .submit(); - }, - function (callback) { - if (!final_create) { - self.remote - .once('ledger_closed', function (ledger_hash, ledger_index) { - // console.log("LEDGER_CLOSED: %d: %s", ledger_index, ledger_hash); + callback(); + }) + .submit(); + }, + function (callback) { + if (!final_create) { + self.remote + .once('ledger_closed', function (ledger_hash, ledger_index) { + // console.log("LEDGER_CLOSED: %d: %s", ledger_index, ledger_hash); - }) - .ledger_accept(); - } - else { - callback(); - } - }, - function (callback) { - // console.log("CANCEL: offer_cancel: %d", offer_seq); + }) + .ledger_accept(); + } + else { + callback(); + } + }, + function (callback) { + // console.log("CANCEL: offer_cancel: %d", offer_seq); - self.remote.transaction() - .offer_cancel("root", offer_seq) - .on('proposed', function (m) { - // console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .on('final', function (m) { - // console.log("FINAL: offer_cancel: %s", JSON.stringify(m)); + self.remote.transaction() + .offer_cancel("root", offer_seq) + .on('proposed', function (m) { + // console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); + }) + .on('final', function (m) { + // console.log("FINAL: offer_cancel: %s", JSON.stringify(m)); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); - buster.assert(final_create); + buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); + buster.assert(final_create); - done(); - }) - .submit(); - }, - // See if ledger_accept will crash. - function (callback) { - self.remote - .once('ledger_closed', function (ledger_hash, ledger_index) { - // console.log("LEDGER_CLOSED: A: %d: %s", ledger_index, ledger_hash); - callback(); - }) - .ledger_accept(); - }, - function (callback) { - self.remote - .once('ledger_closed', function (ledger_hash, ledger_index) { - // console.log("LEDGER_CLOSED: B: %d: %s", ledger_index, ledger_hash); - callback(); - }) - .ledger_accept(); - }, - ], function (error) { - // console.log("result: error=%s", error); - buster.refute(error); + done(); + }) + .submit(); + }, + // See if ledger_accept will crash. + function (callback) { + self.remote + .once('ledger_closed', function (ledger_hash, ledger_index) { + // console.log("LEDGER_CLOSED: A: %d: %s", ledger_index, ledger_hash); + callback(); + }) + .ledger_accept(); + }, + function (callback) { + self.remote + .once('ledger_closed', function (ledger_hash, ledger_index) { + // console.log("LEDGER_CLOSED: B: %d: %s", ledger_index, ledger_hash); + callback(); + }) + .ledger_accept(); + }, + ], function (error) { + // console.log("result: error=%s", error); + buster.refute(error); - if (error) done(); - }); + if (error) done(); + }); }, @@ -163,92 +163,92 @@ buster.testCase("Offer tests", { var offer_seq; async.waterfall([ - function (callback) { - self.remote.transaction() - .payment('root', 'alice', "1000") - .set_flags('CreateAccount') - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - buster.assert.equals(m.result, 'tesSUCCESS'); - callback(); - }) - .submit() - }, - function (callback) { - self.remote.transaction() - .offer_create("alice", "500", "100/USD/alice") - .on('proposed', function (m) { - // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); + function (callback) { + self.remote.transaction() + .payment('root', 'alice', "1000") + .set_flags('CreateAccount') + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + buster.assert.equals(m.result, 'tesSUCCESS'); + callback(); + }) + .submit() + }, + function (callback) { + self.remote.transaction() + .offer_create("alice", "500", "100/USD/alice") + .on('proposed', function (m) { + // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); - offer_seq = m.tx_json.Sequence; + offer_seq = m.tx_json.Sequence; - callback(m.result !== 'tesSUCCESS'); - }) - .on('final', function (m) { - // console.log("FINAL: offer_create: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); + }) + .on('final', function (m) { + // console.log("FINAL: offer_create: %s", JSON.stringify(m)); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); + buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); - final_create = m; + final_create = m; - callback(); - }) - .submit(); - }, - function (callback) { - if (!final_create) { - self.remote - .once('ledger_closed', function (ledger_hash, ledger_index) { - // console.log("LEDGER_CLOSED: %d: %s", ledger_index, ledger_hash); + callback(); + }) + .submit(); + }, + function (callback) { + if (!final_create) { + self.remote + .once('ledger_closed', function (ledger_hash, ledger_index) { + // console.log("LEDGER_CLOSED: %d: %s", ledger_index, ledger_hash); - }) - .ledger_accept(); - } - else { - callback(); - } - }, - function (callback) { - // console.log("CANCEL: offer_cancel: %d", offer_seq); + }) + .ledger_accept(); + } + else { + callback(); + } + }, + function (callback) { + // console.log("CANCEL: offer_cancel: %d", offer_seq); - self.remote.transaction() - .offer_cancel("alice", offer_seq) - .on('proposed', function (m) { - // console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .on('final', function (m) { - // console.log("FINAL: offer_cancel: %s", JSON.stringify(m)); + self.remote.transaction() + .offer_cancel("alice", offer_seq) + .on('proposed', function (m) { + // console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); + }) + .on('final', function (m) { + // console.log("FINAL: offer_cancel: %s", JSON.stringify(m)); - buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); - buster.assert(final_create); + buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); + buster.assert(final_create); - done(); - }) - .submit(); - }, - // See if ledger_accept will crash. - function (callback) { - self.remote - .once('ledger_closed', function (ledger_hash, ledger_index) { - // console.log("LEDGER_CLOSED: A: %d: %s", ledger_index, ledger_hash); - callback(); - }) - .ledger_accept(); - }, - function (callback) { - self.remote - .once('ledger_closed', function (ledger_hash, ledger_index) { - // console.log("LEDGER_CLOSED: B: %d: %s", ledger_index, ledger_hash); - callback(); - }) - .ledger_accept(); - }, - ], function (error) { - // console.log("result: error=%s", error); - buster.refute(error); - if (error) done(); - }); + done(); + }) + .submit(); + }, + // See if ledger_accept will crash. + function (callback) { + self.remote + .once('ledger_closed', function (ledger_hash, ledger_index) { + // console.log("LEDGER_CLOSED: A: %d: %s", ledger_index, ledger_hash); + callback(); + }) + .ledger_accept(); + }, + function (callback) { + self.remote + .once('ledger_closed', function (ledger_hash, ledger_index) { + // console.log("LEDGER_CLOSED: B: %d: %s", ledger_index, ledger_hash); + callback(); + }) + .ledger_accept(); + }, + ], function (error) { + // console.log("result: error=%s", error); + buster.refute(error); + if (error) done(); + }); }, "offer cancel past and future sequence" : @@ -257,81 +257,81 @@ buster.testCase("Offer tests", { var final_create; async.waterfall([ - function (callback) { - self.remote.transaction() - .payment('root', 'alice', Amount.from_json("10000")) - .set_flags('CreateAccount') - .on('proposed', function (m) { - // console.log("PROPOSED: CreateAccount: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS', m); - }) - .on('error', function(m) { - // console.log("error: %s", m); + function (callback) { + self.remote.transaction() + .payment('root', 'alice', Amount.from_json("10000")) + .set_flags('CreateAccount') + .on('proposed', function (m) { + // console.log("PROPOSED: CreateAccount: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS', m); + }) + .on('error', function(m) { + // console.log("error: %s", m); - buster.assert(false); - callback(m); - }) - .submit(); - }, - // Past sequence but wrong - function (m, callback) { - self.remote.transaction() - .offer_cancel("root", m.tx_json.Sequence) - .on('proposed', function (m) { - // console.log("PROPOSED: offer_cancel past: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS', m); - }) - .submit(); - }, - // Same sequence - function (m, callback) { - self.remote.transaction() - .offer_cancel("root", m.tx_json.Sequence+1) - .on('proposed', function (m) { - // console.log("PROPOSED: offer_cancel same: %s", JSON.stringify(m)); - callback(m.result !== 'temBAD_SEQUENCE', m); - }) - .submit(); - }, - // Future sequence - function (m, callback) { - // After a malformed transaction, need to recover correct sequence. - self.remote.set_account_seq("root", self.remote.account_seq("root")-1); + buster.assert(false); + callback(m); + }) + .submit(); + }, + // Past sequence but wrong + function (m, callback) { + self.remote.transaction() + .offer_cancel("root", m.tx_json.Sequence) + .on('proposed', function (m) { + // console.log("PROPOSED: offer_cancel past: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS', m); + }) + .submit(); + }, + // Same sequence + function (m, callback) { + self.remote.transaction() + .offer_cancel("root", m.tx_json.Sequence+1) + .on('proposed', function (m) { + // console.log("PROPOSED: offer_cancel same: %s", JSON.stringify(m)); + callback(m.result !== 'temBAD_SEQUENCE', m); + }) + .submit(); + }, + // Future sequence + function (m, callback) { + // After a malformed transaction, need to recover correct sequence. + self.remote.set_account_seq("root", self.remote.account_seq("root")-1); - self.remote.transaction() - .offer_cancel("root", m.tx_json.Sequence+2) - .on('proposed', function (m) { - // console.log("ERROR: offer_cancel future: %s", JSON.stringify(m)); - callback(m.result !== 'temBAD_SEQUENCE'); - }) - .submit(); - }, - // See if ledger_accept will crash. - function (callback) { - self.remote - .once('ledger_closed', function (ledger_hash, ledger_index) { - // console.log("LEDGER_CLOSED: A: %d: %s", ledger_index, ledger_hash); - callback(); - }) - .ledger_accept(); - }, - function (callback) { - self.remote - .once('ledger_closed', function (ledger_hash, ledger_index) { - // console.log("LEDGER_CLOSED: B: %d: %s", ledger_index, ledger_hash); - callback(); - }) - .ledger_accept(); - }, - function (callback) { - callback(); - } - ], function (error) { - // console.log("result: error=%s", error); - buster.refute(error); + self.remote.transaction() + .offer_cancel("root", m.tx_json.Sequence+2) + .on('proposed', function (m) { + // console.log("ERROR: offer_cancel future: %s", JSON.stringify(m)); + callback(m.result !== 'temBAD_SEQUENCE'); + }) + .submit(); + }, + // See if ledger_accept will crash. + function (callback) { + self.remote + .once('ledger_closed', function (ledger_hash, ledger_index) { + // console.log("LEDGER_CLOSED: A: %d: %s", ledger_index, ledger_hash); + callback(); + }) + .ledger_accept(); + }, + function (callback) { + self.remote + .once('ledger_closed', function (ledger_hash, ledger_index) { + // console.log("LEDGER_CLOSED: B: %d: %s", ledger_index, ledger_hash); + callback(); + }) + .ledger_accept(); + }, + function (callback) { + callback(); + } + ], function (error) { + // console.log("result: error=%s", error); + buster.refute(error); - done(); - }); + done(); + }); }, "ripple currency conversion : entire offer" : @@ -341,80 +341,80 @@ buster.testCase("Offer tests", { var seq; async.waterfall([ - function (callback) { - self.what = "Create accounts."; + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "mtgox"], callback); - }, - function (callback) { - self.what = "Set limits."; + testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "mtgox"], callback); + }, + function (callback) { + self.what = "Set limits."; - testutils.credit_limits(self.remote, - { - "alice" : "100/USD/mtgox", - "bob" : "1000/USD/mtgox" - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; + testutils.credit_limits(self.remote, + { + "alice" : "100/USD/mtgox", + "bob" : "1000/USD/mtgox" + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; - testutils.payments(self.remote, - { - "mtgox" : "100/USD/alice" - }, - callback); - }, - function (callback) { - self.what = "Create offer."; + testutils.payments(self.remote, + { + "mtgox" : "100/USD/alice" + }, + callback); + }, + function (callback) { + self.what = "Create offer."; - self.remote.transaction() - .offer_create("bob", "100/USD/mtgox", "500") - .on('proposed', function (m) { - // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); + self.remote.transaction() + .offer_create("bob", "100/USD/mtgox", "500") + .on('proposed', function (m) { + // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); - seq = m.tx_json.Sequence; - }) - .submit(); - }, - function (callback) { - self.what = "Verify offer balance."; + seq = m.tx_json.Sequence; + }) + .submit(); + }, + function (callback) { + self.what = "Verify offer balance."; - testutils.verify_offer(self.remote, "bob", seq, "100/USD/mtgox", "500", callback); - }, - function (callback) { - self.what = "Alice converts USD to XRP."; + testutils.verify_offer(self.remote, "bob", seq, "100/USD/mtgox", "500", callback); + }, + function (callback) { + self.what = "Alice converts USD to XRP."; - self.remote.transaction() - .payment("alice", "alice", "500") - .send_max("100/USD/mtgox") - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + self.remote.transaction() + .payment("alice", "alice", "500") + .send_max("100/USD/mtgox") + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances."; + callback(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balances."; - testutils.verify_balances(self.remote, - { - "alice" : [ "0/USD/mtgox", String(10000+500-2*(Remote.fees['default'].to_number())) ], - "bob" : "100/USD/mtgox", - }, - callback); - }, - function (callback) { - self.what = "Verify offer consumed."; + testutils.verify_balances(self.remote, + { + "alice" : [ "0/USD/mtgox", String(10000+500-2*(Remote.fees['default'].to_number())) ], + "bob" : "100/USD/mtgox", + }, + callback); + }, + function (callback) { + self.what = "Verify offer consumed."; - testutils.verify_offer_not_found(self.remote, "bob", seq, callback); - }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); + testutils.verify_offer_not_found(self.remote, "bob", seq, callback); + }, + ], function (error) { + buster.refute(error, self.what); + done(); + }); }, "ripple currency conversion : in parts" : @@ -423,117 +423,117 @@ buster.testCase("Offer tests", { var seq; async.waterfall([ - function (callback) { - self.what = "Create accounts."; + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "mtgox"], callback); - }, - function (callback) { - self.what = "Set limits."; + testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "mtgox"], callback); + }, + function (callback) { + self.what = "Set limits."; - testutils.credit_limits(self.remote, - { - "alice" : "200/USD/mtgox", - "bob" : "1000/USD/mtgox" - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; + testutils.credit_limits(self.remote, + { + "alice" : "200/USD/mtgox", + "bob" : "1000/USD/mtgox" + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; - testutils.payments(self.remote, - { - "mtgox" : "200/USD/alice" - }, - callback); - }, - function (callback) { - self.what = "Create offer."; + testutils.payments(self.remote, + { + "mtgox" : "200/USD/alice" + }, + callback); + }, + function (callback) { + self.what = "Create offer."; - self.remote.transaction() - .offer_create("bob", "100/USD/mtgox", "500") - .on('proposed', function (m) { - // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); + self.remote.transaction() + .offer_create("bob", "100/USD/mtgox", "500") + .on('proposed', function (m) { + // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); - seq = m.tx_json.Sequence; - }) - .submit(); - }, - function (callback) { - self.what = "Alice converts USD to XRP."; + seq = m.tx_json.Sequence; + }) + .submit(); + }, + function (callback) { + self.what = "Alice converts USD to XRP."; - self.remote.transaction() - .payment("alice", "alice", "200") - .send_max("100/USD/mtgox") - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + self.remote.transaction() + .payment("alice", "alice", "200") + .send_max("100/USD/mtgox") + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify offer balance."; + callback(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify offer balance."; - testutils.verify_offer(self.remote, "bob", seq, "60/USD/mtgox", "300", callback); - }, - function (callback) { - self.what = "Verify balances."; + testutils.verify_offer(self.remote, "bob", seq, "60/USD/mtgox", "300", callback); + }, + function (callback) { + self.what = "Verify balances."; - testutils.verify_balances(self.remote, - { - "alice" : [ "160/USD/mtgox", String(10000+200-2*(Remote.fees['default'].to_number())) ], - "bob" : "40/USD/mtgox", - }, - callback); - }, - function (callback) { - self.what = "Alice converts USD to XRP should fail due to PartialPayment."; + testutils.verify_balances(self.remote, + { + "alice" : [ "160/USD/mtgox", String(10000+200-2*(Remote.fees['default'].to_number())) ], + "bob" : "40/USD/mtgox", + }, + callback); + }, + function (callback) { + self.what = "Alice converts USD to XRP should fail due to PartialPayment."; - self.remote.transaction() - .payment("alice", "alice", "600") - .send_max("100/USD/mtgox") - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + self.remote.transaction() + .payment("alice", "alice", "600") + .send_max("100/USD/mtgox") + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tepPATH_PARTIAL'); - }) - .submit(); - }, - function (callback) { - self.what = "Alice converts USD to XRP."; + callback(m.result !== 'tepPATH_PARTIAL'); + }) + .submit(); + }, + function (callback) { + self.what = "Alice converts USD to XRP."; - self.remote.transaction() - .payment("alice", "alice", "600") - .send_max("100/USD/mtgox") - .set_flags('PartialPayment') - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + self.remote.transaction() + .payment("alice", "alice", "600") + .send_max("100/USD/mtgox") + .set_flags('PartialPayment') + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify offer consumed."; + callback(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify offer consumed."; - testutils.verify_offer_not_found(self.remote, "bob", seq, callback); - }, - function (callback) { - self.what = "Verify balances."; + testutils.verify_offer_not_found(self.remote, "bob", seq, callback); + }, + function (callback) { + self.what = "Verify balances."; - testutils.verify_balances(self.remote, - { - "alice" : [ "100/USD/mtgox", String(10000+200+300-4*(Remote.fees['default'].to_number())) ], - "bob" : "100/USD/mtgox", - }, - callback); - }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); + testutils.verify_balances(self.remote, + { + "alice" : [ "100/USD/mtgox", String(10000+200+300-4*(Remote.fees['default'].to_number())) ], + "bob" : "100/USD/mtgox", + }, + callback); + }, + ], function (error) { + buster.refute(error, self.what); + done(); + }); }, }); @@ -551,76 +551,76 @@ buster.testCase("Offer cross currency", { // self.remote.set_trace(); async.waterfall([ - function (callback) { - self.what = "Create accounts."; + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "carol", "mtgox"], callback); - }, - function (callback) { - self.what = "Set limits."; + testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "carol", "mtgox"], callback); + }, + function (callback) { + self.what = "Set limits."; - testutils.credit_limits(self.remote, - { - "carol" : "1000/USD/mtgox", - "bob" : "2000/USD/mtgox" - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; + testutils.credit_limits(self.remote, + { + "carol" : "1000/USD/mtgox", + "bob" : "2000/USD/mtgox" + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; - testutils.payments(self.remote, - { - "mtgox" : "500/USD/carol" - }, - callback); - }, - function (callback) { - self.what = "Create offer."; + testutils.payments(self.remote, + { + "mtgox" : "500/USD/carol" + }, + callback); + }, + function (callback) { + self.what = "Create offer."; - self.remote.transaction() - .offer_create("carol", "500", "50/USD/mtgox") - .on('proposed', function (m) { - // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); + self.remote.transaction() + .offer_create("carol", "500", "50/USD/mtgox") + .on('proposed', function (m) { + // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); - seq = m.tx_json.Sequence; - }) - .submit(); - }, - function (callback) { - self.what = "Alice send USD/mtgox converting from XRP."; + seq = m.tx_json.Sequence; + }) + .submit(); + }, + function (callback) { + self.what = "Alice send USD/mtgox converting from XRP."; - self.remote.transaction() - .payment("alice", "bob", "25/USD/mtgox") - .send_max("333") - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + self.remote.transaction() + .payment("alice", "bob", "25/USD/mtgox") + .send_max("333") + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances."; + callback(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balances."; - testutils.verify_balances(self.remote, - { -// "alice" : [ "500" ], - "bob" : "25/USD/mtgox", - "carol" : "475/USD/mtgox", - }, - callback); - }, - function (callback) { - self.what = "Verify offer consumed."; + testutils.verify_balances(self.remote, + { +// "alice" : [ "500" ], + "bob" : "25/USD/mtgox", + "carol" : "475/USD/mtgox", + }, + callback); + }, + function (callback) { + self.what = "Verify offer consumed."; - testutils.verify_offer_not_found(self.remote, "bob", seq, callback); - }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); + testutils.verify_offer_not_found(self.remote, "bob", seq, callback); + }, + ], function (error) { + buster.refute(error, self.what); + done(); + }); }, "ripple cross currency payment - end with XRP" : @@ -633,76 +633,76 @@ buster.testCase("Offer cross currency", { // self.remote.set_trace(); async.waterfall([ - function (callback) { - self.what = "Create accounts."; + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "carol", "mtgox"], callback); - }, - function (callback) { - self.what = "Set limits."; + testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "carol", "mtgox"], callback); + }, + function (callback) { + self.what = "Set limits."; - testutils.credit_limits(self.remote, - { - "alice" : "1000/USD/mtgox", - "carol" : "2000/USD/mtgox" - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; + testutils.credit_limits(self.remote, + { + "alice" : "1000/USD/mtgox", + "carol" : "2000/USD/mtgox" + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; - testutils.payments(self.remote, - { - "mtgox" : "500/USD/alice" - }, - callback); - }, - function (callback) { - self.what = "Create offer."; + testutils.payments(self.remote, + { + "mtgox" : "500/USD/alice" + }, + callback); + }, + function (callback) { + self.what = "Create offer."; - self.remote.transaction() - .offer_create("carol", "50/USD/mtgox", "500") - .on('proposed', function (m) { - // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); + self.remote.transaction() + .offer_create("carol", "50/USD/mtgox", "500") + .on('proposed', function (m) { + // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); - seq = m.tx_json.Sequence; - }) - .submit(); - }, - function (callback) { - self.what = "Alice send XRP to bob converting from USD/mtgox."; + seq = m.tx_json.Sequence; + }) + .submit(); + }, + function (callback) { + self.what = "Alice send XRP to bob converting from USD/mtgox."; - self.remote.transaction() - .payment("alice", "bob", "250") - .send_max("333/USD/mtgox") - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + self.remote.transaction() + .payment("alice", "bob", "250") + .send_max("333/USD/mtgox") + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances."; + callback(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balances."; - testutils.verify_balances(self.remote, - { - "alice" : "475/USD/mtgox", - "bob" : "10250", - "carol" : "25/USD/mtgox", - }, - callback); - }, - function (callback) { - self.what = "Verify offer partially consumed."; + testutils.verify_balances(self.remote, + { + "alice" : "475/USD/mtgox", + "bob" : "10250", + "carol" : "25/USD/mtgox", + }, + callback); + }, + function (callback) { + self.what = "Verify offer partially consumed."; - testutils.verify_offer(self.remote, "carol", seq, "25/USD/mtgox", "250", callback); - }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); + testutils.verify_offer(self.remote, "carol", seq, "25/USD/mtgox", "250", callback); + }, + ], function (error) { + buster.refute(error, self.what); + done(); + }); }, "ripple cross currency bridged payment" : @@ -716,99 +716,100 @@ buster.testCase("Offer cross currency", { // self.remote.set_trace(); async.waterfall([ - function (callback) { - self.what = "Create accounts."; + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "carol", "dan", "bitstamp", "mtgox"], callback); - }, - function (callback) { - self.what = "Set limits."; + testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "carol", "dan", "bitstamp", "mtgox"], callback); + }, + function (callback) { + self.what = "Set limits."; - testutils.credit_limits(self.remote, - { - "alice" : "1000/USD/mtgox", - "bob" : "1000/EUR/bitstamp", - "carol" : "1000/USD/mtgox", - "dan" : "1000/EUR/bitstamp" - }, - callback); - }, - function (callback) { - self.what = "Distribute funds."; + testutils.credit_limits(self.remote, + { + "alice" : "1000/USD/mtgox", + "bob" : "1000/EUR/bitstamp", + "carol" : "1000/USD/mtgox", + "dan" : "1000/EUR/bitstamp" + }, + callback); + }, + function (callback) { + self.what = "Distribute funds."; - testutils.payments(self.remote, - { - "bitstamp" : "400/EUR/dan", - "mtgox" : "500/USD/alice", - }, - callback); - }, - function (callback) { - self.what = "Create offer carol."; + testutils.payments(self.remote, + { + "bitstamp" : "400/EUR/dan", + "mtgox" : "500/USD/alice", + }, + callback); + }, + function (callback) { + self.what = "Create offer carol."; - self.remote.transaction() - .offer_create("carol", "50/USD/mtgox", "500") - .on('proposed', function (m) { - // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); + self.remote.transaction() + .offer_create("carol", "50/USD/mtgox", "500") + .on('proposed', 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 = "Create offer dan."; + seq_carol = m.tx_json.Sequence; + }) + .submit(); + }, + function (callback) { + self.what = "Create offer dan."; - self.remote.transaction() - .offer_create("dan", "500", "50/EUR/bitstamp") - .on('proposed', function (m) { - // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); + self.remote.transaction() + .offer_create("dan", "500", "50/EUR/bitstamp") + .on('proposed', function (m) { + // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); - seq_dan = m.tx_json.Sequence; - }) - .submit(); - }, - function (callback) { - self.what = "Alice send EUR/bitstamp to bob converting from USD/mtgox."; + seq_dan = m.tx_json.Sequence; + }) + .submit(); + }, + function (callback) { + self.what = "Alice send EUR/bitstamp to bob converting from USD/mtgox."; - self.remote.transaction() - .payment("alice", "bob", "30/EUR/bitstamp") - .send_max("333/USD/mtgox") - .path_add( [ { currency: "XRP" } ]) - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + self.remote.transaction() + .payment("alice", "bob", "30/EUR/bitstamp") + .send_max("333/USD/mtgox") + .path_add( [ { currency: "XRP" } ]) + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances."; + callback(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balances."; - testutils.verify_balances(self.remote, - { - "alice" : "470/USD/mtgox", - "bob" : "30/EUR/bitstamp", - "carol" : "30/USD/mtgox", - "dan" : "370/EUR/bitstamp", - }, - callback); - }, - function (callback) { - self.what = "Verify carol offer partially consumed."; + testutils.verify_balances(self.remote, + { + "alice" : "470/USD/mtgox", + "bob" : "30/EUR/bitstamp", + "carol" : "30/USD/mtgox", + "dan" : "370/EUR/bitstamp", + }, + callback); + }, + function (callback) { + self.what = "Verify carol offer partially consumed."; - testutils.verify_offer(self.remote, "carol", seq_carol, "20/USD/mtgox", "200", callback); - }, - function (callback) { - self.what = "Verify dan offer partially consumed."; + testutils.verify_offer(self.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); - }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); + testutils.verify_offer(self.remote, "dan", seq_dan, "200", "20/EUR/mtgox", callback); + }, + ], function (error) { + buster.refute(error, self.what); + done(); + }); }, }); -// vim:sw=2:sts=2:ts=8 + +// vim:sw=2:sts=2:ts=8:et diff --git a/test/path-test.js b/test/path-test.js index d82cc8fabe..3b2e7c332f 100644 --- a/test/path-test.js +++ b/test/path-test.js @@ -1,11 +1,11 @@ -var async = require("async"); -var buster = require("buster"); +var async = require("async"); +var buster = require("buster"); -var Amount = require("../src/js/amount.js").Amount; -var Remote = require("../src/js/remote.js").Remote; -var Server = require("./server.js").Server; +var Amount = require("../src/js/amount.js").Amount; +var Remote = require("../src/js/remote.js").Remote; +var Server = require("./server.js").Server; -var testutils = require("./testutils.js"); +var testutils = require("./testutils.js"); require("../src/js/amount.js").config = require("./config.js"); require("../src/js/remote.js").config = require("./config.js"); @@ -21,46 +21,47 @@ buster.testCase("Path finding", { var self = this; async.waterfall([ - function (callback) { - self.what = "Create accounts."; + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "mtgox"], callback); - }, - function (callback) { - self.what = "Set credit limits."; + testutils.create_accounts(self.remote, "root", "10000", ["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(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"; + 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: m", JSON.stringify(m)); + self.remote.request_ripple_path_find("alice", "bob", "5/USD/mtgox", + [ { 'currency' : "USD" } ]) + .on('success', function (m) { + console.log("proposed: m", JSON.stringify(m)); - callback(); - }) - .request(); - }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); + callback(); + }) + .request(); + }, + ], function (error) { + buster.refute(error, self.what); + done(); + }); }, }); -// vim:sw=2:sts=2:ts=8 + +// vim:sw=2:sts=2:ts=8:et diff --git a/test/remote-test.js b/test/remote-test.js index f722a6258e..73c8c6bea4 100644 --- a/test/remote-test.js +++ b/test/remote-test.js @@ -1,19 +1,19 @@ -var buster = require("buster"); +var buster = require("buster"); -var Amount = require("../src/js/amount.js").Amount; -var Remote = require("../src/js/remote.js").Remote; -var Server = require("./server.js").Server; +var Amount = require("../src/js/amount.js").Amount; +var Remote = require("../src/js/remote.js").Remote; +var Server = require("./server.js").Server; -var testutils = require("./testutils.js"); +var testutils = require("./testutils.js"); require("../src/js/amount.js").config = require("./config.js"); require("../src/js/remote.js").config = require("./config.js"); // How long to wait for server to start. -var serverDelay = 1500; // XXX Not implemented. +var serverDelay = 1500; // XXX Not implemented. buster.testRunner.timeout = 5000; - + buster.testCase("Remote functions", { 'setUp' : testutils.build_setup(), 'tearDown' : testutils.build_teardown(), @@ -21,16 +21,16 @@ buster.testCase("Remote functions", { "request_ledger_current" : function (done) { this.remote.request_ledger_current().on('success', function (m) { - // console.log(m); + // console.log(m); - buster.assert.equals(m.ledger_current_index, 3); - done(); - }) + buster.assert.equals(m.ledger_current_index, 3); + done(); + }) .on('error', function(m) { - // console.log(m); + // console.log(m); - buster.assert(false); - }) + buster.assert(false); + }) .request(); }, @@ -38,16 +38,16 @@ buster.testCase("Remote functions", { "request_ledger_hash" : function (done) { this.remote.request_ledger_hash().on('success', function (m) { - // console.log("result: %s", JSON.stringify(m)); + // console.log("result: %s", JSON.stringify(m)); - buster.assert.equals(m.ledger_index, 2); - done(); - }) + buster.assert.equals(m.ledger_index, 2); + done(); + }) .on('error', function(m) { - // console.log("error: %s", m); + // console.log("error: %s", m); - buster.assert(false); - }) + buster.assert(false); + }) .request(); }, @@ -56,30 +56,30 @@ buster.testCase("Remote functions", { var self = this; this.remote.request_ledger_hash().on('success', function (r) { - // console.log("result: %s", JSON.stringify(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)); + 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('node' in r); + done(); + }) + .on('error', function(m) { + // console.log("error: %s", m); - buster.assert(false); - }) - .request(); - }) + buster.assert(false); + }) + .request(); + }) .on('error', function(m) { - // console.log("error: %s", m); + // console.log("error: %s", m); - buster.assert(false); - }) + buster.assert(false); + }) .request(); }, @@ -89,31 +89,31 @@ buster.testCase("Remote functions", { var self = this; this.remote.request_ledger_hash().on('success', function (r) { - // console.log("result: %s", JSON.stringify(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)); + 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(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(); - }) + buster.assert.equals(m.error, 'remoteError'); + buster.assert.equals(m.remote.error, 'malformedAddress'); + done(); + }) + .request(); + }) .on('error', function(m) { - // console.log("error: %s", m); + // console.log("error: %s", m); - buster.assert(false); - }) + buster.assert(false); + }) .request(); }, @@ -122,31 +122,31 @@ buster.testCase("Remote functions", { var self = this; this.remote.request_ledger_hash().on('success', function (r) { - // console.log("result: %s", JSON.stringify(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)); + 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(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(); - }) + buster.assert.equals(m.error, 'remoteError'); + buster.assert.equals(m.remote.error, 'entryNotFound'); + done(); + }) + .request(); + }) .on('error', function(m) { - // console.log("error: %s", m); + // console.log("error: %s", m); - buster.assert(false); - }).request(); + buster.assert(false); + }).request(); }, "ledger_entry index" : @@ -154,52 +154,52 @@ buster.testCase("Remote functions", { var self = this; this.remote.request_ledger_hash().on('success', function (r) { - // console.log("result: %s", JSON.stringify(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)); + 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('node_binary' in r); + done(); + }) + .on('error', function(m) { + // console.log("error: %s", m); - buster.assert(false); - }). - request(); - }) + buster.assert(false); + }). + request(); + }) .on('error', function(m) { - // console.log(m); + // console.log(m); - buster.assert(false); - }) + buster.assert(false); + }) .request(); }, "create account" : function (done) { this.remote.transaction() - .payment('root', 'alice', Amount.from_json("10000")) - .set_flags('CreateAccount') - .on('success', function (r) { - // console.log("account_root: %s", JSON.stringify(r)); + .payment('root', 'alice', Amount.from_json("10000")) + .set_flags('CreateAccount') + .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: %s", m); + // Need to verify account and balance. + buster.assert(true); + done(); + }) + .on('error', function(m) { + // console.log("error: %s", m); - buster.assert(false); - }) - .submit(); + buster.assert(false); + }) + .submit(); }, "create account final" : @@ -210,39 +210,39 @@ buster.testCase("Remote functions", { var got_success; this.remote.transaction() - .payment('root', 'alice', Amount.from_json("10000")) - .set_flags('CreateAccount') - .on('success', function (r) { - // console.log("create_account: %s", JSON.stringify(r)); + .payment('root', 'alice', Amount.from_json("10000")) + .set_flags('CreateAccount') + .on('success', function (r) { + // console.log("create_account: %s", JSON.stringify(r)); - got_success = true; - }) - .on('error', function (m) { - // console.log("error: %s", m); + 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(false); + }) + .on('final', function (m) { + // console.log("final: %s", JSON.stringify(m)); - buster.assert(got_success && got_proposed); - done(); - }) - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + buster.assert(got_success && got_proposed); + done(); + }) + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - // buster.assert.equals(m.result, 'terNO_DST'); - buster.assert.equals(m.result, 'tesSUCCESS'); + // buster.assert.equals(m.result, 'terNO_DST'); + buster.assert.equals(m.result, 'tesSUCCESS'); - got_proposed = true; + got_proposed = true; - self.remote.ledger_accept(); - }) - .on('status', function (s) { - // console.log("status: %s", JSON.stringify(s)); - }) - .submit(); + self.remote.ledger_accept(); + }) + .on('status', function (s) { + // console.log("status: %s", JSON.stringify(s)); + }) + .submit(); }, }); -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et diff --git a/test/send-test.js b/test/send-test.js index 21d261c7a7..b09ca26431 100644 --- a/test/send-test.js +++ b/test/send-test.js @@ -1,11 +1,11 @@ -var async = require("async"); -var buster = require("buster"); +var async = require("async"); +var buster = require("buster"); -var Amount = require("../src/js/amount.js").Amount; -var Remote = require("../src/js/remote.js").Remote; -var Server = require("./server.js").Server; +var Amount = require("../src/js/amount.js").Amount; +var Remote = require("../src/js/remote.js").Remote; +var Server = require("./server.js").Server; -var testutils = require("./testutils.js"); +var testutils = require("./testutils.js"); require("../src/js/amount.js").config = require("./config.js"); require("../src/js/remote.js").config = require("./config.js"); @@ -15,104 +15,104 @@ var serverDelay = 1500; buster.testRunner.timeout = 5000; - /* buster.testCase("Fee Changes", { - 'setUp' : testutils.build_setup({no_server: true}), // + 'setUp' : testutils.build_setup({no_server: true}), // 'tearDown' : testutils.build_teardown(), "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(); - - } - }); - */ + 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(), 'tearDown' : testutils.build_teardown(), "send XRP to non-existent account without create." : function (done) { - var self = this; + var self = this; var ledgers = 20; var got_proposed; this.remote.transaction() - .payment('root', 'alice', "10000") - .on('success', function (r) { - // Transaction sent. + .payment('root', 'alice', "10000") + .on('success', function (r) { + // Transaction sent. - // console.log("success: %s", JSON.stringify(r)); - }) - .on('pending', function() { - // Moving ledgers along. - // console.log("missing: %d", ledgers); + // console.log("success: %s", JSON.stringify(r)); + }) + .on('pending', function() { + // Moving ledgers along. + // console.log("missing: %d", ledgers); - ledgers -= 1; - if (ledgers) { - self.remote.ledger_accept(); - } - else { - buster.assert(false, "Final never received."); - done(); - } - }) - .on('lost', function () { - // Transaction did not make it in. - // console.log("lost"); + ledgers -= 1; + if (ledgers) { + self.remote.ledger_accept(); + } + else { + buster.assert(false, "Final never received."); + done(); + } + }) + .on('lost', function () { + // Transaction did not make it in. + // console.log("lost"); - buster.assert(true); - done(); - }) - .on('proposed', function (m) { - // Transaction got an error. - // console.log("proposed: %s", JSON.stringify(m)); + buster.assert(true); + done(); + }) + .on('proposed', function (m) { + // Transaction got an error. + // console.log("proposed: %s", JSON.stringify(m)); - buster.assert.equals(m.result, 'terNO_DST'); + buster.assert.equals(m.result, 'terNO_DST'); - got_proposed = true; + got_proposed = true; - self.remote.ledger_accept(); // Move it along. - }) - .on('final', function (m) { - // console.log("final: %s", JSON.stringify(m)); + self.remote.ledger_accept(); // Move it along. + }) + .on('final', function (m) { + // console.log("final: %s", JSON.stringify(m)); - buster.assert(false, "Should not have got a final."); - done(); - }) - .on('error', function(m) { - // console.log("error: %s", m); + buster.assert(false, "Should not have got a final."); + done(); + }) + .on('error', function(m) { + // console.log("error: %s", m); - buster.assert(false); - }) - .submit(); + buster.assert(false); + }) + .submit(); }, // Also test transaction becomes lost after terNO_DST. "credit_limit to non-existent account = terNO_DST" : function (done) { this.remote.transaction() - .ripple_line_set("root", "100/USD/alice") - .on('proposed', function (m) { - //console.log("proposed: %s", JSON.stringify(m)); + .ripple_line_set("root", "100/USD/alice") + .on('proposed', function (m) { + //console.log("proposed: %s", JSON.stringify(m)); - buster.assert.equals(m.result, 'terNO_DST'); + buster.assert.equals(m.result, 'terNO_DST'); - done(); - }) - .submit(); + done(); + }) + .submit(); }, "credit_limit" : @@ -120,143 +120,143 @@ buster.testCase("Sending", { var self = this; async.waterfall([ - function (callback) { - self.what = "Create accounts."; + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "mtgox"], callback); - }, - function (callback) { - self.what = "Check a non-existent credit limit."; + testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "mtgox"], callback); + }, + 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)); + 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)); - buster.assert.equals('remoteError', m.error); - buster.assert.equals('entryNotFound', m.remote.error); - callback(); - }) - .request(); - }, - function (callback) { - self.what = "Create a credit limit."; + buster.assert.equals('remoteError', m.error); + buster.assert.equals('entryNotFound', m.remote.error); + callback(); + }) + .request(); + }, + function (callback) { + self.what = "Create a credit limit."; - 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("issuer_balance: %s", m.issuer_balance.to_text_full()); -// console.log("issuer_limit: %s", m.issuer_limit.to_text_full()); - buster.assert(m.account_balance.equals("0/USD/alice")); - buster.assert(m.account_limit.equals("800/USD/alice")); - buster.assert(m.issuer_balance.equals("0/USD/mtgox")); - buster.assert(m.issuer_limit.equals("0/USD/mtgox")); + 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("issuer_balance: %s", m.issuer_balance.to_text_full()); +// console.log("issuer_limit: %s", m.issuer_limit.to_text_full()); + buster.assert(m.account_balance.equals("0/USD/alice")); + buster.assert(m.account_limit.equals("800/USD/alice")); + buster.assert(m.issuer_balance.equals("0/USD/mtgox")); + buster.assert(m.issuer_limit.equals("0/USD/mtgox")); - callback(); - }) - .request(); - }, - function (callback) { - self.what = "Modify a credit limit."; + callback(); + }) + .request(); + }, + function (callback) { + self.what = "Modify a credit limit."; - 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/alice")); - buster.assert(m.issuer_balance.equals("0/USD/mtgox")); - buster.assert(m.issuer_limit.equals("0/USD/mtgox")); + 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/alice")); + buster.assert(m.issuer_balance.equals("0/USD/mtgox")); + buster.assert(m.issuer_limit.equals("0/USD/mtgox")); - callback(); - }) - .request(); - }, - function (callback) { - self.what = "Zero a credit limit."; + callback(); + }) + .request(); + }, + function (callback) { + self.what = "Zero a credit limit."; - testutils.credit_limit(self.remote, "alice", "0/USD/mtgox", callback); - }, - function (callback) { - self.what = "Make sure still exists."; + testutils.credit_limit(self.remote, "alice", "0/USD/mtgox", callback); + }, + function (callback) { + self.what = "Make sure still exists."; - 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("0/USD/alice")); - buster.assert(m.issuer_balance.equals("0/USD/mtgox")); - buster.assert(m.issuer_limit.equals("0/USD/mtgox")); + 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("0/USD/alice")); + buster.assert(m.issuer_balance.equals("0/USD/mtgox")); + buster.assert(m.issuer_limit.equals("0/USD/mtgox")); - callback(); - }) - .request(); - }, - // Set negative limit. - function (callback) { - self.remote.transaction() - .ripple_line_set("alice", "-1/USD/mtgox") - .on('proposed', function (m) { - buster.assert.equals('temBAD_AMOUNT', m.result); + callback(); + }) + .request(); + }, + // Set negative limit. + function (callback) { + self.remote.transaction() + .ripple_line_set("alice", "-1/USD/mtgox") + .on('proposed', function (m) { + buster.assert.equals('temBAD_AMOUNT', m.result); - // After a malformed transaction, need to recover correct sequence. - self.remote.set_account_seq("alice", self.remote.account_seq("alice")-1); - callback('temBAD_AMOUNT' !== m.result); - }) - .submit(); - }, - // TODO Check in both owner books. - function (callback) { - self.what = "Set another limit."; + // After a malformed transaction, need to recover correct sequence. + self.remote.set_account_seq("alice", self.remote.account_seq("alice")-1); + callback('temBAD_AMOUNT' !== m.result); + }) + .submit(); + }, + // TODO Check in both owner books. + function (callback) { + self.what = "Set another limit."; - testutils.credit_limit(self.remote, "alice", "600/USD/bob", callback); - }, - function (callback) { - self.what = "Set limit on other side."; + testutils.credit_limit(self.remote, "alice", "600/USD/bob", callback); + }, + function (callback) { + self.what = "Set limit on other side."; - testutils.credit_limit(self.remote, "bob", "500/USD/alice", callback); - }, - function (callback) { - self.what = "Check ripple_line's state from alice's pov."; + testutils.credit_limit(self.remote, "bob", "500/USD/alice", callback); + }, + function (callback) { + self.what = "Check ripple_line's state from alice's pov."; - self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') - .on('ripple_state', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + .on('ripple_state', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - buster.assert(m.account_balance.equals("0/USD/alice")); - buster.assert(m.account_limit.equals("600/USD/alice")); - buster.assert(m.issuer_balance.equals("0/USD/bob")); - buster.assert(m.issuer_limit.equals("500/USD/bob")); + buster.assert(m.account_balance.equals("0/USD/alice")); + buster.assert(m.account_limit.equals("600/USD/alice")); + buster.assert(m.issuer_balance.equals("0/USD/bob")); + buster.assert(m.issuer_limit.equals("500/USD/bob")); - callback(); - }) - .request(); - }, - function (callback) { - self.what = "Check ripple_line's state from bob's pov."; + callback(); + }) + .request(); + }, + function (callback) { + self.what = "Check ripple_line's state from bob'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/bob")); - buster.assert(m.issuer_balance.equals("0/USD/alice")); - buster.assert(m.issuer_limit.equals("600/USD/alice")); + 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/bob")); + buster.assert(m.issuer_balance.equals("0/USD/alice")); + buster.assert(m.issuer_limit.equals("600/USD/alice")); - callback(); - }) - .request(); - }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); + callback(); + }) + .request(); + }, + ], function (error) { + buster.refute(error, self.what); + done(); + }); }, }); @@ -272,202 +272,202 @@ buster.testCase("Sending future", { // self.remote.set_trace(); async.waterfall([ - function (callback) { - self.what = "Create accounts."; + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob"], callback); - }, - function (callback) { - self.what = "Set alice's limit."; + testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob"], callback); + }, + function (callback) { + self.what = "Set alice's limit."; - testutils.credit_limit(self.remote, "alice", "600/USD/bob", callback); - }, - function (callback) { - self.what = "Set bob's limit."; + testutils.credit_limit(self.remote, "alice", "600/USD/bob", callback); + }, + function (callback) { + self.what = "Set bob's limit."; - testutils.credit_limit(self.remote, "bob", "700/USD/alice", callback); - }, - function (callback) { - self.what = "Set alice send bob partial with alice as issuer."; + testutils.credit_limit(self.remote, "bob", "700/USD/alice", callback); + }, + function (callback) { + self.what = "Set alice send bob partial with alice as issuer."; - self.remote.transaction() - .payment('alice', 'bob', "24/USD/alice") - .once('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .once('final', function (m) { - buster.assert(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balance."; + self.remote.transaction() + .payment('alice', 'bob', "24/USD/alice") + .once('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); + }) + .once('final', function (m) { + buster.assert(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balance."; - 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.issuer_balance.equals("24/USD/bob")); + 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.issuer_balance.equals("24/USD/bob")); - callback(); - }) - .request(); - }, - function (callback) { - self.what = "Set alice send bob more with bob as issuer."; + callback(); + }) + .request(); + }, + function (callback) { + self.what = "Set alice send bob more with bob as issuer."; - self.remote.transaction() - .payment('alice', 'bob', "33/USD/bob") - .once('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .once('final', function (m) { - buster.assert(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balance from bob's pov."; + self.remote.transaction() + .payment('alice', 'bob', "33/USD/bob") + .once('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); + }) + .once('final', function (m) { + buster.assert(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balance from bob's pov."; - 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.issuer_balance.equals("-57/USD/alice")); + 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.issuer_balance.equals("-57/USD/alice")); - callback(); - }) - .request(); - }, - function (callback) { - self.what = "Bob send back more than sent."; + callback(); + }) + .request(); + }, + function (callback) { + self.what = "Bob send back more than sent."; - self.remote.transaction() - .payment('bob', 'alice', "90/USD/bob") - .once('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .once('final', function (m) { - buster.assert(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balance from alice's pov."; + self.remote.transaction() + .payment('bob', 'alice', "90/USD/bob") + .once('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); + }) + .once('final', function (m) { + buster.assert(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balance from alice'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")); + self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + .once('ripple_state', function (m) { + buster.assert(m.account_balance.equals("33/USD/alice")); - callback(); - }) - .request(); - }, - function (callback) { - self.what = "Alice send to limit."; + callback(); + }) + .request(); + }, + function (callback) { + self.what = "Alice send to limit."; - self.remote.transaction() - .payment('alice', 'bob', "733/USD/bob") - .once('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .once('final', function (m) { - buster.assert(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balance from alice's pov."; + self.remote.transaction() + .payment('alice', 'bob', "733/USD/bob") + .once('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); + }) + .once('final', function (m) { + buster.assert(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balance from alice's pov."; - self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') - .once('ripple_state', function (m) { - buster.assert(m.account_balance.equals("-700/USD/alice")); + self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + .once('ripple_state', function (m) { + buster.assert(m.account_balance.equals("-700/USD/alice")); - callback(); - }) - .request(); - }, - function (callback) { - self.what = "Bob send to limit."; + callback(); + }) + .request(); + }, + function (callback) { + self.what = "Bob send to limit."; - self.remote.transaction() - .payment('bob', 'alice', "1300/USD/bob") - .once('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tesSUCCESS'); - }) - .once('final', function (m) { - buster.assert(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balance from alice's pov."; + self.remote.transaction() + .payment('bob', 'alice', "1300/USD/bob") + .once('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.result !== 'tesSUCCESS'); + }) + .once('final', function (m) { + buster.assert(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balance from alice's pov."; - self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') - .once('ripple_state', function (m) { - buster.assert(m.account_balance.equals("600/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(); - }, - function (callback) { - // If this gets applied out of order, it could stop the big payment. - self.what = "Bob send past limit."; + callback(); + }) + .request(); + }, + function (callback) { + // If this gets applied out of order, it could stop the big payment. + self.what = "Bob send past limit."; - self.remote.transaction() - .payment('bob', 'alice', "1/USD/bob") - .once('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tepPATH_DRY'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balance from alice's pov."; + self.remote.transaction() + .payment('bob', 'alice', "1/USD/bob") + .once('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); + callback(m.result !== 'tepPATH_DRY'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balance from alice's pov."; - self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') - .once('ripple_state', function (m) { - buster.assert(m.account_balance.equals("600/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(); - }, -// function (callback) { -// // Make sure all is good after canonical ordering. -// self.what = "Close the ledger and check balance."; + 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 (ledger_closed, ledger_closed_index) { -// // 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."; +// self.remote +// .once('ledger_closed', function (ledger_closed, ledger_closed_index) { +// // 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."; // -// 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("issuer_balance: %s", m.issuer_balance.to_text_full()); -// console.log("issuer_limit: %s", m.issuer_limit.to_text_full()); +// 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("issuer_balance: %s", m.issuer_balance.to_text_full()); +// console.log("issuer_limit: %s", m.issuer_limit.to_text_full()); // -// buster.assert(m.account_balance.equals("600/USD/alice")); +// buster.assert(m.account_balance.equals("600/USD/alice")); // -// callback(); -// }) -// .request(); -// }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); +// callback(); +// }) +// .request(); +// }, + ], function (error) { + buster.refute(error, self.what); + done(); + }); }, // Ripple without credit path. @@ -485,68 +485,68 @@ buster.testCase("Indirect ripple", { // self.remote.set_trace(); async.waterfall([ - function (callback) { - self.what = "Create accounts."; + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "mtgox"], callback); - }, - function (callback) { - self.what = "Set credit limits."; + testutils.create_accounts(self.remote, "root", "10000", ["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(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 = "Verify alice balance with mtgox."; + testutils.payments(self.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(self.remote, "alice", "70/USD/mtgox", callback); + }, + function (callback) { + self.what = "Verify bob balance with mtgox."; - testutils.verify_balance(self.remote, "bob", "50/USD/mtgox", callback); - }, - function (callback) { - self.what = "Alice sends more than has to issuer: 100 out of 70"; + 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"; - self.remote.transaction() - .payment("alice", "mtgox", "100/USD/mtgox") - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + self.remote.transaction() + .payment("alice", "mtgox", "100/USD/mtgox") + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tepPATH_PARTIAL'); - }) - .submit(); - }, - function (callback) { - self.what = "Alice sends more than has to bob: 100 out of 70"; + callback(m.result !== 'tepPATH_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") - .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + self.remote.transaction() + .payment("alice", "bob", "100/USD/mtgox") + .on('proposed', function (m) { + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result !== 'tepPATH_PARTIAL'); - }) - .submit(); - }, - ], function (error) { - buster.refute(error, self.what); - done(); - }); + callback(m.result !== 'tepPATH_PARTIAL'); + }) + .submit(); + }, + ], function (error) { + buster.refute(error, self.what); + done(); + }); }, "indirect ripple with path" : @@ -554,57 +554,57 @@ buster.testCase("Indirect ripple", { var self = this; async.waterfall([ - function (callback) { - self.what = "Create accounts."; + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "mtgox"], callback); - }, - function (callback) { - self.what = "Set credit limits."; + testutils.create_accounts(self.remote, "root", "10000", ["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(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 = "Alice sends via a path"; + testutils.payments(self.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)); + self.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.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify alice balance with mtgox."; + callback(m.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(self.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); - done(); - }); + testutils.verify_balance(self.remote, "bob", "55/USD/mtgox", callback); + }, + ], function (error) { + buster.refute(error, self.what); + done(); + }); }, "indirect ripple with multi path" : @@ -612,61 +612,61 @@ buster.testCase("Indirect ripple", { var self = this; async.waterfall([ - function (callback) { - self.what = "Create accounts."; + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "carol", "amazon", "mtgox"], callback); - }, - function (callback) { - self.what = "Set credit limits."; + testutils.create_accounts(self.remote, "root", "10000", ["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(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.payments(self.remote, - { - "mtgox" : [ "100/USD/bob", "100/USD/carol" ], - }, - callback); - }, - function (callback) { - self.what = "Alice pays amazon via multiple paths"; + testutils.payments(self.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)); + 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)); - callback(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances."; + callback(m.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); - done(); - }); + 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); + done(); + }); }, "indirect ripple with path and transfer fee" : @@ -674,69 +674,70 @@ buster.testCase("Indirect ripple", { var self = this; async.waterfall([ - function (callback) { - self.what = "Create accounts."; + function (callback) { + self.what = "Create accounts."; - testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "carol", "amazon", "mtgox"], callback); - }, - function (callback) { - self.what = "Set mtgox transfer rate."; + testutils.create_accounts(self.remote, "root", "10000", ["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(self.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(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.payments(self.remote, - { - "mtgox" : [ "100/USD/bob", "100/USD/carol" ], - }, - callback); - }, - function (callback) { - self.what = "Alice pays amazon via multiple paths"; + testutils.payments(self.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)); + 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)); - callback(m.result !== 'tesSUCCESS'); - }) - .submit(); - }, - function (callback) { - self.what = "Verify balances."; + callback(m.result !== 'tesSUCCESS'); + }) + .submit(); + }, + function (callback) { + self.what = "Verify balances."; - 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); - done(); - }); + 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); + done(); + }); }, // Direct ripple without no liqudity. // Test with XRP at start and end. }); -// vim:sw=2:sts=2:ts=8 + +// vim:sw=2:sts=2:ts=8:et diff --git a/test/server-test.js b/test/server-test.js index 24496537ef..f443791620 100644 --- a/test/server-test.js +++ b/test/server-test.js @@ -12,17 +12,17 @@ buster.testCase("Standalone server startup", { alpha = Server.from_config("alpha"); alpha - .on('started', function () { - alpha - .on('stopped', function () { - buster.assert(true); + .on('started', function () { + alpha + .on('stopped', function () { + buster.assert(true); - done(); - }) - .stop(); - }) - .start(); + done(); + }) + .stop(); + }) + .start(); } }); -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et diff --git a/test/server.js b/test/server.js index 2608c1d73e..400abf6ae0 100644 --- a/test/server.js +++ b/test/server.js @@ -2,11 +2,11 @@ // // Usage: // s = new Server(name, config) -// s.verbose() : optional +// s.verbose() : optional // .start() -// 'started' +// 'started' // -// s.stop() : stops server is started. +// s.stop() : stops server is started. // 'stopped' // @@ -15,22 +15,22 @@ // 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 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 config = require("./config.js"); -var nodeutils = require("../src/js/nodeutils.js"); +var config = require("./config.js"); +var nodeutils = require("../src/js/nodeutils.js"); // Create a server object var Server = function (name, config, verbose) { - this.name = name; - this.config = config; - this.started = false; - this.quiet = !verbose; + this.name = name; + this.config = config; + this.started = false; + this.quiet = !verbose; }; Server.prototype = new EventEmitter; @@ -66,7 +66,7 @@ Server.prototype._writeConfig = function(done) { fs.writeFile( this.configPath(), Object.keys(this.config).map(function(o) { - return util.format("[%s]\n%s\n", o, self.config[o]); + return util.format("[%s]\n%s\n", o, self.config[o]); }).join(""), 'utf8', done); }; @@ -111,10 +111,10 @@ Server.prototype._makeBase = function (done) { // Reset the server directory, build it if needed. nodeutils.resetPath(path, '0777', function (e) { if (e) { - throw e; + throw e; } else { - self._writeConfig(done); + self._writeConfig(done); } }); }; @@ -128,17 +128,17 @@ Server.prototype.verbose = function () { // Create a standalone server. // Prepare the working directory and spawn the server. Server.prototype.start = function () { - var self = this; + var self = this; if (!this.quiet) console.log("server: start: %s: %s", this.name, JSON.stringify(this.config)); this._makeBase(function (e) { if (e) { - throw e; + throw e; } else { - self._serverSpawnSync(); - self.emit('started'); + self._serverSpawnSync(); + self.emit('started'); } }); @@ -153,10 +153,10 @@ Server.prototype.stop = function () { // Update the on exit to invoke done. this.child.on('exit', function (code, signal) { - if (!self.quiet) console.log("server: stop: server exited"); + if (!self.quiet) console.log("server: stop: server exited"); - self.emit('stopped'); - delete this.child; + self.emit('stopped'); + delete this.child; }); this.child.kill(); @@ -171,4 +171,4 @@ Server.prototype.stop = function () { exports.Server = Server; -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et diff --git a/test/testutils.js b/test/testutils.js index 3b2a1acf69..84ac5979d7 100644 --- a/test/testutils.js +++ b/test/testutils.js @@ -1,5 +1,4 @@ var async = require("async"); -// var buster = require("buster"); var Amount = require("../src/js/amount.js").Amount; var Remote = require("../src/js/remote.js").Remote; @@ -15,24 +14,24 @@ var account_dump = function (remote, account, callback) { async.waterfall([ function (callback) { - self.what = "Get latest account_root"; + self.what = "Get latest account_root"; - remote - .request_ledger_entry('account_root') - .ledger_hash(remote.ledger_hash()) - .account_root("root") - .on('success', function (r) { - //console.log("account_root: %s", JSON.stringify(r, undefined, 2)); + remote + .request_ledger_entry('account_root') + .ledger_hash(remote.ledger_hash()) + .account_root("root") + .on('success', function (r) { + //console.log("account_root: %s", JSON.stringify(r, undefined, 2)); - callback(); - }) - .on('error', function(m) { - console.log("error: %s", m); + callback(); + }) + .on('error', function(m) { + console.log("error: %s", m); - buster.assert(false); - callback(); - }) - .request(); + buster.assert(false); + callback(); + }) + .request(); }, ], function (error) { callback(error); @@ -106,10 +105,10 @@ var build_setup = function (opts, host) { * @param host {String} Identifier for the host configuration to be used. */ var build_teardown = function (host) { - + return function (done) { - - + + host = host || config.server_default; var data = this.store[host]; @@ -117,22 +116,22 @@ var build_teardown = function (host) { async.series([ function disconnectWebsocketStep(callback) { - + data.remote .on('disconnected', callback) .connect(false); }, function stopServerStep(callback) { - - if (opts.no_server) + + if (opts.no_server) { - - return callback(); - } + + return callback(); + } data.server.on('stopped', callback).stop(); } - ], done); + ], done); }; }; @@ -144,15 +143,15 @@ var create_accounts = function (remote, src, amount, accounts, callback) { .payment(src, account, amount) .set_flags('CreateAccount') .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result != 'tesSUCCESS'); - }) + callback(m.result != 'tesSUCCESS'); + }) .on('error', function (m) { - // console.log("error: %s", JSON.stringify(m)); + // console.log("error: %s", JSON.stringify(m)); - callback(m); - }) + callback(m); + }) .submit(); }, callback); }; @@ -163,14 +162,14 @@ var credit_limit = function (remote, src, amount, callback) { remote.transaction() .ripple_line_set(src, amount) .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result != 'tesSUCCESS'); + callback(m.result != 'tesSUCCESS'); }) .on('error', function (m) { - // console.log("error: %s", JSON.stringify(m)); + // console.log("error: %s", JSON.stringify(m)); - callback(m); + callback(m); }) .submit(); }; @@ -181,8 +180,8 @@ var credit_limits = function (remote, balances, callback) { var limits = []; for (var src in balances) { - var values_src = balances[src]; - var values = 'string' === typeof values_src ? [ values_src ] : values_src; + var values_src = balances[src]; + var values = 'string' === typeof values_src ? [ values_src ] : values_src; for (var index in values) { limits.push( { "source" : src, "amount" : values[index] } ); @@ -192,7 +191,7 @@ var credit_limits = function (remote, balances, callback) { async.every(limits, function (limit, callback) { credit_limit(remote, limit.source, limit.amount, - function (mismatch) { callback(!mismatch); }); + function (mismatch) { callback(!mismatch); }); }, function (every) { callback(!every); @@ -205,14 +204,14 @@ var payment = function (remote, src, dst, amount, callback) { remote.transaction() .payment(src, dst, amount) .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result != 'tesSUCCESS'); + callback(m.result != 'tesSUCCESS'); }) .on('error', function (m) { - // console.log("error: %s", JSON.stringify(m)); + // console.log("error: %s", JSON.stringify(m)); - callback(m); + callback(m); }) .submit(); }; @@ -223,8 +222,8 @@ var payments = function (remote, balances, callback) { var sends = []; for (var src in balances) { - var values_src = balances[src]; - var values = 'string' === typeof values_src ? [ values_src ] : values_src; + var values_src = balances[src]; + var values = 'string' === typeof values_src ? [ values_src ] : values_src; for (var index in values) { var amount_json = values[index]; @@ -237,7 +236,7 @@ var payments = function (remote, balances, callback) { async.every(sends, function (send, callback) { payment(remote, send.source, send.destination, send.amount, - function (mismatch) { callback(!mismatch); }); + function (mismatch) { callback(!mismatch); }); }, function (every) { callback(!every); @@ -251,14 +250,14 @@ var transfer_rate = function (remote, src, billionths, callback) { .account_set(src) .transfer_rate(billionths) .on('proposed', function (m) { - // console.log("proposed: %s", JSON.stringify(m)); + // console.log("proposed: %s", JSON.stringify(m)); - callback(m.result != 'tesSUCCESS'); + callback(m.result != 'tesSUCCESS'); }) .on('error', function (m) { - // console.log("error: %s", JSON.stringify(m)); + // console.log("error: %s", JSON.stringify(m)); - callback(m); + callback(m); }) .submit(); }; @@ -270,32 +269,32 @@ var verify_balance = function (remote, src, amount_json, callback) { if (amount_req.is_native()) { remote.request_account_balance(src, 'CURRENT') .once('account_balance', function (amount_act) { - if (!amount_act.equals(amount_req)) - console.log("verify_balance: failed: %s / %s", - amount_act.to_text_full(), - amount_req.to_text_full()); + if (!amount_act.equals(amount_req)) + console.log("verify_balance: failed: %s / %s", + amount_act.to_text_full(), + amount_req.to_text_full()); - callback(!amount_act.equals(amount_req)); - }) + callback(!amount_act.equals(amount_req)); + }) .request(); } else { remote.request_ripple_balance(src, amount_req.issuer().to_json(), amount_req.currency().to_json(), 'CURRENT') .once('ripple_state', function (m) { - // console.log("BALANCE: %s", JSON.stringify(m)); - // console.log("account_balance: %s", m.account_balance.to_text_full()); - // console.log("account_limit: %s", m.account_limit.to_text_full()); - // console.log("issuer_balance: %s", m.issuer_balance.to_text_full()); - // console.log("issuer_limit: %s", m.issuer_limit.to_text_full()); + // console.log("BALANCE: %s", JSON.stringify(m)); + // console.log("account_balance: %s", m.account_balance.to_text_full()); + // console.log("account_limit: %s", m.account_limit.to_text_full()); + // console.log("issuer_balance: %s", m.issuer_balance.to_text_full()); + // console.log("issuer_limit: %s", m.issuer_limit.to_text_full()); - var account_balance = Amount.from_json(m.account_balance); + var account_balance = Amount.from_json(m.account_balance); - if (!account_balance.equals(amount_req)) { - console.log("verify_balance: failed: %s vs %s is %s: %s", src, account_balance.to_text_full(), amount_req.to_text_full(), account_balance.not_equals_why(amount_req)); - } + if (!account_balance.equals(amount_req)) { + console.log("verify_balance: failed: %s vs %s is %s: %s", src, account_balance.to_text_full(), amount_req.to_text_full(), account_balance.not_equals_why(amount_req)); + } - callback(!account_balance.equals(amount_req)); - }) + callback(!account_balance.equals(amount_req)); + }) .request(); } }; @@ -304,8 +303,8 @@ var verify_balances = function (remote, balances, callback) { var tests = []; for (var src in balances) { - var values_src = balances[src]; - var values = 'string' === typeof values_src ? [ values_src ] : values_src; + var values_src = balances[src]; + var values = 'string' === typeof values_src ? [ values_src ] : values_src; for (var index in values) { tests.push( { "source" : src, "amount" : values[index] } ); @@ -315,7 +314,7 @@ var verify_balances = function (remote, balances, callback) { async.every(tests, function (check, callback) { verify_balance(remote, check.source, check.amount, - function (mismatch) { callback(!mismatch); }); + function (mismatch) { callback(!mismatch); }); }, function (every) { callback(!every); @@ -332,13 +331,13 @@ var verify_offer = function (remote, owner, seq, taker_pays, taker_gets, callbac remote.request_ledger_entry('offer') .offer_id(owner, seq) .on('success', function (m) { - var wrong = (!Amount.from_json(m.node.TakerGets).equals(Amount.from_json(taker_gets)) - || !Amount.from_json(m.node.TakerPays).equals(Amount.from_json(taker_pays))); + var wrong = (!Amount.from_json(m.node.TakerGets).equals(Amount.from_json(taker_gets)) + || !Amount.from_json(m.node.TakerPays).equals(Amount.from_json(taker_pays))); - if (wrong) - console.log("verify_offer: failed: %s", JSON.stringify(m)); + if (wrong) + console.log("verify_offer: failed: %s", JSON.stringify(m)); - callback(wrong); + callback(wrong); }) .request(); }; @@ -349,32 +348,32 @@ var verify_offer_not_found = function (remote, owner, seq, callback) { remote.request_ledger_entry('offer') .offer_id(owner, seq) .on('success', function (m) { - console.log("verify_offer_not_found: found offer: %s", JSON.stringify(m)); + console.log("verify_offer_not_found: found offer: %s", JSON.stringify(m)); - callback('entryFound'); + callback('entryFound'); }) .on('error', function (m) { - // console.log("verify_offer_not_found: success: %s", JSON.stringify(m)); + // console.log("verify_offer_not_found: success: %s", JSON.stringify(m)); - callback('remoteError' !== m.error - || 'entryNotFound' !== m.remote.error); + callback('remoteError' !== m.error + || 'entryNotFound' !== m.remote.error); }) .request(); }; -exports.account_dump = account_dump; +exports.account_dump = account_dump; -exports.build_setup = build_setup; -exports.create_accounts = create_accounts; -exports.credit_limit = credit_limit; -exports.credit_limits = credit_limits; -exports.payment = payment; -exports.payments = payments; -exports.build_teardown = build_teardown; -exports.transfer_rate = transfer_rate; -exports.verify_balance = verify_balance; -exports.verify_balances = verify_balances; -exports.verify_offer = verify_offer; -exports.verify_offer_not_found = verify_offer_not_found; +exports.build_setup = build_setup; +exports.create_accounts = create_accounts; +exports.credit_limit = credit_limit; +exports.credit_limits = credit_limits; +exports.payment = payment; +exports.payments = payments; +exports.build_teardown = build_teardown; +exports.transfer_rate = transfer_rate; +exports.verify_balance = verify_balance; +exports.verify_balances = verify_balances; +exports.verify_offer = verify_offer; +exports.verify_offer_not_found = verify_offer_not_found; -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et diff --git a/test/utils-test.js b/test/utils-test.js index cea1f43644..c1f8f8f967 100644 --- a/test/utils-test.js +++ b/test/utils-test.js @@ -1,4 +1,4 @@ -var fs = require("fs"); +var fs = require("fs"); var buster = require("buster"); var utils = require("../src/js/utils.js"); @@ -23,4 +23,4 @@ buster.testCase("Utils", { } }); -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et diff --git a/test/websocket-test.js b/test/websocket-test.js index 6730866bb2..02d7e59f9b 100644 --- a/test/websocket-test.js +++ b/test/websocket-test.js @@ -17,23 +17,23 @@ buster.testCase("WebSocket connection", { "websocket connect and disconnect" : function (done) { - var alpha = Remote.from_config("alpha"); + var alpha = Remote.from_config("alpha"); alpha - .on('connected', function () { - // OPEN - buster.assert(true); + .on('connected', function () { + // OPEN + buster.assert(true); - alpha - .on('disconnected', function () { - // CLOSED - buster.assert(true); - done(); - }) - .connect(false); - }) - .connect(); + alpha + .on('disconnected', function () { + // CLOSED + buster.assert(true); + done(); + }) + .connect(false); + }) + .connect(); }, }); -// vim:sw=2:sts=2:ts=8 +// vim:sw=2:sts=2:ts=8:et