aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/actions/restore_vault_test.js
blob: 609f5429e415b422ac7c0f992790dbee8f176b3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var jsdom = require('mocha-jsdom')
var assert = require('assert')
var freeze = require('deep-freeze-strict')
var path = require('path')
var sinon = require('sinon')

var actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js'))
var reducers = require(path.join(__dirname, '..', '..',  '..', 'ui', 'app', 'reducers.js'))

describe('#recoverFromSeed(password, seed)', function() {

  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()
  })

  // stub out account manager
  actions._setAccountManager({
    recoverFromSeed(pw, seed, cb) {
      cb(null, {
        identities: {
          foo: 'bar'
        }
      })
    },
  })

  it('sets metamask.isUnlocked to true', function() {
    var initialState = {
      metamask: {
        isUnlocked: false,
        isInitialized: false,
      }
    }
    freeze(initialState)

    const restorePhrase = 'invite heavy among daring outdoor dice jelly coil stable note seat vicious'
    const password = 'foo'
    const dispatchFunc = actions.recoverFromSeed(password, restorePhrase)

    var dispatchStub = this.sinon.stub()
    dispatchStub.withArgs({ TYPE: actions.unlockMetamask() }).onCall(0)
    dispatchStub.withArgs({ TYPE: actions.showAccountsPage() }).onCall(1)

    var action
    var resultingState = initialState
    dispatchFunc((newAction) => {
      action = newAction
      resultingState = reducers(resultingState, action)
    })

    assert.equal(resultingState.metamask.isUnlocked, true, 'was unlocked')
    assert.equal(resultingState.metamask.isInitialized, true, 'was initialized')
  });
});