Add controller tests (#4205)

* add walletHome test template

* add create test

* add fixtures

* do not mock parseSecret

* better hash

* use fixtures for create controller test

* add import test

* stubs reset

* add more controller tests

* Remove $state dependency

* refactore fixtures + profiles

* add backup.js test

* update bwc

* rm log
This commit is contained in:
Matias Alejo Garcia 2016-05-20 11:50:55 -03:00
commit aec2aac47b
20 changed files with 2265 additions and 28 deletions

View file

@ -0,0 +1,46 @@
describe('Backup Controller', function() {
var walletService;
describe('Incomplete wallet', function() {
beforeEach(function(done) {
mocks.init(FIXTURES, 'backupController', {
loadProfile: PROFILE.incomplete2of2,
}, done);
});
afterEach(function(done) {
mocks.clear({}, done);
});
it('should be defined', function() {
should.exist(ctrl);
});
it('should set the mnemonic incomplete wallets', function(done) {
should.exist(ctrl);
ctrl.mnemonicWords.should.deep.equal('dizzy cycle skirt decrease exotic fork sure mixture hair vapor copper hero'.split(' '));
done();
});
});
describe('Complete 1-1 wallet', function() {
beforeEach(function(done) {
mocks.init(FIXTURES, 'backupController', {
loadProfile: PROFILE.testnet1of1,
}, done);
});
afterEach(function(done) {
mocks.clear({}, done);
});
it('should not set the mnemonic for complete wallets', function() {
ctrl.mnemonicWords.should.deep.equal('cheese where alarm job conduct donkey license pave congress pepper fence current'.split(' '));
});
it('should set main wallet info', function(done) {
ctrl.walletName.should.equal('kk');
done();
});
});
});

View file

@ -0,0 +1,18 @@
describe('copayers', function() {
var walletService;
var fixtures = {};
beforeEach(function(done){
mocks.init(fixtures, 'copayersController', {}, done);
})
afterEach(function(done){
mocks.clear({}, done);
})
it('should be defined', function() {
should.exist(ctrl);
});
});

View file

@ -0,0 +1,180 @@
describe('createController', function() {
var fixtures = {
// createWallet 1-1
'56db6f58f2c212591afb4d508d03e5fb40bb786f23dc56c43b98bde42dc513e5': {
"walletId": "267bfa75-5575-4af7-8aa3-f5186bc99262"
},
// join ^
'd2f00a570de17f52fcda4b1b4b4ed1bc688a3b33c193b71630c3183dab70e6ec': {
"copayerId": "a9dcee10fe9c611300e6c7926ece20780f89b9a98baaa342928038b5503ed929",
"wallet": {
"version": "1.0.0",
"createdOn": 1463488747,
"id": "267bfa75-5575-4af7-8aa3-f5186bc99262",
"name": "{\"iv\":\"BZQVWAP6d1e4G8Fq1rQKbA==\",\"v\":1,\"iter\":1,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":\"70OA+k4+xTPxim+QSdDtA5/Cf055\"}",
"m": 1,
"n": 1,
"status": "complete",
"publicKeyRing": [{
"xPubKey": "xpub6DRjAgkh3vGTWDcEmDp4TPwy48Nu8yrp6swCEdCCLL615CgnZon7r3vXYr8LYibMLJh5DriGSito1FRBwVoBkjD1ZWG4dmgiC935wLj3nQC",
"requestPubKey": "02befcc7499abcecf9608bb05e665f374434a89ca0c4e9baeab7dd28c027143458"
}],
"copayers": [{
"version": 2,
"createdOn": 1463490295,
"xPubKey": "xpub6DRjAgkh3vGTWDcEmDp4TPwy48Nu8yrp6swCEdCCLL615CgnZon7r3vXYr8LYibMLJh5DriGSito1FRBwVoBkjD1ZWG4dmgiC935wLj3nQC",
"id": "a9dcee10fe9c611300e6c7926ece20780f89b9a98baaa342928038b5503ed929",
"name": "{\"iv\":\"BZQVWAP6d1e4G8Fq1rQKbA==\",\"v\":1,\"iter\":1,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":\"wwZd+2LQgYR6cA==\"}",
"requestPubKey": "02befcc7499abcecf9608bb05e665f374434a89ca0c4e9baeab7dd28c027143458",
"signature": "3044022042e069126a42f1b9b498c315a825ef4fc9f4214156442651e4fef5c7678245e702205936045d7b22baa36ba36ef827cc3e5d542d57d9a1afb3a54080d12f0b95c67e",
"requestPubKeys": [{
"key": "02befcc7499abcecf9608bb05e665f374434a89ca0c4e9baeab7dd28c027143458",
"signature": "3044022042e069126a42f1b9b498c315a825ef4fc9f4214156442651e4fef5c7678245e702205936045d7b22baa36ba36ef827cc3e5d542d57d9a1afb3a54080d12f0b95c67e"
}],
"customData": "{\"iv\":\"BZQVWAP6d1e4G8Fq1rQKbA==\",\"v\":1,\"iter\":1,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":\"1Wjf2KvFkd5k0ypiiSNkSVXk7zdBOiTeCrwzPBI7fMQ/VqXUzrSB6gMGs9jISr+MvCaL1GJIXjaMnlQZNMR0lx/Pd1c6R/nKGBdHjKh0mlI=\"}"
}],
"pubKey": "026d95bb5cc2a30c19e22379ae78b4757aaa2dd0ccbd15a1db054fb50cb98ed361",
"network": "livenet",
"derivationStrategy": "BIP44",
"addressType": "P2PKH",
"addressManager": {
"version": 2,
"derivationStrategy": "BIP44",
"receiveAddressIndex": 0,
"changeAddressIndex": 0,
"copayerIndex": 2147483647
},
"scanStatus": null
}
},
//createWallet 2-2
'e46ef870b70e6deca6bbfa61bd0d83b0dc5b712402538b0dabcd0d4f038b0eba': {
"walletId": "7bd8d22f-d132-43e1-b259-d5b430752553"
},
// join ^
'2df76b91e0080f1552926b7d3ce5dd99db054bc4dfce309d8455cab5d9a93ad4': {
"copayerId": "3d4eb9b439eee1b2b73cf792eda52e420f4665109c7234a50cf3cdbf296ea8fb",
"wallet": {
"version": "1.0.0",
"createdOn": 1463511645,
"id": "7bd8d22f-d132-43e1-b259-d5b430752553",
"name": "{\"iv\":\"BZQVWAP6d1e4G8Fq1rQKbA==\",\"v\":1,\"iter\":1,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":\"70OA+k4+xTPxim+QSdDtA5/Cf055\"}",
"m": 2,
"n": 2,
"status": "pending",
"publicKeyRing": [],
"copayers": [{
"version": 2,
"createdOn": 1463511988,
"xPubKey": "xpub6CkPnrzSUp9qzBVM3hpo4oS2JKC6GJq6brE1yW59QrnhDpvkFLakpxUGRGXH62fiXb5S2VbnD4h2DLoCMfSkwfonbNgNYTJw9Ko5SqWEqCR",
"id": "3d4eb9b439eee1b2b73cf792eda52e420f4665109c7234a50cf3cdbf296ea8fb",
"name": "{\"iv\":\"BZQVWAP6d1e4G8Fq1rQKbA==\",\"v\":1,\"iter\":1,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":\"wwZd+2LQgYR6cA==\"}",
"requestPubKey": "022941a5ecb8c7224f812ad6b03bd1c9bb77861080b21703eabe18ef9a72b48e72",
"signature": "30440220521623cf346f667658c00f1dea113407f23cecf02932c7dcb4b8bf35f1836b7a02202c77b8e4260942f4e13a58faae1f92e1130bae1157492056347e66741150eb2c",
"requestPubKeys": [{
"key": "022941a5ecb8c7224f812ad6b03bd1c9bb77861080b21703eabe18ef9a72b48e72",
"signature": "30440220521623cf346f667658c00f1dea113407f23cecf02932c7dcb4b8bf35f1836b7a02202c77b8e4260942f4e13a58faae1f92e1130bae1157492056347e66741150eb2c"
}],
"customData": "{\"iv\":\"BZQVWAP6d1e4G8Fq1rQKbA==\",\"v\":1,\"iter\":1,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":\"YJqN/LtkCY0cOB235RtbGEAY7wKGT0cUUpAvUeLkAUKz3/1axsYZtnG+PU0jHtwQvgmKNLkNcXNR60K+tyRpU0TG1z8pyx4gKwwD3Dt7KzA=\"}"
}],
"pubKey": "026d95bb5cc2a30c19e22379ae78b4757aaa2dd0ccbd15a1db054fb50cb98ed361",
"network": "livenet",
"derivationStrategy": "BIP44",
"addressType": "P2SH",
"addressManager": {
"version": 2,
"derivationStrategy": "BIP44",
"receiveAddressIndex": 0,
"changeAddressIndex": 0,
"copayerIndex": 2147483647
},
"scanStatus": null
}
},
}; // TODO: Read from file
beforeEach(function(done){
mocks.init(fixtures, 'createController', {}, done);
})
afterEach(function(done){
mocks.clear({}, done);
});
it('should be defined', function() {
should.exist(ctrl);
});
it('should create a 1-1 wallet from mnemonic', function(done) {
var fakeForm = {};
// FROM DATA
scope.seedSource = {
id: 'set'
};
scope.requiredCopayers = 1;
scope.totalCopayers = 1
scope.walletName = 'A test wallet';
scope.isTestnet = false;
scope.bwsurl = null;
scope.privateKey = 'legal winner thank year wave sausage worth useful legal winner thank yellow';
scope._walletPrivKey = 'Kz4CFSTgLzoYfMkt97BTBotUbZYXjMts6Ej9HbVfCf5oLmun1BXy';
ctrl.setSeedSource();
ctrl.create(fakeForm);
should.not.exist(ctrl.error);
mocks.go.walletHome.calledOnce.should.equal(true);
// check resulting profile
storageService.getProfile(function(err, profile) {
should.not.exist(err);
var c = profile.credentials[0];
c.network.should.equal('livenet');
// from test vectors from https://dcpos.github.io/bip39/
c.xPrivKey.should.equal('xprv9s21ZrQH143K2x4gnzRB1eZDq92Uuvy9CXbvgQGdvykXZ9mkkot6LBjzDpgaAfvzkuxJe9JKJXQ38VoPutxvACA5MsyoBs5UyQ4HZKGshGs');
done();
});
});
it('should create an incomplete 2-2 wallet from mnemonic', function(done) {
var fakeForm = {};
// FROM DATA
scope.seedSource = {
id: 'set'
};
scope.requiredCopayers = 2;
scope.totalCopayers = 2;
scope.walletName = 'A test wallet';
scope.isTestnet = false;
scope.bwsurl = null;
scope.privateKey = 'dizzy cycle skirt decrease exotic fork sure mixture hair vapor copper hero';
scope._walletPrivKey = 'Kz4CFSTgLzoYfMkt97BTBotUbZYXjMts6Ej9HbVfCf5oLmun1BXy';
ctrl.setSeedSource();
ctrl.create(fakeForm);
should.not.exist(ctrl.error);
mocks.go.walletHome.calledOnce.should.equal(true, 'Go Wallet Home Called');
// check resulting profile
storageService.getProfile(function(err, profile) {
should.not.exist(err);
var c = profile.credentials[0];
c.network.should.equal('livenet');
// from test vectors from https://dcpos.github.io/bip39/
c.xPrivKey.should.equal('xprv9s21ZrQH143K27bhzfejhNcitEAJgLKCfdLxwhr1FLu43FLqLwscAxXgmkucpF4k8eGmepSctkiQDbcR98Qd1bzSeDuR9jeyQAQEanPT2A4');
// m/44'/0'/0'
c.xPubKey.should.equal('xpub6CkPnrzSUp9qzBVM3hpo4oS2JKC6GJq6brE1yW59QrnhDpvkFLakpxUGRGXH62fiXb5S2VbnD4h2DLoCMfSkwfonbNgNYTJw9Ko5SqWEqCR');
done();
});
});
});

View file

@ -0,0 +1,110 @@
describe('importController', function() {
var walletService;
var storeProfile;
var fixtures = {
'4599136eff6deb4c9c78043fa84113617a16d75c45920d662305f6227ae8f0a0': {
"wallet": {
"version": "1.0.0",
"createdOn": 1463488747,
"id": "267bfa75-5575-4af7-8aa3-f5186bc99262",
"name": "{\"iv\":\"BZQVWAP6d1e4G8Fq1rQKbA==\",\"v\":1,\"iter\":1,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":\"70OA+k4+xTPxim+QSdDtA5/Cf055\"}",
"m": 1,
"n": 1,
"status": "complete",
"publicKeyRing": [{
"xPubKey": "xpub6DRjAgkh3vGTWDcEmDp4TPwy48Nu8yrp6swCEdCCLL615CgnZon7r3vXYr8LYibMLJh5DriGSito1FRBwVoBkjD1ZWG4dmgiC935wLj3nQC",
"requestPubKey": "02befcc7499abcecf9608bb05e665f374434a89ca0c4e9baeab7dd28c027143458"
}],
"copayers": [{
"version": 2,
"createdOn": 1463490295,
"id": "a9dcee10fe9c611300e6c7926ece20780f89b9a98baaa342928038b5503ed929",
"name": "{\"iv\":\"BZQVWAP6d1e4G8Fq1rQKbA==\",\"v\":1,\"iter\":1,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":\"wwZd+2LQgYR6cA==\"}",
"xPubKey": "xpub6DRjAgkh3vGTWDcEmDp4TPwy48Nu8yrp6swCEdCCLL615CgnZon7r3vXYr8LYibMLJh5DriGSito1FRBwVoBkjD1ZWG4dmgiC935wLj3nQC",
"requestPubKey": "02befcc7499abcecf9608bb05e665f374434a89ca0c4e9baeab7dd28c027143458",
"signature": "3044022042e069126a42f1b9b498c315a825ef4fc9f4214156442651e4fef5c7678245e702205936045d7b22baa36ba36ef827cc3e5d542d57d9a1afb3a54080d12f0b95c67e",
"requestPubKeys": [{
"key": "02befcc7499abcecf9608bb05e665f374434a89ca0c4e9baeab7dd28c027143458",
"signature": "3044022042e069126a42f1b9b498c315a825ef4fc9f4214156442651e4fef5c7678245e702205936045d7b22baa36ba36ef827cc3e5d542d57d9a1afb3a54080d12f0b95c67e"
}],
"customData": "{\"iv\":\"BZQVWAP6d1e4G8Fq1rQKbA==\",\"v\":1,\"iter\":1,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":\"1Wjf2KvFkd5k0ypiiSNkSVXk7zdBOiTeCrwzPBI7fMQ/VqXUzrSB6gMGs9jISr+MvCaL1GJIXjaMnlQZNMR0lx/Pd1c6R/nKGBdHjKh0mlI=\"}"
}],
"pubKey": "026d95bb5cc2a30c19e22379ae78b4757aaa2dd0ccbd15a1db054fb50cb98ed361",
"network": "livenet",
"derivationStrategy": "BIP44",
"addressType": "P2PKH",
"addressManager": {
"version": 2,
"derivationStrategy": "BIP44",
"receiveAddressIndex": 0,
"changeAddressIndex": 0,
"copayerIndex": 2147483647
},
"scanStatus": null
},
"preferences": {},
"pendingTxps": [],
"balance": {
"totalAmount": 0,
"lockedAmount": 0,
"totalConfirmedAmount": 0,
"lockedConfirmedAmount": 0,
"availableAmount": 0,
"availableConfirmedAmount": 0,
"byAddress": [],
"totalBytesToSendMax": 0,
"totalBytesToSendConfirmedMax": 0
}
}
}; // TODO: Read from file
beforeEach(function(done){
mocks.init(fixtures, 'importController', {}, done);
})
afterEach(function(done){
mocks.clear({}, done);
});
it('should be defined', function() {
should.exist(ctrl);
});
it('should import a 1-1 wallet from mnemonic', function(done) {
var fakeForm = {
words: {
$modelValue: 'legal winner thank year wave sausage worth useful legal winner thank yellow'
},
passphrase: {}
};
// FROM DATA
scope.seedSource = {
id: 'set'
};
scope.bwsurl = null;
scope._walletPrivKey = 'Kz4CFSTgLzoYfMkt97BTBotUbZYXjMts6Ej9HbVfCf5oLmun1BXy';
ctrl.setSeedSource();
ctrl.importMnemonic(fakeForm);
should.not.exist(ctrl.error);
mocks.notification.success.calledOnce.should.equal(true);
// mocks.go.walletHome.calledOnce.should.equal(true);
// check resulting profile
storageService.getProfile(function(err, profile) {
should.not.exist(err);
var c = profile.credentials[0];
c.network.should.equal('livenet');
// from test vectors from https://dcpos.github.io/bip39/
c.xPrivKey.should.equal('xprv9s21ZrQH143K2x4gnzRB1eZDq92Uuvy9CXbvgQGdvykXZ9mkkot6LBjzDpgaAfvzkuxJe9JKJXQ38VoPutxvACA5MsyoBs5UyQ4HZKGshGs');
done();
});
});
});

View file

@ -0,0 +1,71 @@
describe('index', function() {
var walletService;
describe('Incomplete wallet', function() {
beforeEach(function(done) {
mocks.init(FIXTURES, 'indexController', {
loadProfile: PROFILE.incomplete2of2,
initController: true,
}, done);
});
afterEach(function(done) {
mocks.clear({}, done);
});
it('should be defined', function() {
should.exist(ctrl);
});
it('should set the invitation code for incomplete wallets', function(done) {
should.exist(ctrl);
ctrl.walletSecret.should.equal('GJ1A8mopdW7wPNWGVksqwQKz4CFSTgLzoYfMkt97BTBotUbZYXjMts6Ej9HbVfCf5oLmun1BXyL');
// should redirect to copayers
mocks.go.path.getCall(0).args[0].should.equal('copayers');
done();
});
});
describe('Complete 1-1 wallet', function() {
beforeEach(function(done) {
mocks.init(FIXTURES, 'indexController', {
loadProfile: PROFILE.testnet1of1,
initController: true,
}, done);
});
afterEach(function(done) {
mocks.clear({}, done);
});
it('should not set the invitation code for complete wallets', function() {
// should redirect to copayers
mocks.go.path.callCount.should.equal(0);
should.not.exist(ctrl.walletSecret);
});
it('should set main wallet info', function(done) {
ctrl.walletName.should.equal('kk');
ctrl.totalBalanceSat.should.equal(1847686);
done();
});
it('should set information for receive tab', function(done) {
ctrl.tab.should.equal('walletHome');
ctrl.setTab('receive');
ctrl.tab.should.equal('receive');
done();
});
it('should updates remote preferences', function(done) {
ctrl.updateRemotePreferences({}, function() {
done();
});
});
});
});

View file

@ -0,0 +1,72 @@
describe('joinController', function() {
var walletService;
var fakeNotification = {};
mocks.init({}, 'joinController');
// Init config
beforeEach(function(done) {
inject(function($rootScope, $controller, _configService_, _profileService_) {
scope = $rootScope.$new();
_configService_.get(function() {
join = $controller('joinController', {
$scope: scope,
$modal: mocks.fakeModal,
notification: fakeNotification,
configService: _configService_,
profileService: _profileService_,
});
done();
});
});
});
it.skip('should be defined', function() {
should.exist(join);
});
// // Get html template from cache
// beforeEach(inject(function($templateCache) {
// viewHtml = $templateCache.get("some/valid/templateUrl");
// }));
// // beforeEach(inject(function(_$compile_, _$rootScope_){
// $compile = _$compile_;
// $rootScope = _$rootScope_;
//
// $scope = $rootScope.$new();
// $scope.user = {};
// $scope.logout = sinon.stub();
// dropdownElement = angular.element(viewHtml);
// }));
it.skip('should join a wallet once the form is submitted', function(done) {
// View's joinForm is not available
//join.onQrCodeScanned('aQRCode');
var fakeForm = {
secret: {
$modelValue: 'anInvitationCode'
},
myName: {
$modelValue: 'myCopayerName'
},
bwsurl: 'aFakeURL',
createPassphrase: {
$modelValue: null
},
};
join.join(fakeForm);
should.not.exist(join.error);
});
});

View file

@ -0,0 +1,20 @@
describe('walletHome', function() {
var walletService;
var fixtures = {};
beforeEach(function(done){
mocks.init(fixtures, 'walletHomeController', {}, done);
})
afterEach(function(done){
mocks.clear({}, done);
});
it('should be defined', function() {
should.exist(ctrl);
});
});