@@ -37,25 +37,30 @@ it's an important tool to ensuring your contract will work as expected.
37
37
38
38
## Let's Get Started
39
39
40
- ### Setting up our project
40
+ ### Setting up our project dependencies
41
41
42
42
If you have an existing project from your previous work on the TierNFT lesson,
43
- you have all the Hardhat dependencies installed in order to run our testing
44
- suite.
43
+ you have all the Hardhat dependencies installed.
45
44
46
- Otherwise, let's create a new Hardhat project, copy in the contract and jump
47
- into some testing!
45
+ Otherwise let's create a new Hardhat project and copy in the contract which
46
+ we'll be testing.
48
47
49
- 1 . Please refer to Lesson 2 and search for ` npx hardhat ` in the "Create your
50
- project " section to get your project going. After running through that
51
- section you'll have a working Hardhat project for the next steps .
48
+ To create a new project, please refer to _ Lesson 3 - Tier NFTs _ and search for
49
+ the “First things first 👷♂️ " section to get your project going. Follow the steps
50
+ until "Let’s start coding”, then open up your code editor .
52
51
53
- 2 . Next add a line in your ` scripts ` section of ` package.json ` so it looks like
54
- this below. You may already have other scripts' lines so don't get rid of
55
- those. If you already have a ` "test" ` script line, make sure it now has
56
- ` hardhat test --network hardhat ` . If you have multiple script lines make sure
57
- the last line does not have a comma at the end, otherwise you'll see an
58
- error.
52
+ _ If you are using VSCode, type ` code . ` in your terminal to open VSCode._
53
+
54
+ After running through that section you'll have a working Hardhat project for the
55
+ next steps.
56
+
57
+ ### Add test command for running tests
58
+
59
+ Add a line in your ` scripts ` section of ` package.json ` so it looks like this
60
+ below. You may already have other scripts' lines so don't get rid of those. If
61
+ you already have a ` "test" ` script line, make sure it now has
62
+ ` hardhat test --network hardhat ` . If you have multiple script lines make sure
63
+ the last line does not have a comma at the end, otherwise you'll see an error.
59
64
60
65
``` javascript
61
66
" scripts" : {
@@ -64,9 +69,11 @@ into some testing!
64
69
},
65
70
```
66
71
67
- 3 . Below is the contract from Lesson 3 we'll be testing. Please copy this code
68
- into a new file called ` TierNFT.sol ` in a ` contracts ` folder in the root of
69
- the project.
72
+ ### Bring in the contract we'll be testing
73
+
74
+ If you don't already have ` TierNFT.sol ` in your project from Lesson 3, below is
75
+ that same contract. Please create a new file called ` TierNFT.sol ` in a
76
+ ` contracts ` folder in the root of the project, and copy in this code:
70
77
71
78
``` solidity
72
79
// SPDX-License-Identifier: MIT
@@ -167,10 +174,31 @@ contract TierNFT is ERC721, Ownable {
167
174
}
168
175
```
169
176
177
+ ### Verify Solidity Version
178
+
179
+ One small, but crucial change before we proceed. Ensure the version of Solidity
180
+ being used to run the contract is the same one configured in
181
+ ` hardhat.config.js ` .
182
+
183
+ Copy the Solidity version from the ` pragma ` statement at the top of your
184
+ contract, to the ` hardhat.config.js ` file and replace that ` solidity: "version" `
185
+ with that of your contract.
186
+
187
+ For example, since our contract is using Solidity ` 0.8.12 ` :
188
+
189
+ ```
190
+ require("@nomicfoundation/hardhat-toolbox");
191
+ require('dotenv').config();
192
+
193
+ module.exports = {
194
+ solidity: "0.8.12",
195
+ };
196
+ ```
197
+
170
198
## What do we want to test on our TierNFT contract?
171
199
172
200
Now that the tools are set up, let's talk about what we want to test in our
173
- smart contract. We'll then add create tests.
201
+ smart contract. We'll then create the tests.
174
202
175
203
What is the contract trying to do?
176
204
@@ -188,8 +216,9 @@ mint fails if there is not enough Eth spent.
188
216
189
217
### Creating our test file
190
218
191
- Create a ` test ` folder in the root of your project, and add a new file called
192
- ` tier-nft.test.js ` which will hold our new test code.
219
+ If you don't have one already, create a ` test ` folder in the root of your
220
+ project, and add a new file called ` tier-nft.test.js ` which will hold our new
221
+ test code.
193
222
194
223
### Start testing constructor(), mint() and withdraw()
195
224
@@ -241,6 +270,7 @@ describe('TierNFT', function () {
241
270
<ContentCallout emoji = " 💡" size = " md" variant = " info" >
242
271
Before we walk through, let's make sure everything is working correctly. Run
243
272
the tests using ` npm test ` and you should see these two initial tests pass.
273
+ <strong >This is an important milestone! You created your first tests and they now pass.<strong >
244
274
</ContentCallout >
245
275
246
276
Now let's walk through the test code we've pasted in and explain what it does.
0 commit comments