mirror of https://github.com/BTCPrivate/copay.git
test in Txproposals working again
This commit is contained in:
parent
42c73f9a01
commit
5d2b50f77f
2
copay.js
2
copay.js
|
@ -1,7 +1,7 @@
|
||||||
// core
|
// core
|
||||||
module.exports.PublicKeyRing = require('./js/models/core/PublicKeyRing');
|
module.exports.PublicKeyRing = require('./js/models/core/PublicKeyRing');
|
||||||
module.exports.TxProposal = require('./js/models/core/TxProposal');
|
module.exports.TxProposal = require('./js/models/core/TxProposal');
|
||||||
module.exports.TxProposalsSet = require('./js/models/core/TxProposalsSet');
|
module.exports.TxProposals = require('./js/models/core/TxProposals');
|
||||||
module.exports.PrivateKey = require('./js/models/core/PrivateKey');
|
module.exports.PrivateKey = require('./js/models/core/PrivateKey');
|
||||||
module.exports.Passphrase = require('./js/models/core/Passphrase');
|
module.exports.Passphrase = require('./js/models/core/Passphrase');
|
||||||
module.exports.HDPath = require('./js/models/core/HDPath');
|
module.exports.HDPath = require('./js/models/core/HDPath');
|
||||||
|
|
|
@ -13,10 +13,10 @@ var preconditions = require('preconditions').instance();
|
||||||
|
|
||||||
function TxProposal(opts) {
|
function TxProposal(opts) {
|
||||||
preconditions.checkArgument(opts);
|
preconditions.checkArgument(opts);
|
||||||
preconditions.checkArgument(opts.inputChainPaths);
|
preconditions.checkArgument(opts.inputChainPaths,'no inputChainPaths');
|
||||||
preconditions.checkArgument(opts.creator);
|
preconditions.checkArgument(opts.creator,'no creator');
|
||||||
preconditions.checkArgument(opts.createdTs);
|
preconditions.checkArgument(opts.createdTs,'no createdTs');
|
||||||
preconditions.checkArgument(opts.builder);
|
preconditions.checkArgument(opts.builder,'no builder');
|
||||||
|
|
||||||
|
|
||||||
this.creator = opts.creator;
|
this.creator = opts.creator;
|
||||||
|
@ -53,9 +53,14 @@ TxProposal.prototype.setSent = function(sentTxid) {
|
||||||
};
|
};
|
||||||
|
|
||||||
TxProposal.fromObj = function(o, forceOpts) {
|
TxProposal.fromObj = function(o, forceOpts) {
|
||||||
|
|
||||||
|
console.log('[TxProposal.js.56]'); //TODO
|
||||||
preconditions.checkArgument(o.builderObj);
|
preconditions.checkArgument(o.builderObj);
|
||||||
|
|
||||||
|
console.log('[TxProposal.js.59]'); //TODO
|
||||||
delete o['builder'];
|
delete o['builder'];
|
||||||
|
|
||||||
|
console.log('[TxProposal.js.62]'); //TODO
|
||||||
try {
|
try {
|
||||||
// force opts is requested.
|
// force opts is requested.
|
||||||
for (var k in forceOpts) {
|
for (var k in forceOpts) {
|
||||||
|
@ -63,14 +68,20 @@ TxProposal.fromObj = function(o, forceOpts) {
|
||||||
}
|
}
|
||||||
o.builder = TransactionBuilder.fromObj(o.builderObj);
|
o.builder = TransactionBuilder.fromObj(o.builderObj);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
|
console.log('[TxProposal.js.71]'); //TODO
|
||||||
if (!o.version) {
|
if (!o.version) {
|
||||||
o.builder = new BuilderMockV0(o.builderObj);
|
o.builder = new BuilderMockV0(o.builderObj);
|
||||||
o.readonly = 1;
|
o.readonly = 1;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('[TxProposal.js.78]', o); //TODO
|
||||||
var t = new TxProposal(o);
|
var t = new TxProposal(o);
|
||||||
t._check();
|
t._check();
|
||||||
t._updateSignedBy();
|
t._updateSignedBy();
|
||||||
|
|
||||||
|
console.log('[TxProposal.js.78]'); //TODO
|
||||||
return t;
|
return t;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -114,13 +125,14 @@ TxProposal._verifySignatures = function(inKeys, scriptSig, txSigHash) {
|
||||||
};
|
};
|
||||||
|
|
||||||
TxProposal._infoFromRedeemScript = function(s) {
|
TxProposal._infoFromRedeemScript = function(s) {
|
||||||
|
console.log('[TxProposal.js.127]',s.getBuffer().toString('hex')); //TODO
|
||||||
var redeemScript = new Script(s.chunks[s.chunks.length - 1]);
|
var redeemScript = new Script(s.chunks[s.chunks.length - 1]);
|
||||||
if (!redeemScript)
|
if (!redeemScript)
|
||||||
throw new Error('Bad scriptSig');
|
throw new Error('Bad scriptSig (no redeemscript)');
|
||||||
|
|
||||||
var pubkeys = redeemScript.capture();
|
var pubkeys = redeemScript.capture();
|
||||||
if (!pubkeys || !pubkeys.length)
|
if (!pubkeys || !pubkeys.length)
|
||||||
throw new Error('Bad scriptSig');
|
throw new Error('Bad scriptSig (no pubkeys)');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
keys: pubkeys,
|
keys: pubkeys,
|
||||||
|
|
|
@ -12,7 +12,7 @@ var buffertools = bitcore.buffertools;
|
||||||
var preconditions = require('preconditions').instance();
|
var preconditions = require('preconditions').instance();
|
||||||
|
|
||||||
|
|
||||||
function TxProposalsSet(opts) {
|
function TxProposals(opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
this.walletId = opts.walletId;
|
this.walletId = opts.walletId;
|
||||||
this.network = opts.networkName === 'livenet' ?
|
this.network = opts.networkName === 'livenet' ?
|
||||||
|
@ -20,8 +20,8 @@ function TxProposalsSet(opts) {
|
||||||
this.txps = {};
|
this.txps = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
TxProposalsSet.fromObj = function(o, forceOpts) {
|
TxProposals.fromObj = function(o, forceOpts) {
|
||||||
var ret = new TxProposalsSet({
|
var ret = new TxProposals({
|
||||||
networkName: o.networkName,
|
networkName: o.networkName,
|
||||||
walletId: o.walletId,
|
walletId: o.walletId,
|
||||||
});
|
});
|
||||||
|
@ -36,11 +36,11 @@ TxProposalsSet.fromObj = function(o, forceOpts) {
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
TxProposalsSet.prototype.getNtxids = function() {
|
TxProposals.prototype.getNtxids = function() {
|
||||||
return Object.keys(this.txps);
|
return Object.keys(this.txps);
|
||||||
};
|
};
|
||||||
|
|
||||||
TxProposalsSet.prototype.toObj = function() {
|
TxProposals.prototype.toObj = function() {
|
||||||
var ret = [];
|
var ret = [];
|
||||||
for (var id in this.txps) {
|
for (var id in this.txps) {
|
||||||
var t = this.txps[id];
|
var t = this.txps[id];
|
||||||
|
@ -55,15 +55,7 @@ TxProposalsSet.prototype.toObj = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TxProposalsSet.prototype.mergeFromObj = function(txProposalObj, allowedPubKeys, opts) {
|
TxProposals.prototype.merge = function(inTxp, allowedPubKeys) {
|
||||||
var inTxp = TxProposal.fromObj(txProposalObj, opts);
|
|
||||||
var mergeInfo = this.txProposals.merge(inTxp, allowedPubKeys);
|
|
||||||
mergeInfo.inTxp = inTxp;
|
|
||||||
return mergeInfo;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
TxProposalsSet.prototype.merge = function(inTxp, allowedPubKeys) {
|
|
||||||
var myTxps = this.txps;
|
var myTxps = this.txps;
|
||||||
|
|
||||||
var ntxid = inTxp.getId();
|
var ntxid = inTxp.getId();
|
||||||
|
@ -75,7 +67,8 @@ TxProposalsSet.prototype.merge = function(inTxp, allowedPubKeys) {
|
||||||
var v0 = myTxps[ntxid];
|
var v0 = myTxps[ntxid];
|
||||||
var v1 = inTxp;
|
var v1 = inTxp;
|
||||||
ret = v0.merge(v1, allowedPubKeys);
|
ret = v0.merge(v1, allowedPubKeys);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this.txps[ntxid] = inTxp;
|
this.txps[ntxid] = inTxp;
|
||||||
ret.hasChanged = true;
|
ret.hasChanged = true;
|
||||||
ret.events.push({
|
ret.events.push({
|
||||||
|
@ -87,21 +80,31 @@ TxProposalsSet.prototype.merge = function(inTxp, allowedPubKeys) {
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TxProposals.prototype.mergeFromObj = function(txProposalObj, allowedPubKeys, opts) {
|
||||||
|
var inTxp = TxProposal.fromObj(txProposalObj, opts);
|
||||||
|
var mergeInfo = this.merge(inTxp, allowedPubKeys);
|
||||||
|
mergeInfo.inTxp = inTxp;
|
||||||
|
return mergeInfo;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Add a LOCALLY CREATED (trusted) tx proposal
|
// Add a LOCALLY CREATED (trusted) tx proposal
|
||||||
TxProposalsSet.prototype.add = function(data) {
|
TxProposals.prototype.add = function(data) {
|
||||||
var txp = new TxProposal(data);
|
var txp = new TxProposal(data);
|
||||||
var ntxid = txp.getId();
|
var ntxid = txp.getId();
|
||||||
this.txps[ntxid] = txp;
|
this.txps[ntxid] = txp;
|
||||||
return ntxid;
|
return ntxid;
|
||||||
};
|
};
|
||||||
|
|
||||||
TxProposalsSet.prototype.setSent = function(ntxid, txid) {
|
TxProposals.prototype.setSent = function(ntxid, txid) {
|
||||||
//sent TxProposalsSet are local an not broadcasted.
|
//sent TxProposals are local an not broadcasted.
|
||||||
this.txps[ntxid].setSent(txid);
|
this.txps[ntxid].setSent(txid);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TxProposalsSet.prototype.getTxProposal = function(ntxid, copayers) {
|
TxProposals.prototype.getTxProposal = function(ntxid, copayers) {
|
||||||
var txp = this.txps[ntxid];
|
var txp = this.txps[ntxid];
|
||||||
var i = JSON.parse(JSON.stringify(txp));
|
var i = JSON.parse(JSON.stringify(txp));
|
||||||
i.builder = txp.builder;
|
i.builder = txp.builder;
|
||||||
|
@ -139,7 +142,7 @@ TxProposalsSet.prototype.getTxProposal = function(ntxid, copayers) {
|
||||||
};
|
};
|
||||||
|
|
||||||
//returns the unspent txid-vout used in PENDING Txs
|
//returns the unspent txid-vout used in PENDING Txs
|
||||||
TxProposalsSet.prototype.getUsedUnspent = function(maxRejectCount) {
|
TxProposals.prototype.getUsedUnspent = function(maxRejectCount) {
|
||||||
var ret = {};
|
var ret = {};
|
||||||
for (var i in this.txps) {
|
for (var i in this.txps) {
|
||||||
var u = this.txps[i].builder.getSelectedUnspent();
|
var u = this.txps[i].builder.getSelectedUnspent();
|
||||||
|
@ -154,4 +157,4 @@ TxProposalsSet.prototype.getUsedUnspent = function(maxRejectCount) {
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = TxProposalsSet;
|
module.exports = TxProposals;
|
|
@ -17,7 +17,7 @@ var Address = bitcore.Address;
|
||||||
|
|
||||||
var HDParams = require('./HDParams');
|
var HDParams = require('./HDParams');
|
||||||
var PublicKeyRing = require('./PublicKeyRing');
|
var PublicKeyRing = require('./PublicKeyRing');
|
||||||
var TxProposalsSet = require('./TxProposalsSet');
|
var TxProposals = require('./TxProposals');
|
||||||
var PrivateKey = require('./PrivateKey');
|
var PrivateKey = require('./PrivateKey');
|
||||||
var copayConfig = require('../../../config');
|
var copayConfig = require('../../../config');
|
||||||
|
|
||||||
|
@ -132,13 +132,14 @@ Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
|
||||||
Wallet.prototype._handleTxProposal = function(senderId, data) {
|
Wallet.prototype._handleTxProposal = function(senderId, data) {
|
||||||
this.log('RECV TXPROPOSAL: ', data);
|
this.log('RECV TXPROPOSAL: ', data);
|
||||||
var mergeInfo;
|
var mergeInfo;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mergeInfo = this.txProposals.mergeFromObj(data.txProposal, senderId, Wallet.builderOpts);
|
mergeInfo = this.txProposals.mergeFromObj(data.txProposal, senderId, Wallet.builderOpts);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.log('[Wallet.js.141]',e); //TODO
|
||||||
var corruptEvent = {
|
var corruptEvent = {
|
||||||
type: 'corrupt',
|
type: 'corrupt',
|
||||||
cId: mergeInfo.inTxp.creator
|
cId: senderId,
|
||||||
|
error: e,
|
||||||
};
|
};
|
||||||
this.emit('txProposalEvent', corruptEvent);
|
this.emit('txProposalEvent', corruptEvent);
|
||||||
return;
|
return;
|
||||||
|
@ -386,7 +387,7 @@ Wallet.fromObj = function(o, storage, network, blockchain) {
|
||||||
opts.addressBook = o.addressBook;
|
opts.addressBook = o.addressBook;
|
||||||
|
|
||||||
opts.publicKeyRing = PublicKeyRing.fromObj(o.publicKeyRing);
|
opts.publicKeyRing = PublicKeyRing.fromObj(o.publicKeyRing);
|
||||||
opts.txProposals = TxProposalsSet.fromObj(o.txProposals, Wallet.builderOpts);
|
opts.txProposals = TxProposals.fromObj(o.txProposals, Wallet.builderOpts);
|
||||||
opts.privateKey = PrivateKey.fromObj(o.privateKey);
|
opts.privateKey = PrivateKey.fromObj(o.privateKey);
|
||||||
|
|
||||||
opts.storage = storage;
|
opts.storage = storage;
|
||||||
|
@ -494,7 +495,7 @@ Wallet.prototype.generateAddress = function(isChange, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype.getTxProposalsSet = function() {
|
Wallet.prototype.getTxProposals = function() {
|
||||||
var ret = [];
|
var ret = [];
|
||||||
var copayers = this.getRegisteredCopayerIds();
|
var copayers = this.getRegisteredCopayerIds();
|
||||||
for (var ntxid in this.txProposals.txps) {
|
for (var ntxid in this.txProposals.txps) {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
var imports = require('soop').imports();
|
var imports = require('soop').imports();
|
||||||
|
|
||||||
var TxProposalsSet = require('./TxProposalsSet');
|
var TxProposals = require('./TxProposals');
|
||||||
var PublicKeyRing = require('./PublicKeyRing');
|
var PublicKeyRing = require('./PublicKeyRing');
|
||||||
var PrivateKey = require('./PrivateKey');
|
var PrivateKey = require('./PrivateKey');
|
||||||
var Wallet = require('./Wallet');
|
var Wallet = require('./Wallet');
|
||||||
|
|
|
@ -178,7 +178,7 @@ describe('TxProposal', function() {
|
||||||
for(var i in keys){
|
for(var i in keys){
|
||||||
keys[i].toString('hex').should.equal(pubkeys[i].toString('hex'));
|
keys[i].toString('hex').should.equal(pubkeys[i].toString('hex'));
|
||||||
}
|
}
|
||||||
Buffer.isBuffer(info.scriptBuf).should.equal(true);
|
Buffer.isBuffer(info.script.getBuffer()).should.equal(true);
|
||||||
});
|
});
|
||||||
it('#_updateSignedBy', function() {
|
it('#_updateSignedBy', function() {
|
||||||
var txp = dummyProposal;
|
var txp = dummyProposal;
|
||||||
|
|
|
@ -21,7 +21,7 @@ try {
|
||||||
|
|
||||||
var FakeBuilder = require('./mocks/FakeBuilder');
|
var FakeBuilder = require('./mocks/FakeBuilder');
|
||||||
var TxProposal = copay.TxProposal;
|
var TxProposal = copay.TxProposal;
|
||||||
var TxProposalsSet = copay.TxProposalsSet;
|
var TxProposals = copay.TxProposals;
|
||||||
|
|
||||||
var dummyProposal = new TxProposal({
|
var dummyProposal = new TxProposal({
|
||||||
creator: 1,
|
creator: 1,
|
||||||
|
@ -32,17 +32,17 @@ var dummyProposal = new TxProposal({
|
||||||
|
|
||||||
var someKeys = ["03b39d61dc9a504b13ae480049c140dcffa23a6cc9c09d12d6d1f332fee5e18ca5", "022929f515c5cf967474322468c3bd945bb6f281225b2c884b465680ef3052c07e"];
|
var someKeys = ["03b39d61dc9a504b13ae480049c140dcffa23a6cc9c09d12d6d1f332fee5e18ca5", "022929f515c5cf967474322468c3bd945bb6f281225b2c884b465680ef3052c07e"];
|
||||||
|
|
||||||
describe('TxProposalsSet', function() {
|
describe('TxProposals', function() {
|
||||||
describe('constructor', function() {
|
describe('constructor', function() {
|
||||||
it('should create an instance', function() {
|
it('should create an instance', function() {
|
||||||
var txps = new TxProposalsSet();
|
var txps = new TxProposals();
|
||||||
should.exist(txps);
|
should.exist(txps);
|
||||||
txps.network.name.should.equal('testnet');
|
txps.network.name.should.equal('testnet');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('#fromObj', function() {
|
describe('#fromObj', function() {
|
||||||
it('should create an instance from an Object', function() {
|
it('should create an instance from an Object', function() {
|
||||||
var txps = TxProposalsSet.fromObj({
|
var txps = TxProposals.fromObj({
|
||||||
networkName:'livenet',
|
networkName:'livenet',
|
||||||
walletId: '123a12',
|
walletId: '123a12',
|
||||||
txps: [],
|
txps: [],
|
||||||
|
@ -51,7 +51,7 @@ describe('TxProposalsSet', function() {
|
||||||
txps.network.name.should.equal('livenet');
|
txps.network.name.should.equal('livenet');
|
||||||
});
|
});
|
||||||
it('should fail create an instance from an Object with errors', function() {
|
it('should fail create an instance from an Object with errors', function() {
|
||||||
(function() {var txps = TxProposalsSet.fromObj({
|
(function() {var txps = TxProposals.fromObj({
|
||||||
networkName:'livenet',
|
networkName:'livenet',
|
||||||
walletId: '123a12',
|
walletId: '123a12',
|
||||||
txps: [ { a: 1 }],
|
txps: [ { a: 1 }],
|
||||||
|
@ -60,14 +60,14 @@ describe('TxProposalsSet', function() {
|
||||||
});
|
});
|
||||||
describe('#getNtxids', function() {
|
describe('#getNtxids', function() {
|
||||||
it('should return keys', function() {
|
it('should return keys', function() {
|
||||||
var txps = new TxProposalsSet();
|
var txps = new TxProposals();
|
||||||
txps.txps = {a:1, b:2};
|
txps.txps = {a:1, b:2};
|
||||||
txps.getNtxids().should.deep.equal(['a','b']);
|
txps.getNtxids().should.deep.equal(['a','b']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('#toObj', function() {
|
describe('#toObj', function() {
|
||||||
it('should an object', function() {
|
it('should an object', function() {
|
||||||
var txps = TxProposalsSet.fromObj({
|
var txps = TxProposals.fromObj({
|
||||||
networkName:'livenet',
|
networkName:'livenet',
|
||||||
walletId: '123a12',
|
walletId: '123a12',
|
||||||
txps: [],
|
txps: [],
|
||||||
|
@ -77,7 +77,7 @@ describe('TxProposalsSet', function() {
|
||||||
o.networkName.should.equal('livenet');
|
o.networkName.should.equal('livenet');
|
||||||
});
|
});
|
||||||
it('should export txps', function() {
|
it('should export txps', function() {
|
||||||
var txps = TxProposalsSet.fromObj({
|
var txps = TxProposals.fromObj({
|
||||||
networkName:'livenet',
|
networkName:'livenet',
|
||||||
walletId: '123a12',
|
walletId: '123a12',
|
||||||
txps: [],
|
txps: [],
|
||||||
|
@ -90,7 +90,7 @@ describe('TxProposalsSet', function() {
|
||||||
o.txps.length.should.equal(2);
|
o.txps.length.should.equal(2);
|
||||||
});
|
});
|
||||||
it('should filter sent txp', function() {
|
it('should filter sent txp', function() {
|
||||||
var txps = TxProposalsSet.fromObj({
|
var txps = TxProposals.fromObj({
|
||||||
networkName:'livenet',
|
networkName:'livenet',
|
||||||
walletId: '123a12',
|
walletId: '123a12',
|
||||||
txps: [],
|
txps: [],
|
||||||
|
@ -105,5 +105,11 @@ describe('TxProposalsSet', function() {
|
||||||
o.txps.length.should.equal(1);
|
o.txps.length.should.equal(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe.skip('#merge', function() {
|
||||||
|
it('mergeFromObj', function() {
|
||||||
|
var txps = new TxProposals();
|
||||||
|
txps.mergeFromObj(dummyProposal.toObj());
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1064,7 +1064,10 @@ describe('Wallet model', function() {
|
||||||
]);
|
]);
|
||||||
var txp = {
|
var txp = {
|
||||||
'txProposal': {
|
'txProposal': {
|
||||||
'builderObj': txb.toObj()
|
builderObj: txb.toObj(),
|
||||||
|
inputChainPaths: 'm/1',
|
||||||
|
creator: '1234',
|
||||||
|
createdTs: Date.now(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
w._handleTxProposal('senderID', txp, true);
|
w._handleTxProposal('senderID', txp, true);
|
||||||
|
@ -1072,11 +1075,11 @@ describe('Wallet model', function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
it('should validate for undefined', function(done) {
|
it('should validate for undefined', function(done) {
|
||||||
var result = 'new';
|
var result = 'corrupt';
|
||||||
var signhash;
|
var signhash;
|
||||||
testValidate(signhash, result, done);
|
testValidate(signhash, result, done);
|
||||||
});
|
});
|
||||||
it('should validate for SIGHASH_ALL', function(done) {
|
it.only('should validate for SIGHASH_ALL', function(done) {
|
||||||
var result = 'new';
|
var result = 'new';
|
||||||
var signhash = Transaction.SIGHASH_ALL;
|
var signhash = Transaction.SIGHASH_ALL;
|
||||||
testValidate(signhash, result, done);
|
testValidate(signhash, result, done);
|
||||||
|
|
Loading…
Reference in New Issue