add wallet tests

This commit is contained in:
Matias Alejo Garcia 2014-04-15 15:50:22 -03:00
parent 341c9d8ffa
commit d4b2ac1ad4
2 changed files with 50 additions and 10 deletions

View File

@ -35,6 +35,7 @@ Wallet.prototype._startInterface = function(config) {
Wallet.prototype.create = function(opts) { Wallet.prototype.create = function(opts) {
opts = opts || {};
this.id = opts.id || Wallet.getRandomId(); this.id = opts.id || Wallet.getRandomId();
this.log('### CREATING NEW WALLET.' + (opts.id ? ' USING ID: ' + opts.id : ' NEW ID')); this.log('### CREATING NEW WALLET.' + (opts.id ? ' USING ID: ' + opts.id : ' NEW ID'));
@ -67,14 +68,6 @@ Wallet.prototype._checkLoad = function(walletId) {
this.storage.get(walletId, 'txProposals') && this.storage.get(walletId, 'txProposals') &&
this.storage.get(walletId, 'privateKey') this.storage.get(walletId, 'privateKey')
; ;
console.log('[Wallet.js.71]',
this.storage.get(walletId, 'publicKeyRing'),
this.storage.get(walletId, 'txProposals'),
this.storage.get(walletId, 'privateKey'));
console.log('[Wallet.js.73:ret:]',walletId, ret); //TODO
return ret; return ret;
} }
@ -169,6 +162,15 @@ Wallet.prototype.addSeenToTxProposals = function() {
return ret; return ret;
}; };
Wallet.prototype.getAddresses = function() {
return this.publicKeyRing.getAddresses();
};
Wallet.prototype.listUnspent = function(cb) {
this.blockchain.listUnspent(this.getAddresses(), cb);
};
// // HERE? not sure // // HERE? not sure
// Wallet.prototype.cleanPeers = function() { // Wallet.prototype.cleanPeers = function() {
// this.storage.remove('peerData'); // this.storage.remove('peerData');

View File

@ -9,6 +9,13 @@ var Wallet = require('soop').load('../js/models/core/Wallet', {
Blockchain: copay.Insight Blockchain: copay.Insight
}); });
var addCopayers = function (w) {
for(var i=0; i<4; i++) {
w.publicKeyRing.addCopayer();
}
};
describe('Wallet model', function() { describe('Wallet model', function() {
var config = { var config = {
wallet: { wallet: {
@ -19,13 +26,44 @@ describe('Wallet model', function() {
var opts = {}; var opts = {};
it.skip('should create an instance', function () { it('should create an instance', function () {
var opts = {}; var opts = {};
var w = Wallet.create(config, opts); var w = new Wallet(config);
should.exist(w); should.exist(w);
}); });
it('should fail to load', function () {
var opts = {};
var w = new Wallet(config);
w.load(123);
should.not.exist(w.id);
});
it('should create', function () {
var opts = {};
var w = new Wallet(config);
w.create();
should.exist(w.id);
should.exist(w.publicKeyRing);
should.exist(w.privateKey);
should.exist(w.txProposals);
});
it('should create', function () {
var opts = {};
var w = new Wallet(config);
w.create();
addCopayers(w);
w.publicKeyRing.generateAddress(false);
should.exist(w.id);
w.publicKeyRing.isComplete().should.equal(true);
});
describe('factory', function() { describe('factory', function() {
it('should create the factory', function() { it('should create the factory', function() {
should.exist(Wallet.factory); should.exist(Wallet.factory);