Fix Conflicts:
js/models/core/WalletFactory.js
This commit is contained in:
commit
21baa103bd
13 changed files with 346 additions and 137 deletions
|
|
@ -3,27 +3,17 @@
|
|||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
|
||||
var copay = copay || require('../copay');
|
||||
var sinon = require('sinon');
|
||||
var FakeNetwork = require('./mocks/FakeNetwork');
|
||||
var Insight = require('../js/models/blockchain/Insight');
|
||||
var FakeBlockchain = require('./mocks/FakeBlockchain');
|
||||
var FakeStorage = require('./mocks/FakeStorage');
|
||||
|
||||
try {
|
||||
var copay = require('copay'); //browser
|
||||
} catch (e) {
|
||||
var copay = require('../copay'); //node
|
||||
}
|
||||
var WalletFactory = require('../js/models/core/WalletFactory');
|
||||
|
||||
var addCopayers = function(w) {
|
||||
for (var i = 0; i < 4; i++) {
|
||||
w.publicKeyRing.addCopayer();
|
||||
}
|
||||
};
|
||||
|
||||
describe('WalletFactory model', function() {
|
||||
var config = {
|
||||
Network: FakeNetwork,
|
||||
Blockchain: Insight,
|
||||
Blockchain: FakeBlockchain,
|
||||
Storage: FakeStorage,
|
||||
wallet: {
|
||||
requiredCopayers: 3,
|
||||
|
|
@ -38,12 +28,34 @@ describe('WalletFactory model', function() {
|
|||
},
|
||||
networkName: 'testnet',
|
||||
passphrase: 'test',
|
||||
storageObj: new FakeStorage(),
|
||||
networkObj: new FakeNetwork(),
|
||||
blockchainObj: new FakeBlockchain(),
|
||||
};
|
||||
|
||||
it('should create the factory', function() {
|
||||
var wf = new WalletFactory(config);
|
||||
should.exist(wf);
|
||||
beforeEach(function() {
|
||||
config.storageObj.reset();
|
||||
});
|
||||
|
||||
it('should create the factory', function() {
|
||||
var wf = new WalletFactory(config, '0.0.1');
|
||||
should.exist(wf);
|
||||
wf.networkName.should.equal(config.networkName);
|
||||
wf.walletDefaults.should.deep.equal(config.wallet);
|
||||
wf.version.should.equal('0.0.1');
|
||||
});
|
||||
|
||||
it('should log', function() {
|
||||
var c2 = JSON.parse(JSON.stringify(config));
|
||||
c2.verbose = 1;
|
||||
var wf = new WalletFactory(c2, '0.0.1');
|
||||
var spy = sinon.spy(console, 'log');
|
||||
wf.log('ok');
|
||||
sinon.assert.callCount(spy, 1);
|
||||
spy.getCall(0).args[0].should.equal('ok');
|
||||
});
|
||||
|
||||
|
||||
it('#_checkRead should return false', function() {
|
||||
var wf = new WalletFactory(config);
|
||||
wf._checkRead('dummy').should.equal(false);
|
||||
|
|
@ -75,7 +87,7 @@ describe('WalletFactory model', function() {
|
|||
should.exist(w.publicKeyRing.getCopayerId);
|
||||
should.exist(w.txProposals.toObj);
|
||||
should.exist(w.privateKey.toObj);
|
||||
|
||||
|
||||
JSON.stringify(w.toObj()).should.equal(o);
|
||||
});
|
||||
|
||||
|
|
@ -83,7 +95,7 @@ describe('WalletFactory model', function() {
|
|||
it('BIP32 length problem', function() {
|
||||
var sconfig = {
|
||||
Network: FakeNetwork,
|
||||
Blockchain: Insight,
|
||||
Blockchain: FakeBlockchain,
|
||||
Storage: FakeStorage,
|
||||
"networkName": "testnet",
|
||||
"network": {
|
||||
|
|
@ -101,7 +113,7 @@ describe('WalletFactory model', function() {
|
|||
"wallet": {
|
||||
"requiredCopayers": 2,
|
||||
"totalCopayers": 3,
|
||||
"reconnectDelay":100,
|
||||
"reconnectDelay": 100,
|
||||
"spendUnconfirmed": 1,
|
||||
"verbose": 0
|
||||
},
|
||||
|
|
@ -114,7 +126,10 @@ describe('WalletFactory model', function() {
|
|||
"port": 3001
|
||||
},
|
||||
"verbose": 0,
|
||||
"themes": ["default"]
|
||||
"themes": ["default"],
|
||||
storageObj: new FakeStorage(),
|
||||
networkObj: new FakeNetwork(),
|
||||
blockchainObj: new FakeBlockchain(),
|
||||
};
|
||||
var wf = new WalletFactory(sconfig, '0.0.1');
|
||||
var opts = {
|
||||
|
|
@ -125,4 +140,30 @@ describe('WalletFactory model', function() {
|
|||
|
||||
});
|
||||
|
||||
it('should be able to get current wallets', function() {
|
||||
var wf = new WalletFactory(config, '0.0.1');
|
||||
var ws = wf.getWallets();
|
||||
|
||||
var w = wf.create({
|
||||
name: 'test wallet'
|
||||
});
|
||||
var ws = wf.getWallets();
|
||||
ws.length.should.equal(1);
|
||||
ws[0].name.should.equal('test wallet');
|
||||
});
|
||||
|
||||
it('should be able to delete wallet', function(done) {
|
||||
var wf = new WalletFactory(config, '0.0.1');
|
||||
var w = wf.create({
|
||||
name: 'test wallet'
|
||||
});
|
||||
var ws = wf.getWallets();
|
||||
ws.length.should.equal(1);
|
||||
wf.delete(ws[0].id, function() {
|
||||
ws = wf.getWallets();
|
||||
ws.length.should.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue