add #addWallet to profile
This commit is contained in:
parent
77a01370cb
commit
7abdc77611
4 changed files with 91 additions and 42 deletions
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -44,6 +44,27 @@ describe('Profile model', function() {
|
|||
p2.should.deep.equal(p);
|
||||
});
|
||||
|
||||
describe.only('#addWallet', function() {
|
||||
it('should add a wallet id', function(done) {
|
||||
var p = new Profile(opts, password, storage);
|
||||
p.addWallet('123', function(err) {
|
||||
p.walletIds['123'].should.be.above(123456789);
|
||||
storage.set.getCall(0).args[1].should.deep.equal(p.toObj());
|
||||
done();
|
||||
})
|
||||
});
|
||||
it('should keep old value', function(done) {
|
||||
var p = new Profile(opts, password, storage);
|
||||
p.walletIds['123']=1;
|
||||
p.addWallet('123', function(err) {
|
||||
p.walletIds['123'].should.equal(1);
|
||||
should.not.exist(storage.set.getCall(0));
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#store', function() {
|
||||
it('should call storage set', function(done) {
|
||||
var p = new Profile(opts, password, storage);
|
||||
|
|
@ -62,11 +83,13 @@ describe('Profile model', function() {
|
|||
done();
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
it('should use overwrite param', function(done) {
|
||||
storage.get = sinon.stub().yields(123);
|
||||
var p = new Profile(opts, password, storage);
|
||||
p.store({overwrite:true}, function(err) {
|
||||
p.store({
|
||||
overwrite: true
|
||||
}, function(err) {
|
||||
storage.set.getCall(0).args[1].should.deep.equal(p.toObj());
|
||||
should.not.exist(err);
|
||||
done();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue