Update system tests for mocha and new ripple-lib transaction submission

This commit is contained in:
wltsmrz
2013-09-04 16:29:32 -07:00
committed by Vinnie Falco
parent 01d7d7bed9
commit c76e2b54a9
14 changed files with 3287 additions and 3168 deletions

View File

@@ -16,12 +16,11 @@
"simple-jsonrpc": "~0.0.2" "simple-jsonrpc": "~0.0.2"
}, },
"devDependencies": { "devDependencies": {
"buster": "~0.6.12", "mocha": "~1.13.0"
"mocha": "~1.12.0"
}, },
"scripts": { "scripts": {
"test": "./node_modules/buster/bin/buster-test --reporter specification" "test": "mocha --reporter spec --ui tdd --timeout 10000 --slow 600 test/*-test.js"
}, },
"repository": { "repository": {

View File

@@ -1,123 +1,131 @@
var async = require("async"); var async = require("async");
var buster = require("buster"); var assert = require('assert');
var Amount = require("ripple-lib").Amount;
var Remote = require("ripple-lib").Remote; var Remote = require("ripple-lib").Remote;
var Request = require("ripple-lib").Request;
var Server = require("./server").Server;
var testutils = require("./testutils"); var testutils = require("./testutils");
var config = testutils.init_config(); var config = testutils.init_config();
// How long to wait for server to start. suite('Account set', function() {
var serverDelay = 1500; var $ = { };
buster.testRunner.timeout = 5000; setup(function(done) {
testutils.build_setup().call($, done);
});
buster.testCase("AccountSet", { teardown(function(done) {
'setUp' : testutils.build_setup(), testutils.build_teardown().call($, done);
// 'setUp' : testutils.build_setup({verbose: true , no_server: false}), });
'tearDown' : testutils.build_teardown(),
"RequireDestTag" : function (done) { test('set RequireDestTag', function(done) {
var self = this; var self = this;
async.waterfall([ var steps = [
function (callback) { function (callback) {
self.what = "Set RequireDestTag."; self.what = "Set RequireDestTag.";
self.remote.transaction() $.remote.transaction()
.account_set("root") .account_set("root")
.set_flags('RequireDestTag') .set_flags('RequireDestTag')
.on('submitted', function (m) { .on('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m)); //console.log("proposed: %s", JSON.stringify(m));
if (m.engine_result === 'tesSUCCESS') {
callback(m.engine_result !== 'tesSUCCESS'); callback(null);
} else {
callback(new Error(m.engine_result));
}
}) })
.submit(); .submit();
}, },
function (callback) { function (callback) {
self.what = "Check RequireDestTag"; self.what = "Check RequireDestTag";
self.remote.request_account_flags('root', 'CURRENT') $.remote.request_account_flags('root', 'CURRENT')
.on('success', function (m) { .on('success', function (m) {
var wrong = !(m.node.Flags & Remote.flags.account_root.RequireDestTag); var wrong = !(m.node.Flags & Remote.flags.account_root.RequireDestTag);
if (wrong) if (wrong) {
console.log("Set RequireDestTag: failed: %s", JSON.stringify(m)); console.log("Set RequireDestTag: failed: %s", JSON.stringify(m));
}
callback(wrong); callback(wrong ? new Error(wrong) : null);
}) })
.request(); .request();
}, },
function (callback) { function (callback) {
self.what = "Clear RequireDestTag."; self.what = "Clear RequireDestTag.";
self.remote.transaction() $.remote.transaction()
.account_set("root") .account_set("root")
.set_flags('OptionalDestTag') .set_flags('OptionalDestTag')
.on('submitted', function (m) { .on('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m)); //console.log("proposed: %s", JSON.stringify(m));
callback(m.engine_result === 'tesSUCCESS' ? null : new Error());
callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
function (callback) { function (callback) {
self.what = "Check No RequireDestTag"; self.what = "Check No RequireDestTag";
self.remote.request_account_flags('root', 'CURRENT') $.remote.request_account_flags('root', 'CURRENT')
.on('success', function (m) { .on('success', function (m) {
var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireDestTag); var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireDestTag);
if (wrong) if (wrong) {
console.log("Clear RequireDestTag: failed: %s", JSON.stringify(m)); console.log("Clear RequireDestTag: failed: %s", JSON.stringify(m));
}
callback(wrong); callback(wrong ? new Error(m) : null);
}) })
.request(); .request();
}, }
], function (error) { ]
buster.refute(error, self.what);
async.waterfall(steps,function (error) {
assert(!error, self.what);
done(); done();
}); });
}, });
"RequireAuth" : function (done) { test("set RequireAuth", function (done) {
var self = this; var self = this;
async.waterfall([ var steps = [
function (callback) { function (callback) {
self.what = "Set RequireAuth."; self.what = "Set RequireAuth.";
self.remote.transaction() $.remote.transaction()
.account_set("root") .account_set("root")
.set_flags('RequireAuth') .set_flags('RequireAuth')
.on('submitted', function (m) { .on('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m)); //console.log("proposed: %s", JSON.stringify(m));
callback(m.engine_result === 'tesSUCCESS' ? null : new Error(m));
callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
function (callback) { function (callback) {
self.what = "Check RequireAuth"; self.what = "Check RequireAuth";
self.remote.request_account_flags('root', 'CURRENT') $.remote.request_account_flags('root', 'CURRENT')
.on('error', callback)
.on('success', function (m) { .on('success', function (m) {
var wrong = !(m.node.Flags & Remote.flags.account_root.RequireAuth); var wrong = !(m.node.Flags & Remote.flags.account_root.RequireAuth);
if (wrong) if (wrong) {
console.log("Set RequireAuth: failed: %s", JSON.stringify(m)); console.log("Set RequireAuth: failed: %s", JSON.stringify(m));
}
callback(wrong); callback(wrong ? new Error(m) : null);
}) })
.request(); .request();
}, },
function (callback) { function (callback) {
self.what = "Clear RequireAuth."; self.what = "Clear RequireAuth.";
self.remote.transaction() $.remote.transaction()
.account_set("root") .account_set("root")
.set_flags('OptionalAuth') .set_flags('OptionalAuth')
.on('submitted', function (m) { .on('submitted', function (m) {
@@ -127,91 +135,101 @@ buster.testCase("AccountSet", {
}) })
.submit(); .submit();
}, },
function (callback) { function (callback) {
self.what = "Check No RequireAuth"; self.what = "Check No RequireAuth";
self.remote.request_account_flags('root', 'CURRENT') $.remote.request_account_flags('root', 'CURRENT')
.on('error', callback)
.on('success', function (m) { .on('success', function (m) {
var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireAuth); var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireAuth);
if (wrong) if (wrong) {
console.log("Clear RequireAuth: failed: %s", JSON.stringify(m)); console.log("Clear RequireAuth: failed: %s", JSON.stringify(m));
}
callback(wrong); callback(wrong ? new Error(m) : null);
}) })
.request(); .request();
}, }
// XXX Also check fails if something is owned. // XXX Also check fails if something is owned.
], function (error) { ]
buster.refute(error, self.what);
async.waterfall(steps, function(error) {
assert(!error, self.what);
done(); done();
}); });
}, });
"DisallowXRP" : function (done) { test('set DisallowXRP', function(done) {
var self = this; var self = this;
async.waterfall([ var steps = [
function (callback) { function (callback) {
self.what = "Set DisallowXRP."; self.what = "Set DisallowXRP.";
self.remote.transaction() $.remote.transaction()
.account_set("root") .account_set("root")
.set_flags('DisallowXRP') .set_flags('DisallowXRP')
.on('submitted', function (m) { .on('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m)); //console.log("proposed: %s", JSON.stringify(m));
callback(m.engine_result === 'tesSUCCESS' ? null : new Error(m));
callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
function (callback) { function (callback) {
self.what = "Check DisallowXRP"; self.what = "Check DisallowXRP";
self.remote.request_account_flags('root', 'CURRENT') $.remote.request_account_flags('root', 'CURRENT')
.on('error', callback)
.on('success', function (m) { .on('success', function (m) {
var wrong = !(m.node.Flags & Remote.flags.account_root.DisallowXRP); var wrong = !(m.node.Flags & Remote.flags.account_root.DisallowXRP);
if (wrong) if (wrong) {
console.log("Set RequireDestTag: failed: %s", JSON.stringify(m)); console.log("Set RequireDestTag: failed: %s", JSON.stringify(m));
}
callback(wrong); callback(wrong ? new Error(m) : null);
}) })
.request(); .request();
}, },
function (callback) { function (callback) {
self.what = "Clear DisallowXRP."; self.what = "Clear DisallowXRP.";
self.remote.transaction() $.remote.transaction()
.account_set("root") .account_set("root")
.set_flags('AllowXRP') .set_flags('AllowXRP')
.on('submitted', function (m) { .on('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m)); //console.log("proposed: %s", JSON.stringify(m));
callback(m.engine_result !== 'tesSUCCESS'); callback(m.engine_result === 'tesSUCCESS' ? null : new Error(m));
}) })
.submit(); .submit();
}, },
function (callback) { function (callback) {
self.what = "Check AllowXRP"; self.what = "Check AllowXRP";
self.remote.request_account_flags('root', 'CURRENT') $.remote.request_account_flags('root', 'CURRENT')
.on('error', callback)
.on('success', function (m) { .on('success', function (m) {
var wrong = !!(m.node.Flags & Remote.flags.account_root.DisallowXRP); var wrong = !!(m.node.Flags & Remote.flags.account_root.DisallowXRP);
if (wrong) if (wrong) {
console.log("Clear DisallowXRP: failed: %s", JSON.stringify(m)); console.log("Clear DisallowXRP: failed: %s", JSON.stringify(m));
}
callback(wrong); callback(wrong ? new Error(m) : null);
}) })
.request(); .request();
}, }
], function (error) { ]
buster.refute(error, self.what);
async.waterfall(steps, function(err) {
assert(!err);
done(); done();
}); });
}, });
}); });
// vim:sw=2:sts=2:ts=8:et

View File

@@ -1,210 +1,395 @@
var async = require("async"); ////var assert = require('assert');
var buster = require("buster"); ////var async = require("async");
////var extend = require('extend');
var Amount = require("ripple-lib").Amount; ////var Amount = require("ripple-lib").Amount;
var Remote = require("ripple-lib").Remote; ////var Remote = require("ripple-lib").Remote;
var Transaction = require("ripple-lib").Transaction; ////var Transaction = require("ripple-lib").Transaction;
var Server = require("./server").Server; ////var RippleError = require("ripple-lib").RippleError;
////var Server = require("./server").Server;
var testutils = require("./testutils"); ////var testutils = require("./testutils");
var config = testutils.init_config(); ////var config = testutils.init_config();
////
buster.testRunner.timeout = 350000; //This is a very long test! ////// Hard-coded limits we'll be testing:
////var BINARY_LIMIT = 500;
////var NONBINARY_LIMIT = 200;
// Hard-coded limits we'll be testing: ////
var BINARY_LIMIT = 500; ////var ACCOUNT = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh";
var NONBINARY_LIMIT = 200; ////var OFFSET = 180;
////var LIMIT = 170;
var ACCOUNT = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"; ////
var FIRST_BATCH = 199; // Within both limits ////var FIRST_BATCH = 199; // Within both limits
var OFFSET = 180; ////var SECOND_BATCH = 10; // Between NONBINARY_LIMIT and BINARY_LIMIT
var LIMIT = 170; ////var THIRD_BATCH = 295; // Exceeds both limits
var SECOND_BATCH = 10; // Between NONBINARY_LIMIT and BINARY_LIMIT ////var VERBOSE = false;
var THIRD_BATCH = 295; // Exceeds both limits ////
var VERBOSE = false; ////
////suite('Account_tx tests', function() {
buster.testCase("//Account_tx tests", { //// var $ = { };
'setUp' : testutils.build_setup(), ////
'tearDown' : testutils.build_teardown(), //// setup(function(done) {
//// testutils.build_setup().call($, done);
"make a lot of transactions and query using account_tx" : function (done) { //// });
var self = this; ////
var final_create; //// teardown(function(done) {
var transactionCounter = 0; //// testutils.build_teardown().call($, done);
var f = 0; //// });
var functionHolder; ////
var createOfferFunction = function (callback) { //// test('make many transactions and query using account_tx', function(done) {
self.remote.transaction() //// var root_id = $.remote.account('root')._account_id;
.offer_create("root", "500", "100/USD/root") //// $.remote.request_subscribe().accounts(root_id).request();
.on('proposed', function (m) { ////
transactionCounter++; //// var self = this;
if (VERBOSE) console.log('Submitted transaction', transactionCounter); //// var transactionCounter = 0;
//// var final_create;
callback(m.result !== 'tesSUCCESS'); ////
}) //// function createOffer(callback) {
.on('final', function (m) { //// var tx = $.remote.transaction();
f++; //// tx.offer_create("root", "500", "100/USD/root");
if (VERBOSE) console.log("Finalized transaction", f); ////
buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); //// tx.once('proposed', function(m) {
buster.assert(final_create); //// $.remote.ledger_accept();
if ( f == transactionCounter ) { //// });
if (VERBOSE) console.log("All transactions have been finalized."); ////
functionHolder(); //// tx.once('error', callback);
} ////
}) //// tx.once('final', function(m) {
.submit(); //// callback();
}; //// });
////
function lotsOfTransactions(number, whenDone) { //// tx.submit();
var bunchOfOffers = []; //// };
for (var i=0; i<number; i++) { ////
bunchOfOffers.push(createOfferFunction); //// function lotsOfTransactions(count, callback) {
} //// ;(function nextOffer(i) {
functionHolder = whenDone; //lolwut //// createOffer(function(err) {
async.parallel(bunchOfOffers, function (error) { //// console.log(i, count);
if (VERBOSE) console.log("Accepting ledger."); //// if (err) callback(err);
buster.refute(error); //// else if (++i === count) callback(null);
self.remote //// else nextOffer(i);
.once('ledger_closed', function (message) { //// });
final_create = message; //// })(0);
}) //// };
.ledger_accept(); ////
}); //// function firstBatch() {
} //// lotsOfTransactions(FIRST_BATCH, function(a, b) {
//// runTests(self, FIRST_BATCH, 0, void(0), function() {
function firstBatch() { //// console.log('2');
lotsOfTransactions(FIRST_BATCH, //// runTests(self, FIRST_BATCH, OFFSET, void(0), function() {
function(){runTests(self, FIRST_BATCH, 0, undefined, //// console.log('3');
function(){runTests(self, FIRST_BATCH, OFFSET, undefined, //// runTests(self, FIRST_BATCH, -1, LIMIT, secondBatch);
function(){runTests(self, FIRST_BATCH, 0, LIMIT, secondBatch)})} //// })
)}); //// })});
} //// }
////
function secondBatch() { //// function secondBatch() {
lotsOfTransactions(SECOND_BATCH, //// lotsOfTransactions(SECOND_BATCH, function() {
function(){runTests(self, FIRST_BATCH+SECOND_BATCH, 0, undefined, //// runTests(self, FIRST_BATCH+SECOND_BATCH, 0, void(0), function() {
function(){runTests(self, FIRST_BATCH+SECOND_BATCH, OFFSET, undefined, thirdBatch)} //// runTests(self, FIRST_BATCH+SECOND_BATCH, OFFSET, void(0), thirdBatch);
)}); //// })});
} //// }
////
function thirdBatch() { //// function thirdBatch() {
lotsOfTransactions(THIRD_BATCH, //// lotsOfTransactions(THIRD_BATCH, function() {
function(){runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, 0, undefined, //// runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, 0, void(0), function() {
function(){runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, OFFSET, undefined, done)} //// runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, OFFSET, void(0), done);
)}); //// })});
} //// }
////
firstBatch(); //// firstBatch();
////
//// function errorHandler(callback) {
function standardErrorHandler(callback) { //// return function(r) {
return function(r) { //// if (VERBOSE) console.log("ERROR!");
if (VERBOSE) console.log("ERROR!"); //// if (VERBOSE) console.log(r);
if (VERBOSE) console.log(r); //// callback(r);
callback(r); //// }
} //// }
} ////
//// function txOptions(ext) {
//// var defaults = {
function runTests(self, actualNumberOfTransactions, offset, limit, finalCallback) { //// account: ACCOUNT,
if (VERBOSE) console.log("Testing batch with offset and limit:", offset, limit); //// ledger_index_min: -1,
async.series([ //// ledger_index_max: -1
function(callback) { //// }
if (VERBOSE) console.log('nonbinary'); //// return extend(defaults, ext);
self.remote.request_account_tx({ //// };
account:ACCOUNT, ////
ledger_index_min:-1, //// function sortByLedger(a, b) {
ledger_index_max:-1, //// assert(a.tx, 'Transaction missing');
offset:offset, //// assert(b.tx, 'Transaction missing');
limit:limit //// if (a.tx.inLedger > b.tx.inLedger) {
}).on('success', function (r) { //// return 1;
if (r.transactions) { //// } else if (a.tx.inLedger < b.tx.inLedger) {
var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset); //// return -1;
buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength ); //// } else {
//Check for proper ordering. //// return 0;
for (var i=0; i<r.transactions.length-1; i++) { //// }
var t1 = r.transactions[i].tx; //// };
var t2 = r.transactions[i+1].tx; ////
buster.assert(t1.inLedger<=t2.inLedger, //// function runTests(self, transactionCount, offset, limit, callback) {
"Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence); //// var steps = [
} //// function(callback) {
} else { //// if (VERBOSE) console.log('nonbinary');
buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit); ////
} //// var req = $.remote.request_account_tx(txOptions({ offset: offset, limit: limit }));
////
callback(false); //// req.callback(function(err, r) {
}) //// if (err) return callback(err);
.on('error', standardErrorHandler(callback)) //// assert(r && r.transactions);
.request(); //// var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit, transactionCount - offset) : transactionCount - offset);
}, //// assert.strictEqual(r.transactions.length, targetLength, 'Transactions unexpected length');
//// //assert.deepEqual(r.transactions.sort(sortByLedger), r.transactions, 'Transactions out of order');
function(callback) { //// callback();
if (VERBOSE) console.log('binary'); //// });
self.remote.request_account_tx({ //// },
account:ACCOUNT, ////
ledger_index_min:-1, //// function(callback) {
ledger_index_max:-1, //// if (VERBOSE) console.log('binary');
binary:true, ////
offset:offset, //// var req = $.remote.request_account_tx(txOptions({ binary: true, offset: offset, limit: limit }));
limit:limit ////
}).on('success', function (r) { //// req.callback(function(err, r) {
if (r.transactions) { //// if (err) return callback(err);
var targetLength = Math.min(BINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset); //// assert(r && r.transactions);
buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength ); //// var targetLength = Math.min(BINARY_LIMIT, limit ? Math.min(limit, transactionCount-offset) : transactionCount-offset);
} else { //// assert.strictEqual(r.transactions.length, targetLength, 'Transactions unexpected length');
buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit); //// //assert.deepEqual(r.transactions.sort(sortByLedger), r.transactions, 'Transactions out of order');
} //// callback();
callback(false); //// });
}) //// },
.on('error', standardErrorHandler(callback)) ////
.request(); //// function(callback) {
}, //// if (VERBOSE) console.log('nonbinary+offset');
////
function(callback) { //// var req = $.remote.request_account_tx(txOptions({ descending: true, offset: offset, limit: limit }));
if (VERBOSE) console.log('nonbinary+offset'); ////
self.remote.request_account_tx({ //// req.callback(function(err, r) {
account:ACCOUNT, //// if (err) return callback(err);
ledger_index_min:-1, //// assert(r && r.transactions);
ledger_index_max:-1, //// var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit,transactionCount-offset) : transactionCount-offset );
descending:true, //// assert.strictEqual(r.transactions.length, targetLength, 'Transactions unexpected length');
offset:offset, //// //assert.deepEqual(r.transactions.sort(sortByLedger), r.transactions, 'Transactions out of order');
limit:limit //// callback();
}).on('success', function (r) { //// });
if (r.transactions) { //// }
var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset ); //// ]
buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength ); ////
//Check for proper ordering. //// async.series(steps, function(error) {
for (var i=0; i<r.transactions.length-1; i++) { //// console.log(error);
var t1 = r.transactions[i].tx; //// assert.ifError(error);
var t2 = r.transactions[i+1].tx; //// callback();
//buster.assert(t1.inLedger>t2.inLedger || (t1.inLedger==t2.inLedger && t1.Sequence > t2.Sequence ), //// });
// "Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence); //// }
buster.assert(t1.inLedger>=t2.inLedger, //// });
"Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence); ////});
} //=======
} else { //var async = require("async");
buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit); //var buster = require("buster");
} //
//var Amount = require("ripple-lib").Amount;
//var Remote = require("ripple-lib").Remote;
callback(false); //var Transaction = require("ripple-lib").Transaction;
}) //var Server = require("./server").Server;
.on('error', standardErrorHandler(callback)) //
.request(); //var testutils = require("./testutils");
}, //var config = testutils.init_config();
//
//buster.testRunner.timeout = 350000; //This is a very long test!
], function (error) { //
buster.refute(error); //
finalCallback(); //// Hard-coded limits we'll be testing:
} //var BINARY_LIMIT = 500;
); //var NONBINARY_LIMIT = 200;
} //
} //var ACCOUNT = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh";
}); //var FIRST_BATCH = 199; // Within both limits
//var OFFSET = 180;
//var LIMIT = 170;
//var SECOND_BATCH = 10; // Between NONBINARY_LIMIT and BINARY_LIMIT
// TODO: //var THIRD_BATCH = 295; // Exceeds both limits
// Test the "count" feature. //var VERBOSE = false;
//
//buster.testCase("//Account_tx tests", {
// 'setUp' : testutils.build_setup(),
// 'tearDown' : testutils.build_teardown(),
//
// "make a lot of transactions and query using account_tx" : function (done) {
// var self = this;
// var final_create;
// var transactionCounter = 0;
// var f = 0;
// var functionHolder;
// var createOfferFunction = function (callback) {
// self.remote.transaction()
// .offer_create("root", "500", "100/USD/root")
// .on('proposed', function (m) {
// transactionCounter++;
// if (VERBOSE) console.log('Submitted transaction', transactionCounter);
//
// callback(m.result !== 'tesSUCCESS');
// })
// .on('final', function (m) {
// f++;
// if (VERBOSE) console.log("Finalized transaction", f);
// buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult);
// buster.assert(final_create);
// if ( f == transactionCounter ) {
// if (VERBOSE) console.log("All transactions have been finalized.");
// functionHolder();
// }
// })
// .submit();
// };
//
// function lotsOfTransactions(number, whenDone) {
// var bunchOfOffers = [];
// for (var i=0; i<number; i++) {
// bunchOfOffers.push(createOfferFunction);
// }
// functionHolder = whenDone; //lolwut
// async.parallel(bunchOfOffers, function (error) {
// if (VERBOSE) console.log("Accepting ledger.");
// buster.refute(error);
// self.remote
// .once('ledger_closed', function (message) {
// final_create = message;
// })
// .ledger_accept();
// });
// }
//
// function firstBatch() {
// lotsOfTransactions(FIRST_BATCH,
// function(){runTests(self, FIRST_BATCH, 0, undefined,
// function(){runTests(self, FIRST_BATCH, OFFSET, undefined,
// function(){runTests(self, FIRST_BATCH, 0, LIMIT, secondBatch)})}
// )});
// }
//
// function secondBatch() {
// lotsOfTransactions(SECOND_BATCH,
// function(){runTests(self, FIRST_BATCH+SECOND_BATCH, 0, undefined,
// function(){runTests(self, FIRST_BATCH+SECOND_BATCH, OFFSET, undefined, thirdBatch)}
// )});
// }
//
// function thirdBatch() {
// lotsOfTransactions(THIRD_BATCH,
// function(){runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, 0, undefined,
// function(){runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, OFFSET, undefined, done)}
// )});
// }
//
// firstBatch();
//
//
// function standardErrorHandler(callback) {
// return function(r) {
// if (VERBOSE) console.log("ERROR!");
// if (VERBOSE) console.log(r);
// callback(r);
// }
// }
//
//
// function runTests(self, actualNumberOfTransactions, offset, limit, finalCallback) {
// if (VERBOSE) console.log("Testing batch with offset and limit:", offset, limit);
// async.series([
// function(callback) {
// if (VERBOSE) console.log('nonbinary');
// self.remote.request_account_tx({
// account:ACCOUNT,
// ledger_index_min:-1,
// ledger_index_max:-1,
// offset:offset,
// limit:limit
// }).on('success', function (r) {
// if (r.transactions) {
// var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset);
// buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength );
// //Check for proper ordering.
// for (var i=0; i<r.transactions.length-1; i++) {
// var t1 = r.transactions[i].tx;
// var t2 = r.transactions[i+1].tx;
// buster.assert(t1.inLedger<=t2.inLedger,
// "Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence);
// }
// } else {
// buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit);
// }
//
// callback(false);
// })
// .on('error', standardErrorHandler(callback))
// .request();
// },
//
// function(callback) {
// if (VERBOSE) console.log('binary');
// self.remote.request_account_tx({
// account:ACCOUNT,
// ledger_index_min:-1,
// ledger_index_max:-1,
// binary:true,
// offset:offset,
// limit:limit
// }).on('success', function (r) {
// if (r.transactions) {
// var targetLength = Math.min(BINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset);
// buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength );
// } else {
// buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit);
// }
// callback(false);
// })
// .on('error', standardErrorHandler(callback))
// .request();
// },
//
// function(callback) {
// if (VERBOSE) console.log('nonbinary+offset');
// self.remote.request_account_tx({
// account:ACCOUNT,
// ledger_index_min:-1,
// ledger_index_max:-1,
// descending:true,
// offset:offset,
// limit:limit
// }).on('success', function (r) {
// if (r.transactions) {
// var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset );
// buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength );
// //Check for proper ordering.
// for (var i=0; i<r.transactions.length-1; i++) {
// var t1 = r.transactions[i].tx;
// var t2 = r.transactions[i+1].tx;
// //buster.assert(t1.inLedger>t2.inLedger || (t1.inLedger==t2.inLedger && t1.Sequence > t2.Sequence ),
// // "Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence);
// buster.assert(t1.inLedger>=t2.inLedger,
// "Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence);
// }
// } else {
// buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit);
// }
//
//
// callback(false);
// })
// .on('error', standardErrorHandler(callback))
// .request();
// },
//
//
// ], function (error) {
// buster.refute(error);
// finalCallback();
// }
// );
// }
// }
//});
//
//
//
//// TODO:
//// Test the "count" feature.

View File

@@ -1,11 +0,0 @@
var config = module.exports;
config["Ripple tests"] = {
rootPath: "../",
environment: "node",
tests: [
"test/*-test.js"
]
}
// vim:sw=2:sts=2:ts=8:et

View File

@@ -1,26 +1,13 @@
var async = require("async"); var async = require("async");
var buster = require("buster"); var assert = require('assert');
var http = require("http"); var http = require("http");
var jsonrpc = require("simple-jsonrpc"); var jsonrpc = require("simple-jsonrpc");
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
var Amount = require("ripple-lib").Amount;
var Remote = require("ripple-lib").Remote; var Remote = require("ripple-lib").Remote;
var Server = require("./server").Server;
var testutils = require("./testutils"); var testutils = require("./testutils");
var config = testutils.init_config(); var config = testutils.init_config();
// How long to wait for server to start. function build_setup(options) {
var serverDelay = 1500;
buster.testRunner.timeout = 5000;
var server;
var server_events;
var build_setup = function (options) {
var setup = testutils.build_setup(options); var setup = testutils.build_setup(options);
return function (done) { return function (done) {
@@ -28,49 +15,42 @@ var build_setup = function (options) {
var http_config = config.http_servers["zed"]; var http_config = config.http_servers["zed"];
server_events = new EventEmitter; self.server_events = new EventEmitter;
server = http.createServer(function (req, res) {
self.server = http.createServer(function (req, res) {
// console.log("REQUEST"); // console.log("REQUEST");
var input = ""; var input = "";
req.setEncoding(); req.setEncoding('utf8');
req.on('data', function (buffer) { req.on('data', function (buffer) {
// console.log("DATA: %s", buffer); // console.log("DATA: %s", buffer);
input = input + buffer; input = input + buffer;
}); });
req.on('end', function () { req.on('end', function () {
// console.log("END");
var request = JSON.parse(input); var request = JSON.parse(input);
// console.log("REQ: %s", JSON.stringify(request, undefined, 2)); // console.log("REQ: %s", JSON.stringify(request, undefined, 2));
self.server_events.emit('request', request, res);
server_events.emit('request', request, res);
}); });
req.on('close', function () { req.on('close', function () { });
// console.log("CLOSE");
});
}); });
server.listen(http_config.port, http_config.ip, undefined, self.server.listen(http_config.port, http_config.ip, void(0), function () {
function () {
// console.log("server up: %s %d", http_config.ip, http_config.port); // console.log("server up: %s %d", http_config.ip, http_config.port);
setup.call(self, done); setup.call(self, done);
}); });
}; };
}; };
var build_teardown = function () { function build_teardown() {
var teardown = testutils.build_teardown(); var teardown = testutils.build_teardown();
return function (done) { return function (done) {
var self = this; var self = this;
server.close(function () { self.server.close(function () {
// console.log("server closed"); // console.log("server closed");
teardown.call(self, done); teardown.call(self, done);
@@ -78,27 +58,30 @@ var build_teardown = function () {
}; };
}; };
buster.testCase("JSON-RPC", { suite('JSON-RPC', function() {
setUp : build_setup(), var $ = { };
// setUp : build_setup({ verbose: true }),
// setUp : build_setup({verbose: true , no_server: true}),
tearDown : build_teardown(),
"server_info" : setup(function(done) {
function (done) { build_setup().call($, done);
});
teardown(function(done) {
build_teardown().call($, done);
});
test('server info', function(done) {
var rippled_config = config.servers.alpha; var rippled_config = config.servers.alpha;
var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port); var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port);
client.call('server_info', [], function (result) { client.call('server_info', [ ], function (result) {
// console.log(JSON.stringify(result, undefined, 2)); // console.log(JSON.stringify(result, undefined, 2));
buster.assert('info' in result); assert(typeof result === 'object');
assert('info' in result);
done(); done();
}); });
}, });
"subscribe server" : test('subscribe server', function(done) {
function (done) {
var rippled_config = config.servers.alpha; var rippled_config = config.servers.alpha;
var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port); var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port);
var http_config = config.http_servers["zed"]; var http_config = config.http_servers["zed"];
@@ -108,22 +91,20 @@ buster.testCase("JSON-RPC", {
'streams' : [ 'server' ], 'streams' : [ 'server' ],
}], function (result) { }], function (result) {
// console.log(JSON.stringify(result, undefined, 2)); // console.log(JSON.stringify(result, undefined, 2));
assert(typeof result === 'object');
buster.assert('random' in result); assert('random' in result);
done(); done();
}); });
}, });
"subscribe ledger" : test('subscribe ledger', function(done) {
function (done) {
var self = this; var self = this;
var rippled_config = config.servers.alpha; var rippled_config = config.servers.alpha;
var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port); var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port);
var http_config = config.http_servers["zed"]; var http_config = config.http_servers["zed"];
async.waterfall([ var steps = [
function (callback) { function (callback) {
self.what = "Subscribe."; self.what = "Subscribe.";
@@ -132,20 +113,20 @@ buster.testCase("JSON-RPC", {
'streams' : [ 'ledger' ], 'streams' : [ 'ledger' ],
}], function (result) { }], function (result) {
//console.log(JSON.stringify(result, undefined, 2)); //console.log(JSON.stringify(result, undefined, 2));
assert(typeof result === 'object');
buster.assert('ledger_index' in result); assert('ledger_index' in result);
callback(); callback();
}); });
}, },
function (callback) { function (callback) {
self.what = "Accept a ledger."; self.what = "Accept a ledger.";
server_events.once('request', function (request, response) { $.server_events.once('request', function (request, response) {
// console.log("GOT: %s", JSON.stringify(request, undefined, 2)); // console.log("GOT: %s", JSON.stringify(request, undefined, 2));
buster.assert.equals(1, request.params.seq); assert.strictEqual(1, request.params.seq);
buster.assert.equals(3, request.params.ledger_index); assert.strictEqual(3, request.params.ledger_index);
response.statusCode = 200; response.statusCode = 200;
response.end(JSON.stringify({ response.end(JSON.stringify({
@@ -157,16 +138,17 @@ buster.testCase("JSON-RPC", {
callback(); callback();
}); });
self.remote.ledger_accept(); $.remote.ledger_accept();
}, },
function (callback) { function (callback) {
self.what = "Accept another ledger."; self.what = "Accept another ledger.";
server_events.once('request', function (request, response) { $.server_events.once('request', function (request, response) {
// console.log("GOT: %s", JSON.stringify(request, undefined, 2)); // console.log("GOT: %s", JSON.stringify(request, undefined, 2));
buster.assert.equals(2, request.params.seq); assert.strictEqual(2, request.params.seq);
buster.assert.equals(4, request.params.ledger_index); assert.strictEqual(4, request.params.ledger_index);
response.statusCode = 200; response.statusCode = 200;
response.end(JSON.stringify({ response.end(JSON.stringify({
@@ -178,11 +160,13 @@ buster.testCase("JSON-RPC", {
callback(); callback();
}); });
self.remote.ledger_accept(); $.remote.ledger_accept();
}, }
], function (error) { ]
buster.refute(error, self.what);
async.waterfall(steps, function(error) {
assert(!error, self.what);
done(); done();
}); });
} });
}); });

View File

@@ -1,52 +1,53 @@
var async = require("async"); var async = require("async");
var buster = require("buster"); var assert = require('assert');
var Amount = require("ripple-lib").Amount;
var Remote = require("ripple-lib").Remote; var Remote = require("ripple-lib").Remote;
var Server = require("./server").Server;
var testutils = require("./testutils"); var testutils = require("./testutils");
var config = testutils.init_config(); var config = testutils.init_config();
buster.testRunner.timeout = 5000; suite('Monitor account', function() {
var $ = { };
buster.testCase("//Monitor account", { setup(function(done) {
'setUp' : testutils.build_setup({ verbose: true }), testutils.build_setup().call($, done);
'tearDown' : testutils.build_teardown(),
"monitor root" :
function (done) {
var self = this;
async.waterfall([
function (callback) {
self.what = "Create accounts.";
testutils.create_accounts(self.remote, "root", "10000", ["alice"], callback);
},
function (callback) {
self.what = "Close ledger.";
self.remote.once('ledger_closed', function () {
callback();
}); });
self.remote.ledger_accept(); teardown(function(done) {
testutils.build_teardown().call($, done);
});
test('monitor root', function() {
var self = this;
var steps = [
function (callback) {
self.what = "Create accounts.";
testutils.create_accounts($.remote, "root", "10000", ["alice"], callback);
}, },
function (callback) {
self.what = "Close ledger.";
$.remote.once('ledger_closed', function () {
callback();
});
$.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($.remote, "root", function (error) {
buster.refute(error); assert.ifError(error);
callback(); callback();
}); });
}, }
], function (error) { ]
buster.refute(error, self.what);
async.waterfall(steps, function(error) {
assert(!effor, self.what);
done(); done();
}); });
}, });
}); });
// vim:sw=2:sts=2:ts=8:et // vim:sw=2:sts=2:ts=8:et

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,233 +1,173 @@
var buster = require("buster"); var assert = require('assert');
var Amount = require("ripple-lib").Amount;
var Remote = require("ripple-lib").Remote; var Remote = require("ripple-lib").Remote;
var Server = require("./server.js").Server;
var testutils = require("./testutils.js"); var testutils = require("./testutils.js");
var config = testutils.init_config(); var config = testutils.init_config();
// How long to wait for server to start. suite('Remote functions', function() {
var serverDelay = 1500; // XXX Not implemented. var $ = { };
buster.testRunner.timeout = 5000 * 10; setup(function(done) {
testutils.build_setup().call($, done);
});
buster.testCase("Remote functions", { teardown(function(done) {
'setUp' : testutils.build_setup(), testutils.build_teardown().call($, done);
'tearDown' : testutils.build_teardown(), });
"request_ledger_current" : function (done) { test('request_ledger_current', function(done) {
this.remote.request_ledger_current().on('success', function (m) { $.remote.request_ledger_current(function(err, m) {
buster.assert.equals(m.ledger_current_index, 3); assert(!err);
assert.strictEqual(m.ledger_current_index, 3);
done(); done();
}) });
.on('error', function(m) { });
buster.assert(false);
})
.request(); test('request_ledger_hash', function(done) {
}, $.remote.request_ledger_hash(function(err, m) {
"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));
assert(!err);
buster.assert.equals(m.ledger_index, 2); assert.strictEqual(m.ledger_index, 2);
done(); done();
}) })
.on('error', function(m) { });
// console.log("error: %s", m);
buster.assert(false); test('manual account_root success', function(done) {
})
.request();
},
"manual account_root success" : function (done) {
var self = this; var self = this;
this.remote.request_ledger_hash().on('success', function (r) { $.remote.request_ledger_hash(function(err, r) {
// console.log("result: %s", JSON.stringify(r)); //console.log("result: %s", JSON.stringify(r));
assert(!err);
assert('ledger_hash' in r);
self.remote var request = $.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) {
request.callback(function(err, r) {
// console.log("account_root: %s", JSON.stringify(r)); // console.log("account_root: %s", JSON.stringify(r));
assert(!err);
buster.assert('node' in r); assert('node' in r);
done(); done();
}) });
.on('error', function(m) { });
// console.log("error: %s", m); });
buster.assert(false); test('account_root remote malformedAddress', function(done) {
})
.request();
})
.on('error', function(m) {
// console.log("error: %s", m);
buster.assert(false);
})
.request();
},
// XXX This should be detected locally.
"account_root remote malformedAddress" : function (done) {
var self = this; var self = this;
this.remote.request_ledger_hash().on('success', function (r) { $.remote.request_ledger_hash(function(err, r) {
// console.log("result: %s", JSON.stringify(r)); // console.log("result: %s", JSON.stringify(r));
assert(!err);
self.remote var request = $.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) {
request.callback(function(err, r) {
// console.log("account_root: %s", JSON.stringify(r)); // console.log("account_root: %s", JSON.stringify(r));
buster.assert(false); assert(err);
}) assert.strictEqual(err.error, 'remoteError');
.on('error', function(m) { assert.strictEqual(err.remote.error, 'malformedAddress');
// console.log("error: %s", m);
buster.assert.equals(m.error, 'remoteError');
buster.assert.equals(m.remote.error, 'malformedAddress');
done(); done();
});
}) })
.request(); });
})
.on('error', function(m) {
// console.log("error: %s", m);
buster.assert(false); test('account_root entryNotFound', function(done) {
})
.request();
},
"account_root entryNotFound" : function (done) {
var self = this; var self = this;
this.remote.request_ledger_hash().on('success', function (r) { $.remote.request_ledger_hash(function(err, r) {
// console.log("result: %s", JSON.stringify(r)); // console.log("result: %s", JSON.stringify(r));
assert(!err);
self.remote var request = $.remote.request_ledger_entry('account_root')
.request_ledger_entry('account_root') .ledger_hash(r.ledger_hash)
.account_root("alice");
request.callback(function(err, r) {
// console.log("error: %s", m);
assert(err);
assert.strictEqual(err.error, 'remoteError');
assert.strictEqual(err.remote.error, 'entryNotFound');
done();
});
})
});
test('ledger_entry index', function(done) {
var self = this;
$.remote.request_ledger_hash(function(err, r) {
assert(!err);
var request = $.remote.request_ledger_entry('index')
.ledger_hash(r.ledger_hash) .ledger_hash(r.ledger_hash)
.account_root("alice") .account_root("alice")
.on('success', function (r) { .index("2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8");
// console.log("account_root: %s", JSON.stringify(r));
buster.assert(false); request.callback(function(err, r) {
}) assert(!err);
.on('error', function(m) { assert('node_binary' in r);
// console.log("error: %s", m);
buster.assert.equals(m.error, 'remoteError');
buster.assert.equals(m.remote.error, 'entryNotFound');
done(); done();
});
}) })
.request(); });
})
.on('error', function(m) {
// console.log("error: %s", m);
buster.assert(false); test('create account', function(done) {
}).request();
},
"ledger_entry index" : function (done) {
var self = this; var self = this;
this.remote.request_ledger_hash().on('success', function (r) { var root_id = $.remote.account('root')._account_id;
// console.log("result: %s", JSON.stringify(r));
self.remote $.remote.request_subscribe().accounts(root_id).request();
.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); $.remote.transaction()
done();
})
.on('error', function(m) {
// console.log("error: %s", m);
buster.assert(false);
}).
request();
})
.on('error', function(m) {
// console.log(m);
buster.assert(false);
})
.request();
},
"create account" : function (done) {
var self = this;
var root_id = this.remote.account('root')._account_id;
this.remote.request_subscribe().accounts(root_id).request();
this.remote.transaction()
.payment('root', 'alice', "10000.0") .payment('root', 'alice', "10000.0")
.on('proposed', function(res) { .once('error', done)
.once('proposed', function(res) {
//console.log('Submitted', res); //console.log('Submitted', res);
self.remote.ledger_accept(); $.remote.ledger_accept();
}) })
.on('success', function (r) { .once('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);
done(); done();
}) })
.on('error', function(m) {
console.log('Error');
console.log("error: %s", m);
buster.assert(false);
})
.submit(); .submit();
}, });
"create account final" : function (done) { test('create account final', function(done) {
var self = this; var self = this;
var got_proposed; var got_proposed;
var got_success; var got_success;
var root_id = this.remote.account('root')._account_id; var root_id = $.remote.account('root')._account_id;
this.remote.request_subscribe().accounts(root_id).request();
this.remote.transaction() $.remote.request_subscribe().accounts(root_id).request();
var transaction = $.remote.transaction()
.payment('root', 'alice', "10000.0") .payment('root', 'alice', "10000.0")
.on('success', function (r) { .once('error', done)
.once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m));
// buster.assert.equals(m.result, 'terNO_DST_INSUF_XRP');
assert.strictEqual(m.engine_result, 'tesSUCCESS');
})
.once('proposed', function() {
got_proposed = true;
$.remote.ledger_accept();
})
.once('success', function (r) {
// console.log("create_account: %s", JSON.stringify(r)); // console.log("create_account: %s", JSON.stringify(r));
got_success = true; got_success = true;
}) })
.on('error', function (m) { .once('final', function (m) {
// console.log("error: %s", m);
buster.assert(false);
})
.on('final', function (m) {
// console.log("final: %s", JSON.stringify(m)); // console.log("final: %s", JSON.stringify(m));
buster.assert(got_success && got_proposed); assert(got_success);
assert(got_proposed);
done(); done();
}) });
.on('proposed', function() { transaction.submit();
got_proposed = true; });
self.remote.ledger_accept();
})
.on('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m));
// buster.assert.equals(m.result, 'terNO_DST_INSUF_XRP');
buster.assert.equals(m.engine_result, 'tesSUCCESS');
})
.submit();
},
}); });
// vim:sw=2:sts=2:ts=8:et //vim:sw=2:sts=2:ts=8:et

File diff suppressed because it is too large Load Diff

View File

@@ -1,34 +1,19 @@
var buster = require("buster"); var assert = require('assert');
var extend = require("extend"); var extend = require("extend");
var Server = require("./server").Server; var Server = require("./server").Server;
var testutils = require("./testutils"); var testutils = require("./testutils");
var config = testutils.init_config(); var config = testutils.init_config();
// How long to wait for server to start. suite('Standalone server startup', function() {
// var serverDelay = 1500; test('server start and stop', function(done) {
var cfg = extend({}, config.default_server_config, config.servers.alpha);
var alpha; var alpha = Server.from_config("alpha", cfg);
alpha.on('started', function () {
buster.testCase("Standalone server startup", { alpha.on('stopped', function () {
"server start and stop" : function (done) {
var cfg = extend({}, config.default_server_config,
config.servers.alpha);
alpha = Server.from_config("alpha", cfg);
alpha
.on('started', function () {
alpha
.on('stopped', function () {
buster.assert(true);
done(); done();
}) })
.stop(); alpha.stop();
}) })
.start(); alpha.start();
} });
}); });
// vim:sw=2:sts=2:ts=8:et

View File

@@ -15,17 +15,16 @@
// Servers are created in tmp/server/$server // Servers are created in tmp/server/$server
// //
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 assert = require('assert');
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
var nodeutils = require("./nodeutils"); var nodeutils = require("./nodeutils");
// Create a server object // Create a server object
var Server = function (name, config, verbose) { function Server(name, config, verbose) {
this.name = name; this.name = name;
this.config = config; this.config = config;
this.started = false; this.started = false;
@@ -47,10 +46,8 @@ var Server = function (name, config, verbose) {
? nodejs_version[0] - wanted_version[0] ? nodejs_version[0] - wanted_version[0]
: -1; : -1;
if (sgn < 0) if (sgn < 0) {
{
console.log("\n*** Node.js version is too low."); console.log("\n*** Node.js version is too low.");
throw "Nodejs version is too low."; throw "Nodejs version is too low.";
} }
}; };
@@ -61,18 +58,6 @@ Server.from_config = function (name, config, verbose) {
return new Server(name, config, verbose); return new Server(name, config, verbose);
}; };
Server.prototype.on = function (e, c) {
EventEmitter.prototype.on.call(this, e, c);
return this;
};
Server.prototype.once = function (e, c) {
EventEmitter.prototype.once.call(this, e, c);
return this;
};
Server.prototype.serverPath = function() { Server.prototype.serverPath = function() {
return path.resolve("tmp/server", this.name); return path.resolve("tmp/server", this.name);
}; };
@@ -103,15 +88,14 @@ Server.prototype._serverSpawnSync = function() {
"--conf=rippled.cfg" "--conf=rippled.cfg"
]; ];
// Spawn in standalone mode for now. var options = {
this.child = child.spawn(
this.config.rippled_path,
args,
{
cwd: this.serverPath(), cwd: this.serverPath(),
env: process.env, env: process.env,
stdio: this.quiet ? 'ignore' : 'inherit' stdio: this.quiet ? 'ignore' : 'inherit'
}); };
// Spawn in standalone mode for now.
this.child = child.spawn(this.config.rippled_path, args, options);
if (!this.quiet) if (!this.quiet)
console.log("server: start %s: %s --conf=%s", console.log("server: start %s: %s --conf=%s",
@@ -126,16 +110,10 @@ Server.prototype._serverSpawnSync = function() {
self.emit('exited'); self.emit('exited');
// Workaround for
// https://github.com/busterjs/buster/issues/266
if (!self.stopping) {
buster.assertions.throwOnFailure = true;
}
// If could not exec: code=127, signal=null // If could not exec: code=127, signal=null
// If regular exit: code=0, signal=null // If regular exit: code=0, signal=null
// Fail the test if the server has not called "stop". // Fail the test if the server has not called "stop".
buster.assert(self.stopping, 'Server died with signal '+signal); assert(self.stopping, 'Server died with signal '+signal);
}); });
}; };
@@ -146,12 +124,8 @@ 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 {
self._writeConfig(done); self._writeConfig(done);
}
}); });
}; };
@@ -169,13 +143,9 @@ Server.prototype.start = function () {
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 {
self._serverSpawnSync(); self._serverSpawnSync();
self.emit('started'); self.emit('started');
}
}); });
return this; return this;
@@ -187,23 +157,19 @@ Server.prototype.stop = function () {
self.stopping = true; self.stopping = true;
if (this.child) { if (!this.child) {
console.log("server: stop: can't stop");
return;
}
// 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 self.child; delete self.child;
}); });
this.child.kill(); this.child.kill();
}
else
{
buster.log("server: stop: can't stop");
}
return this; return this;
}; };

View File

@@ -1,18 +1,19 @@
var async = require('async'); var async = require('async');
var assert = require('assert');
var extend = require('extend'); var extend = require('extend');
var Amount = require('ripple-lib').Amount; var Amount = require('ripple-lib').Amount;
var Remote = require('ripple-lib').Remote; var Remote = require('ripple-lib').Remote;
var Server = require('./server').Server;
var Transaction = require('ripple-lib').Transaction; var Transaction = require('ripple-lib').Transaction;
var Server = require('./server').Server;
var server = { };
function get_config() { function get_config() {
var cfg = require('./config-example'); var cfg = require(__dirname + '/config-example');
// See if the person testing wants to override the configuration by creating a // See if the person testing wants to override the configuration by creating a
// file called test/config.js. // file called test/config.js.
try { try {
cfg = extend({}, cfg, require('./config')); cfg = extend({}, cfg, require(__dirname + '/config'));
} catch (e) { } } catch (e) { }
return cfg; return cfg;
@@ -40,7 +41,7 @@ function account_dump(remote, account, callback) {
request.ledger_hash(remote.ledger_hash()); request.ledger_hash(remote.ledger_hash());
request.account_root('root'); request.account_root('root');
request.callback(function(err, r) { request.callback(function(err, r) {
buster.isNull(err); assert(!err, self.what);
if (err) { if (err) {
//console.log('error: %s', m); //console.log('error: %s', m);
callback(err); callback(err);
@@ -119,7 +120,10 @@ function build_setup(opts, host) {
data.server = Server.from_config(host, server_config, !!opts.verbose_server); data.server = Server.from_config(host, server_config, !!opts.verbose_server);
data.server.once('started', callback); data.server.once('started', function() {
callback();
});
data.server.once('exited', function () { data.server.once('exited', function () {
// If know the remote, tell it server is gone. // If know the remote, tell it server is gone.
if (self.remote) { if (self.remote) {
@@ -127,12 +131,15 @@ function build_setup(opts, host) {
} }
}); });
server[host] = data.server;
data.server.start(); data.server.start();
}, },
function connect_websocket(callback) { function connect_websocket(callback) {
self.remote = data.remote = Remote.from_config(host, !!opts.verbose_ws); self.remote = data.remote = Remote.from_config(host, !!opts.verbose_ws);
self.remote.once('ledger_closed', callback); self.remote.once('ledger_closed', function(ledger) {
callback();
});
self.remote.connect(); self.remote.connect();
} }
]; ];
@@ -160,7 +167,7 @@ function build_teardown(host) {
function disconnect_websocket(callback) { function disconnect_websocket(callback) {
data.remote.once('disconnected', callback) data.remote.once('disconnected', callback)
data.remote.once('error', function (m) { data.remote.once('error', function (m) {
console.log('server error: ', m); //console.log('server error: ', m);
}) })
data.remote.connect(false); data.remote.connect(false);
}, },
@@ -171,6 +178,7 @@ function build_teardown(host) {
} else { } else {
data.server.once('stopped', callback) data.server.once('stopped', callback)
data.server.stop(); data.server.stop();
delete server[host];
} }
} }
]; ];
@@ -196,12 +204,12 @@ function create_accounts(remote, src, amount, accounts, callback) {
tx.payment(src, account, amount); tx.payment(src, account, amount);
tx.once('proposed', function (m) { tx.once('proposed', function (m) {
// console.log('proposed: %s', JSON.stringify(m)); //console.log('proposed: %s', JSON.stringify(m));
callback(m.engine_result === 'tesSUCCESS' ? null : new Error()); callback(m.engine_result === 'tesSUCCESS' ? null : new Error());
}); });
tx.once('error', function (m) { tx.once('error', function (m) {
// console.log('error: %s', JSON.stringify(m)); //console.log('error: %s', JSON.stringify(m));
callback(m); callback(m);
}); });
@@ -269,9 +277,9 @@ function verify_limit(remote, src, amount, callback) {
if (err) { if (err) {
callback(err); callback(err);
} else { } else {
buster.assert(m.account_limit.equals(limit)); assert(m.account_limit.equals(limit));
buster.assert(isNaN(quality_in) || m.account_quality_in === quality_in); assert(isNaN(quality_in) || m.account_quality_in === quality_in);
buster.assert(isNaN(quality_out) || m.account_quality_out === quality_out); assert(isNaN(quality_out) || m.account_quality_out === quality_out);
callback(null); callback(null);
} }
}); });
@@ -321,7 +329,6 @@ function payment(remote, src, dst, amount, callback) {
// console.log('error: %s', JSON.stringify(m)); // console.log('error: %s', JSON.stringify(m));
callback(m); callback(m);
}); });
tx.submit(); tx.submit();
}; };
@@ -348,7 +355,7 @@ function payments(remote, balances, callback) {
}; };
function transfer_rate(remote, src, billionths, callback) { function transfer_rate(remote, src, billionths, callback) {
assert(arguments.length === 4); assert.strictEqual(arguments.length, 4);
var tx = remote.transaction(); var tx = remote.transaction();
tx.account_set(src); tx.account_set(src);
@@ -518,4 +525,10 @@ exports.verify_offer_not_found = verify_offer_not_found;
exports.verify_owner_count = verify_owner_count; exports.verify_owner_count = verify_owner_count;
exports.verify_owner_counts = verify_owner_counts; exports.verify_owner_counts = verify_owner_counts;
process.on('uncaughtException', function() {
Object.keys(server).forEach(function(host) {
server[host].stop();
});
});
// vim:sw=2:sts=2:ts=8:et // vim:sw=2:sts=2:ts=8:et

View File

@@ -1,55 +1,46 @@
var buster = require("buster"); var assert = require('assert');
var extend = require("extend"); var extend = require("extend");
var Server = require("./server").Server; var Server = require("./server").Server;
var Remote = require("ripple-lib").Remote; var Remote = require("ripple-lib").Remote;
var testutils = require('./testutils'); var testutils = require('./testutils');
var config = testutils.init_config(); var config = testutils.init_config();
buster.testRunner.timeout = 5000; suite('WebSocket connection', function() {
var server;
var server; setup(function(done) {
buster.testCase("WebSocket connection", { var cfg = extend({}, config.default_server_config, config.servers.alpha);
'setUp' :
function (done) {
var cfg = extend({}, config.default_server_config,
config.servers.alpha);
if (cfg.no_server) { if (cfg.no_server) {
done(); done();
} else { } else {
server = Server.from_config("alpha", cfg).on('started', done).start(); server = Server.from_config("alpha", cfg);
server.once('started', done)
server.start();
} }
}, });
'tearDown' : teardown(function(done) {
function (done) {
if (config.servers.alpha.no_server) { if (config.servers.alpha.no_server) {
done(); done();
} else { } else {
server.on('stopped', done).stop(); server.on('stopped', done);
server.stop();
} }
}, });
"websocket connect and disconnect" : test('WebSocket connect and disconnect', function() {
function (done) {
var alpha = Remote.from_config("alpha"); var alpha = Remote.from_config("alpha");
alpha alpha.on('connected', function () {
.on('connected', function () { alpha.on('disconnected', function () {
// OPEN
buster.assert(true);
alpha
.on('disconnected', function () {
// CLOSED // CLOSED
buster.assert(true);
done(); done();
});
alpha.connect(false);
}) })
.connect(false);
}) alpha.connect();
.connect(); });
},
}); });
// vim:sw=2:sts=2:ts=8:et // vim:sw=2:sts=2:ts=8:et