1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 11:01:41 +01:00
metamask-extension/test/unit/address-book-controller.js

55 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-03-10 18:52:05 +01:00
const assert = require('assert')
const AddressBookController = require('../../app/scripts/controllers/address-book')
const mockKeyringController = {
memStore: {
getState: function () {
return {
identities: {
2017-05-04 23:35:10 +02:00
'0x0aaa': {
address: '0x0aaa',
name: 'owned',
2017-05-04 23:35:10 +02:00
},
},
}
2017-05-04 23:35:10 +02:00
},
},
}
2017-05-04 23:35:10 +02:00
describe('address-book-controller', function () {
2017-03-10 18:52:05 +01:00
var addressBookController
2017-05-04 23:35:10 +02:00
beforeEach(function () {
addressBookController = new AddressBookController({}, mockKeyringController)
2017-03-10 18:52:05 +01:00
})
describe('addres book management', function () {
describe('#_getAddressBook', function () {
it('should be empty by default.', function () {
assert.equal(addressBookController._getAddressBook().length, 0)
})
})
describe('#setAddressBook', function () {
it('should properly set a new address.', function () {
addressBookController.setAddressBook('0x01234', 'test')
var addressBook = addressBookController._getAddressBook()
assert.equal(addressBook.length, 1, 'incorrect address book length.')
assert.equal(addressBook[0].address, '0x01234', 'incorrect addresss')
assert.equal(addressBook[0].name, 'test', 'incorrect nickname')
})
2017-03-10 19:34:18 +01:00
it('should reject duplicates.', function () {
addressBookController.setAddressBook('0x01234', 'test')
addressBookController.setAddressBook('0x01234', 'test')
var addressBook = addressBookController._getAddressBook()
assert.equal(addressBook.length, 1, 'incorrect address book length.')
})
it('should not add any identities that are under user control', function () {
addressBookController.setAddressBook('0x0aaa', ' ')
var addressBook = addressBookController._getAddressBook()
assert.equal(addressBook.length, 0, 'incorrect address book length.')
})
2017-03-10 18:52:05 +01:00
})
})
})