fix test on node

This commit is contained in:
Matias Alejo Garcia 2014-04-09 14:30:12 -03:00
parent c4f88a3d2d
commit 4f2499e13c
6 changed files with 24 additions and 2986 deletions

View File

@ -2,5 +2,6 @@
module.exports.Storage = require('./js/models/Storage'); module.exports.Storage = require('./js/models/Storage');
module.exports.PublicKeyRing = require('./js/models/PublicKeyRing'); module.exports.PublicKeyRing = require('./js/models/PublicKeyRing');
module.exports.Wallet = require('./js/models/Wallet'); module.exports.Wallet = require('./js/models/Wallet');
module.exports.TxProposals = require('./js/models/TxProposals');
module.exports.CopayPeer = require('./js/models/CopayPeer'); module.exports.CopayPeer = require('./js/models/CopayPeer');
module.exports.FakeStorage = require('./test/FakeStorage'); module.exports.FakeStorage = require('./test/FakeStorage');

File diff suppressed because it is too large Load Diff

View File

@ -236,7 +236,6 @@ CopayPeer.prototype.send = function(peerIds, data, cb) {
peerIds = this.connectedPeers; peerIds = this.connectedPeers;
data.isBroadcast = 1; data.isBroadcast = 1;
} }
console.log('[CopayPeer.js.216:SENDD:]',data); //TODO
if (Array.isArray(peerIds)) { if (Array.isArray(peerIds)) {
var l = peerIds.length; var l = peerIds.length;

View File

@ -123,7 +123,6 @@ PublicKeyRing.prototype.store = function (passphrase) {
if (!this.id) if (!this.id)
throw new Error('wallet has no id'); throw new Error('wallet has no id');
storage.set(this.id, PublicKeyRing.encrypt(passphrase,this.serialize())); storage.set(this.id, PublicKeyRing.encrypt(passphrase,this.serialize()));
this.dirty = 0; this.dirty = 0;
@ -136,13 +135,13 @@ PublicKeyRing.prototype.registeredCopayers = function () {
PublicKeyRing.prototype.haveAllRequiredPubKeys = function () { PublicKeyRing.prototype.isComplete = function () {
return this.registeredCopayers() >= this.totalCopayers; return this.registeredCopayers() >= this.totalCopayers;
}; };
PublicKeyRing.prototype._checkKeys = function() { PublicKeyRing.prototype._checkKeys = function() {
if (!this.haveAllRequiredPubKeys()) if (!this.isComplete())
throw new Error('dont have required keys yet'); throw new Error('dont have required keys yet');
}; };
@ -154,7 +153,7 @@ PublicKeyRing.prototype._newExtendedPublicKey = function () {
PublicKeyRing.prototype.addCopayer = function (newEpk) { PublicKeyRing.prototype.addCopayer = function (newEpk) {
if (this.haveAllRequiredPubKeys()) if (this.isComplete())
throw new Error('already have all required key:' + this.totalCopayers); throw new Error('already have all required key:' + this.totalCopayers);
if (!newEpk) { if (!newEpk) {
@ -172,7 +171,7 @@ PublicKeyRing.prototype.addCopayer = function (newEpk) {
}; };
PublicKeyRing.prototype.getCopayersPubKeys = function (index, isChange) { PublicKeyRing.prototype.getPubKeys = function (index, isChange) {
this._checkKeys(); this._checkKeys();
var pubKeys = []; var pubKeys = [];
@ -197,7 +196,7 @@ PublicKeyRing.prototype._checkIndexRange = function (index, isChange) {
PublicKeyRing.prototype.getRedeemScript = function (index, isChange) { PublicKeyRing.prototype.getRedeemScript = function (index, isChange) {
this._checkIndexRange(index, isChange); this._checkIndexRange(index, isChange);
var pubKeys = this.getCopayersPubKeys(index, isChange); var pubKeys = this.getPubKeys(index, isChange);
var script = Script.createMultisig(this.requiredCopayers, pubKeys); var script = Script.createMultisig(this.requiredCopayers, pubKeys);
return script; return script;
}; };

View File

@ -3,12 +3,12 @@ var FakeStorage = function(){
this.storage = {}; this.storage = {};
}; };
FakeStorage.prototype.set = function (id) { FakeStorage.prototype.set = function (id, payload) {
return this.storage[id]; this.storage[id] = payload;
}; };
FakeStorage.prototype.get = function(id, payload) { FakeStorage.prototype.get = function(id) {
this.storage[id] = payload; return this.storage[id];
} }
module.exports = require('soop')(FakeStorage); module.exports = require('soop')(FakeStorage);

View File

@ -7,7 +7,9 @@ var Address = bitcore.Address;
var buffertools = bitcore.buffertools; var buffertools = bitcore.buffertools;
var copay = copay || require('../copay'); var copay = copay || require('../copay');
var fakeStorage = copay.FakeStorage; var fakeStorage = copay.FakeStorage;
var PublicKeyRing = copay.PublicKeyRing || require('soop').load('../js/models/PublicKeyRing', {Storage: fakeStorage});
var PublicKeyRing = (typeof process.versions === 'undefined') ? copay.PublicKeyRing :
require('soop').load('../js/models/PublicKeyRing', {Storage: fakeStorage});
var aMasterPubKey = 'tprv8ZgxMBicQKsPdSVTiWXEqCCzqRaRr9EAQdn5UVMpT9UHX67Dh1FmzEMbavPumpAicsUm2XvC6NTdcWB89yN5DUWx5HQ7z3KByUg7Ht74VRZ'; var aMasterPubKey = 'tprv8ZgxMBicQKsPdSVTiWXEqCCzqRaRr9EAQdn5UVMpT9UHX67Dh1FmzEMbavPumpAicsUm2XvC6NTdcWB89yN5DUWx5HQ7z3KByUg7Ht74VRZ';
@ -17,7 +19,6 @@ var config = {
}; };
var createW = function (networkName) { var createW = function (networkName) {
var config = { var config = {
networkName: networkName || 'livenet', networkName: networkName || 'livenet',
}; };
@ -27,7 +28,7 @@ var createW = function (networkName) {
var copayers = []; var copayers = [];
for(var i=0; i<5; i++) { for(var i=0; i<5; i++) {
w.haveAllRequiredPubKeys().should.equal(false); w.isComplete().should.equal(false);
var newEpk = w.addCopayer(); var newEpk = w.addCopayer();
copayers.push(newEpk); copayers.push(newEpk);
} }
@ -55,7 +56,7 @@ describe('PublicKeyRing model', function() {
should.exist(w2); should.exist(w2);
w2.registeredCopayers().should.equal(0); w2.registeredCopayers().should.equal(0);
w2.haveAllRequiredPubKeys().should.equal(false); w2.isComplete().should.equal(false);
w2.getAddress.bind(false).should.throw(); w2.getAddress.bind(false).should.throw();
}); });
@ -65,7 +66,7 @@ describe('PublicKeyRing model', function() {
var w = k.w; var w = k.w;
var copayers = k.copayers; var copayers = k.copayers;
w.haveAllRequiredPubKeys().should.equal(true); w.isComplete().should.equal(true);
w.addCopayer.bind().should.throw(); w.addCopayer.bind().should.throw();
for(var i =0; i<5; i++) for(var i =0; i<5; i++)
w.addCopayer.bind(copayers[i]).should.throw(); w.addCopayer.bind(copayers[i]).should.throw();
@ -86,7 +87,7 @@ describe('PublicKeyRing model', function() {
w.store.bind().should.throw(); w.store.bind().should.throw();
var w2 = PublicKeyRing.read(ID); var w2 = PublicKeyRing.read(ID);
w2.haveAllRequiredPubKeys().should.equal(true); w2.isComplete().should.equal(true);
w2.addCopayer.bind().should.throw(); w2.addCopayer.bind().should.throw();
for(var i =0; i<5; i++) for(var i =0; i<5; i++)
w2.addCopayer.bind(copayers[i]).should.throw(); w2.addCopayer.bind(copayers[i]).should.throw();
@ -188,12 +189,8 @@ describe('PublicKeyRing model', function() {
}); });
(function() { w2.merge(w.toObj());}).should.throw(); (function() { w2.merge(w.toObj());}).should.throw();
(function() { w2.merge(w,true);}).should.throw(); (function() { w2.merge(w,true);}).should.throw();
console.log('[test.publickeyring.js.190]'); //TODO
w2.merge(w.toObj(),true).should.equal(true); w2.merge(w.toObj(),true).should.equal(true);
console.log('[test.publickeyring.js.193]'); //TODO
var w3 = new PublicKeyRing({ var w3 = new PublicKeyRing({
networkName: 'livenet', networkName: 'livenet',
@ -232,7 +229,7 @@ console.log('[test.publickeyring.js.193]'); //TODO
should.exist(w); should.exist(w);
var copayers = []; var copayers = [];
for(var i=0; i<2; i++) { for(var i=0; i<2; i++) {
w.haveAllRequiredPubKeys().should.equal(false); w.isComplete().should.equal(false);
w.addCopayer(); w.addCopayer();
} }
@ -243,16 +240,16 @@ console.log('[test.publickeyring.js.193]'); //TODO
should.exist(w); should.exist(w);
var copayers = []; var copayers = [];
for(var i=0; i<3; i++) { for(var i=0; i<3; i++) {
w2.haveAllRequiredPubKeys().should.equal(false); w2.isComplete().should.equal(false);
w2.addCopayer(); w2.addCopayer();
} }
w2.merge(w.toObj()).should.equal(true); w2.merge(w.toObj()).should.equal(true);
w2.haveAllRequiredPubKeys().should.equal(true); w2.isComplete().should.equal(true);
w2.merge(w.toObj()).should.equal(false); w2.merge(w.toObj()).should.equal(false);
w.haveAllRequiredPubKeys().should.equal(false); w.isComplete().should.equal(false);
w.merge(w2.toObj()).should.equal(true); w.merge(w2.toObj()).should.equal(true);
w.haveAllRequiredPubKeys().should.equal(true); w.isComplete().should.equal(true);
w.merge(w2.toObj()).should.equal(false); w.merge(w2.toObj()).should.equal(false);
}); });
@ -261,7 +258,7 @@ console.log('[test.publickeyring.js.193]'); //TODO
should.exist(w); should.exist(w);
for(var i=0; i<5; i++) { for(var i=0; i<5; i++) {
w.haveAllRequiredPubKeys().should.equal(false); w.isComplete().should.equal(false);
var w2 = new PublicKeyRing({ var w2 = new PublicKeyRing({
networkName: 'livenet', networkName: 'livenet',
id: w.id, id: w.id,
@ -269,7 +266,7 @@ console.log('[test.publickeyring.js.193]'); //TODO
w2.addCopayer(); w2.addCopayer();
w.merge(w2.toObj()).should.equal(true); w.merge(w2.toObj()).should.equal(true);
} }
w.haveAllRequiredPubKeys().should.equal(true); w.isComplete().should.equal(true);
}); });
}); });