Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
16bd1020
Commit
16bd1020
authored
Jan 30, 2020
by
LianaHus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added more tests and fixed bug when only receive declared
parent
5b387f63
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
21 deletions
+73
-21
universal-dapp-ui.js
src/app/ui/universal-dapp-ui.js
+12
-6
specialFunctions.js
test-browser/tests/specialFunctions.js
+61
-15
No files found.
src/app/ui/universal-dapp-ui.js
View file @
16bd1020
...
@@ -133,7 +133,7 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address
...
@@ -133,7 +133,7 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address
<label class="pt-2 border-top d-flex justify-content-start flex-grow-1">
<label class="pt-2 border-top d-flex justify-content-start flex-grow-1">
Low level interactions with contract
Low level interactions with contract
</label>
</label>
<a href="https://solidity.readthedocs.io/en/v0.6.2/contracts.html#receive-ether-function"
class=""
title="the link to documentation" target="_blank">
<a href="https://solidity.readthedocs.io/en/v0.6.2/contracts.html#receive-ether-function" title="the link to documentation" target="_blank">
<i aria-hidden="true" class="fas fa-info text-info my-2 mr-2"></i>
<i aria-hidden="true" class="fas fa-info text-info my-2 mr-2"></i>
</a>
</a>
</div>
</div>
...
@@ -161,7 +161,7 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address
...
@@ -161,7 +161,7 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address
const
fallback
=
self
.
udapp
.
getFallbackInterface
(
contractABI
)
const
fallback
=
self
.
udapp
.
getFallbackInterface
(
contractABI
)
const
receive
=
self
.
udapp
.
getReceiveInterface
(
contractABI
)
const
receive
=
self
.
udapp
.
getReceiveInterface
(
contractABI
)
const
args
=
{
const
args
=
{
funABI
:
fallback
,
funABI
:
fallback
||
receive
,
address
:
address
,
address
:
address
,
contractName
:
contractName
,
contractName
:
contractName
,
contractABI
:
contractABI
contractABI
:
contractABI
...
@@ -177,16 +177,22 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address
...
@@ -177,16 +177,22 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address
}
}
}
}
if
(
calldata
)
{
if
(
calldata
)
{
if
(
calldata
.
length
>
3
&&
calldata
.
substr
(
0
,
2
)
===
'0x'
)
{
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
)))
{
if
(
!
helper
.
isHexadecimal
(
calldata
.
substr
(
2
,
calldata
.
length
)))
{
setLLIError
(
'
t
he calldata should be a valid hexadecimal value.'
)
setLLIError
(
'
T
he calldata should be a valid hexadecimal value.'
)
}
}
}
else
if
(
!
helper
.
isHexadecimal
(
calldata
))
{
setLLIError
(
'The calldata should be a valid hexadecimal value.'
)
}
}
if
(
!
fallback
)
{
if
(
!
fallback
)
{
setLLIError
(
"'
f
allback' function is not defined"
)
setLLIError
(
"'
F
allback' function is not defined"
)
}
}
}
}
if
((
calldata
||
amount
!==
'0'
)
&&
!
error
)
self
.
runTransaction
(
false
,
args
,
null
,
calldata
,
null
)
if
(
!
receive
&&
!
fallback
)
setLLIError
(
"Both 'receive' and 'fallback' functions are not defined"
)
if
(
!
error
)
self
.
runTransaction
(
false
,
args
,
null
,
calldata
,
null
)
}
}
contractActionsWrapper
.
appendChild
(
lowLevelInteracions
)
contractActionsWrapper
.
appendChild
(
lowLevelInteracions
)
...
...
test-browser/tests/specialFunctions.js
View file @
16bd1020
...
@@ -2,15 +2,6 @@
...
@@ -2,15 +2,6 @@
var
init
=
require
(
'../helpers/init'
)
var
init
=
require
(
'../helpers/init'
)
var
sauce
=
require
(
'./sauce'
)
var
sauce
=
require
(
'./sauce'
)
/**
* both are declared, sending data
* both are declared - receive called, sending wei
* both are declared - fallback should fail cause not payable, sending data and wei
* receive is declared, failing, fallback is not declared, sending data
* receive is not declared, fallback is payable, sending wei
* receive is not declared, fallback is payable, sending data and wei
* both are not declared, sending data and wei, should fail
*/
module
.
exports
=
{
module
.
exports
=
{
before
:
function
(
browser
,
done
)
{
before
:
function
(
browser
,
done
)
{
init
(
browser
,
done
)
init
(
browser
,
done
)
...
@@ -36,6 +27,18 @@ module.exports = {
...
@@ -36,6 +27,18 @@ module.exports = {
})
})
})
})
},
},
'Use special functions receive/follback - both are declared - receive called, failing sending data < 1 byte'
:
function
(
browser
)
{
// don't need to redeploy it, same contract
browser
.
perform
((
done
)
=>
{
browser
.
getAddressAtPosition
(
0
,
(
address
)
=>
{
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`
)
.
perform
(
done
)
})
})
},
'Use special functions receive/follback - both are declared - receive called, sending wei'
:
function
(
browser
)
{
'Use special functions receive/follback - both are declared - receive called, sending wei'
:
function
(
browser
)
{
// don't need to redeploy it, same contract
// don't need to redeploy it, same contract
browser
.
perform
((
done
)
=>
{
browser
.
perform
((
done
)
=>
{
...
@@ -61,7 +64,7 @@ module.exports = {
...
@@ -61,7 +64,7 @@ module.exports = {
})
})
})
})
},
},
'Use special functions receive/follback -
receive is declared, failing, fallback is not declared, sending data
'
:
function
(
browser
)
{
'Use special functions receive/follback -
only receive is declared, sending wei
'
:
function
(
browser
)
{
browser
.
waitForElementVisible
(
'#icon-panel'
,
10000
)
browser
.
waitForElementVisible
(
'#icon-panel'
,
10000
)
.
testContracts
(
'receiveOnly.sol'
,
sources
[
1
][
'browser/receiveOnly.sol'
],
[
'CheckSpecials'
])
.
testContracts
(
'receiveOnly.sol'
,
sources
[
1
][
'browser/receiveOnly.sol'
],
[
'CheckSpecials'
])
.
clickLaunchIcon
(
'udapp'
)
.
clickLaunchIcon
(
'udapp'
)
...
@@ -70,15 +73,28 @@ module.exports = {
...
@@ -70,15 +73,28 @@ module.exports = {
.
clickInstance
(
1
)
.
clickInstance
(
1
)
.
perform
((
done
)
=>
{
.
perform
((
done
)
=>
{
browser
.
getAddressAtPosition
(
1
,
(
address
)
=>
{
browser
.
getAddressAtPosition
(
1
,
(
address
)
=>
{
browser
.
sendLowLevelTx
(
address
,
'1'
,
''
)
.
pause
(
1000
)
.
journalLastChildIncludes
(
'to:CheckSpecials.(receive)'
)
.
journalLastChildIncludes
(
'value:1 wei'
)
.
journalLastChildIncludes
(
'data:0x'
)
.
perform
(
done
)
})
})
},
'Use special functions receive/follback - only receive is declared, failing, fallback is not declared, sending data'
:
function
(
browser
)
{
// don't need to redeploy it, same contract
browser
.
perform
((
done
)
=>
{
browser
.
getAddressAtPosition
(
1
,
(
address
)
=>
{
browser
.
sendLowLevelTx
(
address
,
'0'
,
'0xaa'
)
browser
.
sendLowLevelTx
(
address
,
'0'
,
'0xaa'
)
.
pause
(
1000
)
.
pause
(
1000
)
.
waitForElementVisible
(
`#instance
${
address
}
label[id="deployAndRunLLTxError"]`
)
.
waitForElementVisible
(
`#instance
${
address
}
label[id="deployAndRunLLTxError"]`
)
.
assert
.
containsText
(
`#instance
${
address
}
label[id="deployAndRunLLTxError"]`
,
`'
f
allback' function is not defined`
)
.
assert
.
containsText
(
`#instance
${
address
}
label[id="deployAndRunLLTxError"]`
,
`'
F
allback' function is not defined`
)
.
perform
(
done
)
.
perform
(
done
)
})
})
})
})
},
},
'Use special functions receive/fallback -
receive is not declared,
fallback is payable, sending wei'
:
function
(
browser
)
{
'Use special functions receive/fallback -
only
fallback is payable, sending wei'
:
function
(
browser
)
{
browser
.
waitForElementVisible
(
'#icon-panel'
,
10000
)
browser
.
waitForElementVisible
(
'#icon-panel'
,
10000
)
.
testContracts
(
'fallbackOnlyPayable.sol'
,
sources
[
2
][
'browser/fallbackOnlyPayable.sol'
],
[
'CheckSpecials'
])
.
testContracts
(
'fallbackOnlyPayable.sol'
,
sources
[
2
][
'browser/fallbackOnlyPayable.sol'
],
[
'CheckSpecials'
])
.
clickLaunchIcon
(
'udapp'
)
.
clickLaunchIcon
(
'udapp'
)
...
@@ -96,7 +112,7 @@ module.exports = {
...
@@ -96,7 +112,7 @@ module.exports = {
})
})
})
})
},
},
'Use special functions receive/follback -
receive is not declared, fallback
is payable, sending data and wei'
:
function
(
browser
)
{
'Use special functions receive/follback -
only fallback is diclared and
is payable, sending data and wei'
:
function
(
browser
)
{
// don't need to redeploy it, same contract
// don't need to redeploy it, same contract
browser
.
perform
((
done
)
=>
{
browser
.
perform
((
done
)
=>
{
browser
.
getAddressAtPosition
(
2
,
(
address
)
=>
{
browser
.
getAddressAtPosition
(
2
,
(
address
)
=>
{
...
@@ -109,7 +125,7 @@ module.exports = {
...
@@ -109,7 +125,7 @@ module.exports = {
})
})
})
})
},
},
'Use special functions receive/fallback -
receive is not
declared, fallback should fail cause not payable, sending wei'
:
function
(
browser
)
{
'Use special functions receive/fallback -
only fallback is
declared, fallback should fail cause not payable, sending wei'
:
function
(
browser
)
{
browser
.
waitForElementVisible
(
'#icon-panel'
,
10000
)
browser
.
waitForElementVisible
(
'#icon-panel'
,
10000
)
.
testContracts
(
'fallbackOnlyNotPayable.sol'
,
sources
[
3
][
'browser/fallbackOnlyNotPayable.sol'
],
[
'CheckSpecials'
])
.
testContracts
(
'fallbackOnlyNotPayable.sol'
,
sources
[
3
][
'browser/fallbackOnlyNotPayable.sol'
],
[
'CheckSpecials'
])
.
clickLaunchIcon
(
'udapp'
)
.
clickLaunchIcon
(
'udapp'
)
...
@@ -136,7 +152,7 @@ module.exports = {
...
@@ -136,7 +152,7 @@ module.exports = {
.
setValue
(
'#value'
,
0
)
.
setValue
(
'#value'
,
0
)
.
createContract
(
''
)
.
createContract
(
''
)
.
clickInstance
(
4
)
.
clickInstance
(
4
)
.
pause
(
1000
0
)
.
pause
(
1000
)
.
perform
((
done
)
=>
{
.
perform
((
done
)
=>
{
browser
.
getAddressAtPosition
(
4
,
(
address
)
=>
{
browser
.
getAddressAtPosition
(
4
,
(
address
)
=>
{
browser
.
sendLowLevelTx
(
address
,
'1'
,
'0xaa'
)
browser
.
sendLowLevelTx
(
address
,
'1'
,
'0xaa'
)
...
@@ -147,6 +163,27 @@ module.exports = {
...
@@ -147,6 +163,27 @@ module.exports = {
.
perform
(
done
)
.
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'
])
.
clickLaunchIcon
(
'udapp'
)
.
selectContract
(
'CheckSpecials'
)
.
waitForElementVisible
(
'#value'
)
.
clearValue
(
'#value'
)
.
setValue
(
'#value'
,
0
)
.
createContract
(
''
)
.
clickInstance
(
5
)
.
pause
(
1000
)
.
perform
((
done
)
=>
{
browser
.
getAddressAtPosition
(
5
,
(
address
)
=>
{
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`
)
.
perform
(
done
)
})
})
.
end
()
.
end
()
},
},
tearDown
:
sauce
tearDown
:
sauce
...
@@ -199,5 +236,14 @@ var sources = [
...
@@ -199,5 +236,14 @@ var sources = [
}
}
`
`
}
}
},
{
'browser/notSpecial.sol'
:
{
content
:
`
contract CheckSpecials {
function otherFallback() payable external {}
}
`
}
}
}
]
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment