Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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
Truffle Quick Start Guide

You're reading from   Truffle Quick Start Guide Learn the fundamentals of Ethereum development

Arrow left icon
Product type Paperback
Published in Jun 2018
Publisher Packt
ISBN-13 9781789132540
Length 170 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Author (1):
Arrow left icon
Nikhil Bhaskar Nikhil Bhaskar
Author Profile Icon Nikhil Bhaskar
Nikhil Bhaskar
Arrow right icon
View More author details
Toc

Testing for Solidity events

We briefly touched on testing for events but we did not get into much detail. Now is the time.

Events are a great way to let the client (frontend) know what has happened, and they're great for providing metadata about a transaction or public function invocation of your Solidity smart contract. Along with testing the state modifications of a transaction, return value of a view function, and modifiers, we can also test whether an event was emitted with the appropriate metadata.

Right now, our TaskMaster contract has no events. Let's quickly add one.

Inside the TaskMaster.sol file, underneath the state variable declarations and before the constructor, add the following line of code:

event LogRecipientRewarded(address recipient, uint rewardAmount);

This is how you declare an event in Solidity.

We call it LogRecipientRewarded. We also specify the...

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