mirror of https://github.com/BTCPrivate/copay.git
add fail search script
This commit is contained in:
parent
b1eb0bffbc
commit
b568473d0e
|
@ -17,23 +17,23 @@ var fakeStorage = copay.FakeStorage;
|
||||||
var PrivateKey = copay.PrivateKey || require('../js/models/PrivateKey');
|
var PrivateKey = copay.PrivateKey || require('../js/models/PrivateKey');
|
||||||
var TxProposals = copay.TxProposals || require('../js/models/TxProposal');
|
var TxProposals = copay.TxProposals || require('../js/models/TxProposal');
|
||||||
var PublicKeyRing = is_browser ? copay.PublicKeyRing :
|
var PublicKeyRing = is_browser ? copay.PublicKeyRing :
|
||||||
require('soop').load('../js/models/core/PublicKeyRing', {Storage: fakeStorage});
|
require('soop').load('../js/models/core/PublicKeyRing', {
|
||||||
|
Storage: fakeStorage
|
||||||
|
});
|
||||||
var is_browser = (typeof process.versions === 'undefined')
|
var is_browser = (typeof process.versions === 'undefined')
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
networkName: 'livenet',
|
networkName: 'livenet',
|
||||||
};
|
};
|
||||||
|
|
||||||
var unspentTest = [
|
var unspentTest = [{
|
||||||
{
|
|
||||||
"address": "dummy",
|
"address": "dummy",
|
||||||
"scriptPubKey": "dummy",
|
"scriptPubKey": "dummy",
|
||||||
"txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
|
"txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
|
||||||
"vout": 1,
|
"vout": 1,
|
||||||
"amount": 10,
|
"amount": 10,
|
||||||
"confirmations": 7
|
"confirmations": 7
|
||||||
}
|
}];
|
||||||
];
|
|
||||||
|
|
||||||
var createPKR = function(bip32s) {
|
var createPKR = function(bip32s) {
|
||||||
var w = new PublicKeyRing(config);
|
var w = new PublicKeyRing(config);
|
||||||
|
@ -43,8 +43,7 @@ var createPKR = function (bip32s) {
|
||||||
if (bip32s) {
|
if (bip32s) {
|
||||||
var b = bip32s[i];
|
var b = bip32s[i];
|
||||||
w.addCopayer(b ? b.deriveBIP45Branch().extendedPublicKeyString() : null);
|
w.addCopayer(b ? b.deriveBIP45Branch().extendedPublicKeyString() : null);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
w.addCopayer();
|
w.addCopayer();
|
||||||
}
|
}
|
||||||
w.generateAddress(true);
|
w.generateAddress(true);
|
||||||
|
@ -75,7 +74,11 @@ describe('TxProposals model', function() {
|
||||||
var isChange = 0;
|
var isChange = 0;
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var pkr = createPKR([priv, priv2, priv3]);
|
var pkr = createPKR([priv, priv2, priv3]);
|
||||||
var opts = {remainderOut: { address: pkr.generateAddress(true).toString() }};
|
var opts = {
|
||||||
|
remainderOut: {
|
||||||
|
address: pkr.generateAddress(true).toString()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var w = new TxProposals({
|
var w = new TxProposals({
|
||||||
networkName: config.networkName,
|
networkName: config.networkName,
|
||||||
|
@ -120,7 +123,7 @@ describe('TxProposals model', function() {
|
||||||
w.network.name.should.equal('livenet');
|
w.network.name.should.equal('livenet');
|
||||||
});
|
});
|
||||||
|
|
||||||
function createTx(toAddress, amountSatStr, utxos, opts, priv, pkr) {
|
var createTx = function(toAddress, amountSatStr, utxos, opts, priv, pkr) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
var amountSat = bitcore.bignum(amountSatStr);
|
var amountSat = bitcore.bignum(amountSatStr);
|
||||||
|
@ -130,14 +133,18 @@ describe('TxProposals model', function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opts.remainderOut) {
|
if (!opts.remainderOut) {
|
||||||
opts.remainderOut ={ address: pkr.generateAddress(true).toString() };
|
opts.remainderOut = {
|
||||||
|
address: pkr.generateAddress(true).toString()
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var b = new Builder(opts)
|
var b = new Builder(opts)
|
||||||
.setUnspent(utxos)
|
.setUnspent(utxos)
|
||||||
.setHashToScriptMap(pkr.getRedeemScriptMap())
|
.setHashToScriptMap(pkr.getRedeemScriptMap())
|
||||||
.setOutputs([{address: toAddress, amountSat: amountSat}])
|
.setOutputs([{
|
||||||
;
|
address: toAddress,
|
||||||
|
amountSat: amountSat
|
||||||
|
}]);
|
||||||
|
|
||||||
var signRet;
|
var signRet;
|
||||||
if (priv) {
|
if (priv) {
|
||||||
|
@ -169,8 +176,7 @@ describe('TxProposals model', function() {
|
||||||
w.add(createTx(
|
w.add(createTx(
|
||||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||||
'123456789',
|
'123456789',
|
||||||
unspentTest,
|
unspentTest, {},
|
||||||
{},
|
|
||||||
priv,
|
priv,
|
||||||
pkr
|
pkr
|
||||||
));
|
));
|
||||||
|
@ -196,8 +202,7 @@ describe('TxProposals model', function() {
|
||||||
w.add(createTx(
|
w.add(createTx(
|
||||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||||
'123456789',
|
'123456789',
|
||||||
unspentTest,
|
unspentTest, {},
|
||||||
{},
|
|
||||||
priv,
|
priv,
|
||||||
pkr
|
pkr
|
||||||
));
|
));
|
||||||
|
@ -228,7 +233,11 @@ describe('TxProposals model', function() {
|
||||||
var isChange = 0;
|
var isChange = 0;
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var pkr = createPKR([priv]);
|
var pkr = createPKR([priv]);
|
||||||
var opts = {remainderOut: { address: pkr.generateAddress(true).toString() }};
|
var opts = {
|
||||||
|
remainderOut: {
|
||||||
|
address: pkr.generateAddress(true).toString()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var w = new TxProposals({
|
var w = new TxProposals({
|
||||||
|
@ -296,7 +305,7 @@ var _dumpChunks = function (scriptSig, label) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
it('#merge, merge signatures case 2', function () {
|
it.only('#merge, merge signatures case 2', function() {
|
||||||
|
|
||||||
var priv = new PrivateKey(config);
|
var priv = new PrivateKey(config);
|
||||||
var priv2 = new PrivateKey(config);
|
var priv2 = new PrivateKey(config);
|
||||||
|
@ -305,7 +314,11 @@ var _dumpChunks = function (scriptSig, label) {
|
||||||
var isChange = 0;
|
var isChange = 0;
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var pkr = createPKR([priv, priv2]);
|
var pkr = createPKR([priv, priv2]);
|
||||||
var opts = {remainderOut: { address: pkr.generateAddress(true).toString() }};
|
var opts = {
|
||||||
|
remainderOut: {
|
||||||
|
address: pkr.generateAddress(true).toString()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var w = new TxProposals({
|
var w = new TxProposals({
|
||||||
networkName: config.networkName,
|
networkName: config.networkName,
|
||||||
|
@ -322,13 +335,17 @@ var _dumpChunks = function (scriptSig, label) {
|
||||||
pkr
|
pkr
|
||||||
));
|
));
|
||||||
|
|
||||||
var k = Object.keys(w.txps)[0];
|
var ntxid = Object.keys(w.txps)[0];
|
||||||
var tx = w.txps[k].builder.build();
|
var tx = w.txps[ntxid].builder.build();
|
||||||
|
console.log('first should');
|
||||||
tx.isComplete().should.equal(false);
|
tx.isComplete().should.equal(false);
|
||||||
|
console.log('2 should');
|
||||||
tx.countInputMissingSignatures(0).should.equal(1);
|
tx.countInputMissingSignatures(0).should.equal(1);
|
||||||
|
|
||||||
Object.keys(w.txps[k].signedBy).length.should.equal(0);
|
console.log('3 should');
|
||||||
Object.keys(w.txps[k].seenBy).length.should.equal(1);
|
Object.keys(w.txps[ntxid].signedBy).length.should.equal(0);
|
||||||
|
console.log('4 should');
|
||||||
|
Object.keys(w.txps[ntxid].seenBy).length.should.equal(1);
|
||||||
|
|
||||||
|
|
||||||
var w2 = new TxProposals({
|
var w2 = new TxProposals({
|
||||||
|
@ -347,19 +364,28 @@ var _dumpChunks = function (scriptSig, label) {
|
||||||
));
|
));
|
||||||
var k = Object.keys(w2.txps)[0];
|
var k = Object.keys(w2.txps)[0];
|
||||||
tx = w2.txps[k].builder.build();
|
tx = w2.txps[k].builder.build();
|
||||||
|
console.log('5 should');
|
||||||
tx.isComplete().should.equal(false);
|
tx.isComplete().should.equal(false);
|
||||||
|
console.log('6 should');
|
||||||
tx.countInputMissingSignatures(0).should.equal(2);
|
tx.countInputMissingSignatures(0).should.equal(2);
|
||||||
|
|
||||||
|
console.log('7 should');
|
||||||
(w2.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
|
(w2.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
|
||||||
|
console.log('8 should');
|
||||||
(w2.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
|
(w2.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
|
||||||
|
|
||||||
w.merge(w2);
|
w.merge(w2);
|
||||||
|
console.log('9 should');
|
||||||
Object.keys(w.txps).length.should.equal(1);
|
Object.keys(w.txps).length.should.equal(1);
|
||||||
|
|
||||||
tx = w.txps[k].builder.build();
|
tx = w.txps[k].builder.build();
|
||||||
|
console.log('10 should');
|
||||||
tx.isComplete().should.equal(false);
|
tx.isComplete().should.equal(false);
|
||||||
|
console.log('11 should');
|
||||||
tx.countInputMissingSignatures(0).should.equal(2);
|
tx.countInputMissingSignatures(0).should.equal(2);
|
||||||
|
console.log('12 should');
|
||||||
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
|
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
|
||||||
|
console.log('13 should');
|
||||||
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
|
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
|
||||||
|
|
||||||
|
|
||||||
|
@ -378,22 +404,33 @@ var _dumpChunks = function (scriptSig, label) {
|
||||||
pkr
|
pkr
|
||||||
));
|
));
|
||||||
tx = w3.txps[k].builder.build();
|
tx = w3.txps[k].builder.build();
|
||||||
|
console.log('14 should');
|
||||||
tx.isComplete().should.equal(false);
|
tx.isComplete().should.equal(false);
|
||||||
|
console.log('15 should');
|
||||||
tx.countInputMissingSignatures(0).should.equal(2);
|
tx.countInputMissingSignatures(0).should.equal(2);
|
||||||
|
|
||||||
|
console.log('16 should');
|
||||||
(w3.txps[k].signedBy[priv2.id] - ts > 0).should.equal(true);
|
(w3.txps[k].signedBy[priv2.id] - ts > 0).should.equal(true);
|
||||||
|
console.log('17 should');
|
||||||
(w3.txps[k].seenBy[priv2.id] - ts > 0).should.equal(true);
|
(w3.txps[k].seenBy[priv2.id] - ts > 0).should.equal(true);
|
||||||
|
|
||||||
w.merge(w3);
|
w.merge(w3);
|
||||||
|
console.log('18 should');
|
||||||
Object.keys(w.txps).length.should.equal(1);
|
Object.keys(w.txps).length.should.equal(1);
|
||||||
|
|
||||||
|
console.log('19 should');
|
||||||
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
|
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
|
||||||
|
console.log('20 should');
|
||||||
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
|
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
|
||||||
|
console.log('21 should');
|
||||||
(w.txps[k].signedBy[priv2.id] - ts > 0).should.equal(true);
|
(w.txps[k].signedBy[priv2.id] - ts > 0).should.equal(true);
|
||||||
|
console.log('22 should');
|
||||||
(w.txps[k].seenBy[priv2.id] - ts > 0).should.equal(true);
|
(w.txps[k].seenBy[priv2.id] - ts > 0).should.equal(true);
|
||||||
|
|
||||||
tx = w.txps[k].builder.build();
|
tx = w.txps[k].builder.build();
|
||||||
|
console.log('23 should');
|
||||||
tx.isComplete().should.equal(false);
|
tx.isComplete().should.equal(false);
|
||||||
|
console.log('24 should');
|
||||||
tx.countInputMissingSignatures(0).should.equal(1);
|
tx.countInputMissingSignatures(0).should.equal(1);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -408,7 +445,11 @@ var _dumpChunks = function (scriptSig, label) {
|
||||||
var isChange = 0;
|
var isChange = 0;
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var pkr = createPKR([priv, priv2, priv3]);
|
var pkr = createPKR([priv, priv2, priv3]);
|
||||||
var opts = {remainderOut: { address: pkr.generateAddress(true).toString() }};
|
var opts = {
|
||||||
|
remainderOut: {
|
||||||
|
address: pkr.generateAddress(true).toString()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var w = new TxProposals({
|
var w = new TxProposals({
|
||||||
networkName: config.networkName,
|
networkName: config.networkName,
|
||||||
|
@ -513,8 +554,7 @@ var _dumpChunks = function (scriptSig, label) {
|
||||||
w.add(createTx(
|
w.add(createTx(
|
||||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||||
'123456789',
|
'123456789',
|
||||||
unspentTest,
|
unspentTest, {},
|
||||||
{},
|
|
||||||
priv,
|
priv,
|
||||||
pkr
|
pkr
|
||||||
));
|
));
|
||||||
|
|
Loading…
Reference in New Issue