ganacheHelper.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. {
  7. jsonrpc: '2.0',
  8. id: Date.now(),
  9. method,
  10. params,
  11. },
  12. (err, res) => {
  13. return err ? reject(err) : resolve(res)
  14. },
  15. )
  16. })
  17. }
  18. const takeSnapshot = async () => {
  19. return await send('evm_snapshot')
  20. }
  21. const traceTransaction = async (tx) => {
  22. return await send('debug_traceTransaction', [tx, {}])
  23. }
  24. const revertSnapshot = async (id) => {
  25. await send('evm_revert', [id])
  26. }
  27. const mineBlock = async (timestamp) => {
  28. await send('evm_mine', [timestamp])
  29. }
  30. const increaseTime = async (seconds) => {
  31. await send('evm_increaseTime', [seconds])
  32. }
  33. const minerStop = async () => {
  34. await send('miner_stop', [])
  35. }
  36. const minerStart = async () => {
  37. await send('miner_start', [])
  38. }
  39. module.exports = {
  40. takeSnapshot,
  41. revertSnapshot,
  42. mineBlock,
  43. minerStop,
  44. minerStart,
  45. increaseTime,
  46. traceTransaction,
  47. }