ganacheHelper.js 912 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 revertSnapshot = async (id) => {
  19. await send('evm_revert', [id])
  20. }
  21. const mineBlock = async (timestamp) => {
  22. await send('evm_mine', [timestamp])
  23. }
  24. const increaseTime = async (seconds) => {
  25. await send('evm_increaseTime', [seconds])
  26. }
  27. const minerStop = async () => {
  28. await send('miner_stop', [])
  29. }
  30. const minerStart = async () => {
  31. await send('miner_start', [])
  32. }
  33. module.exports = {
  34. takeSnapshot,
  35. revertSnapshot,
  36. mineBlock,
  37. minerStop,
  38. minerStart,
  39. increaseTime,
  40. }