From 1aa2e45219ba01fb21103fdeada18f08797bb491 Mon Sep 17 00:00:00 2001 From: Eswara Sai Date: Wed, 31 Jan 2018 18:09:37 +0530 Subject: [PATCH] Initial commit to check for valid address --- src/app/tabs/run-tab.js | 7 +++++++ test-browser/helpers/contracts.js | 8 +++++++- test-browser/tests/ballot.js | 10 ++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index 5fff59d730..01be4b6eb7 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -12,6 +12,7 @@ var copyToClipboard = require('../ui/copy-to-clipboard') var Recorder = require('../../recorder') var EventManager = remixLib.EventManager var addTooltip = require('../ui/tooltip') +var ethJSUtil = require('ethereumjs-util') var csjs = require('csjs-inject') var css = require('./styles/run-tab-styles') @@ -311,6 +312,12 @@ function contractDropdown (events, appAPI, appEvents, instanceContainer) { noInstancesText.style.display = 'none' var contractNames = document.querySelector(`.${css.contractNames.classNames[0]}`) var address = atAddressButtonInput.value + if (!ethJSUtil.isValidAddress(address)) { + return modalDialogCustom.alert('Invalid address.') + } + if (/[a-f]/.test(address) && /[A-F]/.test(address) && !ethJSUtil.isValidChecksumAddress(address)) { + return modalDialogCustom.alert('Invalid checksum address.') + } if (/.(.abi)$/.exec(appAPI.currentFile())) { modalDialogCustom.confirm(null, 'Do you really want to interact with ' + address + ' using the current ABI definition ?', () => { var abi diff --git a/test-browser/helpers/contracts.js b/test-browser/helpers/contracts.js index 6d01addfa9..183612edcf 100644 --- a/test-browser/helpers/contracts.js +++ b/test-browser/helpers/contracts.js @@ -1,5 +1,6 @@ 'use strict' var deepequal = require('deep-equal') +var ethJSUtil = require('ethereumjs-util') module.exports = { getCompiledContracts: getCompiledContracts, @@ -161,11 +162,16 @@ function setEditorValue (value, callback) { return this } -function addInstance (browser, address, callback) { +function addInstance(browser, address, isValidFormat, isValidChecksum, callback) { browser.setValue('.ataddressinput', address, function () { browser.click('div[class^="atAddress"]') .perform((client, done) => { browser.execute(function () { + if (!isValidFormat) { + browser.assert.fail(document.querySelector('div[class^="modalBody"] div').innerHTML, 'Invalid address.', '') + } else if (!isValidChecksum) { + browser.assert.fail(document.querySelector('div[class^="modalBody"] div').innerHTML, 'Invalid checksum address.', '') + } document.querySelector('#modal-footer-ok').click() }, [], function (result) { done() diff --git a/test-browser/tests/ballot.js b/test-browser/tests/ballot.js index ecc846fe62..00dabb091a 100644 --- a/test-browser/tests/ballot.js +++ b/test-browser/tests/ballot.js @@ -72,8 +72,14 @@ function runTests (browser, testData) { }) }) .perform((client, done) => { - console.log('addInstance 0x692a70d2e424a56d2c6c27aa97d1a86395877b3a') - contractHelper.addInstance(browser, '0x692a70d2e424a56d2c6c27aa97d1a86395877b3a', () => { + console.log('addInstance invalid checksum address 0x692a70d2e424a56d2c6c27aa97d1a86395877b3a') + contractHelper.addInstance(browser, '0x692a70d2e424a56d2c6c27aa97d1a86395877b3a', true, false, () => { + done() + }) + }) + .perform((client, done) => { + console.log('addInstance 0x692a70D2e424a56D2C6C27aA97D1a86395877b3A') + contractHelper.addInstance(browser, '0x692a70D2e424a56D2C6C27aA97D1a86395877b3A', true, true, () => { done() }) })