mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #3146 from MetaMask/i3082-AddTokenValidateInputs
Set address to default with empty string, add test validation.
This commit is contained in:
commit
1a93b1ade2
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
- Fix provider for Kovan network.
|
- Fix provider for Kovan network.
|
||||||
- Bump limit for EventEmitter listeners before warning.
|
- Bump limit for EventEmitter listeners before warning.
|
||||||
|
- Display Error when empty string is entered as a token address.
|
||||||
|
|
||||||
## 3.13.7 2018-1-22
|
## 3.13.7 2018-1-22
|
||||||
|
|
||||||
|
@ -172,12 +172,14 @@
|
|||||||
"deep-freeze-strict": "^1.1.1",
|
"deep-freeze-strict": "^1.1.1",
|
||||||
"del": "^3.0.0",
|
"del": "^3.0.0",
|
||||||
"envify": "^4.0.0",
|
"envify": "^4.0.0",
|
||||||
"enzyme": "^3.2.0",
|
"enzyme": "^3.3.0",
|
||||||
|
"enzyme-adapter-react-15": "^1.0.5",
|
||||||
"eslint-plugin-chai": "0.0.1",
|
"eslint-plugin-chai": "0.0.1",
|
||||||
"eslint-plugin-mocha": "^4.9.0",
|
"eslint-plugin-mocha": "^4.9.0",
|
||||||
"eth-json-rpc-middleware": "^1.2.7",
|
"eth-json-rpc-middleware": "^1.2.7",
|
||||||
"fs-promise": "^2.0.3",
|
"fs-promise": "^2.0.3",
|
||||||
"gulp": "github:gulpjs/gulp#6d71a658c61edb3090221579d8f97dbe086ba2ed",
|
"gulp": "github:gulpjs/gulp#6d71a658c61edb3090221579d8f97dbe086ba2ed",
|
||||||
|
"gulp-eslint": "^4.0.0",
|
||||||
"gulp-if": "^2.0.1",
|
"gulp-if": "^2.0.1",
|
||||||
"gulp-json-editor": "^2.2.1",
|
"gulp-json-editor": "^2.2.1",
|
||||||
"gulp-livereload": "^3.8.1",
|
"gulp-livereload": "^3.8.1",
|
||||||
@ -186,7 +188,6 @@
|
|||||||
"gulp-util": "^3.0.7",
|
"gulp-util": "^3.0.7",
|
||||||
"gulp-watch": "^5.0.0",
|
"gulp-watch": "^5.0.0",
|
||||||
"gulp-zip": "^4.0.0",
|
"gulp-zip": "^4.0.0",
|
||||||
"gulp-eslint": "^4.0.0",
|
|
||||||
"isomorphic-fetch": "^2.2.1",
|
"isomorphic-fetch": "^2.2.1",
|
||||||
"jsdom": "^11.1.0",
|
"jsdom": "^11.1.0",
|
||||||
"jsdom-global": "^3.0.2",
|
"jsdom-global": "^3.0.2",
|
||||||
@ -210,6 +211,7 @@
|
|||||||
"react-addons-test-utils": "^15.5.1",
|
"react-addons-test-utils": "^15.5.1",
|
||||||
"react-test-renderer": "^15.6.2",
|
"react-test-renderer": "^15.6.2",
|
||||||
"react-testutils-additions": "^15.2.0",
|
"react-testutils-additions": "^15.2.0",
|
||||||
|
"redux-test-utils": "^0.2.2",
|
||||||
"sinon": "^4.0.0",
|
"sinon": "^4.0.0",
|
||||||
"tape": "^4.5.1",
|
"tape": "^4.5.1",
|
||||||
"testem": "^2.0.0",
|
"testem": "^2.0.0",
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
import Enzyme from 'enzyme'
|
||||||
|
import Adapter from 'enzyme-adapter-react-15'
|
||||||
|
|
||||||
|
Enzyme.configure({ adapter: new Adapter() })
|
||||||
// disallow promises from swallowing errors
|
// disallow promises from swallowing errors
|
||||||
enableFailureOnUnhandledPromiseRejection()
|
enableFailureOnUnhandledPromiseRejection()
|
||||||
|
|
||||||
|
20
test/lib/shallow-with-store.js
Normal file
20
test/lib/shallow-with-store.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
const { shallow, mount } = require('enzyme')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
shallowWithStore,
|
||||||
|
mountWithStore,
|
||||||
|
}
|
||||||
|
|
||||||
|
function shallowWithStore (component, store) {
|
||||||
|
const context = {
|
||||||
|
store,
|
||||||
|
}
|
||||||
|
return shallow(component, {context})
|
||||||
|
}
|
||||||
|
|
||||||
|
function mountWithStore (component, store) {
|
||||||
|
const context = {
|
||||||
|
store,
|
||||||
|
}
|
||||||
|
return mount(component, {context})
|
||||||
|
}
|
43
test/unit/ui/add-token.spec.js
Normal file
43
test/unit/ui/add-token.spec.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
const assert = require('assert')
|
||||||
|
const { createMockStore } = require('redux-test-utils')
|
||||||
|
const h = require('react-hyperscript')
|
||||||
|
const { shallowWithStore } = require('../../lib/shallow-with-store')
|
||||||
|
const AddTokenScreen = require('../../../ui/app/add-token')
|
||||||
|
|
||||||
|
describe('Add Token Screen', function () {
|
||||||
|
let addTokenComponent, store, component
|
||||||
|
const mockState = {
|
||||||
|
metamask: {
|
||||||
|
identities: {
|
||||||
|
'0x7d3517b0d011698406d6e0aed8453f0be2697926': {
|
||||||
|
'address': '0x7d3517b0d011698406d6e0aed8453f0be2697926',
|
||||||
|
'name': 'Add Token Name',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
beforeEach(function () {
|
||||||
|
store = createMockStore(mockState)
|
||||||
|
component = shallowWithStore(h(AddTokenScreen), store)
|
||||||
|
addTokenComponent = component.dive()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('#ValidateInputs', function () {
|
||||||
|
|
||||||
|
it('Default State', function () {
|
||||||
|
addTokenComponent.instance().validateInputs()
|
||||||
|
const state = addTokenComponent.state()
|
||||||
|
assert.equal(state.warning, 'Address is invalid.')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Address is a Metamask Identity', function () {
|
||||||
|
addTokenComponent.setState({
|
||||||
|
address: '0x7d3517b0d011698406d6e0aed8453f0be2697926',
|
||||||
|
})
|
||||||
|
addTokenComponent.instance().validateInputs()
|
||||||
|
const state = addTokenComponent.state()
|
||||||
|
assert.equal(state.warning, 'Personal address detected. Input the token contract address.')
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
@ -25,7 +25,7 @@ inherits(AddTokenScreen, Component)
|
|||||||
function AddTokenScreen () {
|
function AddTokenScreen () {
|
||||||
this.state = {
|
this.state = {
|
||||||
warning: null,
|
warning: null,
|
||||||
address: null,
|
address: '',
|
||||||
symbol: 'TOKEN',
|
symbol: 'TOKEN',
|
||||||
decimals: 18,
|
decimals: 18,
|
||||||
}
|
}
|
||||||
@ -190,7 +190,7 @@ AddTokenScreen.prototype.validateInputs = function () {
|
|||||||
|
|
||||||
const validAddress = ethUtil.isValidAddress(address)
|
const validAddress = ethUtil.isValidAddress(address)
|
||||||
if (!validAddress) {
|
if (!validAddress) {
|
||||||
msg += 'Address is invalid. '
|
msg += 'Address is invalid.'
|
||||||
}
|
}
|
||||||
|
|
||||||
const validDecimals = decimals >= 0 && decimals < 36
|
const validDecimals = decimals >= 0 && decimals < 36
|
||||||
|
Loading…
Reference in New Issue
Block a user