aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2016-12-22 06:31:07 +0800
committerGitHub <noreply@github.com>2016-12-22 06:31:07 +0800
commit6f7c23fd28ef37ae51478b735c1f5888c97bbaf5 (patch)
treeb927871ed00c33a66341a26de09f00cf006314b8 /test
parenta85c691b71d5142d2412000930328fbe9161760a (diff)
parent73cdf0bfd49470bad1f0da4d0d894278c87af54e (diff)
downloadtangerine-wallet-browser-6f7c23fd28ef37ae51478b735c1f5888c97bbaf5.tar
tangerine-wallet-browser-6f7c23fd28ef37ae51478b735c1f5888c97bbaf5.tar.gz
tangerine-wallet-browser-6f7c23fd28ef37ae51478b735c1f5888c97bbaf5.tar.bz2
tangerine-wallet-browser-6f7c23fd28ef37ae51478b735c1f5888c97bbaf5.tar.lz
tangerine-wallet-browser-6f7c23fd28ef37ae51478b735c1f5888c97bbaf5.tar.xz
tangerine-wallet-browser-6f7c23fd28ef37ae51478b735c1f5888c97bbaf5.tar.zst
tangerine-wallet-browser-6f7c23fd28ef37ae51478b735c1f5888c97bbaf5.zip
Merge branch 'dev' into TxManager
Diffstat (limited to 'test')
-rw-r--r--test/integration/lib/encryptor-test.js71
-rw-r--r--test/integration/lib/keyring-controller-test.js60
-rw-r--r--test/integration/mocks/badVault.json1
-rw-r--r--test/unit/config-manager-test.js6
-rw-r--r--test/unit/idStore-migration-test.js31
-rw-r--r--test/unit/keyring-controller-test.js15
-rw-r--r--test/unit/notice-controller-test.js115
7 files changed, 184 insertions, 115 deletions
diff --git a/test/integration/lib/encryptor-test.js b/test/integration/lib/encryptor-test.js
deleted file mode 100644
index 897d22740..000000000
--- a/test/integration/lib/encryptor-test.js
+++ /dev/null
@@ -1,71 +0,0 @@
-var encryptor = require('../../../app/scripts/lib/encryptor')
-
-QUnit.module('encryptor')
-
-QUnit.test('encryptor:serializeBufferForStorage', function (assert) {
- assert.expect(1)
- var buf = new Buffer(2)
- buf[0] = 16
- buf[1] = 1
-
- var output = encryptor.serializeBufferForStorage(buf)
-
- var expect = '0x1001'
- assert.equal(expect, output)
-})
-
-QUnit.test('encryptor:serializeBufferFromStorage', function (assert) {
- assert.expect(2)
- var input = '0x1001'
- var output = encryptor.serializeBufferFromStorage(input)
-
- assert.equal(output[0], 16)
- assert.equal(output[1], 1)
-})
-
-QUnit.test('encryptor:encrypt & decrypt', function(assert) {
- var done = assert.async();
- var password, data, encrypted
-
- password = 'a sample passw0rd'
- data = { foo: 'data to encrypt' }
-
- encryptor.encrypt(password, data)
- .then(function(encryptedStr) {
- assert.equal(typeof encryptedStr, 'string', 'returns a string')
- return encryptor.decrypt(password, encryptedStr)
- })
- .then(function (decryptedObj) {
- assert.deepEqual(decryptedObj, data, 'decrypted what was encrypted')
- done()
- })
- .catch(function(reason) {
- assert.ifError(reason, 'threw an error')
- done(reason)
- })
-
-})
-
-QUnit.test('encryptor:encrypt & decrypt with wrong password', function(assert) {
- var done = assert.async();
- var password, data, encrypted, wrongPassword
-
- password = 'a sample passw0rd'
- wrongPassword = 'a wrong password'
- data = { foo: 'data to encrypt' }
-
- encryptor.encrypt(password, data)
- .then(function(encryptedStr) {
- assert.equal(typeof encryptedStr, 'string', 'returns a string')
- return encryptor.decrypt(wrongPassword, encryptedStr)
- })
- .then(function (decryptedObj) {
- assert.equal(!decryptedObj, true, 'Wrong password should not decrypt')
- done()
- })
- .catch(function(reason) {
- done()
- })
-})
-
-
diff --git a/test/integration/lib/keyring-controller-test.js b/test/integration/lib/keyring-controller-test.js
index 2d16e2f95..314641841 100644
--- a/test/integration/lib/keyring-controller-test.js
+++ b/test/integration/lib/keyring-controller-test.js
@@ -2,11 +2,14 @@ var KeyringController = require('../../../app/scripts/keyring-controller')
var ConfigManager = require('../../../app/scripts/lib/config-manager')
var oldStyleVault = require('../mocks/oldVault.json')
+var badStyleVault = require('../mocks/badVault.json')
var STORAGE_KEY = 'metamask-config'
var PASSWORD = '12345678'
var FIRST_ADDRESS = '0x4dd5d356c5A016A220bCD69e82e5AF680a430d00'.toLowerCase()
+var BAD_STYLE_FIRST_ADDRESS = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9'
+
QUnit.module('Old Style Vaults', {
beforeEach: function () {
@@ -45,6 +48,63 @@ QUnit.test('keyringController:submitPassword', function (assert) {
this.keyringController.submitPassword(PASSWORD)
.then((state) => {
assert.ok(state.identities[FIRST_ADDRESS])
+ assert.equal(state.lostAccounts.length, 0, 'no lost accounts')
+ done()
+ })
+})
+
+QUnit.test('keyringController:setLocked', function (assert) {
+ var done = assert.async()
+ var self = this
+
+ this.keyringController.setLocked()
+ .then(function() {
+ assert.notOk(self.keyringController.password, 'password should be deallocated')
+ assert.deepEqual(self.keyringController.keyrings, [], 'keyrings should be deallocated')
+ done()
+ })
+ .catch((reason) => {
+ assert.ifError(reason)
+ done()
+ })
+})
+
+QUnit.module('Old Style Vaults with bad HD seed', {
+ beforeEach: function () {
+ window.localStorage[STORAGE_KEY] = JSON.stringify(badStyleVault)
+
+ this.configManager = new ConfigManager({
+ loadData: () => { return JSON.parse(window.localStorage[STORAGE_KEY]) },
+ setData: (data) => { window.localStorage[STORAGE_KEY] = JSON.stringify(data) },
+ })
+
+ this.keyringController = new KeyringController({
+ configManager: this.configManager,
+ getNetwork: () => { return '2' },
+ })
+
+ this.ethStore = {
+ addAccount: () => {},
+ removeAccount: () => {},
+ }
+
+ this.keyringController.setStore(this.ethStore)
+ }
+})
+
+QUnit.test('keyringController:isInitialized', function (assert) {
+ assert.ok(this.keyringController.getState().isInitialized, 'vault is initialized')
+})
+
+QUnit.test('keyringController:submitPassword', function (assert) {
+ var done = assert.async()
+
+ this.keyringController.submitPassword(PASSWORD)
+ .then((state) => {
+ assert.ok(state.identities[BAD_STYLE_FIRST_ADDRESS])
+ assert.equal(state.lostAccounts.length, 1, 'one lost account')
+ assert.equal(state.lostAccounts[0], '0xe15D894BeCB0354c501AE69429B05143679F39e0'.toLowerCase())
+ assert.deepEqual(this.configManager.getLostAccounts(), state.lostAccounts, 'persisted')
done()
})
})
diff --git a/test/integration/mocks/badVault.json b/test/integration/mocks/badVault.json
new file mode 100644
index 000000000..a59e4626a
--- /dev/null
+++ b/test/integration/mocks/badVault.json
@@ -0,0 +1 @@
+{"meta":{"version":4},"data":{"fiatCurrency":"USD","conversionRate":8.34908448,"conversionDate":1481227505,"isConfirmed":true,"wallet":"{\"encSeed\":{\"encStr\":\"Te2KyAGY3S01bgUJ+7d4y3BOvr/8TKrXrkRZ29cGI6dgyedtN+YgTQxElC2td/pzuoXm7KeSfr+yAoFCvMgqFAJwRcX3arHOsMFQie8kp8mL5I65zwdg/HB2QecB4OJHytrxgApv2zZiKEo0kbu2cs8zYIn5wNlCBIHwgylYmHpUDIJcO1B4zg==\",\"nonce\":\"xnxqk4iy70bjt721F+KPLV4PNfBFNyct\"},\"ksData\":{\"m/44'/60'/0'/0\":{\"info\":{\"curve\":\"secp256k1\",\"purpose\":\"sign\"},\"encHdPathPriv\":{\"encStr\":\"vNrSjekRKLmaGFf77Uca9+aAebmDlvrBwtAV8YthpQ4OX/mXtLSycmnLsYdk4schaByfJvrm6/Mf9fxzOSaScJk+XvKw5XqNXedkDHtbWrmNnxFpuT+9tuB8Nupr3D9GZK9PgXhJD99/7Bn6Wk7/ne+PIDmbtdmx/SWmrdo3pg==\",\"nonce\":\"zqWq/gtJ5zfUVRWQQJkP/zoYjer6Rozj\"},\"hdIndex\":1,\"encPrivKeys\":{\"e15d894becb0354c501ae69429b05143679f39e0\":{\"key\":\"jBLQ9v1l5LOEY1C3kI8z7LpbJKHP1vpVfPAlz90MNSfa8Oe+XlxKQAGYs8Zb4fWm\",\"nonce\":\"fJyrSRo1t0RMNqp2MsneoJnYJWHQnSVY\"}},\"addresses\":[\"e15d894becb0354c501ae69429b05143679f39e0\"]}},\"encHdRootPriv\":{\"encStr\":\"mbvwiFBQGbjj4BJLmdeYzfYi8jb7gtFtwiCQOPfvmyz4h2/KMbHNGzumM16qRKpifioQXkhnBulMIQHaYg0Jwv1MoFsqHxHmuIAT+QP5XvJjz0MRl6708pHowmIVG+R8CZNTLqzE7XS8YkZ4ElRpTvLEM8Wngi5Sg287mQMP9w==\",\"nonce\":\"i5Tp2lQe92rXQzNhjZcu9fNNhfux6Wf4\"},\"salt\":\"FQpA8D9R/5qSp9WtQ94FILyfWZHMI6YZw6RmBYqK0N0=\",\"version\":2}","config":{"provider":{"type":"testnet"},"selectedAccount":"0xe15d894becb0354c501ae69429b05143679f39e0"},"isEthConfirmed":true,"transactions":[],"TOSHash":"a4f4e23f823a7ac51783e7ffba7914a911b09acdb97263296b7e14b527f80c5b","gasMultiplier":1}}
diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js
index 61226d624..075abbe65 100644
--- a/test/unit/config-manager-test.js
+++ b/test/unit/config-manager-test.js
@@ -1,12 +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
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
diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js
index 639eb0d72..c4a3f3ae4 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:
@@ -83,33 +87,8 @@ describe('IdentityStore to KeyringController migration', function() {
keyringController.configManager.setWallet('something')
const state = keyringController.getState()
assert(state.isInitialized, 'old vault counted as initialized.')
+ 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 a2b65a6b5..37fd7175e 100644
--- a/test/unit/keyring-controller-test.js
+++ b/test/unit/keyring-controller-test.js
@@ -99,21 +99,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'
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)
+ })
+ })
+ })
+
+})