Test Automation For Blockchain - How to improve development speed and code quality, Part 1
Tags: blockchain, testing, javascript, opensource
Published: 2019-04-09 09:52:05

---
title: Test Automation For Blockchain - How to improve development speed and code quality, Part 1
published: true
description: Blockchain technology and applications provide unique challenges that are more easily rectified with automated testing. 
canonical_url: https://blog.lisk.io/how-introducing-automation-testing-for-our-blockchain-significantly-improved-development-speed-and-10c0a6934e37
cover_image: https://thepracticaldev.s3.amazonaws.com/i/47gnm8ryitobmfpia87i.png
series: Test Automation for Blockchain
tags: blockchain, testing, javascript, opensource
---
<div><em>Today we will discuss the importance of software testing in blockchain, outline benefits of automation testing and explain how to get involved in the Quality Assurance of our open source project. This is part one of the two-part blog post.</em></div> <p pid="2"><br> </p> <p pid="3">Many blockchain projects don't survive long after hitting the initial production state. For most, the lack of proper software testing is one of the main reasons for their demise. It's estimated that over <a href="https://news.bitcoin.com/bad-code-has-lost-500-million-of-cryptocurrency-in-under-a-year/" target="_blank">half a billion dollars worth of cryptocurrency</a> has been lost due to bad code in the last year alone. You probably heard about <a href="https://medium.com/swlh/the-story-of-the-dao-its-history-and-consequences-71e6a8a551ee" target="_blank">The DAO's code loophole</a>, which allowed attackers to drain out 3.6 million ETH (worth $70 million at the time) from the Ethereum-based smart contract. Another notorious case was the <a href="https://elementus.io/blog/which-icos-are-affected-by-the-parity-wallet-bug/" target="_blank">Parity bug</a> which resulted in over $150 million permanently frozen. Even <a href="https://cointelegraph.com/news/the-anatomy-of-bitcoin-cores-recent-bug" target="_blank">Bitcoin itself</a> is not immune to hacks. Late last year, a bug discovered in the code allowed malicious individuals to artificially inflate Bitcoin's supply via double input. If the bug wasn't quickly identified and addressed, it could have had catastrophic effects on the network. This is just the tip of the iceberg — there are plenty of smaller incidents caused by inexperienced or inattentive developers that don't make the headlines.</p> <p pid="4">What does this tell us? In development, things can go wrong fast and the outcome can be ugly. This is why software testing is so important for any project utilizing blockchain technology, such as blockchain platforms, blockchain applications or blockchain-based services.</p> <p pid="5">In this article, we will discuss our experience and best practices with software testing while developing <a href="https://lisk.io" target="_blank">Lisk</a>, a blockchain application platform. We will also show you how implementing automation testing improved our internal workflows and code reliability. Lastly, we will show you how you can get involved in testing our open source software.</p> <p pid="6"><strong>This is a long blog post, but we've broken it down into bite-sized pieces for you.</strong></p> <p pid="7">Part 1:</p> <ol> <li><em>Introduction to Blockchain and Lisk</em></li> <li><em>What is Software Testing?</em></li> <li><em>Testing blockchain applications adds new metrics to traditional software testing</em></li> <li><em>Why blockchain developers need to pay much more attention to details</em></li> <li><em>Automation testing can significantly cut down the release process</em></li> <li><em>Different types of automated tests</em></li> <li><em>Continuous Integration (CI) is best practice when it comes to automation testing</em></li> <li><em>Which CI platform to pick? Travis CI vs CircleCI vs Jenkins</em></li> </ol> <p pid="20"><br> </p> <p pid="9">Part 2:</p> <ol> <li><em>Software testing is not enough - introducing Quality Assurance</em></li> <li><em>How manual testing slowed down our software development process</em></li> <li><em>How we implemented Quality Assurance at Lightcurve</em></li> <li><em>The results of having a QA team in place</em></li> <li><em>Our blockchain network's QA testing process</em></li> <li><em>Get involved in our open source automation testing</em></li> <li><em>How to start contributing to our QA</em></li> <li><em>Which QA tools can we offer you?</em></li> </ol> <h2>Introduction to Blockchain and Lisk</h2> <p pid="10">You've probably heard about blockchain in the context of cryptocurrencies like Bitcoin, but what makes this new technology so special? The <a href="https://lisk.io/academy/blockchain-basics/what-is-blockchain" target="_blank">blockchain</a>, which is a type of distributed ledger technology (DLT), is an open, distributed database that is able to record transactions among parties permanently and in an efficient, verifiable way. Those transactions are packed into blocks, <a href="https://lisk.io/academy/blockchain-basics/how-does-blockchain-work/blockchain-cryptography-explained" target="_blank">cryptographically</a>-signed and form the actual chain. Data stored in blockchain can't be altered or tampered with, as all the records are <a href="https://lisk.io/academy/blockchain-basics/benefits-of-blockchain/why-is-blockchain-trustless" target="_blank">immutable</a>. Once data is saved into the ledger, it stays there forever. The blockchain is also a <a href="https://lisk.io/academy/blockchain-basics/benefits-of-blockchain/what-is-decentralization" target="_blank">decentralized network</a>, meaning there is no central authority with control over it.</p> <p pid="11">It's easy to get excited about blockchain, but very difficult to actually develop a working product on top of it. Blockchain developers still seem to be a rare breed of programmers for various reasons, including the steep learning curve required. Lisk plans to tackle these problems head-on by making it easy for every developer to build and deploy <a href="https://lisk.io/products" target="_blank">blockchain applications in JavaScript</a>. Lightcurve is a blockchain product development studio and consultancy based in Berlin, Germany. We're currently focused on developing all aspects of Lisk, including the product, marketing, community, and design.</p> <figure></figure> <h2>What is Software Testing?</h2> <p pid="12">Basically, software testing is defined as a set of activities that can be done to guarantee that software is behaving as expected and it's bug-free. A proper software testing process will help you to identify and prevent mistakes, ensure that the actual implementation of particular features matches the requirements and increase overall confidence in the code.</p> <h3>Testing Blockchain Applications Adds New Metrics to Traditional Software Testing</h3> <p pid="13">Testing blockchain applications is not much different from testing non-blockchain ones. However, with blockchain, additional test metrics are involved, for example:</p> <ul> <li><strong>Chain size</strong>. The longer the blockchain is, the more data it contains. This results in more space taken on the datastore. The chain can grow really fast and there is no limit on its actual size, as new blocks are constantly being added. We need to know the maximum possible amount of data stored on the chain over a certain amount of time. This way we can estimate how much space a blockchain can take, for example after a year from now.</li> <li><strong>Throughput </strong>in blockchain is measured by calculating the number of transactions per second (TPS). Higher TPS is always better, but it comes with a cost of increasing overall network load and not every node is able to catch up. TPS as a factor of <a href="https://www.codementor.io/blog/blockchain-scalability-5rs5ra8eej" target="_blank">scalability</a> is a challenge and a hot topic of discussion in the blockchain industry. Many projects are chasing TPS blindly without focusing on other, more important indicators of performance. This often results with projects becoming less <a href="https://lisk.io/academy/blockchain-basics/benefits-of-blockchain/what-is-decentralization" target="_blank">decentralized</a>, which in turns negates the ideology of blockchain.</li> <li><strong>Security and cryptography</strong>. The code needs to be constantly reviewed and audited to ensure that there are no flaws regarding the creation of new tokens, maintaining account balances, verifying blocks, or transactions signatures.</li> <li><strong>Data integrity</strong> ensures that all the data stored on the blockchain is consistent between network <a href="https://lisk.io/academy/blockchain-basics/how-does-blockchain-work/nodes" target="_blank">nodes</a>. This is guaranteed by cryptography for blocks and transactions. However, some blockchain applications calculate and maintain states (for example actual account balances) in the memory or helper databases in order to make sure that data consistency is preserved. There is no other way than just comparing data directly between nodes.</li> <li><strong>Data propagation</strong> is the distribution of data from one node to another. A decentralized network can consist of thousands of nodes and all of them need to maintain a reasonable amount of connections with each other. When some portion of data hits one node, it needs to be forwarded to the entire network without disruption. The time this propagation takes is an important metric.</li> </ul> <h3>Why Blockchain Developers Need to Pay Much More Attention to Details</h3> <p pid="14">If a bug was introduced in a centralized system, providing a fix would be relatively straightforward. Even if it corrupted some data, it would be easier to correct. This is because in most cases, the company maintaining the application has complete control over the data. Given that blockchains are immutable ledgers, corrupted data is incredibly hard if not impossible to correct. Complicating the process even further, delivering a fix needs to be coordinated with all participants of the decentralized network. With Lisk, we must coordinate every release with hundreds of node operators, as well as block producers called delegates in our <a href="https://lisk.io/academy/blockchain-basics/how-does-blockchain-work/delegated-proof-of-stake" target="_blank">DPoS consensus algorithm</a>. Taking all these scenarios into account, the consequences of bugs in blockchain applications can be much more dangerous than in centralized software.</p> <blockquote><strong>In development, things can go wrong fast and the outcome can be ugly.</strong></blockquote> <h3>Automation Testing Can Significantly Cut Down the Release Process</h3> <p pid="15">Now that we have discussed the importance of testing in a blockchain project, we can divide the actual tests according to the way we execute them:</p> <ul> <li><strong>Manual testing</strong> is executed by QA/test engineers and is useful when some of the test scenarios are not yet migrated or ready to be executed in an automated way, such as new features. However, not everything can be done in this way for various reasons, including difficulty, time and budget constraints. Manual testing is overall the most time-consuming method.</li> <li><strong>Automation testing</strong> is the basis of continuous delivery. It is a development methodology that allows development teams to safely deploy changes to production. Continuous delivery enables developers to find bugs quickly and helps teams deliver new releases with confidence. For complex applications, automation testing can reduce the time required for the release process from months or years to days or even hours. Investing time to implement a high-quality test suite can dramatically enhance developers' productivity. However, it requires some effort to implement and maintain both the test scenarios and the infrastructure for executing them.</li> </ul> <h2>Different Types of Automated Tests</h2> <p pid="16">We can distinguish a few types of automated tests, such as unit tests, integration tests, and functional tests. However, in some of the existing test suites, those types are confused with each other and there is absolutely no distinction between them. This makes a test suite not well-suited for anything in particular. It's very important for a developer to understand different types of tests as each one has a unique role to play.</p> <ul> <li><strong>Unit testing</strong> is used as a fast feedback mechanism for a developer and "first line of defense" during the development process. In unit testing, particular units of code (functions) are tested independently from each other with simulated input and the main focus is to test the logic in the unit. This means I/O operations (like file access, Ajax/RPC calls, DOM interaction), timers, and expensive functions (encryption) are usually faked.</li> <li><strong>Integration testing</strong> is a defense mechanism against protocol changes (e.g. argument order) in mocked dependencies in the unit. Stubbing is often avoided in integration tests and actual interaction between units is being tested. Therefore, integration tests are more expensive than unit tests.</li> <li><strong>Functional testing, </strong>to paraphrase <a href="https://medium.com/javascript-scene/mocking-is-a-code-smell-944a70c90a6a" target="_blank">Eric Elliott</a>, is usually considered as a subset of integration tests, as they test all pieces of the application together (in the context of the running application).</li> </ul> <blockquote><strong>For complex applications, automation testing can reduce the time required for the release process from months or years to days or even hours</strong>. </blockquote> <h3>Continuous Integration Is A Best Practice When It Comes to Automation Testing</h3> <p pid="17">Continuous Integration (CI) is a software development practice which depends on frequent integration of the code into a shared repository. Every time a team member commits some code changes to version control (for example, Git) the automated process of building and testing the code can be triggered. Developers are encouraged to submit their code together with tests (unit, functional, integration) after the completion of every small task (fixing an issue, implementing a feature). Automated build system fetches the latest version of the code from the shared repository and applies changes if needed. It then executes all scheduled actions against it, like executing tests. CI is considered best practice because software developers need to integrate all the changes done by them with the rest of the changes made by other members of the development team. It helps to avoid merge conflicts, difficult bugs, or duplicated efforts. This is because CI forces the code to be merged into a shared version control branch continuously, allowing them to identify possible problems earlier and more easily. It also minimizes both the time spent on debugging and the time required for code reviews, allowing developers to focus more on adding features.</p> <h3>Which Platform to Pick?: Travis CI vs. CircleCI vs. Jenkins</h3> <p pid="18">The few popular CI platforms currently available vary by features and flexibility. Some of them are free. For others, you need to pay.</p> <ul> <li><a href="https://circleci.com" target="_blank">CircleCI</a> is very easy to start with. There are some free plans available, but with some limitations, like 1 concurrent job with 1 container and no parallelism. It's a cloud-based tool, so you don't need to host the infrastructure on your own. It has various integrations such as GitHub, Slack, Jira, etc. The initial setup is very easy and they have great customer support.</li> <li><a href="https://travis-ci.org/" target="_blank">Travis CI</a> is very similar to CircleCI, however, Travis CI is more flexible. It allows you to run builds and tests on Linux and Mac OS X at the same time, as well as support more languages (they even provide tutorials for them). It's free for open source projects.</li> <li><a href="https://jenkins.io/" target="_blank">Jenkins</a> is the leading open source automation server and definitely the most flexible one. You need to host it yourself, so it requires some more effort to initially set up and later to maintain. Jenkins allows you to have full control over any aspect of your builds. It can also be extended using plugins and there are hundreds available already, so you can integrate it with basically every tool you want to. While using Jenkins for small projects can be a bit of an overkill, it's great for large ones.</li> </ul> <p pid="19">If you want to compare CI platforms in more detail, there is a very nice comparison available on <a href="https://stackshare.io/stackups/circleci-vs-jenkins-vs-travis-ci" target="_blank">Stackshare.io</a>.</p> <p pid="21">That’s it for Part 1! Check out Part 2 of the walkthrough to read about the importance of quality assurance, our experience in implementing automated testing and links to get involved in the QA testing of our blockchain.</p>