fix fee / feeSat opts
This commit is contained in:
parent
765d3dd658
commit
740be93836
2 changed files with 42 additions and 32 deletions
|
|
@ -125,12 +125,22 @@ TxProposal._trim = function(o) {
|
||||||
TxProposal.fromObj = function(o, forceOpts) {
|
TxProposal.fromObj = function(o, forceOpts) {
|
||||||
preconditions.checkArgument(o.builderObj);
|
preconditions.checkArgument(o.builderObj);
|
||||||
delete o['builder'];
|
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 {
|
try {
|
||||||
// force opts is requested.
|
|
||||||
for (var k in forceOpts) {
|
|
||||||
o.builderObj.opts[k] = forceOpts[k];
|
|
||||||
}
|
|
||||||
o.builder = TransactionBuilder.fromObj(o.builderObj);
|
o.builder = TransactionBuilder.fromObj(o.builderObj);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error("Invalid or Incompatible Backup Detected.");
|
throw new Error("Invalid or Incompatible Backup Detected.");
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,7 @@ var TransactionBuilder = bitcore.TransactionBuilder;
|
||||||
var util = bitcore.util;
|
var util = bitcore.util;
|
||||||
var networks = bitcore.networks;
|
var networks = bitcore.networks;
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
var is_browser = typeof process == 'undefined'
|
var is_browser = typeof process == 'undefined' || typeof process.versions === 'undefined';
|
||||||
|| typeof process.versions === 'undefined';
|
|
||||||
if (is_browser) {
|
if (is_browser) {
|
||||||
var copay = require('copay'); //browser
|
var copay = require('copay'); //browser
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -112,18 +111,6 @@ describe('TxProposal', function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
describe('#fromObj', 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() {
|
it('should fail to create from wrong object', function() {
|
||||||
var b = new FakeBuilder();
|
var b = new FakeBuilder();
|
||||||
(function() {
|
(function() {
|
||||||
|
|
@ -135,8 +122,21 @@ describe('TxProposal', function() {
|
||||||
});
|
});
|
||||||
}).should.throw('Invalid or Incompatible Backup Detected');
|
}).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() {
|
(function() {
|
||||||
txp.setCopayers(
|
txp.setCopayers(
|
||||||
'creator', {
|
'creator', {
|
||||||
pk0: 'creator',
|
pk0: 'creator',
|
||||||
pk1: 'pepe',
|
pk1: 'pepe',
|
||||||
pk2: 'john'
|
pk2: 'john'
|
||||||
}, {
|
}, {
|
||||||
'creator2': 1
|
'creator2': 1
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}).should.throw('only 1');
|
}).should.throw('only 1');
|
||||||
})
|
})
|
||||||
|
|
@ -441,20 +441,20 @@ describe('TxProposal', function() {
|
||||||
});
|
});
|
||||||
it('should report isPending 1', function() {
|
it('should report isPending 1', function() {
|
||||||
var txp = dummyProposal;
|
var txp = dummyProposal;
|
||||||
txp.rejectedBy=[];
|
txp.rejectedBy = [];
|
||||||
txp.sentTxid=1;
|
txp.sentTxid = 1;
|
||||||
txp.isPending(3).should.equal(false);
|
txp.isPending(3).should.equal(false);
|
||||||
});
|
});
|
||||||
it('should report isPending 2', function() {
|
it('should report isPending 2', function() {
|
||||||
var txp = dummyProposal;
|
var txp = dummyProposal;
|
||||||
txp.rejectedBy=[];
|
txp.rejectedBy = [];
|
||||||
txp.sentTxid=null;
|
txp.sentTxid = null;
|
||||||
txp.isPending(3).should.equal(true);
|
txp.isPending(3).should.equal(true);
|
||||||
});
|
});
|
||||||
it('should report isPending 3', function() {
|
it('should report isPending 3', function() {
|
||||||
var txp = dummyProposal;
|
var txp = dummyProposal;
|
||||||
txp.rejectedBy=[1,2,3,4];
|
txp.rejectedBy = [1, 2, 3, 4];
|
||||||
txp.sentTxid=null;
|
txp.sentTxid = null;
|
||||||
txp.isPending(3).should.equal(false);
|
txp.isPending(3).should.equal(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue