From 740be93836e502313df318e38159f9e484192de1 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 9 Sep 2014 10:43:13 -0300 Subject: [PATCH 1/2] fix fee / feeSat opts --- js/models/core/TxProposal.js | 18 +++++++++--- test/test.TxProposal.js | 56 ++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/js/models/core/TxProposal.js b/js/models/core/TxProposal.js index 9f2aa78e2..c3e65a812 100644 --- a/js/models/core/TxProposal.js +++ b/js/models/core/TxProposal.js @@ -125,12 +125,22 @@ TxProposal._trim = function(o) { TxProposal.fromObj = function(o, forceOpts) { preconditions.checkArgument(o.builderObj); delete o['builder']; + forceOpts = forceOpts || {}; + + + // force opts is requested. + for (var k in forceOpts) { + o.builderObj.opts[k] = forceOpts[k]; + } + // Handle undef options + if (_.isUndefined(forceOpts.fee) && _.isUndefined(forceOpts.feeSat)) { + if (o.builderObj.opts) { + o.builderObj.opts.fee = undefined; + o.builderObj.opts.feeSat = undefined; + } + } try { - // force opts is requested. - for (var k in forceOpts) { - o.builderObj.opts[k] = forceOpts[k]; - } o.builder = TransactionBuilder.fromObj(o.builderObj); } catch (e) { throw new Error("Invalid or Incompatible Backup Detected."); diff --git a/test/test.TxProposal.js b/test/test.TxProposal.js index 3e22e130c..1371e44f4 100644 --- a/test/test.TxProposal.js +++ b/test/test.TxProposal.js @@ -13,8 +13,7 @@ var TransactionBuilder = bitcore.TransactionBuilder; var util = bitcore.util; var networks = bitcore.networks; var sinon = require('sinon'); -var is_browser = typeof process == 'undefined' - || typeof process.versions === 'undefined'; +var is_browser = typeof process == 'undefined' || typeof process.versions === 'undefined'; if (is_browser) { var copay = require('copay'); //browser } else { @@ -112,18 +111,6 @@ describe('TxProposal', function() { }); describe('#fromObj', function() { - it.skip('should create from Object', function() { - var b = new FakeBuilder(); - var txp = TxProposal.fromObj({ - creator: 1, - createdTs: 1, - builderObj: b.toObj(), - inputChainPaths: ['m/1'], - }); - should.exist(txp); - }); - - it('should fail to create from wrong object', function() { var b = new FakeBuilder(); (function() { @@ -135,8 +122,21 @@ describe('TxProposal', function() { }); }).should.throw('Invalid or Incompatible Backup Detected'); }); - - + it('sets force opts', function() { + var b = new FakeBuilder(); + b.opts={juan:1, pepe:1, fee:1000}; + var txp; + var o = { + creator: 1, + createdTs: 1, + builderObj: b.toObj(), + inputChainPaths: ['m/1'], + }; + (function() { + txp = TxProposal.fromObj(o,{pepe:100}); + }).should.throw('Invalid or Incompatible Backup Detected'); + o.builderObj.opts.should.deep.equal({juan:1, pepe:100, feeSat:undefined, fee:undefined}); + }); }); @@ -398,12 +398,12 @@ describe('TxProposal', function() { (function() { txp.setCopayers( 'creator', { - pk0: 'creator', - pk1: 'pepe', - pk2: 'john' - }, { - 'creator2': 1 - } + pk0: 'creator', + pk1: 'pepe', + pk2: 'john' + }, { + 'creator2': 1 + } ); }).should.throw('only 1'); }) @@ -441,20 +441,20 @@ describe('TxProposal', function() { }); it('should report isPending 1', function() { var txp = dummyProposal; - txp.rejectedBy=[]; - txp.sentTxid=1; + txp.rejectedBy = []; + txp.sentTxid = 1; txp.isPending(3).should.equal(false); }); it('should report isPending 2', function() { var txp = dummyProposal; - txp.rejectedBy=[]; - txp.sentTxid=null; + txp.rejectedBy = []; + txp.sentTxid = null; txp.isPending(3).should.equal(true); }); it('should report isPending 3', function() { var txp = dummyProposal; - txp.rejectedBy=[1,2,3,4]; - txp.sentTxid=null; + txp.rejectedBy = [1, 2, 3, 4]; + txp.sentTxid = null; txp.isPending(3).should.equal(false); }); }); From 7bcf35f6d08227fcca11028d810ccaa579272f0a Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 9 Sep 2014 10:43:29 -0300 Subject: [PATCH 2/2] fix no fore opts --- js/models/core/TxProposal.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/js/models/core/TxProposal.js b/js/models/core/TxProposal.js index c3e65a812..cb5c4987b 100644 --- a/js/models/core/TxProposal.js +++ b/js/models/core/TxProposal.js @@ -128,6 +128,10 @@ TxProposal.fromObj = function(o, forceOpts) { forceOpts = forceOpts || {}; + if (forceOpts){ + o.builderObj.opts = o.builderObj.opts || {}; + } + // force opts is requested. for (var k in forceOpts) { o.builderObj.opts[k] = forceOpts[k];