Update tests to support latest ripple-lib:

* Update ripple-lib api usage
* Use latest npm ripple-lib
  * Tested with bignumber.js branch and tip of develop
* Use new version of coffee-script
  * Better source maps
* Update mocha
* Add assert-diff for better error reporting
* Add rconsole, enabled via USE_RCONSOLE env var
  * For use with manual installation only
This commit is contained in:
Nicholas Dudfield
2015-01-17 12:40:11 +07:00
committed by Nik Bougalis
parent 44450bf644
commit 4dc2cf8a6b
9 changed files with 72 additions and 78 deletions

View File

@@ -2,33 +2,28 @@
"name": "rippled", "name": "rippled",
"version": "0.0.1", "version": "0.0.1",
"description": "Rippled Server", "description": "Rippled Server",
"private": true, "private": true,
"directories": { "directories": {
"test": "test" "test": "test"
}, },
"dependencies": { "dependencies": {
"ripple-lib": "0.8.2", "assert-diff": "0.0.4",
"async": "~0.2.9", "async": "~0.2.9",
"deep-equal": "0.0.0",
"extend": "~1.2.0", "extend": "~1.2.0",
"simple-jsonrpc": "~0.0.2", "ripple-lib": "0.10.0",
"deep-equal": "0.0.0" "simple-jsonrpc": "~0.0.2"
}, },
"devDependencies": { "devDependencies": {
"coffee-script": "~1.6.3", "coffee-script": "^1.8.0",
"mocha": "~1.13.0" "mocha": "^2.1.0"
}, },
"scripts": { "scripts": {
"test": "mocha test/websocket-test.js test/server-test.js test/*-test.{js,coffee}" "test": "mocha test/websocket-test.js test/server-test.js test/*-test.{js,coffee}"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/ripple/rippled.git" "url": "git://github.com/ripple/rippled.git"
}, },
"readmeFilename": "README.md" "readmeFilename": "README.md"
} }

View File

@@ -101,6 +101,9 @@ exports.submit_for_final = (tx, done) ->
accept so the transaction will finalize. accept so the transaction will finalize.
''' '''
tx.on 'proposed', -> tx.remote.ledger_accept() tx.on 'submitted', (m) ->
ter = (m.engine_result ? '').slice(0, 3)
if ter in ['tes', 'tec']
tx.remote.ledger_accept()
tx.on 'final', (m) -> done(m) tx.on 'final', (m) -> done(m)
tx.submit() tx.submit()

View File

@@ -188,7 +188,8 @@ config = testutils.init_config()
#################################### HELPERS ################################### #################################### HELPERS ###################################
get_lines = (remote, acc, done) -> get_lines = (remote, acc, done) ->
remote.request_account_lines acc, null, 'validated', (err, lines) -> args = {account: acc, ledger: 'validated'}
remote.request_account_lines args, (err, lines) ->
done(lines) done(lines)
account_set_factory = (remote, ledger, alias_for) -> account_set_factory = (remote, ledger, alias_for) ->

View File

@@ -357,12 +357,12 @@ exports.LedgerState = class LedgerState
incr_reserve_amt = @incr_reserve() incr_reserve_amt = @incr_reserve()
base_reserve = @parse_amount base_reserve_amt base_reserve = @parse_amount base_reserve_amt
inc_reserve = @parse_amount incr_reserve_amt incr_reserve = @parse_amount incr_reserve_amt
@assert base_reserve != null, @assert base_reserve != null,
"Base reserve amount #{base_reserve_amt} is invalid" "Base reserve amount #{base_reserve_amt} is invalid"
@assert base_reserve != null, @assert incr_reserve != null,
"incremental amount #{incr_reserve_amt} is invalid" "incremental amount #{incr_reserve_amt} is invalid"
for account_id, account of @declaration.accounts for account_id, account of @declaration.accounts
@@ -380,10 +380,10 @@ exports.LedgerState = class LedgerState
owner_count += Object.keys(@trusts_by_ci[account_id]).length owner_count += Object.keys(@trusts_by_ci[account_id]).length
owner_count_amount = Amount.from_json(String(owner_count)) owner_count_amount = Amount.from_json(String(owner_count))
inc_reserve_n = owner_count_amount.multiply(inc_reserve) inc_reserve_n = owner_count_amount.multiply(incr_reserve)
total_needed = total_needed.add(inc_reserve_n) total_needed = total_needed.add(inc_reserve_n)
@assert @accounts[account_id].compareTo total_needed != - 1, @assert @accounts[account_id].compareTo(total_needed) != - 1,
"Account #{account_id} needs more XRP for reserve" "Account #{account_id} needs more XRP for reserve"
@reserves[account_id] = total_needed @reserves[account_id] = total_needed
@@ -481,12 +481,6 @@ exports.LedgerState = class LedgerState
tx.offer_create(src, pays, gets) tx.offer_create(src, pays, gets)
tx.set_flags(flags) tx.set_flags(flags)
# console.log tx.tx_json
# process.exit()
# tx_json = make_tx_json(src, 'OfferCreate')
# tx_json.TakerPays = pays.to_json()
# tx_json.TakerGets = gets.to_json()
lines.push submit_line(src, tx.tx_json) lines.push submit_line(src, tx.tx_json)
ledger_accept() ledger_accept()

View File

@@ -2,6 +2,11 @@ mocha = require("mocha")
// Stash a reference away to this // Stash a reference away to this
old_loader = mocha.prototype.loadFiles old_loader = mocha.prototype.loadFiles
// Optionally use a more useful (but noisy) logger
if (process.env.USE_RCONSOLE) {
require('rconsole');
};
if (!old_loader.monkey_patched) { if (!old_loader.monkey_patched) {
// Gee thanks Mocha ... // Gee thanks Mocha ...
mocha.prototype.loadFiles = function() { mocha.prototype.loadFiles = function() {

View File

@@ -1,6 +1,6 @@
--require ./test/mocha-loader-patch.js --require ./test/mocha-loader-patch.js
--reporter spec --reporter spec
--compilers coffee:coffee-script --compilers coffee:coffee-script/register
--ui tdd --ui tdd
--timeout 10000 --timeout 10000
--slow 600 --slow 600

View File

@@ -1,5 +1,5 @@
var async = require('async'); var async = require('async');
var assert = require('assert'); var assert = require('assert-diff')({strict:true});
var Account = require('ripple-lib').UInt160; var Account = require('ripple-lib').UInt160;
var Remote = require('ripple-lib').Remote; var Remote = require('ripple-lib').Remote;
var Transaction = require('ripple-lib').Transaction; var Transaction = require('ripple-lib').Transaction;
@@ -132,8 +132,6 @@ suite('Order Book', function() {
Flags: 0, Flags: 0,
LedgerEntryType: 'Offer', LedgerEntryType: 'Offer',
OwnerNode: '0000000000000000', OwnerNode: '0000000000000000',
PreviousTxnID: offers[0].PreviousTxnID,
PreviousTxnLgrSeq: offers[0].PreviousTxnLgrSeq,
Sequence: 2, Sequence: 2,
TakerGets: { currency: 'USD', TakerGets: { currency: 'USD',
issuer: 'rGihwhaqU8g7ahwAvTq6iX5rvsfcbgZw6v', issuer: 'rGihwhaqU8g7ahwAvTq6iX5rvsfcbgZw6v',
@@ -142,11 +140,11 @@ suite('Order Book', function() {
TakerPays: '4000', TakerPays: '4000',
index: 'CD6AE78EE0A5438978501A0404D9093597F57B705D566B5070D58BD48F98468C', index: 'CD6AE78EE0A5438978501A0404D9093597F57B705D566B5070D58BD48F98468C',
owner_funds: '100', owner_funds: '100',
quality: '400',
is_fully_funded: true, is_fully_funded: true,
taker_gets_funded: '10', taker_gets_funded: '10',
taker_pays_funded: '4000' } taker_pays_funded: '4000' }
] ]
assert.deepEqual(offers, expected); assert.deepEqual(offers, expected);
callback(null, ob); callback(null, ob);
@@ -186,8 +184,6 @@ suite('Order Book', function() {
Flags: 0, Flags: 0,
LedgerEntryType: 'Offer', LedgerEntryType: 'Offer',
OwnerNode: '0000000000000000', OwnerNode: '0000000000000000',
PreviousTxnID: offers[0].PreviousTxnID,
PreviousTxnLgrSeq: offers[0].PreviousTxnLgrSeq,
Sequence: 2, Sequence: 2,
TakerGets: TakerGets:
{ currency: 'USD', { currency: 'USD',
@@ -196,7 +192,6 @@ suite('Order Book', function() {
TakerPays: '2000', TakerPays: '2000',
index: 'CD6AE78EE0A5438978501A0404D9093597F57B705D566B5070D58BD48F98468C', index: 'CD6AE78EE0A5438978501A0404D9093597F57B705D566B5070D58BD48F98468C',
owner_funds: '94.5', owner_funds: '94.5',
quality: '400',
is_fully_funded: true, is_fully_funded: true,
taker_gets_funded: '5', taker_gets_funded: '5',
taker_pays_funded: '2000' } taker_pays_funded: '2000' }

View File

@@ -72,10 +72,10 @@ make_suite('Robust transaction submission', function() {
tx.submit(); tx.submit();
//Invoke callback immediately //Invoke callback immediately
callback(); callback(null, tx);
}, },
function sendValidTransaction(callback) { function sendValidTransaction(previousTx, callback) {
self.what = 'Send normal transaction which should succeed'; self.what = 'Send normal transaction which should succeed';
var tx = $.remote.transaction().payment({ var tx = $.remote.transaction().payment({
@@ -99,7 +99,8 @@ make_suite('Robust transaction submission', function() {
}); });
tx.once('final', function() { tx.once('final', function() {
callback(); previousTx.once('final', function(){ callback(); });
testutils.ledger_wait($.remote, previousTx);
}); });
tx.submit(); tx.submit();
@@ -121,7 +122,7 @@ make_suite('Robust transaction submission', function() {
] ]
async.series(steps, function(err) { async.waterfall(steps, function(err) {
assert(!err, self.what + ': ' + err); assert(!err, self.what + ': ' + err);
assert(self.resubmitted, 'Transaction failed to resubmit'); assert(self.resubmitted, 'Transaction failed to resubmit');
done(); done();

View File

@@ -245,7 +245,7 @@ function(remote, src, account, amount, callback) {
// Before creating the account, check if it exists in the ledger. // Before creating the account, check if it exists in the ledger.
// If it does, regardless of the balance, fail the test, because // If it does, regardless of the balance, fail the test, because
// the ledger is not in the expected state. // the ledger is not in the expected state.
var info = remote.requestAccountInfo(account); var info = remote.requestAccountInfo({account: account});
info.once('success', function(result) { info.once('success', function(result) {
// The account exists. Fail by returning an error to callback. // The account exists. Fail by returning an error to callback.