more tests fixes
This commit is contained in:
parent
f1e6d6cfc6
commit
f48898033f
3 changed files with 46 additions and 27 deletions
|
|
@ -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() {
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
@ -34,7 +47,7 @@ FakeStorage.prototype.setLock = function(id) {
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
FakeStorage.prototype.getLock = function(id,cb) {
|
FakeStorage.prototype.getLock = function(id, cb) {
|
||||||
return cb(this.storage[id + '::lock']);
|
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'];
|
delete this.storage[id + '::lock'];
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
FakeStorage.prototype.removeGlobal = function(id,cb) {
|
FakeStorage.prototype.removeGlobal = function(id, cb) {
|
||||||
delete this.storage[id];
|
delete this.storage[id];
|
||||||
cb();
|
cb();
|
||||||
};
|
};
|
||||||
|
|
@ -78,7 +91,7 @@ FakeStorage.prototype.getWalletIds = function(cb) {
|
||||||
if (split.length == 2) {
|
if (split.length == 2) {
|
||||||
var walletId = split[0];
|
var walletId = split[0];
|
||||||
|
|
||||||
if (!walletId || walletId === 'nameFor' || walletId ==='lock')
|
if (!walletId || walletId === 'nameFor' || walletId === 'lock')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (typeof uniq[walletId] === 'undefined') {
|
if (typeof uniq[walletId] === 'undefined') {
|
||||||
|
|
@ -106,8 +119,8 @@ FakeStorage.prototype.deleteWallet = function(walletId, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
FakeStorage.prototype.getName = function(walletId,cb) {
|
FakeStorage.prototype.getName = function(walletId, cb) {
|
||||||
return this.getGlobal('nameFor::' + walletId,cb);
|
return this.getGlobal('nameFor::' + walletId, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
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 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();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue