I want to test my contract using truffle test
which required a mock ERC20.
I've found this example in Github and also this thread.
const ERC20 = artifacts.require("ERC20");
I've tried but got
Error: Could not find artifacts for ERC20 from any sources
How do I use ERC20 artifact from the truffle build-in test suite like so?
Or is there anyways to achieve the goal without needing to add an actual ERC20 contract to the project?
Best Answer
Take a look at the OpenZeppelin presets, follow this link for the ERC-20 ones.
EDIT : Giving you an example on how to use it (assuming Openzeppelin v4) :
First import the preset file, ex :
Running :
Will produce the different artifacts :
If you want the Mock ERC20 to be deployed automatically (not only when running tests) you will need to add an entry to your migration file.
In order to import it and use it inside your test file you could do something similar to this (assuming the mock ERC20 contract was automatically deployed when migrating) :
If you do not want to deploy your mock ERC20 contract by default (which makes perfect sense as you could be using it only for test purposes..) this example might be more usefull :