tornado-core/lib/ganacheHelper.js

48 lines
912 B
JavaScript
Raw Normal View History

2019-07-18 14:41:18 -04:00
// This module is used only for tests
2019-07-10 12:58:21 -04:00
function send(method, params = []) {
return new Promise((resolve, reject) => {
2019-07-16 11:58:42 -04:00
// eslint-disable-next-line no-undef
2019-07-10 12:58:21 -04:00
web3.currentProvider.send({
jsonrpc: '2.0',
id: Date.now(),
method,
params
}, (err, res) => {
2019-07-16 11:58:42 -04:00
return err ? reject(err) : resolve(res)
})
})
2019-07-10 12:58:21 -04:00
}
2019-07-16 11:58:42 -04:00
const takeSnapshot = async () => {
return await send('evm_snapshot')
2019-07-10 12:58:21 -04:00
}
const revertSnapshot = async (id) => {
2019-07-16 11:58:42 -04:00
await send('evm_revert', [id])
2019-07-10 12:58:21 -04:00
}
const mineBlock = async (timestamp) => {
2019-07-16 11:58:42 -04:00
await send('evm_mine', [timestamp])
2019-07-10 12:58:21 -04:00
}
const increaseTime = async (seconds) => {
2019-07-16 11:58:42 -04:00
await send('evm_increaseTime', [seconds])
2019-07-10 12:58:21 -04:00
}
const minerStop = async () => {
2019-07-16 11:58:42 -04:00
await send('miner_stop', [])
2019-07-10 12:58:21 -04:00
}
const minerStart = async () => {
2019-07-16 11:58:42 -04:00
await send('miner_start', [])
2019-07-10 12:58:21 -04:00
}
module.exports = {
takeSnapshot,
revertSnapshot,
mineBlock,
minerStop,
minerStart,
increaseTime,
2019-07-16 11:58:42 -04:00
}