2014-04-10 13:57:41 -07:00
|
|
|
'use strict';
|
|
|
|
|
2014-04-14 14:30:08 -07:00
|
|
|
var chai = chai || require('chai');
|
|
|
|
var should = chai.should();
|
|
|
|
var copay = copay || require('../copay');
|
|
|
|
var Wallet = require('soop').load('../js/models/core/Wallet', {
|
|
|
|
Storage: require('./FakeStorage'),
|
|
|
|
Network: copay.WebRTC,
|
|
|
|
Blockchain: copay.Insight
|
|
|
|
});
|
2014-04-10 13:57:41 -07:00
|
|
|
|
2014-04-15 11:50:22 -07:00
|
|
|
|
|
|
|
var addCopayers = function (w) {
|
|
|
|
for(var i=0; i<4; i++) {
|
|
|
|
w.publicKeyRing.addCopayer();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-10 13:57:41 -07:00
|
|
|
describe('Wallet model', function() {
|
2014-04-14 14:30:08 -07:00
|
|
|
var config = {
|
|
|
|
wallet: {
|
|
|
|
requiredCopayers: 3,
|
|
|
|
totalCopayers: 5,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var opts = {};
|
|
|
|
|
2014-04-10 13:57:41 -07:00
|
|
|
|
2014-04-15 11:50:22 -07:00
|
|
|
it('should create an instance', function () {
|
2014-04-14 13:17:56 -07:00
|
|
|
var opts = {};
|
2014-04-15 11:50:22 -07:00
|
|
|
var w = new Wallet(config);
|
2014-04-10 13:57:41 -07:00
|
|
|
should.exist(w);
|
|
|
|
});
|
2014-04-14 14:30:08 -07:00
|
|
|
|
|
|
|
|
2014-04-15 11:50:22 -07:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-14 14:30:08 -07:00
|
|
|
describe('factory', function() {
|
|
|
|
it('should create the factory', function() {
|
|
|
|
should.exist(Wallet.factory);
|
|
|
|
});
|
|
|
|
it('should be able to create wallets', function() {
|
|
|
|
var w = Wallet.factory.create(config, opts);
|
|
|
|
should.exist(w);
|
|
|
|
});
|
|
|
|
it.skip('should be able to get wallets', function() {
|
|
|
|
var w = Wallet.factory.create(config, opts);
|
|
|
|
var v = Wallet.factory.get(config, w.id);
|
|
|
|
should.exist(w);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-04-10 13:57:41 -07:00
|
|
|
});
|