diff --git a/content/tutorials/custom-zk-chain/10.index.md b/content/tutorials/custom-zk-chain/10.index.md index c4b82528..92170aa7 100644 --- a/content/tutorials/custom-zk-chain/10.index.md +++ b/content/tutorials/custom-zk-chain/10.index.md @@ -59,6 +59,9 @@ Make sure Docker is running on your machine. Move to a directory where you want your ecosystem folder to be, and run the command below to generate an ecosystem folder. +:test-action{actionId="project-folder"} +:test-action{actionId="create-ecosystem"} + ```bash zkstack ecosystem create ``` @@ -76,10 +79,10 @@ If you choose different names for your ecosystem or chain, remember to update th │ my_elastic_chain │ ◇ Select the origin of zksync-era repository -│ Clone for me (recommended) +│ Clone for me (recommended) │ ◇ Select the L1 network -│ Localhost +│ Localhost │ ◇ What do you want to name the chain? │ zk_chain_1 @@ -88,16 +91,19 @@ If you choose different names for your ecosystem or chain, remember to update th │ 271 │ ◇ Select how do you want to create the wallet -│ Localhost +│ Localhost │ ◇ Select the prover mode -│ NoProofs +│ NoProofs │ ◇ Select the commit data generator mode -│ Rollup +│ Rollup │ ◇ Select the base token to use -│ Eth +│ Eth +│ +◇ Enable EVM emulator? +│ No │ ◇ Do you want to start containers after creating the ecosystem? │ Yes @@ -123,16 +129,16 @@ By running this command and selecting these options, you just: You can read more about data availability options for ZK chains in the [ZK chains](https://docs.zksync.io/zk-stack/concepts/zk-chains#data-availability-da) docs. - Selected ETH to use as the base token. +- Opted to not enable the EVM emulator. - Started the containers for the ecosystem in Docker. Inside the generated `my_elastic_chain` folder, you should now have the following contents: -- `ZkStack.yaml`: a configuration file for the ecosystem. - `chains`: a folder with configurations for each chain created. -- `configs`: configuration for the deployments and wallets. -- `volumes`: dependencies for running local nodes. +- `configs`: configurations for the deployments and wallets. - `zksync-era`: a clone of the `zksync-era` repository. - `docker-compose.yml`: a Docker compose file to start up a local environment. +- `ZkStack.yaml`: a configuration file for the ecosystem. ## Deploying the ecosystem @@ -144,12 +150,17 @@ The next step is to deploy your ecosystem contracts to the L1 and register your Move into the ecosystem folder: +:test-action{actionId="move-to-ecosystem-folder"} + ```bash cd my_elastic_chain ``` Next, run the `zkstack ecosystem init` command below to deploy the ecosystem: +:test-action{actionId="add-tsconfig"} +:test-action{actionId="init-ecosystem"} + ```bash zkstack ecosystem init --dev ``` @@ -200,6 +211,8 @@ Never commit your private keys or sensitive secrets. The last step here is to start a server for `zk_chain_1`: +:test-action{actionId="start-server"} + ```bash zkstack server ``` @@ -219,6 +232,8 @@ Never use these wallets in production or send real funds to them. Open a new terminal and run the command below to bridge some ETH to `zk_chain_1` using ZKsync CLI: +:test-action{actionId="deposit-eth"} + ```bash npx zksync-cli bridge deposit --rpc=http://localhost:3050 --l1-rpc=http://localhost:8545 ``` @@ -233,6 +248,8 @@ For testing purposes, we'll use one of the rich wallets as both the sender and r To see that it worked, let's check the balance of that address on `zk_chain_1`: +:test-action{actionId="check-balance"} + ```bash npx zksync-cli wallet balance \ --address 0x36615Cf349d7F6344891B1e7CA7C72883F5dc049 \ @@ -247,6 +264,8 @@ Now that your chain is deployed and your wallet is funded, let's create a templa Move out of your ecosystem folder and initialize a new hardhat project using ZKsync CLI: +:test-action{actionId="create-test-project"} + ```bash npx zksync-cli@latest create --template zksync-101 zk-chain-test cd zk-chain-test @@ -254,24 +273,52 @@ cd zk-chain-test Use the same private key for the rich wallet: +:test-action{actionId="npm-install"} +:test-action{actionId="add-pk"} + ```shell ? Private key of the wallet responsible for deploying contracts (optional) 0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110 ``` -In the `hardhat.config.ts` file, change the default network on line 6 to `dockerizedNode`, -which is already configured to connect to the local chain node running on port `3050`: +In the `hardhat.config.ts` file, let's add the local network and configure it as the default: -```bash +:test-action{actionId="change-network"} + +```ts defaultNetwork: "dockerizedNode", + networks: { + dockerizedNode: { + url: 'http://localhost:3050', + ethNetwork: 'http://localhost:8545', + zksync: true, + }, ``` Finally, compile the contract and run the deploy script: -```bash +:test-action{actionId="compile-and-deploy"} + +::code-group + +```bash [npm] +npm run compile && npm run deploy:hello-zksync +``` + +```bash [yarn] yarn compile && yarn deploy:hello-zksync ``` +```bash [pnpm] +pnpm compile && pnpm deploy:hello-zksync +``` + +```bash [bun] +bun compile && bun deploy:hello-zksync +``` + +:: + Nice - you just deployed a contract to your own local ZK chain! Next, let's take a look at customizing a chain. diff --git a/content/tutorials/custom-zk-chain/20.customizing-your-chain.md b/content/tutorials/custom-zk-chain/20.customizing-your-chain.md index 99352600..f64541da 100644 --- a/content/tutorials/custom-zk-chain/20.customizing-your-chain.md +++ b/content/tutorials/custom-zk-chain/20.customizing-your-chain.md @@ -36,6 +36,8 @@ cd base-token-contract Then, run the `hardhat init` command to generate a new project: +:test-action{actionId="new-hh-project"} + ```bash npx hardhat init ``` @@ -44,6 +46,8 @@ Select the option **Create a Typescript project** and accept the default options Run the command below to install the necessary dependencies: +:test-action{actionId="install-token-deps"} + ::code-group ```bash [npm] @@ -60,7 +64,9 @@ yarn add -D typescript ts-node @openzeppelin/contracts @nomicfoundation/hardhat- Once installed, replace your existing config in `hardhat.config.ts` with the config below: -```ts +:test-action{actionId="hh-config"} + +```ts [hardhat.config.ts] import { HardhatUserConfig } from "hardhat/config"; import "@nomicfoundation/hardhat-toolbox"; @@ -86,6 +92,8 @@ However, in the future this may change. Next, create a `.env` file with: +:test-action{actionId="create-env"} + ```bash touch .env ``` @@ -93,9 +101,11 @@ touch .env Add the governor private key from our elastic_chain setup to ensure that this address becomes the owner of the token contract. Here's how you can add the `WALLET_PRIVATE_KEY` environment variable: -```bash +:test-action{actionId="new-env"} + +```bash [.env] # Use the private key of the `governor` from wallet.yaml -WALLET_PRIVATE_KEY= +WALLET_PRIVATE_KEY= ``` ### Deploying an ERC20 Contract @@ -103,13 +113,17 @@ WALLET_PRIVATE_KEY= Now that we've configured hardhat and the deployer wallet, let's add the contract and deploy script. Rename the example generated contract file to `CustomBaseToken.sol`: +:test-action{actionId="rename-contract-file"} + ```bash mv contracts/Lock.sol contracts/CustomBaseToken.sol ``` Open the `CustomBaseToken.sol` file and replace the example contract with the ERC20 contract below: -```solidity +:test-action{actionId="token-contract"} + +```solidity [CustomBaseToken.sol] // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.20; @@ -131,13 +145,17 @@ contract CustomBaseToken is ERC20, Ownable, ERC20Burnable { Next, let's update the ignition module to deploy the ERC20 contract. Rename the module file with the command below: +:test-action{actionId="rename-module"} + ```bash mv ignition/modules/Lock.ts ignition/modules/CustomBaseToken.ts ``` Then, replace the module file with the code below: -```ts +:test-action{actionId="new-deploy-module"} + +```ts [CustomBaseToken.ts] import { buildModule } from "@nomicfoundation/hardhat-ignition/modules"; const CustomBaseTokenModule = buildModule("CustomBaseTokenModule", (m) => { @@ -154,6 +172,9 @@ export default CustomBaseTokenModule; To run the module and deploy the token contract, run: +:test-action{actionId="ignore-deploy-confirm"} +:test-action{actionId="deploy-token-contract"} + ```bash npx hardhat ignition deploy ./ignition/modules/CustomBaseToken.ts --network localRethNode ``` @@ -164,6 +185,9 @@ After deploying, the token contract address should be logged in your console. The constructor function in the contract should have minted tokens to the deployer address. Let's verify that the tokens were minted to the deployer address using the Foundry `cast` CLI: +:test-action{actionId="get-contract-address"} +:test-action{actionId="check-token-balance"} + ```bash cast balance --erc20 <0xYOUR_TOKEN_ADDRESS> 0x36615Cf349d7F6344891B1e7CA7C72883F5dc049 \ --rpc-url http://localhost:8545 @@ -175,8 +199,16 @@ Now that your ERC20 token is deployed, you can create a new chain. First, shut down the node server running for `zk_chain_1` by terminating the process. +:test-action{actionId="shutdown-server"} + +```bash +zkstack chain create +``` + Move back into your elastic chain ecosystem folder and run the `zkstack chain create` subcommand: +:test-action{actionId="create-new-chain"} + ```bash zkstack chain create ``` @@ -224,22 +256,34 @@ For example, if we set the nominator to 20 and the denominator to 1, together th this would mean that 20 tokens would be given the equivalent value as 1 ETH for gas. For testing purposes, we'll just use a 1:1 ratio. +:test-action{actionId="get-gov-address"} +:test-action{actionId="fund-other"} +:test-action{actionId="fund-gov"} + +```bash +cast send <0x_BASE_TOKEN_ADDRESS> "transfer(address,uint256)" <0x_GOVERNOR_ADDRESS> 500000000000000000 --private-key 0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110 --rpc-url http://localhost:8545 --gas-price 30000000000 +``` + ### Initializing the chain ::callout{icon="i-heroicons-exclamation-triangle" color="amber"} Make sure the server for `zk_chain_1` that you started in the previous section is shut down. :: -Next, initialize the chain in the ecosystem with the command below, and select the default options for the prompts. +Next, initialize the chain in the ecosystem with the command below. + +:test-action{actionId="init-new-chain"} ```bash -zkstack chain init +zkstack chain init --dev ``` During the initialization process, your ERC20 token address gets added to the allowlist mentioned earlier. Now that the chain is initialized, you can start the chain server: +:test-action{actionId="start-server-2"} + ```bash zkstack server ``` @@ -251,6 +295,8 @@ Base tokens can not be minted on the L2 without being backed by the correspondin Open a new terminal and use ZKsync CLI to bridge the tokens with the command below: +:test-action{actionId="bridge-tokens"} + ```bash npx zksync-cli bridge deposit --token <0x_YOUR_TOKEN_ADDRESS> \ --rpc=http://localhost:3050 \ @@ -265,6 +311,8 @@ npx zksync-cli bridge deposit --token <0x_YOUR_TOKEN_ADDRESS> \ To verify that this worked, let's check the new balance of our address on the L2 chain: +:test-action{actionId="l2-token-balance"} + ```bash npx zksync-cli wallet balance \ --address 0x36615Cf349d7F6344891B1e7CA7C72883F5dc049 \ @@ -285,6 +333,8 @@ The answer is that if you try to bridge regular ETH to this chain, it will just You can try this out by depositing ETH from the L1 to this new chain: +:test-action{actionId="bridge-ETH"} + ```bash npx zksync-cli bridge deposit \ --rpc=http://localhost:3050 \ @@ -304,6 +354,8 @@ To find the L2 token address for ETH, you can use the `l2TokenAddress` method av To try this out, open your hardhat project `zk-chain-test` from the previous section, and run the commands below to create a new script file: +:test-action{actionId="create-script"} + ```bash mkdir scripts touch scripts/checkBalance.ts @@ -311,6 +363,8 @@ touch scripts/checkBalance.ts Next, copy and paste the script below into the `checkBalance.ts` file: +:test-action{actionId="l2-eth-address-script"} + ```ts import { ETH_ADDRESS_IN_CONTRACTS } from "zksync-ethers/build/utils.js"; import { getWallet } from "../deploy/utils"; @@ -329,6 +383,8 @@ main(); Run the script with the `hardhat run` command: +:test-action{actionId="run-address-script"} + ```bash npx hardhat run scripts/checkBalance.ts ``` diff --git a/content/tutorials/custom-zk-chain/_dir.yml b/content/tutorials/custom-zk-chain/_dir.yml index 5575efbd..fc73fde4 100644 --- a/content/tutorials/custom-zk-chain/_dir.yml +++ b/content/tutorials/custom-zk-chain/_dir.yml @@ -15,7 +15,7 @@ what_you_will_learn: - How to create and locally run an Elastic Chain ecosystem. - How to create a ZK chain and deploy a contract to it. - How to setup a ZK chain with a custom base token. -updated: 2024-08-14 +updated: 2024-12-11 tools: - zkstack - hardhat diff --git a/playwright.config.ts b/playwright.config.ts index 56704d3e..419a09e9 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -30,7 +30,7 @@ export default defineConfig({ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on', }, - timeout: 8 * 60 * 1000, + timeout: 50 * 60 * 1000, /* Configure projects for major browsers */ projects: [ diff --git a/tests/configs/config.ts b/tests/configs/config.ts index 4c30b086..bcdf7ce1 100644 --- a/tests/configs/config.ts +++ b/tests/configs/config.ts @@ -4,6 +4,7 @@ import { steps as dailySpendLimitSteps } from './daily-spend-limit'; import { steps as signingWithWebAuthnSteps } from './signing-txns-with-webauthn'; import { steps as multisigSteps } from './native-aa-multisig'; import { steps as frontendPaymasterSteps } from './frontend-paymaster'; +import { steps as customZKChainSteps } from './custom-zk-chain'; export function getConfig(tutorialName: string) { let steps; @@ -26,6 +27,9 @@ export function getConfig(tutorialName: string) { case 'frontend-paymaster': steps = frontendPaymasterSteps; break; + case 'custom-zk-chain': + steps = customZKChainSteps; + break; default: break; } diff --git a/tests/configs/custom-zk-chain.ts b/tests/configs/custom-zk-chain.ts new file mode 100644 index 00000000..29a6ad0d --- /dev/null +++ b/tests/configs/custom-zk-chain.ts @@ -0,0 +1,228 @@ +import type { IStepConfig } from '../utils/types'; + +const chainID = 281; + +const partOneSteps: IStepConfig = { + 'project-folder': { + action: 'runCommand', + useSetCommand: 'mkdir custom-zk-chain', + }, + 'create-ecosystem': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain', + useSetCommand: `zkstack ecosystem create --ecosystem-name my_elastic_chain --l1-network localhost --chain-name zk_chain_1 --chain-id 271 --prover-mode no-proofs --wallet-creation localhost --l1-batch-commit-data-generator-mode rollup --evm-emulator false --base-token-address 0x0000000000000000000000000000000000000001 --start-containers true --base-token-price-nominator 1 --base-token-price-denominator 1`, + prompts: 'Clone for me:', + waitTime: 60000 * 7, + }, + 'move-to-ecosystem-folder': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain', + }, + 'add-tsconfig': { + action: 'writeToFile', + filepath: 'tests-output/tsconfig.json', + useSetData: `{ + "compilerOptions": { + "target": "es2020", + "module": "commonjs", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true + } + } + `, + }, + 'init-ecosystem': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/my_elastic_chain', + waitTime: 60000 * 15, + prompts: 'thisIsRandomJustToTestSomething: ', + }, + 'start-server': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/my_elastic_chain', + preCommand: "bun pm2 start '' --name zk_chain_1_server", + waitTime: 30000, + }, + 'deposit-eth': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/my_elastic_chain', + prompts: + 'Amount to deposit:9|Private key of the sender:0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110|Recipient address on L2:', + }, + 'check-balance': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/my_elastic_chain', + }, + 'create-test-project': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain', + prompts: 'Private key of the wallet responsible:', + }, + 'npm-install': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/zk-chain-test', + useSetCommand: 'npm install', + }, + 'add-pk': { + action: 'modifyFile', + filepath: 'tests-output/custom-zk-chain/zk-chain-test/.env', + useSetData: `WALLET_PRIVATE_KEY=0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110`, + atLine: 3, + removeLines: [3], + }, + 'change-network': { + action: 'modifyFile', + filepath: 'tests-output/custom-zk-chain/zk-chain-test/hardhat.config.ts', + atLine: 9, + removeLines: [9, 10], + }, + 'compile-and-deploy': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/zk-chain-test', + }, +}; + +const partTwoSteps: IStepConfig = { + 'new-hh-project': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain', + projectFolder: 'base-token-contract', + }, + 'install-token-deps': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/base-token-contract', + }, + 'hh-config': { + action: 'writeToFile', + filepath: 'tests-output/custom-zk-chain/base-token-contract/hardhat.config.ts', + }, + 'create-env': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/base-token-contract', + }, + 'new-env': { + action: 'extractDataToEnv', + dataFilepath: 'tests-output/custom-zk-chain/my_elastic_chain/configs/wallets.yaml', + envFilepath: 'tests-output/custom-zk-chain/base-token-contract/.env', + regex: /0x[a-fA-F0-9a-zA-Z]{64,}/g, + variableName: 'WALLET_PRIVATE_KEY', + }, + 'rename-contract-file': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/base-token-contract', + }, + 'token-contract': { + action: 'writeToFile', + filepath: 'tests-output/custom-zk-chain/base-token-contract/contracts/CustomBaseToken.sol', + }, + 'rename-module': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/base-token-contract', + }, + 'new-deploy-module': { + action: 'writeToFile', + filepath: 'tests-output/custom-zk-chain/base-token-contract/ignition/modules/CustomBaseToken.ts', + }, + 'ignore-deploy-confirm': { + action: 'modifyFile', + filepath: 'tests-output/custom-zk-chain/base-token-contract/.env', + atLine: 2, + useSetData: 'HARDHAT_IGNITION_CONFIRM_DEPLOYMENT=false', + }, + 'deploy-token-contract': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/base-token-contract', + saveOutput: 'tests-output/custom-zk-chain/base-token-contract/deployed.txt', + }, + 'get-contract-address': { + action: 'extractDataToEnv', + dataFilepath: 'tests-output/custom-zk-chain/base-token-contract/deployed.txt', + envFilepath: 'tests-output/custom-zk-chain/my_elastic_chain/.env', + regex: /0x[a-fA-F0-9]{40}/, + variableName: 'BASE_TOKEN_ADDRESS', + }, + 'check-token-balance': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/my_elastic_chain', + replaceString: '<0xYOUR_TOKEN_ADDRESS>:$BASE_TOKEN_ADDRESS', + preCommand: 'source .env && ', + checkForOutput: '100000000000000000000 [1e20]', + }, + 'shutdown-server': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/my_elastic_chain', + useSetCommand: 'bun pm2 stop zk_chain_1_server', + }, + 'create-new-chain': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/my_elastic_chain', + preCommand: `source .env && --chain-name custom_zk_chain_${chainID} --chain-id ${chainID} --prover-mode no-proofs --wallet-creation localhost --l1-batch-commit-data-generator-mode rollup --base-token-address $BASE_TOKEN_ADDRESS --base-token-price-nominator 1 --base-token-price-denominator 1 --set-as-default true --evm-emulator false`, + waitTime: 30000, + }, + 'get-gov-address': { + action: 'extractDataToEnv', + dataFilepath: `tests-output/custom-zk-chain/my_elastic_chain/chains/custom_zk_chain_${chainID}/configs/wallets.yaml`, + envFilepath: 'tests-output/custom-zk-chain/my_elastic_chain/.env', + regex: /(?<=governor:\n\s+address:\s+)0x[a-fA-F0-9]{40}/, + variableName: 'GOVERNOR_ADDRESS', + }, + 'fund-gov': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/my_elastic_chain', + replaceString: '<0x_BASE_TOKEN_ADDRESS>:$BASE_TOKEN_ADDRESS|<0x_GOVERNOR_ADDRESS>:$GOVERNOR_ADDRESS', + preCommand: 'source .env && ', + }, + 'fund-other': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/my_elastic_chain', + replaceString: + '<0x_BASE_TOKEN_ADDRESS>:$BASE_TOKEN_ADDRESS|<0x_GOVERNOR_ADDRESS>:0x8002cD98Cfb563492A6fB3E7C8243b7B9Ad4cc92', + preCommand: 'source .env && ', + }, + 'init-new-chain': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/my_elastic_chain', + waitTime: 60000 * 5, + }, + 'start-server-2': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/my_elastic_chain', + preCommand: `bun pm2 start '' --name custom_zk_chain_${chainID}_server`, + waitTime: 30000, + }, + 'bridge-tokens': { + action: 'runCommand', + prompts: + 'Amount to deposit:5|Private key of the sender:0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110|Recipient address on L2:', + // TODO: checkForOutput: '' + }, + 'l2-token-balance': { + action: 'runCommand', + // TODO: checkForOutput: '' + }, + 'bridge-ETH': { + action: 'runCommand', + prompts: + 'Amount to deposit:20|Private key of the sender:0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110|Recipient address on L2:', + // TODO: checkForOutput: '' + }, + 'create-script': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/zk-chain-test', + }, + 'l2-eth-address-script': { + action: 'writeToFile', + filepath: 'tests-output/custom-zk-chain/zk-chain-test/scripts/checkBalance.ts', + }, + 'run-address-script': { + action: 'runCommand', + commandFolder: 'tests-output/custom-zk-chain/zk-chain-test', + checkForOutput: 'L2 ETH Balance 🎉: 20000000000000000000n', + }, +}; + +export const steps: IStepConfig = { + ...partOneSteps, + ...partTwoSteps, +}; diff --git a/tests/custom-zk-chain.spec.ts b/tests/custom-zk-chain.spec.ts new file mode 100644 index 00000000..a07b1d53 --- /dev/null +++ b/tests/custom-zk-chain.spec.ts @@ -0,0 +1,14 @@ +import { test } from '@playwright/test'; +import { setupAndRunTest } from './utils/runTest'; + +test('Custom ZK Chain', async ({ page, context }) => { + await setupAndRunTest( + page, + context, + [ + // '/custom-zk-chain', + '/custom-zk-chain/customizing-your-chain', + ], + 'custom-zk-chain' + ); +}); diff --git a/tests/utils/runCommand.ts b/tests/utils/runCommand.ts index fa9e03b7..e1122d04 100644 --- a/tests/utils/runCommand.ts +++ b/tests/utils/runCommand.ts @@ -12,18 +12,29 @@ export async function runCommand( buttonName: string, goToFolder: string = 'tests-output', projectFolder: string = 'hardhat-project', + waitTime?: number, preCommand?: string, useSetCommand?: string, prompts?: string, saveOutput?: string, checkForOutput?: string, - expectError?: string + expectError?: string, + replaceString?: string ) { + const thisWaitTime = waitTime ? waitTime : prompts ? 35000 : 15000; + console.log('WAIT TIME', thisWaitTime); let command = useSetCommand; if (!command) { command = await clickCopyButton(page, buttonName); console.log('COPIED', command); } + if (replaceString) { + const split = replaceString.split('|'); + split.forEach((replaceString) => { + const splitReplace = replaceString.split(':'); + command = command?.replace(splitReplace[0], splitReplace[1]); + }); + } const copied = command; const newHardhatProject = command.includes('npx hardhat init'); @@ -47,15 +58,16 @@ export async function runCommand( } else { await run(command, saveOutput, checkForOutput, expectError); } + await page.waitForTimeout(thisWaitTime); + console.log(`waited ${thisWaitTime / 1000} seconds`); } - await page.waitForTimeout(1500); } async function run(command: string, saveOutput?: string, checkForOutput?: string, expectError?: string): Promise { console.log('RUNNING COMMAND:', command); return new Promise((resolve, reject) => { - exec(command, { encoding: 'utf-8' }, (error, stdout, stderr) => { + exec(command, { encoding: 'utf-8', maxBuffer: 1024 * 1024 * 10 }, (error, stdout, stderr) => { if (error) { if (expectError) { console.log('EXPECT ERROR', expectError); @@ -74,6 +86,7 @@ async function run(command: string, saveOutput?: string, checkForOutput?: string } else { if (checkForOutput) { expect(stdout).toContain(checkForOutput); + console.log('✅ FOUND OUTPUT:', checkForOutput); } if (saveOutput && stdout) { @@ -149,7 +162,4 @@ export async function runWithPrompts(page: Page, command: string, prompts: strin }); ptyProcess.write(command + '\r'); - - await page.waitForTimeout(35000); - console.log('waited 35 seconds'); } diff --git a/tests/utils/runTest.ts b/tests/utils/runTest.ts index 3f81d303..69ce58c6 100644 --- a/tests/utils/runTest.ts +++ b/tests/utils/runTest.ts @@ -64,12 +64,14 @@ export async function runTest( stepID, stepData.commandFolder, stepData.projectFolder, + stepData.waitTime, stepData.preCommand, stepData.useSetCommand, stepData.prompts, stepData.saveOutput, stepData.checkForOutput, - stepData.expectError + stepData.expectError, + stepData.replaceString ); break; case 'wait': diff --git a/tests/utils/types.ts b/tests/utils/types.ts index f95ef0ed..5a0649f6 100644 --- a/tests/utils/types.ts +++ b/tests/utils/types.ts @@ -27,6 +27,8 @@ export interface IRunCommand { projectFolder?: string; // add something before the command preCommand?: string; + // how long to wait after running the command + waitTime?: number; // use this command instead of copying from the page useSetCommand?: string; // if the command has prompts, pass them here @@ -38,6 +40,10 @@ export interface IRunCommand { checkForOutput?: string; // if the command is expected to fail, pass at least part of the error message here expectError?: string; + // replace a string in the command with another string + // ex: "<0x_YOUR_ADDRESS>:0x123" + // replaces "<0x_YOUR_ADDRESS>" with "0x123" + replaceString?: string; } export interface IWait { diff --git a/tsconfig.json b/tsconfig.json index 727b4ff5..3344e21c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { // https://nuxt.com/docs/guide/concepts/typescript "extends": "./.nuxt/tsconfig.json", - "exclude": ["code", "tests-output"] + "exclude": ["code", "tests-output", "tests-output/**/*", "**/tests-output/**"] }