A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/test/unit/ui/app/reducers/metamask.spec.js

397 lines
9.1 KiB

6 years ago
import assert from 'assert'
import reduceMetamask from '../../../../../ui/app/ducks/metamask/metamask'
import { actionConstants as actions } from '../../../../../ui/app/store/actions'
6 years ago
6 years ago
describe('MetaMask Reducers', () => {
6 years ago
it('init state', () => {
const initState = reduceMetamask(undefined, {})
6 years ago
assert(initState)
})
it('unlocks MetaMask', () => {
const state = reduceMetamask({}, {
6 years ago
type: actions.UNLOCK_METAMASK,
value: 'test address',
})
assert.equal(state.isUnlocked, true)
assert.equal(state.isInitialized, true)
assert.equal(state.selectedAddress, 'test address')
6 years ago
})
it('locks MetaMask', () => {
const unlockMetaMaskState = {
isUnlocked: true,
isInitialzed: false,
selectedAddress: 'test address',
}
6 years ago
const lockMetaMask = reduceMetamask(unlockMetaMaskState, {
type: actions.LOCK_METAMASK,
})
assert.equal(lockMetaMask.isUnlocked, false)
})
it('sets rpc target', () => {
const state = reduceMetamask({}, {
type: actions.SET_RPC_TARGET,
value: 'https://custom.rpc',
})
assert.equal(state.provider.rpcTarget, 'https://custom.rpc')
})
it('sets provider type', () => {
const state = reduceMetamask({}, {
type: actions.SET_PROVIDER_TYPE,
value: 'provider type',
})
assert.equal(state.provider.type, 'provider type')
})
it('shows account detail', () => {
const state = reduceMetamask({}, {
6 years ago
type: actions.SHOW_ACCOUNT_DETAIL,
value: 'test address',
})
assert.equal(state.isUnlocked, true)
assert.equal(state.isInitialized, true)
assert.equal(state.selectedAddress, 'test address')
})
it('sets select ', () => {
const state = reduceMetamask({}, {
type: actions.SET_SELECTED_TOKEN,
value: 'test token',
})
assert.equal(state.selectedTokenAddress, 'test token')
})
it('sets account label', () => {
const state = reduceMetamask({}, {
type: actions.SET_ACCOUNT_LABEL,
value: {
account: 'test account',
label: 'test label',
},
})
assert.deepEqual(state.identities, { 'test account': { name: 'test label' } })
})
it('sets current fiat', () => {
const value = {
currentCurrency: 'yen',
conversionRate: 3.14,
conversionDate: new Date(2018, 9),
}
const state = reduceMetamask({}, {
type: actions.SET_CURRENT_FIAT,
value,
})
assert.equal(state.currentCurrency, value.currentCurrency)
assert.equal(state.conversionRate, value.conversionRate)
assert.equal(state.conversionDate, value.conversionDate)
})
it('updates tokens', () => {
const newTokens = {
'address': '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
'decimals': 18,
'symbol': 'META',
}
const state = reduceMetamask({}, {
type: actions.UPDATE_TOKENS,
newTokens,
})
assert.deepEqual(state.tokens, newTokens)
})
it('updates send gas limit', () => {
const state = reduceMetamask({}, {
type: actions.UPDATE_GAS_LIMIT,
value: '0xGasLimit',
})
assert.equal(state.send.gasLimit, '0xGasLimit')
})
it('updates send gas price', () => {
const state = reduceMetamask({}, {
type: actions.UPDATE_GAS_PRICE,
value: '0xGasPrice',
})
assert.equal(state.send.gasPrice, '0xGasPrice')
})
it('toggles account menu ', () => {
const state = reduceMetamask({}, {
type: actions.TOGGLE_ACCOUNT_MENU,
})
assert.equal(state.isAccountMenuOpen, true)
})
it('updates gas total', () => {
const state = reduceMetamask({}, {
type: actions.UPDATE_GAS_TOTAL,
value: '0xGasTotal',
})
assert.equal(state.send.gasTotal, '0xGasTotal')
})
it('updates send token balance', () => {
const state = reduceMetamask({}, {
type: actions.UPDATE_SEND_TOKEN_BALANCE,
value: '0xTokenBalance',
})
assert.equal(state.send.tokenBalance, '0xTokenBalance')
})
it('updates data', () => {
const state = reduceMetamask({}, {
type: actions.UPDATE_SEND_HEX_DATA,
value: '0xData',
})
assert.equal(state.send.data, '0xData')
})
it('updates send to', () => {
const state = reduceMetamask({}, {
type: actions.UPDATE_SEND_TO,
value: {
to: '0xAddress',
nickname: 'nickname',
},
})
assert.equal(state.send.to, '0xAddress')
assert.equal(state.send.toNickname, 'nickname')
})
it('update send amount', () => {
const state = reduceMetamask({}, {
type: actions.UPDATE_SEND_AMOUNT,
value: '0xAmount',
})
assert.equal(state.send.amount, '0xAmount')
})
it('updates max mode', () => {
const state = reduceMetamask({}, {
type: actions.UPDATE_MAX_MODE,
value: true,
})
assert.equal(state.send.maxModeOn, true)
})
it('update send', () => {
const value = {
gasLimit: '0xGasLimit',
gasPrice: '0xGasPrice',
gasTotal: '0xGasTotal',
tokenBalance: '0xBalance',
from: '0xAddress',
to: '0xAddress',
toNickname: '',
maxModeOn: false,
amount: '0xAmount',
memo: '0xMemo',
errors: {},
editingTransactionId: 22,
forceGasMin: '0xGas',
Address book send plus contact list (#6914) * Style Send Header * Move Send to-row to send view and restyle * Add "Recents" group to select recipient view * Rename SendToRow to AddRecipient * Basic UI and Layout * New ENSInput component * wip - fuzzy search for input * small refactor * Add Dialog * contact list initial * initial error on invalid address * clean up edit * Click to open modal * Create AddToAddressBookModal component * Modal styling and layout * modal i18n * Add to Addressbook * ens wip * ens wip * ENS Resolution * Reset input * Send to explicit address * Happy Path Complete * Add back error checking * Reset send-to when emptying input * Add back warning object * Fix linter * Fix unit test #1 - fix import paths * Remove dead tests * One more to go * Fix all unit tests * add unit test for reducers and actions * test rendering AddRecipient * Add tests for dialog boxes in AddRecipient * Add test for validating * Fix linter * Fix e2e tests * Token send e2e fix * Style View Contact * Style edit-contact * Fix e2e * Fix from-import-beta-ui e2e spec * Make section header say "add recipient” by default * Auto-focus add recipient input * Update placeholder text * Update input title font size * Auto advance to next step if user paste a valid address * Ellipsify address when recipient is selected * Fix app header background color on desktop * Give each form row a margin of 16px * Use .container/.component naming pattern for ens-input * Auto-focus on input when add to addressbook modal is opened; Save on Enter * Fix and add unit test * Fix selectors name in e2e tests * Correct e2e test token amount for address-book-send changes * Adds e2e test for editing a transaction * Delete test/integration/lib/send-new-ui.js * Add tests for amount max button and high value error on send screen to test/e2e/metamask-ui.spec.js * lint and revert to address as object keys * add chainId based on current network to address book entry * fix test * only display contacts for the current network * Improve ENS message when not found on current network * Add error to indicate when network does not support ENS * bump gaba * address book, resolve comments * Move contact-list to its own component * De-duplicate getaddressbook selector and refactor name selection logic in contact-list-tab/ * Use contact-list component in contact-list-tab.component (i.e. in settings) * Improve/fix settings headers for popup and browser views * Lint fixes related to address book updates * Add 'My accounts' page to settings address book * Update add new contact button in settings to match floating circular design * Improve styles of view contact page * Improve styles and labels of the add-contact.component * Further lint fixes related to address book updates * Update unit tests as per address book updates * Ensure that contact list groups are sorted alphabetically * Refactor settings component to use a container for connection to redux; allow display of addressbook name in settings header * Decouple ens-input.component from send context * Add ens resolution to add contact screen in settings * Switching networks when an ens address is shown on send form removes the ens address. * Resolve send screen search for ensAddress to matching address book entry if it exists * Show resolved ens icon and address if exists (settings: add-contact.component) * Make the displayed and copied address in view-contact.component the checksummed address * Default alias state prop in AddToAddressBookModal to empty string * Use keyCode to detect enter key in AddToAddressBookModal * Ensure add-contact component properly updates after QR code detection * Fix display of all recents after clicking 'Load More' in contact list * Fix send screen contact searching after network switching * Code cleanup related to address book changes * Update unit tests for address book changes * Update ENS name not found on network message * Add ens registration error message * Cancel on edit mode takes user back to view screen * Adds support for memo to settings contact list view and edit screens * Modify designs of edit and view contact in popup environment * Update settings content list UX to show split columns in fullscreen and proper internal navigation * Correct background address book API usages in UI
5 years ago
ensResolution: null,
ensResolutionError: '',
6 years ago
}
const sendState = reduceMetamask({}, {
6 years ago
type: actions.UPDATE_SEND,
value,
})
assert.deepEqual(sendState.send, value)
})
it('clears send', () => {
const initStateSend = {
send:
{ gasLimit: null,
gasPrice: null,
gasTotal: null,
tokenBalance: null,
from: '',
to: '',
amount: '0x0',
memo: '',
errors: {},
maxModeOn: false,
editingTransactionId: null,
forceGasMin: null,
toNickname: '' },
}
const sendState = {
send: {
gasLimit: '0xGasLimit',
gasPrice: '0xGasPrice',
gasTotal: '0xGasTotal',
tokenBalance: '0xBalance',
from: '0xAddress',
to: '0xAddress',
toNickname: '',
maxModeOn: false,
amount: '0xAmount',
memo: '0xMemo',
errors: {},
editingTransactionId: 22,
forceGasMin: '0xGas',
},
}
6 years ago
const state = reduceMetamask(sendState, {
type: actions.CLEAR_SEND,
})
assert.deepEqual(state.send, initStateSend.send)
6 years ago
})
it('updates value of tx by id', () => {
const oldState = {
selectedAddressTxList: [
{
id: 1,
txParams: 'foo',
},
],
6 years ago
}
const state = reduceMetamask(oldState, {
type: actions.UPDATE_TRANSACTION_PARAMS,
id: 1,
value: 'bar',
})
assert.equal(state.selectedAddressTxList[0].txParams, 'bar')
})
it('updates pair for shapeshift', () => {
const state = reduceMetamask({}, {
type: actions.PAIR_UPDATE,
value: {
marketinfo: {
pair: 'test pair',
foo: 'bar',
},
},
})
assert.equal(state.tokenExchangeRates['test pair'].pair, 'test pair')
})
it('sets blockies', () => {
const state = reduceMetamask({}, {
type: actions.SET_USE_BLOCKIE,
value: true,
})
assert.equal(state.useBlockie, true)
})
it('updates an arbitrary feature flag', () => {
6 years ago
const state = reduceMetamask({}, {
type: actions.UPDATE_FEATURE_FLAGS,
value: {
foo: true,
6 years ago
},
})
assert.equal(state.featureFlags.foo, true)
6 years ago
})
it('close welcome screen', () => {
const state = reduceMetamask({}, {
type: actions.CLOSE_WELCOME_SCREEN,
})
assert.equal(state.welcomeScreenSeen, true)
})
it('sets current locale', () => {
const state = reduceMetamask({}, {
type: actions.SET_CURRENT_LOCALE,
value: { locale: 'ge' },
6 years ago
})
assert.equal(state.currentLocale, 'ge')
})
it('sets pending tokens ', () => {
const payload = {
'address': '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
'decimals': 18,
'symbol': 'META',
}
const pendingTokensState = reduceMetamask({}, {
6 years ago
type: actions.SET_PENDING_TOKENS,
payload,
})
assert.deepEqual(pendingTokensState.pendingTokens, payload)
})
it('clears pending tokens', () => {
const payload = {
'address': '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
'decimals': 18,
'symbol': 'META',
}
const pendingTokensState = {
pendingTokens: payload,
}
6 years ago
const state = reduceMetamask(pendingTokensState, {
type: actions.CLEAR_PENDING_TOKENS,
})
assert.deepEqual(state.pendingTokens, {})
})
Address book send plus contact list (#6914) * Style Send Header * Move Send to-row to send view and restyle * Add "Recents" group to select recipient view * Rename SendToRow to AddRecipient * Basic UI and Layout * New ENSInput component * wip - fuzzy search for input * small refactor * Add Dialog * contact list initial * initial error on invalid address * clean up edit * Click to open modal * Create AddToAddressBookModal component * Modal styling and layout * modal i18n * Add to Addressbook * ens wip * ens wip * ENS Resolution * Reset input * Send to explicit address * Happy Path Complete * Add back error checking * Reset send-to when emptying input * Add back warning object * Fix linter * Fix unit test #1 - fix import paths * Remove dead tests * One more to go * Fix all unit tests * add unit test for reducers and actions * test rendering AddRecipient * Add tests for dialog boxes in AddRecipient * Add test for validating * Fix linter * Fix e2e tests * Token send e2e fix * Style View Contact * Style edit-contact * Fix e2e * Fix from-import-beta-ui e2e spec * Make section header say "add recipient” by default * Auto-focus add recipient input * Update placeholder text * Update input title font size * Auto advance to next step if user paste a valid address * Ellipsify address when recipient is selected * Fix app header background color on desktop * Give each form row a margin of 16px * Use .container/.component naming pattern for ens-input * Auto-focus on input when add to addressbook modal is opened; Save on Enter * Fix and add unit test * Fix selectors name in e2e tests * Correct e2e test token amount for address-book-send changes * Adds e2e test for editing a transaction * Delete test/integration/lib/send-new-ui.js * Add tests for amount max button and high value error on send screen to test/e2e/metamask-ui.spec.js * lint and revert to address as object keys * add chainId based on current network to address book entry * fix test * only display contacts for the current network * Improve ENS message when not found on current network * Add error to indicate when network does not support ENS * bump gaba * address book, resolve comments * Move contact-list to its own component * De-duplicate getaddressbook selector and refactor name selection logic in contact-list-tab/ * Use contact-list component in contact-list-tab.component (i.e. in settings) * Improve/fix settings headers for popup and browser views * Lint fixes related to address book updates * Add 'My accounts' page to settings address book * Update add new contact button in settings to match floating circular design * Improve styles of view contact page * Improve styles and labels of the add-contact.component * Further lint fixes related to address book updates * Update unit tests as per address book updates * Ensure that contact list groups are sorted alphabetically * Refactor settings component to use a container for connection to redux; allow display of addressbook name in settings header * Decouple ens-input.component from send context * Add ens resolution to add contact screen in settings * Switching networks when an ens address is shown on send form removes the ens address. * Resolve send screen search for ensAddress to matching address book entry if it exists * Show resolved ens icon and address if exists (settings: add-contact.component) * Make the displayed and copied address in view-contact.component the checksummed address * Default alias state prop in AddToAddressBookModal to empty string * Use keyCode to detect enter key in AddToAddressBookModal * Ensure add-contact component properly updates after QR code detection * Fix display of all recents after clicking 'Load More' in contact list * Fix send screen contact searching after network switching * Code cleanup related to address book changes * Update unit tests for address book changes * Update ENS name not found on network message * Add ens registration error message * Cancel on edit mode takes user back to view screen * Adds support for memo to settings contact list view and edit screens * Modify designs of edit and view contact in popup environment * Update settings content list UX to show split columns in fullscreen and proper internal navigation * Correct background address book API usages in UI
5 years ago
it('update ensResolution', () => {
const state = reduceMetamask({}, {
type: actions.UPDATE_SEND_ENS_RESOLUTION,
payload: '0x1337',
})
assert.deepEqual(state.send.ensResolution, '0x1337')
assert.deepEqual(state.send.ensResolutionError, '')
})
it('update ensResolutionError', () => {
const state = reduceMetamask({}, {
type: actions.UPDATE_SEND_ENS_RESOLUTION_ERROR,
payload: 'ens name not found',
})
assert.deepEqual(state.send.ensResolutionError, 'ens name not found')
assert.deepEqual(state.send.ensResolution, null)
})
6 years ago
})