1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 10:30:04 +01:00
metamask-extension/test/unit/config-manager-test.js

116 lines
3.4 KiB
JavaScript
Raw Normal View History

2017-01-10 21:39:01 +01:00
// polyfill fetch
global.fetch = global.fetch || require('isomorphic-fetch')
const assert = require('assert')
2017-01-10 21:39:01 +01:00
const configManagerGen = require('../lib/mock-config-manager')
2017-05-04 23:35:10 +02:00
describe('config-manager', function () {
2016-12-16 20:58:15 +01:00
var configManager
2017-05-04 23:35:10 +02:00
beforeEach(function () {
2016-06-25 01:13:27 +02:00
configManager = configManagerGen()
})
2017-05-04 23:35:10 +02:00
describe('#setConfig', function () {
it('should set the config key', function () {
var testConfig = {
provider: {
type: 'rpc',
2017-05-04 23:35:10 +02:00
rpcTarget: 'foobar',
},
}
configManager.setConfig(testConfig)
var result = configManager.getData()
assert.equal(result.config.provider.type, testConfig.provider.type)
assert.equal(result.config.provider.rpcTarget, testConfig.provider.rpcTarget)
})
2017-05-04 23:35:10 +02:00
it('setting wallet should not overwrite config', function () {
var testConfig = {
provider: {
type: 'rpc',
2017-05-04 23:35:10 +02:00
rpcTarget: 'foobar',
},
}
configManager.setConfig(testConfig)
var testWallet = {
2017-05-04 23:35:10 +02:00
name: 'this is my fake wallet',
}
configManager.setWallet(testWallet)
var result = configManager.getData()
assert.equal(result.wallet.name, testWallet.name, 'wallet name is set')
assert.equal(result.config.provider.rpcTarget, testConfig.provider.rpcTarget)
testConfig.provider.type = 'something else!'
configManager.setConfig(testConfig)
result = configManager.getData()
assert.equal(result.wallet.name, testWallet.name, 'wallet name is set')
assert.equal(result.config.provider.rpcTarget, testConfig.provider.rpcTarget)
assert.equal(result.config.provider.type, testConfig.provider.type)
})
})
2017-05-04 23:35:10 +02:00
describe('wallet nicknames', function () {
it('should return null when no nicknames are saved', function () {
var nick = configManager.nicknameForWallet('0x0')
assert.equal(nick, null, 'no nickname returned')
})
2017-05-04 23:35:10 +02:00
it('should persist nicknames', function () {
var account = '0x0'
var nick1 = 'foo'
var nick2 = 'bar'
configManager.setNicknameForWallet(account, nick1)
var result1 = configManager.nicknameForWallet(account)
assert.equal(result1, nick1)
configManager.setNicknameForWallet(account, nick2)
var result2 = configManager.nicknameForWallet(account)
assert.equal(result2, nick2)
})
})
2017-05-04 23:35:10 +02:00
describe('rpc manipulations', function () {
it('changing rpc should return a different rpc', function () {
var firstRpc = 'first'
var secondRpc = 'second'
configManager.setRpcTarget(firstRpc)
var firstResult = configManager.getCurrentRpcAddress()
assert.equal(firstResult, firstRpc)
configManager.setRpcTarget(secondRpc)
var secondResult = configManager.getCurrentRpcAddress()
assert.equal(secondResult, secondRpc)
})
})
2017-05-04 23:35:10 +02:00
describe('transactions', function () {
beforeEach(function () {
configManager.setTxList([])
})
2017-05-04 23:35:10 +02:00
describe('#getTxList', function () {
it('when new should return empty array', function () {
var result = configManager.getTxList()
assert.ok(Array.isArray(result))
assert.equal(result.length, 0)
})
})
2017-05-04 23:35:10 +02:00
describe('#setTxList', function () {
it('saves the submitted data to the tx list', function () {
var target = [{ foo: 'bar' }]
configManager.setTxList(target)
var result = configManager.getTxList()
assert.equal(result[0].foo, 'bar')
})
})
})
})