diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-11-23 16:23:41 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-11-23 16:23:41 +0800 |
commit | 600f5c31db47a06c0c9bb9a97c01476d77b0a0df (patch) | |
tree | 5bfd1ce4ebaa634509cd099d1ce981309b5914e8 /test | |
parent | c77d355e98d3c61699a3a85dfc2ed1f320a9eb03 (diff) | |
download | tangerine-wallet-browser-600f5c31db47a06c0c9bb9a97c01476d77b0a0df.tar tangerine-wallet-browser-600f5c31db47a06c0c9bb9a97c01476d77b0a0df.tar.gz tangerine-wallet-browser-600f5c31db47a06c0c9bb9a97c01476d77b0a0df.tar.bz2 tangerine-wallet-browser-600f5c31db47a06c0c9bb9a97c01476d77b0a0df.tar.lz tangerine-wallet-browser-600f5c31db47a06c0c9bb9a97c01476d77b0a0df.tar.xz tangerine-wallet-browser-600f5c31db47a06c0c9bb9a97c01476d77b0a0df.tar.zst tangerine-wallet-browser-600f5c31db47a06c0c9bb9a97c01476d77b0a0df.zip |
Mostly got async keyringController tests passing
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/keyring-controller-test.js | 42 | ||||
-rw-r--r-- | test/unit/keyrings/hd-test.js | 67 | ||||
-rw-r--r-- | test/unit/keyrings/simple-test.js | 37 |
3 files changed, 91 insertions, 55 deletions
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() + }) }) }) diff --git a/test/unit/keyrings/hd-test.js b/test/unit/keyrings/hd-test.js index bec1a8134..2c984267e 100644 --- a/test/unit/keyrings/hd-test.js +++ b/test/unit/keyrings/hd-test.js @@ -16,15 +16,18 @@ describe('hd-keyring', function() { keyring = new HdKeyring() }) - describe('constructor', function() { + describe('constructor', function(done) { keyring = new HdKeyring({ mnemonic: sampleMnemonic, numberOfAccounts: 2, }) const accounts = keyring.getAccounts() - assert.equal(accounts[0], firstAcct) - assert.equal(accounts[1], secondAcct) + .then((accounts) => { + assert.equal(accounts[0], firstAcct) + assert.equal(accounts[1], secondAcct) + done() + }) }) describe('Keyring.type', function() { @@ -44,49 +47,62 @@ describe('hd-keyring', function() { describe('#serialize empty wallets.', function() { it('serializes a new mnemonic', function() { - const output = keyring.serialize() - assert.equal(output.numberOfAccounts, 0) - assert.equal(output.mnemonic, null) + keyring.serialize() + .then((output) => { + assert.equal(output.numberOfAccounts, 0) + assert.equal(output.mnemonic, null) + }) }) }) describe('#deserialize a private key', function() { - it('serializes what it deserializes', function() { + it('serializes what it deserializes', function(done) { keyring.deserialize({ mnemonic: sampleMnemonic, numberOfAccounts: 1 }) - assert.equal(keyring.wallets.length, 1, 'restores two accounts') - keyring.addAccounts(1) - - const accounts = keyring.getAccounts() - assert.equal(accounts[0], firstAcct) - assert.equal(accounts[1], secondAcct) - assert.equal(accounts.length, 2) - - const serialized = keyring.serialize() - assert.equal(serialized.mnemonic, sampleMnemonic) + .then(() => { + assert.equal(keyring.wallets.length, 1, 'restores two accounts') + keyring.addAccounts(1) + + const accounts = keyring.getAccounts() + assert.equal(accounts[0], firstAcct) + assert.equal(accounts[1], secondAcct) + assert.equal(accounts.length, 2) + + keyring.serialize() + .then((serialized) => { + assert.equal(serialized.mnemonic, sampleMnemonic) + done() + }) + }) }) }) describe('#addAccounts', function() { describe('with no arguments', function() { - it('creates a single wallet', function() { + it('creates a single wallet', function(done) { keyring.addAccounts() - assert.equal(keyring.wallets.length, 1) + .then(() => { + assert.equal(keyring.wallets.length, 1) + done() + }) }) }) describe('with a numeric argument', function() { - it('creates that number of wallets', function() { + it('creates that number of wallets', function(done) { keyring.addAccounts(3) - assert.equal(keyring.wallets.length, 3) + .then(() => { + assert.equal(keyring.wallets.length, 3) + done() + }) }) }) }) describe('#getAccounts', function() { - it('calls getAddress on each wallet', function() { + it('calls getAddress on each wallet', function(done) { // Push a mock wallet const desiredOutput = 'foo' @@ -101,8 +117,11 @@ describe('hd-keyring', function() { }) const output = keyring.getAccounts() - assert.equal(output[0], desiredOutput) - assert.equal(output.length, 1) + .then((output) => { + assert.equal(output[0], desiredOutput) + assert.equal(output.length, 1) + done() + }) }) }) }) diff --git a/test/unit/keyrings/simple-test.js b/test/unit/keyrings/simple-test.js index 96a2fdcf0..979abdb69 100644 --- a/test/unit/keyrings/simple-test.js +++ b/test/unit/keyrings/simple-test.js @@ -28,19 +28,23 @@ describe('simple-keyring', function() { }) describe('#serialize empty wallets.', function() { - it('serializes an empty array', function() { - const output = keyring.serialize() - assert.deepEqual(output, []) + it('serializes an empty array', function(done) { + keyring.serialize() + .then((output) => { + assert.deepEqual(output, []) + done() + }) }) }) describe('#deserialize a private key', function() { it('serializes what it deserializes', function() { keyring.deserialize([privKeyHex]) - assert.equal(keyring.wallets.length, 1, 'has one wallet') - - const serialized = keyring.serialize() - assert.equal(serialized[0], privKeyHex) + .then(() => { + assert.equal(keyring.wallets.length, 1, 'has one wallet') + const serialized = keyring.serialize() + assert.equal(serialized[0], privKeyHex) + }) }) }) @@ -48,20 +52,24 @@ describe('simple-keyring', function() { describe('with no arguments', function() { it('creates a single wallet', function() { keyring.addAccounts() - assert.equal(keyring.wallets.length, 1) + .then(() => { + assert.equal(keyring.wallets.length, 1) + }) }) }) describe('with a numeric argument', function() { it('creates that number of wallets', function() { keyring.addAccounts(3) - assert.equal(keyring.wallets.length, 3) + .then(() => { + assert.equal(keyring.wallets.length, 3) + }) }) }) }) describe('#getAccounts', function() { - it('calls getAddress on each wallet', function() { + it('calls getAddress on each wallet', function(done) { // Push a mock wallet const desiredOutput = 'foo' @@ -75,9 +83,12 @@ describe('simple-keyring', function() { } }) - const output = keyring.getAccounts() - assert.equal(output[0], desiredOutput) - assert.equal(output.length, 1) + keyring.getAccounts() + .then((output) => { + assert.equal(output[0], desiredOutput) + assert.equal(output.length, 1) + done() + }) }) }) }) |