-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add erc20 paymaster test and refactor testing
- Loading branch information
1 parent
3737777
commit 7453c9a
Showing
15 changed files
with
492 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ During the alpha phase, ZKsync Era Test Nodes are currently undergoing developme | |
|
||
First, initialize a new Hardhat TypeScript project: | ||
|
||
<span id="initialize-hardhat-project" data-name="runCommand"></span> | ||
<span id="initialize-hardhat-project" data-test-action></span> | ||
|
||
```bash | ||
npx hardhat init | ||
|
@@ -36,7 +36,7 @@ Select the `Create a TypeScript project` option and install the sample project's | |
|
||
To install the `hardhat-zksync` plugin, execute the following command: | ||
|
||
<span id="install-hh-zksync" data-name="runCommand" data-command-folder="tests-output/hardhat-project"></span> | ||
<span id="install-hh-zksync" data-test-action></span> | ||
|
||
::code-group | ||
|
||
|
@@ -52,8 +52,7 @@ yarn add -D @matterlabs/hardhat-zksync | |
|
||
Once installed, add the plugin at the top of your `hardhat.config.ts` file. | ||
|
||
<span id="import-zksync-config" data-name="modifyFile" data-filepath="tests-output/hardhat-project/hardhat.config.ts" | ||
data-at-line="3"></span> | ||
<span id="import-zksync-config" data-test-action></span> | ||
|
||
```ts [hardhat.config.ts] | ||
import "@matterlabs/hardhat-zksync"; | ||
|
@@ -63,7 +62,7 @@ import "@matterlabs/hardhat-zksync"; | |
|
||
You can now safely run the **ZKsync Era Test Node** with the following command: | ||
|
||
<span id="run-hh-node" data-name="runCommand" data-command-folder="tests-output/hardhat-project" data-pre-command="bun pm2 start '<COMMAND>' --name hh-zknode"></span> | ||
<span id="run-hh-node" data-test-action></span> | ||
|
||
::code-group | ||
|
||
|
@@ -77,9 +76,9 @@ yarn hardhat node-zksync | |
|
||
:: | ||
|
||
<span id="wait-for-hh-node" data-name="wait" data-timeout="6000"></span> | ||
<span id="wait-for-hh-node" data-test-action></span> | ||
|
||
<span id="test-hh-node" data-name="checkIfBalanceIsZero" data-network-url="http://127.0.0.1:8011" data-address="0xe2b8Cb53a43a56d4d2AB6131C81Bd76B86D3AFe5"></span> | ||
<span id="test-hh-node" data-test-action></span> | ||
|
||
::callout{icon="i-heroicons-exclamation-circle"} | ||
We'll want to verify the correctness of our installations and test if we can run a **ZKsync Era Test Node**, | ||
|
@@ -107,8 +106,7 @@ To enable the usage of ZKsync Era Test Node in Hardhat, | |
add the `zksync:true` option to the hardhat network in the `hardhat.config.ts` file | ||
and the `latest` version of `zksolc`: | ||
|
||
<span id="zksync-hh-network" data-name="modifyFile" data-filepath="tests-output/hardhat-project/hardhat.config.ts" | ||
data-at-line="7"></span> | ||
<span id="zksync-hh-network" data-test-action></span> | ||
|
||
```ts | ||
zksolc: { | ||
|
@@ -128,7 +126,7 @@ it's necessary to use the `hardhat-chai-matchers` plugin. | |
|
||
In the root directory of your project, execute this command: | ||
|
||
<span id="install-chai-ethers" data-name="runCommand" data-command-folder="tests-output/hardhat-project" data-pre-command="<COMMAND>"></span> | ||
<span id="install-chai-ethers" data-test-action></span> | ||
|
||
::code-group | ||
|
||
|
@@ -144,16 +142,15 @@ yarn add -D @nomicfoundation/hardhat-chai-matchers [email protected] | |
|
||
After installing it, add the plugin at the top of your `hardhat.config.ts` file: | ||
|
||
<span id="import-chai-matchers" data-name="modifyFile" data-filepath="tests-output/hardhat-project/hardhat.config.ts" | ||
data-at-line="4"></span> | ||
<span id="import-chai-matchers" data-test-action></span> | ||
|
||
```ts [hardhat.config.ts] | ||
import "@nomicfoundation/hardhat-chai-matchers"; | ||
``` | ||
|
||
With the previous steps completed, your `hardhat.config.ts` file should now be properly configured to include settings for local testing. | ||
|
||
<span id="compare-config" data-name="compareToFile" data-filepath="tests-output/hardhat-project/hardhat.config.ts"></span> | ||
<span id="compare-config" data-test-action></span> | ||
|
||
```ts [hardhat.config.ts] | ||
import { HardhatUserConfig } from "hardhat/config"; | ||
|
@@ -182,15 +179,15 @@ To set up the environment for using chai matchers and writing tests, you'll need | |
|
||
Inside the **contracts** folder, rename the example contract file to **Greeter.sol**. | ||
|
||
<span id="rename-greeter-file" data-name="runCommand" data-command-folder="tests-output/hardhat-project"></span> | ||
<span id="rename-greeter-file" data-test-action></span> | ||
|
||
```bash | ||
mv contracts/Lock.sol contracts/Greeter.sol | ||
``` | ||
|
||
Now replace the example contract in **Greeter.sol** with the new `Greeter` contract below: | ||
|
||
<span id="create-greeter-contract" data-name="writeToFile" data-filepath="tests-output/hardhat-project/contracts/Greeter.sol"></span> | ||
<span id="create-greeter-contract" data-test-action></span> | ||
|
||
```solidity [Greeter.sol] | ||
// SPDX-License-Identifier: MIT | ||
|
@@ -223,15 +220,15 @@ Now you can create a test with the `hardhat-chai-matchers` plugin: | |
|
||
Inside the `/test` folder, rename the example test file to `test.ts`. | ||
|
||
<span id="rename-test-file" data-name="runCommand" data-command-folder="tests-output/hardhat-project"></span> | ||
<span id="rename-test-file" data-test-action></span> | ||
|
||
```bash | ||
mv test/Lock.ts test/test.ts | ||
``` | ||
|
||
Replace the old test with this example showcasing the functionalities of the contract: | ||
|
||
<span id="create-test" data-name="writeToFile" data-filepath="tests-output/hardhat-project/test/test.ts"></span> | ||
<span id="create-test" data-test-action></span> | ||
|
||
```typescript | ||
import * as hre from "hardhat"; | ||
|
@@ -284,7 +281,7 @@ describe("Greeter", function () { | |
|
||
Execute the following command in your terminal to run the tests: | ||
|
||
<span id="run-test" data-name="runCommand" data-command-folder="tests-output/hardhat-project"></span> | ||
<span id="run-test" data-test-action></span> | ||
|
||
::code-group | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { steps as erc20PaymasterSteps } from './erc20-paymaster'; | ||
import { steps as howToTestContractsSteps } from './how-to-test-contracts'; | ||
|
||
export function getConfig(tutorialName: string) { | ||
let steps; | ||
switch (tutorialName) { | ||
case 'erc20-paymaster': | ||
steps = erc20PaymasterSteps; | ||
break; | ||
case 'how-to-test-contracts': | ||
steps = howToTestContractsSteps; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
return steps; | ||
} |
Oops, something went wrong.