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:
- "@openzeppelin/test-helpers": "^0.5.5",
- "truffle": "^5.1.24"
so YMMV!