working towards fixing tests with new rules
This commit is contained in:
parent
542f6d5cea
commit
cf159241a9
4 changed files with 37 additions and 17 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
|
|
||||||
var imports = require('soop').imports();
|
var imports = require('soop').imports();
|
||||||
|
var preconditions = require('preconditions').instance();
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
var HK = bitcore.HierarchicalKey;
|
var HK = bitcore.HierarchicalKey;
|
||||||
var PrivateKey = require('./PrivateKey');
|
var PrivateKey = require('./PrivateKey');
|
||||||
|
|
@ -62,6 +63,7 @@ PublicKeyRing.prototype.toObj = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
PublicKeyRing.prototype.getCopayerId = function(i) {
|
PublicKeyRing.prototype.getCopayerId = function(i) {
|
||||||
|
preconditions.checkArgument(typeof i !== 'undefined');
|
||||||
return this.copayerIds[i];
|
return this.copayerIds[i];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,9 @@ TxProposal.getSentTs = function() {
|
||||||
return this.sentTs;
|
return this.sentTs;
|
||||||
};
|
};
|
||||||
|
|
||||||
TxProposal.prototype.merge = function(other) {
|
TxProposal.prototype.merge = function(other, author) {
|
||||||
var ret = {};
|
var ret = {};
|
||||||
ret.events = this.mergeMetadata(other);
|
ret.events = this.mergeMetadata(other, author);
|
||||||
ret.hasChanged = this.mergeBuilder(other);
|
ret.hasChanged = this.mergeBuilder(other);
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
@ -69,7 +69,7 @@ TxProposal.prototype.mergeBuilder = function(other) {
|
||||||
return after !== before;
|
return after !== before;
|
||||||
};
|
};
|
||||||
|
|
||||||
TxProposal.prototype.mergeMetadata = function(v1) {
|
TxProposal.prototype.mergeMetadata = function(v1, author) {
|
||||||
var events = [];
|
var events = [];
|
||||||
var v0 = this;
|
var v0 = this;
|
||||||
|
|
||||||
|
|
@ -77,6 +77,7 @@ TxProposal.prototype.mergeMetadata = function(v1) {
|
||||||
|
|
||||||
Object.keys(v1.seenBy).forEach(function(k) {
|
Object.keys(v1.seenBy).forEach(function(k) {
|
||||||
if (!v0.seenBy[k]) {
|
if (!v0.seenBy[k]) {
|
||||||
|
if (k != author) throw new Error('Non authoritative seenBy change by '+author);
|
||||||
v0.seenBy[k] = v1.seenBy[k];
|
v0.seenBy[k] = v1.seenBy[k];
|
||||||
events.push({
|
events.push({
|
||||||
type: 'seen',
|
type: 'seen',
|
||||||
|
|
@ -88,6 +89,7 @@ TxProposal.prototype.mergeMetadata = function(v1) {
|
||||||
|
|
||||||
Object.keys(v1.signedBy).forEach(function(k) {
|
Object.keys(v1.signedBy).forEach(function(k) {
|
||||||
if (!v0.signedBy[k]) {
|
if (!v0.signedBy[k]) {
|
||||||
|
if (k != author) throw new Error('Non authoritative signedBy change by '+author);
|
||||||
v0.signedBy[k] = v1.signedBy[k];
|
v0.signedBy[k] = v1.signedBy[k];
|
||||||
events.push({
|
events.push({
|
||||||
type: 'signed',
|
type: 'signed',
|
||||||
|
|
@ -99,6 +101,7 @@ TxProposal.prototype.mergeMetadata = function(v1) {
|
||||||
|
|
||||||
Object.keys(v1.rejectedBy).forEach(function(k) {
|
Object.keys(v1.rejectedBy).forEach(function(k) {
|
||||||
if (!v0.rejectedBy[k]) {
|
if (!v0.rejectedBy[k]) {
|
||||||
|
if (k != author) throw new Error('Non authoritative rejectedBy change by '+author);
|
||||||
v0.rejectedBy[k] = v1.rejectedBy[k];
|
v0.rejectedBy[k] = v1.rejectedBy[k];
|
||||||
events.push({
|
events.push({
|
||||||
type: 'rejected',
|
type: 'rejected',
|
||||||
|
|
@ -168,7 +171,7 @@ TxProposals.prototype.toObj = function(onlyThisNtxid) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
TxProposals.prototype.merge = function(inTxp) {
|
TxProposals.prototype.merge = function(inTxp, author) {
|
||||||
var myTxps = this.txps;
|
var myTxps = this.txps;
|
||||||
|
|
||||||
var ntxid = inTxp.getID();
|
var ntxid = inTxp.getID();
|
||||||
|
|
@ -179,7 +182,7 @@ TxProposals.prototype.merge = function(inTxp) {
|
||||||
if (myTxps[ntxid]) {
|
if (myTxps[ntxid]) {
|
||||||
var v0 = myTxps[ntxid];
|
var v0 = myTxps[ntxid];
|
||||||
var v1 = inTxp;
|
var v1 = inTxp;
|
||||||
ret = v0.merge(v1);
|
ret = v0.merge(v1, author);
|
||||||
} else {
|
} else {
|
||||||
this.txps[ntxid] = inTxp;
|
this.txps[ntxid] = inTxp;
|
||||||
ret.hasChanged = true;
|
ret.hasChanged = true;
|
||||||
|
|
@ -192,7 +195,13 @@ TxProposals.prototype.merge = function(inTxp) {
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var preconditions = require('preconditions').instance();
|
||||||
TxProposals.prototype.add = function(data) {
|
TxProposals.prototype.add = function(data) {
|
||||||
|
preconditions.checkArgument(data.inputChainPaths);
|
||||||
|
preconditions.checkArgument(data.signedBy);
|
||||||
|
preconditions.checkArgument(data.creator);
|
||||||
|
preconditions.checkArgument(data.createdTs);
|
||||||
|
preconditions.checkArgument(data.builder);
|
||||||
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;
|
||||||
|
|
|
||||||
|
|
@ -118,10 +118,11 @@ Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype._handleTxProposal = function(senderId, data) {
|
Wallet.prototype._handleTxProposal = function(senderId, data) {
|
||||||
|
preconditions.checkArgument(senderId);
|
||||||
this.log('RECV TXPROPOSAL:', data);
|
this.log('RECV TXPROPOSAL:', data);
|
||||||
|
|
||||||
var inTxp = TxProposals.TxProposal.fromObj(data.txProposal);
|
var inTxp = TxProposals.TxProposal.fromObj(data.txProposal);
|
||||||
var mergeInfo = this.txProposals.merge(inTxp);
|
var mergeInfo = this.txProposals.merge(inTxp, senderId);
|
||||||
var added = this.addSeenToTxProposals();
|
var added = this.addSeenToTxProposals();
|
||||||
|
|
||||||
this.emit('txProposalsUpdated');
|
this.emit('txProposalsUpdated');
|
||||||
|
|
@ -498,6 +499,7 @@ Wallet.prototype.reject = function(ntxid) {
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype.sign = function(ntxid, cb) {
|
Wallet.prototype.sign = function(ntxid, cb) {
|
||||||
|
preconditions.checkState(typeof this.getMyCopayerId() !== 'undefined');
|
||||||
var self = this;
|
var self = this;
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
var myId = self.getMyCopayerId();
|
var myId = self.getMyCopayerId();
|
||||||
|
|
@ -709,7 +711,6 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
var selectedUtxos = b.getSelectedUnspent();
|
var selectedUtxos = b.getSelectedUnspent();
|
||||||
|
|
||||||
var inputChainPaths = selectedUtxos.map(function(utxo) {
|
var inputChainPaths = selectedUtxos.map(function(utxo) {
|
||||||
return pkr.pathForAddress(utxo.address);
|
return pkr.pathForAddress(utxo.address);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -149,16 +149,23 @@ describe('TxProposals model', function() {
|
||||||
address: toAddress,
|
address: toAddress,
|
||||||
amountSat: amountSat
|
amountSat: amountSat
|
||||||
}]);
|
}]);
|
||||||
|
var selectedUtxos = b.getSelectedUnspent();
|
||||||
|
var inputChainPaths = selectedUtxos.map(function(utxo) {
|
||||||
|
return pkr.pathForAddress(utxo.address);
|
||||||
|
});
|
||||||
|
|
||||||
var signRet;
|
var signRet;
|
||||||
if (priv) {
|
if (priv) {
|
||||||
var pkeys = priv.getAll(pkr.indexes.getReceiveIndex(), pkr.indexes.getChangeIndex());
|
var pkeys = priv.getForPaths(inputChainPaths);
|
||||||
b.sign(pkeys);
|
b.sign(pkeys);
|
||||||
}
|
}
|
||||||
var me = {};
|
var me = {};
|
||||||
if (priv) me[priv.id] = Date.now();
|
if (priv) me[priv.getId()] = Date.now();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
inputChainPaths: inputChainPaths,
|
||||||
|
creator: priv.getId(),
|
||||||
|
createdTs: new Date(),
|
||||||
signedBy: priv && b.signaturesAdded ? me : {},
|
signedBy: priv && b.signaturesAdded ? me : {},
|
||||||
seenBy: priv ? me : {},
|
seenBy: priv ? me : {},
|
||||||
builder: b,
|
builder: b,
|
||||||
|
|
@ -216,10 +223,11 @@ describe('TxProposals model', function() {
|
||||||
tx.isComplete().should.equal(false);
|
tx.isComplete().should.equal(false);
|
||||||
tx.countInputMissingSignatures(0).should.equal(2);
|
tx.countInputMissingSignatures(0).should.equal(2);
|
||||||
|
|
||||||
(w.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
|
var x = priv.getId();
|
||||||
|
(w.txps[ntxid].signedBy[priv.getId()] - ts > 0).should.equal(true);
|
||||||
(w.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
|
(w.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
|
||||||
|
|
||||||
var info = w.merge(w.txps[ntxid]);
|
var info = w.merge(w.txps[ntxid], pkr.getCopayerId(0));
|
||||||
info.events.length.should.equal(0);
|
info.events.length.should.equal(0);
|
||||||
|
|
||||||
Object.keys(w.txps).length.should.equal(1);
|
Object.keys(w.txps).length.should.equal(1);
|
||||||
|
|
@ -293,7 +301,7 @@ describe('TxProposals model', function() {
|
||||||
(w2.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
|
(w2.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
|
||||||
(w2.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
|
(w2.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
|
||||||
|
|
||||||
var info = w.merge(w2.txps[ntxid]);
|
var info = w.merge(w2.txps[ntxid], pkr.getCopayerId(0));
|
||||||
info.events.length.should.equal(1);
|
info.events.length.should.equal(1);
|
||||||
info.events[0].type.should.equal('signed');
|
info.events[0].type.should.equal('signed');
|
||||||
|
|
||||||
|
|
@ -401,7 +409,7 @@ describe('TxProposals model', function() {
|
||||||
(w2.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
|
(w2.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
|
||||||
(w2.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
|
(w2.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
|
||||||
|
|
||||||
var info = w.merge(w2.txps[ntxid]);
|
var info = w.merge(w2.txps[ntxid], pkr.getCopayerId(0));
|
||||||
info.events.length.should.equal(1);
|
info.events.length.should.equal(1);
|
||||||
info.events[0].type.should.equal('signed');
|
info.events[0].type.should.equal('signed');
|
||||||
|
|
||||||
|
|
@ -431,7 +439,7 @@ describe('TxProposals model', function() {
|
||||||
(w3.txps[ntxid].signedBy[priv2.id] - ts > 0).should.equal(true);
|
(w3.txps[ntxid].signedBy[priv2.id] - ts > 0).should.equal(true);
|
||||||
(w3.txps[ntxid].seenBy[priv2.id] - ts > 0).should.equal(true);
|
(w3.txps[ntxid].seenBy[priv2.id] - ts > 0).should.equal(true);
|
||||||
|
|
||||||
var info = w.merge(w3.txps[ntxid]);
|
var info = w.merge(w3.txps[ntxid], pkr.getCopayerId(0));
|
||||||
info.events.length.should.equal(0);
|
info.events.length.should.equal(0);
|
||||||
|
|
||||||
Object.keys(w.txps).length.should.equal(1);
|
Object.keys(w.txps).length.should.equal(1);
|
||||||
|
|
@ -522,7 +530,7 @@ describe('TxProposals model', function() {
|
||||||
(w3.txps[ntxid].signedBy[priv3.id] - ts > 0).should.equal(true);
|
(w3.txps[ntxid].signedBy[priv3.id] - ts > 0).should.equal(true);
|
||||||
(w3.txps[ntxid].seenBy[priv3.id] - ts > 0).should.equal(true);
|
(w3.txps[ntxid].seenBy[priv3.id] - ts > 0).should.equal(true);
|
||||||
|
|
||||||
var info = w.merge(w2.txps[ntxid]);
|
var info = w.merge(w2.txps[ntxid], pkr.getCopayerId(0));
|
||||||
info.events.length.should.equal(0);
|
info.events.length.should.equal(0);
|
||||||
|
|
||||||
Object.keys(w.txps).length.should.equal(1);
|
Object.keys(w.txps).length.should.equal(1);
|
||||||
|
|
@ -535,7 +543,7 @@ describe('TxProposals model', function() {
|
||||||
(w.txps[ntxid].signedBy[priv2.id] - ts > 0).should.equal(true);
|
(w.txps[ntxid].signedBy[priv2.id] - ts > 0).should.equal(true);
|
||||||
|
|
||||||
|
|
||||||
var info = w.merge(w3.txps[ntxid]);
|
var info = w.merge(w3.txps[ntxid], pkr.getCopayerId(0));
|
||||||
info.events.length.should.equal(0);
|
info.events.length.should.equal(0);
|
||||||
|
|
||||||
var tx = w.txps[ntxid].builder.build();
|
var tx = w.txps[ntxid].builder.build();
|
||||||
|
|
@ -601,7 +609,7 @@ describe('TxProposals model', function() {
|
||||||
should.exist(w2.txps[ntxid].builder);
|
should.exist(w2.txps[ntxid].builder);
|
||||||
should.exist(w2.txps[ntxid].builder.valueInSat);
|
should.exist(w2.txps[ntxid].builder.valueInSat);
|
||||||
|
|
||||||
w2.merge(w.txps[ntxid]);
|
w2.merge(w.txps[ntxid], pkr.getCopayerId(0));
|
||||||
Object.keys(w2.txps).length.should.equal(1);
|
Object.keys(w2.txps).length.should.equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue