add sign in block

This commit is contained in:
Matias Alejo Garcia 2014-04-09 23:04:22 -03:00
commit c3efcb3f27
6 changed files with 79 additions and 30 deletions

View file

@ -47,4 +47,24 @@ describe('PrivateKey model', function() {
}
}
});
it('should derive priv keys array', function () {
var w = new PrivateKey(config);
var wks = w.getAll(2,3);
wks.length.should.equal(5);
for(var j=0; j<wks.length; j++) {
var wk = wks[j];
should.exist(wk);
var o=wk.storeObj();
should.exist(o);
should.exist(o.priv);
should.exist(o.pub);
should.exist(o.addr);
var a = new Address(o.addr);
a.isValid().should.equal(true);
(function() {
var p = new PrivateKey(o.priv)
}).should.not.throw();
}
});
});

View file

@ -6,10 +6,7 @@ var bitcore = bitcore || require('bitcore');
var Address = bitcore.Address;
var buffertools = bitcore.buffertools;
var copay = copay || require('../copay');
var fakeStorage = copay.FakeStorage;
var PublicKeyRing = (typeof process.versions === 'undefined') ? copay.PublicKeyRing :
require('soop').load('../js/models/PublicKeyRing', {Storage: fakeStorage});
var PublicKeyRing = copay.PublicKeyRing;
var aMasterPubKey = 'tprv8ZgxMBicQKsPdSVTiWXEqCCzqRaRr9EAQdn5UVMpT9UHX67Dh1FmzEMbavPumpAicsUm2XvC6NTdcWB89yN5DUWx5HQ7z3KByUg7Ht74VRZ';
@ -72,7 +69,7 @@ describe('PublicKeyRing model', function() {
w.addCopayer.bind(copayers[i]).should.throw();
});
it('show be able to store and retrieve', function () {
it('show be able to tostore and read', function () {
var k = createW();
var w = k.w;
var copayers = k.copayers;
@ -81,12 +78,12 @@ describe('PublicKeyRing model', function() {
for(var i=0; i<5; i++)
w.generateAddress(false);
w.store().should.equal(true);
var ID = w.id;
delete w['id'];
w.store.bind().should.throw();
var data = w.toStore();
should.exist(data);
var w2 = PublicKeyRing.read(ID);
var ID = w.id;
var w2 = PublicKeyRing.read(data, ID, 'dummy' );
w2.isComplete().should.equal(true);
w2.addCopayer.bind().should.throw();
for(var i =0; i<5; i++)

View file

@ -84,7 +84,7 @@ describe('TxProposals model', function() {
tx.isComplete().should.equal(false);
});
it('#create. Singing with derivate keys', function () {
it('#create. Signing with derivate keys', function () {
var priv = new PrivateKey(config);
var w = new TxProposals({
@ -104,7 +104,37 @@ describe('TxProposals model', function() {
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
bignum('123456789'),
unspentTest,
priv.get(index,isChange)
[priv.get(index,isChange)]
);
should.exist(tx);
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
}
}
});
it('#create. Signing with derivate keys block', function () {
var priv = new PrivateKey(config);
var privs = priv.getAll(3,3);
var w = new TxProposals({
networkName: config.networkName,
publicKeyRing: createW([priv.getBIP32()]),
});
should.exist(w);
w.network.name.should.equal('livenet');
for (var isChange=0; isChange<2; isChange++) {
for (var index=0; index<3; index++) {
unspentTest[0].address = w.publicKeyRing.getAddress(index, isChange);
unspentTest[0].scriptPubKey = w.publicKeyRing.getRedeemScript(index, isChange).getBuffer();
var tx = w.create(
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
bignum('123456789'),
unspentTest,
privs
);
should.exist(tx);
tx.isComplete().should.equal(false);