commit
45954a533e
@ -0,0 +1,59 @@ |
|||||||
|
'use strict' |
||||||
|
import { NightwatchBrowser } from 'nightwatch' |
||||||
|
import init from '../helpers/init' |
||||||
|
|
||||||
|
module.exports = { |
||||||
|
'@disabled': true, |
||||||
|
before: function (browser: NightwatchBrowser, done: VoidFunction) { |
||||||
|
init(browser, done) |
||||||
|
}, |
||||||
|
'@sources': function () { |
||||||
|
return '' |
||||||
|
}, |
||||||
|
|
||||||
|
'Execute a call that retrieve previous block hashes #group1': function (browser: NightwatchBrowser) { |
||||||
|
const code = ` |
||||||
|
contract A { |
||||||
|
function foo(uint p) public view returns(bytes32) { |
||||||
|
return blockhash(p); |
||||||
|
} |
||||||
|
}` |
||||||
|
browser.testContracts('test.sol',{ content: code } , ['A']) |
||||||
|
.clickLaunchIcon('udapp') |
||||||
|
.selectAccount('0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c') // this account will be used for this test suite
|
||||||
|
.click('.udapp_contractActionsContainerSingle > button') |
||||||
|
.clickInstance(0) |
||||||
|
.clickFunction('foo - call', { types: 'uint256 p', values: '0' })
|
||||||
|
.perform((done) => { |
||||||
|
browser.getAddressAtPosition(0, (address) => { |
||||||
|
browser |
||||||
|
.verifyCallReturnValue(address, (values: string[]) => { |
||||||
|
// should be looking like: ['0:bytes32: 0x0391a96b0b74805e5fbb79a18840548c5b6c0f1c5e933fc5e3ee015823856e00']
|
||||||
|
const value = values[0].replace('0:bytes32: ', '') |
||||||
|
let pass = value !== '0x0000000000000000000000000000000000000000000000000000000000000000' && value !== '0x' |
||||||
|
return { |
||||||
|
pass, |
||||||
|
message: pass ? 'pass' : 'a non empty blockhash should be returned' |
||||||
|
} |
||||||
|
}) |
||||||
|
.perform(() => done()) |
||||||
|
}) |
||||||
|
}) |
||||||
|
.clickFunction('foo - call', { types: 'uint256 p', values: '1' })
|
||||||
|
.perform((done) => { |
||||||
|
browser.getAddressAtPosition(0, (address) => { |
||||||
|
browser |
||||||
|
.verifyCallReturnValue(address, (values: string[]) => { |
||||||
|
// should be looking like: ['0:bytes32: 0x0391a96b0b74805e5fbb79a18840548c5b6c0f1c5e933fc5e3ee015823856e00']
|
||||||
|
const value = values[0].replace('0:bytes32: ', '') |
||||||
|
let pass = value !== '0x0000000000000000000000000000000000000000000000000000000000000000' && value !== '0x' |
||||||
|
return { |
||||||
|
pass, |
||||||
|
message: pass ? 'pass' : 'a non empty blockhash should be returned' |
||||||
|
} |
||||||
|
}) |
||||||
|
.perform(() => done()) |
||||||
|
}) |
||||||
|
}).end() |
||||||
|
} |
||||||
|
} |
@ -1,25 +0,0 @@ |
|||||||
import { Block } from '@ethereumjs/block' |
|
||||||
import { ConsensusType } from '@ethereumjs/common' |
|
||||||
|
|
||||||
export function generateBlock (vmContext) { |
|
||||||
const common = vmContext.vmObject().common |
|
||||||
|
|
||||||
const difficulty = common.consensusType() === ConsensusType.ProofOfStake ? 0 : 69762765929000 |
|
||||||
|
|
||||||
return new Promise((resolve, reject) => { |
|
||||||
const block: Block = Block.fromBlockData({ |
|
||||||
header: { |
|
||||||
timestamp: (new Date().getTime() / 1000 | 0), |
|
||||||
number: 0, |
|
||||||
coinbase: '0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a', |
|
||||||
difficulty, |
|
||||||
gasLimit: 8000000 |
|
||||||
} |
|
||||||
}, { common: vmContext.vmObject().common }) |
|
||||||
|
|
||||||
vmContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }).then(() => { |
|
||||||
vmContext.addBlock(block) |
|
||||||
resolve({}) |
|
||||||
}).catch((e) => reject(e)) |
|
||||||
}) |
|
||||||
} |
|
Loading…
Reference in new issue