more tests fixes

This commit is contained in:
Matias Alejo Garcia 2014-09-08 14:24:57 -03:00
commit f48898033f
3 changed files with 46 additions and 27 deletions

View file

@ -91,6 +91,8 @@ WalletFactory.prototype.fromObj = function(obj, skipFields) {
preconditions.checkArgument(obj); preconditions.checkArgument(obj);
// not stored options
obj.opts = obj.opts || {};
obj.opts.reconnectDelay = this.walletDefaults.reconnectDelay; obj.opts.reconnectDelay = this.walletDefaults.reconnectDelay;
// this is only used if private key or public key ring is skipped // this is only used if private key or public key ring is skipped
@ -231,7 +233,6 @@ WalletFactory.prototype.create = function(opts, cb) {
opts.totalCopayers = totalCopayers; opts.totalCopayers = totalCopayers;
opts.version = opts.version || this.version; opts.version = opts.version || this.version;
console.log('[WalletFactory.js.165]'); //TODO
var w = new Wallet(opts); var w = new Wallet(opts);
var self = this; var self = this;
w.store(function() { w.store(function() {

View file

@ -20,6 +20,19 @@ FakeStorage.prototype.getGlobal = function(id, cb) {
return cb(this.storage[id]); return cb(this.storage[id]);
}; };
FakeStorage.prototype.getMany = function(wid, fields, cb) {
var self= this;
var ret = [];
for(var ii in fields){
var k = fields[ii];
ret[k] = this.storage[wid + '::' + k];
}
return cb(ret);
};
FakeStorage.prototype.setLastOpened = function(val, cb) { FakeStorage.prototype.setLastOpened = function(val, cb) {
this.storage['lastOpened'] = val; this.storage['lastOpened'] = val;
return cb(); return cb();

View file

@ -85,6 +85,7 @@ function assertObjectEqual(a, b, msg) {
describe('WalletFactory model', function() { describe('WalletFactory model', function() {
var config = { var config = {
Network: FakeNetwork, Network: FakeNetwork,
Blockchain: FakeBlockchain, Blockchain: FakeBlockchain,
@ -121,42 +122,46 @@ describe('WalletFactory model', function() {
it('should be able to create wallets', function(done) { it('should be able to create wallets', function(done) {
var wf = new WalletFactory(config, '0.0.1'); var wf = new WalletFactory(config, '0.0.1');
wf.create(null, function(err, w) { wf.create(null, function(err, w) {
console.log('[test.WalletFactory.js.123]'); //TODO
should.not.exist(err);
should.exist(w); should.exist(w);
w.should.be.instanceof('WalletFactory'); should.not.exist(err);
done(); done();
}); });
}); });
it('should be able to create wallets with given pk', function() { it('should be able to create wallets with given pk', function(done) {
var wf = new WalletFactory(config, '0.0.1'); var wf = new WalletFactory(config, '0.0.1');
var priv = 'tprv8ZgxMBicQKsPdEqHcA7RjJTayxA3gSSqeRTttS1JjVbgmNDZdSk9EHZK5pc52GY5xFmwcakmUeKWUDzGoMLGAhrfr5b3MovMUZUTPqisL2m'; var priv = 'tprv8ZgxMBicQKsPdEqHcA7RjJTayxA3gSSqeRTttS1JjVbgmNDZdSk9EHZK5pc52GY5xFmwcakmUeKWUDzGoMLGAhrfr5b3MovMUZUTPqisL2m';
var w = wf.create({ wf.create({
privateKeyHex: priv, privateKeyHex: priv,
}); }, function(err, w) {
w.privateKey.toObj().extendedPrivateKeyString.should.equal(priv); w.privateKey.toObj().extendedPrivateKeyString.should.equal(priv);
should.not.exist(err);
done();
});
}); });
it('should be able to create wallets with random pk', function() { it('should be able to create wallets with random pk', function(done) {
var wf = new WalletFactory(config, '0.0.1'); var wf = new WalletFactory(config, '0.0.1');
var priv = 'tprv8ZgxMBicQKsPdEqHcA7RjJTayxA3gSSqeRTttS1JjVbgmNDZdSk9EHZK5pc52GY5xFmwcakmUeKWUDzGoMLGAhrfr5b3MovMUZUTPqisL2m'; wf.create(null, function(err, w1) {
var w1 = wf.create(); wf.create(null, function(err, w2) {
var w2 = wf.create();
w1.privateKey.toObj().extendedPrivateKeyString.should.not.equal( w1.privateKey.toObj().extendedPrivateKeyString.should.not.equal(
w2.privateKey.toObj().extendedPrivateKeyString w2.privateKey.toObj().extendedPrivateKeyString
); );
done();
});
});
}); });
it('should be able to get wallets', function() { it.only('should be able to get wallets', function(done) {
var wf = new WalletFactory(config, '0.0.1'); var wf = new WalletFactory(config, '0.0.1');
var w = wf.create(); wf.create(null, function(err,w){
wf.read(w.id, [], function(err, w2){
var w2 = wf.read(w.id);
should.exist(w2); should.exist(w2);
w2.id.should.equal(w.id); w2.id.should.equal(w.id);
done();
});
});
}); });