Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Blockchain for Python Developers

You're reading from   Hands-On Blockchain for Python Developers Empowering Python developers in the world of blockchain and smart contracts

Arrow left icon
Product type Paperback
Published in Jun 2024
Publisher Packt
ISBN-13 9781805121367
Length 436 pages
Edition 2nd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Arjuna Sky Kok Arjuna Sky Kok
Author Profile Icon Arjuna Sky Kok
Arjuna Sky Kok
Arrow right icon
View More author details
Toc

Table of Contents (27) Chapters Close

Preface 1. Part 1:Blockchain and Smart Contract FREE CHAPTER
2. Chapter 1: Introduction to Blockchain Programming 3. Chapter 2: Smart Contract Fundamentals 4. Chapter 3: Using Vyper to Implement a Smart Contract 5. Part 2: Web3 and Ape Framework
6. Chapter 4: Using Web3.py to Interact with Smart Contracts 7. Chapter 5: Ape Framework 8. Chapter 6: Building a Practical Decentralized Application 9. Part 3: Graphical User Interface Applications
10. Chapter 7: Front-End Decentralized Application 11. Chapter 8: Cryptocurrency Wallet 12. Part 4: Related Technologies
13. Chapter 9: InterPlanetary: A Brave New File System 14. Chapter 10: Implementing a Decentralized Application Using IPFS 15. Chapter 11: Exploring Layer 2 16. Part 5: Cryptocurrency and NFT
17. Chapter 12: Creating Tokens on Ethereum 18. Chapter 13: How to Create an NFT 19. Part 6: Writing Complex Smart Contracts
20. Chapter 14: Writing NFT Marketplace Smart Contracts 21. Chapter 15: Writing a Lending Vault Smart Contract 22. Chapter 16: Decentralized Exchange 23. Part 7: Building a Full-Stack Web3 Application
24. Chapter 17: Token-Gated Applications 25. Index 26. Other Books You May Enjoy

Writing the unit test of the voting smart contract

To make sure the smart contract works well, you need to confirm it with unit tests. The way you write the unit test is similar to what you did in the previous chapter.

First, create the conftest.py file inside the tests folder, then add the following code to it:

import pytest
@pytest.fixture
def deployer(accounts):
    return accounts[0]
@pytest.fixture
def contract(deployer, project):
    return deployer.deploy(project.VotingApp)

This file contains the initial setup and configuration required for your test file to run properly. The deployer function returns the deployer, which uses the first test account. The contract function is used to deploy the voting smart contract.

Next, let’s create the test_voting_app.py file inside the tests folder and add the following code to it:

import pytest
from ape.exceptions import ContractLogicError
def test_chairperson(contract, deployer...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime