aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorbrunobar79 <brunobar79@gmail.com>2018-07-17 13:17:18 +0800
committerbrunobar79 <brunobar79@gmail.com>2018-07-17 13:17:18 +0800
commitde4265c629f8e68d882c2ded0e20417327cf4d2f (patch)
tree0c2a9abc3a83fc103861d48c19f455118859ab49 /test
parente5512c306ded1d2a521a0ba0d2c3cdd5878e53bb (diff)
downloadtangerine-wallet-browser-de4265c629f8e68d882c2ded0e20417327cf4d2f.tar
tangerine-wallet-browser-de4265c629f8e68d882c2ded0e20417327cf4d2f.tar.gz
tangerine-wallet-browser-de4265c629f8e68d882c2ded0e20417327cf4d2f.tar.bz2
tangerine-wallet-browser-de4265c629f8e68d882c2ded0e20417327cf4d2f.tar.lz
tangerine-wallet-browser-de4265c629f8e68d882c2ded0e20417327cf4d2f.tar.xz
tangerine-wallet-browser-de4265c629f8e68d882c2ded0e20417327cf4d2f.tar.zst
tangerine-wallet-browser-de4265c629f8e68d882c2ded0e20417327cf4d2f.zip
added more unit tests
Diffstat (limited to 'test')
-rw-r--r--test/unit/app/controllers/metamask-controller-test.js57
1 files changed, 55 insertions, 2 deletions
diff --git a/test/unit/app/controllers/metamask-controller-test.js b/test/unit/app/controllers/metamask-controller-test.js
index bef126f1f..a08371f86 100644
--- a/test/unit/app/controllers/metamask-controller-test.js
+++ b/test/unit/app/controllers/metamask-controller-test.js
@@ -233,10 +233,12 @@ describe('MetaMaskController', function () {
})
it('should add the Trezor Hardware keyring', async function () {
+ sinon.spy(metamaskController.keyringController, 'addNewKeyring')
await metamaskController.connectHardware('trezor', 0).catch((e) => null)
const keyrings = await metamaskController.keyringController.getKeyringsByType(
'Trezor Hardware'
)
+ assert.equal(metamaskController.keyringController.addNewKeyring.getCall(0).args, 'Trezor Hardware')
assert.equal(keyrings.length, 1)
})
@@ -281,15 +283,66 @@ describe('MetaMaskController', function () {
})
describe('unlockTrezorAccount', function () {
- it('should set accountToUnlock in the keyring', async function () {
+ let accountToUnlock
+ let windowOpenStub
+ let addNewAccountStub
+ let getAccountsStub
+ beforeEach(async function () {
+ accountToUnlock = 10
+ windowOpenStub = sinon.stub(window, 'open')
+ windowOpenStub.returns(noop)
+
+ addNewAccountStub = sinon.stub(metamaskController.keyringController, 'addNewAccount')
+ addNewAccountStub.returns({})
+
+ getAccountsStub = sinon.stub(metamaskController.keyringController, 'getAccounts')
+ // Need to return different address to mock the behavior of
+ // adding a new account from the keyring
+ getAccountsStub.onCall(0).returns(Promise.resolve(['0x1']))
+ getAccountsStub.onCall(1).returns(Promise.resolve(['0x2']))
+ getAccountsStub.onCall(2).returns(Promise.resolve(['0x3']))
+ getAccountsStub.onCall(3).returns(Promise.resolve(['0x4']))
+ sinon.spy(metamaskController.preferencesController, 'setAddresses')
+ sinon.spy(metamaskController.preferencesController, 'setSelectedAddress')
+ sinon.spy(metamaskController.preferencesController, 'setAccountLabel')
await metamaskController.connectHardware('trezor', 0).catch((e) => null)
- const accountToUnlock = 10
await metamaskController.unlockTrezorAccount(accountToUnlock).catch((e) => null)
+ })
+
+ afterEach(function () {
+ metamaskController.keyringController.addNewAccount.restore()
+ window.open.restore()
+ })
+
+ it('should set accountToUnlock in the keyring', async function () {
const keyrings = await metamaskController.keyringController.getKeyringsByType(
'Trezor Hardware'
)
assert.equal(keyrings[0].unlockedAccount, accountToUnlock)
})
+
+
+ it('should call keyringController.addNewAccount', async function () {
+ assert(metamaskController.keyringController.addNewAccount.calledOnce)
+ })
+
+ it('should call keyringController.getAccounts ', async function () {
+ assert(metamaskController.keyringController.getAccounts.called)
+ })
+
+ it('should call preferencesController.setAddresses', async function () {
+ assert(metamaskController.preferencesController.setAddresses.calledOnce)
+ })
+
+ it('should call preferencesController.setSelectedAddress', async function () {
+ assert(metamaskController.preferencesController.setSelectedAddress.calledOnce)
+ })
+
+ it('should call preferencesController.setAccountLabel', async function () {
+ assert(metamaskController.preferencesController.setAccountLabel.calledOnce)
+ })
+
+
})
describe('#setCustomRpc', function () {