Part Seven: Stateful Testing

This article is part of a series. If you haven’t yet, check out the previous articles:

Part One: Why we Test
Part Two: Core Concepts of Testing
Part Three: Writing Basic Tests
Part Four: Running Your Tests
Part Five: Tools and Techniques for Effective Testing
Part Six: Parametrization and Property-Based Testing
Part Seven: Stateful Testing

Stateful testing is a more advanced method of property-based testing used to test complex systems. In a stateful test you define a number of actions that can be combined together in different ways, and Hypothesis attempts to find a sequence of those actions that results…


Part Six: Parametrization and Property-Based Testing

This article is part of a series. If you haven’t yet, check out the previous articles:

Part One: Why we Test
Part Two: Core Concepts of Testing
Part Three: Writing Basic Tests
Part Four: Running Your Tests
Part Five: Tools and Techniques for Effective Testing
Part Six: Parametrization and Property-Based Testing
Part Seven: Stateful Testing

Let’s revisit one of our earlier ERC20 test cases:

Here we verify that the transfer function adjusts the sender’s balance as intended. Simple enough, right? Ship it and on to test the next behavior!

On it’s own, however, this test isn’t as strong as…


Part Five: Tools for Effective Testing

This article is part of a series. If you haven’t yet, check out the previous articles:

Part One: Why we Test
Part Two: Core Concepts of Testing
Part Three: Writing Basic Tests
Part Four: Running Your Tests
Part Five: Tools and Techniques for Effective Testing
Part Six: Parametrization and Property-Based Testing
Part Seven: Stateful Testing

Dealing with Tests that cannot Pass

At some point you may find yourself dealing with a test that cannot pass. Maybe you are unsure of the reason why but need to focus on something else for now, maybe you’re in the middle of a large-scale refactor and so the failure is…


Part Four: Running Your Tests

This article is part of a series. If you haven’t yet, check out the previous articles:

Part One: Why we Test
Part Two: Core Concepts of Testing
Part Three: Writing Basic Tests
Part Four: Running Your Tests
Part Five: Tools and Techniques for Effective Testing
Part Six: Parametrization and Property-Based Testing
Part Seven: Stateful Testing

Now that we’ve covered the basics of writing tests, let’s look at how to run them and how to understand the output.

Running Tests

To execute the entire test suite, run the following command in the root folder of your project:

brownie test

You will receive output…


Part Three: Writing Basic Tests

This article is part of a series. If you haven’t yet, check out the previous articles:

Part One: Why we Test
Part Two: Core Concepts of Testing
Part Three: Writing Basic Tests
Part Four: Running Your Tests
Part Five: Tools and Techniques for Effective Testing
Part Six: Parametrization and Property-Based Testing
Part Seven: Stateful Testing

It’s time to write our first tests! We will be testing functionality in a simple ERC20 contract. If you want to follow along using Solidity you can create a local copy of the contract with the following command:

brownie bake token

or if you prefer…


Part One: Why we Test

A major component in developing smart contracts is testing smart contracts. And yet, for the amount of content written on “how to code in Solidity” there is an unfortunate lack of content about how to write tests for that code.

I think there are several reasons for this:

  1. This is still a very new ecosystem. Solidity is only 5 years old, Vyper less than 3. While the tooling available today is much greater than what it was just a year ago, it is still far from the state of most mainstream languages.
  2. Many developers with experience in other languages come…


or: how I learned to stop mocking and embrace the --fork

An Indulgent Introduction…

Looking at Ethereum smart contract development over the years all I can think is —man, the times, they are a-changin’. When I wrote my first smart contract, my approach to security was to view that contract as an island. I sought to build an impenetrable fortress, capable of protecting the wealth within and preventing unsolicited interactions from what I viewed as an unknown horde of potential attackers.

As I kept learning and tinkering I grew to understand the unique challenges that immutability presented me. I started using libraries and building interconnected systems. I became comfortable with the idea that my…


Basic Brownie functionality

Photo by André François McKenzie on Unsplash

Now that we’ve installed Brownie and created a project, it’s time to get acquainted with some of the core functionality.

If you haven’t yet, start by opening the console:

brownie console

Brownie will launch Ganache and create some objects to help you interact with your project. Once it’s ready, you are given a command prompt:


Working with Brownie projects

Photo by Thought Catalog on Unsplash

Missed part one? Click here.

We’ve just installed Brownie and confirmed that it works. Now what? Let’s start with a quick orientation, and then we’ll dive into some of the more important areas. First things first: We need a project!

Create a Brownie Project

Most of the time when using Brownie, you’ll be working with a project. A project consists of one or more smart contracts, unit tests, and scripts to handle deployment and common interactions.

We can start a new project by typing brownie init inside an empty folder, but for this tutorial, we’re instead going work from a pre-made project. …

Ben Hauser

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