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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 From 45c5a26405e20a64fab16fa212fd4e5b21e49e68 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 28 Nov 2017 17:25:09 -0800 Subject: Fix test to skip screens before privacy notice --- test/integration/lib/mascara-first-time.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js index 3398a5511..9141b68d2 100644 --- a/test/integration/lib/mascara-first-time.js +++ b/test/integration/lib/mascara-first-time.js @@ -57,8 +57,14 @@ async function runFirstTimeUsageTest (assert, done) { await timeout(1000) + // Skip things before Privacy: + let detail = app.find('.tou__title')[0] + while (detail !== 'Privacy Notice') { + app.find('button').click() + await timeout(1000) + } + // Privacy Screen - const detail = app.find('.tou__title')[0] assert.equal(detail.textContent, 'Privacy Notice', 'privacy notice screen') app.find('button').click() -- cgit v1.2.3 From e35cd77eee3212063703f42b37f51be80cdbdab1 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 29 Nov 2017 11:49:53 -0800 Subject: Accept all notices in integration tests --- test/integration/lib/mascara-first-time.js | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'test') diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js index 9141b68d2..42ef83f4f 100644 --- a/test/integration/lib/mascara-first-time.js +++ b/test/integration/lib/mascara-first-time.js @@ -57,29 +57,14 @@ async function runFirstTimeUsageTest (assert, done) { await timeout(1000) - // Skip things before Privacy: + // Skip notices: let detail = app.find('.tou__title')[0] - while (detail !== 'Privacy Notice') { + let button = app.find('button') + if (button.html() === 'Accept') { app.find('button').click() await timeout(1000) } - // Privacy Screen - assert.equal(detail.textContent, 'Privacy Notice', 'privacy notice screen') - app.find('button').click() - - await timeout(1000) - - - // terms of service screen - const tou = app.find('.tou__title')[0] - assert.equal(tou.textContent, 'Terms of Use', 'terms of use screen') - app.find('.tou__body').scrollTop(100000) - await timeout(1000) - - app.find('.first-time-flow__button').click() - await timeout(1000) - // secret backup phrase const seedTitle = app.find('.backup-phrase__title')[0] assert.equal(seedTitle.textContent, 'Secret Backup Phrase', 'seed phrase screen') -- cgit v1.2.3 From 4e6946f47cc91ed494e1e4033768af01cd4a7e16 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 29 Nov 2017 11:52:26 -0800 Subject: Fix test selector --- test/integration/lib/mascara-first-time.js | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js index 42ef83f4f..c07260544 100644 --- a/test/integration/lib/mascara-first-time.js +++ b/test/integration/lib/mascara-first-time.js @@ -63,6 +63,7 @@ async function runFirstTimeUsageTest (assert, done) { if (button.html() === 'Accept') { app.find('button').click() await timeout(1000) + button = app.find('button') } // secret backup phrase -- cgit v1.2.3 From 6d63720f872c67f083a321d3081e2792acf57453 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 29 Nov 2017 12:11:09 -0800 Subject: Remove duplicate button declaration --- test/integration/lib/mascara-first-time.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js index c07260544..55b98765f 100644 --- a/test/integration/lib/mascara-first-time.js +++ b/test/integration/lib/mascara-first-time.js @@ -51,7 +51,7 @@ async function runFirstTimeUsageTest (assert, done) { assert.equal(created.textContent, 'Your unique account image', 'unique image screen') // Agree button - const button = app.find('button')[0] + let button = app.find('button')[0] assert.ok(button, 'button present') button.click() @@ -59,7 +59,7 @@ async function runFirstTimeUsageTest (assert, done) { // Skip notices: let detail = app.find('.tou__title')[0] - let button = app.find('button') + button = app.find('button') if (button.html() === 'Accept') { app.find('button').click() await timeout(1000) -- cgit v1.2.3 From 119c0fdecf504fcaa84987639e8f3c031b1b8285 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 29 Nov 2017 12:23:31 -0800 Subject: Make test more resilient --- test/integration/lib/mascara-first-time.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js index 55b98765f..aebaef83c 100644 --- a/test/integration/lib/mascara-first-time.js +++ b/test/integration/lib/mascara-first-time.js @@ -9,7 +9,7 @@ async function runFirstTimeUsageTest (assert, done) { // recurse notices while (true) { const button = app.find('button') - if (button.html() === 'Accept') { + if (button && button.html() === 'Accept') { // still notices to accept const termsPage = app.find('.markdown')[0] termsPage.scrollTop = termsPage.scrollHeight @@ -59,8 +59,8 @@ async function runFirstTimeUsageTest (assert, done) { // Skip notices: let detail = app.find('.tou__title')[0] - button = app.find('button') - if (button.html() === 'Accept') { + button = app.find('button')[0] + if (button && button.html() === 'Accept') { app.find('button').click() await timeout(1000) button = app.find('button') -- cgit v1.2.3 From 9276fea6bc3a2d3678afdd60fa14e661b64a30a0 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 29 Nov 2017 12:30:10 -0800 Subject: Redundantly skip notices --- test/integration/lib/mascara-first-time.js | 47 ++++++++++++++---------------- 1 file changed, 22 insertions(+), 25 deletions(-) (limited to 'test') diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js index aebaef83c..6772dd701 100644 --- a/test/integration/lib/mascara-first-time.js +++ b/test/integration/lib/mascara-first-time.js @@ -6,23 +6,7 @@ async function runFirstTimeUsageTest (assert, done) { const app = $('#app-content') - // recurse notices - while (true) { - const button = app.find('button') - if (button && button.html() === 'Accept') { - // still notices to accept - const termsPage = app.find('.markdown')[0] - termsPage.scrollTop = termsPage.scrollHeight - await timeout() - console.log('Clearing notice') - button.click() - await timeout() - } else { - // exit loop - console.log('No more notices...') - break - } - } + skipNotices() await timeout() @@ -57,14 +41,7 @@ async function runFirstTimeUsageTest (assert, done) { await timeout(1000) - // Skip notices: - let detail = app.find('.tou__title')[0] - button = app.find('button')[0] - if (button && button.html() === 'Accept') { - app.find('button').click() - await timeout(1000) - button = app.find('button') - } + skipNotices() // secret backup phrase const seedTitle = app.find('.backup-phrase__title')[0] @@ -157,3 +134,23 @@ function timeout (time) { setTimeout(resolve, time || 1500) }) } + +function skipNotices () { + while (true) { + const button = app.find('button') + if (button && button.html() === 'Accept') { + // still notices to accept + const termsPage = app.find('.markdown')[0] + termsPage.scrollTop = termsPage.scrollHeight + await timeout() + console.log('Clearing notice') + button.click() + await timeout() + } else { + console.dir(button) + // exit loop + console.log('No more notices...') + break + } + } +} -- cgit v1.2.3 From 42108ba3bc536d619e3658fa945520e8fc44071e Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 29 Nov 2017 12:39:48 -0800 Subject: Make notice skipping async --- test/integration/lib/mascara-first-time.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js index 6772dd701..f5912d9cd 100644 --- a/test/integration/lib/mascara-first-time.js +++ b/test/integration/lib/mascara-first-time.js @@ -6,7 +6,7 @@ async function runFirstTimeUsageTest (assert, done) { const app = $('#app-content') - skipNotices() + await skipNotices() await timeout() @@ -41,7 +41,7 @@ async function runFirstTimeUsageTest (assert, done) { await timeout(1000) - skipNotices() + await skipNotices() // secret backup phrase const seedTitle = app.find('.backup-phrase__title')[0] @@ -135,7 +135,7 @@ function timeout (time) { }) } -function skipNotices () { +async function skipNotices () { while (true) { const button = app.find('button') if (button && button.html() === 'Accept') { -- cgit v1.2.3 From f725bc6ab72c1e0aac600cc830be703961ae8ec1 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 29 Nov 2017 12:41:55 -0800 Subject: Fix test reference --- test/integration/lib/mascara-first-time.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js index f5912d9cd..c43f99b29 100644 --- a/test/integration/lib/mascara-first-time.js +++ b/test/integration/lib/mascara-first-time.js @@ -6,7 +6,7 @@ async function runFirstTimeUsageTest (assert, done) { const app = $('#app-content') - await skipNotices() + await skipNotices(app) await timeout() @@ -41,7 +41,7 @@ async function runFirstTimeUsageTest (assert, done) { await timeout(1000) - await skipNotices() + await skipNotices(app) // secret backup phrase const seedTitle = app.find('.backup-phrase__title')[0] @@ -135,7 +135,7 @@ function timeout (time) { }) } -async function skipNotices () { +async function skipNotices (app) { while (true) { const button = app.find('button') if (button && button.html() === 'Accept') { -- cgit v1.2.3 From adc66974ff6c14988945ddc93e56e5030ba144d1 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 29 Nov 2017 13:34:19 -0800 Subject: Add markdown class to mascara ui markdown field --- test/integration/lib/mascara-first-time.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js index c43f99b29..da649803a 100644 --- a/test/integration/lib/mascara-first-time.js +++ b/test/integration/lib/mascara-first-time.js @@ -141,14 +141,15 @@ async function skipNotices (app) { if (button && button.html() === 'Accept') { // still notices to accept const termsPage = app.find('.markdown')[0] + if (!termsPage) { + debugger + break + } termsPage.scrollTop = termsPage.scrollHeight await timeout() - console.log('Clearing notice') button.click() await timeout() } else { - console.dir(button) - // exit loop console.log('No more notices...') break } -- cgit v1.2.3 From 10459ebaf4ca9c7357e7f4e520087fadc493909e Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 29 Nov 2017 13:35:48 -0800 Subject: Remove debugger --- test/integration/lib/mascara-first-time.js | 1 - 1 file changed, 1 deletion(-) (limited to 'test') diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js index da649803a..5c18cd254 100644 --- a/test/integration/lib/mascara-first-time.js +++ b/test/integration/lib/mascara-first-time.js @@ -142,7 +142,6 @@ async function skipNotices (app) { // still notices to accept const termsPage = app.find('.markdown')[0] if (!termsPage) { - debugger break } termsPage.scrollTop = termsPage.scrollHeight -- cgit v1.2.3 From af8fcb67778fadd7056c0930eeb9d22eb28b0e69 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 6 Dec 2017 14:10:11 -0330 Subject: Update resubmitPendingTxs tests. --- test/unit/pending-tx-test.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js index 4b5170dfe..7069554f7 100644 --- a/test/unit/pending-tx-test.js +++ b/test/unit/pending-tx-test.js @@ -206,6 +206,7 @@ describe('PendingTransactionTracker', function () { }) describe('#resubmitPendingTxs', function () { + const blockStub = { number: '0x0' }; beforeEach(function () { const txMeta2 = txMeta3 = txMeta txList = [txMeta, txMeta2, txMeta3].map((tx) => { @@ -223,7 +224,7 @@ describe('PendingTransactionTracker', function () { Promise.all(txList.map((tx) => tx.processed)) .then((txCompletedList) => done()) .catch(done) - pendingTxTracker.resubmitPendingTxs() + pendingTxTracker.resubmitPendingTxs(blockStub) }) it('should not emit \'tx:failed\' if the txMeta throws a known txError', function (done) { knownErrors =[ @@ -250,7 +251,7 @@ describe('PendingTransactionTracker', function () { .then((txCompletedList) => done()) .catch(done) - pendingTxTracker.resubmitPendingTxs() + pendingTxTracker.resubmitPendingTxs(blockStub) }) it('should emit \'tx:warning\' if it encountered a real error', function (done) { pendingTxTracker.once('tx:warning', (txMeta, err) => { @@ -268,7 +269,7 @@ describe('PendingTransactionTracker', function () { .then((txCompletedList) => done()) .catch(done) - pendingTxTracker.resubmitPendingTxs() + pendingTxTracker.resubmitPendingTxs(blockStub) }) }) describe('#_resubmitTx', function () { -- cgit v1.2.3 From 3356c15d04d947c92a2c19690384396651c352e5 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 6 Dec 2017 14:11:14 -0330 Subject: Add tests for exponential backoff code in _resubmitTx --- test/unit/pending-tx-test.js | 80 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 17 deletions(-) (limited to 'test') diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js index 7069554f7..393601a57 100644 --- a/test/unit/pending-tx-test.js +++ b/test/unit/pending-tx-test.js @@ -273,24 +273,70 @@ describe('PendingTransactionTracker', function () { }) }) describe('#_resubmitTx', function () { - it('should publishing the transaction', function (done) { - const enoughBalance = '0x100000' - pendingTxTracker.getBalance = (address) => { - assert.equal(address, txMeta.txParams.from, 'Should pass the address') - return enoughBalance - } - pendingTxTracker.publishTransaction = async (rawTx) => { - assert.equal(rawTx, txMeta.rawTx, 'Should pass the rawTx') - } + const mockFirstRetryBlockNumber = '0x1' + let txMetaToTestExponentialBackoff + + beforeEach(() => { + pendingTxTracker.getBalance = (address) => { + assert.equal(address, txMeta.txParams.from, 'Should pass the address') + return enoughBalance + } + pendingTxTracker.publishTransaction = async (rawTx) => { + assert.equal(rawTx, txMeta.rawTx, 'Should pass the rawTx') + } + sinon.spy(pendingTxTracker, 'publishTransaction') + + txMetaToTestExponentialBackoff = Object.assign({}, txMeta, { + retryCount: 4, + firstRetryBlockNumber: mockFirstRetryBlockNumber, + }) + }) - // Stubbing out current account state: - // Adding the fake tx: - pendingTxTracker._resubmitTx(txMeta) - .then(() => done()) - .catch((err) => { - assert.ifError(err, 'should not throw an error') - done(err) + afterEach(() => { + pendingTxTracker.publishTransaction.reset() + }) + + it('should publish the transaction', function (done) { + const enoughBalance = '0x100000' + + // Stubbing out current account state: + // Adding the fake tx: + pendingTxTracker._resubmitTx(txMeta) + .then(() => done()) + .catch((err) => { + assert.ifError(err, 'should not throw an error') + done(err) + }) + + assert.equal(pendingTxTracker.publishTransaction.callCount, 1, 'Should call publish transaction') + }) + + it('should not publish the transaction if the limit of retries has been exceeded', function (done) { + const enoughBalance = '0x100000' + const mockLatestBlockNumber = '0x5' + + pendingTxTracker._resubmitTx(txMetaToTestExponentialBackoff, mockLatestBlockNumber) + .then(() => done()) + .catch((err) => { + assert.ifError(err, 'should not throw an error') + done(err) + }) + + assert.equal(pendingTxTracker.publishTransaction.callCount, 0, 'Should NOT call publish transaction') + }) + + it('should publish the transaction if the number of blocks since last retry exceeds the last set limit', function (done) { + const enoughBalance = '0x100000' + const mockLatestBlockNumber = '0x11' + + pendingTxTracker._resubmitTx(txMetaToTestExponentialBackoff, mockLatestBlockNumber) + .then(() => done()) + .catch((err) => { + assert.ifError(err, 'should not throw an error') + done(err) + }) + + assert.equal(pendingTxTracker.publishTransaction.callCount, 1, 'Should call publish transaction') }) - }) }) }) -- cgit v1.2.3 From ec6c3c33bdbe2d90dc71649d0cc5fb3c07d96af7 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 5 Dec 2017 13:11:59 -0330 Subject: Merge branch 'master' into NewUI-flat-merge-with-master --- test/integration/lib/mascara-first-time.js | 59 ++++++++++++------------------ test/unit/metamask-controller-test.js | 33 +++++++++++++++++ 2 files changed, 57 insertions(+), 35 deletions(-) (limited to 'test') diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js index 398ecea0e..515c7f383 100644 --- a/test/integration/lib/mascara-first-time.js +++ b/test/integration/lib/mascara-first-time.js @@ -6,23 +6,7 @@ async function runFirstTimeUsageTest (assert, done) { const app = $('#app-content') - // recurse notices - while (true) { - const button = app.find('button') - if (button.html() === 'Accept') { - // still notices to accept - const termsPage = app.find('.markdown')[0] - termsPage.scrollTop = termsPage.scrollHeight - await timeout() - console.log('Clearing notice') - button.click() - await timeout() - } else { - // exit loop - console.log('No more notices...') - break - } - } + await skipNotices(app) await timeout() @@ -51,28 +35,13 @@ async function runFirstTimeUsageTest (assert, done) { assert.equal(created.textContent, 'Your unique account image', 'unique image screen') // Agree button - const button = app.find('button')[0] + let button = app.find('button')[0] assert.ok(button, 'button present') button.click() await timeout(1000) - // Privacy Screen - const detail = app.find('.tou__title')[0] - assert.equal(detail.textContent, 'Privacy Notice', 'privacy notice screen') - app.find('button').click() - - await timeout(1000) - - - // terms of service screen - const tou = app.find('.tou__title')[0] - assert.equal(tou.textContent, 'Terms of Use', 'terms of use screen') - app.find('.tou__body').scrollTop(100000) - await timeout(1000) - - app.find('.first-time-flow__button').click() - await timeout(1000) + await skipNotices(app) // secret backup phrase const seedTitle = app.find('.backup-phrase__title')[0] @@ -156,4 +125,24 @@ function timeout (time) { return new Promise((resolve, reject) => { setTimeout(resolve, time || 1500) }) -} \ No newline at end of file +} + +async function skipNotices (app) { + while (true) { + const button = app.find('button') + if (button && button.html() === 'Accept') { + // still notices to accept + const termsPage = app.find('.markdown')[0] + if (!termsPage) { + break + } + termsPage.scrollTop = termsPage.scrollHeight + await timeout() + button.click() + await timeout() + } else { + console.log('No more notices...') + break + } + } +} diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index ef6cae758..fd420a70f 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -11,6 +11,15 @@ describe('MetaMaskController', function () { unlockAccountMessage: noop, showUnapprovedTx: noop, platform: {}, + encryptor: { + encrypt: function(password, object) { + this.object = object + return Promise.resolve() + }, + decrypt: function () { + return Promise.resolve(this.object) + } + }, // initial state initState: clone(firstTimeState), }) @@ -27,6 +36,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 password = 'a-fake-password' + + const first = await metamaskController.createNewVaultAndKeychain(password) + const second = await metamaskController.createNewVaultAndKeychain(password) + + assert(metamaskController.keyringController.createNewVaultAndKeychain.calledOnce) + + selectStub.reset() + }) + }) }) }) -- cgit v1.2.3