Skip to content

Commit

Permalink
[FEATURE] Add tests and support for ledger for requestBookOffers
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Cohen committed Dec 20, 2014
1 parent 3cb4a64 commit 34c0677
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/js/ripple/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -1476,10 +1476,12 @@ Remote.prototype.requestTxHistory = function(start, callback) {
/**
* Request book_offers
*
* @param {Object} gets
* @param {Object} pays
* @param {String} taker
* @param [Function] calback
* @param {Object} options - taker_options or can be an options object with the following properties
* @param {Object} options.gets - taker_options
* @param {Object} options.pays - taker_pays
* @param {String} [options.taker]
* @param {String} [options.ledger]
* @param [Function] callback
* @return {Request}
*/

Expand All @@ -1488,13 +1490,15 @@ Remote.prototype.requestBookOffers = function(gets, pays, taker, callback) {

if (gets.hasOwnProperty('gets') || gets.hasOwnProperty('taker_gets')) {
var options = gets;
var ledger;
// This would mutate the `lastArg` in `arguments` to be `null` and is
// redundant. Once upon a time, some awkward code was written f(g, null,
// null, cb) ...
callback = pays;
taker = options.taker;
pays = options.pays || options.taker_pays;
gets = options.gets || options.taker_gets;
ledger = options.ledger;
}

if (typeof lastArg === 'function') {
Expand All @@ -1521,8 +1525,9 @@ Remote.prototype.requestBookOffers = function(gets, pays, taker, callback) {

request.message.taker = taker ? taker : UInt160.ACCOUNT_ONE;

request.callback(callback);
request.ledgerSelect(ledger);

request.callback(callback);
return request;
};

Expand Down
39 changes: 39 additions & 0 deletions test/remote-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ var assert = require('assert');
var Remote = require('ripple-lib').Remote;
var Server = require('ripple-lib').Server;
var Request = require('ripple-lib').Request;
var UInt160 = require('ripple-lib').UInt160;
var Currency = require('ripple-lib').Currency;

var options, remote, callback, database, tx;

Expand Down Expand Up @@ -434,6 +436,43 @@ describe('Remote', function () {
assert(request.requested);
});

it('requestBookOffers, ledger', function() {
var callback = function() {};
var remote = new Remote({
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
});
var request = remote.requestBookOffers(
{
gets: {
currency: 'USD',
issuer: ADDRESS
},
pays: {
currency: 'XRP'
},
ledger: LEDGER_HASH
},
callback
);

assert.deepEqual(request.message, {
command: 'book_offers',
id: undefined,
taker_gets: {
currency: Currency.from_human('USD').to_hex(),
issuer: ADDRESS
},
taker_pays: {
currency: '0000000000000000000000000000000000000000'
},
taker: UInt160.ACCOUNT_ONE,
ledger_hash: LEDGER_HASH
});

assert(request.requested);
});


it('create remote and get pending transactions', function() {
before(function() {
tx = [{
Expand Down

0 comments on commit 34c0677

Please sign in to comment.