aboutsummaryrefslogtreecommitdiffstats
path: root/test/lib/mock-simple-keychain.js
blob: d3addc3e8a3d0d07ad177d52345fbd1a53f26b4f (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
var fakeWallet = {
  privKey: '0x123456788890abcdef',
  address: '0xfedcba0987654321',
}
const type = 'Simple Key Pair'

module.exports = class MockSimpleKeychain {

  static type () { return type }

  constructor (opts) {
    this.type = type
    this.opts = opts || {}
    this.wallets = []
  }

  serialize () {
    return [ fakeWallet.privKey ]
  }

  deserialize (data) {
    if (!Array.isArray(data)) {
      throw new Error('Simple keychain deserialize requires a privKey array.')
    }
    this.wallets = [ fakeWallet ]
  }

  addAccounts (n = 1) {
    for (var i = 0; i < n; i++) {
      this.wallets.push(fakeWallet)
    }
  }

  getAccounts () {
    return this.wallets.map(w => w.address)
  }

}