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,
|
2021-02-11 01:23:18 -05:00
|
|
|
params,
|
2019-07-10 12:58:21 -04:00
|
|
|
}, (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
|
|
|
}
|
|
|
|
|
2019-10-25 07:12:28 -04:00
|
|
|
const traceTransaction = async (tx) => {
|
|
|
|
return await send('debug_traceTransaction', [tx, {}])
|
|
|
|
}
|
|
|
|
|
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,
|
2021-02-11 01:23:18 -05:00
|
|
|
traceTransaction,
|
2019-07-16 11:58:42 -04:00
|
|
|
}
|