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.

3 Answers 3


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!

  • 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
    Commented Feb 12, 2018 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
    Commented Feb 15, 2018 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 Commented Mar 17, 2019 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.

  • 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
    Commented Nov 20, 2017 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. Commented Nov 20, 2017 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!

  • Is this still valid? I got Error: Could not find artifacts for ERC20 from any sources. Do I need to add any config first?
    – kitta
    Commented Nov 1, 2021 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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