add #addWallet to profile

This commit is contained in:
Matias Alejo Garcia 2014-09-28 21:22:53 -03:00
commit 7abdc77611
4 changed files with 91 additions and 42 deletions

View file

@ -46,11 +46,16 @@ describe('Identity model', function() {
profile = sinon.stub();
profile.test = sinon.stub();
profile.store = sinon.stub();
profile.store.yields(null);
profile.store = sinon.stub().yields(null);;
Identity._newProfile = sinon.stub().returns(profile);
iden = new Identity(email, password, config);
var w = sinon.stub();
w.store = sinon.stub().yields(null);
iden._getWallet = sinon.stub().returns(w);
});
@ -187,6 +192,40 @@ describe('Identity model', function() {
});
});
describe('#createWallet', function() {
it('should create wallet', function(done) {
iden.createWallet(null, function(err, w) {
should.exist(w);
should.not.exist(err);
done();
});
});
it('should be able to create wallets with given pk', function(done) {
var priv = 'tprv8ZgxMBicQKsPdEqHcA7RjJTayxA3gSSqeRTttS1JjVbgmNDZdSk9EHZK5pc52GY5xFmwcakmUeKWUDzGoMLGAhrfr5b3MovMUZUTPqisL2m';
iden.createWallet({
privateKeyHex: priv,
}, function(err, w) {
iden._getWallet.getCall(0).args[0].privateKey.toObj().extendedPrivateKeyString.should.equal(priv);
should.not.exist(err);
done();
});
});
it('should be able to create wallets with random pk', function(done) {
iden.createWallet(null, function(err, w1) {
iden.createWallet(null, function(err, w2) {
iden._getWallet.getCall(0).args[0].privateKey.toObj().extendedPrivateKeyString.should.not.equal(
iden._getWallet.getCall(1).args[0].privateKey.toObj().extendedPrivateKeyString
);
done();
});
});
});
});
// TODO this is a WALLET TEST! not Wallet Factory. Move it.
describe.skip('#fromObj / #toObj', function() {
it('round trip', function() {
@ -492,38 +531,6 @@ describe('Identity model', function() {
});
});
describe('#createWallet', function() {
it('should create wallet', function(done) {
iden.createWallet(null, function(err, w) {
should.exist(w);
should.not.exist(err);
done();
});
});
it('should be able to create wallets with given pk', function(done) {
var priv = 'tprv8ZgxMBicQKsPdEqHcA7RjJTayxA3gSSqeRTttS1JjVbgmNDZdSk9EHZK5pc52GY5xFmwcakmUeKWUDzGoMLGAhrfr5b3MovMUZUTPqisL2m';
iden.createWallet({
privateKeyHex: priv,
}, function(err, w) {
iden._getWallet.getCall(0).args[0].privateKey.toObj().extendedPrivateKeyString.should.equal(priv);
should.not.exist(err);
done();
});
});
it('should be able to create wallets with random pk', function(done) {
iden.createWallet(null, function(err, w1) {
iden.createWallet(null, function(err, w2) {
iden._getWallet.getCall(0).args[0].privateKey.toObj().extendedPrivateKeyString.should.not.equal(
iden._getWallet.getCall(1).args[0].privateKey.toObj().extendedPrivateKeyString
);
done();
});
});
});
});
describe('#joinWallet', function() {
var opts = {
secret: '8WtTuiFTkhP5ao7AF2QErSwV39Cbur6pdMebKzQXFqL59RscXM',