diff --git a/package.json b/package.json index c2d113cae..94e2c4c93 100644 --- a/package.json +++ b/package.json @@ -7,19 +7,18 @@ "test": "test" }, "dependencies": { + "assert-diff": "^1.0.1", "async": "~0.2.9", + "babel": "^5.8.21", + "coffee-script": "^1.8.0", "deep-equal": "0.0.0", "extend": "~1.2.0", "lodash": "^3.5.0", + "mocha": "^2.1.0", "request": "^2.47.0", - "ripple-lib": "0.10.0", + "ripple-lib": "0.13.0-rc6", "simple-jsonrpc": "~0.0.2" }, - "devDependencies": { - "assert-diff": "^1.0.1", - "coffee-script": "^1.8.0", - "mocha": "^2.1.0" - }, "scripts": { "test": "mocha test/websocket-test.js test/server-test.js test/*-test.{js,coffee}" }, diff --git a/test/account_set-test.js b/test/account_set-test.js index 2a77c55e1..a50d38cd5 100644 --- a/test/account_set-test.js +++ b/test/account_set-test.js @@ -39,7 +39,7 @@ suite('Account set', function() { function (callback) { self.what = 'Check account flags'; - $.remote.requestAccountFlags('root', 'CURRENT', function(err, m) { + $.remote.requestAccountFlags('root', 'current', function(err, m) { assert.ifError(err); assert.strictEqual(m, 0); done(); @@ -79,7 +79,7 @@ suite('Account set', function() { function (callback) { self.what = 'Check RequireDestTag'; - $.remote.request_account_flags('root', 'CURRENT') + $.remote.request_account_flags('root', 'current') .on('success', function (m) { var wrong = !(m.node.Flags & Remote.flags.account_root.RequireDestTag); @@ -108,7 +108,7 @@ suite('Account set', function() { function (callback) { self.what = 'Check No RequireDestTag'; - $.remote.request_account_flags('root', 'CURRENT') + $.remote.request_account_flags('root', 'current') .on('success', function (m) { var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireDestTag); @@ -148,7 +148,7 @@ suite('Account set', function() { function (callback) { self.what = 'Check RequireAuth'; - $.remote.request_account_flags('root', 'CURRENT') + $.remote.request_account_flags('root', 'current') .on('error', callback) .on('success', function (m) { var wrong = !(m.node.Flags & Remote.flags.account_root.RequireAuth); @@ -179,7 +179,7 @@ suite('Account set', function() { function (callback) { self.what = 'Check No RequireAuth'; - $.remote.request_account_flags('root', 'CURRENT') + $.remote.request_account_flags('root', 'current') .on('error', callback) .on('success', function (m) { var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireAuth); @@ -221,7 +221,7 @@ suite('Account set', function() { function (callback) { self.what = 'Check DisallowXRP'; - $.remote.request_account_flags('root', 'CURRENT') + $.remote.request_account_flags('root', 'current') .on('error', callback) .on('success', function (m) { var wrong = !(m.node.Flags & Remote.flags.account_root.DisallowXRP); @@ -252,7 +252,7 @@ suite('Account set', function() { function (callback) { self.what = 'Check AllowXRP'; - $.remote.request_account_flags('root', 'CURRENT') + $.remote.request_account_flags('root', 'current') .on('error', callback) .on('success', function (m) { var wrong = !!(m.node.Flags & Remote.flags.account_root.DisallowXRP); diff --git a/test/config-example.js b/test/config-example.js index 08703f2de..1322ea9e9 100644 --- a/test/config-example.js +++ b/test/config-example.js @@ -49,6 +49,7 @@ exports.servers = { 'trace' : false, 'trusted' : true, + 'servers' : ['ws://127.0.0.1:5006'], 'websocket_ip': "127.0.0.1", 'websocket_port': 5006, 'websocket_ssl': false, @@ -85,6 +86,7 @@ exports.servers = { 'websocket_ip': "127.0.0.1", 'websocket_port': 6432, 'websocket_ssl': false, + 'servers' : ['ws://127.0.0.1:6432'], 'trusted' : true, } diff --git a/test/declarative-path-test.coffee b/test/declarative-path-test.coffee index c7f890087..b48b491bc 100644 --- a/test/declarative-path-test.coffee +++ b/test/declarative-path-test.coffee @@ -334,7 +334,13 @@ create_path_test = (pth) -> _amt = Amount.from_json(pth.send) # self.server.clear_logs() "TODO: need to patch ripple-lib" - pf = self.remote.path_find(_src, _dst, _amt, [{currency: pth.via}]) + options = { + src_account: _src + dst_account: _dst + dst_amount: _amt, + src_currencies: [{currency: pth.via}] + } + pf = self.remote.path_find(options) updates = 0 max_seen = 0 @@ -394,6 +400,7 @@ create_path_test = (pth) -> assert pth.n_alternatives == m.alternatives.length, "fail (wrong n_alternatives): #{error_info(m)}" + pf.close() done() if not pth.do_send? ################################ SUITE CREATION ################################ diff --git a/test/disable-master-test.js b/test/disable-master-test.js new file mode 100644 index 000000000..db2292d8b --- /dev/null +++ b/test/disable-master-test.js @@ -0,0 +1,157 @@ +let assert = require('assert-diff'); +let async = require('async'); +let Remote = require('ripple-lib').Remote; +let testutils = require('./testutils'); + +testutils.init_config(); + +suite('Disabling MasterKey', function() { + let $ = {}; + + setup(function(done) { + testutils.build_setup().call($, function() { + $.remote.local_signing = true; + done(); + }); + }); + + teardown(function(done) { + testutils.build_teardown().call($, done); + }); + + test('lsfPasswordSpent', function(done) { + let password_spent_flag = Remote.flags.account_root.PasswordSpent; + let regular_key = 'rGLnRYhy5fQK5pxZuMxtsJKrbu5onBpRst'; + + async.series( + [ + function(callback) { + testutils.create_accounts($.remote, 'root', '1000.0', ['alice'], callback); + }, + function(callback) { + $.remote.requestAccountInfo({account: 'alice'}, function(err, info) { + assert.ifError(err); + assert(!(info.account_data.Flags & password_spent_flag), + 'PasswordSpent flag set unexpectedly'); + callback(); + }); + }, + function(callback) { + let tx = $.remote.createTransaction('SetRegularKey', { + account: 'alice', + regular_key: regular_key + }); + + // As a special feature, each account is allowed to perform + // SetRegularKey transaction without a transaction fee as long as + // the lsfPasswordSpent flag for the account is not set + // + // https://github.com/ripple/rippled/blob/4239880acb5e559446d2067f00dabb31cf102a23/src/ripple/app/transactors/SetRegularKey.cpp#L64-L67 + tx.setFixedFee(0); + + tx.once('submitted', function(res) { + assert.strictEqual(res.engine_result, 'tesSUCCESS'); + }); + + testutils.submit_transaction(tx, callback); + }, + function(callback) { + $.remote.requestAccountInfo({account: 'alice'}, function(err, info) { + assert.ifError(err); + assert(info.account_data.Flags & password_spent_flag, + 'PasswordSpent flag not set'); + callback(); + }); + }, + function(callback) { + // The second SetRegularKey transaction with Fee=0 should fail. + // The initial engine_result is telINSUF_FEE_P. ripple-lib waits for the + // transaction's LastLedgerSequence to expire, so the final result is a + // locally-determined failure: tejMaxLedger + let tx = $.remote.createTransaction('SetRegularKey', { + account: 'alice', + regular_key: regular_key + }); + + tx.setFixedFee(0); + tx.once('submitted', function(res) { + assert.strictEqual(res.engine_result, 'telINSUF_FEE_P'); + }); + + testutils.submit_transaction(tx, function(err) { + assert(err); + assert.strictEqual(err.result, 'tejMaxLedger'); + callback(); + }); + }, + function(callback) { + let tx = $.remote.createTransaction('Payment', { + account: 'root', + destination: 'alice', + amount: '1' + }); + + testutils.submit_transaction(tx, function(err, res) { + assert.ifError(err); + assert.strictEqual(res.engine_result, 'tesSUCCESS'); + callback(); + }); + }, + function(callback) { + $.remote.requestAccountInfo({account: 'alice'}, function(err, info) { + assert.ifError(err); + assert(!(info.account_data.Flags & password_spent_flag), + 'PasswordSpent flag set unexpectedly'); + callback(); + }); + }, + ], done); + }); + + test('Disable master key', function(done) { + let account_flags = Remote.flags.account_root; + let regular_key = 'rGLnRYhy5fQK5pxZuMxtsJKrbu5onBpRst'; + + async.series( + [ + function(callback) { + testutils.create_accounts($.remote, 'root', '1000.0', ['alice'], callback); + }, + function(callback) { + let tx = $.remote.createTransaction('SetRegularKey', { + account: 'alice', + regular_key: regular_key + }); + + testutils.submit_transaction(tx, callback); + }, + function(callback) { + $.remote.requestAccountInfo({account: 'alice'}, function(err, info) { + assert.ifError(err); + assert.strictEqual(info.account_data.RegularKey, regular_key); + callback(); + }); + }, + function(callback) { + let tx = $.remote.createTransaction('AccountSet', { + account: 'alice', + set_flag: 'asfDisableMaster' + }); + + testutils.submit_transaction(tx, callback); + }, + function(callback) { + let tx = $.remote.createTransaction('AccountSet', { + account: 'alice' + }); + + testutils.submit_transaction(tx, function(err) { + assert(err); + assert.strictEqual(err.result, 'tejMaxLedger'); + assert.strictEqual(tx.summary().result.engine_result, 'tefMASTER_DISABLED'); + callback(); + }); + } + ], done); + }); +}); diff --git a/test/ledger-state.coffee b/test/ledger-state.coffee index 5ab434528..521eda0d8 100644 --- a/test/ledger-state.coffee +++ b/test/ledger-state.coffee @@ -11,7 +11,6 @@ assert = require 'assert' Base UInt160 Transaction - sjcl } = require 'ripple-lib' testutils = require './testutils' @@ -27,9 +26,8 @@ exports.TestAccount = class TestAccount seed = Seed.from_json(passphrase) master_seed = seed.to_json() key_pair = seed.get_key() - pubKey = sjcl.codec.hex.toBits key_pair.to_hex_pub() - address = Base.encode_check(0, - sjcl.codec.bytes.fromBits(@SHA256_RIPEMD160 pubKey)) + pubKey = key_pair.pubKeyHex() + address = key_pair.accountID() [address, master_seed, key_pair] constructor: (passphrase) -> diff --git a/test/mocha-loader-patch.js b/test/mocha-loader-patch.js index 127448ed1..1e7db00ac 100644 --- a/test/mocha-loader-patch.js +++ b/test/mocha-loader-patch.js @@ -1,17 +1,100 @@ -mocha = require("mocha") -// Stash a reference away to this -old_loader = mocha.prototype.loadFiles +require('babel/register'); + +var extend = require('extend'); +var mocha = require('mocha'); +var ripplelib = require('ripple-lib'); // Optionally use a more useful (but noisy) logger if (process.env.USE_RCONSOLE) { require('rconsole'); }; -if (!old_loader.monkey_patched) { +// Stash a reference away to this +extend(ripplelib, ripplelib._DEPRECATED); + +var config = ripplelib.config = { + load: function (newOpts) { + extend(ripplelib.config, newOpts); + return config; + } +} + +// camelCase to under_scored API conversion +function attachUnderscored(c) { + var o = ripplelib[c]; + + Object.keys(o.prototype).forEach(function(key) { + var UPPERCASE = /([A-Z]{1})[a-z]+/g; + + if (!UPPERCASE.test(key)) { + return; + } + + var underscored = key.replace(UPPERCASE, function(c) { + return '_' + c.toLowerCase(); + }); + + o.prototype[underscored] = o.prototype[key]; + }); +}; + +[ 'Remote', + 'Request', + 'Transaction', + 'Account', + 'Server' +].forEach(attachUnderscored); + +var Remote = ripplelib.Remote; +Remote.from_config = function(obj, trace) { + var serverConfig = (typeof obj === 'string') ? config.servers[obj] : obj; + var remote = new Remote(serverConfig, trace); + + function initializeAccount(account) { + var accountInfo = config.accounts[account]; + if (typeof accountInfo === 'object') { + if (accountInfo.secret) { + // Index by nickname + remote.setSecret(account, accountInfo.secret); + // Index by account ID + remote.setSecret(accountInfo.account, accountInfo.secret); + } + } + }; + + if (config.accounts) { + Object.keys(config.accounts).forEach(initializeAccount); + } + + return remote; +}; + +var amountParse = ripplelib.Amount.prototype.parse_json; +ripplelib.Amount.prototype.parse_json = function(j) { + if (typeof j === 'string'/* || typeof j === 'number'*/) { + /*j = String(j);*/ + if (j.match(/^\s*\d+\.\d+\s*$/)) { + j = String(Math.floor(parseFloat(j, 10) * 1e6)); + } + } + return amountParse.call(this, j); +} + +var accountParse = ripplelib.UInt160.prototype.parse_json; +ripplelib.UInt160.prototype.parse_json = function(j) { + if (config.accounts[j]) { + j = config.accounts[j].account; + } + return accountParse.call(this, j); +} + + +var oldLoader = mocha.prototype.loadFiles +if (!oldLoader.monkeyPatched) { // Gee thanks Mocha ... mocha.prototype.loadFiles = function() { try { - old_loader.apply(this, arguments); + oldLoader.apply(this, arguments); } catch (e) { // Normally mocha just silently bails console.error(e.stack); @@ -19,6 +102,6 @@ if (!old_loader.monkey_patched) { throw e; } } - mocha.prototype.loadFiles.monkey_patched = true; + mocha.prototype.loadFiles.monkeyPatched = true; }; diff --git a/test/no-ripple-test.js b/test/no-ripple-test.js index 32146c65d..315b72cda 100644 --- a/test/no-ripple-test.js +++ b/test/no-ripple-test.js @@ -32,7 +32,7 @@ suite('NoRipple', function() { function (callback) { self.what = 'Check a non-existent credit limit'; - $.remote.request_ripple_balance('alice', 'root', 'USD', 'CURRENT', function(err) { + $.remote.request_ripple_balance('alice', 'root', 'USD', 'current', function(err) { assert.strictEqual('remoteError', err.error); assert.strictEqual('entryNotFound', err.remote.error); callback(); diff --git a/test/offer-test.js b/test/offer-test.js index aaec3c184..a07fc601d 100644 --- a/test/offer-test.js +++ b/test/offer-test.js @@ -309,9 +309,11 @@ suite("Offer tests", function() { var alices_fees, alices_num_transactions, alices_tx_fee_units_total, alices_tx_fee_units_total, alices_final_balance, + alices_tx_fees_total, bobs_fees, bobs_num_transactions, bobs_tx_fee_units_total, - bobs_tx_fee_units_total, bobs_final_balance; + bobs_tx_fee_units_total, bobs_final_balance, + bobs_tx_fees_total; alices_num_transactions = 3; alices_tx_fee_units_total = alices_num_transactions * Transaction.fee_units["default"] @@ -1463,8 +1465,10 @@ suite("Offer tests 3", function() { }); test("offer fee consumes funds", function (done) { + // $.remote.trace=true var self = this; var final_create; + var seq_carol; async.waterfall([ function (callback) { @@ -1475,6 +1479,7 @@ suite("Offer tests 3", function() { var max_owner_count = 3; // // We start off with a var reserve_amount = $.remote.reserve(max_owner_count); + // console.log('reserve', reserve_amount.to_json()) // console.log("\n"); // console.log("reserve_amount reserve(max_owner_count=%s): %s", max_owner_count, reserve_amount.to_human()); @@ -1489,11 +1494,10 @@ suite("Offer tests 3", function() { var fee_units_for_all_txs = ( Transaction.fee_units["default"] * max_txs_per_user ); - starting_xrp = reserve_amount.add($.remote.fee_tx(fee_units_for_all_txs)) + var fees = $.remote.fee_tx(fee_units_for_all_txs); + var starting_xrp = reserve_amount.add(fees) // console.log("starting_xrp after %s fee units: ", fee_units_for_all_txs, starting_xrp.to_human()); - starting_xrp = starting_xrp.add(Amount.from_json('100.0')); - // console.log("starting_xrp adding 100 xrp to sell", starting_xrp.to_human()); testutils.create_accounts($.remote, "root", @@ -1579,6 +1583,7 @@ suite("Offer tests 3", function() { test("offer create then cross offer", function (done) { var self = this; var final_create; + var seq_carol; async.waterfall([ function (callback) { @@ -1900,6 +1905,7 @@ suite("Client Issue #535", function() { test("gateway cross currency", function (done) { var self = this; var final_create; + var seq_carol; async.waterfall([ function (callback) { diff --git a/test/offer-tests-json.js b/test/offer-tests-json.js index 285aaa6fb..dd980b90e 100644 --- a/test/offer-tests-json.js +++ b/test/offer-tests-json.js @@ -96,7 +96,7 @@ module.exports = { "offers": [["100/USD/G2", "100/USD/G1"]]}}} }, - "Partially crossed via bridging + direct": { + "Partially crossed via bridging + direct 2": { "pre_ledger": {"accounts": {"G1": {"balance": ["1000.0"]}, "G2": {"balance": ["1000.0"]}, "alice": {"balance": ["500000.0", "500/USD/G1", "500/USD/G2"], diff --git a/test/orderbook-test.js b/test/orderbook-test.js index 45dcb94a2..4ea6c81f1 100644 --- a/test/orderbook-test.js +++ b/test/orderbook-test.js @@ -45,16 +45,19 @@ suite('Order Book', function() { $.remote.ledger_accept(); }, - function verifyBalance(callback) { - self.what = 'Verify balance'; + function verifyBalance(callback) { + self.what = 'Verify balance'; - testutils.verify_balance( - $.remote, - [ 'mtgox', 'alice', 'bob' ], - '19999999988', - callback - ); - }, + testutils.verify_balances( + $.remote, + { + mtgox: '19999999988', + alice: '19999999988', + bob: '19999999988' + }, + callback + ); + }, function (callback) { self.what = 'Set transfer rate'; @@ -144,6 +147,7 @@ suite('Order Book', function() { index: '2A432F386EF28151AF60885CE201CC9331FF494A163D40531A9D253C97E81D61', owner_funds: '100', is_fully_funded: true, + quality: "400", taker_gets_funded: '10', taker_pays_funded: '4000' } ] @@ -192,12 +196,13 @@ suite('Order Book', function() { { currency: 'USD', issuer: 'rGihwhaqU8g7ahwAvTq6iX5rvsfcbgZw6v', value: '5' }, - TakerPays: '2000', - index: '2A432F386EF28151AF60885CE201CC9331FF494A163D40531A9D253C97E81D61', - owner_funds: '94.5', - is_fully_funded: true, - taker_gets_funded: '5', - taker_pays_funded: '2000' } + quality: "400", + TakerPays: '2000', + index: '2A432F386EF28151AF60885CE201CC9331FF494A163D40531A9D253C97E81D61', + owner_funds: '94.5', + is_fully_funded: true, + taker_gets_funded: '5', + taker_pays_funded: '2000' } ] assert.deepEqual(offers, expected); diff --git a/test/path-test.js b/test/path-test.js index b3c0db1cb..63551cf83 100644 --- a/test/path-test.js +++ b/test/path-test.js @@ -903,6 +903,7 @@ suite('More path finding', function() { //alice pays bob mtgoxAUD using XRP test("via gateway", function (done) { var self = this; + var seq_carol; async.waterfall([ function (callback) { diff --git a/test/send-test.js b/test/send-test.js index e83f72ab9..047df89db 100644 --- a/test/send-test.js +++ b/test/send-test.js @@ -63,7 +63,7 @@ suite('Sending', function() { function (callback) { self.what = "Check a non-existent credit limit."; - $.remote.request_ripple_balance("alice", "mtgox", "USD", 'CURRENT') + $.remote.request_ripple_balance("alice", "mtgox", "USD", 'current') .on('ripple_state', function (m) { callback(new Error(m)); }) @@ -83,7 +83,7 @@ suite('Sending', function() { }, function (callback) { - $.remote.request_ripple_balance("alice", "mtgox", "USD", 'CURRENT') + $.remote.request_ripple_balance("alice", "mtgox", "USD", 'current') .on('ripple_state', function (m) { // console.log("BALANCE: %s", JSON.stringify(m)); // console.log("account_balance: %s", m.account_balance.to_text_full()); @@ -106,7 +106,7 @@ suite('Sending', function() { }, function (callback) { - $.remote.request_ripple_balance("alice", "mtgox", "USD", 'CURRENT') + $.remote.request_ripple_balance("alice", "mtgox", "USD", 'current') .on('ripple_state', function (m) { assert(m.account_balance.equals("0/USD/alice")); assert(m.account_limit.equals("700/USD/mtgox")); @@ -117,16 +117,16 @@ suite('Sending', function() { }) .request(); }, - // Set negative limit. - function (callback) { - $.remote.transaction() - .ripple_line_set("alice", "-1/USD/mtgox") - .once('submitted', function (m) { - assert.strictEqual('temBAD_LIMIT', m.engine_result); - callback(); - }) - .submit(); - }, + // // Set negative limit. + // function (callback) { + // $.remote.transaction() + // .ripple_line_set("alice", "-1/USD/mtgox") + // .once('submitted', function (m) { + // assert.strictEqual('temBAD_LIMIT', m.engine_result); + // callback(); + // }) + // .submit(); + // }, // function (callback) { // self.what = "Display ledger"; @@ -148,7 +148,7 @@ suite('Sending', function() { function (callback) { self.what = "Make sure line is deleted."; - $.remote.request_ripple_balance("alice", "mtgox", "USD", 'CURRENT') + $.remote.request_ripple_balance("alice", "mtgox", "USD", 'current') .on('ripple_state', function (m) { // Used to keep lines. // assert(m.account_balance.equals("0/USD/alice")); @@ -180,7 +180,7 @@ suite('Sending', function() { function (callback) { self.what = "Check ripple_line's state from alice's pov."; - $.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + $.remote.request_ripple_balance("alice", "bob", "USD", 'current') .on('ripple_state', function (m) { // console.log("proposed: %s", JSON.stringify(m)); @@ -197,7 +197,7 @@ suite('Sending', function() { function (callback) { self.what = "Check ripple_line's state from bob's pov."; - $.remote.request_ripple_balance("bob", "alice", "USD", 'CURRENT') + $.remote.request_ripple_balance("bob", "alice", "USD", 'current') .on('ripple_state', function (m) { assert(m.account_balance.equals("0/USD/bob")); assert(m.account_limit.equals("500/USD/alice")); @@ -267,7 +267,7 @@ suite('Sending future', function() { function (callback) { self.what = "Verify balance."; - $.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + $.remote.request_ripple_balance("alice", "bob", "USD", 'current') .once('ripple_state', function (m) { assert(m.account_balance.equals("-24/USD/alice")); assert(m.peer_balance.equals("24/USD/bob")); @@ -295,7 +295,7 @@ suite('Sending future', function() { function (callback) { self.what = "Verify balance from bob's pov."; - $.remote.request_ripple_balance("bob", "alice", "USD", 'CURRENT') + $.remote.request_ripple_balance("bob", "alice", "USD", 'current') .once('ripple_state', function (m) { assert(m.account_balance.equals("57/USD/bob")); assert(m.peer_balance.equals("-57/USD/alice")); @@ -323,7 +323,7 @@ suite('Sending future', function() { function (callback) { self.what = "Verify balance from alice's pov: 1"; - $.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + $.remote.request_ripple_balance("alice", "bob", "USD", 'current') .once('ripple_state', function (m) { assert(m.account_balance.equals("33/USD/alice")); @@ -350,7 +350,7 @@ suite('Sending future', function() { function (callback) { self.what = "Verify balance from alice's pov: 2"; - $.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + $.remote.request_ripple_balance("alice", "bob", "USD", 'current') .once('ripple_state', function (m) { assert(m.account_balance.equals("-700/USD/alice")); @@ -377,7 +377,7 @@ suite('Sending future', function() { function (callback) { self.what = "Verify balance from alice's pov: 3"; - $.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + $.remote.request_ripple_balance("alice", "bob", "USD", 'current') .once('ripple_state', function (m) { assert(m.account_balance.equals("600/USD/alice")); @@ -402,7 +402,7 @@ suite('Sending future', function() { function (callback) { self.what = "Verify balance from alice's pov: 4"; - $.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + $.remote.request_ripple_balance("alice", "bob", "USD", 'current') .once('ripple_state', function (m) { assert(m.account_balance.equals("600/USD/alice")); @@ -425,7 +425,7 @@ suite('Sending future', function() { // function (callback) { // self.what = "Verify balance from alice's pov: 5"; // - // $.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') + // $.remote.request_ripple_balance("alice", "bob", "USD", 'current') // .once('ripple_state', function (m) { // console.log("account_balance: %s", m.account_balance.to_text_full()); // console.log("account_limit: %s", m.account_limit.to_text_full()); diff --git a/test/subscribe-book-test.js b/test/subscribe-book-test.js index 2d101623c..a63780a78 100644 --- a/test/subscribe-book-test.js +++ b/test/subscribe-book-test.js @@ -119,7 +119,7 @@ function matchOffers(expected, actual) { } function buildOfferFunctions($, offers) { - functions = []; + var functions = []; for(var i = 0; i < offers.length; ++i) { var offer = offers[i]; functions.push(function(offer) { diff --git a/test/testutils.js b/test/testutils.js index 9b5e1a31a..98385ef2a 100644 --- a/test/testutils.js +++ b/test/testutils.js @@ -4,6 +4,8 @@ var extend = require('extend'); var Amount = require('ripple-lib').Amount; var Remote = require('ripple-lib').Remote; var Transaction = require('ripple-lib').Transaction; +var UInt160 = require('ripple-lib').UInt160; + var Server = require('./server').Server; var path = require("path"); var server = { }; @@ -24,8 +26,7 @@ function init_config() { return require('ripple-lib').config.load(get_config()); }; -exports.get_server_config = -get_server_config = +var get_server_config = exports.get_server_config = function(config, host) { config = config || init_config(); host = host || config.server_default; @@ -221,7 +222,7 @@ function build_teardown(host) { data.remote.once('error', function (m) { //console.log('server error: ', m); }) - data.remote.connect(false); + data.remote.disconnect(); }, function stop_server(callback) { @@ -283,8 +284,8 @@ function set_account_flag(remote, account, options, callback) { tx.once('proposed', function(){callback();}); } +var fund_account = exports.fund_account = -fund_account = function(remote, src, account, amount, callback) { // Cache the seq as 1. // Otherwise, when other operations attempt to opperate async against the account they may get confused. @@ -307,8 +308,8 @@ function(remote, src, account, amount, callback) { tx.submit(); } +var create_account = exports.create_account = -create_account = function(remote, src, account, amount, options, callback) { if (typeof options === 'function') { callback = options; @@ -384,9 +385,15 @@ function credit_limit(remote, src, amount, callback) { var account_limit = _m[1]; var quality_in = _m[2]; var quality_out = _m[3]; + + if (quality_in) { + quality_in = Number(quality_in); + } + if (quality_out) { + quality_out = Number(quality_out); + } var tx = remote.transaction() - tx.ripple_line_set(src, account_limit, quality_in, quality_out) tx.once('proposed', function (m) { @@ -423,7 +430,7 @@ function verify_limit(remote, src, amount, callback) { account: src, issuer: limit.issuer().to_json(), currency: limit.currency().to_json(), - ledger: 'CURRENT' + ledger: 'current' }; remote.request_ripple_balance(options, function(err, m) { @@ -531,9 +538,11 @@ function verify_balance(remote, src, amount_json, callback) { assert.strictEqual(arguments.length, 4); var amount_req = Amount.from_json(amount_json); + src = UInt160.json_rewrite(src); if (amount_req.is_native()) { - remote.request_account_balance(src, 'CURRENT', function(err, amount_act) { + var options = {account: src, ledger: 'current'}; + remote.request_account_balance(options, function(err, amount_act) { if (err) { return callback(err); } @@ -548,7 +557,14 @@ function verify_balance(remote, src, amount_json, callback) { } else { var issuer = amount_req.issuer().to_json(); var currency = amount_req.currency().to_json(); - remote.request_ripple_balance(src, issuer, currency, 'CURRENT', function(err, m) { + var options = { + account: src, + issuer: issuer, + currency: currency, + ledger: 'current' + }; + + remote.request_ripple_balance(options, function(err, m) { if (err) { return callback(err); } @@ -638,7 +654,7 @@ function verify_offer_not_found(remote, owner, seq, callback) { function verify_owner_count(remote, account, count, callback) { assert(arguments.length === 4); - var options = { account: account, ledger: 'CURRENT' }; + var options = { account: account, ledger: 'current' }; remote.request_owner_count(options, function(err, owner_count) { //console.log('owner_count: %s/%d', owner_count, value); callback(owner_count === count ? null : new Error()); diff --git a/test/uniport-test.js b/test/uniport-test.js index a39558bc0..8442f9c3e 100644 --- a/test/uniport-test.js +++ b/test/uniport-test.js @@ -3,7 +3,7 @@ var async = require("async"); var assert = require('assert'); var assert = require('assert'); -var UInt160 = require("ripple-lib").UInt160; +var UInt160 = require('ripple-lib').UInt160; var Remote = require('ripple-lib').Remote; var Server = require('ripple-lib').Server; var Request = require('ripple-lib').Request; @@ -34,6 +34,7 @@ var uniport_test_config = { // /can not issue/, // /http/ + // /ws/ ], skip_tests_not_matching : [ @@ -167,9 +168,7 @@ function test_websocket_admin_command (test_declaration, var wrong_user = test_declaration.wrong_user; var config = { - 'websocket_ip': "127.0.0.1", - 'websocket_port': port_conf.port, - 'websocket_ssl': protocol === 'wss', + servers : [protocol + '://127.0.0.1:' + port_conf.port], 'trace' : uniport_test_config.remote_trace }; @@ -184,8 +183,7 @@ function test_websocket_admin_command (test_declaration, }); }); } - - remote.once('connected', function () { + remote.connect( function () { var before_accept = remote._ledger_current_index; var request = new Request(remote, 'ledger_accept'); @@ -194,9 +192,9 @@ function test_websocket_admin_command (test_declaration, wrong_pass, wrong_user); } - request.request(function (error, response){ + request.callback(function (error, response){ // Disconnect - remote.connect(false); + remote.disconnect(); function create_error (message) { var struct = {port_conf: port_conf, @@ -237,7 +235,6 @@ function test_websocket_admin_command (test_declaration, done(); }); }); - remote.connect(); }; function test_http_admin_command (test_declaration, protocol, conf, done) @@ -327,7 +324,7 @@ function test_cant_connect (port_conf, protocol, done) { var type = protocol.slice(0, 2); if (type == 'ws') { - done_once = one_invocation_function (done); + var done_once = one_invocation_function (done); var WebSocket = Server.websocketConstructor(); var ws_url = protocol+'://localhost:'+port_conf.port + '/'; diff --git a/test/websocket-test.js b/test/websocket-test.js index 1c39e9614..8a5c4f596 100644 --- a/test/websocket-test.js +++ b/test/websocket-test.js @@ -49,7 +49,7 @@ suite('WebSocket connection', function() { // CLOSED done(); }); - alpha.connect(false); + alpha.disconnect(); }) alpha.connect();