I checked out openzeppelin-contracts-upgradeable from GitHub and docs as well.
I created my own Token contract from preset: https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/v3.0.0/contracts/presets/ERC20PresetMinterPauser.sol
I changed and added some needed logic to it. I deployed and manually tested it using the local hardhat network.
It is time to write tests for my contract to be sure everything is ok. Before doing it I decided to copy preset contract and test for it to my local project to be sure I have the correct setup and copy few tests to my own contract.
I copypasted the ERC20PresetMinterPauser.sol and test file (https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/master/test/presets/ERC20PresetMinterPauser.test.js) for it to my project, and tests failed. I saw, that test uses ERC20PresetMinterPauser, but the real smart contact is ERC20PresetMinterPauserUpgradeable. I also mentioned few scripts in âscriptsâ folder that add suffix âUpgradeableâ in the repo. I manually change the name from:
const ERC20PresetMinterPauser = artifacts.require(âERC20PresetMinterPauserâ);
to
const ERC20PresetMinterPauser = artifacts.require(âERC20PresetMinterPauserUpgradeableâ);
and still tests failed. I tried different ways to init a contract (using âinitializeâ method, âdeployâ and âdeployProxyâ) for this test but was not able to get tests passed.
Can you please advise me on how to init ERC20PresetMinterPauser contract correctly to pass the existed tests? Also, I tried to copy tests for ERC20 contract, AccessControll but had the same issue.
Environment
âdependenciesâ: {
â@openzeppelin/cliâ: â^2.8.2â,
â@openzeppelin/contractsâ: â^3.3.0â,
â@openzeppelin/contracts-upgradeableâ: â^3.3.0â,
â@openzeppelin/upgradesâ: â^2.8.0â
},
âdevDependenciesâ: {
â@nomiclabs/hardhat-ethersâ: â^2.0.1â,
â@nomiclabs/hardhat-truffle5â: â^2.0.0â,
â@nomiclabs/hardhat-waffleâ: â^2.0.1â,
â@nomiclabs/hardhat-web3â: â^2.0.0â,
â@openzeppelin/gsn-helpersâ: â^0.2.4â,
â@openzeppelin/hardhat-upgradesâ: â^1.5.0â,
â@openzeppelin/test-environmentâ: â^0.1.9â,
â@openzeppelin/test-helpersâ: â^0.5.10â,
âchaiâ: â^4.2.0â,
âethereum-waffleâ: â^3.2.2â,
âethersâ: â^5.0.26â,
âhardhatâ: â^2.0.8â,
âmochaâ: â^8.2.1â,
âweb3â: â^1.3.3â
}
Code to reproduce
const ERC20PresetMinterPauser = artifacts.require('ERC20PresetMinterPauser'); //ERC20PresetMinterPauserUpgradeable
contract('ERC20PresetMinterPauser', function (accounts) {
const [ deployer, other ] = accounts;
const name = 'MinterPauserToken';
const symbol = 'DRT';
const amount = new BN('5000');
const DEFAULT_ADMIN_ROLE = '0x0000000000000000000000000000000000000000000000000000000000000000';
const MINTER_ROLE = web3.utils.soliditySha3('MINTER_ROLE');
const PAUSER_ROLE = web3.utils.soliditySha3('PAUSER_ROLE');
beforeEach(async function () {
// what is the correct way to init token to get tests passed?
this.token = await ERC20PresetMinterPauser.new(name, symbol, { from: deployer });
});