Truffle test Error: Cannot find module './ERC20.behavior'

I am running a truffle test on the contract: ERC20.test.js

const { accounts, contract } = require('@openzeppelin/test-environment');

const { BN, constants, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const { ZERO_ADDRESS } = constants;

const {
  shouldBehaveLikeERC20,
  shouldBehaveLikeERC20Transfer,
  shouldBehaveLikeERC20Approve,
**} = require('./ERC20.behavior');**

when the test is run, i get the following error:
Error: Cannot find module './ERC20.behavior’

1 Like

Hi @crypto_economics,

ERC20.behavior is part of OpenZeppelin Contracts internal tests, so you would use this when contributing to OpenZeppelin Contracts.

If you are extending OpenZeppelin Contracts ERC20 implementation to create your own ERC20 token then you should unit test any functionality that you are adding. You can use the tests in OpenZeppelin Contracts repository for inspiration. As a minimum, you would ideally test MetaData, supply, minting (if not fixed supply).

If you haven’t already I would look at the Learn guides on testing:

@abcoathup thank you. Can you send me a link to the exact testsin the OZ Contracts repository that I can use? I thought that this file, ERC20.test, was one of those tests, however, it seem as though I can run it.

1 Like

Hi @crypto_economics,

You could clone ERC20.behavior.js though my focus would be on anything you specifically add when you extend the contract such as MetaData, supply etc.

If you still get stuck, let me know and I will put together some simple tests.

@abcoathup if you could please help me with a couple of tests. I really need to see some examples for perhaps something like: check supply, balance, check transfer, check mint, check burn, etc? I am trying to write 5 tests. I have been stuck for about 10 days on this. The test style that I am somewhat comfortable with is:

it("should mark addresses as enrolled", async () => {
    await instance.enroll({from: alice})

    const aliceEnrolled = await instance.enrolled(alice, {from: alice})
    assert.equal(aliceEnrolled, true, 'enroll balance is incorrect, check balance method or constructor')
  });
1 Like

@abcoathup

I managed to write a couple of tests using the OZ repo. I have attached screenshots showing my ERC20 contract and test contract. Could you help add 3 more tests please? maybe: check totalSupply, mint, burn?

1 Like

Hi @crypto_economics,

I have added: Simple ERC20 token example which has a few tests.

This is a fixed supply token so there isn’t any minting (other than in the constructor).

1 Like