txproposal comuninication between peers. Still WIP
This commit is contained in:
parent
c255c27e5f
commit
ac784ad9ae
12 changed files with 282 additions and 124 deletions
|
|
@ -158,65 +158,71 @@ describe('PublicKeyRing model', function() {
|
|||
networkName: 'livenet',
|
||||
id: w.id,
|
||||
});
|
||||
w2.merge(w.toObj()).should.equal(true);
|
||||
w2.merge(w).should.equal(true);
|
||||
w2.requiredCopayers.should.equal(3);
|
||||
w2.totalCopayers.should.equal(5);
|
||||
w2.changeAddressIndex.should.equal(2);
|
||||
w2.addressIndex.should.equal(3);
|
||||
|
||||
//
|
||||
w2.merge(w.toObj()).should.equal(false);
|
||||
w2.merge(w).should.equal(false);
|
||||
});
|
||||
|
||||
|
||||
it('#merge check tests', function () {
|
||||
var k = createW();
|
||||
var w = k.w;
|
||||
|
||||
for(var i=0; i<2; i++)
|
||||
w.generateAddress(true);
|
||||
for(var i=0; i<3; i++)
|
||||
w.generateAddress(false);
|
||||
|
||||
|
||||
|
||||
var w2 = new PublicKeyRing({
|
||||
var config = {
|
||||
networkName: 'livenet',
|
||||
});
|
||||
(function() { w2.merge(w.toObj());}).should.throw();
|
||||
(function() { w2.merge(w,true);}).should.throw();
|
||||
w2.merge(w.toObj(),true).should.equal(true);
|
||||
};
|
||||
|
||||
var w = new PublicKeyRing(config);
|
||||
var w2 = new PublicKeyRing({
|
||||
networkName: 'testnet', //wrong
|
||||
id: w.id,
|
||||
});
|
||||
(function() { w2.merge(w);}).should.throw();
|
||||
|
||||
var w3 = new PublicKeyRing({
|
||||
networkName: 'livenet',
|
||||
id: w.id,
|
||||
requiredCopayers: 2,
|
||||
requiredCopayers: 2, // wrong
|
||||
});
|
||||
(function() { w3.merge(w.toObj());}).should.throw();
|
||||
(function() { w3.merge(w);}).should.throw();
|
||||
|
||||
var w4 = new PublicKeyRing({
|
||||
networkName: 'testnet',
|
||||
id: w.id,
|
||||
});
|
||||
(function() { w4.merge(w.toObj());}).should.throw();
|
||||
|
||||
var w5 = new PublicKeyRing({
|
||||
networkName: 'livenet',
|
||||
id: w.id,
|
||||
totalCopayers: 4,
|
||||
totalCopayers: 3, // wrong
|
||||
});
|
||||
(function() { w5.merge(w.toObj());}).should.throw();
|
||||
(function() { w4.merge(w);}).should.throw();
|
||||
|
||||
|
||||
var w6 = new PublicKeyRing({
|
||||
networkName: 'livenet',
|
||||
id: w.id,
|
||||
});
|
||||
(function() { w6.merge(w);}).should.throw();
|
||||
w.networkName= 'livenet';
|
||||
(function() { w6.merge(w);}).should.throw();
|
||||
|
||||
|
||||
var w0 = new PublicKeyRing({
|
||||
networkName: 'livenet',
|
||||
});
|
||||
w0.addCopayer();
|
||||
w0.addCopayer();
|
||||
w0.addCopayer();
|
||||
w0.addCopayer();
|
||||
w0.addCopayer();
|
||||
(function() { w0.merge(w);}).should.throw();
|
||||
w.merge(w0,true).should.equal(true);
|
||||
w.isComplete().should.equal(true);
|
||||
|
||||
var wx = new PublicKeyRing({
|
||||
networkName: 'livenet',
|
||||
});
|
||||
wx.addCopayer();
|
||||
(function() { w.merge(wx, true);}).should.throw();
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -239,14 +245,14 @@ describe('PublicKeyRing model', function() {
|
|||
w2.isComplete().should.equal(false);
|
||||
w2.addCopayer();
|
||||
}
|
||||
w2.merge(w.toObj()).should.equal(true);
|
||||
w2.merge(w).should.equal(true);
|
||||
w2.isComplete().should.equal(true);
|
||||
w2.merge(w.toObj()).should.equal(false);
|
||||
w2.merge(w).should.equal(false);
|
||||
|
||||
w.isComplete().should.equal(false);
|
||||
w.merge(w2.toObj()).should.equal(true);
|
||||
w.merge(w2).should.equal(true);
|
||||
w.isComplete().should.equal(true);
|
||||
w.merge(w2.toObj()).should.equal(false);
|
||||
w.merge(w2).should.equal(false);
|
||||
});
|
||||
|
||||
it('#merge pubkey tests (case 2)', function () {
|
||||
|
|
@ -260,7 +266,7 @@ describe('PublicKeyRing model', function() {
|
|||
id: w.id,
|
||||
});
|
||||
w2.addCopayer();
|
||||
w.merge(w2.toObj()).should.equal(true);
|
||||
w.merge(w2).should.equal(true);
|
||||
}
|
||||
w.isComplete().should.equal(true);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ describe('TxProposals model', function() {
|
|||
|
||||
var tx = w.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
bignum('123456789'),
|
||||
'123456789',
|
||||
unspentTest
|
||||
);
|
||||
should.exist(tx);
|
||||
|
|
@ -105,7 +105,7 @@ describe('TxProposals model', function() {
|
|||
var priv = new PrivateKey(config);
|
||||
var tx = w.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
bignum('123456789'),
|
||||
'123456789',
|
||||
unspentTest,
|
||||
priv
|
||||
);
|
||||
|
|
@ -131,7 +131,7 @@ describe('TxProposals model', function() {
|
|||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange);
|
||||
var tx = w.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
bignum('123456789'),
|
||||
'123456789',
|
||||
unspentTest,
|
||||
priv
|
||||
);
|
||||
|
|
@ -161,7 +161,7 @@ describe('TxProposals model', function() {
|
|||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange);
|
||||
var tx = w.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
bignum('123456789'),
|
||||
'123456789',
|
||||
unspentTest,
|
||||
priv
|
||||
);
|
||||
|
|
@ -204,7 +204,7 @@ describe('TxProposals model', function() {
|
|||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange);
|
||||
w.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
bignum('123456789'),
|
||||
'123456789',
|
||||
unspentTest,
|
||||
priv2,
|
||||
opts
|
||||
|
|
@ -225,7 +225,7 @@ describe('TxProposals model', function() {
|
|||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange);
|
||||
w2.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
bignum('123456789'),
|
||||
'123456789',
|
||||
unspentTest,
|
||||
priv,
|
||||
opts
|
||||
|
|
@ -274,7 +274,7 @@ var _dumpChunks = function (scriptSig, label) {
|
|||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange);
|
||||
w.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
bignum('123456789'),
|
||||
'123456789',
|
||||
unspentTest,
|
||||
priv3,
|
||||
opts
|
||||
|
|
@ -295,7 +295,7 @@ var _dumpChunks = function (scriptSig, label) {
|
|||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange);
|
||||
w2.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
bignum('123456789'),
|
||||
'123456789',
|
||||
unspentTest,
|
||||
priv,
|
||||
opts
|
||||
|
|
@ -322,7 +322,7 @@ var _dumpChunks = function (scriptSig, label) {
|
|||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange);
|
||||
w3.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
bignum('123456789'),
|
||||
'123456789',
|
||||
unspentTest,
|
||||
priv2,
|
||||
opts
|
||||
|
|
@ -365,7 +365,7 @@ var _dumpChunks = function (scriptSig, label) {
|
|||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange);
|
||||
w.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
bignum('123456789'),
|
||||
'123456789',
|
||||
unspentTest,
|
||||
priv,
|
||||
opts
|
||||
|
|
@ -384,7 +384,7 @@ var _dumpChunks = function (scriptSig, label) {
|
|||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange);
|
||||
w2.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
bignum('123456789'),
|
||||
'123456789',
|
||||
unspentTest,
|
||||
priv2,
|
||||
opts
|
||||
|
|
@ -403,7 +403,7 @@ var _dumpChunks = function (scriptSig, label) {
|
|||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange);
|
||||
w3.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
bignum('123456789'),
|
||||
'123456789',
|
||||
unspentTest,
|
||||
priv3,
|
||||
opts
|
||||
|
|
@ -441,6 +441,7 @@ var _dumpChunks = function (scriptSig, label) {
|
|||
|
||||
var priv = new PrivateKey(config);
|
||||
var w = new TxProposals({
|
||||
walletId: 'qwerty',
|
||||
networkName: config.networkName,
|
||||
publicKeyRing: createPKR([priv.getBIP32()]),
|
||||
});
|
||||
|
|
@ -452,7 +453,7 @@ var _dumpChunks = function (scriptSig, label) {
|
|||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange);
|
||||
var tx = w.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
bignum('123456789'),
|
||||
'123456789',
|
||||
unspentTest,
|
||||
priv
|
||||
);
|
||||
|
|
@ -470,11 +471,14 @@ var _dumpChunks = function (scriptSig, label) {
|
|||
should.exist(o.txps[0].signedBy[priv.id]);
|
||||
|
||||
var w2 = TxProposals.fromObj(o);
|
||||
w2.walletId.should.equal(w.walletId);
|
||||
var tx2 = w2.txps[0].tx;
|
||||
tx2.isComplete().should.equal(false);
|
||||
tx2.countInputMissingSignatures(0).should.equal(2);
|
||||
(w2.txps[0].signedBy[priv.id] - ts > 0).should.equal(true);
|
||||
(w2.txps[0].seenBy[priv.id] - ts > 0).should.equal(true);
|
||||
|
||||
w2.merge(w);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue