Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #222 from lumberj/test/orders_complex_currencies
Browse files Browse the repository at this point in the history
[TEST] Orders: Add tests for complex currencies (RLJS-119)
  • Loading branch information
geertweening committed Dec 3, 2014
2 parents 7bf22dd + 472c2f9 commit d36d345
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 11 deletions.
18 changes: 9 additions & 9 deletions test/fixtures/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports.order = function(options) {
taker_pays: '100/USD/' + addresses.ISSUER
});

return {
return {
secret: options.secret,
order: {
type: options.type,
Expand Down Expand Up @@ -129,9 +129,9 @@ module.exports.rippledSubmitErrorResponse = function(request, options) {
options = options || {};
_.defaults(options, DEFAULTS);

return JSON.stringify({
return JSON.stringify({
id: request.id,
result: {
result: {
engine_result: options.engine_result,
engine_result_code: options.engine_result_code,
engine_result_message: options.engine_result_message,
Expand All @@ -148,20 +148,20 @@ module.exports.rippledSubmitErrorResponse = function(request, options) {
"TransactionType": "OfferCreate",
"TxnSignature": "3045022100F6CAC4B1A57D7298112B970D4D2F93CCDADD897BBE20612D6D8210697360563202201B91F3B1FA184BDC1A4EDFBC47B43D22EE858F1A902D469031D641BFCEFA652F",
"hash": options.hash
}
}
},
status: 'success',
type: 'response'
type: 'response'
});
};

module.exports.rippledCancelErrorResponse = function(request, options) {
options = options || {};
_.defaults(options, DEFAULTS);

return JSON.stringify({
return JSON.stringify({
id: request.id,
result: {
result: {
engine_result: options.engine_result,
engine_result_code: options.engine_result_code,
engine_result_message: options.engine_result_message,
Expand All @@ -180,7 +180,7 @@ module.exports.rippledCancelErrorResponse = function(request, options) {
}
},
status: 'success',
type: 'response'
type: 'response'
});
};

Expand Down Expand Up @@ -472,4 +472,4 @@ module.exports.RESTCancelTransactionResponse = function(options) {
sequence: options.sequence + 1
}
});
};
};
102 changes: 100 additions & 2 deletions test/orders-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ var errors = require('./fixtures').errors;
var addresses = require('./fixtures').addresses;
var utils = require('./../lib/utils');

const HEX_CURRENCY = '0158415500000000C1F76FF6ECB0BAC600000000';
const ISSUER = 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
const VALUE = '0.00000001'

suite('post orders', function() {
var self = this;

Expand Down Expand Up @@ -49,6 +53,100 @@ suite('post orders', function() {
.end(done);
});

test('/orders -- with taker_gets hex currency', function(done) {
var lastLedger = self.app.remote._ledger_current_index;
var hash = testutils.generateHash();

var options = {
hash: hash,
last_ledger: lastLedger,
taker_gets: {
currency: HEX_CURRENCY,
issuer: ISSUER,
value: VALUE
}
};

self.wss.once('request_account_info', function(message, conn) {
assert.strictEqual(message.command, 'account_info');
assert.strictEqual(message.account, addresses.VALID);
conn.send(fixtures.accountInfoResponse(message));
});

self.wss.once('request_submit', function (message, conn) {
var so = new ripple.SerializedObject(message.tx_blob).to_json();
assert.strictEqual(so.TakerGets.value, VALUE);
assert.strictEqual(so.TakerGets.currency, HEX_CURRENCY);
assert.strictEqual(so.TakerGets.issuer, ISSUER);
assert.strictEqual(message.command, 'submit');

conn.send(fixtures.requestSubmitResponse(message, options));
});


self.app
.post('/v1/accounts/' + addresses.VALID + '/orders')
.send(fixtures.order({taker_gets: VALUE + '/' + HEX_CURRENCY + '/' + ISSUER}))
.expect(testutils.checkStatus(200))
.expect(testutils.checkHeaders)
.end(function(err, res) {
if (err) return done(err);

assert.strictEqual(res.body.order.taker_gets.currency, HEX_CURRENCY);
assert.strictEqual(res.body.order.taker_gets.value, VALUE);
assert.strictEqual(res.body.order.taker_gets.issuer, ISSUER);

done();
});
});


test('/orders -- with taker_pays hex currency', function(done) {
var lastLedger = self.app.remote._ledger_current_index;
var hash = testutils.generateHash();

var options = {
hash: hash,
last_ledger: lastLedger,
taker_pays: {
currency: HEX_CURRENCY,
issuer: ISSUER,
value: VALUE
}
};

self.wss.once('request_account_info', function(message, conn) {
assert.strictEqual(message.command, 'account_info');
assert.strictEqual(message.account, addresses.VALID);
conn.send(fixtures.accountInfoResponse(message));
});

self.wss.once('request_submit', function (message, conn) {
var so = new ripple.SerializedObject(message.tx_blob).to_json();
assert.strictEqual(so.TakerPays.value, VALUE);
assert.strictEqual(so.TakerPays.currency, HEX_CURRENCY);
assert.strictEqual(so.TakerPays.issuer, ISSUER);
assert.strictEqual(message.command, 'submit');

conn.send(fixtures.requestSubmitResponse(message, options));
});

self.app
.post('/v1/accounts/' + addresses.VALID + '/orders')
.send(fixtures.order({taker_pays: VALUE + '/' + HEX_CURRENCY + '/' + ISSUER}))
.expect(testutils.checkStatus(200))
.expect(testutils.checkHeaders)
.end(function(err, res) {
if (err) return done(err);

assert.strictEqual(res.body.order.taker_pays.currency, HEX_CURRENCY);
assert.strictEqual(res.body.order.taker_pays.value, VALUE);
assert.strictEqual(res.body.order.taker_pays.issuer, ISSUER);

done();
});
});

test('/orders -- with validated true and ledger sequence too high error', function(done) {
var hash = testutils.generateHash();

Expand Down Expand Up @@ -501,7 +599,7 @@ suite('post orders', function() {
});
});

suite('delete orders', function() {
suite('delete orders', function() {
var self = this;

setup(testutils.setup.bind(self));
Expand Down Expand Up @@ -886,4 +984,4 @@ suite('delete orders', function() {
})))
.end(done);
});
});
});

0 comments on commit d36d345

Please sign in to comment.