From 600f5c31db47a06c0c9bb9a97c01476d77b0a0df Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 23 Nov 2016 00:23:41 -0800 Subject: Mostly got async keyringController tests passing --- test/unit/keyring-controller-test.js | 42 ++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'test/unit/keyring-controller-test.js') diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js index b20def02e..d35c8927f 100644 --- a/test/unit/keyring-controller-test.js +++ b/test/unit/keyring-controller-test.js @@ -61,7 +61,7 @@ describe('KeyringController', function() { describe('#restoreKeyring', function() { - it(`should pass a keyring's serialized data back to the correct type.`, function() { + it(`should pass a keyring's serialized data back to the correct type.`, function(done) { const mockSerialized = { type: 'HD Key Tree', data: { @@ -74,12 +74,14 @@ describe('KeyringController', function() { mock.expects('getBalanceAndNickname') .exactly(1) - var keyring = keyringController.restoreKeyring(mockSerialized) - assert.equal(keyring.wallets.length, 1, 'one wallet restored') - assert.equal(keyring.getAccounts()[0], addresses[0]) - mock.verify() + keyringController.restoreKeyring(mockSerialized) + .then((keyring) => { + assert.equal(keyring.wallets.length, 1, 'one wallet restored') + assert.equal(keyring.getAccounts()[0], addresses[0]) + mock.verify() + done() + }) }) - }) describe('#migrateOldVaultIfAny', function() { @@ -92,6 +94,7 @@ describe('KeyringController', function() { }) .catch((reason) => { assert.ifError(reason) + done() }) }) }) @@ -110,15 +113,17 @@ describe('KeyringController', function() { }) describe('#saveAccountLabel', function() { - it ('sets the nickname', function() { + it ('sets the nickname', function(done) { const account = addresses[0] var nick = 'Test nickname' keyringController.identities[ethUtil.addHexPrefix(account)] = {} - const label = keyringController.saveAccountLabel(account, nick) - assert.equal(label, nick) - - const persisted = keyringController.configManager.nicknameForWallet(account) - assert.equal(persisted, nick) + keyringController.saveAccountLabel(account, nick, (err, label) => { + assert.ifError(err) + assert.equal(label, nick) + const persisted = keyringController.configManager.nicknameForWallet(account) + assert.equal(persisted, nick) + done() + }) }) this.timeout(10000) @@ -126,9 +131,7 @@ describe('KeyringController', function() { const account = addresses[0] var nick = 'Test nickname' keyringController.configManager.setNicknameForWallet(account, nick) - console.log('calling to restore') keyringController.createNewVaultAndRestore(password, seedWords, (err, state) => { - console.dir({err}) assert.ifError(err) const identity = keyringController.identities['0x' + account] @@ -143,12 +146,15 @@ describe('KeyringController', function() { describe('#getAccounts', function() { it('returns the result of getAccounts for each keyring', function() { keyringController.keyrings = [ - { getAccounts() { return [1,2,3] } }, - { getAccounts() { return [4,5,6] } }, + { getAccounts() { return Promise.resolve([1,2,3]) } }, + { getAccounts() { return Promise.resolve([4,5,6]) } }, ] - const result = keyringController.getAccounts() - assert.deepEqual(result, [1,2,3,4,5,6]) + keyringController.getAccounts() + .then((result) => { + assert.deepEqual(result, [1,2,3,4,5,6]) + done() + }) }) }) -- cgit From 230a0ab876df82edc8147fd3c0ba18f10ffc4e3c Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 23 Nov 2016 11:58:34 -0800 Subject: Fix more keyring asyncifying tests --- test/unit/keyring-controller-test.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'test/unit/keyring-controller-test.js') diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js index d35c8927f..056e465ca 100644 --- a/test/unit/keyring-controller-test.js +++ b/test/unit/keyring-controller-test.js @@ -77,10 +77,17 @@ describe('KeyringController', function() { keyringController.restoreKeyring(mockSerialized) .then((keyring) => { assert.equal(keyring.wallets.length, 1, 'one wallet restored') - assert.equal(keyring.getAccounts()[0], addresses[0]) + return keyring.getAccounts() + }) + .then((accounts) => { + assert.equal(accounts[0], addresses[0]) mock.verify() done() }) + .catch((reason) => { + assert.ifError(reason) + done() + }) }) }) -- cgit