Photo by Markus Spiske on Unsplash

Building a Blockchain: Subroutines in the Virtual Machine

Usually, every day I practice programming using TDD (Test-Driven Development) workflow: few minutes adding a minimal feature to one of my personal projects. One of them is writing a blockchain in Java. Based on ideas from Ethereum blockchain, it has a virtual machine to execute smart contracts. Today, I implemented subroutines in that virtual, adding three opcodes and their behavior, according Ethereum Improving Proposal 2315.

The relevant commits:

You can see the incremental coding, adding new expected behavior, writing test in red, then adding code to make the tests pass.

The main additions were:

It was easy to add this feature: using TDD, the initial code is simple and it can be tested by code without much effort (previous virtual machine tests were available to serve as a basis for the new tests); and writing explicitly each expected behavior tests facilitated the write of the corresponding production code.

Pending work: add some additional tests about executing nested subroutines, and minor refactors.

Angel “Java” Lopez

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store