From ab9e15b782620002c0a2477829db3e56a25a7d5c Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 8 Dec 2016 14:22:02 -0800 Subject: Mostly added bad account detection Currently riddled with logs, because the migrator is inexplicably returning before generating the new style accounts for comparison. --- test/unit/idStore-migration-test.js | 32 ++++++-------------------------- test/unit/keyring-controller-test.js | 15 --------------- 2 files changed, 6 insertions(+), 41 deletions(-) (limited to 'test/unit') diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js index ac8e23d22..2ea5cc36f 100644 --- a/test/unit/idStore-migration-test.js +++ b/test/unit/idStore-migration-test.js @@ -21,6 +21,10 @@ const mockVault = { account: '0x5d8de92c205279c10e5669f797b853ccef4f739a', } +const badVault = { + seed: 'radar blur cabbage chef fix engine embark joy scheme fiction master release', +} + describe('IdentityStore to KeyringController migration', function() { // The stars of the show: @@ -79,33 +83,9 @@ describe('IdentityStore to KeyringController migration', function() { keyringController.configManager.setWallet('something') const state = keyringController.getState() assert(state.isInitialized, 'old vault counted as initialized.') + console.dir(state) + assert.equal(state.lostAccounts.length, 0, 'no lost accounts') }) - - /* - it('should use the password to migrate the old vault', function(done) { - this.timeout(5000) - console.log('calling submitPassword') - console.dir(keyringController) - keyringController.submitPassword(password, function (err, state) { - assert.ifError(err, 'submitPassword threw error') - - function log(str, dat) { console.log(str + ': ' + JSON.stringify(dat)) } - - let newAccounts = keyringController.getAccounts() - log('new accounts: ', newAccounts) - - let newAccount = ethUtil.addHexPrefix(newAccounts[0]) - assert.equal(ethUtil.addHexPrefix(newAccount), mockVault.account, 'restored the correct account') - const newSeed = keyringController.keyrings[0].mnemonic - log('keyringController keyrings', keyringController.keyrings) - assert.equal(newSeed, mockVault.seed, 'seed phrase transferred.') - - assert(configManager.getVault(), 'new type of vault is persisted') - done() - }) - }) - */ - }) }) diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js index 69a57ef52..8bb1126fa 100644 --- a/test/unit/keyring-controller-test.js +++ b/test/unit/keyring-controller-test.js @@ -95,21 +95,6 @@ describe('KeyringController', function() { }) }) - describe('#migrateOldVaultIfAny', function() { - it('should return and init a new vault', function(done) { - keyringController.migrateOldVaultIfAny(password) - .then(() => { - assert(keyringController.configManager.getVault(), 'now has a vault') - assert(keyringController.password, 'has a password set') - done() - }) - .catch((reason) => { - assert.ifError(reason) - done() - }) - }) - }) - describe('#createNickname', function() { it('should add the address to the identities hash', function() { const fakeAddress = '0x12345678' -- cgit v1.2.3 From 8819475a2ed2ee7c34e983ebb5ab12661be1a961 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 7 Dec 2016 14:34:15 -0800 Subject: Add ability to show notices to user & get confirmation. Implement generation of markdown for notice files. Create npm command. Enhance notice generation. Add test files to test multiple notices. Add basic markdown support to notices. Interval checks for updates. Add extensionizer and linker Add terms and conditions state file Add link support to disclaimer. Changelog addition. --- test/unit/config-manager-test.js | 95 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) (limited to 'test/unit') diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index 6aa7146f0..4283c516c 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -3,6 +3,7 @@ const extend = require('xtend') const STORAGE_KEY = 'metamask-persistance-key' var configManagerGen = require('../lib/mock-config-manager') var configManager +var testList const rp = require('request-promise') const nock = require('nock') @@ -13,6 +14,100 @@ describe('config-manager', function() { configManager = configManagerGen() }) + describe('notices', function() { + describe('#getNoticesList', function() { + it('should return an empty array when new', function() { + var testList = [{ + id:0, + read:false, + title:"Futuristic Notice" + }] + var result = configManager.getNoticesList() + assert.equal(result.length, 0) + }) + }) + + describe('#setNoticesList', function() { + it('should set data appropriately', function () { + var testList = [{ + id:0, + read:false, + title:"Futuristic Notice" + }] + configManager.setNoticesList(testList) + var testListId = configManager.getNoticesList()[0].id + assert.equal(testListId, 0) + }) + }) + + describe('#updateNoticeslist', function() { + it('should integrate the latest changes from the source', function() { + var testList = [{ + id:55, + read:false, + title:"Futuristic Notice" + }] + configManager.setNoticesList(testList) + configManager.updateNoticesList().then(() => { + var newList = configManager.getNoticesList() + assert.ok(newList[0].id === 55) + assert.ok(newList[1]) + }) + }) + it('should not overwrite any existing fields', function () { + var testList = [{ + id:0, + read:false, + title:"Futuristic Notice" + }] + configManager.setNoticesList(testList) + configManager.updateNoticesList().then(() => { + var newList = configManager.getNoticesList() + assert.equal(newList[0].id, 0) + assert.equal(newList[0].title, "Futuristic Notice") + assert.equal(newList.length, 1) + }) + }) + }) + + describe('#markNoticeRead', function () { + it('should mark a notice as read', function () { + var testList = [{ + id:0, + read:false, + title:"Futuristic Notice" + }] + configManager.setNoticesList(testList) + configManager.markNoticeRead(testList[0]) + var newList = configManager.getNoticesList() + assert.ok(newList[0].read) + }) + }) + + describe('#getLatestUnreadNotice', function () { + it('should retrieve the latest unread notice', function () { + var testList = [ + {id:0,read:true,title:"Past Notice"}, + {id:1,read:false,title:"Current Notice"}, + {id:2,read:false,title:"Future Notice"}, + ] + configManager.setNoticesList(testList) + var latestUnread = configManager.getLatestUnreadNotice() + assert.equal(latestUnread.id, 2) + }) + it('should return undefined if no unread notices exist.', function () { + var testList = [ + {id:0,read:true,title:"Past Notice"}, + {id:1,read:true,title:"Current Notice"}, + {id:2,read:true,title:"Future Notice"}, + ] + configManager.setNoticesList(testList) + var latestUnread = configManager.getLatestUnreadNotice() + assert.ok(!latestUnread) + }) + }) + }) + describe('currency conversions', function() { describe('#getCurrentFiat', function() { -- cgit v1.2.3 From 4c390a622137b34687866ce0ec937b8dd54a3c1a Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 16 Dec 2016 11:58:15 -0800 Subject: clean - code style --- test/unit/config-manager-test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'test/unit') diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index 4283c516c..409a7b3f7 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -1,13 +1,12 @@ const assert = require('assert') const extend = require('xtend') -const STORAGE_KEY = 'metamask-persistance-key' -var configManagerGen = require('../lib/mock-config-manager') -var configManager -var testList const rp = require('request-promise') const nock = require('nock') +var configManagerGen = require('../lib/mock-config-manager') +const STORAGE_KEY = 'metamask-persistance-key' describe('config-manager', function() { + var configManager beforeEach(function() { window.localStorage = {} // Hacking localStorage support into JSDom -- cgit v1.2.3 From 73998feeb2b6ba4ebb9a16c6ed54cce195c09013 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 16 Dec 2016 12:44:47 -0800 Subject: move notice code from metamask-controller + config-manager, in to notice-controller --- test/unit/config-manager-test.js | 94 ----------------------------- test/unit/notice-controller-test.js | 115 ++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 94 deletions(-) create mode 100644 test/unit/notice-controller-test.js (limited to 'test/unit') diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index 409a7b3f7..26aa35a74 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -13,100 +13,6 @@ describe('config-manager', function() { configManager = configManagerGen() }) - describe('notices', function() { - describe('#getNoticesList', function() { - it('should return an empty array when new', function() { - var testList = [{ - id:0, - read:false, - title:"Futuristic Notice" - }] - var result = configManager.getNoticesList() - assert.equal(result.length, 0) - }) - }) - - describe('#setNoticesList', function() { - it('should set data appropriately', function () { - var testList = [{ - id:0, - read:false, - title:"Futuristic Notice" - }] - configManager.setNoticesList(testList) - var testListId = configManager.getNoticesList()[0].id - assert.equal(testListId, 0) - }) - }) - - describe('#updateNoticeslist', function() { - it('should integrate the latest changes from the source', function() { - var testList = [{ - id:55, - read:false, - title:"Futuristic Notice" - }] - configManager.setNoticesList(testList) - configManager.updateNoticesList().then(() => { - var newList = configManager.getNoticesList() - assert.ok(newList[0].id === 55) - assert.ok(newList[1]) - }) - }) - it('should not overwrite any existing fields', function () { - var testList = [{ - id:0, - read:false, - title:"Futuristic Notice" - }] - configManager.setNoticesList(testList) - configManager.updateNoticesList().then(() => { - var newList = configManager.getNoticesList() - assert.equal(newList[0].id, 0) - assert.equal(newList[0].title, "Futuristic Notice") - assert.equal(newList.length, 1) - }) - }) - }) - - describe('#markNoticeRead', function () { - it('should mark a notice as read', function () { - var testList = [{ - id:0, - read:false, - title:"Futuristic Notice" - }] - configManager.setNoticesList(testList) - configManager.markNoticeRead(testList[0]) - var newList = configManager.getNoticesList() - assert.ok(newList[0].read) - }) - }) - - describe('#getLatestUnreadNotice', function () { - it('should retrieve the latest unread notice', function () { - var testList = [ - {id:0,read:true,title:"Past Notice"}, - {id:1,read:false,title:"Current Notice"}, - {id:2,read:false,title:"Future Notice"}, - ] - configManager.setNoticesList(testList) - var latestUnread = configManager.getLatestUnreadNotice() - assert.equal(latestUnread.id, 2) - }) - it('should return undefined if no unread notices exist.', function () { - var testList = [ - {id:0,read:true,title:"Past Notice"}, - {id:1,read:true,title:"Current Notice"}, - {id:2,read:true,title:"Future Notice"}, - ] - configManager.setNoticesList(testList) - var latestUnread = configManager.getLatestUnreadNotice() - assert.ok(!latestUnread) - }) - }) - }) - describe('currency conversions', function() { describe('#getCurrentFiat', function() { diff --git a/test/unit/notice-controller-test.js b/test/unit/notice-controller-test.js new file mode 100644 index 000000000..4aa4c8e7b --- /dev/null +++ b/test/unit/notice-controller-test.js @@ -0,0 +1,115 @@ +const assert = require('assert') +const extend = require('xtend') +const rp = require('request-promise') +const nock = require('nock') +const configManagerGen = require('../lib/mock-config-manager') +const NoticeController = require('../../app/scripts/notice-controller') +const STORAGE_KEY = 'metamask-persistance-key' +// Hacking localStorage support into JSDom +window.localStorage = {} + +describe('notice-controller', function() { + var noticeController + + beforeEach(function() { + let configManager = configManagerGen() + noticeController = new NoticeController({ + configManager: configManager, + }) + }) + + describe('notices', function() { + describe('#getNoticesList', function() { + it('should return an empty array when new', function() { + var testList = [{ + id:0, + read:false, + title:"Futuristic Notice" + }] + var result = noticeController.getNoticesList() + assert.equal(result.length, 0) + }) + }) + + describe('#setNoticesList', function() { + it('should set data appropriately', function () { + var testList = [{ + id:0, + read:false, + title:"Futuristic Notice" + }] + noticeController.setNoticesList(testList) + var testListId = noticeController.getNoticesList()[0].id + assert.equal(testListId, 0) + }) + }) + + describe('#updateNoticeslist', function() { + it('should integrate the latest changes from the source', function() { + var testList = [{ + id:55, + read:false, + title:"Futuristic Notice" + }] + noticeController.setNoticesList(testList) + noticeController.updateNoticesList().then(() => { + var newList = noticeController.getNoticesList() + assert.ok(newList[0].id === 55) + assert.ok(newList[1]) + }) + }) + it('should not overwrite any existing fields', function () { + var testList = [{ + id:0, + read:false, + title:"Futuristic Notice" + }] + noticeController.setNoticesList(testList) + noticeController.updateNoticesList().then(() => { + var newList = noticeController.getNoticesList() + assert.equal(newList[0].id, 0) + assert.equal(newList[0].title, "Futuristic Notice") + assert.equal(newList.length, 1) + }) + }) + }) + + describe('#markNoticeRead', function () { + it('should mark a notice as read', function () { + var testList = [{ + id:0, + read:false, + title:"Futuristic Notice" + }] + noticeController.setNoticesList(testList) + noticeController.markNoticeRead(testList[0]) + var newList = noticeController.getNoticesList() + assert.ok(newList[0].read) + }) + }) + + describe('#getLatestUnreadNotice', function () { + it('should retrieve the latest unread notice', function () { + var testList = [ + {id:0,read:true,title:"Past Notice"}, + {id:1,read:false,title:"Current Notice"}, + {id:2,read:false,title:"Future Notice"}, + ] + noticeController.setNoticesList(testList) + var latestUnread = noticeController.getLatestUnreadNotice() + assert.equal(latestUnread.id, 2) + }) + it('should return undefined if no unread notices exist.', function () { + var testList = [ + {id:0,read:true,title:"Past Notice"}, + {id:1,read:true,title:"Current Notice"}, + {id:2,read:true,title:"Future Notice"}, + ] + noticeController.setNoticesList(testList) + var latestUnread = noticeController.getLatestUnreadNotice() + assert.ok(!latestUnread) + }) + }) + }) + +}) -- cgit v1.2.3 From 20d2204ce6a9e8dcd3269c588b2f4ce6ff93408b Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 19 Dec 2016 16:29:44 -0800 Subject: Made changes according to feedback. --- test/unit/idStore-migration-test.js | 1 - 1 file changed, 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js index 2ea5cc36f..66dd4683d 100644 --- a/test/unit/idStore-migration-test.js +++ b/test/unit/idStore-migration-test.js @@ -83,7 +83,6 @@ describe('IdentityStore to KeyringController migration', function() { keyringController.configManager.setWallet('something') const state = keyringController.getState() assert(state.isInitialized, 'old vault counted as initialized.') - console.dir(state) assert.equal(state.lostAccounts.length, 0, 'no lost accounts') }) }) -- cgit v1.2.3