Reader small image

You're reading from  Mastering Blockchain Programming with Solidity

Product typeBook
Published inAug 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781839218262
Edition1st Edition
Languages
Concepts
Right arrow
Author (1)
Jitendra Chittoda
Jitendra Chittoda
author image
Jitendra Chittoda

Jitendra Chittoda is a blockchain security engineer at ChainSecurity. His day job is to perform security audit on smart contracts and expose security vulnerabilities in Solidity and Scilla contracts. He has also developed a non-custodial, decentralized, P2P lending contracts for ETHLend. The Solidity contracts that he has developed or audited handle over $100 million worth of cryptoassets. He also served as a tech and security advisor in various ICO projects. Before finding his passion for blockchain, he coded in Java for over 11 years. He is the founder and leader of Delhi-NCR-JUG, a non-profit meetup group for Java. He holds a master's degree in computer applications and is regularly invited as a speaker at various conferences and meetups.
Read more about Jitendra Chittoda

Right arrow

Taking Advantage of Code Quality Tools

Code quality is one of the important aspects of writing applications. Good quality code always tends to have fewer bugs and problems when deployed in production. To maintain and improve code quality, there are always some tools specific to the language you are coding with. Similarly, there are some tools for Solidity as well.

In this chapter, we are going to learn about some of the tools that are used while developing Solidity contracts. There are many open source tools available for the Solidity language, and these include code quality tools such as contract graph generators, linters, and code coverage tools. Using these contract graph generators, you can view how the contracts are linked together; using the linters, you can fix possible bugs, errors, and stylistic errors; and using the code coverage tools, you can discover which part of...

Technical requirements

You can find the code used in this chapter on GitHub at https://github.com/PacktPublishing/Mastering-Blockchain-Programming-with-Solidity/tree/master/Chapter06.

In this chapter, we are going to use different code quality tools. For each tool, you can install the latest version of these tools. As of writing this book, the following are the latest version of these tools:

To install the preceding tools, you must have Node...

Using the surya tool

The surya tool is an open source command-line utility tool that is used to generate a number of graphical and other reports. The tool works by scanning through the Solidity smart contract files and can generate inheritance and function call graphs. It also generates a function-specific report in a tabular format. Using all of these generated graphs and reports, a developer can understand smart contract architecture and dependencies by doing a manual inspection.

Let's start by installing the surya tool on your machine.

Installing surya

To install the surya utility tool on your machine, run the following command: 

$ npm install -g surya

Once this is installed, you can...

Understanding Solidity linters

Linters are the utility tools that analyze the given source code and report programming errors, bugs, and stylistic errors. For the Solidity language, there are some linter tools available that a developer can use to improve the quality of their Solidity contracts. These tools report the known pattern of errors or bugs and also check any security flaws that could be checked by the developers to ensure the safety of the contract.

However, these linter tools should be used along with the compiler's reported warnings. Because the compiler itself reports many warnings and informs the developer about the best language guidelines, it also suggests using the improved language syntax to reduce the security bug. You should bear in mind that the compiler warnings are not sufficient to have good quality code. You can also automate and write a script...

The solidity-coverage tool

Code coverage tools are used to determine which part of the code is covered and tested by the different test cases and which part is not tested. These tools offer an insightful view of the code and its related test cases. Once developers write the test cases for their Solidity project, they can use the coverage tools to find their code coverage. The more the code is covered with test cases, the lower the probability that you will find any bugs in the code in the future.

For Solidity, there is an open source tool called solidity-coverage. In this section, we will take a look at this tool in more detail and use it on the sample code. Files related to this section are present in the Chapter06/LintersTutorial folder.

Installing solidity-coverage

...

Summary

In this chapter, we explored the surya tool, which is helpful in generating many types of reports such as inheritance graphs, function flow graphs, inheritance dependencies, and function traces. Following this, we learned about the installation and usage of Solidity linters, such as solium and solhint, and how you can improve the code quality and find security issues. We learned about the installation and usage of code coverage tool to generate the coverage report.

Using all of these tools is recommended to improve the quality of your code. Once you generate reports with these tools, sometimes, you tend to find the bugs while looking at the reports itself. Hence, it is a good practice to generate these reports and improve the code coverage of your code.

In the next chapter, we are going to look into the most frequently used ERC20 token standard of the Ethereum...

Questions

  1. Do linters help to fix security issues?
  2. Does 100% Solidity coverage ensure that the testing of the contract is done efficiently?
  3. In which cases are function traces useful?
  4. Should every Solidity project use linters?
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Blockchain Programming with Solidity
Published in: Aug 2019Publisher: PacktISBN-13: 9781839218262
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.
undefined
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 $15.99/month. Cancel anytime

Author (1)

author image
Jitendra Chittoda

Jitendra Chittoda is a blockchain security engineer at ChainSecurity. His day job is to perform security audit on smart contracts and expose security vulnerabilities in Solidity and Scilla contracts. He has also developed a non-custodial, decentralized, P2P lending contracts for ETHLend. The Solidity contracts that he has developed or audited handle over $100 million worth of cryptoassets. He also served as a tech and security advisor in various ICO projects. Before finding his passion for blockchain, he coded in Java for over 11 years. He is the founder and leader of Delhi-NCR-JUG, a non-profit meetup group for Java. He holds a master's degree in computer applications and is regularly invited as a speaker at various conferences and meetups.
Read more about Jitendra Chittoda