Skip to content

Commit

Permalink
checking for even and new test
Browse files Browse the repository at this point in the history
  • Loading branch information
LianaHus committed Jan 30, 2020
1 parent 5d8258e commit 69b8768
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
22 changes: 10 additions & 12 deletions src/app/ui/universal-dapp-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address
contractName: contractName,
contractABI: contractABI
}
let calldata = calldataInput.value
const amount = document.querySelector('#value').value
if (amount !== '0') {
// check for numeric and receive/fallback
Expand All @@ -176,16 +175,15 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address
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.length < 2) setLLIError('the calldata should be a valid hexadecimal value with size of at least one byte.')
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.')
} else if (calldata.substr(0, 2) === '0x') {
if (!helper.isHexadecimal(calldata.substr(2, calldata.length))) {
setLLIError('The calldata should be a valid hexadecimal value.')
}
} else if (!helper.isHexadecimal(calldata)) {
setLLIError('The calldata should be a valid hexadecimal value.')
if (calldata.length < 2 || calldata.length < 4 && helper.is0XPrefixed(calldata))
setLLIError('the calldata should be a valid hexadecimal value with size of at least one byte.')
else {
if (helper.is0XPrefixed(calldata))
calldata = calldata.substr(2, calldata.length)
if (!helper.isHexadecimal(calldata))
setLLIError('the calldata should be a valid hexadecimal value with size of at least one byte.')
}
if (!fallback) {
setLLIError("'Fallback' function is not defined")
Expand All @@ -200,9 +198,9 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address
if (receive && !calldata) args.funABI = receive
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)
Expand Down
5 changes: 4 additions & 1 deletion src/lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ module.exports = {
return name.match(/[:*?"<>\\'|]/) != null
},
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) {
return /^\+?(0|[1-9]\d*)$/.test(value)
Expand Down
16 changes: 14 additions & 2 deletions test-browser/tests/specialFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
browser.sendLowLevelTx(address, '0', '0xa')
.pause(1000)
.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)
})
})
Expand Down Expand Up @@ -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) {
browser.waitForElementVisible('#icon-panel', 10000)
.testContracts('notSpecial.sol', sources[5]['browser/notSpecial.sol'], ['CheckSpecials'])
Expand All @@ -180,7 +192,7 @@ module.exports = {
browser.sendLowLevelTx(address, '0', '')
.pause(1000)
.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)
})
})
Expand Down

0 comments on commit 69b8768

Please sign in to comment.