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

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

View File

@@ -1,210 +1,395 @@
var async = require("async");
var buster = require("buster");
var Amount = require("ripple-lib").Amount;
var Remote = require("ripple-lib").Remote;
var Transaction = require("ripple-lib").Transaction;
var Server = require("./server").Server;
var testutils = require("./testutils");
var config = testutils.init_config();
buster.testRunner.timeout = 350000; //This is a very long test!
// Hard-coded limits we'll be testing:
var BINARY_LIMIT = 500;
var NONBINARY_LIMIT = 200;
var ACCOUNT = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh";
var FIRST_BATCH = 199; // Within both limits
var OFFSET = 180;
var LIMIT = 170;
var SECOND_BATCH = 10; // Between NONBINARY_LIMIT and BINARY_LIMIT
var THIRD_BATCH = 295; // Exceeds both limits
var VERBOSE = false;
buster.testCase("//Account_tx tests", {
'setUp' : testutils.build_setup(),
'tearDown' : testutils.build_teardown(),
"make a lot of transactions and query using account_tx" : function (done) {
var self = this;
var final_create;
var transactionCounter = 0;
var f = 0;
var functionHolder;
var createOfferFunction = function (callback) {
self.remote.transaction()
.offer_create("root", "500", "100/USD/root")
.on('proposed', function (m) {
transactionCounter++;
if (VERBOSE) console.log('Submitted transaction', transactionCounter);
callback(m.result !== 'tesSUCCESS');
})
.on('final', function (m) {
f++;
if (VERBOSE) console.log("Finalized transaction", f);
buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult);
buster.assert(final_create);
if ( f == transactionCounter ) {
if (VERBOSE) console.log("All transactions have been finalized.");
functionHolder();
}
})
.submit();
};
function lotsOfTransactions(number, whenDone) {
var bunchOfOffers = [];
for (var i=0; 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.
////var assert = require('assert');
////var async = require("async");
////var extend = require('extend');
////var Amount = require("ripple-lib").Amount;
////var Remote = require("ripple-lib").Remote;
////var Transaction = require("ripple-lib").Transaction;
////var RippleError = require("ripple-lib").RippleError;
////var Server = require("./server").Server;
////var testutils = require("./testutils");
////var config = testutils.init_config();
////
////// Hard-coded limits we'll be testing:
////var BINARY_LIMIT = 500;
////var NONBINARY_LIMIT = 200;
////
////var ACCOUNT = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh";
////var OFFSET = 180;
////var LIMIT = 170;
////
////var FIRST_BATCH = 199; // Within both limits
////var SECOND_BATCH = 10; // Between NONBINARY_LIMIT and BINARY_LIMIT
////var THIRD_BATCH = 295; // Exceeds both limits
////var VERBOSE = false;
////
////
////suite('Account_tx tests', function() {
//// var $ = { };
////
//// setup(function(done) {
//// testutils.build_setup().call($, done);
//// });
////
//// teardown(function(done) {
//// testutils.build_teardown().call($, done);
//// });
////
//// test('make many transactions and query using account_tx', function(done) {
//// var root_id = $.remote.account('root')._account_id;
//// $.remote.request_subscribe().accounts(root_id).request();
////
//// var self = this;
//// var transactionCounter = 0;
//// var final_create;
////
//// function createOffer(callback) {
//// var tx = $.remote.transaction();
//// tx.offer_create("root", "500", "100/USD/root");
////
//// tx.once('proposed', function(m) {
//// $.remote.ledger_accept();
//// });
////
//// tx.once('error', callback);
////
//// tx.once('final', function(m) {
//// callback();
//// });
////
//// tx.submit();
//// };
////
//// function lotsOfTransactions(count, callback) {
//// ;(function nextOffer(i) {
//// createOffer(function(err) {
//// console.log(i, count);
//// if (err) callback(err);
//// else if (++i === count) callback(null);
//// else nextOffer(i);
//// });
//// })(0);
//// };
////
//// function firstBatch() {
//// lotsOfTransactions(FIRST_BATCH, function(a, b) {
//// runTests(self, FIRST_BATCH, 0, void(0), function() {
//// console.log('2');
//// runTests(self, FIRST_BATCH, OFFSET, void(0), function() {
//// console.log('3');
//// runTests(self, FIRST_BATCH, -1, LIMIT, secondBatch);
//// })
//// })});
//// }
////
//// function secondBatch() {
//// lotsOfTransactions(SECOND_BATCH, function() {
//// runTests(self, FIRST_BATCH+SECOND_BATCH, 0, void(0), function() {
//// runTests(self, FIRST_BATCH+SECOND_BATCH, OFFSET, void(0), thirdBatch);
//// })});
//// }
////
//// function thirdBatch() {
//// lotsOfTransactions(THIRD_BATCH, function() {
//// runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, 0, void(0), function() {
//// runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, OFFSET, void(0), done);
//// })});
//// }
////
//// firstBatch();
////
//// function errorHandler(callback) {
//// return function(r) {
//// if (VERBOSE) console.log("ERROR!");
//// if (VERBOSE) console.log(r);
//// callback(r);
//// }
//// }
////
//// function txOptions(ext) {
//// var defaults = {
//// account: ACCOUNT,
//// ledger_index_min: -1,
//// ledger_index_max: -1
//// }
//// return extend(defaults, ext);
//// };
////
//// function sortByLedger(a, b) {
//// assert(a.tx, 'Transaction missing');
//// assert(b.tx, 'Transaction missing');
//// if (a.tx.inLedger > b.tx.inLedger) {
//// return 1;
//// } else if (a.tx.inLedger < b.tx.inLedger) {
//// return -1;
//// } else {
//// return 0;
//// }
//// };
////
//// function runTests(self, transactionCount, offset, limit, callback) {
//// var steps = [
//// function(callback) {
//// if (VERBOSE) console.log('nonbinary');
////
//// var req = $.remote.request_account_tx(txOptions({ offset: offset, limit: limit }));
////
//// req.callback(function(err, r) {
//// if (err) return callback(err);
//// assert(r && r.transactions);
//// var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit, transactionCount - offset) : transactionCount - offset);
//// assert.strictEqual(r.transactions.length, targetLength, 'Transactions unexpected length');
//// //assert.deepEqual(r.transactions.sort(sortByLedger), r.transactions, 'Transactions out of order');
//// callback();
//// });
//// },
////
//// function(callback) {
//// if (VERBOSE) console.log('binary');
////
//// var req = $.remote.request_account_tx(txOptions({ binary: true, offset: offset, limit: limit }));
////
//// req.callback(function(err, r) {
//// if (err) return callback(err);
//// assert(r && r.transactions);
//// var targetLength = Math.min(BINARY_LIMIT, limit ? Math.min(limit, transactionCount-offset) : transactionCount-offset);
//// assert.strictEqual(r.transactions.length, targetLength, 'Transactions unexpected length');
//// //assert.deepEqual(r.transactions.sort(sortByLedger), r.transactions, 'Transactions out of order');
//// callback();
//// });
//// },
////
//// function(callback) {
//// if (VERBOSE) console.log('nonbinary+offset');
////
//// var req = $.remote.request_account_tx(txOptions({ descending: true, offset: offset, limit: limit }));
////
//// req.callback(function(err, r) {
//// if (err) return callback(err);
//// assert(r && r.transactions);
//// var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit,transactionCount-offset) : transactionCount-offset );
//// assert.strictEqual(r.transactions.length, targetLength, 'Transactions unexpected length');
//// //assert.deepEqual(r.transactions.sort(sortByLedger), r.transactions, 'Transactions out of order');
//// callback();
//// });
//// }
//// ]
////
//// async.series(steps, function(error) {
//// console.log(error);
//// assert.ifError(error);
//// callback();
//// });
//// }
//// });
////});
//=======
//var async = require("async");
//var buster = require("buster");
//
//var Amount = require("ripple-lib").Amount;
//var Remote = require("ripple-lib").Remote;
//var Transaction = require("ripple-lib").Transaction;
//var Server = require("./server").Server;
//
//var testutils = require("./testutils");
//var config = testutils.init_config();
//
//buster.testRunner.timeout = 350000; //This is a very long test!
//
//
//// Hard-coded limits we'll be testing:
//var BINARY_LIMIT = 500;
//var NONBINARY_LIMIT = 200;
//
//var ACCOUNT = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh";
//var FIRST_BATCH = 199; // Within both limits
//var OFFSET = 180;
//var LIMIT = 170;
//var SECOND_BATCH = 10; // Between NONBINARY_LIMIT and BINARY_LIMIT
//var THIRD_BATCH = 295; // Exceeds both limits
//var VERBOSE = false;
//
//buster.testCase("//Account_tx tests", {
// 'setUp' : testutils.build_setup(),
// 'tearDown' : testutils.build_teardown(),
//
// "make a lot of transactions and query using account_tx" : function (done) {
// var self = this;
// var final_create;
// var transactionCounter = 0;
// var f = 0;
// var functionHolder;
// var createOfferFunction = function (callback) {
// self.remote.transaction()
// .offer_create("root", "500", "100/USD/root")
// .on('proposed', function (m) {
// transactionCounter++;
// if (VERBOSE) console.log('Submitted transaction', transactionCounter);
//
// callback(m.result !== 'tesSUCCESS');
// })
// .on('final', function (m) {
// f++;
// if (VERBOSE) console.log("Finalized transaction", f);
// buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult);
// buster.assert(final_create);
// if ( f == transactionCounter ) {
// if (VERBOSE) console.log("All transactions have been finalized.");
// functionHolder();
// }
// })
// .submit();
// };
//
// function lotsOfTransactions(number, whenDone) {
// var bunchOfOffers = [];
// for (var i=0; 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 buster = require("buster");
var http = require("http");
var jsonrpc = require("simple-jsonrpc");
var EventEmitter = require('events').EventEmitter;
var async = require("async");
var assert = require('assert');
var http = require("http");
var jsonrpc = require("simple-jsonrpc");
var EventEmitter = require('events').EventEmitter;
var Remote = require("ripple-lib").Remote;
var testutils = require("./testutils");
var config = testutils.init_config();
var Amount = require("ripple-lib").Amount;
var Remote = require("ripple-lib").Remote;
var Server = require("./server").Server;
var testutils = require("./testutils");
var config = testutils.init_config();
// How long to wait for server to start.
var serverDelay = 1500;
buster.testRunner.timeout = 5000;
var server;
var server_events;
var build_setup = function (options) {
function build_setup(options) {
var setup = testutils.build_setup(options);
return function (done) {
var self = this;
var self = this;
var http_config = config.http_servers["zed"];
var http_config = config.http_servers["zed"];
server_events = new EventEmitter;
server = http.createServer(function (req, res) {
// console.log("REQUEST");
var input = "";
self.server_events = new EventEmitter;
req.setEncoding();
self.server = http.createServer(function (req, res) {
// console.log("REQUEST");
var input = "";
req.on('data', function (buffer) {
// console.log("DATA: %s", buffer);
req.setEncoding('utf8');
input = input + buffer;
});
req.on('data', function (buffer) {
// console.log("DATA: %s", buffer);
input = input + buffer;
});
req.on('end', function () {
// console.log("END");
var request = JSON.parse(input);
req.on('end', function () {
var request = JSON.parse(input);
// console.log("REQ: %s", JSON.stringify(request, undefined, 2));
self.server_events.emit('request', request, res);
});
// console.log("REQ: %s", JSON.stringify(request, undefined, 2));
req.on('close', function () { });
});
server_events.emit('request', request, res);
});
req.on('close', function () {
// console.log("CLOSE");
});
});
server.listen(http_config.port, http_config.ip, undefined,
function () {
// console.log("server up: %s %d", http_config.ip, http_config.port);
setup.call(self, done);
});
};
self.server.listen(http_config.port, http_config.ip, void(0), function () {
// console.log("server up: %s %d", http_config.ip, http_config.port);
setup.call(self, done);
});
};
};
var build_teardown = function () {
function build_teardown() {
var teardown = testutils.build_teardown();
return function (done) {
var self = this;
server.close(function () {
// console.log("server closed");
teardown.call(self, done);
});
self.server.close(function () {
// console.log("server closed");
teardown.call(self, done);
});
};
};
buster.testCase("JSON-RPC", {
setUp : build_setup(),
// setUp : build_setup({ verbose: true }),
// setUp : build_setup({verbose: true , no_server: true}),
tearDown : build_teardown(),
suite('JSON-RPC', function() {
var $ = { };
"server_info" :
function (done) {
var rippled_config = config.servers.alpha;
var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port);
setup(function(done) {
build_setup().call($, done);
});
client.call('server_info', [], function (result) {
// console.log(JSON.stringify(result, undefined, 2));
buster.assert('info' in result);
teardown(function(done) {
build_teardown().call($, done);
});
done();
});
},
test('server info', function(done) {
var rippled_config = config.servers.alpha;
var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port);
"subscribe server" :
function (done) {
var rippled_config = config.servers.alpha;
var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port);
var http_config = config.http_servers["zed"];
client.call('server_info', [ ], function (result) {
// console.log(JSON.stringify(result, undefined, 2));
assert(typeof result === 'object');
assert('info' in result);
done();
});
});
client.call('subscribe', [{
test('subscribe server', function(done) {
var rippled_config = config.servers.alpha;
var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port);
var http_config = config.http_servers["zed"];
client.call('subscribe', [{
'url' : "http://" + http_config.ip + ":" + http_config.port,
'streams' : [ 'server' ],
}], function (result) {
// console.log(JSON.stringify(result, undefined, 2));
assert(typeof result === 'object');
assert('random' in result);
done();
});
});
test('subscribe ledger', function(done) {
var self = this;
var rippled_config = config.servers.alpha;
var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port);
var http_config = config.http_servers["zed"];
var steps = [
function (callback) {
self.what = "Subscribe.";
client.call('subscribe', [{
'url' : "http://" + http_config.ip + ":" + http_config.port,
'streams' : [ 'server' ],
'streams' : [ 'ledger' ],
}], function (result) {
// console.log(JSON.stringify(result, undefined, 2));
buster.assert('random' in result);
done();
//console.log(JSON.stringify(result, undefined, 2));
assert(typeof result === 'object');
assert('ledger_index' in result);
callback();
});
},
},
"subscribe ledger" :
function (done) {
var self = this;
function (callback) {
self.what = "Accept a ledger.";
var rippled_config = config.servers.alpha;
var client = jsonrpc.client("http://" + rippled_config.rpc_ip + ":" + rippled_config.rpc_port);
var http_config = config.http_servers["zed"];
$.server_events.once('request', function (request, response) {
// console.log("GOT: %s", JSON.stringify(request, undefined, 2));
async.waterfall([
function (callback) {
self.what = "Subscribe.";
assert.strictEqual(1, request.params.seq);
assert.strictEqual(3, request.params.ledger_index);
client.call('subscribe', [{
'url' : "http://" + http_config.ip + ":" + http_config.port,
'streams' : [ 'ledger' ],
}], function (result) {
//console.log(JSON.stringify(result, undefined, 2));
response.statusCode = 200;
response.end(JSON.stringify({
jsonrpc: "2.0",
result: {},
id: request.id
}));
buster.assert('ledger_index' in result);
callback();
});
},
function (callback) {
self.what = "Accept a ledger.";
server_events.once('request', function (request, response) {
// console.log("GOT: %s", JSON.stringify(request, undefined, 2));
buster.assert.equals(1, request.params.seq);
buster.assert.equals(3, request.params.ledger_index);
response.statusCode = 200;
response.end(JSON.stringify({
jsonrpc: "2.0",
result: {},
id: request.id
}));
callback();
});
self.remote.ledger_accept();
},
function (callback) {
self.what = "Accept another ledger.";
server_events.once('request', function (request, response) {
// console.log("GOT: %s", JSON.stringify(request, undefined, 2));
buster.assert.equals(2, request.params.seq);
buster.assert.equals(4, request.params.ledger_index);
response.statusCode = 200;
response.end(JSON.stringify({
jsonrpc: "2.0",
result: {},
id: request.id
}));
callback();
});
self.remote.ledger_accept();
},
], function (error) {
buster.refute(error, self.what);
done();
callback();
});
}
$.remote.ledger_accept();
},
function (callback) {
self.what = "Accept another ledger.";
$.server_events.once('request', function (request, response) {
// console.log("GOT: %s", JSON.stringify(request, undefined, 2));
assert.strictEqual(2, request.params.seq);
assert.strictEqual(4, request.params.ledger_index);
response.statusCode = 200;
response.end(JSON.stringify({
jsonrpc: "2.0",
result: {},
id: request.id
}));
callback();
});
$.remote.ledger_accept();
}
]
async.waterfall(steps, function(error) {
assert(!error, self.what);
done();
});
});
});

View File

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

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

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

View File

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

View File

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

View File

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