Commit 792ffc3e authored by LianaHus's avatar LianaHus

checking for even and new test

parent 5d8258ee
...@@ -166,7 +166,6 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address ...@@ -166,7 +166,6 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address
contractName: contractName, contractName: contractName,
contractABI: contractABI contractABI: contractABI
} }
let calldata = calldataInput.value
const amount = document.querySelector('#value').value const amount = document.querySelector('#value').value
if (amount !== '0') { if (amount !== '0') {
// check for numeric and receive/fallback // check for numeric and receive/fallback
...@@ -176,16 +175,17 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address ...@@ -176,16 +175,17 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address
setLLIError("In order to receive Ether transfer the contract should have either 'receive' or payable 'fallback' function") setLLIError("In order to receive Ether transfer the contract should have either 'receive' or payable 'fallback' function")
} }
} }
let calldata = calldataInput.value
if (calldata) { if (calldata) {
if (calldata.length < 2) setLLIError('the calldata should be a valid hexadecimal value with size of at least one byte.') if (calldata.length < 2 || calldata.length < 4 && helper.is0XPrefixed(calldata)) {
if (calldata.length < 4 && calldata.substr(0, 2) === '0x') { setLLIError('the calldata should be a valid hexadecimal value with size of at least one byte.')
setLLIError('The calldata should be a valid hexadecimal value with size of at least one byte.') } else {
} else if (calldata.substr(0, 2) === '0x') { if (helper.is0XPrefixed(calldata)) {
if (!helper.isHexadecimal(calldata.substr(2, calldata.length))) { calldata = calldata.substr(2, calldata.length)
setLLIError('The calldata should be a valid hexadecimal value.') }
if (!helper.isHexadecimal(calldata)) {
setLLIError('the calldata should be a valid hexadecimal value with size of at least one byte.')
} }
} else if (!helper.isHexadecimal(calldata)) {
setLLIError('The calldata should be a valid hexadecimal value.')
} }
if (!fallback) { if (!fallback) {
setLLIError("'Fallback' function is not defined") setLLIError("'Fallback' function is not defined")
...@@ -200,9 +200,9 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address ...@@ -200,9 +200,9 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address
if (receive && !calldata) args.funABI = receive if (receive && !calldata) args.funABI = receive
else if (fallback) args.funABI = fallback else if (fallback) args.funABI = fallback
if (!args.funABI) setLLIError(`Please define at least a 'Fallback' with/without sending calldata or a 'Receive' without sending calldata`) if (!args.funABI) setLLIError(`Please define a 'Fallback' function to send calldata and a either 'Receive' or payable 'Fallback' to send ethers`)
if (!error) self.runTransaction(false, args, null, calldata, null) if (!error) self.runTransaction(false, args, null, calldataInput.value, null)
} }
contractActionsWrapper.appendChild(lowLevelInteracions) contractActionsWrapper.appendChild(lowLevelInteracions)
......
...@@ -45,7 +45,10 @@ module.exports = { ...@@ -45,7 +45,10 @@ module.exports = {
return name.match(/[:*?"<>\\'|]/) != null return name.match(/[:*?"<>\\'|]/) != null
}, },
isHexadecimal (value) { isHexadecimal (value) {
return /^[0-9a-fA-F]+$/.test(value) return /^[0-9a-fA-F]+$/.test(value) && (value.length % 2 === 0)
},
is0XPrefixed (value) {
return value.substr(0, 2) === '0x'
}, },
isNumeric (value) { isNumeric (value) {
return /^\+?(0|[1-9]\d*)$/.test(value) return /^\+?(0|[1-9]\d*)$/.test(value)
......
...@@ -34,7 +34,7 @@ module.exports = { ...@@ -34,7 +34,7 @@ module.exports = {
browser.sendLowLevelTx(address, '0', '0xa') browser.sendLowLevelTx(address, '0', '0xa')
.pause(1000) .pause(1000)
.waitForElementVisible(`#instance${address} label[id="deployAndRunLLTxError"]`) .waitForElementVisible(`#instance${address} label[id="deployAndRunLLTxError"]`)
.assert.containsText(`#instance${address} label[id="deployAndRunLLTxError"]`, `size of at least one byte`) .assert.containsText(`#instance${address} label[id="deployAndRunLLTxError"]`, `the calldata should be a valid hexadecimal value with size of at least one byte.`)
.perform(done) .perform(done)
}) })
}) })
...@@ -164,6 +164,18 @@ module.exports = { ...@@ -164,6 +164,18 @@ module.exports = {
}) })
}) })
}, },
'Use special functions receive/fallback - receive and fallback are declared and payable, sending wei': function (browser) {
browser.perform((done) => {
browser.getAddressAtPosition(4, (address) => {
browser.sendLowLevelTx(address, '1', '')
.pause(1000)
.journalLastChildIncludes('to:CheckSpecials.(receive)')
.journalLastChildIncludes('value:1 wei')
.journalLastChildIncludes('data:0x')
.perform(done)
})
})
},
'Use special functions receive/fallback - receive and fallback are not declared, sending nothing': function (browser) { 'Use special functions receive/fallback - receive and fallback are not declared, sending nothing': function (browser) {
browser.waitForElementVisible('#icon-panel', 10000) browser.waitForElementVisible('#icon-panel', 10000)
.testContracts('notSpecial.sol', sources[5]['browser/notSpecial.sol'], ['CheckSpecials']) .testContracts('notSpecial.sol', sources[5]['browser/notSpecial.sol'], ['CheckSpecials'])
...@@ -180,7 +192,7 @@ module.exports = { ...@@ -180,7 +192,7 @@ module.exports = {
browser.sendLowLevelTx(address, '0', '') browser.sendLowLevelTx(address, '0', '')
.pause(1000) .pause(1000)
.waitForElementVisible(`#instance${address} label[id="deployAndRunLLTxError"]`) .waitForElementVisible(`#instance${address} label[id="deployAndRunLLTxError"]`)
.assert.containsText(`#instance${address} label[id="deployAndRunLLTxError"]`, `Both 'receive' and 'fallback' functions are not defined`) .assert.containsText(`#instance${address} label[id="deployAndRunLLTxError"]`, `Please define a 'Fallback' function to send calldata and a either 'Receive' or payable 'Fallback' to send ethers`)
.perform(done) .perform(done)
}) })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment