timer.js 754 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. // timer for tests specific to testrpc
  3. // s is the amount of seconds to advance
  4. // if account is provided, will send a transaction from that account to force testrpc to mine the block
  5. module.exports = (s) => {
  6. return new Promise((resolve, reject) => {
  7. web3.currentProvider.sendAsync({
  8. jsonrpc: '2.0',
  9. method: 'evm_increaseTime',
  10. params: [s],
  11. id: new Date().getTime()
  12. }, function(err) {
  13. if (err) {
  14. return reject(err);
  15. }
  16. web3.currentProvider.sendAsync({
  17. jsonrpc: '2.0',
  18. method: 'evm_mine',
  19. id: new Date().getTime()
  20. }, (err, result) => {
  21. if (err) {
  22. return reject(err);
  23. }
  24. resolve(result);
  25. });
  26. });
  27. });
  28. };