Skip to content

Commit

Permalink
feat: add fast-forward script for demo
Browse files Browse the repository at this point in the history
  • Loading branch information
idea404 committed Nov 12, 2023
1 parent 570cac5 commit 27d64b6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
28 changes: 28 additions & 0 deletions demo/fast-forward.ts
Original file line number Diff line number Diff line change
@@ -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);
});

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 27d64b6

Please sign in to comment.