Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ripple-lib integration tests #273

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},

"dependencies": {
"ripple-lib": "0.7.25",
"ripple-lib": "0.7.31",
"async": "~0.2.9",
"extend": "~1.2.0",
"simple-jsonrpc": "~0.0.2",
Expand Down
3 changes: 0 additions & 3 deletions test/mocha.opts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@
--ui tdd
--timeout 10000
--slow 600
test/websocket-test.js
test/server-test.js
test/*-test.{js,coffee}
314 changes: 314 additions & 0 deletions test/no-ripple-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
var async = require('async');
var assert = require('assert');
var ripple = require('ripple-lib');
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();

suite('NoRipple', function() {
var $ = { };

setup(function(done) {
testutils.build_setup().call($, done);
});

teardown(function(done) {
testutils.build_teardown().call($, done);
});

test('set and clear NoRipple', function(done) {
var self = this;

var steps = [

function (callback) {
self.what = 'Create accounts.';
testutils.create_accounts($.remote, 'root', '10000.0', [ 'alice' ], callback);
},

function (callback) {
self.what = 'Check a non-existent credit limit';

$.remote.request_ripple_balance('alice', 'root', 'USD', 'CURRENT', function(err) {
assert.strictEqual('remoteError', err.error);
assert.strictEqual('entryNotFound', err.remote.error);
callback();
});
},

function (callback) {
self.what = 'Create a credit limit with NoRipple flag';

var tx = $.remote.transaction();
tx.trustSet('root', '100/USD/alice');
tx.setFlags('NoRipple');

tx.once('error', callback);
tx.once('proposed', function(res) {
callback();
});

tx.submit();
},

function (callback) {
self.what = 'Check no-ripple sender';

$.remote.requestAccountLines('root', void(0), 'CURRENT', function(err, m) {
if (err) return callback(err);
assert(typeof m === 'object');
assert(Array.isArray(m.lines));
assert(m.lines[0].no_ripple);
callback();
});
},

function (callback) {
self.what = 'Check no-ripple destination';

$.remote.requestAccountLines('alice', void(0), 'CURRENT', function(err, m) {
if (err) return callback(err);
assert(typeof m === 'object');
assert(Array.isArray(m.lines));
assert(m.lines[0].no_ripple_peer);
callback();
});
},

function (callback) {
self.what = 'Create a credit limit with ClearNoRipple flag';

var tx = $.remote.transaction();
tx.trustSet('root', '100/USD/alice');
tx.setFlags('ClearNoRipple');

tx.once('error', callback);
tx.once('proposed', function(res) {
callback();
});

tx.submit();
},

function (callback) {
self.what = 'Check no-ripple cleared sender';

$.remote.requestAccountLines('root', void(0), 'CURRENT', function(err, m) {
if (err) return callback(err);
assert(typeof m === 'object');
assert(Array.isArray(m.lines));
assert(!m.lines[0].no_ripple);
callback();
});
},

function (callback) {
self.what = 'Check no-ripple cleared destination';

$.remote.requestAccountLines('alice', void(0), 'CURRENT', function(err, m) {
if (err) return callback(err);
assert(typeof m === 'object');
assert(Array.isArray(m.lines));
assert(!m.lines[0].no_ripple_peer);
callback();
});
}

]

async.series(steps, function(err) {
assert(!err, self.what + ': ' + err);
done();
});
});

test('set NoRipple on line with negative balance', function(done) {
// Setting NoRipple on a line with negative balance should fail
var self = this;

var steps = [

function (callback) {
self.what = 'Create accounts';

testutils.create_accounts(
$.remote,
'root',
'10000.0',
[ 'alice', 'bob', 'carol' ],
callback);
},

function (callback) {
self.what = 'Set credit limits';

testutils.credit_limits($.remote, {
bob: '100/USD/alice',
carol: '100/USD/bob'
}, callback);
},

function (callback) {
self.what = 'Payment';

var tx = $.remote.transaction();
tx.buildPath(true);
tx.payment('alice', 'carol', '50/USD/carol');

tx.once('submitted', function(m) {
assert.strictEqual(m.engine_result, 'tesSUCCESS');
});

tx.submit(callback);
},

function (callback) {
self.what = 'Set NoRipple alice';

var tx = $.remote.transaction();
tx.trustSet('alice', '100/USD/bob');
tx.setFlags('NoRipple');

tx.once('submitted', function(m) {
assert.strictEqual(m.engine_result, 'tesSUCCESS');
});

tx.submit(callback);
},

function (callback) {
self.what = 'Set NoRipple carol';

var tx = $.remote.transaction();
tx.trustSet('bob', '100/USD/carol');
tx.setFlags('NoRipple');

tx.once('submitted', function(m) {
assert.strictEqual(m.engine_result, 'tesSUCCESS');
});

tx.submit(callback);
},

function (callback) {
self.what = 'Find path alice > carol';

var request = $.remote.requestRipplePathFind('alice', 'carol', '1/USD/carol', [ { currency: 'USD' } ]);
request.callback(function(err, paths) {
assert.ifError(err);
assert(Array.isArray(paths.alternatives));
assert.strictEqual(paths.alternatives.length, 1);
callback();
});
},

function (callback) {
$.remote.requestAccountLines('alice', function(err, res) {
assert.ifError(err);
assert.strictEqual(typeof res, 'object');
assert(Array.isArray(res.lines));
assert.strictEqual(res.lines.length, 1);
assert(!(res.lines[0].no_ripple));
callback();
});
}

]

async.series(steps, function(error) {
assert(!error, self.what + ': ' + error);
done();
});
});

test('pairwise NoRipple', function(done) {
var self = this;

var steps = [

function (callback) {
self.what = 'Create accounts';

testutils.create_accounts(
$.remote,
'root',
'10000.0',
[ 'alice', 'bob', 'carol' ],
callback);
},

function (callback) {
self.what = 'Set credit limits';

testutils.credit_limits($.remote, {
bob: '100/USD/alice',
carol: '100/USD/bob'
}, callback);
},

function (callback) {
self.what = 'Set NoRipple alice';

var tx = $.remote.transaction();
tx.trustSet('bob', '100/USD/alice');
tx.setFlags('NoRipple');

tx.once('submitted', function(m) {
assert.strictEqual(m.engine_result, 'tesSUCCESS');
});

tx.submit(callback);
},

function (callback) {
self.what = 'Set NoRipple carol';

var tx = $.remote.transaction();
tx.trustSet('bob', '100/USD/carol');
tx.setFlags('NoRipple');

tx.once('submitted', function(m) {
assert.strictEqual(m.engine_result, 'tesSUCCESS');
});

tx.submit(callback);
},

function (callback) {
self.what = 'Find path alice > carol';

var request = $.remote.requestRipplePathFind('alice', 'carol', '1/USD/carol', [ { currency: 'USD' } ]);
request.callback(function(err, paths) {
assert.ifError(err);
assert(Array.isArray(paths.alternatives));
assert.strictEqual(paths.alternatives.length, 0);
callback();
});
},

function (callback) {
self.what = 'Payment';

var tx = $.remote.transaction();
tx.buildPath(true);
tx.payment('alice', 'carol', '1/USD/carol');

tx.once('submitted', function(m) {
assert.strictEqual(m.engine_result, 'tecPATH_DRY');
callback();
});

tx.submit();
}

]

async.series(steps, function(error) {
assert(!error, self.what + ': ' + error);
done();
});
});
});
Loading