JS & UT: add et to vim setting.

This commit is contained in:
Arthur Britto
2012-11-24 14:07:21 -08:00
parent 189c1276a3
commit 49e6ca70ba
21 changed files with 1569 additions and 1565 deletions

View File

@@ -22,4 +22,4 @@ var Account = function (network, account) {
exports.Account = Account; exports.Account = Account;
// vim:sw=2:sts=2:ts=8 // vim:sw=2:sts=2:ts=8:et

View File

@@ -704,4 +704,4 @@ exports.UInt160 = UInt160;
exports.config = {}; exports.config = {};
// vim:sw=2:sts=2:ts=8 // vim:sw=2:sts=2:ts=8:et

View File

@@ -1216,4 +1216,4 @@ BigInteger.ONE = nbv(1);
exports.nbi = nbi; exports.nbi = nbi;
exports.BigInteger = BigInteger; exports.BigInteger = BigInteger;
// vim:sw=2:sts=2:ts=8 // vim:sw=2:sts=2:ts=8:et

View File

@@ -55,4 +55,4 @@ Network.protocol.stop = function () {
exports.Network = Network; exports.Network = Network;
// vim:sw=2:sts=2:ts=8 // vim:sw=2:sts=2:ts=8:et

View File

@@ -88,4 +88,4 @@ exports.mkPath = mkPath;
exports.resetPath = resetPath; exports.resetPath = resetPath;
exports.rmPath = rmPath; exports.rmPath = rmPath;
// vim:sw=2:sts=2:ts=8 // vim:sw=2:sts=2:ts=8:et

View File

@@ -1489,4 +1489,4 @@ Transaction.prototype.wallet_add = function (src, amount, authorized_key, public
exports.config = {}; exports.config = {};
exports.Remote = Remote; exports.Remote = Remote;
// vim:sw=2:sts=2:ts=8 // vim:sw=2:sts=2:ts=8:et

View File

@@ -41,4 +41,4 @@ serializer.addUInt160 = function(value) {
serializer.getSHA512Half = function() { serializer.getSHA512Half = function() {
}; };
// vim:ts=4 // vim:sw=2:sts=2:ts=8:et

View File

@@ -76,4 +76,4 @@ exports.hexToString = hexToString;
exports.stringToArray = stringToArray; exports.stringToArray = stringToArray;
exports.stringToHex = stringToHex; exports.stringToHex = stringToHex;
// vim:sw=2:sts=2:ts=8 // vim:sw=2:sts=2:ts=8:et

View File

@@ -1,12 +1,12 @@
var buster = require("buster"); var buster = require("buster");
var jsbn = require('../src/js/jsbn.js'); var jsbn = require('../src/js/jsbn.js');
var BigInteger = jsbn.BigInteger; var BigInteger = jsbn.BigInteger;
var nbi = jsbn.nbi; var nbi = jsbn.nbi;
var amount = require("../src/js/amount.js"); var amount = require("../src/js/amount.js");
var Amount = require("../src/js/amount.js").Amount; var Amount = require("../src/js/amount.js").Amount;
var UInt160 = require("../src/js/amount.js").UInt160; var UInt160 = require("../src/js/amount.js").UInt160;
require("../src/js/amount.js").config = require("./config.js"); 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

View File

@@ -4,6 +4,8 @@ config["Newcoin tests"] = {
rootPath: "../", rootPath: "../",
environment: "node", environment: "node",
tests: [ tests: [
"test/*-test.js" "test/*-test.js"
] ]
} }
// vim:sw=2:sts=2:ts=8:et

View File

@@ -7,7 +7,7 @@ var path = require("path");
// Where to find the binary. // Where to find the binary.
exports.rippled = path.resolve("build/rippled"); exports.rippled = path.resolve("build/rippled");
exports.server_default = "alpha"; exports.server_default = "alpha";
// Configuration for servers. // Configuration for servers.
exports.servers = { exports.servers = {
@@ -66,4 +66,4 @@ exports.accounts = {
}, },
}; };
// vim:sw=2:sts=2:ts=8 // vim:sw=2:sts=2:ts=8:et

View File

@@ -1,17 +1,17 @@
var async = require("async"); var async = require("async");
var buster = require("buster"); var buster = require("buster");
var Amount = require("../src/js/amount.js").Amount; var Amount = require("../src/js/amount.js").Amount;
var Remote = require("../src/js/remote.js").Remote; var Remote = require("../src/js/remote.js").Remote;
var Server = require("./server.js").Server; 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/amount.js").config = require("./config.js");
require("../src/js/remote.js").config = require("./config.js"); require("../src/js/remote.js").config = require("./config.js");
buster.testRunner.timeout = 5000; buster.testRunner.timeout = 5000;
buster.testCase("//Monitor account", { buster.testCase("//Monitor account", {
'setUp' : testutils.build_setup({ verbose: true }), 'setUp' : testutils.build_setup({ verbose: true }),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
@@ -21,34 +21,34 @@ buster.testCase("//Monitor account", {
var self = this; var self = this;
async.waterfall([ async.waterfall([
function (callback) { function (callback) {
self.what = "Create accounts."; self.what = "Create accounts.";
testutils.create_accounts(self.remote, "root", "10000", ["alice"], callback); testutils.create_accounts(self.remote, "root", "10000", ["alice"], callback);
}, },
function (callback) { function (callback) {
self.what = "Close ledger."; self.what = "Close ledger.";
self.remote.once('ledger_closed', function (ledger_closed, ledger_index) { self.remote.once('ledger_closed', function (ledger_closed, ledger_index) {
callback(); callback();
}); });
self.remote.ledger_accept(); self.remote.ledger_accept();
}, },
function (callback) { function (callback) {
self.what = "Dumping root."; self.what = "Dumping root.";
testutils.account_dump(self.remote, "root", function (error) { testutils.account_dump(self.remote, "root", function (error) {
buster.refute(error); buster.refute(error);
callback(); callback();
}); });
}, },
], function (error) { ], function (error) {
buster.refute(error, self.what); buster.refute(error, self.what);
done(); done();
}); });
}, },
}); });
// vim:sw=2:sts=2:ts=8 // vim:sw=2:sts=2:ts=8:et

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,11 @@
var async = require("async"); var async = require("async");
var buster = require("buster"); var buster = require("buster");
var Amount = require("../src/js/amount.js").Amount; var Amount = require("../src/js/amount.js").Amount;
var Remote = require("../src/js/remote.js").Remote; var Remote = require("../src/js/remote.js").Remote;
var Server = require("./server.js").Server; 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/amount.js").config = require("./config.js");
require("../src/js/remote.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; var self = this;
async.waterfall([ async.waterfall([
function (callback) { function (callback) {
self.what = "Create accounts."; self.what = "Create accounts.";
testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "mtgox"], callback); testutils.create_accounts(self.remote, "root", "10000", ["alice", "bob", "mtgox"], callback);
}, },
function (callback) { function (callback) {
self.what = "Set credit limits."; self.what = "Set credit limits.";
testutils.credit_limits(self.remote, testutils.credit_limits(self.remote,
{ {
"alice" : "600/USD/mtgox", "alice" : "600/USD/mtgox",
"bob" : "700/USD/mtgox", "bob" : "700/USD/mtgox",
}, },
callback); callback);
}, },
function (callback) { function (callback) {
self.what = "Distribute funds."; self.what = "Distribute funds.";
testutils.payments(self.remote, testutils.payments(self.remote,
{ {
"mtgox" : [ "70/USD/alice", "50/USD/bob" ], "mtgox" : [ "70/USD/alice", "50/USD/bob" ],
}, },
callback); callback);
}, },
function (callback) { function (callback) {
self.what = "Find path from alice to mtgox"; self.what = "Find path from alice to mtgox";
self.remote.request_ripple_path_find("alice", "bob", "5/USD/mtgox", self.remote.request_ripple_path_find("alice", "bob", "5/USD/mtgox",
[ { 'currency' : "USD" } ]) [ { 'currency' : "USD" } ])
.on('success', function (m) { .on('success', function (m) {
console.log("proposed: m", JSON.stringify(m)); console.log("proposed: m", JSON.stringify(m));
callback(); callback();
}) })
.request(); .request();
}, },
], function (error) { ], function (error) {
buster.refute(error, self.what); buster.refute(error, self.what);
done(); done();
}); });
}, },
}); });
// vim:sw=2:sts=2:ts=8
// vim:sw=2:sts=2:ts=8:et

View File

@@ -1,19 +1,19 @@
var buster = require("buster"); var buster = require("buster");
var Amount = require("../src/js/amount.js").Amount; var Amount = require("../src/js/amount.js").Amount;
var Remote = require("../src/js/remote.js").Remote; var Remote = require("../src/js/remote.js").Remote;
var Server = require("./server.js").Server; 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/amount.js").config = require("./config.js");
require("../src/js/remote.js").config = require("./config.js"); require("../src/js/remote.js").config = require("./config.js");
// How long to wait for server to start. // 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.testRunner.timeout = 5000;
buster.testCase("Remote functions", { buster.testCase("Remote functions", {
'setUp' : testutils.build_setup(), 'setUp' : testutils.build_setup(),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
@@ -21,16 +21,16 @@ buster.testCase("Remote functions", {
"request_ledger_current" : "request_ledger_current" :
function (done) { function (done) {
this.remote.request_ledger_current().on('success', function (m) { this.remote.request_ledger_current().on('success', function (m) {
// console.log(m); // console.log(m);
buster.assert.equals(m.ledger_current_index, 3); buster.assert.equals(m.ledger_current_index, 3);
done(); done();
}) })
.on('error', function(m) { .on('error', function(m) {
// console.log(m); // console.log(m);
buster.assert(false); buster.assert(false);
}) })
.request(); .request();
}, },
@@ -38,16 +38,16 @@ buster.testCase("Remote functions", {
"request_ledger_hash" : "request_ledger_hash" :
function (done) { function (done) {
this.remote.request_ledger_hash().on('success', function (m) { 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); buster.assert.equals(m.ledger_index, 2);
done(); done();
}) })
.on('error', function(m) { .on('error', function(m) {
// console.log("error: %s", m); // console.log("error: %s", m);
buster.assert(false); buster.assert(false);
}) })
.request(); .request();
}, },
@@ -56,30 +56,30 @@ buster.testCase("Remote functions", {
var self = this; var self = this;
this.remote.request_ledger_hash().on('success', function (r) { 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 self.remote
.request_ledger_entry('account_root') .request_ledger_entry('account_root')
.ledger_hash(r.ledger_hash) .ledger_hash(r.ledger_hash)
.account_root("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh") .account_root("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")
.on('success', function (r) { .on('success', function (r) {
// console.log("account_root: %s", JSON.stringify(r)); // console.log("account_root: %s", JSON.stringify(r));
buster.assert('node' in r); buster.assert('node' in r);
done(); done();
}) })
.on('error', function(m) { .on('error', function(m) {
// console.log("error: %s", m); // console.log("error: %s", m);
buster.assert(false); buster.assert(false);
}) })
.request(); .request();
}) })
.on('error', function(m) { .on('error', function(m) {
// console.log("error: %s", m); // console.log("error: %s", m);
buster.assert(false); buster.assert(false);
}) })
.request(); .request();
}, },
@@ -89,31 +89,31 @@ buster.testCase("Remote functions", {
var self = this; var self = this;
this.remote.request_ledger_hash().on('success', function (r) { 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 self.remote
.request_ledger_entry('account_root') .request_ledger_entry('account_root')
.ledger_hash(r.ledger_hash) .ledger_hash(r.ledger_hash)
.account_root("zHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh") .account_root("zHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")
.on('success', function (r) { .on('success', function (r) {
// console.log("account_root: %s", JSON.stringify(r)); // console.log("account_root: %s", JSON.stringify(r));
buster.assert(false); buster.assert(false);
}) })
.on('error', function(m) { .on('error', function(m) {
// console.log("error: %s", m); // console.log("error: %s", m);
buster.assert.equals(m.error, 'remoteError'); buster.assert.equals(m.error, 'remoteError');
buster.assert.equals(m.remote.error, 'malformedAddress'); buster.assert.equals(m.remote.error, 'malformedAddress');
done(); done();
}) })
.request(); .request();
}) })
.on('error', function(m) { .on('error', function(m) {
// console.log("error: %s", m); // console.log("error: %s", m);
buster.assert(false); buster.assert(false);
}) })
.request(); .request();
}, },
@@ -122,31 +122,31 @@ buster.testCase("Remote functions", {
var self = this; var self = this;
this.remote.request_ledger_hash().on('success', function (r) { 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 self.remote
.request_ledger_entry('account_root') .request_ledger_entry('account_root')
.ledger_hash(r.ledger_hash) .ledger_hash(r.ledger_hash)
.account_root("alice") .account_root("alice")
.on('success', function (r) { .on('success', function (r) {
// console.log("account_root: %s", JSON.stringify(r)); // console.log("account_root: %s", JSON.stringify(r));
buster.assert(false); buster.assert(false);
}) })
.on('error', function(m) { .on('error', function(m) {
// console.log("error: %s", m); // console.log("error: %s", m);
buster.assert.equals(m.error, 'remoteError'); buster.assert.equals(m.error, 'remoteError');
buster.assert.equals(m.remote.error, 'entryNotFound'); buster.assert.equals(m.remote.error, 'entryNotFound');
done(); done();
}) })
.request(); .request();
}) })
.on('error', function(m) { .on('error', function(m) {
// console.log("error: %s", m); // console.log("error: %s", m);
buster.assert(false); buster.assert(false);
}).request(); }).request();
}, },
"ledger_entry index" : "ledger_entry index" :
@@ -154,52 +154,52 @@ buster.testCase("Remote functions", {
var self = this; var self = this;
this.remote.request_ledger_hash().on('success', function (r) { 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 self.remote
.request_ledger_entry('index') .request_ledger_entry('index')
.ledger_hash(r.ledger_hash) .ledger_hash(r.ledger_hash)
.account_root("alice") .account_root("alice")
.index("2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8") .index("2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8")
.on('success', function (r) { .on('success', function (r) {
// console.log("account_root: %s", JSON.stringify(r)); // console.log("account_root: %s", JSON.stringify(r));
buster.assert('node_binary' in r); buster.assert('node_binary' in r);
done(); done();
}) })
.on('error', function(m) { .on('error', function(m) {
// console.log("error: %s", m); // console.log("error: %s", m);
buster.assert(false); buster.assert(false);
}). }).
request(); request();
}) })
.on('error', function(m) { .on('error', function(m) {
// console.log(m); // console.log(m);
buster.assert(false); buster.assert(false);
}) })
.request(); .request();
}, },
"create account" : "create account" :
function (done) { function (done) {
this.remote.transaction() this.remote.transaction()
.payment('root', 'alice', Amount.from_json("10000")) .payment('root', 'alice', Amount.from_json("10000"))
.set_flags('CreateAccount') .set_flags('CreateAccount')
.on('success', function (r) { .on('success', function (r) {
// console.log("account_root: %s", JSON.stringify(r)); // console.log("account_root: %s", JSON.stringify(r));
// Need to verify account and balance. // Need to verify account and balance.
buster.assert(true); buster.assert(true);
done(); done();
}) })
.on('error', function(m) { .on('error', function(m) {
// console.log("error: %s", m); // console.log("error: %s", m);
buster.assert(false); buster.assert(false);
}) })
.submit(); .submit();
}, },
"create account final" : "create account final" :
@@ -210,39 +210,39 @@ buster.testCase("Remote functions", {
var got_success; var got_success;
this.remote.transaction() this.remote.transaction()
.payment('root', 'alice', Amount.from_json("10000")) .payment('root', 'alice', Amount.from_json("10000"))
.set_flags('CreateAccount') .set_flags('CreateAccount')
.on('success', function (r) { .on('success', function (r) {
// console.log("create_account: %s", JSON.stringify(r)); // console.log("create_account: %s", JSON.stringify(r));
got_success = true; got_success = true;
}) })
.on('error', function (m) { .on('error', function (m) {
// console.log("error: %s", m); // console.log("error: %s", m);
buster.assert(false); buster.assert(false);
}) })
.on('final', function (m) { .on('final', function (m) {
// console.log("final: %s", JSON.stringify(m)); // console.log("final: %s", JSON.stringify(m));
buster.assert(got_success && got_proposed); buster.assert(got_success && got_proposed);
done(); done();
}) })
.on('proposed', function (m) { .on('proposed', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
// buster.assert.equals(m.result, 'terNO_DST'); // buster.assert.equals(m.result, 'terNO_DST');
buster.assert.equals(m.result, 'tesSUCCESS'); buster.assert.equals(m.result, 'tesSUCCESS');
got_proposed = true; got_proposed = true;
self.remote.ledger_accept(); self.remote.ledger_accept();
}) })
.on('status', function (s) { .on('status', function (s) {
// console.log("status: %s", JSON.stringify(s)); // console.log("status: %s", JSON.stringify(s));
}) })
.submit(); .submit();
}, },
}); });
// vim:sw=2:sts=2:ts=8 // vim:sw=2:sts=2:ts=8:et

File diff suppressed because it is too large Load Diff

View File

@@ -12,17 +12,17 @@ buster.testCase("Standalone server startup", {
alpha = Server.from_config("alpha"); alpha = Server.from_config("alpha");
alpha alpha
.on('started', function () { .on('started', function () {
alpha alpha
.on('stopped', function () { .on('stopped', function () {
buster.assert(true); buster.assert(true);
done(); done();
}) })
.stop(); .stop();
}) })
.start(); .start();
} }
}); });
// vim:sw=2:sts=2:ts=8 // vim:sw=2:sts=2:ts=8:et

View File

@@ -2,11 +2,11 @@
// //
// Usage: // Usage:
// s = new Server(name, config) // s = new Server(name, config)
// s.verbose() : optional // s.verbose() : optional
// .start() // .start()
// 'started' // 'started'
// //
// s.stop() : stops server is started. // s.stop() : stops server is started.
// 'stopped' // 'stopped'
// //
@@ -15,22 +15,22 @@
// Servers are created in tmp/server/$server // Servers are created in tmp/server/$server
// //
var buster = require("buster"); var buster = require("buster");
var child = require("child_process"); var child = require("child_process");
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
var util = require("util"); var util = require("util");
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
var config = require("./config.js"); var config = require("./config.js");
var nodeutils = require("../src/js/nodeutils.js"); var nodeutils = require("../src/js/nodeutils.js");
// Create a server object // Create a server object
var Server = function (name, config, verbose) { var Server = function (name, config, verbose) {
this.name = name; this.name = name;
this.config = config; this.config = config;
this.started = false; this.started = false;
this.quiet = !verbose; this.quiet = !verbose;
}; };
Server.prototype = new EventEmitter; Server.prototype = new EventEmitter;
@@ -66,7 +66,7 @@ Server.prototype._writeConfig = function(done) {
fs.writeFile( fs.writeFile(
this.configPath(), this.configPath(),
Object.keys(this.config).map(function(o) { 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(""), }).join(""),
'utf8', done); 'utf8', done);
}; };
@@ -111,10 +111,10 @@ Server.prototype._makeBase = function (done) {
// Reset the server directory, build it if needed. // Reset the server directory, build it if needed.
nodeutils.resetPath(path, '0777', function (e) { nodeutils.resetPath(path, '0777', function (e) {
if (e) { if (e) {
throw e; throw e;
} }
else { else {
self._writeConfig(done); self._writeConfig(done);
} }
}); });
}; };
@@ -128,17 +128,17 @@ Server.prototype.verbose = function () {
// Create a standalone server. // Create a standalone server.
// Prepare the working directory and spawn the server. // Prepare the working directory and spawn the server.
Server.prototype.start = function () { 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)); if (!this.quiet) console.log("server: start: %s: %s", this.name, JSON.stringify(this.config));
this._makeBase(function (e) { this._makeBase(function (e) {
if (e) { if (e) {
throw e; throw e;
} }
else { else {
self._serverSpawnSync(); self._serverSpawnSync();
self.emit('started'); self.emit('started');
} }
}); });
@@ -153,10 +153,10 @@ Server.prototype.stop = function () {
// Update the on exit to invoke done. // Update the on exit to invoke done.
this.child.on('exit', function (code, signal) { 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'); self.emit('stopped');
delete this.child; delete this.child;
}); });
this.child.kill(); this.child.kill();
@@ -171,4 +171,4 @@ Server.prototype.stop = function () {
exports.Server = Server; exports.Server = Server;
// vim:sw=2:sts=2:ts=8 // vim:sw=2:sts=2:ts=8:et

View File

@@ -1,5 +1,4 @@
var async = require("async"); var async = require("async");
// var buster = require("buster");
var Amount = require("../src/js/amount.js").Amount; var Amount = require("../src/js/amount.js").Amount;
var Remote = require("../src/js/remote.js").Remote; var Remote = require("../src/js/remote.js").Remote;
@@ -15,24 +14,24 @@ var account_dump = function (remote, account, callback) {
async.waterfall([ async.waterfall([
function (callback) { function (callback) {
self.what = "Get latest account_root"; self.what = "Get latest account_root";
remote remote
.request_ledger_entry('account_root') .request_ledger_entry('account_root')
.ledger_hash(remote.ledger_hash()) .ledger_hash(remote.ledger_hash())
.account_root("root") .account_root("root")
.on('success', function (r) { .on('success', function (r) {
//console.log("account_root: %s", JSON.stringify(r, undefined, 2)); //console.log("account_root: %s", JSON.stringify(r, undefined, 2));
callback(); callback();
}) })
.on('error', function(m) { .on('error', function(m) {
console.log("error: %s", m); console.log("error: %s", m);
buster.assert(false); buster.assert(false);
callback(); callback();
}) })
.request(); .request();
}, },
], function (error) { ], function (error) {
callback(error); callback(error);
@@ -106,10 +105,10 @@ var build_setup = function (opts, host) {
* @param host {String} Identifier for the host configuration to be used. * @param host {String} Identifier for the host configuration to be used.
*/ */
var build_teardown = function (host) { var build_teardown = function (host) {
return function (done) { return function (done) {
host = host || config.server_default; host = host || config.server_default;
var data = this.store[host]; var data = this.store[host];
@@ -117,22 +116,22 @@ var build_teardown = function (host) {
async.series([ async.series([
function disconnectWebsocketStep(callback) { function disconnectWebsocketStep(callback) {
data.remote data.remote
.on('disconnected', callback) .on('disconnected', callback)
.connect(false); .connect(false);
}, },
function stopServerStep(callback) { function stopServerStep(callback) {
if (opts.no_server) if (opts.no_server)
{ {
return callback(); return callback();
} }
data.server.on('stopped', callback).stop(); 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) .payment(src, account, amount)
.set_flags('CreateAccount') .set_flags('CreateAccount')
.on('proposed', function (m) { .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) { .on('error', function (m) {
// console.log("error: %s", JSON.stringify(m)); // console.log("error: %s", JSON.stringify(m));
callback(m); callback(m);
}) })
.submit(); .submit();
}, callback); }, callback);
}; };
@@ -163,14 +162,14 @@ var credit_limit = function (remote, src, amount, callback) {
remote.transaction() remote.transaction()
.ripple_line_set(src, amount) .ripple_line_set(src, amount)
.on('proposed', function (m) { .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) { .on('error', function (m) {
// console.log("error: %s", JSON.stringify(m)); // console.log("error: %s", JSON.stringify(m));
callback(m); callback(m);
}) })
.submit(); .submit();
}; };
@@ -181,8 +180,8 @@ var credit_limits = function (remote, balances, callback) {
var limits = []; var limits = [];
for (var src in balances) { for (var src in balances) {
var values_src = balances[src]; var values_src = balances[src];
var values = 'string' === typeof values_src ? [ values_src ] : values_src; var values = 'string' === typeof values_src ? [ values_src ] : values_src;
for (var index in values) { for (var index in values) {
limits.push( { "source" : src, "amount" : values[index] } ); limits.push( { "source" : src, "amount" : values[index] } );
@@ -192,7 +191,7 @@ var credit_limits = function (remote, balances, callback) {
async.every(limits, async.every(limits,
function (limit, callback) { function (limit, callback) {
credit_limit(remote, limit.source, limit.amount, credit_limit(remote, limit.source, limit.amount,
function (mismatch) { callback(!mismatch); }); function (mismatch) { callback(!mismatch); });
}, },
function (every) { function (every) {
callback(!every); callback(!every);
@@ -205,14 +204,14 @@ var payment = function (remote, src, dst, amount, callback) {
remote.transaction() remote.transaction()
.payment(src, dst, amount) .payment(src, dst, amount)
.on('proposed', function (m) { .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) { .on('error', function (m) {
// console.log("error: %s", JSON.stringify(m)); // console.log("error: %s", JSON.stringify(m));
callback(m); callback(m);
}) })
.submit(); .submit();
}; };
@@ -223,8 +222,8 @@ var payments = function (remote, balances, callback) {
var sends = []; var sends = [];
for (var src in balances) { for (var src in balances) {
var values_src = balances[src]; var values_src = balances[src];
var values = 'string' === typeof values_src ? [ values_src ] : values_src; var values = 'string' === typeof values_src ? [ values_src ] : values_src;
for (var index in values) { for (var index in values) {
var amount_json = values[index]; var amount_json = values[index];
@@ -237,7 +236,7 @@ var payments = function (remote, balances, callback) {
async.every(sends, async.every(sends,
function (send, callback) { function (send, callback) {
payment(remote, send.source, send.destination, send.amount, payment(remote, send.source, send.destination, send.amount,
function (mismatch) { callback(!mismatch); }); function (mismatch) { callback(!mismatch); });
}, },
function (every) { function (every) {
callback(!every); callback(!every);
@@ -251,14 +250,14 @@ var transfer_rate = function (remote, src, billionths, callback) {
.account_set(src) .account_set(src)
.transfer_rate(billionths) .transfer_rate(billionths)
.on('proposed', function (m) { .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) { .on('error', function (m) {
// console.log("error: %s", JSON.stringify(m)); // console.log("error: %s", JSON.stringify(m));
callback(m); callback(m);
}) })
.submit(); .submit();
}; };
@@ -270,32 +269,32 @@ var verify_balance = function (remote, src, amount_json, callback) {
if (amount_req.is_native()) { if (amount_req.is_native()) {
remote.request_account_balance(src, 'CURRENT') remote.request_account_balance(src, 'CURRENT')
.once('account_balance', function (amount_act) { .once('account_balance', function (amount_act) {
if (!amount_act.equals(amount_req)) if (!amount_act.equals(amount_req))
console.log("verify_balance: failed: %s / %s", console.log("verify_balance: failed: %s / %s",
amount_act.to_text_full(), amount_act.to_text_full(),
amount_req.to_text_full()); amount_req.to_text_full());
callback(!amount_act.equals(amount_req)); callback(!amount_act.equals(amount_req));
}) })
.request(); .request();
} }
else { else {
remote.request_ripple_balance(src, amount_req.issuer().to_json(), amount_req.currency().to_json(), 'CURRENT') remote.request_ripple_balance(src, amount_req.issuer().to_json(), amount_req.currency().to_json(), 'CURRENT')
.once('ripple_state', function (m) { .once('ripple_state', function (m) {
// console.log("BALANCE: %s", JSON.stringify(m)); // console.log("BALANCE: %s", JSON.stringify(m));
// console.log("account_balance: %s", m.account_balance.to_text_full()); // console.log("account_balance: %s", m.account_balance.to_text_full());
// console.log("account_limit: %s", m.account_limit.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_balance: %s", m.issuer_balance.to_text_full());
// console.log("issuer_limit: %s", m.issuer_limit.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)) { 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)); 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(); .request();
} }
}; };
@@ -304,8 +303,8 @@ var verify_balances = function (remote, balances, callback) {
var tests = []; var tests = [];
for (var src in balances) { for (var src in balances) {
var values_src = balances[src]; var values_src = balances[src];
var values = 'string' === typeof values_src ? [ values_src ] : values_src; var values = 'string' === typeof values_src ? [ values_src ] : values_src;
for (var index in values) { for (var index in values) {
tests.push( { "source" : src, "amount" : values[index] } ); tests.push( { "source" : src, "amount" : values[index] } );
@@ -315,7 +314,7 @@ var verify_balances = function (remote, balances, callback) {
async.every(tests, async.every(tests,
function (check, callback) { function (check, callback) {
verify_balance(remote, check.source, check.amount, verify_balance(remote, check.source, check.amount,
function (mismatch) { callback(!mismatch); }); function (mismatch) { callback(!mismatch); });
}, },
function (every) { function (every) {
callback(!every); callback(!every);
@@ -332,13 +331,13 @@ var verify_offer = function (remote, owner, seq, taker_pays, taker_gets, callbac
remote.request_ledger_entry('offer') remote.request_ledger_entry('offer')
.offer_id(owner, seq) .offer_id(owner, seq)
.on('success', function (m) { .on('success', function (m) {
var wrong = (!Amount.from_json(m.node.TakerGets).equals(Amount.from_json(taker_gets)) 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))); || !Amount.from_json(m.node.TakerPays).equals(Amount.from_json(taker_pays)));
if (wrong) if (wrong)
console.log("verify_offer: failed: %s", JSON.stringify(m)); console.log("verify_offer: failed: %s", JSON.stringify(m));
callback(wrong); callback(wrong);
}) })
.request(); .request();
}; };
@@ -349,32 +348,32 @@ var verify_offer_not_found = function (remote, owner, seq, callback) {
remote.request_ledger_entry('offer') remote.request_ledger_entry('offer')
.offer_id(owner, seq) .offer_id(owner, seq)
.on('success', function (m) { .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) { .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 callback('remoteError' !== m.error
|| 'entryNotFound' !== m.remote.error); || 'entryNotFound' !== m.remote.error);
}) })
.request(); .request();
}; };
exports.account_dump = account_dump; exports.account_dump = account_dump;
exports.build_setup = build_setup; exports.build_setup = build_setup;
exports.create_accounts = create_accounts; exports.create_accounts = create_accounts;
exports.credit_limit = credit_limit; exports.credit_limit = credit_limit;
exports.credit_limits = credit_limits; exports.credit_limits = credit_limits;
exports.payment = payment; exports.payment = payment;
exports.payments = payments; exports.payments = payments;
exports.build_teardown = build_teardown; exports.build_teardown = build_teardown;
exports.transfer_rate = transfer_rate; exports.transfer_rate = transfer_rate;
exports.verify_balance = verify_balance; exports.verify_balance = verify_balance;
exports.verify_balances = verify_balances; exports.verify_balances = verify_balances;
exports.verify_offer = verify_offer; exports.verify_offer = verify_offer;
exports.verify_offer_not_found = verify_offer_not_found; exports.verify_offer_not_found = verify_offer_not_found;
// vim:sw=2:sts=2:ts=8 // vim:sw=2:sts=2:ts=8:et

View File

@@ -1,4 +1,4 @@
var fs = require("fs"); var fs = require("fs");
var buster = require("buster"); var buster = require("buster");
var utils = require("../src/js/utils.js"); 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

View File

@@ -17,23 +17,23 @@ buster.testCase("WebSocket connection", {
"websocket connect and disconnect" : "websocket connect and disconnect" :
function (done) { function (done) {
var alpha = Remote.from_config("alpha"); var alpha = Remote.from_config("alpha");
alpha alpha
.on('connected', function () { .on('connected', function () {
// OPEN // OPEN
buster.assert(true); buster.assert(true);
alpha alpha
.on('disconnected', function () { .on('disconnected', function () {
// CLOSED // CLOSED
buster.assert(true); buster.assert(true);
done(); done();
}) })
.connect(false); .connect(false);
}) })
.connect(); .connect();
}, },
}); });
// vim:sw=2:sts=2:ts=8 // vim:sw=2:sts=2:ts=8:et