diff options
Merge pull request #204 from MetaMask/dev
Merge UI redesign into master
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/actions/restore_vault_test.js | 8 | ||||
-rw-r--r-- | test/unit/actions/save_account_label_test.js | 36 | ||||
-rw-r--r-- | test/unit/actions/set_selected_account_test.js | 21 | ||||
-rw-r--r-- | test/unit/config-manager-test.js | 21 | ||||
-rw-r--r-- | test/unit/util_test.js | 68 |
5 files changed, 153 insertions, 1 deletions
diff --git a/test/unit/actions/restore_vault_test.js b/test/unit/actions/restore_vault_test.js index 5675028b1..609f5429e 100644 --- a/test/unit/actions/restore_vault_test.js +++ b/test/unit/actions/restore_vault_test.js @@ -21,7 +21,13 @@ describe('#recoverFromSeed(password, seed)', function() { // stub out account manager actions._setAccountManager({ - recoverFromSeed(pw, seed, cb) { cb(null, [{}, {}]) }, + recoverFromSeed(pw, seed, cb) { + cb(null, { + identities: { + foo: 'bar' + } + }) + }, }) it('sets metamask.isUnlocked to true', function() { diff --git a/test/unit/actions/save_account_label_test.js b/test/unit/actions/save_account_label_test.js new file mode 100644 index 000000000..1df428b1d --- /dev/null +++ b/test/unit/actions/save_account_label_test.js @@ -0,0 +1,36 @@ +var jsdom = require('mocha-jsdom') +var assert = require('assert') +var freeze = require('deep-freeze-strict') +var path = require('path') + +var actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js')) +var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js')) + +describe('SAVE_ACCOUNT_LABEL', function() { + + it('updates the state.metamask.identities[:i].name property of the state to the action.value.label', function() { + var initialState = { + metamask: { + identities: { + foo: { + name: 'bar' + } + }, + } + } + freeze(initialState) + + const action = { + type: actions.SAVE_ACCOUNT_LABEL, + value: { + account: 'foo', + label: 'baz' + }, + } + freeze(action) + + var resultingState = reducers(initialState, action) + assert.equal(resultingState.metamask.identities.foo.name, action.value.label) + }); +}); + diff --git a/test/unit/actions/set_selected_account_test.js b/test/unit/actions/set_selected_account_test.js index 0487bc5f0..69eb11e47 100644 --- a/test/unit/actions/set_selected_account_test.js +++ b/test/unit/actions/set_selected_account_test.js @@ -26,3 +26,24 @@ describe('SET_SELECTED_ACCOUNT', function() { assert.equal(resultingState.appState.activeAddress, action.value) }); }); + +describe('SHOW_ACCOUNT_DETAIL', function() { + it('updates metamask state', function() { + var initialState = { + metamask: { + selectedAccount: 'foo' + } + } + freeze(initialState) + + const action = { + type: actions.SHOW_ACCOUNT_DETAIL, + value: 'bar', + } + freeze(action) + + var resultingState = reducers(initialState, action) + assert.equal(resultingState.metamask.selectedAccount, action.value) + assert.equal(resultingState.metamask.selectedAddress, action.value) + }) +}) diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index e414ecb9e..aa94dc385 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -54,6 +54,27 @@ describe('config-manager', function() { }) }) + 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') + }) + + 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) + }) + }) + describe('rpc manipulations', function() { it('changing rpc should return a different rpc', function() { var firstRpc = 'first' diff --git a/test/unit/util_test.js b/test/unit/util_test.js index 3f46d4e9b..b091d5bc7 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -17,6 +17,53 @@ describe('util', function() { this.sinon.restore() }) + describe('addressSummary', function() { + it('should add case-sensitive checksum', function() { + var address = '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825' + var result = util.addressSummary(address) + assert.equal(result, '0xFDEa65C8...b825') + }) + }) + + describe('isValidAddress', function() { + it('should allow 40-char non-prefixed hex', function() { + var address = 'fdea65c8e26263f6d9a1b5de9555d2931a33b825' + var result = util.isValidAddress(address) + assert.ok(result) + }) + + it('should allow 42-char non-prefixed hex', function() { + var address = '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825' + var result = util.isValidAddress(address) + assert.ok(result) + }) + + it('should not allow less non hex-prefixed', function() { + var address = 'fdea65c8e26263f6d9a1b5de9555d2931a33b85' + var result = util.isValidAddress(address) + assert.ok(!result) + }) + + it('should not allow less hex-prefixed', function() { + var address = '0xfdea65ce26263f6d9a1b5de9555d2931a33b85' + var result = util.isValidAddress(address) + assert.ok(!result) + }) + + it('should recognize correct capitalized checksum', function() { + var address = '0xFDEa65C8e26263F6d9A1B5de9555D2931A33b825' + var result = util.isValidAddress(address) + assert.ok(result) + }) + + it('should recognize incorrect capitalized checksum', function() { + var address = '0xFDea65C8e26263F6d9A1B5de9555D2931A33b825' + var result = util.isValidAddress(address) + assert.ok(!result) + }) + + }) + describe('numericBalance', function() { it('should return a BN 0 if given nothing', function() { @@ -112,8 +159,29 @@ describe('util', function() { }) }) + describe('normalizeEthStringToWei', function() { + it('should convert decimal eth to pure wei BN', function() { + var input = '1.23456789' + var output = util.normalizeEthStringToWei(input) + assert.equal(output.toString(10), '1234567890000000000') + }) + + it('should convert 1 to expected wei', function() { + var input = '1' + var output = util.normalizeEthStringToWei(input) + assert.equal(output.toString(10), ethInWei) + }) + }) + describe('#normalizeNumberToWei', function() { + it('should handle a simple use case', function() { + var input = 0.0002 + var output = util.normalizeNumberToWei(input, 'ether') + var str = output.toString(10) + assert.equal(str, '200000000000000') + }) + it('should convert a kwei number to the appropriate equivalent wei', function() { var result = util.normalizeNumberToWei(1.111, 'kwei') assert.equal(result.toString(10), '1111', 'accepts decimals') |