UNPKG

@ajna-finance/sdk

Version:

A typescript SDK that can be used to create Dapps in Ajna ecosystem.

41 lines 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.takeSnapshot = takeSnapshot; exports.mine = mine; exports.revertToSnapshot = revertToSnapshot; exports.timeJump = timeJump; const tslib_1 = require("tslib"); const BLOCK_LENGTH = 12; function takeSnapshot(provider) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return +(yield provider.send('evm_snapshot', [])); }); } function mine(provider_1) { return tslib_1.__awaiter(this, arguments, void 0, function* (provider, blocks = 1, batchSize = 100000, progressCb) { // HACK: https://github.com/trufflesuite/ganache/issues/4409 while (blocks > batchSize) { yield provider.send('evm_increaseTime', [batchSize * BLOCK_LENGTH]); yield provider.send('evm_mine', [{ blocks: batchSize }]); blocks -= batchSize; progressCb === null || progressCb === void 0 ? void 0 : progressCb(blocks); } yield provider.send('evm_increaseTime', [blocks * BLOCK_LENGTH]); yield provider.send('evm_mine', [{ blocks: blocks }]); }); } // NOTE: due to API limitation, same snapshot couldn't be used twice for reverting function revertToSnapshot(provider, id) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const retval = !!(yield provider.send('evm_revert', [id])); yield mine(provider); return retval; }); } function timeJump(provider, seconds) { return tslib_1.__awaiter(this, void 0, void 0, function* () { yield provider.send('evm_increaseTime', [seconds]); yield mine(provider); }); } //# sourceMappingURL=ganache.js.map