From 27d64b69285a215bdc83aa29406dc36d8083fff0 Mon Sep 17 00:00:00 2001 From: Dennis <10233439+idea404@users.noreply.github.com> Date: Sun, 12 Nov 2023 14:50:35 +0100 Subject: [PATCH] feat: add fast-forward script for demo --- demo/fast-forward.ts | 28 ++++++++++++++++++++++++++++ package.json | 3 ++- test/utils.ts | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 demo/fast-forward.ts diff --git a/demo/fast-forward.ts b/demo/fast-forward.ts new file mode 100644 index 0000000..88e9c71 --- /dev/null +++ b/demo/fast-forward.ts @@ -0,0 +1,28 @@ +// This script will: +// 1. fast forward the blockchain by 10 blocks + +import { config } from "../deploy/utils"; +import * as zks from "zksync-web3"; + +const RPC_URL = config.L2RpcUrl; + +async function advanceBlocks(blockCount: number, provider: zks.Provider) { + for (let i = 0; i < blockCount; i++) { + // Use the 'send' method to send the 'evm_mine' request + await provider.send('evm_mine', []); + } +} + +async function main() { + // Create a new provider instance + const provider = new zks.Provider(RPC_URL); + // Fast forward the blockchain by 10 blocks + await advanceBlocks(10, provider); + console.log(`Fast forwarded 10 blocks`); +} + +main().catch((error) => { + console.error(error); + process.exit(1); +}); + diff --git a/package.json b/package.json index 602b771..ec64b54 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "deploy:pension": "hardhat deploy-zksync --script deploy-pension.ts --network zkSyncLocalnet", "demo:pension-setup": "yarn deploy:pafactory && yarn deploy:pension && yarn demo:pension-fund", "demo:pension-fund": "ts-node demo/pension-fund-eth.ts", - "demo:pension-withdraw": "ts-node demo/pension-send-eth.ts" + "demo:pension-withdraw": "ts-node demo/pension-send-eth.ts", + "demo:fast-forward": "ts-node demo/fast-forward.ts" }, "devDependencies": { "@types/chai": "^4.3.10", diff --git a/test/utils.ts b/test/utils.ts index d9dcaca..65837de 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -175,7 +175,7 @@ function createMockAddress(base: string) { } // Helper function to advance the blockchain by a specified number of blocks -export async function advanceBlocks(numberOfBlocks) { +export async function advanceBlocks(numberOfBlocks: number) { for (let i = 0; i < numberOfBlocks; i++) { await hre.network.provider.request({ method: "evm_mine",