This repository has been archived by the owner on Dec 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add full example for the local setup
- Loading branch information
1 parent
7ec4d78
commit 0ace914
Showing
7 changed files
with
3,514 additions
and
2 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
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 |
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,3 @@ | ||
artifacts/ | ||
cache/ | ||
node_modules/ |
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 @@ | ||
//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; | ||
} | ||
} |
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,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", | ||
}, | ||
}; |
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,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" | ||
} | ||
} |
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,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!"); | ||
}); | ||
}); | ||
|
Oops, something went wrong.