From 3964e4522eb112d8dd55af63c830b92528f34bfd Mon Sep 17 00:00:00 2001 From: Ewald Moitzi Date: Tue, 27 May 2014 12:27:28 +0200 Subject: [PATCH] [FIX] remote.getPendingTransactions sets _clientID now correctly - added testcase for it --- src/js/ripple/remote.js | 3 +- test/remote-test.js | 138 +++++++++++++++++++++++++++++++++------- 2 files changed, 115 insertions(+), 26 deletions(-) diff --git a/src/js/ripple/remote.js b/src/js/ripple/remote.js index ec4d5c46..adc88502 100644 --- a/src/js/ripple/remote.js +++ b/src/js/ripple/remote.js @@ -421,12 +421,11 @@ Remote.prototype.getPendingTransactions = function() { var transaction = self.transaction(); transaction.parseJson(tx.tx_json); - + transaction.clientID(tx.clientID); Object.keys(tx).forEach(function(prop) { switch (prop) { case 'secret': case 'submittedIDs': - case 'clientID': case 'submitIndex': transaction[prop] = tx[prop]; break; diff --git a/test/remote-test.js b/test/remote-test.js index c5ab85a1..84275182 100644 --- a/test/remote-test.js +++ b/test/remote-test.js @@ -5,37 +5,42 @@ var Remote = utils.load_module('remote').Remote; var Server = utils.load_module('server').Server; var Request = utils.load_module('request').Request; -var options, spy, mock, stub, remote, callback; +var options, spy, mock, stub, remote, callback, database, tx; describe('Remote', function () { + beforeEach(function () { + options = { + trace : true, + trusted: true, + local_signing: true, + servers: [ + { host: 's-west.ripple.com', port: 443, secure: true }, + { host: 's-east.ripple.com', port: 443, secure: true } + ], + + blobvault : 'https://blobvault.payward.com', + persistent_auth : false, + transactions_per_page: 50, + + bridge: { + out: { + // 'bitcoin': 'localhost:3000' + // 'bitcoin': 'https://www.bitstamp.net/ripple/bridge/out/bitcoin/' + } + }, + + }; + }) describe('initialing a remote with options', function () { - beforeEach(function () { - options = { - trace : true, - trusted: true, - local_signing: true, - servers: [ - { host: 's-west.ripple.com', port: 443, secure: true }, - { host: 's-east.ripple.com', port: 443, secure: true } - ], - - blobvault : 'https://blobvault.payward.com', - persistent_auth : false, - transactions_per_page: 50, - - bridge: { - out: { - // 'bitcoin': 'localhost:3000' - // 'bitcoin': 'https://www.bitstamp.net/ripple/bridge/out/bitcoin/' - } - }, - - }; - }) it('should add a server for each specified', function (done) { var remote = new Remote(options); done(); }) + + + + + }) describe('functions that return request objects', function () { @@ -100,4 +105,89 @@ describe('Remote', function () { }); }); }) + describe('create remote and get pending transactions', function() { + before(function() { + tx = [{ + tx_json: { + Account : "r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS", + Amount : { + currency : "LTC", + issuer : "r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS", + value : "9.985" + }, + Destination : "r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS", + Fee : "15", + Flags : 0, + Paths : [ + [ + { + account : "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + currency : "USD", + issuer : "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + type : 49, + type_hex : "0000000000000031" + }, + { + currency : "LTC", + issuer : "rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX", + type : 48, + type_hex : "0000000000000030" + }, + { + account : "rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX", + currency : "LTC", + issuer : "rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX", + type : 49, + type_hex : "0000000000000031" + } + ] + ], + SendMax : { + currency : "USD", + issuer : "r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS", + value : "30.30993068" + }, + Sequence : 415, + SigningPubKey : "02854B06CE8F3E65323F89260E9E19B33DA3E01B30EA4CA172612DE77973FAC58A", + TransactionType : "Payment", + TxnSignature : "304602210096C2F385530587DE573936CA51CB86B801A28F777C944E268212BE7341440B7F022100EBF0508A9145A56CDA7FAF314DF3BBE51C6EE450BA7E74D88516891A3608644E" + }, + clientID: '48631', + state: 'pending', + submitIndex: 1, + submittedIDs: ["304602210096C2F385530587DE573936CA51CB86B801A28F777C944E268212BE7341440B7F022100EBF0508A9145A56CDA7FAF314DF3BBE51C6EE450BA7E74D88516891A3608644E"], + secret: 'mysecret' + }]; + database = { + getPendingTransactions: function(callback) { + callback(null, tx); + } + } + }) + it.only('should set transaction members correct ', function(done) { + remote = new Remote(options); + remote.storage = database; + remote.transaction = function() { + return { + clientID: function(id) { + if (typeof id === 'string') { + this._clientID = id; + } + return this; + }, + submit: function() { + assert.deepEqual(this._clientID, tx[0].clientID); + assert.deepEqual(this.submittedIDs,[tx[0].tx_json.TxnSignature]); + assert.equal(this.submitIndex, tx[0].submitIndex); + assert.equal(this.secret, tx[0].secret); + done(); + + }, + parseJson: function(json) {} + } + } + remote.getPendingTransactions(); + + }) + }) })