I have a custom ERC20 token project and I would like to cover the token behaviour with tests. As the ERC20 interface is standardized I wonder whether there are some libraries to test ERC20 functionality or to help me with it?

I use truffle in my project so I prefer tests specifically for this framework but it is not required.


I haven't found out nothing similar to what I was looking for. Hence I have came up with the custom package:


With this package all the tests are already written. Just configure and run the test suite contained!

| improve this answer | |
  • This is great, but I have a few issues using it 1) the import statement no longer works, and 2) I am not sure how I'm supposed to be getting those test addresses – Serj Sagan Feb 12 '18 at 8:56
  • 1
    Wow, so somebody is actually trying to use it? That's great. Feel free to open up an issue on github and let's discuss it there. – mancze Feb 15 '18 at 8:50
  • You have done great job! However it does not work with truffle 5.0 and web3 1.0 anymore. I have updated it to support new truffle: github.com/dukei/token-test-suite – Dmitry Kochin Mar 17 '19 at 20:03

Take a look at the heavily audited ERC20 token contracts found on github.com/ConsenSys/Tokens and github.com/OpenZeppelin/zeppelin-solidity. You'll find extensive tests using truffle.

| improve this answer | |
  • Thanks, I have seen those. The major problem with them they are not designed for code reuse (the tests). So the only way to use them is to copy&paste (and customize). That's not good. – mancze Nov 20 '17 at 13:33
  • @mancze oh gotcha. I haven't seen anything out there like you described. However, it should be pretty simple to take those tests and turn it into a library. – Miguel Mota Nov 20 '17 at 16:20

If you have existing tests and you don't want to figure out how to integrate @mancze's solution, read on.

The key is to use truffle's builtin ERC20 contract using artifacts.require("ERC20");

const { constants } = require('@openzeppelin/test-helpers')
const ERC20 = artifacts.require("ERC20");

then your test will look like

contract('Your_Contract', (accounts) => {
  beforeEach(async () => {
    `let erc20Instance = await ERC20.new();`

  it('ERC20 should work', async () => {
      await expectRevert(
          erc20Instance.transfer(constants.ZERO_ADDRESS, 42, { from: accounts[1] }),
          'ERC20: transfer to the zero address'

This was tested with versions:

  1. "@openzeppelin/test-helpers": "^0.5.5",
  2. "truffle": "^5.1.24"

so YMMV!

| improve this answer | |
New contributor
almel is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.