[General] Testing best practices #95
-
EnvironmentTestnet Provide a brief description of the functionality you're trying to implement.I am currently transferring a project from L1 to zk-sync. Previously, I would test my contracts with hardhat-ethers library and the hardhat network built into Hardhat. I would like to know if there is a similar network/functionality with zksync-era. What is the specific issue or error you're encountering?The Migration guide (https://era.zksync.io/docs/tools/hardhat/migrating-to-zksync.html) was helpful, but because my project was small enough, I found it easier to create a new project with zksync-cli and paste the contracts in to the /contracts dir. My old test scripts are obviously incompatible now, and I want to know the best way to quickly test contract functionality (not on a public testnet). Can you share the error messages or logs you're receiving, if any?Have you made any recent changes to the contract before encountering this issue?Contracts are working on L1 when tested on the hardhat network. Are there any external libraries or contracts that your contract interacts with?Can you provide the relevant portions of your contract code where the issue is occurring?In L1, with hardhat, my test scripts looked like this to deploy and test functionality.
Have you tried to isolate the problem, and if so, what were the results?My new test script looks like this:
What steps have you already taken to try to resolve the issue?The project template has the following test network if the environment variable NODE_ENV is "test":
I am not sure how this network is activated and connected to. When I run the test script I get a noNetwork error: Repo Link (Optional)No response Additional DetailsI am looking for advice on how others test there scripts easily and quickly without deploying to a public testnet? is the only option to set up |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 7 replies
-
Hi @GavinStein1 👋 ! There are a few local test strategies that can be used as part of your migration, please see full description in the docs: https://era.zksync.io/docs/tools/testing/#testing-strategies-for-zksync-era When attempting to use There's also At the moment, there's not an "integrated" network like Hardhat's Network Node. So you would need to start up a node in a separate terminal before running your tests. |
Beta Was this translation helpful? Give feedback.
-
Hi to anyone reading this and is struggling with testing. I have set up the era_test_node using the documentation above and it works quite well. However, I was getting noNetwork errors (sometimes?? go figure) and it is because I was using the What you need to do is use @MexicanAce The docs here show an example test script for testing on the era_test_node and use the |
Beta Was this translation helpful? Give feedback.
Hi @GavinStein1 👋 !
There are a few local test strategies that can be used as part of your migration, please see full description in the docs: https://era.zksync.io/docs/tools/testing/#testing-strategies-for-zksync-era
When attempting to use
http://localhost:3050
, that would be against a local node from the Dockerized Setup.There's also
era_test_node
(as you described) and documentation on using that is available here: https://era.zksync.io/docs/tools/testing/era-test-node.htmlAt the moment, there's not an "integrated" network like Hardhat's Network Node. So you would need to start up a node in a separate terminal before running your tests.