tornado-core/lib/ganacheHelper.js

53 lines
1.0 KiB
JavaScript
Raw Normal View History

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