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

@ -20,6 +20,19 @@ FakeStorage.prototype.getGlobal = function(id, cb) {
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) {
this.storage['lastOpened'] = val;
return cb();
@ -34,7 +47,7 @@ FakeStorage.prototype.setLock = function(id) {
return cb();
}
FakeStorage.prototype.getLock = function(id,cb) {
FakeStorage.prototype.getLock = function(id, cb) {
return cb(this.storage[id + '::lock']);
}
@ -44,12 +57,12 @@ FakeStorage.prototype.getSessionId = function(cb) {
};
FakeStorage.prototype.removeLock = function(id,cb) {
FakeStorage.prototype.removeLock = function(id, cb) {
delete this.storage[id + '::lock'];
cb();
}
FakeStorage.prototype.removeGlobal = function(id,cb) {
FakeStorage.prototype.removeGlobal = function(id, cb) {
delete this.storage[id];
cb();
};
@ -78,7 +91,7 @@ FakeStorage.prototype.getWalletIds = function(cb) {
if (split.length == 2) {
var walletId = split[0];
if (!walletId || walletId === 'nameFor' || walletId ==='lock')
if (!walletId || walletId === 'nameFor' || walletId === 'lock')
continue;
if (typeof uniq[walletId] === 'undefined') {
@ -106,8 +119,8 @@ FakeStorage.prototype.deleteWallet = function(walletId, cb) {
};
FakeStorage.prototype.getName = function(walletId,cb) {
return this.getGlobal('nameFor::' + walletId,cb);
FakeStorage.prototype.getName = function(walletId, cb) {
return this.getGlobal('nameFor::' + walletId, cb);
};

View file

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