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,217 +1,235 @@
var async = require("async"); var async = require("async");
var buster = require("buster"); var assert = require('assert');
var Remote = require("ripple-lib").Remote;
var testutils = require("./testutils");
var config = testutils.init_config();
var Amount = require("ripple-lib").Amount; suite('Account set', function() {
var Remote = require("ripple-lib").Remote; var $ = { };
var Request = require("ripple-lib").Request;
var Server = require("./server").Server;
var testutils = require("./testutils"); setup(function(done) {
var config = testutils.init_config(); testutils.build_setup().call($, done);
});
// How long to wait for server to start. teardown(function(done) {
var serverDelay = 1500; testutils.build_teardown().call($, done);
});
buster.testRunner.timeout = 5000; test('set RequireDestTag', function(done) {
buster.testCase("AccountSet", {
'setUp' : testutils.build_setup(),
// 'setUp' : testutils.build_setup({verbose: true , no_server: false}),
'tearDown' : testutils.build_teardown(),
"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(null);
} else {
callback(new Error(m.engine_result));
}
})
.submit();
},
callback(m.engine_result !== 'tesSUCCESS'); function (callback) {
}) self.what = "Check RequireDestTag";
.submit();
},
function (callback) {
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) {
self.what = "Clear RequireDestTag.";
self.remote.transaction() function (callback) {
.account_set("root") self.what = "Clear RequireDestTag.";
.set_flags('OptionalDestTag')
.on('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m));
callback(m.engine_result !== 'tesSUCCESS'); $.remote.transaction()
}) .account_set("root")
.submit(); .set_flags('OptionalDestTag')
}, .on('submitted', function (m) {
function (callback) { //console.log("proposed: %s", JSON.stringify(m));
self.what = "Check No RequireDestTag"; callback(m.engine_result === 'tesSUCCESS' ? null : new Error());
})
.submit();
},
self.remote.request_account_flags('root', 'CURRENT') function (callback) {
.on('success', function (m) { self.what = "Check No RequireDestTag";
var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireDestTag);
if (wrong) $.remote.request_account_flags('root', 'CURRENT')
console.log("Clear RequireDestTag: failed: %s", JSON.stringify(m)); .on('success', function (m) {
var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireDestTag);
callback(wrong); if (wrong) {
}) console.log("Clear RequireDestTag: failed: %s", JSON.stringify(m));
.request(); }
},
], function (error) { callback(wrong ? new Error(m) : null);
buster.refute(error, self.what); })
.request();
}
]
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));
})
.submit();
},
callback(m.engine_result !== 'tesSUCCESS'); function (callback) {
}) self.what = "Check RequireAuth";
.submit();
},
function (callback) {
self.what = "Check RequireAuth";
self.remote.request_account_flags('root', 'CURRENT') $.remote.request_account_flags('root', 'CURRENT')
.on('success', function (m) { .on('error', callback)
var wrong = !(m.node.Flags & Remote.flags.account_root.RequireAuth); .on('success', function (m) {
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) {
self.what = "Clear RequireAuth.";
self.remote.transaction() function (callback) {
.account_set("root") self.what = "Clear RequireAuth.";
.set_flags('OptionalAuth')
.on('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m));
callback(m.engine_result !== 'tesSUCCESS'); $.remote.transaction()
}) .account_set("root")
.submit(); .set_flags('OptionalAuth')
}, .on('submitted', function (m) {
function (callback) { //console.log("proposed: %s", JSON.stringify(m));
self.what = "Check No RequireAuth";
self.remote.request_account_flags('root', 'CURRENT') callback(m.engine_result !== 'tesSUCCESS');
.on('success', function (m) { })
var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireAuth); .submit();
},
if (wrong) function (callback) {
console.log("Clear RequireAuth: failed: %s", JSON.stringify(m)); self.what = "Check No RequireAuth";
callback(wrong); $.remote.request_account_flags('root', 'CURRENT')
}) .on('error', callback)
.request(); .on('success', function (m) {
}, var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireAuth);
// XXX Also check fails if something is owned.
], function (error) { if (wrong) {
buster.refute(error, self.what); console.log("Clear RequireAuth: failed: %s", JSON.stringify(m));
}
callback(wrong ? new Error(m) : null);
})
.request();
}
// XXX Also check fails if something is owned.
]
async.waterfall(steps, function(error) {
assert(!error, self.what);
done(); 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));
})
.submit();
},
callback(m.engine_result !== 'tesSUCCESS'); function (callback) {
}) self.what = "Check DisallowXRP";
.submit();
},
function (callback) {
self.what = "Check DisallowXRP";
self.remote.request_account_flags('root', 'CURRENT') $.remote.request_account_flags('root', 'CURRENT')
.on('success', function (m) { .on('error', callback)
var wrong = !(m.node.Flags & Remote.flags.account_root.DisallowXRP); .on('success', function (m) {
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) {
self.what = "Clear DisallowXRP.";
self.remote.transaction() function (callback) {
.account_set("root") self.what = "Clear DisallowXRP.";
.set_flags('AllowXRP')
.on('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m));
callback(m.engine_result !== 'tesSUCCESS'); $.remote.transaction()
}) .account_set("root")
.submit(); .set_flags('AllowXRP')
}, .on('submitted', function (m) {
function (callback) { //console.log("proposed: %s", JSON.stringify(m));
self.what = "Check AllowXRP";
self.remote.request_account_flags('root', 'CURRENT') callback(m.engine_result === 'tesSUCCESS' ? null : new Error(m));
.on('success', function (m) { })
var wrong = !!(m.node.Flags & Remote.flags.account_root.DisallowXRP); .submit();
},
if (wrong) function (callback) {
console.log("Clear DisallowXRP: failed: %s", JSON.stringify(m)); self.what = "Check AllowXRP";
callback(wrong); $.remote.request_account_flags('root', 'CURRENT')
}) .on('error', callback)
.request(); .on('success', function (m) {
}, var wrong = !!(m.node.Flags & Remote.flags.account_root.DisallowXRP);
], function (error) {
buster.refute(error, self.what); if (wrong) {
console.log("Clear DisallowXRP: failed: %s", JSON.stringify(m));
}
callback(wrong ? new Error(m) : null);
})
.request();
}
]
async.waterfall(steps, function(err) {
assert(!err);
done(); 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,188 +1,172 @@
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 Remote = require("ripple-lib").Remote;
var testutils = require("./testutils");
var config = testutils.init_config();
var Amount = require("ripple-lib").Amount; function build_setup(options) {
var Remote = require("ripple-lib").Remote;
var Server = require("./server").Server;
var testutils = require("./testutils");
var config = testutils.init_config();
// How long to wait for server to start.
var serverDelay = 1500;
buster.testRunner.timeout = 5000;
var server;
var server_events;
var build_setup = function (options) {
var setup = testutils.build_setup(options); var setup = testutils.build_setup(options);
return function (done) { return function (done) {
var self = this; var self = this;
var http_config = config.http_servers["zed"]; var http_config = config.http_servers["zed"];
server_events = new EventEmitter; self.server_events = new EventEmitter;
server = http.createServer(function (req, res) {
// console.log("REQUEST");
var input = "";
req.setEncoding(); self.server = http.createServer(function (req, res) {
// console.log("REQUEST");
var input = "";
req.on('data', function (buffer) { req.setEncoding('utf8');
// console.log("DATA: %s", buffer);
input = input + buffer; req.on('data', function (buffer) {
}); // console.log("DATA: %s", 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));
self.server_events.emit('request', request, res);
});
// console.log("REQ: %s", JSON.stringify(request, undefined, 2)); req.on('close', function () { });
});
server_events.emit('request', request, res); self.server.listen(http_config.port, http_config.ip, void(0), function () {
}); // console.log("server up: %s %d", http_config.ip, http_config.port);
setup.call(self, done);
req.on('close', function () { });
// console.log("CLOSE"); };
});
});
server.listen(http_config.port, http_config.ip, undefined,
function () {
// console.log("server up: %s %d", http_config.ip, http_config.port);
setup.call(self, done);
});
};
}; };
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);
}); });
}; };
}; };
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);
var rippled_config = config.servers.alpha; });
var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port);
client.call('server_info', [], function (result) { teardown(function(done) {
// console.log(JSON.stringify(result, undefined, 2)); build_teardown().call($, done);
buster.assert('info' in result); });
done(); test('server info', function(done) {
}); var rippled_config = config.servers.alpha;
}, var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port);
"subscribe server" : client.call('server_info', [ ], function (result) {
function (done) { // console.log(JSON.stringify(result, undefined, 2));
var rippled_config = config.servers.alpha; assert(typeof result === 'object');
var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port); assert('info' in result);
var http_config = config.http_servers["zed"]; done();
});
});
client.call('subscribe', [{ test('subscribe server', function(done) {
var rippled_config = config.servers.alpha;
var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port);
var http_config = config.http_servers["zed"];
client.call('subscribe', [{
'url' : "http://" + http_config.ip + ":" + http_config.port,
'streams' : [ 'server' ],
}], function (result) {
// console.log(JSON.stringify(result, undefined, 2));
assert(typeof result === 'object');
assert('random' in result);
done();
});
});
test('subscribe ledger', function(done) {
var self = this;
var rippled_config = config.servers.alpha;
var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port);
var http_config = config.http_servers["zed"];
var steps = [
function (callback) {
self.what = "Subscribe.";
client.call('subscribe', [{
'url' : "http://" + http_config.ip + ":" + http_config.port, 'url' : "http://" + http_config.ip + ":" + http_config.port,
'streams' : [ 'server' ], '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('random' in result); assert('ledger_index' in result);
callback();
done();
}); });
}, },
"subscribe ledger" : function (callback) {
function (done) { self.what = "Accept a ledger.";
var self = this;
var rippled_config = config.servers.alpha; $.server_events.once('request', function (request, response) {
var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port); // console.log("GOT: %s", JSON.stringify(request, undefined, 2));
var http_config = config.http_servers["zed"];
async.waterfall([ assert.strictEqual(1, request.params.seq);
function (callback) { assert.strictEqual(3, request.params.ledger_index);
self.what = "Subscribe.";
client.call('subscribe', [{ response.statusCode = 200;
'url' : "http://" + http_config.ip + ":" + http_config.port, response.end(JSON.stringify({
'streams' : [ 'ledger' ], jsonrpc: "2.0",
}], function (result) { result: {},
//console.log(JSON.stringify(result, undefined, 2)); id: request.id
}));
buster.assert('ledger_index' in result); callback();
callback();
});
},
function (callback) {
self.what = "Accept a ledger.";
server_events.once('request', function (request, response) {
// console.log("GOT: %s", JSON.stringify(request, undefined, 2));
buster.assert.equals(1, request.params.seq);
buster.assert.equals(3, request.params.ledger_index);
response.statusCode = 200;
response.end(JSON.stringify({
jsonrpc: "2.0",
result: {},
id: request.id
}));
callback();
});
self.remote.ledger_accept();
},
function (callback) {
self.what = "Accept another ledger.";
server_events.once('request', function (request, response) {
// console.log("GOT: %s", JSON.stringify(request, undefined, 2));
buster.assert.equals(2, request.params.seq);
buster.assert.equals(4, request.params.ledger_index);
response.statusCode = 200;
response.end(JSON.stringify({
jsonrpc: "2.0",
result: {},
id: request.id
}));
callback();
});
self.remote.ledger_accept();
},
], function (error) {
buster.refute(error, self.what);
done();
}); });
}
$.remote.ledger_accept();
},
function (callback) {
self.what = "Accept another ledger.";
$.server_events.once('request', function (request, response) {
// console.log("GOT: %s", JSON.stringify(request, undefined, 2));
assert.strictEqual(2, request.params.seq);
assert.strictEqual(4, request.params.ledger_index);
response.statusCode = 200;
response.end(JSON.stringify({
jsonrpc: "2.0",
result: {},
id: request.id
}));
callback();
});
$.remote.ledger_accept();
}
]
async.waterfall(steps, function(error) {
assert(!error, self.what);
done();
});
});
}); });

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" : teardown(function(done) {
function (done) { testutils.build_teardown().call($, done);
var self = this; });
async.waterfall([ test('monitor root', function() {
function (callback) {
self.what = "Create accounts.";
testutils.create_accounts(self.remote, "root", "10000", ["alice"], callback); var self = this;
},
function (callback) {
self.what = "Close ledger.";
self.remote.once('ledger_closed', function () { var steps = [
callback(); function (callback) {
}); self.what = "Create accounts.";
testutils.create_accounts($.remote, "root", "10000", ["alice"], callback);
},
self.remote.ledger_accept(); function (callback) {
}, self.what = "Close ledger.";
function (callback) { $.remote.once('ledger_closed', function () {
self.what = "Dumping root."; callback();
});
$.remote.ledger_accept();
},
testutils.account_dump(self.remote, "root", function (error) { function (callback) {
buster.refute(error); self.what = "Dumping root.";
callback(); testutils.account_dump($.remote, "root", function (error) {
}); assert.ifError(error);
}, callback();
], function (error) { });
buster.refute(error, self.what); }
done(); ]
});
}, async.waterfall(steps, function(error) {
assert(!effor, self.what);
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);
done(); assert.strictEqual(m.ledger_current_index, 3);
}) done();
.on('error', function(m) { });
buster.assert(false); });
})
.request(); test('request_ledger_hash', function(done) {
}, $.remote.request_ledger_hash(function(err, m) {
// console.log("result: %s", JSON.stringify(m));
assert(!err);
assert.strictEqual(m.ledger_index, 2);
done();
})
});
"request_ledger_hash" : function (done) { test('manual account_root success', function(done) {
this.remote.request_ledger_hash().on('success', function (m) {
// console.log("result: %s", JSON.stringify(m));
buster.assert.equals(m.ledger_index, 2);
done();
})
.on('error', function(m) {
// console.log("error: %s", m);
buster.assert(false);
})
.request();
},
"manual account_root success" : function (done) {
var self = this;
this.remote.request_ledger_hash().on('success', function (r) {
// console.log("result: %s", JSON.stringify(r));
self.remote
.request_ledger_entry('account_root')
.ledger_hash(r.ledger_hash)
.account_root("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")
.on('success', function (r) {
// console.log("account_root: %s", JSON.stringify(r));
buster.assert('node' in r);
done();
})
.on('error', function(m) {
// console.log("error: %s", m);
buster.assert(false);
})
.request();
})
.on('error', function(m) {
// console.log("error: %s", m);
buster.assert(false);
})
.request();
},
// XXX This should be detected locally.
"account_root remote malformedAddress" : function (done) {
var self = this;
this.remote.request_ledger_hash().on('success', function (r) {
// console.log("result: %s", JSON.stringify(r));
self.remote
.request_ledger_entry('account_root')
.ledger_hash(r.ledger_hash)
.account_root("zHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")
.on('success', function (r) {
// console.log("account_root: %s", JSON.stringify(r));
buster.assert(false);
})
.on('error', function(m) {
// console.log("error: %s", m);
buster.assert.equals(m.error, 'remoteError');
buster.assert.equals(m.remote.error, 'malformedAddress');
done();
})
.request();
})
.on('error', function(m) {
// console.log("error: %s", m);
buster.assert(false);
})
.request();
},
"account_root entryNotFound" : function (done) {
var self = this;
this.remote.request_ledger_hash().on('success', function (r) {
// console.log("result: %s", JSON.stringify(r));
self.remote
.request_ledger_entry('account_root')
.ledger_hash(r.ledger_hash)
.account_root("alice")
.on('success', function (r) {
// console.log("account_root: %s", JSON.stringify(r));
buster.assert(false);
})
.on('error', function(m) {
// console.log("error: %s", m);
buster.assert.equals(m.error, 'remoteError');
buster.assert.equals(m.remote.error, 'entryNotFound');
done();
})
.request();
})
.on('error', function(m) {
// console.log("error: %s", m);
buster.assert(false);
}).request();
},
"ledger_entry index" : function (done) {
var self = this;
this.remote.request_ledger_hash().on('success', function (r) {
// console.log("result: %s", JSON.stringify(r));
self.remote
.request_ledger_entry('index')
.ledger_hash(r.ledger_hash)
.account_root("alice")
.index("2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8")
.on('success', function (r) {
// console.log("account_root: %s", JSON.stringify(r));
buster.assert('node_binary' in r);
done();
})
.on('error', function(m) {
// console.log("error: %s", m);
buster.assert(false);
}).
request();
})
.on('error', function(m) {
// console.log(m);
buster.assert(false);
})
.request();
},
"create account" : function (done) {
var self = this; var self = this;
var root_id = this.remote.account('root')._account_id; $.remote.request_ledger_hash(function(err, r) {
this.remote.request_subscribe().accounts(root_id).request(); //console.log("result: %s", JSON.stringify(r));
assert(!err);
assert('ledger_hash' in r);
this.remote.transaction() var request = $.remote.request_ledger_entry('account_root')
.payment('root', 'alice', "10000.0") .ledger_hash(r.ledger_hash)
.on('proposed', function(res) { .account_root("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
//console.log('Submitted', res);
self.remote.ledger_accept();
})
.on('success', function (r) {
//console.log("account_root: %s", JSON.stringify(r));
// Need to verify account and balance.
buster.assert(true);
done();
})
.on('error', function(m) {
console.log('Error');
console.log("error: %s", m);
buster.assert(false);
})
.submit();
},
"create account final" : function (done) { request.callback(function(err, r) {
var self = this; // console.log("account_root: %s", JSON.stringify(r));
var got_proposed; assert(!err);
var got_success; assert('node' in r);
done();
});
});
});
var root_id = this.remote.account('root')._account_id; test('account_root remote malformedAddress', function(done) {
this.remote.request_subscribe().accounts(root_id).request(); var self = this;
this.remote.transaction() $.remote.request_ledger_hash(function(err, r) {
.payment('root', 'alice', "10000.0") // console.log("result: %s", JSON.stringify(r));
.on('success', function (r) { assert(!err);
// console.log("create_account: %s", JSON.stringify(r));
got_success = true; var request = $.remote.request_ledger_entry('account_root')
}) .ledger_hash(r.ledger_hash)
.on('error', function (m) { .account_root("zHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
// console.log("error: %s", m);
buster.assert(false); request.callback(function(err, r) {
}) // console.log("account_root: %s", JSON.stringify(r));
.on('final', function (m) { assert(err);
// console.log("final: %s", JSON.stringify(m)); assert.strictEqual(err.error, 'remoteError');
buster.assert(got_success && got_proposed); assert.strictEqual(err.remote.error, 'malformedAddress');
done(); done();
}) });
.on('proposed', function() { })
got_proposed = true; });
self.remote.ledger_accept();
}) test('account_root entryNotFound', function(done) {
.on('submitted', function (m) { var self = this;
// console.log("proposed: %s", JSON.stringify(m));
// buster.assert.equals(m.result, 'terNO_DST_INSUF_XRP'); $.remote.request_ledger_hash(function(err, r) {
buster.assert.equals(m.engine_result, 'tesSUCCESS'); // console.log("result: %s", JSON.stringify(r));
}) assert(!err);
.submit();
}, var request = $.remote.request_ledger_entry('account_root')
.ledger_hash(r.ledger_hash)
.account_root("alice");
request.callback(function(err, r) {
// console.log("error: %s", m);
assert(err);
assert.strictEqual(err.error, 'remoteError');
assert.strictEqual(err.remote.error, 'entryNotFound');
done();
});
})
});
test('ledger_entry index', function(done) {
var self = this;
$.remote.request_ledger_hash(function(err, r) {
assert(!err);
var request = $.remote.request_ledger_entry('index')
.ledger_hash(r.ledger_hash)
.account_root("alice")
.index("2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8");
request.callback(function(err, r) {
assert(!err);
assert('node_binary' in r);
done();
});
})
});
test('create account', function(done) {
var self = this;
var root_id = $.remote.account('root')._account_id;
$.remote.request_subscribe().accounts(root_id).request();
$.remote.transaction()
.payment('root', 'alice', "10000.0")
.once('error', done)
.once('proposed', function(res) {
//console.log('Submitted', res);
$.remote.ledger_accept();
})
.once('success', function (r) {
//console.log("account_root: %s", JSON.stringify(r));
// Need to verify account and balance.
done();
})
.submit();
});
test('create account final', function(done) {
var self = this;
var got_proposed;
var got_success;
var root_id = $.remote.account('root')._account_id;
$.remote.request_subscribe().accounts(root_id).request();
var transaction = $.remote.transaction()
.payment('root', 'alice', "10000.0")
.once('error', done)
.once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m));
// buster.assert.equals(m.result, 'terNO_DST_INSUF_XRP');
assert.strictEqual(m.engine_result, 'tesSUCCESS');
})
.once('proposed', function() {
got_proposed = true;
$.remote.ledger_accept();
})
.once('success', function (r) {
// console.log("create_account: %s", JSON.stringify(r));
got_success = true;
})
.once('final', function (m) {
// console.log("final: %s", JSON.stringify(m));
assert(got_success);
assert(got_proposed);
done();
});
transaction.submit();
});
}); });
// vim:sw=2:sts=2:ts=8:et //vim:sw=2:sts=2:ts=8:et

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) { done();
var cfg = extend({}, config.default_server_config,
config.servers.alpha);
alpha = Server.from_config("alpha", cfg);
alpha
.on('started', function () {
alpha
.on('stopped', function () {
buster.assert(true);
done();
})
.stop();
}) })
.start(); alpha.stop();
} })
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);
}; };
@@ -98,20 +83,19 @@ Server.prototype._serverSpawnSync = function() {
var self = this; var self = this;
var args = [ var args = [
"-a", "-a",
"-v", "-v",
"--conf=rippled.cfg" "--conf=rippled.cfg"
]; ];
var options = {
cwd: this.serverPath(),
env: process.env,
stdio: this.quiet ? 'ignore' : 'inherit'
};
// Spawn in standalone mode for now. // Spawn in standalone mode for now.
this.child = child.spawn( this.child = child.spawn(this.config.rippled_path, args, options);
this.config.rippled_path,
args,
{
cwd: this.serverPath(),
env: process.env,
stdio: this.quiet ? 'ignore' : 'inherit'
});
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,13 +124,9 @@ 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; self._writeConfig(done);
} });
else {
self._writeConfig(done);
}
});
}; };
Server.prototype.verbose = function () { Server.prototype.verbose = function () {
@@ -169,14 +143,10 @@ Server.prototype.start = function () {
if (!this.quiet) console.log("server: start: %s: %s", this.name, JSON.stringify(this.config)); 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; self._serverSpawnSync();
} self.emit('started');
else { });
self._serverSpawnSync();
self.emit('started');
}
});
return this; return this;
}; };
@@ -187,24 +157,20 @@ Server.prototype.stop = function () {
self.stopping = true; self.stopping = true;
if (this.child) { if (!this.child) {
// Update the on exit to invoke done. console.log("server: stop: can't stop");
this.child.on('exit', function (code, signal) { return;
if (!self.quiet) console.log("server: stop: server exited");
self.emit('stopped');
delete self.child;
});
this.child.kill();
}
else
{
buster.log("server: stop: can't stop");
} }
// Update the on exit to invoke done.
this.child.on('exit', function (code, signal) {
if (!self.quiet) console.log("server: stop: server exited");
self.emit('stopped');
delete self.child;
});
this.child.kill();
return this; 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();
} }
]; ];
@@ -158,21 +165,22 @@ function build_teardown(host) {
var series = [ var series = [
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);
}, },
function stop_server(callback) { function stop_server(callback) {
if (opts.no_server) { if (opts.no_server) {
callback(); callback();
} else { } else {
data.server.once('stopped', callback) data.server.once('stopped', callback)
data.server.stop(); data.server.stop();
delete server[host];
}
} }
}
]; ];
async.series(series, done); async.series(series, done);
@@ -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);
}); });
@@ -220,9 +228,9 @@ function credit_limit(remote, src, amount, callback) {
} }
// console.log('credit_limit: parsed: %s', JSON.stringify(_m, undefined, 2)); // console.log('credit_limit: parsed: %s', JSON.stringify(_m, undefined, 2));
var account_limit = _m[1]; var account_limit = _m[1];
var quality_in = _m[2]; var quality_in = _m[2];
var quality_out = _m[3]; var quality_out = _m[3];
var tx = remote.transaction() var tx = remote.transaction()
@@ -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' : if (cfg.no_server) {
function (done) { done();
var cfg = extend({}, config.default_server_config, } else {
config.servers.alpha); server = Server.from_config("alpha", cfg);
if (cfg.no_server) { server.once('started', done)
server.start();
}
});
teardown(function(done) {
if (config.servers.alpha.no_server) {
done();
} else {
server.on('stopped', done);
server.stop();
}
});
test('WebSocket connect and disconnect', function() {
var alpha = Remote.from_config("alpha");
alpha.on('connected', function () {
alpha.on('disconnected', function () {
// CLOSED
done(); done();
} else { });
server = Server.from_config("alpha", cfg).on('started', done).start(); alpha.connect(false);
} })
},
'tearDown' : alpha.connect();
function (done) { });
if (config.servers.alpha.no_server) {
done();
} else {
server.on('stopped', done).stop();
}
},
"websocket connect and disconnect" :
function (done) {
var alpha = Remote.from_config("alpha");
alpha
.on('connected', function () {
// OPEN
buster.assert(true);
alpha
.on('disconnected', function () {
// CLOSED
buster.assert(true);
done();
})
.connect(false);
})
.connect();
},
}); });
// vim:sw=2:sts=2:ts=8:et // vim:sw=2:sts=2:ts=8:et