From d2d2d9e385b5f520c9684be5cfdcf55a3dd5db7f Mon Sep 17 00:00:00 2001 From: LianaHus Date: Fri, 24 Jan 2020 10:54:52 +0100 Subject: [PATCH] move isHexadecimal to helpers.js --- src/app/ui/universal-dapp-ui.js | 12 ++---------- src/lib/helper.js | 6 ++++++ test-browser/tests/specialFunctions.js | 27 +++++++++++++------------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/app/ui/universal-dapp-ui.js b/src/app/ui/universal-dapp-ui.js index 423f5271a7..a9bab5991c 100644 --- a/src/app/ui/universal-dapp-ui.js +++ b/src/app/ui/universal-dapp-ui.js @@ -178,7 +178,7 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address const amount = document.querySelector('#value').value if (amount !== '0') { // check for numeric and receive/fallback - if (!isNumeric(amount)) { + if (!helper.isNumeric(amount)) { setLLIError('Value to send should be a number') } else if (!receive && !(fallback && fallback.stateMutability === 'payable')) { setLLIError("In order to receive Ether transfer the contract should have either 'receive' or payable 'fallback' function") @@ -186,7 +186,7 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address } if (calldata) { if (calldata.length > 3 && calldata.substr(0, 2) === '0x') { - if (!isHexadecimal(calldata.substr(2, calldata.length))) { + if (!helper.isHexadecimal(calldata.substr(2, calldata.length))) { setLLIError('the calldata should be a valid hexadecimal value.') } } @@ -197,14 +197,6 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address if ((calldata || amount !== '0') && !error) self.runTransaction(false, args, null, calldata, null) } - function isHexadecimal (value) { - return /^[0-9a-fA-F]+$/.test(value) - } - - function isNumeric (value) { - return /^\+?(0|[1-9]\d*)$/.test(value) - } - contractActionsWrapper.appendChild(lowLevelInteracions) return instance } diff --git a/src/lib/helper.js b/src/lib/helper.js index 8628418f5e..93f688e4f9 100644 --- a/src/lib/helper.js +++ b/src/lib/helper.js @@ -44,6 +44,12 @@ module.exports = { checkSpecialChars (name) { return name.match(/[:*?"<>\\'|]/) != null }, + isHexadecimal (value) { + return /^[0-9a-fA-F]+$/.test(value) + }, + isNumeric (value) { + return /^\+?(0|[1-9]\d*)$/.test(value) + }, find: find } diff --git a/test-browser/tests/specialFunctions.js b/test-browser/tests/specialFunctions.js index 4e011388a5..2efbcc9521 100644 --- a/test-browser/tests/specialFunctions.js +++ b/test-browser/tests/specialFunctions.js @@ -11,21 +11,20 @@ module.exports = { }, 'Use special functions receive/fullback': function (browser) { browser.waitForElementVisible('#icon-panel', 10000) - .testContracts('receiveAndfFallback.sol', sources[0]['browser/Untitled.sol'], ['CheckSpecials']) - .clickLaunchIcon('udapp' - .selectContract('CheckSpecials') - .createContract('') - .clickInstance(0) - .perform((done) => { - browser.getAddressAtPosition(0, (address) => { - browser.sendLowLevelTx(address, '0', '0xaa') - .journalLastChild('dd') - .waitForElementVisible('label[id="deployAndRunLLTxError"]') - .assert.containsText('label[id="deployAndRunLLTxError"]', '') - .perform(done) - }) + .testContracts('browser/receiveAndfFallback.sol', sources[0]['receiveAndfFallback.sol'], ['CheckSpecials']) + .clickLaunchIcon('udapp') + .selectContract('CheckSpecials') + .createContract('') + .clickInstance(0) + .perform((done) => { + browser.getAddressAtPosition(0, (address) => { + browser.sendLowLevelTx(address, '0', '0xaa') + .journalLastChild('dd') + .waitForElementVisible('label[id="deployAndRunLLTxError"]') + .assert.containsText('label[id="deployAndRunLLTxError"]', '') + .perform(done) }) - ) + }) }, tearDown: sauce }