From 041b5493dc43c9f8b69dc5a1dde4b319638618a7 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 13 May 2016 01:13:14 -0700 Subject: Streamlined some transition logic Fixes #122 Had used multiple actions for some transitions, which would lead to brief intermediary states. Now making a few actions much more explicit about what they route to, so there is less intermediary logic, and we can transition confidently to the correct view. --- test/unit/actions/restore_vault_test.js | 8 +++++++- test/unit/actions/set_selected_account_test.js | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'test') 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/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) + }) +}) -- cgit v1.2.3 From c8deb355f7d1e4d1e10868a7d960fa460a7c51db Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 19 May 2016 12:06:45 -0700 Subject: Add address capitalization checksumming --- test/unit/util_test.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'test') diff --git a/test/unit/util_test.js b/test/unit/util_test.js index 3f46d4e9b..020fad783 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -17,6 +17,52 @@ 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() { -- cgit v1.2.3 From 22a77b80411350bd844313b51ea58312940b9738 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 19 May 2016 14:21:35 -0700 Subject: Increase send value precision --- test/unit/util_test.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/unit/util_test.js b/test/unit/util_test.js index 020fad783..5f28dbb25 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -61,6 +61,7 @@ describe('util', function() { var result = util.isValidAddress(address) assert.ok(!result) }) + }) describe('numericBalance', function() { @@ -160,6 +161,13 @@ describe('util', function() { 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') -- cgit v1.2.3 From 60270de53d214edffad7b90356bbe06081a55443 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 19 May 2016 14:46:50 -0700 Subject: Add full precision to send tx value field. --- test/unit/util_test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test') diff --git a/test/unit/util_test.js b/test/unit/util_test.js index 5f28dbb25..b091d5bc7 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -159,6 +159,20 @@ 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() { -- cgit v1.2.3 From 95a3cfe3fcffee2ffabd4cf71e568ae94693b10f Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 20 May 2016 16:18:54 -0700 Subject: Added ability to nickname wallets locally The changes are persisted to localstorage, so they cannot be restored on a new computer, but for right now it's a nice organizational feature. --- test/unit/actions/save_account_label_test.js | 36 ++++++++++++++++++++++++++++ test/unit/config-manager-test.js | 21 ++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 test/unit/actions/save_account_label_test.js (limited to 'test') 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/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' -- cgit v1.2.3