Update ripple-lib integration tests

This commit is contained in:
wltsmrz
2014-06-24 14:52:29 -07:00
committed by Nik Bougalis
parent 3d5ae42660
commit 0848e348bb
11 changed files with 1077 additions and 159 deletions

View File

@@ -32,30 +32,6 @@ function prepare_tests(tests, fn) {
return result;
};
function account_dump(remote, account, callback) {
var self = this;
this.what = 'Get latest account_root';
var request = remote.request_ledger_entry('account_root');
request.ledger_hash(remote.ledger_hash());
request.account_root('root');
request.callback(function(err, r) {
assert(!err, self.what);
if (err) {
//console.log('error: %s', m);
callback(err);
} else {
//console.log('account_root: %s', JSON.stringify(r, undefined, 2));
callback();
}
});
// get closed ledger hash
// get account root
// construct a json result
};
/**
* Helper called by test cases to generate a setUp routine.
*
@@ -110,7 +86,7 @@ function build_setup(opts, host) {
data.opts = opts;
var series = [
var steps = [
function run_server(callback) {
if (opts.no_server) {
return callback();
@@ -127,7 +103,11 @@ function build_setup(opts, host) {
data.server.once('exited', function () {
// If know the remote, tell it server is gone.
if (self.remote) {
self.remote.server_fatal();
try {
self.remote.setServerFatal();
} catch (e) {
self.remote.serverFatal();
}
}
});
@@ -137,14 +117,14 @@ function build_setup(opts, host) {
function connect_websocket(callback) {
self.remote = data.remote = Remote.from_config(host, !!opts.verbose_ws);
self.remote.once('ledger_closed', function(ledger) {
self.remote.once('ledger_closed', function() {
callback();
});
self.remote.connect();
}
];
async.series(series, done);
async.series(steps, done);
};
return setup;
@@ -155,6 +135,7 @@ function build_setup(opts, host) {
*
* @param host {String} Identifier for the host configuration to be used.
*/
function build_teardown(host) {
var config = get_config();
var host = host || config.server_default;
@@ -189,8 +170,32 @@ function build_teardown(host) {
return teardown;
};
function account_dump(remote, account, callback) {
var self = this;
this.what = 'Get latest account_root';
var request = remote.request_ledger_entry('account_root');
request.ledger_hash(remote.ledger_hash());
request.account_root('root');
request.callback(function(err, r) {
assert(!err, self.what);
if (err) {
//console.log('error: %s', m);
callback(err);
} else {
//console.log('account_root: %s', JSON.stringify(r, undefined, 2));
callback();
}
});
// get closed ledger hash
// get account root
// construct a json result
};
function create_accounts(remote, src, amount, accounts, callback) {
assert(arguments.length === 5);
assert.strictEqual(arguments.length, 5);
remote.set_account_seq(src, 1);
@@ -218,7 +223,7 @@ function create_accounts(remote, src, amount, accounts, callback) {
};
function credit_limit(remote, src, amount, callback) {
assert(arguments.length === 4);
assert.strictEqual(arguments.length, 4);
var _m = amount.match(/^(\d+\/...\/[^\:]+)(?::(\d+)(?:,(\d+))?)?$/);
@@ -250,7 +255,7 @@ function credit_limit(remote, src, amount, callback) {
};
function verify_limit(remote, src, amount, callback) {
assert(arguments.length === 4);
assert.strictEqual(arguments.length, 4);
var _m = amount.match(/^(\d+\/...\/[^\:]+)(?::(\d+)(?:,(\d+))?)?$/);
@@ -286,7 +291,7 @@ function verify_limit(remote, src, amount, callback) {
};
function credit_limits(remote, balances, callback) {
assert(arguments.length === 3);
assert.strictEqual(arguments.length, 3);
var limits = [ ];
@@ -303,7 +308,7 @@ function credit_limits(remote, balances, callback) {
credit_limit(remote, limit.source, limit.amount, callback);
}
async.some(limits, iterator, callback);
async.eachSeries(limits, iterator, callback);
};
function ledger_close(remote, callback) {
@@ -314,7 +319,7 @@ function ledger_close(remote, callback) {
};
function payment(remote, src, dst, amount, callback) {
assert(arguments.length === 5);
assert.strictEqual(arguments.length, 5);
var tx = remote.transaction();
@@ -333,7 +338,7 @@ function payment(remote, src, dst, amount, callback) {
};
function payments(remote, balances, callback) {
assert(arguments.length === 3);
assert.strictEqual(arguments.length, 3);
var sends = [ ];
@@ -351,7 +356,7 @@ function payments(remote, balances, callback) {
payment(remote, send.source, send.destination, send.amount, callback);
}
async.some(sends, iterator, callback);
async.eachSeries(sends, iterator, callback);
};
function transfer_rate(remote, src, billionths, callback) {
@@ -375,7 +380,7 @@ function transfer_rate(remote, src, billionths, callback) {
};
function verify_balance(remote, src, amount_json, callback) {
assert(arguments.length === 4);
assert.strictEqual(arguments.length, 4);
var amount_req = Amount.from_json(amount_json);
@@ -390,7 +395,7 @@ function verify_balance(remote, src, amount_json, callback) {
//amount_act.to_text_full(),
//amount_req.to_text_full());
}
callback(valid_balance ? null : new Error());
callback(valid_balance ? null : new Error('Balance invalid: ' + amount_json + ' / ' + amount_act.to_json()));
});
} else {
var issuer = amount_req.issuer().to_json();
@@ -405,7 +410,6 @@ function verify_balance(remote, src, amount_json, callback) {
// console.log('issuer_balance: %s', m.issuer_balance.to_text_full());
// console.log('issuer_limit: %s', m.issuer_limit.to_text_full());
var account_balance = Amount.from_json(m.account_balance);
var valid_balance = account_balance.equals(amount_req, true);
if (!valid_balance) {
@@ -416,7 +420,7 @@ function verify_balance(remote, src, amount_json, callback) {
//account_balance.not_equals_why(amount_req, true));
}
callback(valid_balance ? null : new Error());
callback(valid_balance ? null : new Error('Balance invalid: ' + amount_json + ' / ' + account_balance.to_json()));
})
}
};
@@ -442,7 +446,7 @@ function verify_balances(remote, balances, callback) {
// --> taker_gets: json amount
// --> taker_pays: json amount
function verify_offer(remote, owner, seq, taker_pays, taker_gets, callback) {
assert(arguments.length === 6);
assert.strictEqual(arguments.length, 6);
var request = remote.request_ledger_entry('offer')
request.offer_id(owner, seq)
@@ -460,7 +464,7 @@ function verify_offer(remote, owner, seq, taker_pays, taker_gets, callback) {
};
function verify_offer_not_found(remote, owner, seq, callback) {
assert(arguments.length === 4);
assert.strictEqual(arguments.length, 4);
var request = remote.request_ledger_entry('offer');
@@ -505,25 +509,37 @@ function verify_owner_counts(remote, counts, callback) {
async.every(tests, iterator, callback);
};
exports.account_dump = account_dump;
exports.build_setup = build_setup;
exports.build_teardown = build_teardown;
exports.create_accounts = create_accounts;
exports.credit_limit = credit_limit;
exports.credit_limits = credit_limits;
exports.get_config = get_config;
exports.init_config = init_config;
exports.ledger_close = ledger_close;
exports.payment = payment;
exports.payments = payments;
exports.transfer_rate = transfer_rate;
exports.verify_balance = verify_balance;
exports.verify_balances = verify_balances;
exports.verify_limit = verify_limit;
exports.verify_offer = verify_offer;
exports.verify_offer_not_found = verify_offer_not_found;
exports.verify_owner_count = verify_owner_count;
exports.verify_owner_counts = verify_owner_counts;
function ledger_wait(remote, tx) {
;(function nextLedger() {
remote.once('ledger_closed', function() {
if (!tx.finalized) {
setTimeout(nextLedger, 50);
}
});
remote.ledger_accept();
})();
};
exports.account_dump = account_dump;
exports.build_setup = build_setup;
exports.build_teardown = build_teardown;
exports.create_accounts = create_accounts;
exports.credit_limit = credit_limit;
exports.credit_limits = credit_limits;
exports.get_config = get_config;
exports.init_config = init_config;
exports.ledger_close = ledger_close;
exports.payment = payment;
exports.payments = payments;
exports.transfer_rate = transfer_rate;
exports.verify_balance = verify_balance;
exports.verify_balances = verify_balances;
exports.verify_limit = verify_limit;
exports.verify_offer = verify_offer;
exports.verify_offer_not_found = verify_offer_not_found;
exports.verify_owner_count = verify_owner_count;
exports.verify_owner_counts = verify_owner_counts;
exports.ledger_wait = ledger_wait;
process.on('uncaughtException', function() {
Object.keys(server).forEach(function(host) {