You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
275 lines
10 KiB
275 lines
10 KiB
5 years ago
|
'use strict'
|
||
|
var init = require('../helpers/init')
|
||
|
var sauce = require('./sauce')
|
||
|
|
||
|
module.exports = {
|
||
|
before: function (browser, done) {
|
||
|
init(browser, done)
|
||
|
},
|
||
|
'@sources': function () {
|
||
|
return sources
|
||
|
},
|
||
5 years ago
|
'Use special functions receive/fallback - both are declared, sending data': function (browser) {
|
||
5 years ago
|
browser.waitForElementVisible('#icon-panel', 10000)
|
||
5 years ago
|
.testContracts('receiveAndFallback.sol', sources[0]['browser/receiveAndFallback.sol'], ['CheckSpecials']) // compile
|
||
5 years ago
|
.clickLaunchIcon('udapp')
|
||
5 years ago
|
.selectAccount('0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c') // this account will be used for this test suite
|
||
5 years ago
|
.selectContract('CheckSpecials')
|
||
5 years ago
|
.createContract('') // deploy
|
||
5 years ago
|
.clickInstance(0)
|
||
5 years ago
|
.perform((done) => {
|
||
|
browser.getAddressAtPosition(0, (address) => {
|
||
|
browser.sendLowLevelTx(address, '0', '0xaa')
|
||
|
.pause(1000)
|
||
|
.journalLastChildIncludes('to:CheckSpecials.(fallback)')
|
||
|
.journalLastChildIncludes('value:0 wei')
|
||
|
.journalLastChildIncludes('data:0xaa')
|
||
|
.perform(done)
|
||
|
})
|
||
|
})
|
||
|
},
|
||
5 years ago
|
'Use special functions receive/fallback - both are declared, failing sending data < 1 byte': function (browser) {
|
||
5 years ago
|
// 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"]`)
|
||
5 years ago
|
.assert.containsText(`#instance${address} label[id="deployAndRunLLTxError"]`, `The calldata should be a valid hexadecimal value with size of at least one byte.`)
|
||
|
.perform(done)
|
||
|
})
|
||
|
})
|
||
|
},
|
||
|
'Use special functions receive/fallback - both are declared, failing sending data with odd number of digits': function (browser) {
|
||
|
// don't need to redeploy it, same contract
|
||
|
browser.perform((done) => {
|
||
|
browser.getAddressAtPosition(0, (address) => {
|
||
|
browser.sendLowLevelTx(address, '0', '0x1aa')
|
||
|
.pause(1000)
|
||
|
.waitForElementVisible(`#instance${address} label[id="deployAndRunLLTxError"]`)
|
||
|
.assert.containsText(`#instance${address} label[id="deployAndRunLLTxError"]`, `The calldata should be a valid hexadecimal value.`)
|
||
5 years ago
|
.perform(done)
|
||
|
})
|
||
|
})
|
||
|
},
|
||
5 years ago
|
'Use special functions receive/fallback - both are declared - receive called, sending wei': function (browser) {
|
||
5 years ago
|
// don't need to redeploy it, same contract
|
||
|
browser.perform((done) => {
|
||
|
browser.getAddressAtPosition(0, (address) => {
|
||
|
browser.sendLowLevelTx(address, '1', '')
|
||
|
.pause(1000)
|
||
|
.journalLastChildIncludes('to:CheckSpecials.(receive)')
|
||
|
.journalLastChildIncludes('value:1 wei')
|
||
|
.journalLastChildIncludes('data:0x')
|
||
|
.perform(done)
|
||
|
})
|
||
|
})
|
||
|
},
|
||
5 years ago
|
'Use special functions receive/fallback - both are declared - fallback should fail cause not payable, sending data and wei': function (browser) {
|
||
5 years ago
|
// don't need to redeploy it, same contract
|
||
|
browser.perform((done) => {
|
||
5 years ago
|
browser.getAddressAtPosition(0, (address) => {
|
||
5 years ago
|
browser.sendLowLevelTx(address, '10', '0xaa')
|
||
|
.pause(1000)
|
||
|
.journalLastChildIncludes('to CheckSpecials.(fallback) errored:')
|
||
|
.journalLastChildIncludes('The called function should be payable if you send value')
|
||
|
.perform(done)
|
||
|
})
|
||
|
})
|
||
|
},
|
||
5 years ago
|
'Use special functions receive/fallback - only receive is declared, sending wei': function (browser) {
|
||
5 years ago
|
browser.waitForElementVisible('#icon-panel', 10000)
|
||
|
.testContracts('receiveOnly.sol', sources[1]['browser/receiveOnly.sol'], ['CheckSpecials'])
|
||
|
.clickLaunchIcon('udapp')
|
||
|
.selectContract('CheckSpecials')
|
||
|
.createContract('')
|
||
|
.clickInstance(1)
|
||
|
.perform((done) => {
|
||
5 years ago
|
browser.getAddressAtPosition(1, (address) => {
|
||
|
browser.sendLowLevelTx(address, '1', '')
|
||
|
.pause(1000)
|
||
|
.journalLastChildIncludes('to:CheckSpecials.(receive)')
|
||
|
.journalLastChildIncludes('value:1 wei')
|
||
|
.journalLastChildIncludes('data:0x')
|
||
|
.perform(done)
|
||
|
})
|
||
|
})
|
||
|
},
|
||
5 years ago
|
'Use special functions receive/fallback - only receive is declared, failing, fallback is not declared, sending data': function (browser) {
|
||
5 years ago
|
// don't need to redeploy it, same contract
|
||
|
browser.perform((done) => {
|
||
5 years ago
|
browser.getAddressAtPosition(1, (address) => {
|
||
5 years ago
|
browser.sendLowLevelTx(address, '0', '0xaa')
|
||
5 years ago
|
.pause(1000)
|
||
|
.waitForElementVisible(`#instance${address} label[id="deployAndRunLLTxError"]`)
|
||
5 years ago
|
.assert.containsText(`#instance${address} label[id="deployAndRunLLTxError"]`, `'Fallback' function is not defined`)
|
||
5 years ago
|
.perform(done)
|
||
|
})
|
||
|
})
|
||
|
},
|
||
5 years ago
|
'Use special functions receive/fallback - only fallback declared and is payable, sending wei': function (browser) {
|
||
5 years ago
|
browser.waitForElementVisible('#icon-panel', 10000)
|
||
|
.testContracts('fallbackOnlyPayable.sol', sources[2]['browser/fallbackOnlyPayable.sol'], ['CheckSpecials'])
|
||
|
.clickLaunchIcon('udapp')
|
||
|
.selectContract('CheckSpecials')
|
||
|
.createContract('')
|
||
|
.clickInstance(2)
|
||
|
.perform((done) => {
|
||
|
browser.getAddressAtPosition(2, (address) => {
|
||
|
browser.sendLowLevelTx(address, '1', '')
|
||
|
.pause(1000)
|
||
|
.journalLastChildIncludes('to:CheckSpecials.(fallback)')
|
||
|
.journalLastChildIncludes('value:1 wei')
|
||
|
.journalLastChildIncludes('data:0x')
|
||
5 years ago
|
.perform(done)
|
||
5 years ago
|
})
|
||
5 years ago
|
})
|
||
|
},
|
||
5 years ago
|
'Use special functions receive/fallback - only fallback is diclared and is payable, sending data and wei': function (browser) {
|
||
5 years ago
|
// don't need to redeploy it, same contract
|
||
|
browser.perform((done) => {
|
||
|
browser.getAddressAtPosition(2, (address) => {
|
||
|
browser.sendLowLevelTx(address, '1', '0xaa')
|
||
|
.pause(1000)
|
||
|
.journalLastChildIncludes('to:CheckSpecials.(fallback)')
|
||
|
.journalLastChildIncludes('value:1 wei')
|
||
|
.journalLastChildIncludes('data:0xaa')
|
||
|
.perform(done)
|
||
|
})
|
||
|
})
|
||
|
},
|
||
5 years ago
|
'Use special functions receive/fallback - only fallback is declared, fallback should fail cause not payable, sending wei': function (browser) {
|
||
5 years ago
|
browser.waitForElementVisible('#icon-panel', 10000)
|
||
|
.testContracts('fallbackOnlyNotPayable.sol', sources[3]['browser/fallbackOnlyNotPayable.sol'], ['CheckSpecials'])
|
||
|
.clickLaunchIcon('udapp')
|
||
|
.selectContract('CheckSpecials')
|
||
|
.createContract('')
|
||
|
.clickInstance(3)
|
||
|
.perform((done) => {
|
||
|
browser.getAddressAtPosition(3, (address) => {
|
||
|
browser.sendLowLevelTx(address, '1', '')
|
||
|
.pause(1000)
|
||
|
.waitForElementVisible(`#instance${address} label[id="deployAndRunLLTxError"]`)
|
||
|
.assert.containsText(`#instance${address} label[id="deployAndRunLLTxError"]`, `should have either 'receive' or payable 'fallback'`)
|
||
|
.perform(done)
|
||
|
})
|
||
|
})
|
||
|
},
|
||
|
'Use special functions receive/fallback - receive and fallback are declared, sending data and wei': function (browser) {
|
||
|
browser.waitForElementVisible('#icon-panel', 10000)
|
||
|
.testContracts('receiveAndFallbackBothPayable.sol', sources[4]['browser/receiveAndFallbackBothPayable.sol'], ['CheckSpecials'])
|
||
|
.clickLaunchIcon('udapp')
|
||
|
.selectContract('CheckSpecials')
|
||
|
.waitForElementVisible('#value')
|
||
|
.clearValue('#value')
|
||
|
.setValue('#value', 0)
|
||
|
.createContract('')
|
||
|
.clickInstance(4)
|
||
5 years ago
|
.pause(1000)
|
||
5 years ago
|
.perform((done) => {
|
||
|
browser.getAddressAtPosition(4, (address) => {
|
||
|
browser.sendLowLevelTx(address, '1', '0xaa')
|
||
5 years ago
|
.pause(1000)
|
||
5 years ago
|
.journalLastChildIncludes('to:CheckSpecials.(fallback)')
|
||
|
.journalLastChildIncludes('value:1 wei')
|
||
|
.journalLastChildIncludes('data:0xaa')
|
||
|
.perform(done)
|
||
|
})
|
||
|
})
|
||
5 years ago
|
},
|
||
5 years ago
|
'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)
|
||
|
})
|
||
|
})
|
||
|
},
|
||
5 years ago
|
'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"]`)
|
||
5 years ago
|
.assert.containsText(`#instance${address} label[id="deployAndRunLLTxError"]`, `Both 'receive' and 'fallback' functions are not defined`)
|
||
5 years ago
|
.perform(done)
|
||
|
})
|
||
|
})
|
||
5 years ago
|
.end()
|
||
5 years ago
|
},
|
||
|
tearDown: sauce
|
||
|
}
|
||
|
|
||
|
var sources = [
|
||
|
{
|
||
5 years ago
|
'browser/receiveAndFallback.sol': {
|
||
5 years ago
|
content: `
|
||
|
contract CheckSpecials {
|
||
|
receive() payable external{}
|
||
|
fallback() external {}
|
||
|
}
|
||
|
`
|
||
5 years ago
|
}
|
||
|
},
|
||
|
{
|
||
5 years ago
|
'browser/receiveOnly.sol': {
|
||
|
content: `
|
||
|
contract CheckSpecials {
|
||
5 years ago
|
receive() payable external {}
|
||
5 years ago
|
}
|
||
|
`
|
||
5 years ago
|
}
|
||
|
},
|
||
|
{
|
||
|
'browser/fallbackOnlyPayable.sol': {
|
||
|
content: `
|
||
|
contract CheckSpecials {
|
||
|
fallback() payable external {}
|
||
|
}
|
||
|
`
|
||
|
}
|
||
|
},
|
||
|
{
|
||
|
'browser/fallbackOnlyNotPayable.sol': {
|
||
|
content: `
|
||
|
contract CheckSpecials {
|
||
|
fallback() external {}
|
||
|
}
|
||
|
`
|
||
|
}
|
||
|
},
|
||
|
{
|
||
|
'browser/receiveAndFallbackBothPayable.sol': {
|
||
5 years ago
|
content: `
|
||
|
contract CheckSpecials {
|
||
5 years ago
|
receive() payable external {}
|
||
|
fallback() payable external {}
|
||
5 years ago
|
}
|
||
|
`
|
||
|
}
|
||
5 years ago
|
},
|
||
|
{
|
||
|
'browser/notSpecial.sol': {
|
||
|
content: `
|
||
|
contract CheckSpecials {
|
||
|
function otherFallback() payable external {}
|
||
|
}
|
||
|
`
|
||
|
}
|
||
5 years ago
|
}
|
||
|
]
|