aboutsummaryrefslogtreecommitdiffstats
path: root/test/index.js
blob: 5a8df78b846bbbf37d05c36fc4006f864c8bb5aa (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
var assert = require('assert')
var IdentityStore = require('../app/scripts/lib/idStore')
var jsdom = require('mocha-jsdom')
jsdom()

describe('IdentityStore', function() {

  describe('#createNewVault', function () {
    let idStore
    let password = 'password123'
    let entropy = 'entripppppyy duuude'
    let seedWords
    let accounts = []
    let originalKeystore

    before(function(done) {
      window.localStorage = {} // Hacking localStorage support into JSDom

      idStore = new IdentityStore({
        addAccount(acct) { accounts.push(acct) },
      })

      idStore.createNewVault(password, entropy, (err, seeds) => {
        seedWords = seeds
        originalKeystore = idStore._idmgmt.keyStore
        done()
      })
    })

    describe('#recoverFromSeed', function() {

      before(function() {
        window.localStorage = {} // Hacking localStorage support into JSDom
        accounts = []

        idStore = new IdentityStore({
          addAccount(acct) { accounts.push(acct) },
        })
      })

      it('should return the expected keystore', function () {

        idStore.recoverFromSeed(password, seedWords, (err) => {
          assert.ifError(err)

          let newKeystore = idStore._idmgmt.keyStore
          assert.equal(newKeystore, originalKeystore)
        })
      })
    })
  })
})