You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -59,6 +60,8 @@ It's recommended that you've gone through the [hardhat getting started documenta
59
60
-`yarn --version` And get an output like: `x.x.x`
60
61
- You might need to install it with npm
61
62
63
+
> If you're familiar with `npx` and `npm` instead of `yarn`, you can use `npx` for execution and `npm` for installing dependencies.
64
+
62
65
## Quickstart
63
66
64
67
1. Clone and install dependencies
@@ -88,7 +91,7 @@ yarn hardhat test
88
91
or
89
92
90
93
```
91
-
npx hardhat test
94
+
yarn hardhat test
92
95
```
93
96
94
97
### Typescript
@@ -100,7 +103,7 @@ git checkout typescript
100
103
yarn
101
104
```
102
105
103
-
# Useage
106
+
# Usage
104
107
105
108
If you run `yarn hardhat --help` you'll get an output of all the tasks you can run.
106
109
@@ -140,15 +143,15 @@ To interact with a live or test network, you'll need:
140
143
2. A Private Key
141
144
3. ETH & LINK token (either testnet or real)
142
145
143
-
Let's look at an example of setting these up using the Kovan testnet.
146
+
Let's look at an example of setting these up using the Rinkeby testnet.
144
147
145
-
### Kovan Ethereum Testnet Setup
148
+
### Rinkeby Ethereum Testnet Setup
146
149
147
150
First, we will need to set environment variables. We can do so by setting them in our `.env` file (create it if it's not there). You can also read more about [environment variables](https://www.twilio.com/blog/2017/01/how-to-set-environment-variables.html) from the linked twilio blog. You'll find a sample of what this file will look like in `.env.example`
148
151
149
152
> IMPORTANT: MAKE SURE YOU'D DONT EXPOSE THE KEYS YOU PUT IN THIS `.env` FILE. By that, I mean don't push them to a public repo, and please try to keep them keys you use in development not associated with any real funds.
150
153
151
-
1. Set your `KOVAN_RPC_URL`[environment variable.](https://www.twilio.com/blog/2017/01/how-to-set-environment-variables.html)
154
+
1. Set your `RINKEBY_RPC_URL`[environment variable.](https://www.twilio.com/blog/2017/01/how-to-set-environment-variables.html)
152
155
153
156
You can get one for free from [Alchmey](https://www.alchemy.com/), [Infura](https://infura.io/), or [Moralis](https://moralis.io/speedy-nodes/). This is your connection to the blockchain.
154
157
@@ -164,53 +167,60 @@ Don't commit and push any changes to .env files that may contain sensitive infor
> You can also use a `MNEMONIC` instead of a `PRIVATE_KEY` environment variable by uncommenting the section in the `hardhat.config.js`, and commenting out the `PRIVATE_KEY` line. However this is not recommended.
177
180
178
181
For other networks like mainnet and polygon, you can use different environment variables for your RPC URL and your private key. See the `hardhat.config.js` to learn more.
179
182
180
-
3. Get some Kovan Testnet ETH and LINK
183
+
3. Get some Rinkeby Testnet ETH and LINK
181
184
182
185
Head over to the [Chainlink faucets](https://faucets.chain.link/) and get some ETH and LINK. Please follow [the chainlink documentation](https://docs.chain.link/docs/acquire-link/) if unfamiliar.
183
186
184
-
4. Running commands
187
+
4. Create VRF V2 subscription
188
+
189
+
Head over to [VRF Subscription Page](https://vrf.chain.link/rinkeby) and create the new subscription. Save your subscription ID and put it in `.env` file as `VRF_SUBSCRIPTION_ID`
190
+
191
+
5. Running commands
185
192
186
-
You should now be all setup! You can run any command and just pass the `--network kovan` now!
193
+
You should now be all setup! You can run any command and just pass the `--network rinkeby` now!
187
194
188
195
To deploy contracts:
189
196
190
197
```
191
-
yarn hardhat deploy --network kovan
198
+
yarn hardhat deploy --network rinkeby
192
199
```
193
200
194
201
To run staging testnet tests
195
202
```
196
-
yarn hardhat test --network kovan
203
+
yarn hardhat test --network rinkeby
197
204
```
198
205
199
206
## Forking
200
207
201
208
If you'd like to run tests or on a network that is a [forked network](https://hardhat.org/hardhat-network/guides/mainnet-forking.html)
202
209
1. Set a `MAINNET_RPC_URL` environment variable that connects to the mainnet.
203
-
2. Uncomment the section in your `hardhat.config.js`
210
+
2. Choose a block number to select a state of the network you are forking and set it as `FORKING_BLOCK_NUMBER` environment variable. If ignored, it will use the latest block each time which can lead to test inconsistency.
211
+
3. Set `enabled` flag to `true`/`false` to enable/disable forking feature
204
212
```
205
-
// forking: {
206
-
// url: MAINNET_RPC_URL
207
-
// }
213
+
forking: {
214
+
url: MAINNET_RPC_URL,
215
+
blockNumber: FORKING_BLOCK_NUMBER,
216
+
enabled: false,
217
+
}
208
218
```
209
219
210
220
211
221
## Auto-Funding
212
222
213
-
This Starter Kit is configured by default to attempt to auto-fund any newly deployed contract that uses Any-API or Chainlink VRF, to save having to manually fund them after each deployment. The amount in LINK to send as part of this process can be modified in the [Starter Kit Config](helper-hardhat-config.js), and are configurable per network.
223
+
This Starter Kit is configured by default to attempt to auto-fund any newly deployed contract that uses Any-API, to save having to manually fund them after each deployment. The amount in LINK to send as part of this process can be modified in the [Starter Kit Config](helper-hardhat-config.js), and are configurable per network.
Since all tests are written in a way to be independent from each other, you can save time by running them in parallel. Make sure that `AUTO_FUND=false` inside `.env` file. There are some limitations with parallel testing, read more about them [here](https://hardhat.org/guides/parallel-tests.html)
260
+
261
+
To run tests in parallel:
262
+
```
263
+
yarn test --parallel
264
+
```
265
+
or
266
+
```
267
+
yarn hardhat test --parallel
245
268
```
246
269
247
270
# Interacting with Deployed Contracts
248
271
249
-
After deploying your contracts.
250
-
The deployment output will give you the contract addresses as they are deployed. You can then use these contract addresses in conjunction with Hardhat tasks to perform operations on each contract.
272
+
After deploying your contracts, the deployment output will give you the contract addresses as they are deployed. You can then use these contract addresses in conjunction with Hardhat tasks to perform operations on each contract.
The VRFConsumer contract has two tasks, one to request a random number, and one to read the result of the random number request. This contract needs to be funded with link first:
302
+
The VRFConsumer contract has two tasks, one to request a random number, and one to read the result of the random number request. To start, go to [VRF Subscription Page](https://vrf.chain.link/rinkeby) and create the new subscription. Save your subscription ID and put it in `.env` file as `VRF_SUBSCRIPTION_ID`:
Once it's funded, you can perform a VRF request with the request-random-number task:
308
+
Then, deploy your VRF V2 contract consumer to the network of your recent subscription using subscription id as constructor argument.
309
+
310
+
```bash
311
+
yarn hardhat deploy --network network
312
+
```
313
+
314
+
Finally, you need to go to your subscription page one more time and add the address of deployed contract as a new consumer. Once that's done, you can perform a VRF request with the request-random-number task:
If you'd like to see the gas prices in USD or other currency, add a `COINMARKETCAP_API_KEY` from [Coinmarketcap](https://coinmarketcap.com/api/documentation/v1/).
350
378
379
+
# Code coverage
380
+
381
+
To see a measure in percent of the degree to which the smart contract source code is executed when a particular test suite is run, type
382
+
```
383
+
yarn coverage
384
+
```
385
+
386
+
# Fuzzing
387
+
388
+
We are going to use Echidna as a Fuzz testing tool. You need to have [Docker](https://www.docker.com/) installed with at least 8GB virtual memory allocated (To update this parameter go to _Settings->Resources->Advanced->Memory_).
389
+
390
+
To start Echidna instance run
391
+
392
+
```
393
+
yarn fuzzing
394
+
```
395
+
396
+
If you are using it for the first time, you will need to wait for Docker to download [eth-security-toolbox](https://hub.docker.com/r/trailofbits/eth-security-toolbox) image for us.
0 commit comments