From 0b13429daf00ddd5bdf2705c7a95d7a9d5792f54 Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Thu, 4 May 2017 14:35:10 -0700 Subject: Lint tests --- test/unit/metamask-controller-test.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'test/unit/metamask-controller-test.js') diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index 78b9e9df7..ac588b313 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -4,11 +4,11 @@ const clone = require('clone') const MetaMaskController = require('../../app/scripts/metamask-controller') const firstTimeState = require('../../app/scripts/first-time-state') -const STORAGE_KEY = 'metamask-config' +// const STORAGE_KEY = 'metamask-config' -describe('MetaMaskController', function() { +describe('MetaMaskController', function () { const noop = () => {} - let controller = new MetaMaskController({ + const metamaskController = new MetaMaskController({ showUnconfirmedMessage: noop, unlockAccountMessage: noop, showUnapprovedTx: noop, @@ -16,14 +16,18 @@ describe('MetaMaskController', function() { initState: clone(firstTimeState), }) - beforeEach(function() { + beforeEach(function () { // sinon allows stubbing methods that are easily verified this.sinon = sinon.sandbox.create() }) - afterEach(function() { + afterEach(function () { // sinon requires cleanup otherwise it will overwrite context this.sinon.restore() }) -}) \ No newline at end of file + describe('Metamask Controller', function () { + assert(metamaskController) + }) +}) + -- cgit From 9bd7d06c4f3aab94308335f2e13c01bcca88eb4b Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Thu, 4 May 2017 15:06:27 -0700 Subject: Remove unused modules and STORAGE_KEY --- test/unit/metamask-controller-test.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'test/unit/metamask-controller-test.js') diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index ac588b313..5ee0a6c84 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -4,8 +4,6 @@ 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 () { const noop = () => {} const metamaskController = new MetaMaskController({ -- cgit From 4e57cdf8b35c0bde571fb108b76d70ca251644f7 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Tue, 19 Sep 2017 10:53:56 -0700 Subject: stub platform --- test/unit/metamask-controller-test.js | 1 + 1 file changed, 1 insertion(+) (limited to 'test/unit/metamask-controller-test.js') diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index 5ee0a6c84..ef6cae758 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -10,6 +10,7 @@ describe('MetaMaskController', function () { showUnconfirmedMessage: noop, unlockAccountMessage: noop, showUnapprovedTx: noop, + platform: {}, // initial state initState: clone(firstTimeState), }) -- cgit From 884f2035648a8ab7ddbde9f911ed608670912752 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 20 Nov 2017 14:15:00 -0800 Subject: Add failing test for #2577 Seed Phrase Bug --- test/unit/metamask-controller-test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/unit/metamask-controller-test.js') diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index ef6cae758..548b5f87f 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -27,6 +27,24 @@ describe('MetaMaskController', function () { describe('Metamask Controller', function () { assert(metamaskController) + + describe('#createNewVaultAndKeychain', function () { + it('can only create new vault on keyringController once', async function () { + + const selectStub = sinon.stub(metamaskController, 'selectFirstIdentity') + + const expectation = sinon.mock(metamaskController.keyringController) + .expects('createNewVaultAndKeychain').once() + + const password = 'a-fake-password' + + const first = await metamaskController.createNewVaultAndKeychain(password) + const second = await metamaskController.createNewVaultAndKeychain(password) + + expectation.verify() + selectStub.reset() + }) + }) }) }) -- cgit From 764a5bac56ddc855f669495daee720288cbee200 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 20 Nov 2017 14:44:12 -0800 Subject: Get test passing --- test/unit/metamask-controller-test.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'test/unit/metamask-controller-test.js') diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index 548b5f87f..e80198dda 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -11,6 +11,17 @@ describe('MetaMaskController', function () { unlockAccountMessage: noop, showUnapprovedTx: noop, platform: {}, + encryptor: { + encrypt: function(password, object) { + console.log('encrypting ', object) + this.object = object + return Promise.resolve() + }, + decrypt: function () { + console.log('decrypting') + return Promise.resolve(this.object) + } + }, // initial state initState: clone(firstTimeState), }) @@ -28,20 +39,30 @@ describe('MetaMaskController', function () { describe('Metamask Controller', function () { assert(metamaskController) + beforeEach(function () { + sinon.spy(metamaskController.keyringController, 'createNewVaultAndKeychain') + }) + + afterEach(function () { + metamaskController.keyringController.createNewVaultAndKeychain.restore() + }) + describe('#createNewVaultAndKeychain', function () { it('can only create new vault on keyringController once', async function () { const selectStub = sinon.stub(metamaskController, 'selectFirstIdentity') - const expectation = sinon.mock(metamaskController.keyringController) - .expects('createNewVaultAndKeychain').once() - const password = 'a-fake-password' const first = await metamaskController.createNewVaultAndKeychain(password) + console.log('FIRST ONE RETURNED:') + console.dir(first) const second = await metamaskController.createNewVaultAndKeychain(password) + console.log('SECOND ONE RETURNED:') + console.dir(second) + + assert(metamaskController.keyringController.createNewVaultAndKeychain.calledOnce) - expectation.verify() selectStub.reset() }) }) -- cgit From 8dd0093184cfade8fa75fcab588f4a0e660f39fb Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 20 Nov 2017 14:46:36 -0800 Subject: Remove logs --- test/unit/metamask-controller-test.js | 6 ------ 1 file changed, 6 deletions(-) (limited to 'test/unit/metamask-controller-test.js') diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index e80198dda..fd420a70f 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -13,12 +13,10 @@ describe('MetaMaskController', function () { platform: {}, encryptor: { encrypt: function(password, object) { - console.log('encrypting ', object) this.object = object return Promise.resolve() }, decrypt: function () { - console.log('decrypting') return Promise.resolve(this.object) } }, @@ -55,11 +53,7 @@ describe('MetaMaskController', function () { const password = 'a-fake-password' const first = await metamaskController.createNewVaultAndKeychain(password) - console.log('FIRST ONE RETURNED:') - console.dir(first) const second = await metamaskController.createNewVaultAndKeychain(password) - console.log('SECOND ONE RETURNED:') - console.dir(second) assert(metamaskController.keyringController.createNewVaultAndKeychain.calledOnce) -- cgit From 4b63ec8f1daaba11e66322fbdfb045ba1ea5319d Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 3 Jan 2018 16:44:14 -0800 Subject: Test for failure of the async methods. --- test/unit/metamask-controller-test.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'test/unit/metamask-controller-test.js') diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index fd420a70f..873b8d17d 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -39,17 +39,19 @@ describe('MetaMaskController', function () { beforeEach(function () { sinon.spy(metamaskController.keyringController, 'createNewVaultAndKeychain') + sinon.spy(metamaskController.keyringController, 'createNewVaultAndRestore') }) afterEach(function () { metamaskController.keyringController.createNewVaultAndKeychain.restore() + metamaskController.keyringController.createNewVaultAndRestore.restore() }) describe('#createNewVaultAndKeychain', function () { it('can only create new vault on keyringController once', async function () { - const selectStub = sinon.stub(metamaskController, 'selectFirstIdentity') + const password = 'a-fake-password' const first = await metamaskController.createNewVaultAndKeychain(password) @@ -60,6 +62,22 @@ describe('MetaMaskController', function () { selectStub.reset() }) }) + + describe('#createNewVaultAndRestore', function () { + it('should be able to call newVaultAndRestore despite a mistake.', async function () { + // const selectStub = sinon.stub(metamaskController, 'selectFirstIdentity') + + const password = 'what-what-what' + const wrongSeed = 'debris dizzy just program just float decrease vacant alarm reduce speak stadiu' + const rightSeed = 'debris dizzy just program just float decrease vacant alarm reduce speak stadium' + const first = await metamaskController.createNewVaultAndRestore(password, wrongSeed) + .catch((e) => { + return + }) + const second = await metamaskController.createNewVaultAndRestore(password, rightSeed) + + assert(metamaskController.keyringController.createNewVaultAndRestore.calledTwice) + }) + }) }) }) - -- cgit From 571f6723a64f28f22b7a7439d1f16bcbc9345320 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 5 Jan 2018 21:24:10 -0800 Subject: Add test for better gas estimation --- test/unit/metamask-controller-test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/unit/metamask-controller-test.js') diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index fd420a70f..293a45eef 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -3,6 +3,8 @@ const sinon = require('sinon') const clone = require('clone') const MetaMaskController = require('../../app/scripts/metamask-controller') const firstTimeState = require('../../app/scripts/first-time-state') +const BN = require('ethereumjs-util').BN +const GWEI_BN = new BN('1000000000') describe('MetaMaskController', function () { const noop = () => {} @@ -45,6 +47,29 @@ describe('MetaMaskController', function () { metamaskController.keyringController.createNewVaultAndKeychain.restore() }) + describe('#getGasPrice', function () { + it('gives the 50th percentile lowest accepted gas price from recentBlocksController', async function () { + const realRecentBlocksController = metamaskController.recentBlocksController + metamaskController.recentBlocksController = { + store: { + getState: () => { + return { + recentBlocks: [ + { transactions: [ new BN('50000000000'), new BN('100000000000') ] }, + { transactions: [ new BN('60000000000'), new BN('100000000000') ] }, + ] + } + } + } + } + + const gasPrice = metamaskController.getGasPrice() + assert.equal(gasPrice, 50, 'accurately estimates 50th percentile accepted gas price') + + metamaskController.recentBlocksController = realRecentBlocksController + }) + }) + describe('#createNewVaultAndKeychain', function () { it('can only create new vault on keyringController once', async function () { -- cgit From aec24ec81e4785ceea93375d562458f62be69266 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 5 Jan 2018 22:08:03 -0800 Subject: Fix feature to work --- test/unit/metamask-controller-test.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'test/unit/metamask-controller-test.js') diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index 293a45eef..3deb5a1c7 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -55,8 +55,10 @@ describe('MetaMaskController', function () { getState: () => { return { recentBlocks: [ - { transactions: [ new BN('50000000000'), new BN('100000000000') ] }, - { transactions: [ new BN('60000000000'), new BN('100000000000') ] }, + { gasPrices: [ '0x3b9aca00', '0x174876e800'] }, + { gasPrices: [ '0x3b9aca00', '0x174876e800'] }, + { gasPrices: [ '0x174876e800', '0x174876e800' ]}, + { gasPrices: [ '0x174876e800', '0x174876e800' ]}, ] } } @@ -64,7 +66,7 @@ describe('MetaMaskController', function () { } const gasPrice = metamaskController.getGasPrice() - assert.equal(gasPrice, 50, 'accurately estimates 50th percentile accepted gas price') + assert.equal(gasPrice, '0x3b9aca00', 'accurately estimates 50th percentile accepted gas price') metamaskController.recentBlocksController = realRecentBlocksController }) -- cgit From 943befef91cd725579c4bf4e7024734f02ef98f5 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 8 Jan 2018 15:16:08 -0800 Subject: Add test for gas estimate default --- test/unit/metamask-controller-test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/unit/metamask-controller-test.js') diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index 9ec7cd0af..3fc7f9a98 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -72,6 +72,25 @@ describe('MetaMaskController', function () { metamaskController.recentBlocksController = realRecentBlocksController }) + + it('gives the 1 gwei price if no blocks have been seen.', async function () { + const realRecentBlocksController = metamaskController.recentBlocksController + metamaskController.recentBlocksController = { + store: { + getState: () => { + return { + recentBlocks: [] + } + } + } + } + + const gasPrice = metamaskController.getGasPrice() + assert.equal(gasPrice, '0x' + GWEI_BN.toString(16), 'defaults to 1 gwei') + + metamaskController.recentBlocksController = realRecentBlocksController + }) + }) describe('#createNewVaultAndKeychain', function () { -- cgit