mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-10-22 19:26:13 +02:00
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
const assert = require('assert')
|
|
const sinon = require('sinon')
|
|
const clone = require('clone')
|
|
const MetaMaskController = require('../../app/scripts/metamask-controller')
|
|
const firstTimeState = require('../../app/scripts/first-time-state')
|
|
|
|
describe('MetaMaskController', function () {
|
|
const noop = () => {}
|
|
const metamaskController = new MetaMaskController({
|
|
showUnconfirmedMessage: noop,
|
|
unlockAccountMessage: noop,
|
|
showUnapprovedTx: noop,
|
|
platform: {},
|
|
// initial state
|
|
initState: clone(firstTimeState),
|
|
})
|
|
|
|
beforeEach(function () {
|
|
// sinon allows stubbing methods that are easily verified
|
|
this.sinon = sinon.sandbox.create()
|
|
})
|
|
|
|
afterEach(function () {
|
|
// sinon requires cleanup otherwise it will overwrite context
|
|
this.sinon.restore()
|
|
})
|
|
|
|
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()
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|