Merge pull request #1345 from eordano/fix/revertBuilderDelete

Revert "Delete BuilderMockV0"
This commit is contained in:
Gustavo Maximiliano Cortez 2014-09-10 11:25:59 -03:00
commit 5ff16b9cc3
5 changed files with 48 additions and 11 deletions

View file

@ -0,0 +1,26 @@
'use strict';
var bitcore = require('bitcore');
var Transaction = bitcore.Transaction;
function BuilderMockV0 (data) {
this.vanilla = data;
this.tx = new Transaction();
this.tx.parse(new Buffer(data.tx, 'hex'));
};
BuilderMockV0.prototype.build = function() {
return this.tx;
};
BuilderMockV0.prototype.getSelectedUnspent = function() {
return [];
};
BuilderMockV0.prototype.toObj = function() {
return this.vanilla;
};
module.exports = BuilderMockV0;

View file

@ -4,6 +4,7 @@ var bitcore = require('bitcore');
var _ = require('underscore'); var _ = require('underscore');
var util = bitcore.util; var util = bitcore.util;
var Transaction = bitcore.Transaction; var Transaction = bitcore.Transaction;
var BuilderMockV0 = require('./BuilderMockV0');;
var TransactionBuilder = bitcore.TransactionBuilder; var TransactionBuilder = bitcore.TransactionBuilder;
var Script = bitcore.Script; var Script = bitcore.Script;
var Key = bitcore.Key; var Key = bitcore.Key;
@ -147,7 +148,12 @@ TxProposal.fromObj = function(o, forceOpts) {
try { try {
o.builder = TransactionBuilder.fromObj(o.builderObj); o.builder = TransactionBuilder.fromObj(o.builderObj);
} catch (e) { } catch (e) {
throw new Error("Invalid or Incompatible Backup Detected.");
// backwards (V0) compatatibility fix.
if (!o.version) {
o.builder = new BuilderMockV0(o.builderObj);
o.readonly = 1;
};
} }
return new TxProposal(o); return new TxProposal(o);
}; };

View file

@ -1,9 +1,11 @@
'use strict'; 'use strict';
var BuilderMockV0 = require('./BuilderMockV0');;
var bitcore = require('bitcore'); var bitcore = require('bitcore');
var util = bitcore.util; var util = bitcore.util;
var Transaction = bitcore.Transaction; var Transaction = bitcore.Transaction;
var TxProposal = require('./TxProposal'); var BuilderMockV0 = require('./BuilderMockV0');;
var TxProposal = require('./TxProposal');;
var Script = bitcore.Script; var Script = bitcore.Script;
var Key = bitcore.Key; var Key = bitcore.Key;
var buffertools = bitcore.buffertools; var buffertools = bitcore.buffertools;

View file

@ -120,7 +120,7 @@ describe('TxProposal', function() {
builderObj: b.toObj(), builderObj: b.toObj(),
inputChainPaths: ['m/1'], inputChainPaths: ['m/1'],
}); });
}).should.throw('Invalid or Incompatible Backup Detected'); }).should.throw('Invalid');
}); });
it('sets force opts', function() { it('sets force opts', function() {
var b = new FakeBuilder(); var b = new FakeBuilder();
@ -134,7 +134,7 @@ describe('TxProposal', function() {
}; };
(function() { (function() {
txp = TxProposal.fromObj(o,{pepe:100}); txp = TxProposal.fromObj(o,{pepe:100});
}).should.throw('Invalid or Incompatible Backup Detected'); }).should.throw('Invalid tx proposal: no ins');
o.builderObj.opts.should.deep.equal({juan:1, pepe:100, feeSat:undefined, fee:undefined}); o.builderObj.opts.should.deep.equal({juan:1, pepe:100, feeSat:undefined, fee:undefined});
}); });
}); });

View file

@ -432,13 +432,16 @@ describe('WalletFactory model', function() {
wf.network.start.getCall(0).args[0].privkey.length.should.equal(64); //privkey is hex of private key buffer wf.network.start.getCall(0).args[0].privkey.length.should.equal(64); //privkey is hex of private key buffer
}); });
}); });
describe('break backwards compatibility with older versions', function() { describe('dont break backwards compatibility of wallets', function() {
it('should\'nt be able to import unencrypted legacy wallet TxProposal: v0', function() { it('should be able to import unencrypted legacy wallet TxProposal: v0', function() {
var wf = new WalletFactory(config, '0.0.5');
var w = wf.fromObj(JSON.parse(legacyO));
(function() { should.exist(w);
var wf = new WalletFactory(config, '0.0.5'); w.id.should.equal('55d4bd062d32f90a');
var w = wf.fromObj(JSON.parse(legacyO)); should.exist(w.publicKeyRing.getCopayerId);
}).should.throw('Invalid or Incompatible Backup Detected'); should.exist(w.txProposals.toObj());
should.exist(w.privateKey.toObj());
}); });
it('should be able to import simple 1-of-1 encrypted legacy testnet wallet', function(done) { it('should be able to import simple 1-of-1 encrypted legacy testnet wallet', function(done) {