Skip to content

Commit

Permalink
added tests for removeAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobar79 committed Jul 17, 2018
1 parent de4265c commit e89350b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 0 additions & 2 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,10 +629,8 @@ module.exports = class MetamaskController extends EventEmitter {
const keyState = await keyringController.addNewAccount(keyring)
const newAccounts = await keyringController.getAccounts()
this.preferencesController.setAddresses(newAccounts)
console.log('new vs old', newAccounts, oldAccounts)
newAccounts.forEach(address => {
if (!oldAccounts.includes(address)) {
console.log('new address found', address)
this.preferencesController.setAccountLabel(address, `TREZOR #${parseInt(index, 10) + 1}`)
this.preferencesController.setSelectedAddress(address)
}
Expand Down
33 changes: 33 additions & 0 deletions test/unit/app/controllers/metamask-controller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,39 @@ describe('MetaMaskController', function () {
})
})

describe('#removeAccount', function () {
let ret
const addressToRemove = '0x1'

beforeEach(async function () {
sinon.stub(metamaskController.preferencesController, 'removeAddress')
sinon.stub(metamaskController.accountTracker, 'removeAccount')
sinon.stub(metamaskController.keyringController, 'removeAccount')

ret = await metamaskController.removeAccount(addressToRemove)

})

afterEach(function () {
metamaskController.keyringController.removeAccount.restore()
metamaskController.accountTracker.removeAccount.restore()
metamaskController.preferencesController.removeAddress.restore()
})

it('should call preferencesController.removeAddress', async function () {
assert(metamaskController.preferencesController.removeAddress.calledWith(addressToRemove))
})
it('should call accountTracker.removeAccount', async function () {
assert(metamaskController.accountTracker.removeAccount.calledWith(addressToRemove))
})
it('should call keyringController.removeAccount', async function () {
assert(metamaskController.keyringController.removeAccount.calledWith(addressToRemove))
})
it('should return address', async function () {
assert.equal(ret, '0x1')
})
})

describe('#clearSeedWordCache', function () {

it('should have set seed words', function () {
Expand Down

0 comments on commit e89350b

Please sign in to comment.