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
Copy file name to clipboardExpand all lines: pages/lessons/projects/4.mdx
+33-32Lines changed: 33 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,11 +14,13 @@ import { LessonHeader } from '../../../components/mdx/LessonHeader'
14
14
15
15
## About this lesson
16
16
17
-
Welcome to this lesson where we’ll be adding automated tests for our *TierNFT* smart contract created in the previous tutorial. If you haven’t completed it already, we have a fast-track guide below to that project set-up - assuming you’re already confident with Solidity and a professional development environment. If not, we’d recommend completing the earlier tutorials in this track.
17
+
Welcome to this lesson where we’ll be adding automated tests for our *TierNFT* smart contract created in the previous tutorial. In case you haven’t completed it already, we have a fast-track guide below to that project set-up - assuming you’re confident with Solidity and a professional development environment. If you're not, we’d recommend completing the tutorials in this track before this one, before moving on to *Connecting your TierNFT Smart Contract to a Frontend*, our project series finalé.
18
18
19
-
Over here, you’ll learn about the benefits of writing automated tests, general testing concepts and best practices. You’ll walk away with many practical tests for smart contracts and nibble on some food for thought about test-driven development.
19
+
Back here, you’ll learn about the benefits of writing automated tests, general testing concepts and best practices. You’ll walk away with many practical tests for smart contracts and nibble on some food for thought about test-driven development.
20
20
21
-
As you dive in to the lesson, you'll come across some thought-provoking checkpoint questions designed to test your existing knowledge, measure how well you're absorbing the fresh content, and maybe ask you to predict next steps in the lesson. And to wrap up, a final quiz awaits. To complete this adventure might take anywhere from one to six hours. That all depends on your previous experience and how much new ground you need to cover. But enjoy the journey and remember to take regular breaks along the way. We care about your well-being and have even included a nifty pomodoro timer ⌛ in the menu header. Let it remind you to appreciate nature's gifts and "go touch some grass" for a while. 🌱 Embrace the process, and let's set sail!
21
+
As you dive in to the lesson, you'll come across some thought-provoking checkpoint questions designed to test your existing knowledge, measure how well you're absorbing the fresh content, and we might even ask you to predict next steps in the lesson. And to wrap up, a final quiz awaits. To complete this adventure might take anywhere from one to four hours. That all depends on your previous experience and how much new ground you need to cover. But enjoy the journey and remember to take regular breaks along the way. We care about your well-being and have even included a nifty pomodoro timer ⌛ in the menu header. Let it remind you to appreciate nature's gifts and "go touch some grass" for a while. 🌱 Embrace the process.
22
+
23
+
Let's raise the sails to catch the wind of what's to come:
22
24
23
25
<SideDrawerbuttonText="Warm-up Questions"title="Check out Your Previous Knowledge">
24
26
<Questionquestion="lesson-4/1-intro/Q1" />
@@ -28,8 +30,7 @@ As you dive in to the lesson, you'll come across some thought-provoking checkpoi
28
30
<Questionquestion="lesson-4/1-intro/Q5" />
29
31
</SideDrawer>
30
32
31
-
PART 1
32
-
33
+
And set sail . . .
33
34
34
35
## Why automated testing?
35
36
@@ -44,29 +45,31 @@ Testing can:
44
45
- give you a safety net when you make improvements to the code later
45
46
46
47
Tests are a tool for writing your code and making sure it keeps working as
47
-
expected when changes are made.
48
-
49
-
Automated tests don't fully replace manually testing your smart contract but
48
+
expected when changes are made. Automated tests don't fully replace manually testing your smart contract but
50
49
it's an important tool to ensuring your contract will work as expected.
51
50
52
-
## Let's Get Started
53
51
54
-
### Setting up our project dependencies
52
+
### Quick breakdown of lesson steps
53
+
- Set up our local development environment
54
+
- Write unit tests
55
+
- Test NFT contract initialisation, mint and withdrawl functions
56
+
- Refactor tokenURI() function and test new helper methods:
57
+
- Summary: understanding the concept of Test-Driven Development (TDD)
55
58
56
-
If you have an existing project from your previous work on the TierNFT lesson,
57
-
you have all the Hardhat dependencies installed.
59
+
### Developer tools and libraries we'll be using
60
+
- Hardhat development environment
61
+
- Mocha JavaScript framework for writing units tests
62
+
- Chai, an assertion library compatible with Mocha
63
+
- OpenZeppelin libraries will help bring clarity to testing our contract
58
64
59
-
Otherwise let's create a new Hardhat project and copy in the contract which
60
-
we'll be testing.
65
+
## Let's Get Started
61
66
62
-
To create a new project, please refer to _Lesson 3 - Tier NFTs_ and search for
67
+
### Setting up our project dependencies
68
+
If you have an existing project from your previous work on the TierNFT lesson,
69
+
you have all the Hardhat dependencies installed. {/* @wolovim , would we need to comment out the deployment script if we were to use that 'already set up' project? I mean, would that script give us bother each time we ran the tests in this lesson? */} Otherwise let's create a new Hardhat project and copy in the contract which
70
+
we'll be testing. To create a new project, please refer to _Lesson 3 - Tier NFTs_ and search for
63
71
the “First things first 👷♂️" section to get your project going. Follow the steps
64
-
until "Let’s start coding”, then open up your code editor.
65
-
66
-
67
-
_If you are using VSCode, type `code .` in your terminal to open VSCode._
68
-
69
-
After running through that section you'll have a working Hardhat project for the
72
+
until "Let’s start coding”, then open up your code editor. If you are using VSCode, type `code .` in your terminal to open VSCode. After running through that section you'll have a working Hardhat project for the
70
73
next steps.
71
74
72
75
### Add test command for running tests
@@ -216,7 +219,7 @@ module.exports = {
216
219
<Questionquestion="lesson-4/2-get-set-up/Q4" />
217
220
<Questionquestion="lesson-4/2-get-set-up/Q5" />
218
221
</SideDrawer>
219
-
PART 2
222
+
⌛ Pomodoro? 😊 🌱
220
223
221
224
## What do we want to test on our TierNFT contract?
With all the helpfulness of tests, why didn't we start with them before we wrote
913
-
any of the contract implementation?
914
-
915
-
The main reason was trying to minimize all the things you needed to learn to get
914
+
any of the contract implementation? The main reason was trying to minimize all the things you needed to learn to get
916
915
started, but the methodology of writing tests first is called "Test Driven
917
-
Development" (TDD).
916
+
Development" (TDD).
918
917
919
918
TDD is a very powerful methodology which goes like this:
920
919
@@ -938,21 +937,23 @@ With TDD:
938
937
version that outputs a long base64 string because it's not testable.
939
938
940
939
Bolting on tests after the fact can be painful and boring, and you lose the
941
-
potential code improvements you can make when you test as you go.
940
+
potential code improvements you can make when you test as you go. And speaking of testing as you go, why not take the quiz 😊
942
941
943
942
<br/><br/>
944
943
<Quizquiz="lesson-4-quiz" />
945
944
<br/><br/>
946
945
946
+
You just did some amazing work, and you will do a great service to the web3 ecosystem by being conscious of the value of writing solid code. There’s lots more to explore in Academy, and we’re looking forward to seeing you in our final project in this ERC721 track where you’ll be *Connecting your TierNFT Smart Contract to a Frontend*. Why not dive into the forum in the mean time, and share your new found wisdom with our community.
947
+
947
948
Go forth, test, and prosper knowing you have confidence in the code you're
0 commit comments