Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
Add full example for the local setup
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless committed Mar 14, 2022
1 parent 7ec4d78 commit 0ace914
Show file tree
Hide file tree
Showing 7 changed files with 3,514 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# tutorial-examples
Full examples for tutorials in the zkSync 2.0 documentation
# Complete tutorial examples

Complete examples for tutorials in the zkSync 2.0 documentation
3 changes: 3 additions & 0 deletions local-setup-testing/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifacts/
cache/
node_modules/
18 changes: 18 additions & 0 deletions local-setup-testing/contracts/Greeter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.11;

contract Greeter {
string private greeting;

constructor(string memory _greeting) {
greeting = _greeting;
}

function greet() public view returns (string memory) {
return greeting;
}

function setGreeting(string memory _greeting) public {
greeting = _greeting;
}
}
29 changes: 29 additions & 0 deletions local-setup-testing/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require("@matterlabs/hardhat-zksync-deploy");
require("@matterlabs/hardhat-zksync-solc");

const zkSyncDeploy = process.env.NODE_ENV == 'test' ? {
zkSyncNetwork: "http://localhost:3050",
ethNetwork: "http://localhost:8545",
} : {
zkSyncNetwork: "https://zksync2-testnet.zksync.dev",
ethNetwork: "goerli",
};

module.exports = {
zksolc: {
version: "0.1.0",
compilerSource: "docker",
settings: {
optimizer: {
enabled: true,
},
experimental: {
dockerImage: "matterlabs/zksolc",
},
},
},
zkSyncDeploy,
solidity: {
version: "0.8.11",
},
};
22 changes: 22 additions & 0 deletions local-setup-testing/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "local-testing-tutorial",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@matterlabs/hardhat-zksync-deploy": "^0.1.3",
"@matterlabs/hardhat-zksync-solc": "^0.2.3",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.1.0",
"chai": "^4.3.6",
"ethers": "^5.5.4",
"hardhat": "^2.8.4",
"mocha": "^9.2.1",
"ts-node": "^10.5.0",
"typescript": "^4.5.5",
"zksync-web3": "^0.3.5"
},
"scripts": {
"test": "NODE_ENV=test hardhat test"
}
}
31 changes: 31 additions & 0 deletions local-setup-testing/test/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect } from 'chai';
import { Wallet, Provider, Contract } from 'zksync-web3';
import * as hre from 'hardhat';
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";

const RICH_WALLET_PK = '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110';

async function deployGreeter(deployer: Deployer): Promise<Contract> {
const artifact = await deployer.loadArtifact("Greeter");
return await deployer.deploy(artifact, ["Hi"]);
}

describe("Greeter", function () {
it("Should return the new greeting once it's changed", async function () {
const provider = Provider.getDefaultProvider();

const wallet = new Wallet(RICH_WALLET_PK, provider);
const deployer = new Deployer(hre, wallet);

const greeter = await deployGreeter(deployer);

expect(await greeter.greet()).to.eq("Hi");;

const setGreetingTx = await greeter.setGreeting("Hola, mundo!");
// wait until the transaction is mined
await setGreetingTx.wait();

expect(await greeter.greet()).to.equal("Hola, mundo!");
});
});

Loading

0 comments on commit 0ace914

Please sign in to comment.