1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +01:00

Integration tests for signature requests confirmations. (#3194)

This commit is contained in:
Dan J Miller 2018-02-06 14:50:37 -03:30 committed by Alexander Tseung
parent d452403322
commit a7bfea51e5
5 changed files with 292 additions and 2 deletions

View File

@ -0,0 +1,26 @@
module.exports = {
"confirm sig requests": {
signMessage: (msgData, cb) => {
const stateUpdate = {
unapprovedMsgs: {},
unapprovedMsgCount: 0,
}
return cb(null, stateUpdate)
},
signPersonalMessage: (msgData, cb) => {
const stateUpdate = {
unapprovedPersonalMsgs: {},
unapprovedPersonalMsgsCount: 0,
}
return cb(null, stateUpdate)
},
signTypedMessage: (msgData, cb) => {
const stateUpdate = {
unapprovedTypedMessages: {},
unapprovedTypedMessagesCount: 0,
}
return cb(null, stateUpdate)
},
},
}

View File

@ -11,7 +11,14 @@ function NewComponent () {
NewComponent.prototype.render = function () {
const props = this.props
let { states, selectedKey, actions, store } = props
let {
states,
selectedKey,
actions,
store,
modifyBackgroundConnection,
backGroundConnectionModifiers,
} = props
const state = this.state || {}
const selected = state.selected || selectedKey
@ -23,6 +30,8 @@ NewComponent.prototype.render = function () {
value: selected,
onChange:(event) => {
const selectedKey = event.target.value
const backgroundConnectionModifier = backGroundConnectionModifiers[selectedKey]
modifyBackgroundConnection(backgroundConnectionModifier || {})
store.dispatch(actions.update(selectedKey))
this.setState({ selected: selectedKey })
},

File diff suppressed because one or more lines are too long

View File

@ -20,6 +20,7 @@ const Root = require('./ui/app/root')
const configureStore = require('./ui/app/store')
const actions = require('./ui/app/actions')
const states = require('./development/states')
const backGroundConnectionModifiers = require('./development/backGroundConnectionModifiers')
const Selector = require('./development/selector')
const MetamaskController = require('./app/scripts/metamask-controller')
const firstTimeState = require('./app/scripts/first-time-state')
@ -85,6 +86,11 @@ actions.update = function(stateName) {
}
}
function modifyBackgroundConnection(backgroundConnectionModifier) {
const modifiedBackgroundConnection = Object.assign({}, controller.getApi(), backgroundConnectionModifier)
actions._setBackgroundConnection(modifiedBackgroundConnection)
}
var css = MetaMaskUiCss()
injectCss(css)
@ -113,7 +119,14 @@ function startApp(){
},
}, 'Reset State'),
h(Selector, { actions, selectedKey: selectedView, states, store }),
h(Selector, {
actions,
selectedKey: selectedView,
states,
store,
modifyBackgroundConnection,
backGroundConnectionModifiers,
}),
h('#app-content', {
style: {

View File

@ -0,0 +1,67 @@
const reactTriggerChange = require('react-trigger-change')
const PASSWORD = 'password123'
QUnit.module('confirm sig requests')
QUnit.test('successful confirmation of sig requests', (assert) => {
const done = assert.async()
runConfirmSigRequestsTest(assert).then(done).catch((err) => {
assert.notOk(err, `Error was thrown: ${err.stack}`)
done()
})
})
async function runConfirmSigRequestsTest(assert, done) {
let selectState = $('select')
selectState.val('confirm sig requests')
reactTriggerChange(selectState[0])
await timeout(2000)
let confirmSigHeadline = $('.request-signature__headline')
assert.equal(confirmSigHeadline[0].textContent, 'Your signature is being requested')
let confirmSigRowValue = $('.request-signature__row-value')
assert.ok(confirmSigRowValue[0].textContent.match(/^\#\sTerms\sof\sUse/))
let confirmSigSignButton = $('.request-signature__footer__sign-button')
confirmSigSignButton[0].click()
await timeout(2000)
confirmSigHeadline = $('.request-signature__headline')
assert.equal(confirmSigHeadline[0].textContent, 'Your signature is being requested')
let confirmSigMessage = $('.request-signature__notice')
assert.ok(confirmSigMessage[0].textContent.match(/^Signing\sthis\smessage/))
confirmSigRowValue = $('.request-signature__row-value')
assert.equal(confirmSigRowValue[0].textContent, '0x879a053d4800c6354e76c7985a865d2922c82fb5b3f4577b2fe08b998954f2e0')
confirmSigSignButton = $('.request-signature__footer__sign-button')
confirmSigSignButton[0].click()
await timeout(2000)
confirmSigHeadline = $('.request-signature__headline')
assert.equal(confirmSigHeadline[0].textContent, 'Your signature is being requested')
confirmSigRowValue = $('.request-signature__row-value')
assert.equal(confirmSigRowValue[0].textContent, 'Hi, Alice!')
assert.equal(confirmSigRowValue[1].textContent, '1337')
confirmSigSignButton = $('.request-signature__footer__sign-button')
confirmSigSignButton[0].click()
await timeout(2000)
const txView = $('.tx-view')
assert.ok(txView[0], 'Should return to the account details screen after confirming')
}
function timeout (time) {
return new Promise((resolve, reject) => {
setTimeout(resolve, time || 1500)
})
}