Test Driving a Blockchain Application: A Simple Example
Test Driving a Blockchain Application: A Simple Example
Testing a Blockchain-based application can pose unique problems different from other types of software.
Join the DZone community and get the full member experience.Join For Free
As software developers, a sound testing strategy for the applications built is critical to creating professional software. Testing is a nearly mandatory concept for the different types of applications that can be created. Some examples include web applications, desktop applications, APIs, mobile applications, and more. With the introduction of blockchain in recent years, new considerations appear in the testing a blockchain application. Especially since blockchain generally concerns itself with financials, making sure applications are working as intended is critical to producing high-quality software.
In this guide, I'll:
- Give a clear definition of what blockchain is and how it differs from a standard application.
- List some of the unique challenges in testing a blockchain application.
- Finally, walk through an example of testing a simple blockchain application.
Let's define blockchain to start.
What Is Blockchain?
Seeing as blockchain came into prominence in the last year, it's fair that a number of people don't understand what blockchain actually is. To understand how to test a blockchain application, we need to first understand blockchain itself. Blockchain has a few defining traits:
- A list of transactions (blocks) that exists in multiple locations at once.
- This blockchain does not have a "central" location. Instead, it exists across multiple nodes in a network.
- The blockchain is immutable outside of addition (cannot change existing records) Updating and deleting transactions is not allowed, improving audit capabilities and providing immutability benefits.
With this system in place, blockchain is finding itself in use for a number of industries, and growing more popular by the day. Currently, its most popular use is in cryptocurrency, as it provides a secure method for handling transactions between multiple accounts.
If you're reading this and don't quite have your head wrapped around the concept of blockchain yet, take a look at this video. It helped me get a feel of how blockchain works.
Once you've got a better sense of what blockchain is, we'll move on to testing considerations for a blockchain application.
Unique Challenges With Testing a Blockchain Application
Now that we've defined what blockchain is, let's consider the challenge of testing a blockchain application. First, let's look at the standard methods of testing an application. These include:
- Unit testing
- Integration testing
- Acceptance testing (also called UI testing)
For many blockchain applications, these tests are going to be critical. Just like with any other type of application, writing good tests is a fundamental step to creating good software and if you need a good tool, I 've got to tell you that Typemock's Isolator was a reliable and tool for my endeavors.
There are a few additional things to test in a blockchain application; let's take a look at each one individually.
When a transaction is added to a blockchain, it takes some amount of space to append to the blockchain. Different blockchain technologies can have caps on the block size that can be added. For example, Bitcoin has a limit of 1 MB for block size.
From a testing perspective, it's important to consider what happens if a transaction comes into the blockchain that exceeds this limit. The blockchain should reject the block gracefully, preventing an update across the network for a block.
When considering data transmission for a blockchain, you should focus on both:
- The ability to duplicate the blockchain across the network, making sure the capability to use the distributed capability of the blockchain is sound.
- The security in transmitting data across the network to different nodes.
Block Writing Performance
Another important thing to test for is the performance in appending a block to the blockchain. Since there is extra work in blockchain technology of propagating changes across a network, it's important the performance stays at an acceptable standard.
Consider the case where performance is hampered by block addition to the blockchain. Since this is a function that's going to happen often in many applications, it'll hamper the use of the application. Consider the need to sync all blockchains across an application, and it becomes apparent having an SLA of performance is important.
Blockchain technology provides the concept of a "smart contract." A smart contract essentially does two things:
- It provides terms for dealing with transactions when using blockchain. An example might be charging a fee based on transactions made.
- It automatically enforces the rules. Instead of needing a middle party to enforce the rules of a contract, code will handle it for you.
There are a number of benefits to this automated system. Not only is it more efficient, but it also essentially removes the potential of error. For instance, if you are handling a financial transaction in which a third party is involved, human error can come into play, like someone entering incorrect data. Enforcing automation for the blockchain renders human error moot, keeping consistency in transactions.
In a sense, using smart contracts allows you to better utilize the benefits of blockchain technology-that is, using software engineering to provide automation and further efficiency to the transaction process.
Testing a Blockchain Application: A Walkthrough
Now that we understand the differences between testing a standard application and a blockchain application, let's walk through an example. Here, we'll talk about an application that handles cryptocurrency transactions, allowing you to store a balance using something like Bitcoin.
Before getting into the nitty-gritty of blockchain technology, let's think about the fundamental functionality of what this kind of application does-deposits and withdraws money. A starting point for testing the application capability to deposit and withdraw cryptocurrency is possible with the three major automated test types (unit, integration, and acceptance). However, those won't be enough to cover all of the blockchain-specific technology scenarios.
Here are a few high-level actions to think of when testing a blockchain application:
- The capability of a user to create a new transaction on the blockchain.
- The ability to reverse a record (meaning you'll need to be able to "reverse" the effects of a previous transaction without updating the transaction).
- The functionality of the smart contract to resolve (since the smart contract is immutable for the blockchain creation, you'll want to be sure it can always work as intended).
- Making sure appending an oversized block handles correctly.
- Checking to ensure that the syncing process of the blockchain across nodes can happen successfully.
- Ensuring data transmits securely.
- Finally, ensuring the performance of writing a block to the blockchain stays above a specific SLA.
Hopefully, this guide gives a good overview of what blockchain is and provides you with a means for testing a blockchain application. Whether you are starting work on a blockchain application or have an application you're already working on, try using the information in this article to help you with testing.
Published at DZone with permission of Dave Farinelli , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.