ganacheHelper.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // This module is used only for tests
  2. function send(method, params = []) {
  3. return new Promise((resolve, reject) => {
  4. // eslint-disable-next-line no-undef
  5. web3.currentProvider.send({
  6. jsonrpc: '2.0',
  7. id: Date.now(),
  8. method,
  9. params,
  10. }, (err, res) => {
  11. return err ? reject(err) : resolve(res)
  12. })
  13. })
  14. }
  15. const takeSnapshot = async () => {
  16. return await send('evm_snapshot')
  17. }
  18. const traceTransaction = async (tx) => {
  19. return await send('debug_traceTransaction', [tx, {}])
  20. }
  21. const revertSnapshot = async (id) => {
  22. await send('evm_revert', [id])
  23. }
  24. const mineBlock = async (timestamp) => {
  25. await send('evm_mine', [timestamp])
  26. }
  27. const increaseTime = async (seconds) => {
  28. await send('evm_increaseTime', [seconds])
  29. }
  30. const minerStop = async () => {
  31. await send('miner_stop', [])
  32. }
  33. const minerStart = async () => {
  34. await send('miner_start', [])
  35. }
  36. module.exports = {
  37. takeSnapshot,
  38. revertSnapshot,
  39. mineBlock,
  40. minerStop,
  41. minerStart,
  42. increaseTime,
  43. traceTransaction,
  44. }