From e4e7489dd9085c4fa2cef9262bc683d605d26b50 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 29 Aug 2016 17:34:12 -0700 Subject: Add test for Edge compatibility --- test/unit/extension-test.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test') diff --git a/test/unit/extension-test.js b/test/unit/extension-test.js index 6b695e835..86e1d887a 100644 --- a/test/unit/extension-test.js +++ b/test/unit/extension-test.js @@ -9,6 +9,34 @@ var Extension = require(path.join(__dirname, '..', '..', 'app', 'scripts', 'lib' describe('extension', function() { + describe('extension.getURL', function() { + const desiredResult = 'http://the-desired-result.io' + + describe('in Chrome or Firefox', function() { + GLOBAL.chrome.extension = { + getURL: () => desiredResult + } + + it('returns the desired result', function() { + const extension = new Extension() + const result = extension.extension.getURL() + assert.equal(result, desiredResult) + }) + }) + + describe('in Microsoft Edge', function() { + GLOBAL.browser.extension = { + getURL: () => desiredResult + } + + it('returns the desired result', function() { + const extension = new Extension() + const result = extension.extension.getURL() + assert.equal(result, desiredResult) + }) + }) + }) + describe('with chrome global', function() { let extension @@ -45,4 +73,5 @@ describe('extension', function() { }) }) + }) -- cgit v1.2.3 From dcc24804a1048e9379ce30233f4ecf540db5a54a Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 6 Sep 2016 15:23:48 -0700 Subject: Add negative value validation to tx approval --- test/unit/metamask-controller-test.js | 97 +++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 test/unit/metamask-controller-test.js (limited to 'test') diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js new file mode 100644 index 000000000..b87169ca2 --- /dev/null +++ b/test/unit/metamask-controller-test.js @@ -0,0 +1,97 @@ +var assert = require('assert') +var MetaMaskController = require('../../app/scripts/metamask-controller') +var sinon = require('sinon') +var extend = require('xtend') +const STORAGE_KEY = 'metamask-config' + +describe('MetaMaskController', function() { + const noop = () => {} + let controller = new MetaMaskController({ + showUnconfirmedMessage: noop, + unlockAccountMessage: noop, + showUnconfirmedTx: noop, + setData, + loadData, + }) + + beforeEach(function() { + // sinon allows stubbing methods that are easily verified + this.sinon = sinon.sandbox.create() + window.localStorage = {} // Hacking localStorage support into JSDom + }) + + afterEach(function() { + // sinon requires cleanup otherwise it will overwrite context + this.sinon.restore() + }) + + describe('#enforceTxValidations', function () { + it('returns null for positive values', function() { + var sample = { + value: '0x01' + } + var res = controller.enforceTxValidations(sample) + assert.equal(res, null, 'no error') + }) + + + it('returns error for negative values', function() { + var sample = { + value: '-0x01' + } + var res = controller.enforceTxValidations(sample) + assert.ok(res, 'error') + }) + }) +}) + + +function loadData () { + var oldData = getOldStyleData() + var newData + try { + newData = JSON.parse(window.localStorage[STORAGE_KEY]) + } catch (e) {} + + var data = extend({ + meta: { + version: 0, + }, + data: { + config: { + provider: { + type: 'testnet', + }, + }, + }, + }, oldData || null, newData || null) + return data +} + +function getOldStyleData () { + var config, wallet, seedWords + + var result = { + meta: { version: 0 }, + data: {}, + } + + try { + config = JSON.parse(window.localStorage['config']) + result.data.config = config + } catch (e) {} + try { + wallet = JSON.parse(window.localStorage['lightwallet']) + result.data.wallet = wallet + } catch (e) {} + try { + seedWords = window.localStorage['seedWords'] + result.data.seedWords = seedWords + } catch (e) {} + + return result +} + +function setData (data) { + window.localStorage[STORAGE_KEY] = JSON.stringify(data) +} -- cgit v1.2.3 From 36dc63bc048e62b5ef0d1b0385e530afdad3fefa Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 9 Sep 2016 19:42:18 -0700 Subject: Add new eth-lightwallet salting to vault. eth-lightwallet was previously not salting vault passwords, potentially making it easier to crack them once obtained. This branch incorporates the API changes to allow us to take advantage of the new salting logic. This is still throwing deprecation warnings, but that's actually a bug in eth-lightwallet I wrote, [I've submitted a PR for that here](https://github.com/ConsenSys/eth-lightwallet/pull/116). Fixes #555 --- test/unit/idStore-test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index ee4613236..cbbec43b5 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -23,6 +23,7 @@ describe('IdentityStore', function() { }) idStore.createNewVault(password, entropy, (err, seeds) => { + assert.ifError(err, 'createNewVault threw error') seedWords = seeds originalKeystore = idStore._idmgmt.keyStore done() @@ -59,6 +60,7 @@ describe('IdentityStore', function() { describe('#recoverFromSeed BIP44 compliance', function() { let seedWords = 'picnic injury awful upper eagle junk alert toss flower renew silly vague' let firstAccount = '0x5d8de92c205279c10e5669f797b853ccef4f739a' + const salt = 'lightwalletSalt' let password = 'secret!' let accounts = [] @@ -70,7 +72,7 @@ describe('IdentityStore', function() { idStore = new IdentityStore({ configManager: configManagerGen(), ethStore: { - addAccount(acct) { accounts.push(acct) }, + addAccount(acct) { accounts.push('0x' + acct) }, }, }) }) -- cgit v1.2.3 From 6763871c416001e19c224b90a99ed7d9ece69158 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 11:46:50 -0700 Subject: Captured #640 in failing test --- test/unit/idStore-test.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index cbbec43b5..3d28ddf90 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -83,8 +83,19 @@ describe('IdentityStore', function() { assert.ifError(err) let newKeystore = idStore._idmgmt.keyStore + assert.equal(accounts[0], firstAccount) - done() + + accounts = [] + const secondSeed = 'radar blur cabbage chef fix engine embark joy scheme fiction master release' + const secondAcct = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' + + idStore.recoverFromSeed(password, secondSeed, (err) => { + + let accounts = idStore._getAddresses() + assert.equal(accounts[0], secondAcct) + done() + }) }) }) }) -- cgit v1.2.3 From 59fd86383fbf379724c3bcca6da9d5a6192bbcf2 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 12:08:27 -0700 Subject: Correctly clear ethStore cache on new vault restore --- test/unit/idStore-test.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 3d28ddf90..422db6f7b 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -1,6 +1,7 @@ var assert = require('assert') var IdentityStore = require('../../app/scripts/lib/idStore') var configManagerGen = require('../lib/mock-config-manager') +const ethUtil = require('ethereumjs-util') describe('IdentityStore', function() { @@ -18,7 +19,7 @@ describe('IdentityStore', function() { idStore = new IdentityStore({ configManager: configManagerGen(), ethStore: { - addAccount(acct) { accounts.push(acct) }, + addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, }, }) @@ -39,7 +40,7 @@ describe('IdentityStore', function() { idStore = new IdentityStore({ configManager: configManagerGen(), ethStore: { - addAccount(acct) { newAccounts.push(acct) }, + addAccount(acct) { newAccounts.push(ethUtil.addHexPrefix(acct)) }, }, }) }) @@ -62,6 +63,9 @@ describe('IdentityStore', function() { let firstAccount = '0x5d8de92c205279c10e5669f797b853ccef4f739a' const salt = 'lightwalletSalt' + const secondSeed = 'radar blur cabbage chef fix engine embark joy scheme fiction master release' + const secondAcct = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' + let password = 'secret!' let accounts = [] let idStore @@ -72,11 +76,15 @@ describe('IdentityStore', function() { idStore = new IdentityStore({ configManager: configManagerGen(), ethStore: { - addAccount(acct) { accounts.push('0x' + acct) }, + addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, }, }) }) + beforeEach(function() { + accounts = [] + }) + it('should return the expected first account', function (done) { idStore.recoverFromSeed(password, seedWords, (err) => { @@ -87,9 +95,6 @@ describe('IdentityStore', function() { assert.equal(accounts[0], firstAccount) accounts = [] - const secondSeed = 'radar blur cabbage chef fix engine embark joy scheme fiction master release' - const secondAcct = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' - idStore.recoverFromSeed(password, secondSeed, (err) => { let accounts = idStore._getAddresses() @@ -98,5 +103,16 @@ describe('IdentityStore', function() { }) }) }) + + it('should return the expected second account', function (done) { + idStore.recoverFromSeed(password, secondSeed, (err) => { + assert.ifError(err) + + let newKeystore = idStore._idmgmt.keyStore + + assert.equal(accounts[0], firstAccount) + done() + }) + }) }) }) -- cgit v1.2.3 From 1b77d5300b1ace16f96cf626d69925a26b5f0d29 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 12:15:05 -0700 Subject: Clean up tests --- test/unit/idStore-test.js | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 422db6f7b..1028e35ea 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -59,12 +59,7 @@ describe('IdentityStore', function() { }) describe('#recoverFromSeed BIP44 compliance', function() { - let seedWords = 'picnic injury awful upper eagle junk alert toss flower renew silly vague' - let firstAccount = '0x5d8de92c205279c10e5669f797b853ccef4f739a' - const salt = 'lightwalletSalt' - - const secondSeed = 'radar blur cabbage chef fix engine embark joy scheme fiction master release' - const secondAcct = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' + const salt = 'lightwalletSalt' let password = 'secret!' let accounts = [] @@ -86,31 +81,35 @@ describe('IdentityStore', function() { }) it('should return the expected first account', function (done) { + let seedWords = 'picnic injury awful upper eagle junk alert toss flower renew silly vague' + let firstAccount = '0x5d8de92c205279c10e5669f797b853ccef4f739a' idStore.recoverFromSeed(password, seedWords, (err) => { assert.ifError(err) - let newKeystore = idStore._idmgmt.keyStore - assert.equal(accounts[0], firstAccount) - - accounts = [] - idStore.recoverFromSeed(password, secondSeed, (err) => { - - let accounts = idStore._getAddresses() - assert.equal(accounts[0], secondAcct) - done() - }) + done() }) }) it('should return the expected second account', function (done) { + const secondSeed = 'radar blur cabbage chef fix engine embark joy scheme fiction master release' + const secondAcct = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' + idStore.recoverFromSeed(password, secondSeed, (err) => { assert.ifError(err) + assert.equal(accounts[0], secondAcct) + done() + }) + }) - let newKeystore = idStore._idmgmt.keyStore + it('should return the expected third account', function (done) { + const thirdSeed = 'phone coyote caught pattern found table wedding list tumble broccoli chief swing' + const thirdAcct = '0xb0e868f24bc7fec2bce2efc2b1c344d7569cd9d2' - assert.equal(accounts[0], firstAccount) + idStore.recoverFromSeed(password, thirdSeed, (err) => { + assert.ifError(err) + assert.equal(accounts[0], thirdAcct) done() }) }) -- cgit v1.2.3 From 8922ae1a55d3c5bf743c85aec5e454cf189f94f1 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 12:35:52 -0700 Subject: Made bip44 assertions easier to add to --- test/unit/idStore-test.js | 63 +++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 27 deletions(-) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 1028e35ea..09d8f1b8f 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -2,6 +2,7 @@ var assert = require('assert') var IdentityStore = require('../../app/scripts/lib/idStore') var configManagerGen = require('../lib/mock-config-manager') const ethUtil = require('ethereumjs-util') +const async = require('async') describe('IdentityStore', function() { @@ -65,6 +66,29 @@ describe('IdentityStore', function() { let accounts = [] let idStore + var assertions = [ + { + seed: 'picnic injury awful upper eagle junk alert toss flower renew silly vague', + account: '0x5d8de92c205279c10e5669f797b853ccef4f739a', + }, + { + seed: 'radar blur cabbage chef fix engine embark joy scheme fiction master release', + account: '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9', + }, + { + seed: 'phone coyote caught pattern found table wedding list tumble broccoli chief swing', + account: '0xb0e868f24bc7fec2bce2efc2b1c344d7569cd9d2', + }, + { + seed: 'recycle tag bird palace blue village anxiety census cook soldier example music', + account: '0xab34a45920afe4af212b96ec51232aaa6a33f663', + }, + { + seed: 'half glimpse tape cute harvest sweet bike voyage actual floor poet lazy', + account: '0x28e9044597b625ac4beda7250011670223de43b2', + } + ] + before(function() { window.localStorage = {} // Hacking localStorage support into JSDom @@ -80,36 +104,21 @@ describe('IdentityStore', function() { accounts = [] }) - it('should return the expected first account', function (done) { - let seedWords = 'picnic injury awful upper eagle junk alert toss flower renew silly vague' - let firstAccount = '0x5d8de92c205279c10e5669f797b853ccef4f739a' - - idStore.recoverFromSeed(password, seedWords, (err) => { - assert.ifError(err) - - assert.equal(accounts[0], firstAccount) - done() + it('should enforce seed compliance with TestRPC', function (done) { + const tests = assertions.map((assertion) => { + return function (cb) { + idStore.recoverFromSeed(password, assertion.seed, (err) => { + assert.ifError(err) + + console.log('comparing %s to %s', accounts[0], assertion.account) + assert.equal(accounts[0], assertion.account) + cb() + }) + } }) - }) - - it('should return the expected second account', function (done) { - const secondSeed = 'radar blur cabbage chef fix engine embark joy scheme fiction master release' - const secondAcct = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' - - idStore.recoverFromSeed(password, secondSeed, (err) => { - assert.ifError(err) - assert.equal(accounts[0], secondAcct) - done() - }) - }) - - it('should return the expected third account', function (done) { - const thirdSeed = 'phone coyote caught pattern found table wedding list tumble broccoli chief swing' - const thirdAcct = '0xb0e868f24bc7fec2bce2efc2b1c344d7569cd9d2' - idStore.recoverFromSeed(password, thirdSeed, (err) => { + async.series(tests, function(err, results) { assert.ifError(err) - assert.equal(accounts[0], thirdAcct) done() }) }) -- cgit v1.2.3 From cdd367dc3989d89092c322279972ce5ee18c276e Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 12:38:04 -0700 Subject: Add more bip44 assertions --- test/unit/idStore-test.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 09d8f1b8f..4327013b3 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -86,7 +86,15 @@ describe('IdentityStore', function() { { seed: 'half glimpse tape cute harvest sweet bike voyage actual floor poet lazy', account: '0x28e9044597b625ac4beda7250011670223de43b2', - } + }, + { + seed: 'flavor tiger carpet motor angry hungry document inquiry large critic usage liar', + account: '0xb571be96558940c4e9292e1999461aa7499fb6cd', + }, + { + seed: 'this is a twelve word phrase seven eight nine ten eleven twelve', + account: '0x814e8ec0c3647e140b8e09228fc374b2a867fe48', + }, ] before(function() { -- cgit v1.2.3 From b1590f179e77d80193cc5e82d430c789c6fd816f Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 12:39:50 -0700 Subject: Remove log --- test/unit/idStore-test.js | 1 - 1 file changed, 1 deletion(-) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 4327013b3..28111a85e 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -118,7 +118,6 @@ describe('IdentityStore', function() { idStore.recoverFromSeed(password, assertion.seed, (err) => { assert.ifError(err) - console.log('comparing %s to %s', accounts[0], assertion.account) assert.equal(accounts[0], assertion.account) cb() }) -- cgit v1.2.3 From 5e60b2f0c4c1a88839a87cc93d867c9c40d1090d Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 12:57:11 -0700 Subject: Correct assertion for BIP32 compliance According to [axic's work here](https://github.com/MetaMask/metamask-plugin/issues/640#issuecomment-246133672), MetaMask is generating the correct address, so I've corrected that assertion accordingly. --- test/unit/idStore-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 28111a85e..b3bb1a49c 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -73,7 +73,7 @@ describe('IdentityStore', function() { }, { seed: 'radar blur cabbage chef fix engine embark joy scheme fiction master release', - account: '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9', + account: '0xe15D894BeCB0354c501AE69429B05143679F39e0', }, { seed: 'phone coyote caught pattern found table wedding list tumble broccoli chief swing', -- cgit v1.2.3 From 9b861b6687d5b079560a67b35e4a4890da643b03 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 15:45:34 -0700 Subject: Fixed caching bug Fixed bug where the second new vault created in an IdStore would initially return the accounts from the original store. Also fixed some tests that were incorrect. --- test/unit/idStore-test.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index b3bb1a49c..a763eb0e7 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -73,7 +73,7 @@ describe('IdentityStore', function() { }, { seed: 'radar blur cabbage chef fix engine embark joy scheme fiction master release', - account: '0xe15D894BeCB0354c501AE69429B05143679F39e0', + account: '0xe15d894becb0354c501ae69429b05143679f39e0', }, { seed: 'phone coyote caught pattern found table wedding list tumble broccoli chief swing', @@ -91,10 +91,6 @@ describe('IdentityStore', function() { seed: 'flavor tiger carpet motor angry hungry document inquiry large critic usage liar', account: '0xb571be96558940c4e9292e1999461aa7499fb6cd', }, - { - seed: 'this is a twelve word phrase seven eight nine ten eleven twelve', - account: '0x814e8ec0c3647e140b8e09228fc374b2a867fe48', - }, ] before(function() { @@ -115,10 +111,13 @@ describe('IdentityStore', function() { it('should enforce seed compliance with TestRPC', function (done) { const tests = assertions.map((assertion) => { return function (cb) { + accounts = [] idStore.recoverFromSeed(password, assertion.seed, (err) => { assert.ifError(err) - assert.equal(accounts[0], assertion.account) + var received = accounts[0].toLowerCase() + var expected = assertion.account.toLowerCase() + assert.equal(received, expected) cb() }) } -- cgit v1.2.3 From 5c1d8e299e68be6a74935f4eff56f68a9ccf5b72 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 12 Sep 2016 08:50:42 -0700 Subject: Select first address when restoring vault Fixes #642 --- test/unit/idStore-test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index a763eb0e7..1ed1bf9a7 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -128,5 +128,23 @@ describe('IdentityStore', function() { done() }) }) + + it('should allow restoring and unlocking again', function (done) { + const assertion = assertions[0] + idStore.recoverFromSeed(password, assertion.seed, (err) => { + assert.ifError(err) + + var received = accounts[0].toLowerCase() + var expected = assertion.account.toLowerCase() + assert.equal(received, expected) + + + idStore.submitPassword(password, function(err, account) { + assert.ifError(err) + assert.equal(account, expected) + done() + }) + }) + }) }) }) -- cgit v1.2.3 From 363c2a0939aba5fa73e08ff8e6d65581031242d5 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 12 Sep 2016 11:07:25 -0700 Subject: Fix account unlocking SubmitPassword was not creating a new id-management This is because I broke up the old "createIdmgmt" method to not perform as much conditional logic. Now the pieces are reusable and do what they should do. --- test/unit/idStore-test.js | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 1ed1bf9a7..ac416e5cd 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -109,6 +109,7 @@ describe('IdentityStore', function() { }) it('should enforce seed compliance with TestRPC', function (done) { + this.timeout(5000) const tests = assertions.map((assertion) => { return function (cb) { accounts = [] @@ -118,7 +119,17 @@ describe('IdentityStore', function() { var received = accounts[0].toLowerCase() var expected = assertion.account.toLowerCase() assert.equal(received, expected) - cb() + + idStore.tryPassword(password, function (err) { + + assert.ok(idStore.isUnlocked(), 'should unlock the id store') + + idStore.submitPassword(password, function(err, account) { + assert.ifError(err) + assert.equal(account, expected) + cb() + }) + }) }) } }) @@ -128,23 +139,5 @@ describe('IdentityStore', function() { done() }) }) - - it('should allow restoring and unlocking again', function (done) { - const assertion = assertions[0] - idStore.recoverFromSeed(password, assertion.seed, (err) => { - assert.ifError(err) - - var received = accounts[0].toLowerCase() - var expected = assertion.account.toLowerCase() - assert.equal(received, expected) - - - idStore.submitPassword(password, function(err, account) { - assert.ifError(err) - assert.equal(account, expected) - done() - }) - }) - }) }) }) -- cgit v1.2.3 From e0e38b879f4d8ea367a0ea77be633d0b4d6762fa Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 12 Sep 2016 11:21:27 -0700 Subject: Fix some references --- test/unit/idStore-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index ac416e5cd..03b1d3b41 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -109,7 +109,7 @@ describe('IdentityStore', function() { }) it('should enforce seed compliance with TestRPC', function (done) { - this.timeout(5000) + this.timeout(10000) const tests = assertions.map((assertion) => { return function (cb) { accounts = [] @@ -122,7 +122,7 @@ describe('IdentityStore', function() { idStore.tryPassword(password, function (err) { - assert.ok(idStore.isUnlocked(), 'should unlock the id store') + assert.ok(idStore._isUnlocked(), 'should unlock the id store') idStore.submitPassword(password, function(err, account) { assert.ifError(err) -- cgit v1.2.3 From c3d1404e72f4978db5b4522cb793ffd22653d9ff Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 12 Sep 2016 15:18:32 -0700 Subject: Fix clearing of account cache on vault restore --- test/unit/idStore-test.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 03b1d3b41..31da2cd3d 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -63,7 +63,7 @@ describe('IdentityStore', function() { const salt = 'lightwalletSalt' let password = 'secret!' - let accounts = [] + let accounts = {} let idStore var assertions = [ @@ -99,25 +99,22 @@ describe('IdentityStore', function() { idStore = new IdentityStore({ configManager: configManagerGen(), ethStore: { - addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, + addAccount(acct) { accounts[acct] = acct}, + del(acct) { delete accounts[acct] }, }, }) }) - beforeEach(function() { - accounts = [] - }) - it('should enforce seed compliance with TestRPC', function (done) { this.timeout(10000) const tests = assertions.map((assertion) => { return function (cb) { - accounts = [] + idStore.recoverFromSeed(password, assertion.seed, (err) => { assert.ifError(err) - var received = accounts[0].toLowerCase() var expected = assertion.account.toLowerCase() + var received = accounts[expected].toLowerCase() assert.equal(received, expected) idStore.tryPassword(password, function (err) { @@ -127,6 +124,7 @@ describe('IdentityStore', function() { idStore.submitPassword(password, function(err, account) { assert.ifError(err) assert.equal(account, expected) + assert.equal(Object.keys(idStore._getAddresses()).length, 1, 'only one account on restore') cb() }) }) -- cgit v1.2.3 From cf31e1902909f3bd1f0e26b279cda79a9879ff4e Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 14 Sep 2016 18:24:52 -0700 Subject: Remove logs --- test/unit/extension-test.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'test') diff --git a/test/unit/extension-test.js b/test/unit/extension-test.js index b0b72509b..8f259f05c 100644 --- a/test/unit/extension-test.js +++ b/test/unit/extension-test.js @@ -18,9 +18,7 @@ describe('extension', function() { } it('returns the desired result', function() { - console.dir(Extension) const extension = new Extension() - console.dir(extension) const result = extension.extension.getURL() assert.equal(result, desiredResult) }) -- cgit v1.2.3 From c0d6dcff00b36e89242695a4a29c5f52f4d3a5be Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 5 Oct 2016 02:42:19 -0700 Subject: Rewritten to react standards. Way easier. --- test/integration/tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/integration/tests.js b/test/integration/tests.js index a3f3cd294..f8c1a6fd9 100644 --- a/test/integration/tests.js +++ b/test/integration/tests.js @@ -11,7 +11,7 @@ QUnit.test('agree to terms', function (assert) { wait().then(function() { var title = app.find('h1').text() - assert.equal(title, 'MetaMask', 'title screen') + assert.equal(title, 'Terms of Use Version 1', 'title screen') var buttons = app.find('button') assert.equal(buttons.length, 2, 'two buttons: create and restore') -- cgit v1.2.3 From e20e0f661d81937e34fc2f930eee92b8fe2c7e04 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 5 Oct 2016 19:49:53 -0700 Subject: Fix integration test. --- test/integration/tests.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/integration/tests.js b/test/integration/tests.js index f8c1a6fd9..2d813762d 100644 --- a/test/integration/tests.js +++ b/test/integration/tests.js @@ -3,19 +3,26 @@ QUnit.test('agree to terms', function (assert) { // Select the mock app root var app = $('iframe').contents().find('#app-content .mock-app-root') + // var button = $('.agree') + // button.removeAttr('disabled') - // Agree to terms - app.find('button').click() + app.find('.markdown').prop('scrollTop', 100000000) - // Wait for view to transition: + + // Agree to terms wait().then(function() { + app.find('button').click() + wait().then(function() { - var title = app.find('h1').text() - assert.equal(title, 'Terms of Use Version 1', 'title screen') + var title = app.find('h1').text() + assert.equal(title, 'MetaMask', 'title screen') - var buttons = app.find('button') - assert.equal(buttons.length, 2, 'two buttons: create and restore') + var buttons = app.find('button') + assert.equal(buttons.length, 2, 'two buttons: create and restore') - done() + done() + }) }) + + // Wait for view to transition: }) -- cgit v1.2.3 From ea1a934c7defe7e1b077b675ae9125118f1f3d87 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 11 Oct 2016 15:09:22 -0700 Subject: Add initial KeyringController files --- test/unit/keyring-controller-test.js | 141 +++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 test/unit/keyring-controller-test.js (limited to 'test') diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js new file mode 100644 index 000000000..854ac5212 --- /dev/null +++ b/test/unit/keyring-controller-test.js @@ -0,0 +1,141 @@ +var assert = require('assert') +var KeyringController = require('../../app/scripts/keyring-controller') +var configManagerGen = require('../lib/mock-config-manager') +const ethUtil = require('ethereumjs-util') +const async = require('async') + +describe('KeyringController', function() { + + describe('#createNewVault', function () { + let keyringController + let password = 'password123' + let entropy = 'entripppppyy duuude' + let seedWords + let accounts = [] + let originalKeystore + + before(function(done) { + window.localStorage = {} // Hacking localStorage support into JSDom + + keyringController = new KeyringController({ + configManager: configManagerGen(), + ethStore: { + addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, + }, + }) + + keyringController.createNewVault(password, entropy, (err, seeds) => { + assert.ifError(err, 'createNewVault threw error') + seedWords = seeds + originalKeystore = keyringController._idmgmt.keyStore + done() + }) + }) + + describe('#recoverFromSeed', function() { + let newAccounts = [] + + before(function() { + window.localStorage = {} // Hacking localStorage support into JSDom + + keyringController = new KeyringController({ + configManager: configManagerGen(), + ethStore: { + addAccount(acct) { newAccounts.push(ethUtil.addHexPrefix(acct)) }, + }, + }) + }) + + it('should return the expected keystore', function (done) { + + keyringController.recoverFromSeed(password, seedWords, (err) => { + assert.ifError(err) + + let newKeystore = keyringController._idmgmt.keyStore + assert.equal(newAccounts[0], accounts[0]) + done() + }) + }) + }) + }) + + describe('#recoverFromSeed BIP44 compliance', function() { + const salt = 'lightwalletSalt' + + let password = 'secret!' + let accounts = {} + let keyringController + + var assertions = [ + { + seed: 'picnic injury awful upper eagle junk alert toss flower renew silly vague', + account: '0x5d8de92c205279c10e5669f797b853ccef4f739a', + }, + { + seed: 'radar blur cabbage chef fix engine embark joy scheme fiction master release', + account: '0xe15d894becb0354c501ae69429b05143679f39e0', + }, + { + seed: 'phone coyote caught pattern found table wedding list tumble broccoli chief swing', + account: '0xb0e868f24bc7fec2bce2efc2b1c344d7569cd9d2', + }, + { + seed: 'recycle tag bird palace blue village anxiety census cook soldier example music', + account: '0xab34a45920afe4af212b96ec51232aaa6a33f663', + }, + { + seed: 'half glimpse tape cute harvest sweet bike voyage actual floor poet lazy', + account: '0x28e9044597b625ac4beda7250011670223de43b2', + }, + { + seed: 'flavor tiger carpet motor angry hungry document inquiry large critic usage liar', + account: '0xb571be96558940c4e9292e1999461aa7499fb6cd', + }, + ] + + before(function() { + window.localStorage = {} // Hacking localStorage support into JSDom + + keyringController = new KeyringController({ + configManager: configManagerGen(), + ethStore: { + addAccount(acct) { accounts[acct] = acct}, + del(acct) { delete accounts[acct] }, + }, + }) + }) + + it('should enforce seed compliance with TestRPC', function (done) { + this.timeout(10000) + const tests = assertions.map((assertion) => { + return function (cb) { + + keyringController.recoverFromSeed(password, assertion.seed, (err) => { + assert.ifError(err) + + var expected = assertion.account.toLowerCase() + var received = accounts[expected].toLowerCase() + assert.equal(received, expected) + + keyringController.tryPassword(password, function (err) { + + assert.ok(keyringController._isUnlocked(), 'should unlock the id store') + + keyringController.submitPassword(password, function(err, account) { + assert.ifError(err) + assert.equal(account, expected) + assert.equal(Object.keys(keyringController._getAddresses()).length, 1, 'only one account on restore') + cb() + }) + }) + }) + } + }) + + async.series(tests, function(err, results) { + assert.ifError(err) + done() + }) + }) + }) +}) -- cgit v1.2.3 From 5e9bc31c58aff4b9d1d0d1bd54416ffb0a1b14d3 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 11 Oct 2016 15:50:02 -0700 Subject: Cleanup. --- test/integration/tests.js | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/integration/tests.js b/test/integration/tests.js index 2d813762d..747845d75 100644 --- a/test/integration/tests.js +++ b/test/integration/tests.js @@ -3,25 +3,37 @@ QUnit.test('agree to terms', function (assert) { // Select the mock app root var app = $('iframe').contents().find('#app-content .mock-app-root') - // var button = $('.agree') - // button.removeAttr('disabled') app.find('.markdown').prop('scrollTop', 100000000) // Agree to terms + // wait().then(function() { + // app.find('button').click() + // wait().then(function() { + // + // var title = app.find('h1').text() + // assert.equal(title, 'MetaMask', 'title screen') + // + // var buttons = app.find('button') + // assert.equal(buttons.length, 2, 'two buttons: create and restore') + // + // done() + // }) + // }) + wait().then(function() { app.find('button').click() - wait().then(function() { - - var title = app.find('h1').text() - assert.equal(title, 'MetaMask', 'title screen') + }).then(function() { + return wait() + }).then(function() { + var title = app.find('h1').text() + assert.equal(title, 'MetaMask', 'title screen') - var buttons = app.find('button') - assert.equal(buttons.length, 2, 'two buttons: create and restore') + var buttons = app.find('button') + assert.equal(buttons.length, 2, 'two buttons: create and restore') - done() - }) + done() }) // Wait for view to transition: -- cgit v1.2.3 From 5c0c370fe4bcb4c1a2467edd19e86e463b4fa900 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 11 Oct 2016 15:52:44 -0700 Subject: Remove comments. --- test/integration/tests.js | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'test') diff --git a/test/integration/tests.js b/test/integration/tests.js index 747845d75..92111b05b 100644 --- a/test/integration/tests.js +++ b/test/integration/tests.js @@ -6,22 +6,6 @@ QUnit.test('agree to terms', function (assert) { app.find('.markdown').prop('scrollTop', 100000000) - - // Agree to terms - // wait().then(function() { - // app.find('button').click() - // wait().then(function() { - // - // var title = app.find('h1').text() - // assert.equal(title, 'MetaMask', 'title screen') - // - // var buttons = app.find('button') - // assert.equal(buttons.length, 2, 'two buttons: create and restore') - // - // done() - // }) - // }) - wait().then(function() { app.find('button').click() }).then(function() { -- cgit v1.2.3 From 91f43fa2130e84a32ebecf902696a0b897cdd095 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 17 Oct 2016 12:47:37 -0700 Subject: Increase gas estimate by 100000 wei To prevent minor gas estimation errors, probably usually related to operating on dynamic state. Fixes #738. --- test/unit/idStore-test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 31da2cd3d..7f6324645 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -2,6 +2,7 @@ var assert = require('assert') var IdentityStore = require('../../app/scripts/lib/idStore') var configManagerGen = require('../lib/mock-config-manager') const ethUtil = require('ethereumjs-util') +const BN = ethUtil.BN const async = require('async') describe('IdentityStore', function() { @@ -138,4 +139,20 @@ describe('IdentityStore', function() { }) }) }) + + describe('#addGasBuffer', function() { + const idStore = new IdentityStore({ + configManager: configManagerGen(), + ethStore: { + addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, + }, + }) + + const gas = '0x01' + const bnGas = new BN(gas, 16) + const result = idStore.addGasBuffer(gas) + const bnResult = new BN(result, 16) + + assert.ok(bnResult.gt(gas), 'added more gas as buffer.') + }) }) -- cgit v1.2.3 From 827d7553fc843a75b7a4306c7549505f799609d7 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 17 Oct 2016 13:05:45 -0700 Subject: Restore hex prefix to gas price --- test/unit/idStore-test.js | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 7f6324645..0a57d2121 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -154,5 +154,6 @@ describe('IdentityStore', function() { const bnResult = new BN(result, 16) assert.ok(bnResult.gt(gas), 'added more gas as buffer.') + assert.equal(result.indexOf('0x'), 0, 'include hex prefix') }) }) -- cgit v1.2.3 From 049705004f306bb83ad1bc0b7315d322becf8263 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 17 Oct 2016 14:48:25 -0700 Subject: Reproduced issue 743 in test case This contract hex does include the value `f4`, but it was compiled from a contract with no instance of `.delegatecall`. I believe `f4` in this case is part of some other value or contract address, and `ethBinToOps` has some error in how it skips pushed data. @kumavis --- test/lib/non-delegate-code.txt | 1 + test/unit/idStore-test.js | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 test/lib/non-delegate-code.txt (limited to 'test') diff --git a/test/lib/non-delegate-code.txt b/test/lib/non-delegate-code.txt new file mode 100644 index 000000000..68b0d4dac --- /dev/null +++ b/test/lib/non-delegate-code.txt @@ -0,0 +1 @@ +0x606060405260e060020a60003504637bd703e8811461003157806390b98a111461005c578063f8b2cb4f1461008e575b005b6100b4600435600073f28c53067227848f8145355c455da5cfdd20e3136396e4ee3d6100da84610095565b6100c660043560243533600160a060020a03166000908152602081905260408120548290101561011f57506000610189565b6100b46004355b600160a060020a0381166000908152602081905260409020545b919050565b60408051918252519081900360200190f35b604080519115158252519081900360200190f35b60026040518360e060020a02815260040180838152602001828152602001925050506020604051808303818660325a03f4156100025750506040515191506100af9050565b33600160a060020a0390811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9291505056 \ No newline at end of file diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 0a57d2121..c3f79b088 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -1,10 +1,15 @@ -var assert = require('assert') -var IdentityStore = require('../../app/scripts/lib/idStore') -var configManagerGen = require('../lib/mock-config-manager') +const assert = require('assert') +const IdentityStore = require('../../app/scripts/lib/idStore') +const configManagerGen = require('../lib/mock-config-manager') +const fs = require('fs') +const path = require('path') const ethUtil = require('ethereumjs-util') const BN = ethUtil.BN const async = require('async') +const nonDelegatePath = path.join(__dirname, '..', 'lib', 'non-delegate-code.txt') +const nonDelegateCode = fs.readFileSync(nonDelegatePath).toString() + describe('IdentityStore', function() { describe('#createNewVault', function () { @@ -156,4 +161,16 @@ describe('IdentityStore', function() { assert.ok(bnResult.gt(gas), 'added more gas as buffer.') assert.equal(result.indexOf('0x'), 0, 'include hex prefix') }) + + describe('#checkForDelegateCall', function() { + const idStore = new IdentityStore({ + configManager: configManagerGen(), + ethStore: { + addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, + }, + }) + + var result = idStore.checkForDelegateCall(nonDelegateCode) + assert.equal(result, false, 'no delegate call in provided code') + }) }) -- cgit v1.2.3 From 17506fe14f84680bc6b5421eff4c797154a513bd Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 19 Oct 2016 11:17:29 -0700 Subject: Merge in crypto. --- test/integration/index.html | 2 +- test/integration/index.js | 21 ++++++++++++++++ test/integration/lib/encryptor-test.js | 44 ++++++++++++++++++++++++++++++++++ test/integration/lib/first-time.js | 25 +++++++++++++++++++ test/integration/tests.js | 24 ------------------- 5 files changed, 91 insertions(+), 25 deletions(-) create mode 100644 test/integration/index.js create mode 100644 test/integration/lib/encryptor-test.js create mode 100644 test/integration/lib/first-time.js delete mode 100644 test/integration/tests.js (limited to 'test') diff --git a/test/integration/index.html b/test/integration/index.html index 6de40b046..ad4b4eb14 100644 --- a/test/integration/index.html +++ b/test/integration/index.html @@ -12,7 +12,7 @@ - + diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index a73b0cba3..e7d4ffaa2 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -1,3 +1,5 @@ +const PASSWORD = 'password123' + QUnit.test('agree to terms', function (assert) { var done = assert.async() let app @@ -6,10 +8,30 @@ QUnit.test('agree to terms', function (assert) { app = $('iframe').contents().find('#app-content .mock-app-root') app.find('.markdown').prop('scrollTop', 100000000) return wait() + }).then(function() { + var title = app.find('h1').text() assert.equal(title, 'MetaMask', 'title screen') + var pwBox = app.find('#password-box')[0] + var confBox = app.find('#password-box-confirm')[0] + + pwBox.value = PASSWORD + confBox.value = PASSWORD + return wait() + + }).then(function() { + + var createButton = app.find('button.primary')[0] + createButton.click() + + return wait(1500) + }).then(function() { + + var terms = app.find('h3.terms-header')[0] + assert.equal(terms.textContent, 'MetaMask Terms & Conditions', 'Showing TOS') + done() }) }) -- cgit v1.2.3 From fe533bbef2486bd22e4e23ee43927cff0e1d958e Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 30 Nov 2016 15:18:26 -0800 Subject: Add more integration tests Integration tests now: - Scroll through terms - Accept terms - Confirm seed phrase - Verify account detail screen --- test/integration/lib/first-time.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test') diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index e7d4ffaa2..76b10f568 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -32,6 +32,31 @@ QUnit.test('agree to terms', function (assert) { var terms = app.find('h3.terms-header')[0] assert.equal(terms.textContent, 'MetaMask Terms & Conditions', 'Showing TOS') + // Scroll through terms + var scrollable = app.find('.markdown')[0] + scrollable.scrollTop = scrollable.scrollHeight + + return wait(10) + }).then(function() { + + var button = app.find('button')[0] // Agree button + button.click() + + return wait(1000) + }).then(function() { + + var created = app.find('h3')[0] + assert.equal(created.textContent, 'Vault Created', 'Vault created screen') + + var button = app.find('button')[0] // Agree button + button.click() + + return wait(1000) + }).then(function() { + + var detail = app.find('.account-detail-section')[0] + assert.ok(detail, 'Account detail section loaded.') done() + }) }) -- cgit v1.2.3 From 049e351c9d78dc13a81ba962b04ef96694b13682 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 30 Nov 2016 16:01:51 -0800 Subject: Add integration tests for logging out and back in --- test/integration/lib/first-time.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index 76b10f568..d2fe31878 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -56,7 +56,33 @@ QUnit.test('agree to terms', function (assert) { var detail = app.find('.account-detail-section')[0] assert.ok(detail, 'Account detail section loaded.') - done() + var sandwich = app.find('.sandwich-expando')[0] + sandwich.click() + + return wait() + }).then(function() { + + var sandwich = app.find('.menu-droppo')[0] + var lock = sandwich.children[2] + assert.ok(lock, 'Lock menu item found') + lock.click() + + return wait(1000) + }).then(function() { + + var pwBox = app.find('#password-box')[0] + pwBox.value = PASSWORD + + var createButton = app.find('button.primary')[0] + createButton.click() + + return wait(1500) + }).then(function() { + + var detail = app.find('.account-detail-section')[0] + assert.ok(detail, 'Account detail section loaded again.') + + done() }) }) -- cgit v1.2.3 From 1880cda9b95f3274d56e1f4abc513d1d7ddd59c2 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 30 Nov 2016 19:34:17 -0800 Subject: Fix vault encrypting & unlocking bug This is only a bug in dev, but was committed yesterday. Sometimes the `encrypt` method was being passed values other than the password as the encryption key, leading to un-unlockable vaults. To find this, and avoid it for all time hereafter, I added several more steps to our oft-neglected integration test suite, which now fully initializes a vault, locks it, and unlocks it again, to make sure all of those steps definitely work always. --- test/integration/lib/encryptor-test.js | 4 ++++ test/integration/lib/first-time.js | 2 ++ 2 files changed, 6 insertions(+) (limited to 'test') diff --git a/test/integration/lib/encryptor-test.js b/test/integration/lib/encryptor-test.js index d42608152..897d22740 100644 --- a/test/integration/lib/encryptor-test.js +++ b/test/integration/lib/encryptor-test.js @@ -1,5 +1,7 @@ var encryptor = require('../../../app/scripts/lib/encryptor') +QUnit.module('encryptor') + QUnit.test('encryptor:serializeBufferForStorage', function (assert) { assert.expect(1) var buf = new Buffer(2) @@ -65,3 +67,5 @@ QUnit.test('encryptor:encrypt & decrypt with wrong password', function(assert) { done() }) }) + + diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index d2fe31878..12c573db1 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -1,5 +1,7 @@ const PASSWORD = 'password123' +QUnit.module('first time usage') + QUnit.test('agree to terms', function (assert) { var done = assert.async() let app -- cgit v1.2.3 From fe01ceb85770faff660e6a3bd356a5a91883b7f0 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 7 Dec 2016 16:32:49 -0800 Subject: Remove .only from unit test suite --- test/unit/nodeify-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/nodeify-test.js b/test/unit/nodeify-test.js index d4ac2ea0b..a14d34338 100644 --- a/test/unit/nodeify-test.js +++ b/test/unit/nodeify-test.js @@ -1,7 +1,7 @@ const assert = require('assert') const nodeify = require('../../app/scripts/lib/nodeify') -describe.only('nodeify', function() { +describe('nodeify', function() { var obj = { foo: 'bar', -- cgit v1.2.3 From c93227ea72b980a0ca45f781a5088a819afd9f46 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 7 Dec 2016 16:55:15 -0800 Subject: Cranked up CI test suite wait duration to alleviate their nondeterminism for now --- test/integration/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/integration/helpers.js b/test/integration/helpers.js index 40f78d701..eede103b4 100644 --- a/test/integration/helpers.js +++ b/test/integration/helpers.js @@ -2,6 +2,6 @@ function wait(time) { return new Promise(function(resolve, reject) { setTimeout(function() { resolve() - }, time || 500) + }, time * 3 || 1500) }) } -- cgit v1.2.3 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/integration/lib/keyring-controller-test.js | 58 +++++++++++++++++++++++++ test/integration/mocks/badVault.json | 1 + test/unit/idStore-migration-test.js | 32 +++----------- test/unit/keyring-controller-test.js | 15 ------- 4 files changed, 65 insertions(+), 41 deletions(-) create mode 100644 test/integration/mocks/badVault.json (limited to 'test') diff --git a/test/integration/lib/keyring-controller-test.js b/test/integration/lib/keyring-controller-test.js index ae5ecc578..e37b5df50 100644 --- a/test/integration/lib/keyring-controller-test.js +++ b/test/integration/lib/keyring-controller-test.js @@ -2,6 +2,7 @@ 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' @@ -41,6 +42,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) +}) + +QUnit.test('keyringController:submitPassword', function (assert) { + var done = assert.async() + + this.keyringController.submitPassword(PASSWORD) + .then((state) => { + assert.ok(state.identities[FIRST_ADDRESS]) + assert.equal(state.lostAccounts.length, 1, 'one lost account') + assert.equal(state.lostAccounts[0], 'e15D894BeCB0354c501AE69429B05143679F39e0'.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/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 7b9749e30c4f8228fe62c1ad81515117cf7504bc Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 9 Dec 2016 12:24:25 -0800 Subject: Got bad account detection working and added to state --- test/integration/lib/keyring-controller-test.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/integration/lib/keyring-controller-test.js b/test/integration/lib/keyring-controller-test.js index e37b5df50..666795a6d 100644 --- a/test/integration/lib/keyring-controller-test.js +++ b/test/integration/lib/keyring-controller-test.js @@ -8,6 +8,8 @@ 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 () { @@ -87,7 +89,7 @@ QUnit.module('Old Style Vaults with bad HD seed', { }) QUnit.test('keyringController:isInitialized', function (assert) { - assert.ok(this.keyringController.getState().isInitialized) + assert.ok(this.keyringController.getState().isInitialized, 'vault is initialized') }) QUnit.test('keyringController:submitPassword', function (assert) { @@ -95,9 +97,9 @@ QUnit.test('keyringController:submitPassword', function (assert) { this.keyringController.submitPassword(PASSWORD) .then((state) => { - assert.ok(state.identities[FIRST_ADDRESS]) + assert.ok(state.identities[BAD_STYLE_FIRST_ADDRESS]) assert.equal(state.lostAccounts.length, 1, 'one lost account') - assert.equal(state.lostAccounts[0], 'e15D894BeCB0354c501AE69429B05143679F39e0'.toLowerCase()) + assert.equal(state.lostAccounts[0], '0xe15D894BeCB0354c501AE69429B05143679F39e0'.toLowerCase()) assert.deepEqual(this.configManager.getLostAccounts(), state.lostAccounts, 'persisted') done() }) -- cgit v1.2.3 From 5aba096bd1afe23cf3df491ef67e24858e6efc01 Mon Sep 17 00:00:00 2001 From: Frances Pangilinan Date: Wed, 14 Dec 2016 12:56:53 -0800 Subject: add Test for txManager. As well as fix tests to account for txManager. --- test/integration/lib/keyring-controller-test.js | 4 + test/lib/mock-config-manager.js | 1 + test/unit/config-manager-test.js | 83 +----------- test/unit/idStore-migration-test.js | 4 + test/unit/keyring-controller-test.js | 4 + test/unit/tx-manager-test.js | 169 ++++++++++++++++++++++++ 6 files changed, 185 insertions(+), 80 deletions(-) create mode 100644 test/unit/tx-manager-test.js (limited to 'test') diff --git a/test/integration/lib/keyring-controller-test.js b/test/integration/lib/keyring-controller-test.js index ae5ecc578..2d16e2f95 100644 --- a/test/integration/lib/keyring-controller-test.js +++ b/test/integration/lib/keyring-controller-test.js @@ -20,6 +20,10 @@ QUnit.module('Old Style Vaults', { this.keyringController = new KeyringController({ configManager: this.configManager, getNetwork: () => { return '2' }, + txManager: { + getTxList: () => [], + getUnapprovedTxList: () => [] + }, }) this.ethStore = { diff --git a/test/lib/mock-config-manager.js b/test/lib/mock-config-manager.js index ccd518c68..b79f63090 100644 --- a/test/lib/mock-config-manager.js +++ b/test/lib/mock-config-manager.js @@ -9,6 +9,7 @@ module.exports = function() { function loadData () { var oldData = getOldStyleData() var newData + try { newData = JSON.parse(window.localStorage[STORAGE_KEY]) } catch (e) {} diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index 206460ffb..61226d624 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -215,7 +215,7 @@ describe('config-manager', function() { describe('transactions', function() { beforeEach(function() { - configManager._saveTxList([]) + configManager.setTxList([]) }) describe('#getTxList', function() { @@ -226,90 +226,13 @@ describe('config-manager', function() { }) }) - describe('#_saveTxList', function() { + describe('#setTxList', function() { it('saves the submitted data to the tx list', function() { var target = [{ foo: 'bar' }] - configManager._saveTxList(target) + configManager.setTxList(target) var result = configManager.getTxList() assert.equal(result[0].foo, 'bar') }) }) - - describe('#addTx', function() { - it('adds a tx returned in getTxList', function() { - var tx = { id: 1 } - configManager.addTx(tx) - var result = configManager.getTxList() - assert.ok(Array.isArray(result)) - assert.equal(result.length, 1) - assert.equal(result[0].id, 1) - }) - - it('cuts off early txs beyond a limit', function() { - const limit = configManager.txLimit - for (let i = 0; i < limit + 1; i++) { - let tx = { id: i } - configManager.addTx(tx) - } - var result = configManager.getTxList() - assert.equal(result.length, limit, `limit of ${limit} txs enforced`) - assert.equal(result[0].id, 1, 'early txs truncted') - }) - }) - - describe('#confirmTx', function() { - it('sets the tx status to confirmed', function() { - var tx = { id: 1, status: 'unconfirmed' } - configManager.addTx(tx) - configManager.confirmTx(1) - var result = configManager.getTxList() - assert.ok(Array.isArray(result)) - assert.equal(result.length, 1) - assert.equal(result[0].status, 'confirmed') - }) - }) - - describe('#rejectTx', function() { - it('sets the tx status to rejected', function() { - var tx = { id: 1, status: 'unconfirmed' } - configManager.addTx(tx) - configManager.rejectTx(1) - var result = configManager.getTxList() - assert.ok(Array.isArray(result)) - assert.equal(result.length, 1) - assert.equal(result[0].status, 'rejected') - }) - }) - - describe('#updateTx', function() { - it('replaces the tx with the same id', function() { - configManager.addTx({ id: '1', status: 'unconfirmed' }) - configManager.addTx({ id: '2', status: 'confirmed' }) - configManager.updateTx({ id: '1', status: 'blah', hash: 'foo' }) - var result = configManager.getTx('1') - assert.equal(result.hash, 'foo') - }) - }) - - describe('#unconfirmedTxs', function() { - it('returns unconfirmed txs in a hash', function() { - configManager.addTx({ id: '1', status: 'unconfirmed' }) - configManager.addTx({ id: '2', status: 'confirmed' }) - let result = configManager.unconfirmedTxs() - assert.equal(typeof result, 'object') - assert.equal(result['1'].status, 'unconfirmed') - assert.equal(result['0'], undefined) - assert.equal(result['2'], undefined) - }) - }) - - describe('#getTx', function() { - it('returns a tx with the requested id', function() { - configManager.addTx({ id: '1', status: 'unconfirmed' }) - configManager.addTx({ id: '2', status: 'confirmed' }) - assert.equal(configManager.getTx('1').status, 'unconfirmed') - assert.equal(configManager.getTx('2').status, 'confirmed') - }) - }) }) }) diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js index ac8e23d22..639eb0d72 100644 --- a/test/unit/idStore-migration-test.js +++ b/test/unit/idStore-migration-test.js @@ -64,6 +64,10 @@ describe('IdentityStore to KeyringController migration', function() { addAccount(acct) { newAccounts.push(ethUtil.addHexPrefix(acct)) }, del(acct) { delete newAccounts[acct] }, }, + txManager: { + getTxList: () => [], + getUnapprovedTxList: () => [] + }, }) // Stub out the browser crypto for a mock encryptor. diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js index 69a57ef52..a2b65a6b5 100644 --- a/test/unit/keyring-controller-test.js +++ b/test/unit/keyring-controller-test.js @@ -23,6 +23,10 @@ describe('KeyringController', function() { keyringController = new KeyringController({ configManager: configManagerGen(), + txManager: { + getTxList: () => [], + getUnapprovedTxList: () => [] + }, ethStore: { addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, }, diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js new file mode 100644 index 000000000..0a7c5e83b --- /dev/null +++ b/test/unit/tx-manager-test.js @@ -0,0 +1,169 @@ +const assert = require('assert') +const extend = require('xtend') +const STORAGE_KEY = 'metamask-persistance-key' +const TransactionManager = require('../../app/scripts/transaction-manager') + +describe('Transaction Manager', function() { + let txManager + + const onTxDoneCb = () => true + beforeEach(function() { + txManager = new TransactionManager ({ + TxListFromStore: [], + setTxList: () => {}, + provider: "testnet", + txLimit: 40, + }) + }) + + describe('#getTxList', function() { + it('when new should return empty array', function() { + var result = txManager.getTxList() + assert.ok(Array.isArray(result)) + assert.equal(result.length, 0) + }) + it('should also return transactions from local storage if any', function() { + + }) + }) + + describe('#_saveTxList', function() { + it('saves the submitted data to the tx list', function() { + var target = [{ foo: 'bar' }] + txManager._saveTxList(target) + var result = txManager.getTxList() + assert.equal(result[0].foo, 'bar') + }) + }) + + describe('#addTx', function() { + it('adds a tx returned in getTxList', function() { + var tx = { id: 1 } + txManager.addTx(tx, onTxDoneCb) + var result = txManager.getTxList() + assert.ok(Array.isArray(result)) + assert.equal(result.length, 1) + assert.equal(result[0].id, 1) + }) + + it('cuts off early txs beyond a limit', function() { + const limit = txManager.txLimit + for (let i = 0; i < limit + 1; i++) { + let tx = { id: i, time: new Date()} + txManager.addTx(tx, onTxDoneCb) + } + var result = txManager.getTxList() + assert.equal(result.length, limit, `limit of ${limit} txs enforced`) + assert.equal(result[0].id, 1, 'early txs truncted') + }) + }) + + describe('#setTxStatusSigned', function() { + it('sets the tx status to signed', function() { + var tx = { id: 1, status: 'unapproved' } + txManager.addTx(tx, onTxDoneCb) + txManager.setTxStatusSigned(1) + var result = txManager.getTxList() + assert.ok(Array.isArray(result)) + assert.equal(result.length, 1) + assert.equal(result[0].status, 'signed') + }) + + it('should emit a signed event to signal the exciton of callback', (done) => { + this.timeout(10000) + var tx = { id: 1, status: 'unapproved' } + txManager.on('signed', function (txId) { + var approvalCb = this._unconfTxCbs[txId] + assert(approvalCb(), 'txCb was retrieved') + assert.equal(txId, 1) + assert(true, 'event listener has been triggered') + done() + }) + txManager.addTx(tx, onTxDoneCb) + txManager.setTxStatusSigned(1) + }) + }) + + describe('#setTxStatusRejected', function() { + it('sets the tx status to rejected', function() { + var tx = { id: 1, status: 'unapproved' } + txManager.addTx(tx) + txManager.setTxStatusRejected(1) + var result = txManager.getTxList() + assert.ok(Array.isArray(result)) + assert.equal(result.length, 1) + assert.equal(result[0].status, 'rejected') + }) + + it('should emit a rejected event to signal the exciton of callback', (done) => { + this.timeout(10000) + var tx = { id: 1, status: 'unapproved' } + txManager.on('rejected', function (txId) { + var approvalCb = this._unconfTxCbs[txId] + assert(approvalCb(), 'txCb was retrieved') + assert.equal(txId, 1) + assert(true, 'event listener has been triggered') + done() + }) + txManager.addTx(tx, onTxDoneCb) + txManager.setTxStatusRejected(1) + }) + + }) + + describe('#updateTx', function() { + it('replaces the tx with the same id', function() { + txManager.addTx({ id: '1', status: 'unapproved' }, onTxDoneCb) + txManager.addTx({ id: '2', status: 'confirmed' }, onTxDoneCb) + txManager.updateTx({ id: '1', status: 'blah', hash: 'foo' }) + var result = txManager.getTx('1') + assert.equal(result.hash, 'foo') + }) + }) + + describe('#getUnapprovedTxList', function() { + it('returns unapproved txs in a hash', function() { + txManager.addTx({ id: '1', status: 'unapproved' }, onTxDoneCb) + txManager.addTx({ id: '2', status: 'confirmed' }, onTxDoneCb) + let result = txManager.getUnapprovedTxList() + assert.equal(typeof result, 'object') + assert.equal(result['1'].status, 'unapproved') + assert.equal(result['0'], undefined) + assert.equal(result['2'], undefined) + }) + }) + + describe('#getTx', function() { + it('returns a tx with the requested id', function() { + txManager.addTx({ id: '1', status: 'unapproved' }, onTxDoneCb) + txManager.addTx({ id: '2', status: 'confirmed' }, onTxDoneCb) + assert.equal(txManager.getTx('1').status, 'unapproved') + assert.equal(txManager.getTx('2').status, 'confirmed') + }) + }) + + describe('#getFilterdTxList', function() { + it('returns a tx with the requested data', function() { + var foop = 0 + var zoop = 0 + for (let i = 0; i < 10; ++i ){ + let evryOther = i % 2 + txManager.addTx({ id: i, + status: evryOther ? 'unapproved' : 'confirmed', + txParams: { + from: evryOther ? 'foop' : 'zoop', + to: evryOther ? 'zoop' : 'foop', + } + }, onTxDoneCb) + evryOther ? ++foop : ++zoop + } + assert.equal(txManager.getFilterdTxList({status: 'confirmed', from: 'zoop'}).length, zoop) + assert.equal(txManager.getFilterdTxList({status: 'confirmed', to: 'foop'}).length, zoop) + assert.equal(txManager.getFilterdTxList({status: 'confirmed', from: 'foop'}).length, 0) + assert.equal(txManager.getFilterdTxList({status: 'confirmed'}).length, zoop) + assert.equal(txManager.getFilterdTxList({from: 'foop'}).length, foop) + assert.equal(txManager.getFilterdTxList({from: 'zoop'}).length, zoop) + }) + }) + +}) -- 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') 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') 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') 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') 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 From 26f1e6cbd2af9d6bb0c58871635466c459cc87d8 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 19 Dec 2016 21:55:02 -0800 Subject: Remove encryptor in favor of external browser-passworder I broke out the encryptor lib into its own module on npm called browser-passworder. --- test/integration/lib/encryptor-test.js | 71 ---------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 test/integration/lib/encryptor-test.js (limited to 'test') 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() - }) -}) - - -- cgit v1.2.3 From 4910e2f9bdf1305469edd9c55c59fb90d0e5267d Mon Sep 17 00:00:00 2001 From: Frances Pangilinan Date: Tue, 20 Dec 2016 13:49:22 -0800 Subject: remove network Id 2 from explorer link and Add network Id 3 --- test/unit/explorer-link-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/explorer-link-test.js b/test/unit/explorer-link-test.js index 961b400fd..8aa58bff9 100644 --- a/test/unit/explorer-link-test.js +++ b/test/unit/explorer-link-test.js @@ -4,7 +4,7 @@ var linkGen = require('../../ui/lib/explorer-link') describe('explorer-link', function() { it('adds testnet prefix to morden test network', function() { - var result = linkGen('hash', '2') + var result = linkGen('hash', '3') assert.notEqual(result.indexOf('testnet'), -1, 'testnet injected') }) -- cgit v1.2.3 From afcad53ef974e557c5dc701d364a88157694464f Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 20 Dec 2016 16:11:49 -0800 Subject: Refine a lostAccount test --- test/unit/idStore-migration-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js index 66dd4683d..8532ac914 100644 --- a/test/unit/idStore-migration-test.js +++ b/test/unit/idStore-migration-test.js @@ -83,7 +83,7 @@ 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') + assert(!state.lostAccounts, 'no lost accounts') }) }) }) -- cgit v1.2.3 From b3533f9bf7bc28988d2f2f280ab6ebc04cf66161 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 20 Dec 2016 17:29:44 -0800 Subject: Fixed another lostAccount test --- test/integration/lib/keyring-controller-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/integration/lib/keyring-controller-test.js b/test/integration/lib/keyring-controller-test.js index 666795a6d..4673e65c2 100644 --- a/test/integration/lib/keyring-controller-test.js +++ b/test/integration/lib/keyring-controller-test.js @@ -44,7 +44,7 @@ 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') + assert.ok(state.lostAccounts, 'no lost accounts') done() }) }) -- cgit v1.2.3 From 6e78494846c9032fbf1264a0225c0df4df0867cb Mon Sep 17 00:00:00 2001 From: Frances Pangilinan Date: Fri, 16 Dec 2016 10:33:36 -0800 Subject: First pass at revision requests --- test/unit/idStore-test.js | 50 ------------------------ test/unit/metamask-controller-test.js | 2 +- test/unit/tx-manager-test.js | 73 ++++++++++++++++++++++------------- 3 files changed, 48 insertions(+), 77 deletions(-) (limited to 'test') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 3ca89cd38..000c58a82 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -139,54 +139,4 @@ describe('IdentityStore', function() { }) }) }) - - describe('#addGasBuffer', function() { - it('formats the result correctly', function() { - const idStore = new IdentityStore({ - configManager: configManagerGen(), - ethStore: { - addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, - }, - }) - - const gas = '0x01' - const bnGas = new BN(gas, 16) - const bnResult = idStore.addGasBuffer(bnGas) - - assert.ok(bnResult.gt(gas), 'added more gas as buffer.') - }) - - it('buffers 20%', function() { - const idStore = new IdentityStore({ - configManager: configManagerGen(), - ethStore: { - addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, - }, - }) - - const gas = '0x04ee59' // Actual estimated gas example - const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16) - const five = new BN('5', 10) - const correctBuffer = bnGas.div(five) - const correct = bnGas.add(correctBuffer) - - const bnResult = idStore.addGasBuffer(bnGas) - - assert(bnResult.gt(bnGas), 'Estimate increased in value.') - assert.equal(bnResult.sub(bnGas).toString(10), correctBuffer.toString(10), 'added 20% gas') - }) - }) - - describe('#checkForDelegateCall', function() { - const idStore = new IdentityStore({ - configManager: configManagerGen(), - ethStore: { - addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, - }, - }) - - var result = idStore.checkForDelegateCall(delegateCallCode) - assert.equal(result, true, 'no delegate call in provided code') - }) - }) diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index b87169ca2..414610404 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -9,7 +9,7 @@ describe('MetaMaskController', function() { let controller = new MetaMaskController({ showUnconfirmedMessage: noop, unlockAccountMessage: noop, - showUnconfirmedTx: noop, + showUnapprovedTx: noop, setData, loadData, }) diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js index 0a7c5e83b..f09068a72 100644 --- a/test/unit/tx-manager-test.js +++ b/test/unit/tx-manager-test.js @@ -1,5 +1,6 @@ const assert = require('assert') const extend = require('xtend') +const EventEmitter = require('events') const STORAGE_KEY = 'metamask-persistance-key' const TransactionManager = require('../../app/scripts/transaction-manager') @@ -9,10 +10,11 @@ describe('Transaction Manager', function() { const onTxDoneCb = () => true beforeEach(function() { txManager = new TransactionManager ({ - TxListFromStore: [], + txList: [], setTxList: () => {}, provider: "testnet", - txLimit: 40, + txHistoryLimit: 10, + blockTracker: new EventEmitter(), }) }) @@ -38,7 +40,7 @@ describe('Transaction Manager', function() { describe('#addTx', function() { it('adds a tx returned in getTxList', function() { - var tx = { id: 1 } + var tx = { id: 1, status: 'confirmed',} txManager.addTx(tx, onTxDoneCb) var result = txManager.getTxList() assert.ok(Array.isArray(result)) @@ -47,15 +49,41 @@ describe('Transaction Manager', function() { }) it('cuts off early txs beyond a limit', function() { - const limit = txManager.txLimit + const limit = txManager.txHistoryLimit for (let i = 0; i < limit + 1; i++) { - let tx = { id: i, time: new Date()} + let tx = { id: i, time: new Date(), status: 'confirmed'} txManager.addTx(tx, onTxDoneCb) } var result = txManager.getTxList() assert.equal(result.length, limit, `limit of ${limit} txs enforced`) assert.equal(result[0].id, 1, 'early txs truncted') }) + + it('cuts off early txs beyond a limit weather or not it is confirmed or rejected', function() { + const limit = txManager.txHistoryLimit + for (let i = 0; i < limit + 1; i++) { + let tx = { id: i, time: new Date(), status: 'rejected'} + txManager.addTx(tx, onTxDoneCb) + } + var result = txManager.getTxList() + assert.equal(result.length, limit, `limit of ${limit} txs enforced`) + assert.equal(result[0].id, 1, 'early txs truncted') + }) + + it('cuts off early txs beyond a limit but does not cut unapproved txs', function() { + var unconfirmedTx = { id: 0, time: new Date(), status: 'unapproved'} + txManager.addTx(unconfirmedTx, onTxDoneCb) + const limit = txManager.txHistoryLimit + for (let i = 1; i < limit + 1; i++) { + let tx = { id: i, time: new Date(), status: 'confirmed'} + txManager.addTx(tx, onTxDoneCb) + } + var result = txManager.getTxList() + assert.equal(result.length, limit, `limit of ${limit} txs enforced`) + assert.equal(result[0].id, 0, 'first tx should still be their') + assert.equal(result[0].status, 'unapproved', 'first tx should be unapproved') + assert.equal(result[1].id, 2, 'early txs truncted') + }) }) describe('#setTxStatusSigned', function() { @@ -72,13 +100,10 @@ describe('Transaction Manager', function() { it('should emit a signed event to signal the exciton of callback', (done) => { this.timeout(10000) var tx = { id: 1, status: 'unapproved' } - txManager.on('signed', function (txId) { - var approvalCb = this._unconfTxCbs[txId] - assert(approvalCb(), 'txCb was retrieved') - assert.equal(txId, 1) - assert(true, 'event listener has been triggered') + let onTxDoneCb = function (err, txId) { + assert(true, 'event listener has been triggered and onTxDoneCb executed') done() - }) + } txManager.addTx(tx, onTxDoneCb) txManager.setTxStatusSigned(1) }) @@ -87,7 +112,7 @@ describe('Transaction Manager', function() { describe('#setTxStatusRejected', function() { it('sets the tx status to rejected', function() { var tx = { id: 1, status: 'unapproved' } - txManager.addTx(tx) + txManager.addTx(tx, onTxDoneCb) txManager.setTxStatusRejected(1) var result = txManager.getTxList() assert.ok(Array.isArray(result)) @@ -98,13 +123,10 @@ describe('Transaction Manager', function() { it('should emit a rejected event to signal the exciton of callback', (done) => { this.timeout(10000) var tx = { id: 1, status: 'unapproved' } - txManager.on('rejected', function (txId) { - var approvalCb = this._unconfTxCbs[txId] - assert(approvalCb(), 'txCb was retrieved') - assert.equal(txId, 1) - assert(true, 'event listener has been triggered') + let onTxDoneCb = function (err, txId) { + assert(true, 'event listener has been triggered and onTxDoneCb executed') done() - }) + } txManager.addTx(tx, onTxDoneCb) txManager.setTxStatusRejected(1) }) @@ -128,7 +150,6 @@ describe('Transaction Manager', function() { let result = txManager.getUnapprovedTxList() assert.equal(typeof result, 'object') assert.equal(result['1'].status, 'unapproved') - assert.equal(result['0'], undefined) assert.equal(result['2'], undefined) }) }) @@ -142,7 +163,7 @@ describe('Transaction Manager', function() { }) }) - describe('#getFilterdTxList', function() { + describe('#getFilteredTxList', function() { it('returns a tx with the requested data', function() { var foop = 0 var zoop = 0 @@ -157,12 +178,12 @@ describe('Transaction Manager', function() { }, onTxDoneCb) evryOther ? ++foop : ++zoop } - assert.equal(txManager.getFilterdTxList({status: 'confirmed', from: 'zoop'}).length, zoop) - assert.equal(txManager.getFilterdTxList({status: 'confirmed', to: 'foop'}).length, zoop) - assert.equal(txManager.getFilterdTxList({status: 'confirmed', from: 'foop'}).length, 0) - assert.equal(txManager.getFilterdTxList({status: 'confirmed'}).length, zoop) - assert.equal(txManager.getFilterdTxList({from: 'foop'}).length, foop) - assert.equal(txManager.getFilterdTxList({from: 'zoop'}).length, zoop) + assert.equal(txManager.getFilteredTxList({status: 'confirmed', from: 'zoop'}).length, zoop) + assert.equal(txManager.getFilteredTxList({status: 'confirmed', to: 'foop'}).length, zoop) + assert.equal(txManager.getFilteredTxList({status: 'confirmed', from: 'foop'}).length, 0) + assert.equal(txManager.getFilteredTxList({status: 'confirmed'}).length, zoop) + assert.equal(txManager.getFilteredTxList({from: 'foop'}).length, foop) + assert.equal(txManager.getFilteredTxList({from: 'zoop'}).length, zoop) }) }) -- cgit v1.2.3 From ebeaf3b3d6cf79e2e0f251b9b2da765f0fe6d0e1 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 21 Dec 2016 17:21:10 -0800 Subject: Restructured migration Migrator now returns a lostAccount array that includes objects these objects include keys of address and privateKey, this allows the MetamaskController to restore the lost accounts even without customizing the idStore or the KeyringController. Also includes a patch that allows idStore to synchronously export private keys. --- test/integration/lib/first-time.js | 2 +- test/integration/lib/idStore-migrator-test.js | 74 ++++++++++++++ test/integration/lib/keyring-controller-test.js | 122 ------------------------ 3 files changed, 75 insertions(+), 123 deletions(-) create mode 100644 test/integration/lib/idStore-migrator-test.js delete mode 100644 test/integration/lib/keyring-controller-test.js (limited to 'test') diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index 12c573db1..1811ccbd4 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -79,7 +79,7 @@ QUnit.test('agree to terms', function (assert) { var createButton = app.find('button.primary')[0] createButton.click() - return wait(1500) + return wait(1000) }).then(function() { var detail = app.find('.account-detail-section')[0] diff --git a/test/integration/lib/idStore-migrator-test.js b/test/integration/lib/idStore-migrator-test.js new file mode 100644 index 000000000..338896171 --- /dev/null +++ b/test/integration/lib/idStore-migrator-test.js @@ -0,0 +1,74 @@ +var KeyringController = require('../../../app/scripts/keyring-controller') +var ConfigManager = require('../../../app/scripts/lib/config-manager') +var IdStoreMigrator = require('../../../app/scripts/lib/idStore-migrator') + +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 SEED = 'fringe damage bounce extend tunnel afraid alert sound all soldier all dinner' + +var BAD_STYLE_FIRST_ADDRESS = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' + +QUnit.module('Old Style Vaults', { + beforeEach: function () { + window.localStorage[STORAGE_KEY] = JSON.stringify(oldStyleVault) + + this.configManager = new ConfigManager({ + loadData: () => { return JSON.parse(window.localStorage[STORAGE_KEY]) }, + setData: (data) => { window.localStorage[STORAGE_KEY] = JSON.stringify(data) }, + }) + + this.migrator = new IdStoreMigrator({ + configManager: this.configManager, + }) + } +}) + +QUnit.test('migrator:isInitialized', function (assert) { + assert.ok(this.migrator) +}) + +QUnit.test('migrator:migratedVaultForPassword', function (assert) { + var done = assert.async() + + this.migrator.migratedVaultForPassword(PASSWORD) + .then((result) => { + const { serialized, lostAccounts } = result + assert.equal(serialized.data.mnemonic, SEED, 'seed phrase recovered') + assert.equal(lostAccounts.length, 0, 'no lost accounts') + 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.migrator = new IdStoreMigrator({ + configManager: this.configManager, + }) + } +}) + +QUnit.test('migrator:migratedVaultForPassword', function (assert) { + var done = assert.async() + + this.migrator.migratedVaultForPassword(PASSWORD) + .then((result) => { + const { serialized, lostAccounts } = result + + assert.equal(lostAccounts.length, 1, 'one lost account') + assert.equal(lostAccounts[0].address, '0xe15D894BeCB0354c501AE69429B05143679F39e0'.toLowerCase()) + assert.ok(lostAccounts[0].privateKey, 'private key exported') + done() + }) +}) + diff --git a/test/integration/lib/keyring-controller-test.js b/test/integration/lib/keyring-controller-test.js deleted file mode 100644 index 4673e65c2..000000000 --- a/test/integration/lib/keyring-controller-test.js +++ /dev/null @@ -1,122 +0,0 @@ -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 () { - window.localStorage[STORAGE_KEY] = JSON.stringify(oldStyleVault) - - 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) -}) - -QUnit.test('keyringController:submitPassword', function (assert) { - var done = assert.async() - - this.keyringController.submitPassword(PASSWORD) - .then((state) => { - assert.ok(state.identities[FIRST_ADDRESS]) - assert.ok(state.lostAccounts, '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() - }) -}) - -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() - }) -}) -- cgit v1.2.3 From fde69ea0baf32b5d2a6932b73f4772e983aef552 Mon Sep 17 00:00:00 2001 From: Frankie Date: Fri, 23 Dec 2016 12:34:12 -0800 Subject: fix some minor spelling mistakes and clean up code --- test/unit/tx-manager-test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js index f09068a72..be16facad 100644 --- a/test/unit/tx-manager-test.js +++ b/test/unit/tx-manager-test.js @@ -80,7 +80,7 @@ describe('Transaction Manager', function() { } var result = txManager.getTxList() assert.equal(result.length, limit, `limit of ${limit} txs enforced`) - assert.equal(result[0].id, 0, 'first tx should still be their') + assert.equal(result[0].id, 0, 'first tx should still be there') assert.equal(result[0].status, 'unapproved', 'first tx should be unapproved') assert.equal(result[1].id, 2, 'early txs truncted') }) @@ -168,15 +168,15 @@ describe('Transaction Manager', function() { var foop = 0 var zoop = 0 for (let i = 0; i < 10; ++i ){ - let evryOther = i % 2 + let everyOther = i % 2 txManager.addTx({ id: i, - status: evryOther ? 'unapproved' : 'confirmed', + status: everyOther ? 'unapproved' : 'confirmed', txParams: { - from: evryOther ? 'foop' : 'zoop', - to: evryOther ? 'zoop' : 'foop', + from: everyOther ? 'foop' : 'zoop', + to: everyOther ? 'zoop' : 'foop', } }, onTxDoneCb) - evryOther ? ++foop : ++zoop + everyOther ? ++foop : ++zoop } assert.equal(txManager.getFilteredTxList({status: 'confirmed', from: 'zoop'}).length, zoop) assert.equal(txManager.getFilteredTxList({status: 'confirmed', to: 'foop'}).length, zoop) -- cgit v1.2.3 From e95c93756968284fbe0c968fd79b9d05498d280f Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 23 Dec 2016 17:09:24 -0800 Subject: Add additional migration test --- test/integration/lib/idStore-migrator-test.js | 21 +++++++++++++++++++-- test/integration/mocks/badVault2.json | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/integration/mocks/badVault2.json (limited to 'test') diff --git a/test/integration/lib/idStore-migrator-test.js b/test/integration/lib/idStore-migrator-test.js index 338896171..4ae30411d 100644 --- a/test/integration/lib/idStore-migrator-test.js +++ b/test/integration/lib/idStore-migrator-test.js @@ -1,6 +1,7 @@ -var KeyringController = require('../../../app/scripts/keyring-controller') var ConfigManager = require('../../../app/scripts/lib/config-manager') var IdStoreMigrator = require('../../../app/scripts/lib/idStore-migrator') +var SimpleKeyring = require('../../../app/scripts/keyrings/simple') +var normalize = require('../../../app/scripts/lib/sig-util').normalize var oldStyleVault = require('../mocks/oldVault.json') var badStyleVault = require('../mocks/badVault.json') @@ -68,7 +69,23 @@ QUnit.test('migrator:migratedVaultForPassword', function (assert) { assert.equal(lostAccounts.length, 1, 'one lost account') assert.equal(lostAccounts[0].address, '0xe15D894BeCB0354c501AE69429B05143679F39e0'.toLowerCase()) assert.ok(lostAccounts[0].privateKey, 'private key exported') - done() + + var lostAccount = lostAccounts[0] + var privateKey = lostAccount.privateKey + + var simple = new SimpleKeyring() + simple.deserialize([privateKey]) + .then(() => { + return simple.getAccounts() + }) + .then((accounts) => { + assert.equal(normalize(accounts[0]), lostAccount.address, 'recovered address.') + done() + }) + .catch((reason) => { + assert.ifError(reason) + done(reason) + }) }) }) diff --git a/test/integration/mocks/badVault2.json b/test/integration/mocks/badVault2.json new file mode 100644 index 000000000..4b7aec386 --- /dev/null +++ b/test/integration/mocks/badVault2.json @@ -0,0 +1 @@ +{"meta":{"version":4},"data":{"fiatCurrency":"USD","isConfirmed":true,"TOSHash":"a4f4e23f823a7ac51783e7ffba7914a911b09acdb97263296b7e14b527f80c5b","noticesList":[{"read":true,"date":"Fri Dec 16 2016","title":"Ending Morden Support","body":"Due to [recent events](https://blog.ethereum.org/2016/11/20/from-morden-to-ropsten/), MetaMask is now deprecating support for the Morden Test Network.\n\nUsers will still be able to access Morden through a locally hosted node, but we will no longer be providing hosted access to this network through [Infura](http://infura.io/).\n\nPlease use the new Ropsten Network as your new default test network.\n\nYou can fund your Ropsten account using the buy button on your account page.\n\nBest wishes!\nThe MetaMask Team\n\n","id":0}],"conversionRate":7.07341909,"conversionDate":1482539284,"wallet":"{\"encSeed\":{\"encStr\":\"LZsdN8lJzYkUe1UpmAalnERdgkBFt25gWDdK8kfQUwMAk/27XR+dc+8n5swgoF5qgwhc9LBgliEGNDs1Q/lnuld3aQLabkOeAW4BHS1vS7FxqKrzDS3iyzSuQO6wDQmGno/buuknVgDsKiyjW22hpt7vtVVWA+ZL1P3x6M0+AxGJjeGVrG+E8Q==\",\"nonce\":\"T6O9BmwmTj214XUK3KF0s3iCKo3OlrUD\"},\"ksData\":{\"m/44'/60'/0'/0\":{\"info\":{\"curve\":\"secp256k1\",\"purpose\":\"sign\"},\"encHdPathPriv\":{\"encStr\":\"GNNfZevCMlgMVh9y21y1UwrC9qcmH6XYq7v+9UoqbHnzPQJFlxidN5+x/Sldo72a6+5zJpQkkdZ+Q0lePrzvXfuSd3D/RO7WKFIKo9nAQI5+JWwz4INuCmVcmqCv2J4BTLGjrG8fp5pDJ62Bn0XHqkJo3gx3fpvs3cS66+ZKwg==\",\"nonce\":\"HRTlGj44khQs2veYHEF/GqTI1t0yYvyd\"},\"hdIndex\":3,\"encPrivKeys\":{\"e15d894becb0354c501ae69429b05143679f39e0\":{\"key\":\"ZAeZL9VcRUtiiO4VXOQKBFg787PR5R3iymjUeU5vpDRIqOXbjWN6N4ZNR8YpSXl+\",\"nonce\":\"xLsADagS8uqDYae6cImyhxF7o1kBDbPe\"},\"87658c15aefe7448008a28513a11b6b130ef4cd0\":{\"key\":\"ku0mm5s1agRJNAMYIJO0qeoDe+FqcbqdQI6azXF3GL1OLo6uMlt6I4qS+eeravFi\",\"nonce\":\"xdGfSUPKtkW8ge0SWIbbpahs/NyEMzn5\"},\"aa25854c0379e53c957ac9382e720c577fa31fd5\":{\"key\":\"NjpYC9FbiC95CTx/1kwgOHk5LSN9vl4RULEBbvwfVOjqSH8WixNoP3R6I/QyNIs2\",\"nonce\":\"M/HWpXXA9QvuZxEykkGQPJKKdz33ovQr\"}},\"addresses\":[\"e15d894becb0354c501ae69429b05143679f39e0\",\"87658c15aefe7448008a28513a11b6b130ef4cd0\",\"aa25854c0379e53c957ac9382e720c577fa31fd5\"]}},\"encHdRootPriv\":{\"encStr\":\"f+3prUOzl+95aNAV+ad6lZdsYZz120ZsL67ucjj3tiMXf/CC4X8XB9N2QguhoMy6fW+fATUsTdJe8+CbAAyb79V9HY0Pitzq9Yw/g1g0/Ii2JzsdGBriuMsPdwZSVqz+rvQFw/6Qms1xjW6cqa8S7kM2WA5l8RB1Ck6r5zaqbA==\",\"nonce\":\"oGahxNFekVxH9sg6PUCCHIByvo4WFSqm\"},\"salt\":\"N7xYoEA53yhSweOsEphku1UKkIEuZtX2MwLBhVM6RR8=\",\"version\":2}","config":{"provider":{"type":"testnet"},"selectedAccount":"0xe15d894becb0354c501ae69429b05143679f39e0"},"isDisclaimerConfirmed":true,"walletNicknames":{"0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9":"Account 1","0xd7c0cd9e7d2701c710d64fc492c7086679bdf7b4":"Account 2","0x1acfb961c5a8268eac8e09d6241a26cbeff42241":"Account 3"},"lostAccounts":["0xe15d894becb0354c501ae69429b05143679f39e0","0x87658c15aefe7448008a28513a11b6b130ef4cd0","0xaa25854c0379e53c957ac9382e720c577fa31fd5"]}} \ No newline at end of file -- cgit v1.2.3 From 5e8a344f973fabb331db9b491247396117aa67b1 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 23 Dec 2016 17:31:24 -0800 Subject: Correct getState test to be async --- test/unit/idStore-migration-test.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js index 8532ac914..ad4ce2096 100644 --- a/test/unit/idStore-migration-test.js +++ b/test/unit/idStore-migration-test.js @@ -79,11 +79,14 @@ describe('IdentityStore to KeyringController migration', function() { }) describe('entering a password', function() { - it('should identify an old wallet as an initialized keyring', function() { + it('should identify an old wallet as an initialized keyring', function(done) { keyringController.configManager.setWallet('something') - const state = keyringController.getState() - assert(state.isInitialized, 'old vault counted as initialized.') - assert(!state.lostAccounts, 'no lost accounts') + keyringController.getState() + .then((state) => { + assert(state.isInitialized, 'old vault counted as initialized.') + assert(!state.lostAccounts, 'no lost accounts') + done() + }) }) }) }) -- cgit v1.2.3 From bd382f4705ffdc10d193d02dfaa9d1b5ff2f1488 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 10 Jan 2017 12:39:01 -0800 Subject: tests - add fetch polyfill --- test/unit/config-manager-test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index 075abbe65..77d431d5f 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -1,8 +1,10 @@ +// polyfill fetch +global.fetch = global.fetch || require('isomorphic-fetch') const assert = require('assert') const extend = require('xtend') const rp = require('request-promise') const nock = require('nock') -var configManagerGen = require('../lib/mock-config-manager') +const configManagerGen = require('../lib/mock-config-manager') const STORAGE_KEY = 'metamask-persistance-key' describe('config-manager', function() { -- cgit v1.2.3 From 8012ede12698477692b80769781096b559159a32 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 11 Jan 2017 19:04:19 -0800 Subject: background - introduce ObservableStore --- test/integration/lib/idStore-migrator-test.js | 33 ++++++++++++--------------- 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'test') diff --git a/test/integration/lib/idStore-migrator-test.js b/test/integration/lib/idStore-migrator-test.js index 4ae30411d..1ceaac442 100644 --- a/test/integration/lib/idStore-migrator-test.js +++ b/test/integration/lib/idStore-migrator-test.js @@ -1,25 +1,23 @@ -var ConfigManager = require('../../../app/scripts/lib/config-manager') -var IdStoreMigrator = require('../../../app/scripts/lib/idStore-migrator') -var SimpleKeyring = require('../../../app/scripts/keyrings/simple') -var normalize = require('../../../app/scripts/lib/sig-util').normalize +const ObservableStore = require('../../../app/scripts/lib/observable/') +const ConfigManager = require('../../../app/scripts/lib/config-manager') +const IdStoreMigrator = require('../../../app/scripts/lib/idStore-migrator') +const SimpleKeyring = require('../../../app/scripts/keyrings/simple') +const normalize = require('../../../app/scripts/lib/sig-util').normalize -var oldStyleVault = require('../mocks/oldVault.json') -var badStyleVault = require('../mocks/badVault.json') +const oldStyleVault = require('../mocks/oldVault.json') +const badStyleVault = require('../mocks/badVault.json') -var STORAGE_KEY = 'metamask-config' -var PASSWORD = '12345678' -var FIRST_ADDRESS = '0x4dd5d356c5A016A220bCD69e82e5AF680a430d00'.toLowerCase() -var SEED = 'fringe damage bounce extend tunnel afraid alert sound all soldier all dinner' - -var BAD_STYLE_FIRST_ADDRESS = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' +const PASSWORD = '12345678' +const FIRST_ADDRESS = '0x4dd5d356c5A016A220bCD69e82e5AF680a430d00'.toLowerCase() +const BAD_STYLE_FIRST_ADDRESS = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' +const SEED = 'fringe damage bounce extend tunnel afraid alert sound all soldier all dinner' QUnit.module('Old Style Vaults', { beforeEach: function () { - window.localStorage[STORAGE_KEY] = JSON.stringify(oldStyleVault) + let store = new ObservableStore(oldStyleVault) this.configManager = new ConfigManager({ - loadData: () => { return JSON.parse(window.localStorage[STORAGE_KEY]) }, - setData: (data) => { window.localStorage[STORAGE_KEY] = JSON.stringify(data) }, + store: store, }) this.migrator = new IdStoreMigrator({ @@ -46,11 +44,10 @@ QUnit.test('migrator:migratedVaultForPassword', function (assert) { QUnit.module('Old Style Vaults with bad HD seed', { beforeEach: function () { - window.localStorage[STORAGE_KEY] = JSON.stringify(badStyleVault) + let store = new ObservableStore(badStyleVault) this.configManager = new ConfigManager({ - loadData: () => { return JSON.parse(window.localStorage[STORAGE_KEY]) }, - setData: (data) => { window.localStorage[STORAGE_KEY] = JSON.stringify(data) }, + store: store, }) this.migrator = new IdStoreMigrator({ -- cgit v1.2.3 From 2019c02fc0fc33d4bd98416654370250d7aa0ca6 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 11 Jan 2017 19:26:56 -0800 Subject: test - fix tests from obs-store --- test/lib/mock-config-manager.js | 7 +++++-- test/unit/idStore-migration-test.js | 8 ++++---- test/unit/metamask-controller-test.js | 6 ++++-- 3 files changed, 13 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/lib/mock-config-manager.js b/test/lib/mock-config-manager.js index b79f63090..0e84aa001 100644 --- a/test/lib/mock-config-manager.js +++ b/test/lib/mock-config-manager.js @@ -1,9 +1,12 @@ -var ConfigManager = require('../../app/scripts/lib/config-manager') +const ConfigManager = require('../../app/scripts/lib/config-manager') +const ObservableStore = require('../../app/scripts/lib/observable/') const STORAGE_KEY = 'metamask-config' const extend = require('xtend') module.exports = function() { - return new ConfigManager({ loadData, setData }) + let store = new ObservableStore(loadData()) + store.subscribe(setData) + return new ConfigManager({ store }) } function loadData () { diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js index 54f38fb2f..4adbef740 100644 --- a/test/unit/idStore-migration-test.js +++ b/test/unit/idStore-migration-test.js @@ -3,6 +3,7 @@ const assert = require('assert') const ethUtil = require('ethereumjs-util') const BN = ethUtil.BN const ConfigManager = require('../../app/scripts/lib/config-manager') +const ObservableStore = require('../../app/scripts/lib/observable/') const delegateCallCode = require('../lib/example-code.json').delegateCallCode // The old way: @@ -42,10 +43,9 @@ describe('IdentityStore to KeyringController migration', function() { beforeEach(function(done) { this.sinon = sinon.sandbox.create() window.localStorage = {} // Hacking localStorage support into JSDom - configManager = new ConfigManager({ - loadData, - setData: (d) => { window.localStorage = d } - }) + let store = new ObservableStore(loadData()) + store.subscribe(setData) + configManager = new ConfigManager({ store }) idStore = new IdentityStore({ diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index 414610404..e648ebd1d 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -10,9 +10,11 @@ describe('MetaMaskController', function() { showUnconfirmedMessage: noop, unlockAccountMessage: noop, showUnapprovedTx: noop, - setData, - loadData, + // initial state + initState: loadData(), }) + // setup state persistence + controller.store.subscribe(setData) beforeEach(function() { // sinon allows stubbing methods that are easily verified -- cgit v1.2.3 From 3bc996878b467e1fa5fd63656bd465377daa137d Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 11 Jan 2017 22:47:56 -0800 Subject: background - move pojo migrator to outside of metamask controller --- test/integration/lib/idStore-migrator-test.js | 44 +++++++++--------- test/lib/mock-config-manager.js | 64 +++------------------------ test/unit/config-manager-test.js | 10 ++++- 3 files changed, 39 insertions(+), 79 deletions(-) (limited to 'test') diff --git a/test/integration/lib/idStore-migrator-test.js b/test/integration/lib/idStore-migrator-test.js index 1ceaac442..d95cfb401 100644 --- a/test/integration/lib/idStore-migrator-test.js +++ b/test/integration/lib/idStore-migrator-test.js @@ -4,8 +4,8 @@ const IdStoreMigrator = require('../../../app/scripts/lib/idStore-migrator') const SimpleKeyring = require('../../../app/scripts/keyrings/simple') const normalize = require('../../../app/scripts/lib/sig-util').normalize -const oldStyleVault = require('../mocks/oldVault.json') -const badStyleVault = require('../mocks/badVault.json') +const oldStyleVault = require('../mocks/oldVault.json').data +const badStyleVault = require('../mocks/badVault.json').data const PASSWORD = '12345678' const FIRST_ADDRESS = '0x4dd5d356c5A016A220bCD69e82e5AF680a430d00'.toLowerCase() @@ -14,15 +14,10 @@ const SEED = 'fringe damage bounce extend tunnel afraid alert sound all soldier QUnit.module('Old Style Vaults', { beforeEach: function () { - let store = new ObservableStore(oldStyleVault) - - this.configManager = new ConfigManager({ - store: store, - }) - - this.migrator = new IdStoreMigrator({ - configManager: this.configManager, - }) + let managers = managersFromInitState(oldStyleVault) + + this.configManager = managers.configManager + this.migrator = managers.migrator } }) @@ -35,6 +30,7 @@ QUnit.test('migrator:migratedVaultForPassword', function (assert) { this.migrator.migratedVaultForPassword(PASSWORD) .then((result) => { + assert.ok(result, 'migratedVaultForPassword returned result') const { serialized, lostAccounts } = result assert.equal(serialized.data.mnemonic, SEED, 'seed phrase recovered') assert.equal(lostAccounts.length, 0, 'no lost accounts') @@ -44,15 +40,10 @@ QUnit.test('migrator:migratedVaultForPassword', function (assert) { QUnit.module('Old Style Vaults with bad HD seed', { beforeEach: function () { - let store = new ObservableStore(badStyleVault) - - this.configManager = new ConfigManager({ - store: store, - }) - - this.migrator = new IdStoreMigrator({ - configManager: this.configManager, - }) + let managers = managersFromInitState(badStyleVault) + + this.configManager = managers.configManager + this.migrator = managers.migrator } }) @@ -61,6 +52,7 @@ QUnit.test('migrator:migratedVaultForPassword', function (assert) { this.migrator.migratedVaultForPassword(PASSWORD) .then((result) => { + assert.ok(result, 'migratedVaultForPassword returned result') const { serialized, lostAccounts } = result assert.equal(lostAccounts.length, 1, 'one lost account') @@ -86,3 +78,15 @@ QUnit.test('migrator:migratedVaultForPassword', function (assert) { }) }) +function managersFromInitState(initState){ + + let configManager = new ConfigManager({ + store: new ObservableStore(initState), + }) + + let migrator = new IdStoreMigrator({ + configManager: configManager, + }) + + return { configManager, migrator } +} \ No newline at end of file diff --git a/test/lib/mock-config-manager.js b/test/lib/mock-config-manager.js index 0e84aa001..c62d91da9 100644 --- a/test/lib/mock-config-manager.js +++ b/test/lib/mock-config-manager.js @@ -1,61 +1,11 @@ const ConfigManager = require('../../app/scripts/lib/config-manager') -const ObservableStore = require('../../app/scripts/lib/observable/') +const LocalStorageStore = require('../../app/scripts/lib/observable/local-storage') +const firstTimeState = require('../../app/scripts/first-time-state') const STORAGE_KEY = 'metamask-config' -const extend = require('xtend') module.exports = function() { - let store = new ObservableStore(loadData()) - store.subscribe(setData) - return new ConfigManager({ store }) -} - -function loadData () { - var oldData = getOldStyleData() - var newData - - try { - newData = JSON.parse(window.localStorage[STORAGE_KEY]) - } catch (e) {} - - var data = extend({ - meta: { - version: 0, - }, - data: { - config: { - provider: { - type: 'testnet', - }, - }, - }, - }, oldData || null, newData || null) - return data -} - -function getOldStyleData () { - var config, wallet, seedWords - - var result = { - meta: { version: 0 }, - data: {}, - } - - try { - config = JSON.parse(window.localStorage['config']) - result.data.config = config - } catch (e) {} - try { - wallet = JSON.parse(window.localStorage['lightwallet']) - result.data.wallet = wallet - } catch (e) {} - try { - seedWords = window.localStorage['seedWords'] - result.data.seedWords = seedWords - } catch (e) {} - - return result -} - -function setData (data) { - window.localStorage[STORAGE_KEY] = JSON.stringify(data) -} + let dataStore = new LocalStorageStore({ storageKey: STORAGE_KEY }) + // initial state for first time users + if (!dataStore.get()) dataStore.put(firstTimeState) + return new ConfigManager({ store: dataStore }) +} \ No newline at end of file diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index 77d431d5f..83b242a8b 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -1,5 +1,8 @@ // polyfill fetch global.fetch = global.fetch || require('isomorphic-fetch') +// pollyfill localStorage support into JSDom +global.localStorage = global.localStorage || polyfillLocalStorage() + const assert = require('assert') const extend = require('xtend') const rp = require('request-promise') @@ -11,7 +14,7 @@ describe('config-manager', function() { var configManager beforeEach(function() { - window.localStorage = {} // Hacking localStorage support into JSDom + global.localStorage.clear() configManager = configManagerGen() }) @@ -132,7 +135,6 @@ describe('config-manager', function() { }) describe('#setConfig', function() { - window.localStorage = {} // Hacking localStorage support into JSDom it('should set the config key', function () { var testConfig = { @@ -238,3 +240,7 @@ describe('config-manager', function() { }) }) }) + +function polyfillLocalStorage(){ + return Object.create({ clear: function(){ global.localStorage = polyfillLocalStorage() } }) +} -- cgit v1.2.3 From b33c51c0a6c7c8a7b0c0a9a6ca101f874f2db3d1 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 12 Jan 2017 01:17:05 -0800 Subject: migrations - introduce promise-based migrator --- test/unit/migrations-test.js | 48 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'test') diff --git a/test/unit/migrations-test.js b/test/unit/migrations-test.js index 9ea8d5c5a..715a5feb0 100644 --- a/test/unit/migrations-test.js +++ b/test/unit/migrations-test.js @@ -1,34 +1,34 @@ -var assert = require('assert') -var path = require('path') +const assert = require('assert') +const path = require('path') -var wallet1 = require(path.join('..', 'lib', 'migrations', '001.json')) +const wallet1 = require(path.join('..', 'lib', 'migrations', '001.json')) -var migration2 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '002')) -var migration3 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '003')) -var migration4 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '004')) +const migration2 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '002')) +const migration3 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '003')) +const migration4 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '004')) -describe('wallet1 is migrated successfully', function() { +const oldTestRpc = 'https://rawtestrpc.metamask.io/' +const newTestRpc = 'https://testrpc.metamask.io/' - it('should convert providers', function(done) { +describe('wallet1 is migrated successfully', function() { + it('should convert providers', function() { wallet1.data.config.provider = { type: 'etherscan', rpcTarget: null } - var firstResult = migration2.migrate(wallet1.data) - assert.equal(firstResult.config.provider.type, 'rpc', 'provider should be rpc') - assert.equal(firstResult.config.provider.rpcTarget, 'https://rpc.metamask.io/', 'main provider should be our rpc') - - var oldTestRpc = 'https://rawtestrpc.metamask.io/' - var newTestRpc = 'https://testrpc.metamask.io/' - firstResult.config.provider.rpcTarget = oldTestRpc - - var secondResult = migration3.migrate(firstResult) - assert.equal(secondResult.config.provider.rpcTarget, newTestRpc) - - var thirdResult = migration4.migrate(secondResult) - assert.equal(secondResult.config.provider.rpcTarget, null) - assert.equal(secondResult.config.provider.type, 'testnet') - - done() + return migration2.migrate(wallet1) + .then((firstResult) => { + assert.equal(firstResult.data.config.provider.type, 'rpc', 'provider should be rpc') + assert.equal(firstResult.data.config.provider.rpcTarget, 'https://rpc.metamask.io/', 'main provider should be our rpc') + firstResult.data.config.provider.rpcTarget = oldTestRpc + return migration3.migrate(firstResult) + }).then((secondResult) => { + assert.equal(secondResult.data.config.provider.rpcTarget, newTestRpc) + return migration4.migrate(secondResult) + }).then((thirdResult) => { + assert.equal(thirdResult.data.config.provider.rpcTarget, null) + assert.equal(thirdResult.data.config.provider.type, 'testnet') + }) + }) }) -- cgit v1.2.3 From 29e83d71a82bfdbeadc9fbecfa97d73ef11fecfb Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 13 Jan 2017 02:00:11 -0800 Subject: background - handle tx finalization in controllers instead of provider-engine --- test/unit/metamask-controller-test.js | 18 ------------------ test/unit/tx-manager-test.js | 31 +++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 22 deletions(-) (limited to 'test') diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index 414610404..a6164c9a0 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -25,24 +25,6 @@ describe('MetaMaskController', function() { this.sinon.restore() }) - describe('#enforceTxValidations', function () { - it('returns null for positive values', function() { - var sample = { - value: '0x01' - } - var res = controller.enforceTxValidations(sample) - assert.equal(res, null, 'no error') - }) - - - it('returns error for negative values', function() { - var sample = { - value: '-0x01' - } - var res = controller.enforceTxValidations(sample) - assert.ok(res, 'error') - }) - }) }) diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js index be16facad..d5d386234 100644 --- a/test/unit/tx-manager-test.js +++ b/test/unit/tx-manager-test.js @@ -18,6 +18,27 @@ describe('Transaction Manager', function() { }) }) + describe('#validateTxParams', function () { + it('returns null for positive values', function() { + var sample = { + value: '0x01' + } + var res = txManager.validateTxParams(sample, (err) => { + assert.equal(err, null, 'no error') + }) + }) + + + it('returns error for negative values', function() { + var sample = { + value: '-0x01' + } + var res = txManager.validateTxParams(sample, (err) => { + assert.ok(err, 'error') + }) + }) + }) + describe('#getTxList', function() { it('when new should return empty array', function() { var result = txManager.getTxList() @@ -100,11 +121,12 @@ describe('Transaction Manager', function() { it('should emit a signed event to signal the exciton of callback', (done) => { this.timeout(10000) var tx = { id: 1, status: 'unapproved' } - let onTxDoneCb = function (err, txId) { + let onTxDoneCb = function () { assert(true, 'event listener has been triggered and onTxDoneCb executed') done() } - txManager.addTx(tx, onTxDoneCb) + txManager.addTx(tx) + txManager.on('1:signed', onTxDoneCb) txManager.setTxStatusSigned(1) }) }) @@ -112,7 +134,7 @@ describe('Transaction Manager', function() { describe('#setTxStatusRejected', function() { it('sets the tx status to rejected', function() { var tx = { id: 1, status: 'unapproved' } - txManager.addTx(tx, onTxDoneCb) + txManager.addTx(tx) txManager.setTxStatusRejected(1) var result = txManager.getTxList() assert.ok(Array.isArray(result)) @@ -123,11 +145,12 @@ describe('Transaction Manager', function() { it('should emit a rejected event to signal the exciton of callback', (done) => { this.timeout(10000) var tx = { id: 1, status: 'unapproved' } + txManager.addTx(tx) let onTxDoneCb = function (err, txId) { assert(true, 'event listener has been triggered and onTxDoneCb executed') done() } - txManager.addTx(tx, onTxDoneCb) + txManager.on('1:rejected', onTxDoneCb) txManager.setTxStatusRejected(1) }) -- cgit v1.2.3 From 87505e1742ee56e78fed7f17645f58bf169c4ef7 Mon Sep 17 00:00:00 2001 From: Frankie Date: Fri, 13 Jan 2017 18:01:50 -0800 Subject: fix for linting --- test/unit/tx-manager-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js index d5d386234..5f18e357f 100644 --- a/test/unit/tx-manager-test.js +++ b/test/unit/tx-manager-test.js @@ -23,7 +23,7 @@ describe('Transaction Manager', function() { var sample = { value: '0x01' } - var res = txManager.validateTxParams(sample, (err) => { + var res = txManager.txProviderUtils.validateTxParams(sample, (err) => { assert.equal(err, null, 'no error') }) }) @@ -33,7 +33,7 @@ describe('Transaction Manager', function() { var sample = { value: '-0x01' } - var res = txManager.validateTxParams(sample, (err) => { + var res = txManager.txProviderUtils.validateTxParams(sample, (err) => { assert.ok(err, 'error') }) }) -- cgit v1.2.3 From 3df9ce9809b18253f990458a404a65f01b1947c4 Mon Sep 17 00:00:00 2001 From: kumavis Date: Sat, 14 Jan 2017 21:52:09 -0800 Subject: tests - txManager - add getNetwork fn to fixture txManager --- test/unit/tx-manager-test.js | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js index 5f18e357f..20392a5ca 100644 --- a/test/unit/tx-manager-test.js +++ b/test/unit/tx-manager-test.js @@ -15,6 +15,7 @@ describe('Transaction Manager', function() { provider: "testnet", txHistoryLimit: 10, blockTracker: new EventEmitter(), + getNetwork: function(){ return 'unit test' } }) }) -- cgit v1.2.3 From 993daebc4e67346b8eeedb0af50e34bc451d0400 Mon Sep 17 00:00:00 2001 From: kumavis Date: Sat, 14 Jan 2017 22:09:19 -0800 Subject: test - txManager - add network to all txs --- test/unit/tx-manager-test.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'test') diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js index 20392a5ca..a66003f85 100644 --- a/test/unit/tx-manager-test.js +++ b/test/unit/tx-manager-test.js @@ -53,7 +53,7 @@ describe('Transaction Manager', function() { describe('#_saveTxList', function() { it('saves the submitted data to the tx list', function() { - var target = [{ foo: 'bar' }] + var target = [{ foo: 'bar', metamaskNetworkId: 'unit test' }] txManager._saveTxList(target) var result = txManager.getTxList() assert.equal(result[0].foo, 'bar') @@ -62,7 +62,7 @@ describe('Transaction Manager', function() { describe('#addTx', function() { it('adds a tx returned in getTxList', function() { - var tx = { id: 1, status: 'confirmed',} + var tx = { id: 1, status: 'confirmed', metamaskNetworkId: 'unit test' } txManager.addTx(tx, onTxDoneCb) var result = txManager.getTxList() assert.ok(Array.isArray(result)) @@ -73,7 +73,7 @@ describe('Transaction Manager', function() { it('cuts off early txs beyond a limit', function() { const limit = txManager.txHistoryLimit for (let i = 0; i < limit + 1; i++) { - let tx = { id: i, time: new Date(), status: 'confirmed'} + let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: 'unit test' } txManager.addTx(tx, onTxDoneCb) } var result = txManager.getTxList() @@ -81,10 +81,10 @@ describe('Transaction Manager', function() { assert.equal(result[0].id, 1, 'early txs truncted') }) - it('cuts off early txs beyond a limit weather or not it is confirmed or rejected', function() { + it('cuts off early txs beyond a limit whether or not it is confirmed or rejected', function() { const limit = txManager.txHistoryLimit for (let i = 0; i < limit + 1; i++) { - let tx = { id: i, time: new Date(), status: 'rejected'} + let tx = { id: i, time: new Date(), status: 'rejected', metamaskNetworkId: 'unit test' } txManager.addTx(tx, onTxDoneCb) } var result = txManager.getTxList() @@ -93,11 +93,11 @@ describe('Transaction Manager', function() { }) it('cuts off early txs beyond a limit but does not cut unapproved txs', function() { - var unconfirmedTx = { id: 0, time: new Date(), status: 'unapproved'} + var unconfirmedTx = { id: 0, time: new Date(), status: 'unapproved', metamaskNetworkId: 'unit test' } txManager.addTx(unconfirmedTx, onTxDoneCb) const limit = txManager.txHistoryLimit for (let i = 1; i < limit + 1; i++) { - let tx = { id: i, time: new Date(), status: 'confirmed'} + let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: 'unit test' } txManager.addTx(tx, onTxDoneCb) } var result = txManager.getTxList() @@ -110,7 +110,7 @@ describe('Transaction Manager', function() { describe('#setTxStatusSigned', function() { it('sets the tx status to signed', function() { - var tx = { id: 1, status: 'unapproved' } + var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } txManager.addTx(tx, onTxDoneCb) txManager.setTxStatusSigned(1) var result = txManager.getTxList() @@ -121,7 +121,7 @@ describe('Transaction Manager', function() { it('should emit a signed event to signal the exciton of callback', (done) => { this.timeout(10000) - var tx = { id: 1, status: 'unapproved' } + var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } let onTxDoneCb = function () { assert(true, 'event listener has been triggered and onTxDoneCb executed') done() @@ -134,7 +134,7 @@ describe('Transaction Manager', function() { describe('#setTxStatusRejected', function() { it('sets the tx status to rejected', function() { - var tx = { id: 1, status: 'unapproved' } + var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } txManager.addTx(tx) txManager.setTxStatusRejected(1) var result = txManager.getTxList() @@ -145,7 +145,7 @@ describe('Transaction Manager', function() { it('should emit a rejected event to signal the exciton of callback', (done) => { this.timeout(10000) - var tx = { id: 1, status: 'unapproved' } + var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } txManager.addTx(tx) let onTxDoneCb = function (err, txId) { assert(true, 'event listener has been triggered and onTxDoneCb executed') @@ -159,9 +159,9 @@ describe('Transaction Manager', function() { describe('#updateTx', function() { it('replaces the tx with the same id', function() { - txManager.addTx({ id: '1', status: 'unapproved' }, onTxDoneCb) - txManager.addTx({ id: '2', status: 'confirmed' }, onTxDoneCb) - txManager.updateTx({ id: '1', status: 'blah', hash: 'foo' }) + txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }, onTxDoneCb) + txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test' }, onTxDoneCb) + txManager.updateTx({ id: '1', status: 'blah', hash: 'foo', metamaskNetworkId: 'unit test' }) var result = txManager.getTx('1') assert.equal(result.hash, 'foo') }) @@ -169,8 +169,8 @@ describe('Transaction Manager', function() { describe('#getUnapprovedTxList', function() { it('returns unapproved txs in a hash', function() { - txManager.addTx({ id: '1', status: 'unapproved' }, onTxDoneCb) - txManager.addTx({ id: '2', status: 'confirmed' }, onTxDoneCb) + txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }, onTxDoneCb) + txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test' }, onTxDoneCb) let result = txManager.getUnapprovedTxList() assert.equal(typeof result, 'object') assert.equal(result['1'].status, 'unapproved') @@ -180,8 +180,8 @@ describe('Transaction Manager', function() { describe('#getTx', function() { it('returns a tx with the requested id', function() { - txManager.addTx({ id: '1', status: 'unapproved' }, onTxDoneCb) - txManager.addTx({ id: '2', status: 'confirmed' }, onTxDoneCb) + txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }, onTxDoneCb) + txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test' }, onTxDoneCb) assert.equal(txManager.getTx('1').status, 'unapproved') assert.equal(txManager.getTx('2').status, 'confirmed') }) @@ -195,6 +195,7 @@ describe('Transaction Manager', function() { let everyOther = i % 2 txManager.addTx({ id: i, status: everyOther ? 'unapproved' : 'confirmed', + metamaskNetworkId: 'unit test', txParams: { from: everyOther ? 'foop' : 'zoop', to: everyOther ? 'zoop' : 'foop', -- cgit v1.2.3 From 91e5cc0f29df68dc57edc3404d90d969e4345bf2 Mon Sep 17 00:00:00 2001 From: kumavis Date: Sat, 14 Jan 2017 22:30:12 -0800 Subject: test - clear localStorage in case CI caches it (?) --- test/unit/notice-controller-test.js | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/unit/notice-controller-test.js b/test/unit/notice-controller-test.js index 4aa4c8e7b..e953fc580 100644 --- a/test/unit/notice-controller-test.js +++ b/test/unit/notice-controller-test.js @@ -6,6 +6,7 @@ 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 +if (window.localStorage) window.localStorage.clear() window.localStorage = {} describe('notice-controller', function() { -- cgit v1.2.3 From 85634326e8b7fd077b36d4b007190da2a66d6a89 Mon Sep 17 00:00:00 2001 From: kumavis Date: Sat, 14 Jan 2017 22:35:26 -0800 Subject: test - clear localStorage on test start --- test/unit/notice-controller-test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/unit/notice-controller-test.js b/test/unit/notice-controller-test.js index e953fc580..cf00daeba 100644 --- a/test/unit/notice-controller-test.js +++ b/test/unit/notice-controller-test.js @@ -5,14 +5,14 @@ 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 -if (window.localStorage) window.localStorage.clear() -window.localStorage = {} describe('notice-controller', function() { var noticeController beforeEach(function() { + // simple localStorage polyfill + window.localStorage = {} + if (window.localStorage.clear) window.localStorage.clear() let configManager = configManagerGen() noticeController = new NoticeController({ configManager: configManager, -- cgit v1.2.3 From 4a09f856d11660db3118d05f98eb410d3b208b56 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 16 Jan 2017 12:08:20 -0800 Subject: test - keyring - simple - fix fixture data --- test/unit/keyrings/simple-test.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/unit/keyrings/simple-test.js b/test/unit/keyrings/simple-test.js index 979abdb69..687318f99 100644 --- a/test/unit/keyrings/simple-test.js +++ b/test/unit/keyrings/simple-test.js @@ -1,5 +1,6 @@ const assert = require('assert') const extend = require('xtend') +const ethUtil = require('ethereumjs-util') const SimpleKeyring = require('../../../app/scripts/keyrings/simple') const TYPE_STR = 'Simple Key Pair' @@ -72,14 +73,10 @@ describe('simple-keyring', function() { it('calls getAddress on each wallet', function(done) { // Push a mock wallet - const desiredOutput = 'foo' + const desiredOutput = '0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761' keyring.wallets.push({ getAddress() { - return { - toString() { - return desiredOutput - } - } + return ethUtil.toBuffer(desiredOutput) } }) -- cgit v1.2.3 From 7e886dff778f7772f5664491a1255614c08483f2 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 16 Jan 2017 23:26:37 -0800 Subject: Wrote failing test for eth.sign --- test/unit/keyrings/simple-test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test') diff --git a/test/unit/keyrings/simple-test.js b/test/unit/keyrings/simple-test.js index 687318f99..77eeb834c 100644 --- a/test/unit/keyrings/simple-test.js +++ b/test/unit/keyrings/simple-test.js @@ -49,6 +49,24 @@ describe('simple-keyring', function() { }) }) + describe('#signMessage', function() { + const address = '0x9858e7d8b79fc3e6d989636721584498926da38a' + const message = '0x879a053d4800c6354e76c7985a865d2922c82fb5b3f4577b2fe08b998954f2e0' + const privateKey = '0x7dd98753d7b4394095de7d176c58128e2ed6ee600abe97c9f6d9fd65015d9b18' + const expectedResult = '0x28fcb6768e5110144a55b2e6ce9d1ea5a58103033632d272d2b5cf506906f7941a00b539383fd872109633d8c71c404e13dba87bc84166ee31b0e36061a69e161c' + + it('passes the dennis test', function(done) { + keyring.deserialize([ privateKey ]) + .then(() => { + return keyring.signMessage(address, message) + }) + .then((result) => { + assert.equal(result, expectedResult) + done() + }) + }) + }) + describe('#addAccounts', function() { describe('with no arguments', function() { it('creates a single wallet', function() { -- cgit v1.2.3 From 3572708fda9583df32cf19f692d797a40065ee75 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 17 Jan 2017 16:37:36 -0800 Subject: Fix test to log out despite number of menu items --- test/integration/lib/first-time.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index 1811ccbd4..777fcbb7e 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -66,7 +66,8 @@ QUnit.test('agree to terms', function (assert) { }).then(function() { var sandwich = app.find('.menu-droppo')[0] - var lock = sandwich.children[2] + var children = sandwich.children + var lock = children[children.length - 2] assert.ok(lock, 'Lock menu item found') lock.click() -- cgit v1.2.3 From 463a56ff54b0d850c86348e260e5f7c17b138ccb Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 24 Jan 2017 15:33:33 -0800 Subject: background controller - extract KeyringC.placeSeedWords to MetamaskC --- test/unit/keyring-controller-test.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test') diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js index 37fd7175e..d6d2db817 100644 --- a/test/unit/keyring-controller-test.js +++ b/test/unit/keyring-controller-test.js @@ -41,6 +41,9 @@ describe('KeyringController', function() { state = newState done() }) + .catch((err) => { + done(err) + }) }) afterEach(function() { -- cgit v1.2.3 From 76ce348a04b83693eda0e8a40f9888c1f5fe7ef5 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 24 Jan 2017 19:47:00 -0800 Subject: obs-store - use published module --- test/integration/lib/idStore-migrator-test.js | 2 +- test/lib/mock-config-manager.js | 9 ++++---- test/unit/config-manager-test.js | 30 ++++++++++----------------- test/unit/idStore-migration-test.js | 2 +- 4 files changed, 17 insertions(+), 26 deletions(-) (limited to 'test') diff --git a/test/integration/lib/idStore-migrator-test.js b/test/integration/lib/idStore-migrator-test.js index d95cfb401..f2a437a7c 100644 --- a/test/integration/lib/idStore-migrator-test.js +++ b/test/integration/lib/idStore-migrator-test.js @@ -1,4 +1,4 @@ -const ObservableStore = require('../../../app/scripts/lib/observable/') +const ObservableStore = require('obs-store') const ConfigManager = require('../../../app/scripts/lib/config-manager') const IdStoreMigrator = require('../../../app/scripts/lib/idStore-migrator') const SimpleKeyring = require('../../../app/scripts/keyrings/simple') diff --git a/test/lib/mock-config-manager.js b/test/lib/mock-config-manager.js index c62d91da9..72be86ed1 100644 --- a/test/lib/mock-config-manager.js +++ b/test/lib/mock-config-manager.js @@ -1,11 +1,10 @@ +const ObservableStore = require('obs-store') +const clone = require('clone') const ConfigManager = require('../../app/scripts/lib/config-manager') -const LocalStorageStore = require('../../app/scripts/lib/observable/local-storage') const firstTimeState = require('../../app/scripts/first-time-state') const STORAGE_KEY = 'metamask-config' module.exports = function() { - let dataStore = new LocalStorageStore({ storageKey: STORAGE_KEY }) - // initial state for first time users - if (!dataStore.get()) dataStore.put(firstTimeState) - return new ConfigManager({ store: dataStore }) + let store = new ObservableStore(clone(firstTimeState)) + return new ConfigManager({ store }) } \ No newline at end of file diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index 83b242a8b..fa3929599 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -1,27 +1,23 @@ // polyfill fetch global.fetch = global.fetch || require('isomorphic-fetch') -// pollyfill localStorage support into JSDom -global.localStorage = global.localStorage || polyfillLocalStorage() 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 STORAGE_KEY = 'metamask-persistance-key' describe('config-manager', function() { var configManager beforeEach(function() { - global.localStorage.clear() configManager = configManagerGen() }) describe('currency conversions', function() { describe('#getCurrentFiat', function() { - it('should return false if no previous key exists', function() { + it('should return undefined if no previous key exists', function() { var result = configManager.getCurrentFiat() assert.ok(!result) }) @@ -29,14 +25,14 @@ describe('config-manager', function() { describe('#setCurrentFiat', function() { it('should make getCurrentFiat return true once set', function() { - assert.equal(configManager.getCurrentFiat(), false) + assert.equal(configManager.getCurrentFiat(), undefined) configManager.setCurrentFiat('USD') var result = configManager.getCurrentFiat() assert.equal(result, 'USD') }) it('should work with other currencies as well', function() { - assert.equal(configManager.getCurrentFiat(), false) + assert.equal(configManager.getCurrentFiat(), undefined) configManager.setCurrentFiat('JPY') var result = configManager.getCurrentFiat() assert.equal(result, 'JPY') @@ -44,7 +40,7 @@ describe('config-manager', function() { }) describe('#getConversionRate', function() { - it('should return false if non-existent', function() { + it('should return undefined if non-existent', function() { var result = configManager.getConversionRate() assert.ok(!result) }) @@ -57,7 +53,7 @@ describe('config-manager', function() { .get('/api/ticker/eth-USD') .reply(200, '{"ticker":{"base":"ETH","target":"USD","price":"11.02456145","volume":"44948.91745289","change":"-0.01472534"},"timestamp":1472072136,"success":true,"error":""}') - assert.equal(configManager.getConversionRate(), false) + assert.equal(configManager.getConversionRate(), 0) var promise = new Promise( function (resolve, reject) { configManager.setCurrentFiat('USD') @@ -78,7 +74,7 @@ describe('config-manager', function() { it('should work for JPY as well.', function() { this.timeout(15000) - assert.equal(configManager.getConversionRate(), false) + assert.equal(configManager.getConversionRate(), 0) var jpyMock = nock('https://www.cryptonator.com') .get('/api/ticker/eth-JPY') @@ -106,7 +102,7 @@ describe('config-manager', function() { describe('confirmation', function() { describe('#getConfirmedDisclaimer', function() { - it('should return false if no previous key exists', function() { + it('should return undefined if no previous key exists', function() { var result = configManager.getConfirmedDisclaimer() assert.ok(!result) }) @@ -114,16 +110,16 @@ describe('config-manager', function() { describe('#setConfirmedDisclaimer', function() { it('should make getConfirmedDisclaimer return true once set', function() { - assert.equal(configManager.getConfirmedDisclaimer(), false) + assert.equal(configManager.getConfirmedDisclaimer(), undefined) configManager.setConfirmedDisclaimer(true) var result = configManager.getConfirmedDisclaimer() assert.equal(result, true) }) - it('should be able to set false', function() { - configManager.setConfirmedDisclaimer(false) + it('should be able to set undefined', function() { + configManager.setConfirmedDisclaimer(undefined) var result = configManager.getConfirmedDisclaimer() - assert.equal(result, false) + assert.equal(result, undefined) }) it('should persist to local storage', function() { @@ -240,7 +236,3 @@ describe('config-manager', function() { }) }) }) - -function polyfillLocalStorage(){ - return Object.create({ clear: function(){ global.localStorage = polyfillLocalStorage() } }) -} diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js index 4adbef740..38667fc3e 100644 --- a/test/unit/idStore-migration-test.js +++ b/test/unit/idStore-migration-test.js @@ -1,9 +1,9 @@ const async = require('async') const assert = require('assert') +const ObservableStore = require('obs-store') const ethUtil = require('ethereumjs-util') const BN = ethUtil.BN const ConfigManager = require('../../app/scripts/lib/config-manager') -const ObservableStore = require('../../app/scripts/lib/observable/') const delegateCallCode = require('../lib/example-code.json').delegateCallCode // The old way: -- cgit v1.2.3 From a14a25c423fc8f7c40ba0c1c440991dd8a52410f Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 26 Jan 2017 15:22:13 -0800 Subject: config-manager - default to USD for currentFiat --- test/unit/config-manager-test.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index fa3929599..acc73ebb4 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -16,23 +16,13 @@ describe('config-manager', function() { describe('currency conversions', function() { - describe('#getCurrentFiat', function() { - it('should return undefined if no previous key exists', function() { - var result = configManager.getCurrentFiat() - assert.ok(!result) - }) - }) - describe('#setCurrentFiat', function() { - it('should make getCurrentFiat return true once set', function() { - assert.equal(configManager.getCurrentFiat(), undefined) - configManager.setCurrentFiat('USD') - var result = configManager.getCurrentFiat() - assert.equal(result, 'USD') + it('should return USD as default', function() { + assert.equal(configManager.getCurrentFiat(), 'USD') }) - it('should work with other currencies as well', function() { - assert.equal(configManager.getCurrentFiat(), undefined) + it('should be able to set to other currency', function() { + assert.equal(configManager.getCurrentFiat(), 'USD') configManager.setCurrentFiat('JPY') var result = configManager.getCurrentFiat() assert.equal(result, 'JPY') -- cgit v1.2.3 From 3afd0ef27d69ed5d130f4ea37e3e856cadba34d9 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 27 Jan 2017 23:04:34 -0800 Subject: tests - remove persistence and start with initial state --- test/unit/idStore-migration-test.js | 58 ++---------------------------- test/unit/metamask-controller-test.js | 68 +++++------------------------------ 2 files changed, 11 insertions(+), 115 deletions(-) (limited to 'test') diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js index 38667fc3e..47894a458 100644 --- a/test/unit/idStore-migration-test.js +++ b/test/unit/idStore-migration-test.js @@ -4,12 +4,13 @@ const ObservableStore = require('obs-store') const ethUtil = require('ethereumjs-util') const BN = ethUtil.BN const ConfigManager = require('../../app/scripts/lib/config-manager') +const firstTimeState = require('../../app/scripts/first-time-state') const delegateCallCode = require('../lib/example-code.json').delegateCallCode +const clone = require('clone') // The old way: const IdentityStore = require('../../app/scripts/lib/idStore') const STORAGE_KEY = 'metamask-config' -const extend = require('xtend') // The new ways: var KeyringController = require('../../app/scripts/keyring-controller') @@ -42,12 +43,9 @@ describe('IdentityStore to KeyringController migration', function() { // and THEN create a new one, before we can run tests on it. beforeEach(function(done) { this.sinon = sinon.sandbox.create() - window.localStorage = {} // Hacking localStorage support into JSDom - let store = new ObservableStore(loadData()) - store.subscribe(setData) + let store = new ObservableStore(clone(firstTimeState)) configManager = new ConfigManager({ store }) - idStore = new IdentityStore({ configManager: configManager, ethStore: { @@ -94,53 +92,3 @@ describe('IdentityStore to KeyringController migration', function() { }) }) }) - -function loadData () { - var oldData = getOldStyleData() - var newData - try { - newData = JSON.parse(window.localStorage[STORAGE_KEY]) - } catch (e) {} - - var data = extend({ - meta: { - version: 0, - }, - data: { - config: { - provider: { - type: 'testnet', - }, - }, - }, - }, oldData || null, newData || null) - return data -} - -function setData (data) { - window.localStorage[STORAGE_KEY] = JSON.stringify(data) -} - -function getOldStyleData () { - var config, wallet, seedWords - - var result = { - meta: { version: 0 }, - data: {}, - } - - try { - config = JSON.parse(window.localStorage['config']) - result.data.config = config - } catch (e) {} - try { - wallet = JSON.parse(window.localStorage['lightwallet']) - result.data.wallet = wallet - } catch (e) {} - try { - seedWords = window.localStorage['seedWords'] - result.data.seedWords = seedWords - } catch (e) {} - - return result -} diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index 24d9ddd67..78b9e9df7 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -1,7 +1,9 @@ -var assert = require('assert') -var MetaMaskController = require('../../app/scripts/metamask-controller') -var sinon = require('sinon') -var extend = require('xtend') +const assert = require('assert') +const sinon = require('sinon') +const clone = require('clone') +const MetaMaskController = require('../../app/scripts/metamask-controller') +const firstTimeState = require('../../app/scripts/first-time-state') + const STORAGE_KEY = 'metamask-config' describe('MetaMaskController', function() { @@ -11,15 +13,12 @@ describe('MetaMaskController', function() { unlockAccountMessage: noop, showUnapprovedTx: noop, // initial state - initState: loadData(), + initState: clone(firstTimeState), }) - // setup state persistence - controller.store.subscribe(setData) beforeEach(function() { // sinon allows stubbing methods that are easily verified this.sinon = sinon.sandbox.create() - window.localStorage = {} // Hacking localStorage support into JSDom }) afterEach(function() { @@ -27,55 +26,4 @@ describe('MetaMaskController', function() { this.sinon.restore() }) -}) - - -function loadData () { - var oldData = getOldStyleData() - var newData - try { - newData = JSON.parse(window.localStorage[STORAGE_KEY]) - } catch (e) {} - - var data = extend({ - meta: { - version: 0, - }, - data: { - config: { - provider: { - type: 'testnet', - }, - }, - }, - }, oldData || null, newData || null) - return data -} - -function getOldStyleData () { - var config, wallet, seedWords - - var result = { - meta: { version: 0 }, - data: {}, - } - - try { - config = JSON.parse(window.localStorage['config']) - result.data.config = config - } catch (e) {} - try { - wallet = JSON.parse(window.localStorage['lightwallet']) - result.data.wallet = wallet - } catch (e) {} - try { - seedWords = window.localStorage['seedWords'] - result.data.seedWords = seedWords - } catch (e) {} - - return result -} - -function setData (data) { - window.localStorage[STORAGE_KEY] = JSON.stringify(data) -} +}) \ No newline at end of file -- cgit v1.2.3 From 4dd6ba9c1b6704dafcf9d10e1db02a3bb3071cb6 Mon Sep 17 00:00:00 2001 From: kumavis Date: Sat, 28 Jan 2017 19:19:03 -0800 Subject: migration 5 - move keyring controller state to substate --- test/unit/idStore-migration-test.js | 3 ++ test/unit/keyring-controller-test.js | 56 +++++++++++------------------------- 2 files changed, 20 insertions(+), 39 deletions(-) (limited to 'test') diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js index 47894a458..3aaf4bb94 100644 --- a/test/unit/idStore-migration-test.js +++ b/test/unit/idStore-migration-test.js @@ -89,6 +89,9 @@ describe('IdentityStore to KeyringController migration', function() { assert(!state.lostAccounts, 'no lost accounts') done() }) + .catch((err) => { + done(err) + }) }) }) }) diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js index d6d2db817..347aa2bdf 100644 --- a/test/unit/keyring-controller-test.js +++ b/test/unit/keyring-controller-test.js @@ -1,6 +1,6 @@ -var assert = require('assert') -var KeyringController = require('../../app/scripts/keyring-controller') -var configManagerGen = require('../lib/mock-config-manager') +const assert = require('assert') +const KeyringController = require('../../app/scripts/keyring-controller') +const configManagerGen = require('../lib/mock-config-manager') const ethUtil = require('ethereumjs-util') const BN = ethUtil.BN const async = require('async') @@ -55,17 +55,16 @@ describe('KeyringController', function() { this.timeout(10000) it('should set a vault on the configManager', function(done) { - keyringController.configManager.setVault(null) - assert(!keyringController.configManager.getVault(), 'no previous vault') + keyringController.store.updateState({ vault: null }) + assert(!keyringController.store.getState().vault, 'no previous vault') keyringController.createNewVaultAndKeychain(password) .then(() => { - const vault = keyringController.configManager.getVault() + const vault = keyringController.store.getState().vault assert(vault, 'vault created') done() }) .catch((reason) => { - assert.ifError(reason) - done() + done(reason) }) }) }) @@ -96,8 +95,7 @@ describe('KeyringController', function() { done() }) .catch((reason) => { - assert.ifError(reason) - done() + done(reason) }) }) }) @@ -109,9 +107,6 @@ describe('KeyringController', function() { const identities = keyringController.identities const identity = identities[fakeAddress] assert.equal(identity.address, fakeAddress) - - const nick = keyringController.configManager.nicknameForWallet(fakeAddress) - assert.equal(typeof nick, 'string') }) }) @@ -122,34 +117,17 @@ describe('KeyringController', function() { keyringController.identities[ethUtil.addHexPrefix(account)] = {} keyringController.saveAccountLabel(account, nick) .then((label) => { - assert.equal(label, nick) - const persisted = keyringController.configManager.nicknameForWallet(account) - assert.equal(persisted, nick) - done() - }) - .catch((reason) => { - assert.ifError(reason) - done() - }) - }) - - this.timeout(10000) - it('retrieves the persisted nickname', function(done) { - const account = addresses[0] - var nick = 'Test nickname' - keyringController.configManager.setNicknameForWallet(account, nick) - keyringController.createNewVaultAndRestore(password, seedWords) - .then((state) => { - - const identity = keyringController.identities['0x' + account] - assert.equal(identity.name, nick) - - assert(accounts) - done() + try { + assert.equal(label, nick) + const persisted = keyringController.store.getState().walletNicknames[account] + assert.equal(persisted, nick) + done() + } catch (err) { + done() + } }) .catch((reason) => { - assert.ifError(reason) - done() + done(reason) }) }) }) -- cgit v1.2.3 From 8be68575bbef1dcc89b51355abaee90dbf018387 Mon Sep 17 00:00:00 2001 From: Frankie Date: Fri, 27 Jan 2017 16:11:59 -0800 Subject: Clean up message manger includes: Provider egine bump Remove presence of message manger in keyring controller Change the status wording fom conf to approved make Message manager a class fix messages not being apart of the badge re write message manger to better reflect controller pattern --- test/unit/actions/tx_test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/unit/actions/tx_test.js b/test/unit/actions/tx_test.js index 1f06b1120..7ded5b1ef 100644 --- a/test/unit/actions/tx_test.js +++ b/test/unit/actions/tx_test.js @@ -31,7 +31,7 @@ describe('tx confirmation screen', function() { }, }, metamask: { - unconfTxs: { + unapprovedTxs: { '1457634084250832': { id: 1457634084250832, status: "unconfirmed", @@ -119,7 +119,7 @@ describe('tx confirmation screen', function() { }, }, metamask: { - unconfTxs: { + unapprovedTxs: { '1457634084250832': { id: 1457634084250832, status: "unconfirmed", @@ -162,7 +162,7 @@ describe('tx confirmation screen', function() { }); function getUnconfirmedTxCount(state) { - var txs = state.metamask.unconfTxs + var txs = state.metamask.unapprovedTxs var count = Object.keys(txs).length return count } -- cgit v1.2.3 From 2fa60cfcbfdeb43599007f0dd26fd44a4beec8f1 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 30 Jan 2017 15:25:12 -0800 Subject: continue rename selectedAccount to selectedAddress --- test/integration/mocks/oldVault.json | 2 +- test/unit/actions/set_selected_account_test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/integration/mocks/oldVault.json b/test/integration/mocks/oldVault.json index 5861c41d7..b908ed7ca 100644 --- a/test/integration/mocks/oldVault.json +++ b/test/integration/mocks/oldVault.json @@ -13,7 +13,7 @@ "provider": { "type": "testnet" }, - "selectedAccount": "0x4dd5d356c5a016a220bcd69e82e5af680a430d00" + "selectedAddress": "0x4dd5d356c5a016a220bcd69e82e5af680a430d00" }, "showSeedWords": false, "isEthConfirmed": true diff --git a/test/unit/actions/set_selected_account_test.js b/test/unit/actions/set_selected_account_test.js index f72ca82e4..2dc42d2ec 100644 --- a/test/unit/actions/set_selected_account_test.js +++ b/test/unit/actions/set_selected_account_test.js @@ -31,7 +31,7 @@ describe('SHOW_ACCOUNT_DETAIL', function() { it('updates metamask state', function() { var initialState = { metamask: { - selectedAccount: 'foo' + selectedAddress: 'foo' } } freeze(initialState) @@ -43,6 +43,6 @@ describe('SHOW_ACCOUNT_DETAIL', function() { freeze(action) var resultingState = reducers(initialState, action) - assert.equal(resultingState.metamask.selectedAccount, action.value) + assert.equal(resultingState.metamask.selectedAddress, action.value) }) }) -- cgit v1.2.3 From c0d3db6a8ce2fe0522fa4e3cba1e01d10469280f Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 31 Jan 2017 20:02:38 -0800 Subject: keyring - synchronous getState --- test/unit/idStore-migration-test.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js index 3aaf4bb94..1537e88ec 100644 --- a/test/unit/idStore-migration-test.js +++ b/test/unit/idStore-migration-test.js @@ -83,15 +83,10 @@ describe('IdentityStore to KeyringController migration', function() { describe('entering a password', function() { it('should identify an old wallet as an initialized keyring', function(done) { keyringController.configManager.setWallet('something') - keyringController.getState() - .then((state) => { - assert(state.isInitialized, 'old vault counted as initialized.') - assert(!state.lostAccounts, 'no lost accounts') - done() - }) - .catch((err) => { - done(err) - }) + const state = keyringController.getState() + assert(state.isInitialized, 'old vault counted as initialized.') + assert(!state.lostAccounts, 'no lost accounts') + done() }) }) }) -- cgit v1.2.3 From cd5d95260026333735f25a179c7018077e0da44e Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 1 Feb 2017 00:17:48 -0800 Subject: keyring - move identities into memStore --- test/unit/keyring-controller-test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js index 347aa2bdf..aae4cdfd6 100644 --- a/test/unit/keyring-controller-test.js +++ b/test/unit/keyring-controller-test.js @@ -104,7 +104,7 @@ describe('KeyringController', function() { it('should add the address to the identities hash', function() { const fakeAddress = '0x12345678' keyringController.createNickname(fakeAddress) - const identities = keyringController.identities + const identities = keyringController.memStore.getState().identities const identity = identities[fakeAddress] assert.equal(identity.address, fakeAddress) }) @@ -114,7 +114,9 @@ describe('KeyringController', function() { it ('sets the nickname', function(done) { const account = addresses[0] var nick = 'Test nickname' - keyringController.identities[ethUtil.addHexPrefix(account)] = {} + const identities = keyringController.memStore.getState().identities + identities[ethUtil.addHexPrefix(account)] = {} + keyringController.memStore.updateState({ identities }) keyringController.saveAccountLabel(account, nick) .then((label) => { try { -- cgit v1.2.3 From 1cb730144d6b1c05007323bbc31e4375373628fb Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 1 Feb 2017 00:31:26 -0800 Subject: metamask - adopt isInitialized from keyring controller --- test/unit/idStore-migration-test.js | 9 --------- 1 file changed, 9 deletions(-) (limited to 'test') diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js index 1537e88ec..81a99ef63 100644 --- a/test/unit/idStore-migration-test.js +++ b/test/unit/idStore-migration-test.js @@ -80,13 +80,4 @@ describe('IdentityStore to KeyringController migration', function() { }) }) - describe('entering a password', function() { - it('should identify an old wallet as an initialized keyring', function(done) { - keyringController.configManager.setWallet('something') - const state = keyringController.getState() - assert(state.isInitialized, 'old vault counted as initialized.') - assert(!state.lostAccounts, 'no lost accounts') - done() - }) - }) }) -- cgit v1.2.3 From 1b16b4624186265ccbb6f8106e1bf9ff997e2528 Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 1 Feb 2017 11:54:01 -0800 Subject: code clan up and tests --- test/unit/message-manager-test.js | 98 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 test/unit/message-manager-test.js (limited to 'test') diff --git a/test/unit/message-manager-test.js b/test/unit/message-manager-test.js new file mode 100644 index 000000000..68b977058 --- /dev/null +++ b/test/unit/message-manager-test.js @@ -0,0 +1,98 @@ +const assert = require('assert') +const extend = require('xtend') +const EventEmitter = require('events') + +const MessageManger = require('../../app/scripts/lib/message-manager') + +describe('Transaction Manager', function() { + let messageManager + + beforeEach(function() { + messageManager = new MessageManger () + }) + + describe('#getMsgList', function() { + it('when new should return empty array', function() { + var result = messageManager.getMsgList() + assert.ok(Array.isArray(result)) + assert.equal(result.length, 0) + }) + it('should also return transactions from local storage if any', function() { + + }) + }) + + describe('#_saveMsgList', function() { + it('saves the submitted data to the Msg list', function() { + var target = [{ foo: 'bar', metamaskNetworkId: 'unit test' }] + messageManager._saveMsgList(target) + var result = messageManager.getMsgList() + assert.equal(result[0].foo, 'bar') + }) + }) + + describe('#addMsg', function() { + it('adds a Msg returned in getMsgList', function() { + var Msg = { id: 1, status: 'approved', metamaskNetworkId: 'unit test' } + messageManager.addMsg(Msg) + var result = messageManager.getMsgList() + assert.ok(Array.isArray(result)) + assert.equal(result.length, 1) + assert.equal(result[0].id, 1) + }) + }) + + describe('#setMsgStatusApproved', function() { + it('sets the Msg status to approved', function() { + var Msg = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } + messageManager.addMsg(Msg) + messageManager.setMsgStatusApproved(1) + var result = messageManager.getMsgList() + assert.ok(Array.isArray(result)) + assert.equal(result.length, 1) + assert.equal(result[0].status, 'approved') + }) + }) + + describe('#rejectMsg', function() { + it('sets the Msg status to rejected', function() { + var Msg = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } + messageManager.addMsg(Msg) + messageManager.rejectMsg(1) + var result = messageManager.getMsgList() + assert.ok(Array.isArray(result)) + assert.equal(result.length, 1) + assert.equal(result[0].status, 'rejected') + }) + }) + + describe('#_updateMsg', function() { + it('replaces the Msg with the same id', function() { + messageManager.addMsg({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }) + messageManager.addMsg({ id: '2', status: 'approved', metamaskNetworkId: 'unit test' }) + messageManager._updateMsg({ id: '1', status: 'blah', hash: 'foo', metamaskNetworkId: 'unit test' }) + var result = messageManager.getMsg('1') + assert.equal(result.hash, 'foo') + }) + }) + + describe('#getUnapprovedMsgs', function() { + it('returns unapproved Msgs in a hash', function() { + messageManager.addMsg({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }) + messageManager.addMsg({ id: '2', status: 'approved', metamaskNetworkId: 'unit test' }) + let result = messageManager.getUnapprovedMsgs() + assert.equal(typeof result, 'object') + assert.equal(result['1'].status, 'unapproved') + assert.equal(result['2'], undefined) + }) + }) + + describe('#getMsg', function() { + it('returns a Msg with the requested id', function() { + messageManager.addMsg({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }) + messageManager.addMsg({ id: '2', status: 'approved', metamaskNetworkId: 'unit test' }) + assert.equal(messageManager.getMsg('1').status, 'unapproved') + assert.equal(messageManager.getMsg('2').status, 'approved') + }) + }) +}) -- cgit v1.2.3 From d8a12c2ad0a3244c1e08e650de2e918fdbe3f980 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 1 Feb 2017 16:27:16 -0800 Subject: tests - mockDev - fix first-time flow --- test/integration/lib/first-time.js | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'test') diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index 777fcbb7e..fc9452045 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -8,49 +8,47 @@ QUnit.test('agree to terms', function (assert) { wait().then(function() { app = $('iframe').contents().find('#app-content .mock-app-root') - app.find('.markdown').prop('scrollTop', 100000000) + + // Scroll through terms + let termsPage = app.find('.markdown')[0] + assert.ok(termsPage, 'on terms page') + termsPage.scrollTop = termsPage.scrollHeight + return wait() + }).then(function() { + + // Agree to terms + var button = app.find('button')[0] + button.click() + return wait() }).then(function() { var title = app.find('h1').text() assert.equal(title, 'MetaMask', 'title screen') + // enter password var pwBox = app.find('#password-box')[0] var confBox = app.find('#password-box-confirm')[0] - pwBox.value = PASSWORD confBox.value = PASSWORD + return wait() - }).then(function() { + // create vault var createButton = app.find('button.primary')[0] createButton.click() return wait(1500) }).then(function() { - var terms = app.find('h3.terms-header')[0] - assert.equal(terms.textContent, 'MetaMask Terms & Conditions', 'Showing TOS') - - // Scroll through terms - var scrollable = app.find('.markdown')[0] - scrollable.scrollTop = scrollable.scrollHeight - - return wait(10) - }).then(function() { - - var button = app.find('button')[0] // Agree button - button.click() - - return wait(1000) - }).then(function() { - var created = app.find('h3')[0] assert.equal(created.textContent, 'Vault Created', 'Vault created screen') - var button = app.find('button')[0] // Agree button + // Agree button + var button = app.find('button')[0] + assert.ok(button, 'button present') button.click() return wait(1000) -- cgit v1.2.3 From dacbf16fe2b2a865fcbb1fd15236efdba525c015 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 1 Feb 2017 16:41:28 -0800 Subject: test - first-time - re-add terms header check --- test/integration/lib/first-time.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test') diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index fc9452045..6e75eb6d7 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -10,6 +10,8 @@ QUnit.test('agree to terms', function (assert) { app = $('iframe').contents().find('#app-content .mock-app-root') // Scroll through terms + var termsHeader = app.find('h3.terms-header')[0] + assert.equal(termsHeader.textContent, 'MetaMask Terms & Conditions', 'Showing TOS') let termsPage = app.find('.markdown')[0] assert.ok(termsPage, 'on terms page') termsPage.scrollTop = termsPage.scrollHeight -- cgit v1.2.3 From bcb86f38cbe91fb814d30b3129de76dba45bff66 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 2 Feb 2017 18:21:22 -0800 Subject: messageManager - move view state to obs-store --- test/unit/message-manager-test.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/unit/message-manager-test.js b/test/unit/message-manager-test.js index 68b977058..faf7429d4 100644 --- a/test/unit/message-manager-test.js +++ b/test/unit/message-manager-test.js @@ -13,7 +13,7 @@ describe('Transaction Manager', function() { describe('#getMsgList', function() { it('when new should return empty array', function() { - var result = messageManager.getMsgList() + var result = messageManager.messages assert.ok(Array.isArray(result)) assert.equal(result.length, 0) }) @@ -22,20 +22,11 @@ describe('Transaction Manager', function() { }) }) - describe('#_saveMsgList', function() { - it('saves the submitted data to the Msg list', function() { - var target = [{ foo: 'bar', metamaskNetworkId: 'unit test' }] - messageManager._saveMsgList(target) - var result = messageManager.getMsgList() - assert.equal(result[0].foo, 'bar') - }) - }) - describe('#addMsg', function() { it('adds a Msg returned in getMsgList', function() { var Msg = { id: 1, status: 'approved', metamaskNetworkId: 'unit test' } messageManager.addMsg(Msg) - var result = messageManager.getMsgList() + var result = messageManager.messages assert.ok(Array.isArray(result)) assert.equal(result.length, 1) assert.equal(result[0].id, 1) @@ -47,7 +38,7 @@ describe('Transaction Manager', function() { var Msg = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } messageManager.addMsg(Msg) messageManager.setMsgStatusApproved(1) - var result = messageManager.getMsgList() + var result = messageManager.messages assert.ok(Array.isArray(result)) assert.equal(result.length, 1) assert.equal(result[0].status, 'approved') @@ -59,7 +50,7 @@ describe('Transaction Manager', function() { var Msg = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } messageManager.addMsg(Msg) messageManager.rejectMsg(1) - var result = messageManager.getMsgList() + var result = messageManager.messages assert.ok(Array.isArray(result)) assert.equal(result.length, 1) assert.equal(result[0].status, 'rejected') -- cgit v1.2.3 From 99fa9ab13aaf69cb8602612816a4df49209fa8a6 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 2 Feb 2017 20:20:13 -0800 Subject: migration 7 - break off TransactionManager substate --- test/integration/index.html | 2 +- test/unit/tx-manager-test.js | 112 +++++++++++++++++++++++-------------------- 2 files changed, 60 insertions(+), 54 deletions(-) (limited to 'test') diff --git a/test/integration/index.html b/test/integration/index.html index 8a54cb829..430814a8a 100644 --- a/test/integration/index.html +++ b/test/integration/index.html @@ -15,7 +15,7 @@ - diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js index a66003f85..f03294ce3 100644 --- a/test/unit/tx-manager-test.js +++ b/test/unit/tx-manager-test.js @@ -3,19 +3,18 @@ const extend = require('xtend') const EventEmitter = require('events') const STORAGE_KEY = 'metamask-persistance-key' const TransactionManager = require('../../app/scripts/transaction-manager') +const noop = () => true describe('Transaction Manager', function() { let txManager - const onTxDoneCb = () => true beforeEach(function() { txManager = new TransactionManager ({ - txList: [], - setTxList: () => {}, provider: "testnet", txHistoryLimit: 10, blockTracker: new EventEmitter(), - getNetwork: function(){ return 'unit test' } + getNetwork: function(){ return 'unit test' }, + getSelectedAddress: function(){ return '0xabcd' }, }) }) @@ -53,7 +52,7 @@ describe('Transaction Manager', function() { describe('#_saveTxList', function() { it('saves the submitted data to the tx list', function() { - var target = [{ foo: 'bar', metamaskNetworkId: 'unit test' }] + var target = [{ foo: 'bar', metamaskNetworkId: 'unit test', txParams: {} }] txManager._saveTxList(target) var result = txManager.getTxList() assert.equal(result[0].foo, 'bar') @@ -62,8 +61,8 @@ describe('Transaction Manager', function() { describe('#addTx', function() { it('adds a tx returned in getTxList', function() { - var tx = { id: 1, status: 'confirmed', metamaskNetworkId: 'unit test' } - txManager.addTx(tx, onTxDoneCb) + var tx = { id: 1, status: 'confirmed', metamaskNetworkId: 'unit test', txParams: {} } + txManager.addTx(tx, noop) var result = txManager.getTxList() assert.ok(Array.isArray(result)) assert.equal(result.length, 1) @@ -73,8 +72,8 @@ describe('Transaction Manager', function() { it('cuts off early txs beyond a limit', function() { const limit = txManager.txHistoryLimit for (let i = 0; i < limit + 1; i++) { - let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: 'unit test' } - txManager.addTx(tx, onTxDoneCb) + let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: 'unit test', txParams: {} } + txManager.addTx(tx, noop) } var result = txManager.getTxList() assert.equal(result.length, limit, `limit of ${limit} txs enforced`) @@ -84,8 +83,8 @@ describe('Transaction Manager', function() { it('cuts off early txs beyond a limit whether or not it is confirmed or rejected', function() { const limit = txManager.txHistoryLimit for (let i = 0; i < limit + 1; i++) { - let tx = { id: i, time: new Date(), status: 'rejected', metamaskNetworkId: 'unit test' } - txManager.addTx(tx, onTxDoneCb) + let tx = { id: i, time: new Date(), status: 'rejected', metamaskNetworkId: 'unit test', txParams: {} } + txManager.addTx(tx, noop) } var result = txManager.getTxList() assert.equal(result.length, limit, `limit of ${limit} txs enforced`) @@ -93,12 +92,12 @@ describe('Transaction Manager', function() { }) it('cuts off early txs beyond a limit but does not cut unapproved txs', function() { - var unconfirmedTx = { id: 0, time: new Date(), status: 'unapproved', metamaskNetworkId: 'unit test' } - txManager.addTx(unconfirmedTx, onTxDoneCb) + var unconfirmedTx = { id: 0, time: new Date(), status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} } + txManager.addTx(unconfirmedTx, noop) const limit = txManager.txHistoryLimit for (let i = 1; i < limit + 1; i++) { - let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: 'unit test' } - txManager.addTx(tx, onTxDoneCb) + let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: 'unit test', txParams: {} } + txManager.addTx(tx, noop) } var result = txManager.getTxList() assert.equal(result.length, limit, `limit of ${limit} txs enforced`) @@ -110,8 +109,8 @@ describe('Transaction Manager', function() { describe('#setTxStatusSigned', function() { it('sets the tx status to signed', function() { - var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } - txManager.addTx(tx, onTxDoneCb) + var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} } + txManager.addTx(tx, noop) txManager.setTxStatusSigned(1) var result = txManager.getTxList() assert.ok(Array.isArray(result)) @@ -121,20 +120,20 @@ describe('Transaction Manager', function() { it('should emit a signed event to signal the exciton of callback', (done) => { this.timeout(10000) - var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } - let onTxDoneCb = function () { - assert(true, 'event listener has been triggered and onTxDoneCb executed') + var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} } + let noop = function () { + assert(true, 'event listener has been triggered and noop executed') done() } txManager.addTx(tx) - txManager.on('1:signed', onTxDoneCb) + txManager.on('1:signed', noop) txManager.setTxStatusSigned(1) }) }) describe('#setTxStatusRejected', function() { it('sets the tx status to rejected', function() { - var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } + var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} } txManager.addTx(tx) txManager.setTxStatusRejected(1) var result = txManager.getTxList() @@ -145,13 +144,13 @@ describe('Transaction Manager', function() { it('should emit a rejected event to signal the exciton of callback', (done) => { this.timeout(10000) - var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } + var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} } txManager.addTx(tx) - let onTxDoneCb = function (err, txId) { - assert(true, 'event listener has been triggered and onTxDoneCb executed') + let noop = function (err, txId) { + assert(true, 'event listener has been triggered and noop executed') done() } - txManager.on('1:rejected', onTxDoneCb) + txManager.on('1:rejected', noop) txManager.setTxStatusRejected(1) }) @@ -159,9 +158,9 @@ describe('Transaction Manager', function() { describe('#updateTx', function() { it('replaces the tx with the same id', function() { - txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }, onTxDoneCb) - txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test' }, onTxDoneCb) - txManager.updateTx({ id: '1', status: 'blah', hash: 'foo', metamaskNetworkId: 'unit test' }) + txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} }, noop) + txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test', txParams: {} }, noop) + txManager.updateTx({ id: '1', status: 'blah', hash: 'foo', metamaskNetworkId: 'unit test', txParams: {} }) var result = txManager.getTx('1') assert.equal(result.hash, 'foo') }) @@ -169,8 +168,8 @@ describe('Transaction Manager', function() { describe('#getUnapprovedTxList', function() { it('returns unapproved txs in a hash', function() { - txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }, onTxDoneCb) - txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test' }, onTxDoneCb) + txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} }, noop) + txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test', txParams: {} }, noop) let result = txManager.getUnapprovedTxList() assert.equal(typeof result, 'object') assert.equal(result['1'].status, 'unapproved') @@ -180,8 +179,8 @@ describe('Transaction Manager', function() { describe('#getTx', function() { it('returns a tx with the requested id', function() { - txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }, onTxDoneCb) - txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test' }, onTxDoneCb) + txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} }, noop) + txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test', txParams: {} }, noop) assert.equal(txManager.getTx('1').status, 'unapproved') assert.equal(txManager.getTx('2').status, 'confirmed') }) @@ -189,26 +188,33 @@ describe('Transaction Manager', function() { describe('#getFilteredTxList', function() { it('returns a tx with the requested data', function() { - var foop = 0 - var zoop = 0 - for (let i = 0; i < 10; ++i ){ - let everyOther = i % 2 - txManager.addTx({ id: i, - status: everyOther ? 'unapproved' : 'confirmed', - metamaskNetworkId: 'unit test', - txParams: { - from: everyOther ? 'foop' : 'zoop', - to: everyOther ? 'zoop' : 'foop', - } - }, onTxDoneCb) - everyOther ? ++foop : ++zoop - } - assert.equal(txManager.getFilteredTxList({status: 'confirmed', from: 'zoop'}).length, zoop) - assert.equal(txManager.getFilteredTxList({status: 'confirmed', to: 'foop'}).length, zoop) - assert.equal(txManager.getFilteredTxList({status: 'confirmed', from: 'foop'}).length, 0) - assert.equal(txManager.getFilteredTxList({status: 'confirmed'}).length, zoop) - assert.equal(txManager.getFilteredTxList({from: 'foop'}).length, foop) - assert.equal(txManager.getFilteredTxList({from: 'zoop'}).length, zoop) + let txMetas = [ + { id: 0, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: 'unit test' }, + { id: 1, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: 'unit test' }, + { id: 2, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: 'unit test' }, + { id: 3, status: 'unapproved', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: 'unit test' }, + { id: 4, status: 'unapproved', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: 'unit test' }, + { id: 5, status: 'confirmed', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: 'unit test' }, + { id: 6, status: 'confirmed', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: 'unit test' }, + { id: 7, status: 'confirmed', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: 'unit test' }, + { id: 8, status: 'confirmed', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: 'unit test' }, + { id: 9, status: 'confirmed', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: 'unit test' }, + ] + txMetas.forEach((txMeta) => txManager.addTx(txMeta, noop)) + let filterParams + + filterParams = { status: 'unapproved', from: '0xaa' } + assert.equal(txManager.getFilteredTxList(filterParams).length, 3, `getFilteredTxList - ${JSON.stringify(filterParams)}`) + filterParams = { status: 'unapproved', to: '0xaa' } + assert.equal(txManager.getFilteredTxList(filterParams).length, 2, `getFilteredTxList - ${JSON.stringify(filterParams)}`) + filterParams = { status: 'confirmed', from: '0xbb' } + assert.equal(txManager.getFilteredTxList(filterParams).length, 3, `getFilteredTxList - ${JSON.stringify(filterParams)}`) + filterParams = { status: 'confirmed' } + assert.equal(txManager.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`) + filterParams = { from: '0xaa' } + assert.equal(txManager.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`) + filterParams = { to: '0xaa' } + assert.equal(txManager.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`) }) }) -- cgit v1.2.3 From 0c6df24ecff566c84810a1b29316c1efa2c83870 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 2 Feb 2017 20:59:47 -0800 Subject: metamask - introduce networkStore --- test/unit/tx-manager-test.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js index f03294ce3..3b64f340b 100644 --- a/test/unit/tx-manager-test.js +++ b/test/unit/tx-manager-test.js @@ -1,6 +1,7 @@ const assert = require('assert') const extend = require('xtend') const EventEmitter = require('events') +const ObservableStore = require('obs-store') const STORAGE_KEY = 'metamask-persistance-key' const TransactionManager = require('../../app/scripts/transaction-manager') const noop = () => true @@ -9,11 +10,10 @@ describe('Transaction Manager', function() { let txManager beforeEach(function() { - txManager = new TransactionManager ({ - provider: "testnet", + txManager = new TransactionManager({ + networkStore: new ObservableStore({ network: 'unit test' }), txHistoryLimit: 10, blockTracker: new EventEmitter(), - getNetwork: function(){ return 'unit test' }, getSelectedAddress: function(){ return '0xabcd' }, }) }) @@ -50,15 +50,6 @@ describe('Transaction Manager', function() { }) }) - describe('#_saveTxList', function() { - it('saves the submitted data to the tx list', function() { - var target = [{ foo: 'bar', metamaskNetworkId: 'unit test', txParams: {} }] - txManager._saveTxList(target) - var result = txManager.getTxList() - assert.equal(result[0].foo, 'bar') - }) - }) - describe('#addTx', function() { it('adds a tx returned in getTxList', function() { var tx = { id: 1, status: 'confirmed', metamaskNetworkId: 'unit test', txParams: {} } -- cgit v1.2.3 From f08f40aee2614c9e72efce5d2d10f6e4b84d7a10 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 2 Feb 2017 21:09:17 -0800 Subject: txManager - depend on preferencesStore --- test/unit/tx-manager-test.js | 1 - 1 file changed, 1 deletion(-) (limited to 'test') diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js index 3b64f340b..f64f048e3 100644 --- a/test/unit/tx-manager-test.js +++ b/test/unit/tx-manager-test.js @@ -14,7 +14,6 @@ describe('Transaction Manager', function() { networkStore: new ObservableStore({ network: 'unit test' }), txHistoryLimit: 10, blockTracker: new EventEmitter(), - getSelectedAddress: function(){ return '0xabcd' }, }) }) -- cgit v1.2.3 From 9e4ef45b6ac460e6539e0f79ad5c78959fa1c4cb Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 2 Feb 2017 23:32:24 -0800 Subject: migration #9 - break out CurrencyController substate --- test/unit/config-manager-test.js | 75 ------------------------------ test/unit/currency-controller-test.js | 87 +++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 75 deletions(-) create mode 100644 test/unit/currency-controller-test.js (limited to 'test') diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index acc73ebb4..c6f60192f 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -14,81 +14,6 @@ describe('config-manager', function() { configManager = configManagerGen() }) - describe('currency conversions', function() { - - describe('#setCurrentFiat', function() { - it('should return USD as default', function() { - assert.equal(configManager.getCurrentFiat(), 'USD') - }) - - it('should be able to set to other currency', function() { - assert.equal(configManager.getCurrentFiat(), 'USD') - configManager.setCurrentFiat('JPY') - var result = configManager.getCurrentFiat() - assert.equal(result, 'JPY') - }) - }) - - describe('#getConversionRate', function() { - it('should return undefined if non-existent', function() { - var result = configManager.getConversionRate() - assert.ok(!result) - }) - }) - - describe('#updateConversionRate', function() { - it('should retrieve an update for ETH to USD and set it in memory', function(done) { - this.timeout(15000) - var usdMock = nock('https://www.cryptonator.com') - .get('/api/ticker/eth-USD') - .reply(200, '{"ticker":{"base":"ETH","target":"USD","price":"11.02456145","volume":"44948.91745289","change":"-0.01472534"},"timestamp":1472072136,"success":true,"error":""}') - - assert.equal(configManager.getConversionRate(), 0) - var promise = new Promise( - function (resolve, reject) { - configManager.setCurrentFiat('USD') - configManager.updateConversionRate().then(function() { - resolve() - }) - }) - - promise.then(function() { - var result = configManager.getConversionRate() - assert.equal(typeof result, 'number') - done() - }).catch(function(err) { - console.log(err) - }) - - }) - - it('should work for JPY as well.', function() { - this.timeout(15000) - assert.equal(configManager.getConversionRate(), 0) - - var jpyMock = nock('https://www.cryptonator.com') - .get('/api/ticker/eth-JPY') - .reply(200, '{"ticker":{"base":"ETH","target":"JPY","price":"11.02456145","volume":"44948.91745289","change":"-0.01472534"},"timestamp":1472072136,"success":true,"error":""}') - - - var promise = new Promise( - function (resolve, reject) { - configManager.setCurrentFiat('JPY') - configManager.updateConversionRate().then(function() { - resolve() - }) - }) - - promise.then(function() { - var result = configManager.getConversionRate() - assert.equal(typeof result, 'number') - }).catch(function(err) { - console.log(err) - }) - }) - }) - }) - describe('confirmation', function() { describe('#getConfirmedDisclaimer', function() { diff --git a/test/unit/currency-controller-test.js b/test/unit/currency-controller-test.js new file mode 100644 index 000000000..c57b522c7 --- /dev/null +++ b/test/unit/currency-controller-test.js @@ -0,0 +1,87 @@ +// polyfill fetch +global.fetch = global.fetch || require('isomorphic-fetch') + +const assert = require('assert') +const extend = require('xtend') +const rp = require('request-promise') +const nock = require('nock') +const CurrencyController = require('../../app/scripts/lib/controllers/currency') + +describe('config-manager', function() { + var currencyController + + beforeEach(function() { + currencyController = new CurrencyController() + }) + + describe('currency conversions', function() { + + describe('#setCurrentCurrency', function() { + it('should return USD as default', function() { + assert.equal(currencyController.getCurrentCurrency(), 'USD') + }) + + it('should be able to set to other currency', function() { + assert.equal(currencyController.getCurrentCurrency(), 'USD') + currencyController.setCurrentCurrency('JPY') + var result = currencyController.getCurrentCurrency() + assert.equal(result, 'JPY') + }) + }) + + describe('#getConversionRate', function() { + it('should return undefined if non-existent', function() { + var result = currencyController.getConversionRate() + assert.ok(!result) + }) + }) + + describe('#updateConversionRate', function() { + it('should retrieve an update for ETH to USD and set it in memory', function(done) { + this.timeout(15000) + var usdMock = nock('https://www.cryptonator.com') + .get('/api/ticker/eth-USD') + .reply(200, '{"ticker":{"base":"ETH","target":"USD","price":"11.02456145","volume":"44948.91745289","change":"-0.01472534"},"timestamp":1472072136,"success":true,"error":""}') + + assert.equal(currencyController.getConversionRate(), 0) + currencyController.setCurrentCurrency('USD') + currencyController.updateConversionRate() + .then(function() { + var result = currencyController.getConversionRate() + console.log('currencyController.getConversionRate:', result) + assert.equal(typeof result, 'number') + done() + }).catch(function(err) { + done(err) + }) + + }) + + it('should work for JPY as well.', function() { + this.timeout(15000) + assert.equal(currencyController.getConversionRate(), 0) + + var jpyMock = nock('https://www.cryptonator.com') + .get('/api/ticker/eth-JPY') + .reply(200, '{"ticker":{"base":"ETH","target":"JPY","price":"11.02456145","volume":"44948.91745289","change":"-0.01472534"},"timestamp":1472072136,"success":true,"error":""}') + + + var promise = new Promise( + function (resolve, reject) { + currencyController.setCurrentCurrency('JPY') + currencyController.updateConversionRate().then(function() { + resolve() + }) + }) + + promise.then(function() { + var result = currencyController.getConversionRate() + assert.equal(typeof result, 'number') + }).catch(function(err) { + done(err) + }) + }) + }) + }) + +}) -- cgit v1.2.3 From e1719191f488ab1d842a5e55ddd9f70038329f09 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 3 Feb 2017 15:16:21 -0800 Subject: test - skip eth_sign tests until we have test data --- test/unit/id-management-test.js | 2 +- test/unit/keyrings/simple-test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/id-management-test.js b/test/unit/id-management-test.js index cbc6403bc..25eea8777 100644 --- a/test/unit/id-management-test.js +++ b/test/unit/id-management-test.js @@ -16,7 +16,7 @@ describe('IdManagement', function() { }) describe('#signMsg', function () { - it('passes the dennis test', function() { + it.skip('passes the dennis test', function() { const address = '0x9858e7d8b79fc3e6d989636721584498926da38a' const message = '0x879a053d4800c6354e76c7985a865d2922c82fb5b3f4577b2fe08b998954f2e0' const privateKey = '0x7dd98753d7b4394095de7d176c58128e2ed6ee600abe97c9f6d9fd65015d9b18' diff --git a/test/unit/keyrings/simple-test.js b/test/unit/keyrings/simple-test.js index 77eeb834c..5fe29a67d 100644 --- a/test/unit/keyrings/simple-test.js +++ b/test/unit/keyrings/simple-test.js @@ -55,7 +55,7 @@ describe('simple-keyring', function() { const privateKey = '0x7dd98753d7b4394095de7d176c58128e2ed6ee600abe97c9f6d9fd65015d9b18' const expectedResult = '0x28fcb6768e5110144a55b2e6ce9d1ea5a58103033632d272d2b5cf506906f7941a00b539383fd872109633d8c71c404e13dba87bc84166ee31b0e36061a69e161c' - it('passes the dennis test', function(done) { + it.skip('passes the dennis test', function(done) { keyring.deserialize([ privateKey ]) .then(() => { return keyring.signMessage(address, message) -- cgit v1.2.3 From de6455151e3861a36134ab7f92180f571d55f7dc Mon Sep 17 00:00:00 2001 From: Frankie Date: Thu, 9 Feb 2017 17:31:44 -0800 Subject: Revert old style message sighing --- test/unit/id-management-test.js | 2 +- test/unit/keyrings/simple-test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/id-management-test.js b/test/unit/id-management-test.js index 25eea8777..cbc6403bc 100644 --- a/test/unit/id-management-test.js +++ b/test/unit/id-management-test.js @@ -16,7 +16,7 @@ describe('IdManagement', function() { }) describe('#signMsg', function () { - it.skip('passes the dennis test', function() { + it('passes the dennis test', function() { const address = '0x9858e7d8b79fc3e6d989636721584498926da38a' const message = '0x879a053d4800c6354e76c7985a865d2922c82fb5b3f4577b2fe08b998954f2e0' const privateKey = '0x7dd98753d7b4394095de7d176c58128e2ed6ee600abe97c9f6d9fd65015d9b18' diff --git a/test/unit/keyrings/simple-test.js b/test/unit/keyrings/simple-test.js index 5fe29a67d..77eeb834c 100644 --- a/test/unit/keyrings/simple-test.js +++ b/test/unit/keyrings/simple-test.js @@ -55,7 +55,7 @@ describe('simple-keyring', function() { const privateKey = '0x7dd98753d7b4394095de7d176c58128e2ed6ee600abe97c9f6d9fd65015d9b18' const expectedResult = '0x28fcb6768e5110144a55b2e6ce9d1ea5a58103033632d272d2b5cf506906f7941a00b539383fd872109633d8c71c404e13dba87bc84166ee31b0e36061a69e161c' - it.skip('passes the dennis test', function(done) { + it('passes the dennis test', function(done) { keyring.deserialize([ privateKey ]) .then(() => { return keyring.signMessage(address, message) -- cgit v1.2.3 From 5c9202b2d2a47242f7845bdb6774135d49d3eb6f Mon Sep 17 00:00:00 2001 From: mapachurro Date: Thu, 9 Feb 2017 20:54:29 -0500 Subject: Update first-time.js --- test/integration/lib/first-time.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test') diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index 6e75eb6d7..3b5985401 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -86,6 +86,34 @@ QUnit.test('agree to terms', function (assert) { var detail = app.find('.account-detail-section')[0] assert.ok(detail, 'Account detail section loaded again.') + return wait() + }).then(function (){ + + var qrButton = app.find('.fa.fa-qrcode')[0] + qrButton.click() + + return wait(1000) + }).then(function (){ + + var qrHeader = app.find('.qr-header')[0] + var qrContainer = app.find('#qr-container')[0] + assert.equal(qrHeader.textContent, 'Account 1', 'Should show account label.') + assert.ok(qrContainer, 'QR Container found') + + return wait() + }).then(function (){ + + var networkMenu = app.find('.network-indicator')[0] + networkMenu.click() + + return wait() + }).then(function (){ + + var networkMenu = app.find('.network-indicator')[0] + var children = networkMenu.children + children.length[3] + assert.ok(children, 'All network options present') + done() }) }) -- cgit v1.2.3 From 65c84ac4b2a8a4355bff63690d34e52a4a45a561 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Thu, 9 Feb 2017 18:17:50 -0800 Subject: Delete all code related to disclaimers. --- test/integration/mocks/badVault.json | 2 +- test/integration/mocks/badVault2.json | 2 +- test/integration/mocks/oldVault.json | 2 -- test/unit/config-manager-test.js | 34 ---------------------------------- 4 files changed, 2 insertions(+), 38 deletions(-) (limited to 'test') diff --git a/test/integration/mocks/badVault.json b/test/integration/mocks/badVault.json index a59e4626a..83b4f6298 100644 --- a/test/integration/mocks/badVault.json +++ b/test/integration/mocks/badVault.json @@ -1 +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}} +{"meta":{"version":4},"data":{"fiatCurrency":"USD","conversionRate":8.34908448,"conversionDate":1481227505,"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":[],"gasMultiplier":1}} diff --git a/test/integration/mocks/badVault2.json b/test/integration/mocks/badVault2.json index 4b7aec386..e849ca62a 100644 --- a/test/integration/mocks/badVault2.json +++ b/test/integration/mocks/badVault2.json @@ -1 +1 @@ -{"meta":{"version":4},"data":{"fiatCurrency":"USD","isConfirmed":true,"TOSHash":"a4f4e23f823a7ac51783e7ffba7914a911b09acdb97263296b7e14b527f80c5b","noticesList":[{"read":true,"date":"Fri Dec 16 2016","title":"Ending Morden Support","body":"Due to [recent events](https://blog.ethereum.org/2016/11/20/from-morden-to-ropsten/), MetaMask is now deprecating support for the Morden Test Network.\n\nUsers will still be able to access Morden through a locally hosted node, but we will no longer be providing hosted access to this network through [Infura](http://infura.io/).\n\nPlease use the new Ropsten Network as your new default test network.\n\nYou can fund your Ropsten account using the buy button on your account page.\n\nBest wishes!\nThe MetaMask Team\n\n","id":0}],"conversionRate":7.07341909,"conversionDate":1482539284,"wallet":"{\"encSeed\":{\"encStr\":\"LZsdN8lJzYkUe1UpmAalnERdgkBFt25gWDdK8kfQUwMAk/27XR+dc+8n5swgoF5qgwhc9LBgliEGNDs1Q/lnuld3aQLabkOeAW4BHS1vS7FxqKrzDS3iyzSuQO6wDQmGno/buuknVgDsKiyjW22hpt7vtVVWA+ZL1P3x6M0+AxGJjeGVrG+E8Q==\",\"nonce\":\"T6O9BmwmTj214XUK3KF0s3iCKo3OlrUD\"},\"ksData\":{\"m/44'/60'/0'/0\":{\"info\":{\"curve\":\"secp256k1\",\"purpose\":\"sign\"},\"encHdPathPriv\":{\"encStr\":\"GNNfZevCMlgMVh9y21y1UwrC9qcmH6XYq7v+9UoqbHnzPQJFlxidN5+x/Sldo72a6+5zJpQkkdZ+Q0lePrzvXfuSd3D/RO7WKFIKo9nAQI5+JWwz4INuCmVcmqCv2J4BTLGjrG8fp5pDJ62Bn0XHqkJo3gx3fpvs3cS66+ZKwg==\",\"nonce\":\"HRTlGj44khQs2veYHEF/GqTI1t0yYvyd\"},\"hdIndex\":3,\"encPrivKeys\":{\"e15d894becb0354c501ae69429b05143679f39e0\":{\"key\":\"ZAeZL9VcRUtiiO4VXOQKBFg787PR5R3iymjUeU5vpDRIqOXbjWN6N4ZNR8YpSXl+\",\"nonce\":\"xLsADagS8uqDYae6cImyhxF7o1kBDbPe\"},\"87658c15aefe7448008a28513a11b6b130ef4cd0\":{\"key\":\"ku0mm5s1agRJNAMYIJO0qeoDe+FqcbqdQI6azXF3GL1OLo6uMlt6I4qS+eeravFi\",\"nonce\":\"xdGfSUPKtkW8ge0SWIbbpahs/NyEMzn5\"},\"aa25854c0379e53c957ac9382e720c577fa31fd5\":{\"key\":\"NjpYC9FbiC95CTx/1kwgOHk5LSN9vl4RULEBbvwfVOjqSH8WixNoP3R6I/QyNIs2\",\"nonce\":\"M/HWpXXA9QvuZxEykkGQPJKKdz33ovQr\"}},\"addresses\":[\"e15d894becb0354c501ae69429b05143679f39e0\",\"87658c15aefe7448008a28513a11b6b130ef4cd0\",\"aa25854c0379e53c957ac9382e720c577fa31fd5\"]}},\"encHdRootPriv\":{\"encStr\":\"f+3prUOzl+95aNAV+ad6lZdsYZz120ZsL67ucjj3tiMXf/CC4X8XB9N2QguhoMy6fW+fATUsTdJe8+CbAAyb79V9HY0Pitzq9Yw/g1g0/Ii2JzsdGBriuMsPdwZSVqz+rvQFw/6Qms1xjW6cqa8S7kM2WA5l8RB1Ck6r5zaqbA==\",\"nonce\":\"oGahxNFekVxH9sg6PUCCHIByvo4WFSqm\"},\"salt\":\"N7xYoEA53yhSweOsEphku1UKkIEuZtX2MwLBhVM6RR8=\",\"version\":2}","config":{"provider":{"type":"testnet"},"selectedAccount":"0xe15d894becb0354c501ae69429b05143679f39e0"},"isDisclaimerConfirmed":true,"walletNicknames":{"0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9":"Account 1","0xd7c0cd9e7d2701c710d64fc492c7086679bdf7b4":"Account 2","0x1acfb961c5a8268eac8e09d6241a26cbeff42241":"Account 3"},"lostAccounts":["0xe15d894becb0354c501ae69429b05143679f39e0","0x87658c15aefe7448008a28513a11b6b130ef4cd0","0xaa25854c0379e53c957ac9382e720c577fa31fd5"]}} \ No newline at end of file +{"meta":{"version":4},"data":{"fiatCurrency":"USD","noticesList":[{"read":true,"date":"Fri Dec 16 2016","title":"Ending Morden Support","body":"Due to [recent events](https://blog.ethereum.org/2016/11/20/from-morden-to-ropsten/), MetaMask is now deprecating support for the Morden Test Network.\n\nUsers will still be able to access Morden through a locally hosted node, but we will no longer be providing hosted access to this network through [Infura](http://infura.io/).\n\nPlease use the new Ropsten Network as your new default test network.\n\nYou can fund your Ropsten account using the buy button on your account page.\n\nBest wishes!\nThe MetaMask Team\n\n","id":0}],"conversionRate":7.07341909,"conversionDate":1482539284,"wallet":"{\"encSeed\":{\"encStr\":\"LZsdN8lJzYkUe1UpmAalnERdgkBFt25gWDdK8kfQUwMAk/27XR+dc+8n5swgoF5qgwhc9LBgliEGNDs1Q/lnuld3aQLabkOeAW4BHS1vS7FxqKrzDS3iyzSuQO6wDQmGno/buuknVgDsKiyjW22hpt7vtVVWA+ZL1P3x6M0+AxGJjeGVrG+E8Q==\",\"nonce\":\"T6O9BmwmTj214XUK3KF0s3iCKo3OlrUD\"},\"ksData\":{\"m/44'/60'/0'/0\":{\"info\":{\"curve\":\"secp256k1\",\"purpose\":\"sign\"},\"encHdPathPriv\":{\"encStr\":\"GNNfZevCMlgMVh9y21y1UwrC9qcmH6XYq7v+9UoqbHnzPQJFlxidN5+x/Sldo72a6+5zJpQkkdZ+Q0lePrzvXfuSd3D/RO7WKFIKo9nAQI5+JWwz4INuCmVcmqCv2J4BTLGjrG8fp5pDJ62Bn0XHqkJo3gx3fpvs3cS66+ZKwg==\",\"nonce\":\"HRTlGj44khQs2veYHEF/GqTI1t0yYvyd\"},\"hdIndex\":3,\"encPrivKeys\":{\"e15d894becb0354c501ae69429b05143679f39e0\":{\"key\":\"ZAeZL9VcRUtiiO4VXOQKBFg787PR5R3iymjUeU5vpDRIqOXbjWN6N4ZNR8YpSXl+\",\"nonce\":\"xLsADagS8uqDYae6cImyhxF7o1kBDbPe\"},\"87658c15aefe7448008a28513a11b6b130ef4cd0\":{\"key\":\"ku0mm5s1agRJNAMYIJO0qeoDe+FqcbqdQI6azXF3GL1OLo6uMlt6I4qS+eeravFi\",\"nonce\":\"xdGfSUPKtkW8ge0SWIbbpahs/NyEMzn5\"},\"aa25854c0379e53c957ac9382e720c577fa31fd5\":{\"key\":\"NjpYC9FbiC95CTx/1kwgOHk5LSN9vl4RULEBbvwfVOjqSH8WixNoP3R6I/QyNIs2\",\"nonce\":\"M/HWpXXA9QvuZxEykkGQPJKKdz33ovQr\"}},\"addresses\":[\"e15d894becb0354c501ae69429b05143679f39e0\",\"87658c15aefe7448008a28513a11b6b130ef4cd0\",\"aa25854c0379e53c957ac9382e720c577fa31fd5\"]}},\"encHdRootPriv\":{\"encStr\":\"f+3prUOzl+95aNAV+ad6lZdsYZz120ZsL67ucjj3tiMXf/CC4X8XB9N2QguhoMy6fW+fATUsTdJe8+CbAAyb79V9HY0Pitzq9Yw/g1g0/Ii2JzsdGBriuMsPdwZSVqz+rvQFw/6Qms1xjW6cqa8S7kM2WA5l8RB1Ck6r5zaqbA==\",\"nonce\":\"oGahxNFekVxH9sg6PUCCHIByvo4WFSqm\"},\"salt\":\"N7xYoEA53yhSweOsEphku1UKkIEuZtX2MwLBhVM6RR8=\",\"version\":2}","config":{"provider":{"type":"testnet"},"selectedAccount":"0xe15d894becb0354c501ae69429b05143679f39e0"},"walletNicknames":{"0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9":"Account 1","0xd7c0cd9e7d2701c710d64fc492c7086679bdf7b4":"Account 2","0x1acfb961c5a8268eac8e09d6241a26cbeff42241":"Account 3"},"lostAccounts":["0xe15d894becb0354c501ae69429b05143679f39e0","0x87658c15aefe7448008a28513a11b6b130ef4cd0","0xaa25854c0379e53c957ac9382e720c577fa31fd5"]}} diff --git a/test/integration/mocks/oldVault.json b/test/integration/mocks/oldVault.json index b908ed7ca..dbcd91575 100644 --- a/test/integration/mocks/oldVault.json +++ b/test/integration/mocks/oldVault.json @@ -4,8 +4,6 @@ }, "data": { "fiatCurrency": "USD", - "isConfirmed": true, - "TOSHash": "a4f4e23f823a7ac51783e7ffba7914a911b09acdb97263296b7e14b527f80c5b", "conversionRate": 9.47316629, "conversionDate": 1479510994, "wallet": "{\"encSeed\":{\"encStr\":\"a5tjKtDGlHkua+6Ta5s3wMFWPmsBqaPdMKGmqeI2z1kMbNs3V03HBaCptU7NtMra1DjHKbSNsUToxFUrmrvWBmUejamN16+l1CviwqASsv7kKzpot00/dfyyJgtZwwFP5Je+TAB1V231nRbPidOfeE1cDec5V8KTF8epl6qzsbA25pjeW76Dfw==\",\"nonce\":\"RzID6bAhWfGTSR74xdIh3RaT1+1sLk6F\"},\"ksData\":{\"m/44'/60'/0'/0\":{\"info\":{\"curve\":\"secp256k1\",\"purpose\":\"sign\"},\"encHdPathPriv\":{\"encStr\":\"6nlYAopRbmGcqerRZO08XwgeYaCJg9XRhh4oiYiVVdQtyNPdxvOI9TcE/mqvBiatMwBwA+TmsqTV6eZZe/VDZKYIGajKulQbScd0xQ71JhYfqqmzSG6EH2Pnzwa+aSAsfARgN1JJSaff2+p6wV6Zg5BUDtl72OGEIEfXhcUGwg==\",\"nonce\":\"Ee1KiDqtx7NvYToQUFvjEhKNinNQcXlK\"},\"hdIndex\":1,\"encPrivKeys\":{\"4dd5d356c5a016a220bcd69e82e5af680a430d00\":{\"key\":\"htGRGAH10lGF4M+fvioznmYVIUSWAzwp/yWSIo85psgZZwmCdJY72oyGanYsrFO8\",\"nonce\":\"PkP8XeZ+ok215rzEorvJu9nYTWzkOVr0\"}},\"addresses\":[\"4dd5d356c5a016a220bcd69e82e5af680a430d00\"]}},\"encHdRootPriv\":{\"encStr\":\"TAZAo71a+4IlAaoA66f0w4ts2f+V7ArTSUHRIrMltfAPXz7GfJBmKXNtHPORUYAjRiKqWK6FZnhKLf7Vcng2LG7VnDQwC4xPxzSRZzSEilnoY3V+zRY0HD7Wb/pndb4FliA/buZQmjohO4vezeX0hl70rJlPJEZTyYoWgxbxFA==\",\"nonce\":\"FlJOaLyBEHMaH5fEnYjdHc6nn18+WkRj\"},\"salt\":\"CmuCcWpbqpKUUv+1aE2ZwvQl7EIQ731uFibSq++vwtY=\",\"version\":2}", diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index c6f60192f..05324e741 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -14,37 +14,6 @@ describe('config-manager', function() { configManager = configManagerGen() }) - describe('confirmation', function() { - - describe('#getConfirmedDisclaimer', function() { - it('should return undefined if no previous key exists', function() { - var result = configManager.getConfirmedDisclaimer() - assert.ok(!result) - }) - }) - - describe('#setConfirmedDisclaimer', function() { - it('should make getConfirmedDisclaimer return true once set', function() { - assert.equal(configManager.getConfirmedDisclaimer(), undefined) - configManager.setConfirmedDisclaimer(true) - var result = configManager.getConfirmedDisclaimer() - assert.equal(result, true) - }) - - it('should be able to set undefined', function() { - configManager.setConfirmedDisclaimer(undefined) - var result = configManager.getConfirmedDisclaimer() - assert.equal(result, undefined) - }) - - it('should persist to local storage', function() { - configManager.setConfirmedDisclaimer(true) - var data = configManager.getData() - assert.equal(data.isDisclaimerConfirmed, true) - }) - }) - }) - describe('#setConfig', function() { it('should set the config key', function () { @@ -68,7 +37,6 @@ describe('config-manager', function() { rpcTarget: 'foobar' }, } - configManager.setConfirmedDisclaimer(true) configManager.setConfig(testConfig) var testWallet = { @@ -79,7 +47,6 @@ describe('config-manager', function() { var result = configManager.getData() assert.equal(result.wallet.name, testWallet.name, 'wallet name is set') assert.equal(result.config.provider.rpcTarget, testConfig.provider.rpcTarget) - assert.equal(configManager.getConfirmedDisclaimer(), true) testConfig.provider.type = 'something else!' configManager.setConfig(testConfig) @@ -88,7 +55,6 @@ describe('config-manager', function() { assert.equal(result.wallet.name, testWallet.name, 'wallet name is set') assert.equal(result.config.provider.rpcTarget, testConfig.provider.rpcTarget) assert.equal(result.config.provider.type, testConfig.provider.type) - assert.equal(configManager.getConfirmedDisclaimer(), true) }) }) -- cgit v1.2.3 From 092ec9096bb5ab32ce90948781fdb93c274fcb7f Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Thu, 9 Feb 2017 22:36:40 -0800 Subject: Fix integration tests. --- test/integration/lib/first-time.js | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'test') diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index 6e75eb6d7..581eec6c7 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -2,7 +2,7 @@ const PASSWORD = 'password123' QUnit.module('first time usage') -QUnit.test('agree to terms', function (assert) { +QUnit.test('render init screen', function (assert) { var done = assert.async() let app @@ -10,22 +10,6 @@ QUnit.test('agree to terms', function (assert) { app = $('iframe').contents().find('#app-content .mock-app-root') // Scroll through terms - var termsHeader = app.find('h3.terms-header')[0] - assert.equal(termsHeader.textContent, 'MetaMask Terms & Conditions', 'Showing TOS') - let termsPage = app.find('.markdown')[0] - assert.ok(termsPage, 'on terms page') - termsPage.scrollTop = termsPage.scrollHeight - - return wait() - }).then(function() { - - // Agree to terms - var button = app.find('button')[0] - button.click() - - return wait() - }).then(function() { - var title = app.find('h1').text() assert.equal(title, 'MetaMask', 'title screen') @@ -34,7 +18,7 @@ QUnit.test('agree to terms', function (assert) { var confBox = app.find('#password-box-confirm')[0] pwBox.value = PASSWORD confBox.value = PASSWORD - + return wait() }).then(function() { -- cgit v1.2.3 From b862d942097b645abe31fa2af87226e544ecd627 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 13 Feb 2017 20:13:11 -0800 Subject: Add failing test for signature recovery --- test/unit/keyrings/simple-test.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test') diff --git a/test/unit/keyrings/simple-test.js b/test/unit/keyrings/simple-test.js index 77eeb834c..60b762cb8 100644 --- a/test/unit/keyrings/simple-test.js +++ b/test/unit/keyrings/simple-test.js @@ -1,5 +1,7 @@ const assert = require('assert') const extend = require('xtend') +const Web3 = require('web3') +const web3 = new Web3() const ethUtil = require('ethereumjs-util') const SimpleKeyring = require('../../../app/scripts/keyrings/simple') const TYPE_STR = 'Simple Key Pair' @@ -65,6 +67,37 @@ describe('simple-keyring', function() { done() }) }) + + it('reliably can decode messages it signs', function (done) { + + const message = 'hello there!' + let address, msgHex + + keyring.addAccounts(10) + .then((addresses) => { + address = addresses[0] + msgHex = web3.sha3(message) + return keyring.signMessage(address, msgHex) + }) + .then((signature) => { + var sgn = signature + var r = ethUtil.toBuffer(sgn.slice(0,66)) + var s = ethUtil.toBuffer('0x' + sgn.slice(66,130)) + var v = parseInt(sgn.slice(130,132)) + 27 + var msgBuffer = ethUtil.toBuffer(msgHex) + var msgHash = ethUtil.hashPersonalMessage(msgBuffer) + var pub = ethUtil.ecrecover(msgHash, v, r, s) + var adr = '0x' + ethUtil.pubToAddress(pub).toString('hex') + assert.equal(adr, address) + done() + }) + .catch((reason) => { + console.log('failed for reason:') + console.dir(reason) + assert.equal(true, false, reason) + done() + }) + }) }) describe('#addAccounts', function() { -- cgit v1.2.3 From f2486fbdd34246619f62ff67bb3ab6e77d202f26 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 13 Feb 2017 21:25:02 -0800 Subject: got hash test passing --- test/unit/keyrings/simple-test.js | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/unit/keyrings/simple-test.js b/test/unit/keyrings/simple-test.js index 60b762cb8..c09695b4c 100644 --- a/test/unit/keyrings/simple-test.js +++ b/test/unit/keyrings/simple-test.js @@ -71,31 +71,40 @@ describe('simple-keyring', function() { it('reliably can decode messages it signs', function (done) { const message = 'hello there!' - let address, msgHex + let address, msgHashHex - keyring.addAccounts(10) + keyring.deserialize([ privateKey ]) + .then(() => { + return keyring.getAccounts() + }) .then((addresses) => { address = addresses[0] - msgHex = web3.sha3(message) - return keyring.signMessage(address, msgHex) + msgHashHex = web3.sha3(message) + return keyring.signMessage(address, msgHashHex) }) - .then((signature) => { - var sgn = signature + .then((sgn) => { var r = ethUtil.toBuffer(sgn.slice(0,66)) var s = ethUtil.toBuffer('0x' + sgn.slice(66,130)) - var v = parseInt(sgn.slice(130,132)) + 27 - var msgBuffer = ethUtil.toBuffer(msgHex) - var msgHash = ethUtil.hashPersonalMessage(msgBuffer) - var pub = ethUtil.ecrecover(msgHash, v, r, s) + var v = ethUtil.bufferToInt(ethUtil.toBuffer('0x' + sgn.slice(130,132))) + var m = ethUtil.toBuffer(msgHashHex) + console.dir({ r, s, v, m }) + var pub = ethUtil.ecrecover(m, v, r, s) var adr = '0x' + ethUtil.pubToAddress(pub).toString('hex') - assert.equal(adr, address) + + /* + var sgn = ethUtil.stripHexPrefix(signature) + var r = ethUtil.toBuffer(sgn.slice(0,64)) + var s = ethUtil.toBuffer(sgn.slice(64,128)) + var v = parseInt(sgn.slice(128,130)) + 27 + var msgHashBuffer = ethUtil.toBuffer(msgHashHex) + var pub = ethUtil.ecrecover(msgHashBuffer, v, r, s) + var adr = '0x' + ethUtil.pubToAddress(pub).toString('hex') + */ + assert.equal(adr, address, 'recovers address from signature correctly') done() }) .catch((reason) => { - console.log('failed for reason:') console.dir(reason) - assert.equal(true, false, reason) - done() }) }) }) -- cgit v1.2.3 From 97b8410b3001a45249244b5a236d31e1975154a2 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 13 Feb 2017 21:29:22 -0800 Subject: Verify messages in a loop --- test/unit/keyrings/simple-test.js | 52 +++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'test') diff --git a/test/unit/keyrings/simple-test.js b/test/unit/keyrings/simple-test.js index c09695b4c..ba7dd448a 100644 --- a/test/unit/keyrings/simple-test.js +++ b/test/unit/keyrings/simple-test.js @@ -71,41 +71,39 @@ describe('simple-keyring', function() { it('reliably can decode messages it signs', function (done) { const message = 'hello there!' - let address, msgHashHex + const msgHashHex = web3.sha3(message) + let address + let addresses = [] keyring.deserialize([ privateKey ]) + .then(() => { + keyring.addAccounts(9) + }) .then(() => { return keyring.getAccounts() }) - .then((addresses) => { - address = addresses[0] - msgHashHex = web3.sha3(message) - return keyring.signMessage(address, msgHashHex) + .then((addrs) => { + addresses = addrs + return Promise.all(addresses.map((address) => { + return keyring.signMessage(address, msgHashHex) + })) }) - .then((sgn) => { - var r = ethUtil.toBuffer(sgn.slice(0,66)) - var s = ethUtil.toBuffer('0x' + sgn.slice(66,130)) - var v = ethUtil.bufferToInt(ethUtil.toBuffer('0x' + sgn.slice(130,132))) - var m = ethUtil.toBuffer(msgHashHex) - console.dir({ r, s, v, m }) - var pub = ethUtil.ecrecover(m, v, r, s) - var adr = '0x' + ethUtil.pubToAddress(pub).toString('hex') - - /* - var sgn = ethUtil.stripHexPrefix(signature) - var r = ethUtil.toBuffer(sgn.slice(0,64)) - var s = ethUtil.toBuffer(sgn.slice(64,128)) - var v = parseInt(sgn.slice(128,130)) + 27 - var msgHashBuffer = ethUtil.toBuffer(msgHashHex) - var pub = ethUtil.ecrecover(msgHashBuffer, v, r, s) - var adr = '0x' + ethUtil.pubToAddress(pub).toString('hex') - */ - assert.equal(adr, address, 'recovers address from signature correctly') + .then((signatures) => { + + signatures.forEach((sgn, index) => { + const address = addresses[index] + + var r = ethUtil.toBuffer(sgn.slice(0,66)) + var s = ethUtil.toBuffer('0x' + sgn.slice(66,130)) + var v = ethUtil.bufferToInt(ethUtil.toBuffer('0x' + sgn.slice(130,132))) + var m = ethUtil.toBuffer(msgHashHex) + var pub = ethUtil.ecrecover(m, v, r, s) + var adr = '0x' + ethUtil.pubToAddress(pub).toString('hex') + + assert.equal(adr, address, 'recovers address from signature correctly') + }) done() }) - .catch((reason) => { - console.dir(reason) - }) }) }) -- cgit v1.2.3 From cd75d861874f300fdca7b20274d170d0023d6caf Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 14 Feb 2017 13:21:00 -0800 Subject: Add migrations for removing terms of use data. --- test/unit/migrations-test.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/migrations-test.js b/test/unit/migrations-test.js index 715a5feb0..e4353b313 100644 --- a/test/unit/migrations-test.js +++ b/test/unit/migrations-test.js @@ -6,6 +6,7 @@ const wallet1 = require(path.join('..', 'lib', 'migrations', '001.json')) const migration2 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '002')) const migration3 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '003')) const migration4 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '004')) +const migration11 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '011')) const oldTestRpc = 'https://rawtestrpc.metamask.io/' const newTestRpc = 'https://testrpc.metamask.io/' @@ -27,8 +28,11 @@ describe('wallet1 is migrated successfully', function() { }).then((thirdResult) => { assert.equal(thirdResult.data.config.provider.rpcTarget, null) assert.equal(thirdResult.data.config.provider.type, 'testnet') + return migration11.migrate(thirdResult) + }).then((eleventhResult) => { + assert.equal(eleventhResult.data.isDisclaimerConfirmed, null) + assert.equal(eleventhResult.data.TOSHash, null) }) - + }) }) - -- cgit v1.2.3 From 6ddd613a156b4af9965ebb73c75f2182709e63ae Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 15 Feb 2017 11:15:33 -0800 Subject: Adding additional migration state to account for moving data. --- test/lib/migrations/004.json | 138 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 test/lib/migrations/004.json (limited to 'test') diff --git a/test/lib/migrations/004.json b/test/lib/migrations/004.json new file mode 100644 index 000000000..0e2075c46 --- /dev/null +++ b/test/lib/migrations/004.json @@ -0,0 +1,138 @@ +{ + "meta":{ + "version":4 + }, + "data":{ + "seedWords":null, + "fiatCurrency":"USD", + "isDisclaimerConfirmed":true, + "TOSHash":"a4f4e23f823a7ac51783e7ffba7914a911b09acdb97263296b7e14b527f80c5b", + "shapeShiftTxList":[ + { + "depositAddress": "1L8BJCR6KHkCiVceDqibt7zJscqPpH7pFw", + "depositType": "BTC", + "key": "shapeshift", + "time": 1471564825772, + "response": { + "status": "complete", + "outgoingCoin": "100.00", + "incomingCoin": "1.000", + "transaction": "0x3701e0ac344a12a1fc5417cf251109a7c41f3edab922310202630d9c012414c8" + } + }, + { + "depositAddress": "1L8BJCR6KHkCiVceDqibt7zJscqPpH7pFw", + "depositType": "BTC", + "key": "shapeshift", + "time": 1471566579224, + "response": { + "status": "no_deposits", + "depositAddress": "1L8BJCR6KHkCiVceDqibt7zJscqPpH7pFw" + } + }, + { + "depositAddress": "1L8BJCR6KHkCiVceDqibt7zJscqPpH7pFw", + "depositType": "BTC", + "key": "shapeshift", + "time": 1471566565378, + "response": { + "status": "received", + "depositAddress": "1L8BJCR6KHkCiVceDqibt7zJscqPpH7pFw" + } + } + ], + "noticesList":[ + { + "read":true, + "date":"Fri Dec 16 2016", + "title":"Ending Morden Support", + "body":"Due to [recent events](https://blog.ethereum.org/2016/11/20/from-morden-to-ropsten/), MetaMask is now deprecating support for the Morden Test Network.\n\nUsers will still be able to access Morden through a locally hosted node, but we will no longer be providing hosted access to this network through [Infura](http://infura.io/).\n\nPlease use the new Ropsten Network as your new default test network.\n\nYou can fund your Ropsten account using the buy button on your account page.\n\nBest wishes!\nThe MetaMask Team\n\n", + "id":0 + } + ], + "conversionRate":12.66441492, + "conversionDate":1487184182, + "vault":"{\"data\":\"Z5UFCeI/Tg9F9No0dC7eIhe4evCG91m6qeXhGpSeX48HHCQ/BepyNONKrh05YjB9hXCAd3Jy93judD+pcXNy7WS9zLujjmMI6sI90ToSrzThnMrOE6ixcH7HGS+TCcqvwBhZEsAQqUcQeHhT9CcdCQAxkKwBk8CK8W290MVeZoQVGK88hB2R8kL3mo/uayS5AnHPwWOS0rocgSfd/ioiucClpw==\",\"iv\":\"AYufeEPwp9f2Rdrfq7yS8g==\",\"salt\":\"g7BQIEx8tosH3IxWhPnrgZFu1XRkQn1Pp7l1ehTQQCo=\"}", + "config":{ + "provider":{ + "type":"testnet" + }, + "selectedAccount":"0x0beb674745816b125fbc07285d39fd373e64895c" + }, + "walletNicknames":{ + "0x0beb674745816b125fbc07285d39fd373e64895c":"Account 1", + "0x433eb37d2e4895815b90f555425dfa123ddaed40":"Account 2" + }, + "transactions":[ + { + "id":3922064325443430, + "time":1487184358262, + "status":"confirmed", + "gasMultiplier":1, + "metamaskNetworkId":"3", + "txParams":{ + "from":"0x0beb674745816b125fbc07285d39fd373e64895c", + "to":"0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761", + "value":"0xde0b6b3a7640000", + "metamaskId":3922064325443430, + "metamaskNetworkId":"3", + "gas":"0x5209", + "gasPrice":"0x04a817c800", + "nonce":"0x0", + "gasLimit":"0x5209" + }, + "gasLimitSpecified":false, + "estimatedGas":"0x5209", + "txFee":"17e0186e60800", + "txValue":"de0b6b3a7640000", + "maxCost":"de234b52e4a0800", + "hash":"0x0b36c5bb31528044e6a71e45a64e9872f5f365a14ac42ee1bea49e7766216c12" + }, + { + "id":3922064325443431, + "time":1487184373172, + "status":"confirmed", + "gasMultiplier":1, + "metamaskNetworkId":"3", + "txParams":{ + "from":"0x0beb674745816b125fbc07285d39fd373e64895c", + "to":"0x433eb37d2e4895815b90f555425dfa123ddaed40", + "value":"0xde0b6b3a7640000", + "metamaskId":3922064325443431, + "metamaskNetworkId":"3", + "gas":"0x5209", + "nonce":"0x01", + "gasPrice":"0x04a817c800", + "gasLimit":"0x5209" + }, + "gasLimitSpecified":false, + "estimatedGas":"0x5209", + "txFee":"17e0186e60800", + "txValue":"de0b6b3a7640000", + "maxCost":"de234b52e4a0800", + "hash":"0x305548a8b8bb72de0ca8cf77df45e4fe2b29383e58c4da6b7eac7e9bd59e85e9" + }, + { + "id":3922064325443432, + "time":1487184391226, + "status":"unapproved", + "gasMultiplier":1, + "metamaskNetworkId":"3", + "txParams":{ + "from":"0x0beb674745816b125fbc07285d39fd373e64895c", + "to":"0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761", + "value":"0xde0b6b3a7640000", + "metamaskId":3922064325443432, + "metamaskNetworkId":"3", + "gas":"0x5209" + }, + "gasLimitSpecified":false, + "estimatedGas":"0x5209", + "txFee":"17e0186e60800", + "txValue":"de0b6b3a7640000", + "maxCost":"de234b52e4a0800" + } + ], + "gasMultiplier":1 + } +} -- cgit v1.2.3 From d0e2846eca6f8d2ad16c9338a95fbaac294bac4a Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 15 Feb 2017 11:15:47 -0800 Subject: Complete migration tests. --- test/unit/migrations-test.js | 89 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/unit/migrations-test.js b/test/unit/migrations-test.js index e4353b313..d2a83be77 100644 --- a/test/unit/migrations-test.js +++ b/test/unit/migrations-test.js @@ -2,36 +2,95 @@ const assert = require('assert') const path = require('path') const wallet1 = require(path.join('..', 'lib', 'migrations', '001.json')) +const vault4 = require(path.join('..', 'lib', 'migrations', '004.json')) +let vault5, vault6, vault7, vault8, vault9, vault10, vault11 const migration2 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '002')) const migration3 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '003')) const migration4 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '004')) +const migration5 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '005')) +const migration6 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '006')) +const migration7 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '007')) +const migration8 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '008')) +const migration9 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '009')) +const migration10 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '010')) const migration11 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '011')) const oldTestRpc = 'https://rawtestrpc.metamask.io/' const newTestRpc = 'https://testrpc.metamask.io/' -describe('wallet1 is migrated successfully', function() { - it('should convert providers', function() { +describe('wallet1 is migrated successfully', () => { + it('should convert providers', () => { wallet1.data.config.provider = { type: 'etherscan', rpcTarget: null } return migration2.migrate(wallet1) - .then((firstResult) => { - assert.equal(firstResult.data.config.provider.type, 'rpc', 'provider should be rpc') - assert.equal(firstResult.data.config.provider.rpcTarget, 'https://rpc.metamask.io/', 'main provider should be our rpc') - firstResult.data.config.provider.rpcTarget = oldTestRpc - return migration3.migrate(firstResult) - }).then((secondResult) => { - assert.equal(secondResult.data.config.provider.rpcTarget, newTestRpc) - return migration4.migrate(secondResult) + .then((secondResult) => { + const secondData = secondResult.data + assert.equal(secondData.config.provider.type, 'rpc', 'provider should be rpc') + assert.equal(secondData.config.provider.rpcTarget, 'https://rpc.metamask.io/', 'main provider should be our rpc') + secondResult.data.config.provider.rpcTarget = oldTestRpc + return migration3.migrate(secondResult) }).then((thirdResult) => { - assert.equal(thirdResult.data.config.provider.rpcTarget, null) - assert.equal(thirdResult.data.config.provider.type, 'testnet') - return migration11.migrate(thirdResult) + assert.equal(thirdResult.data.config.provider.rpcTarget, newTestRpc, 'config.provider.rpcTarget should be set to the proper testrpc url.') + return migration4.migrate(thirdResult) + }).then((fourthResult) => { + const fourthData = fourthResult.data + assert.equal(fourthData.config.provider.rpcTarget, null, 'old rpcTarget should not exist.') + assert.equal(fourthData.config.provider.type, 'testnet', 'config.provider should be set to testnet.') + + return migration5.migrate(vault4) + }).then((fifthResult) => { + const fifthData = fifthResult.data + assert.equal(fifthData.vault, null, 'old vault should not exist') + assert.equal(fifthData.walletNicknames, null, 'old walletNicknames should not exist') + assert.equal(fifthData.config.selectedAccount, null, 'old config.selectedAccount should not exist') + assert.equal(fifthData.KeyringController.vault, vault4.data.vault, 'KeyringController.vault should exist') + assert.equal(fifthData.KeyringController.selectedAccount, vault4.data.config.selectedAccount, 'KeyringController.selectedAccount should have moved') + assert.equal(fifthData.KeyringController.walletNicknames['0x0beb674745816b125fbc07285d39fd373e64895c'], vault4.data.walletNicknames['0x0beb674745816b125fbc07285d39fd373e64895c'], 'KeyringController.walletNicknames should have moved') + + vault5 = fifthResult + return migration6.migrate(fifthResult) + }).then((sixthResult) => { + assert.equal(sixthResult.data.KeyringController.selectedAccount, null, 'old selectedAccount should not exist') + assert.equal(sixthResult.data.PreferencesController.selectedAddress, vault5.data.KeyringController.selectedAccount, 'selectedAccount should have moved') + + vault6 = sixthResult + return migration7.migrate(sixthResult) + }).then((seventhResult) => { + assert.equal(seventhResult.data.transactions, null, 'old transactions should not exist') + assert.equal(seventhResult.data.gasMultiplier, null, 'old gasMultiplier should not exist') + assert.equal(seventhResult.data.TransactionManager.transactions[0].id, vault6.data.transactions[0].id, 'transactions should have moved') + assert.equal(seventhResult.data.TransactionManager.gasMultiplier, vault6.data.gasMultiplier, 'gasMultiplier should have moved') + + vault7 = seventhResult + return migration8.migrate(seventhResult) + }).then((eighthResult) => { + assert.equal(eighthResult.data.noticesList, null, 'old noticesList should not exist') + assert.equal(eighthResult.data.NoticeController.noticesList[0].title, vault7.data.noticesList[0].title, 'noticesList should have moved') + + vault8 = eighthResult + return migration9.migrate(eighthResult) + }).then((ninthResult) => { + assert.equal(ninthResult.data.currentFiat, null, 'old currentFiat should not exist') + assert.equal(ninthResult.data.fiatCurrency, null, 'old fiatCurrency should not exist') + assert.equal(ninthResult.data.conversionRate, null, 'old conversionRate should not exist') + assert.equal(ninthResult.data.conversionDate, null, 'old conversionDate should not exist') + + assert.equal(ninthResult.data.CurrencyController.currentCurrency, vault8.data.fiatCurrency, 'currentFiat should have moved') + assert.equal(ninthResult.data.CurrencyController.conversionRate, vault8.data.conversionRate, 'conversionRate should have moved') + assert.equal(ninthResult.data.CurrencyController.conversionDate, vault8.data.conversionDate, 'conversionDate should have moved') + + vault9 = ninthResult + return migration10.migrate(ninthResult) + }).then((tenthResult) => { + assert.equal(tenthResult.data.shapeShiftTxList, null, 'old shapeShiftTxList should not exist') + assert.equal(tenthResult.data.ShapeShiftController.shapeShiftTxList[0].transaction, vault9.data.shapeShiftTxList[0].transaction) + + return migration11.migrate(tenthResult) }).then((eleventhResult) => { - assert.equal(eleventhResult.data.isDisclaimerConfirmed, null) - assert.equal(eleventhResult.data.TOSHash, null) + assert.equal(eleventhResult.data.isDisclaimerConfirmed, null, 'isDisclaimerConfirmed should not exist') + assert.equal(eleventhResult.data.TOSHash, null, 'TOSHash should not exist') }) }) -- cgit v1.2.3