I didn’t try that, but yes, this works for me, also.
It seems that it is failing when executing using Truffle (exec
, or console
).
If I change the contract to an ERC20PresetFixedSupplyUpgradeable
contract as below, it works fine:
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/presets/ERC20PresetFixedSupplyUpgradeable.sol";
contract FooUpgradeable is ERC20PresetFixedSupplyUpgradeable {
function initialize() public initializer {
super.initialize("Foo", "FOO", 100 * 10 ** decimals(), _msgSender());
}
}
Output:
npx truffle console --network development
truffle(development)> const foo = await FooUpgradeable.new();
undefined
truffle(development)> await foo.initialize();
{
tx: '0x1e29867ba0dea0248d0c0efabfda38bea24a6fa26c18254239adc29bd5fb0db7',
...
But if I do the exact same with the ERC777PresetFixedSupplyUpgradeable
contract, I get the below output:
npx truffle console --network development
truffle(development)> const foo2 = await FooUpgradeable.new();
undefined
truffle(development)> await foo2.initialize();
Uncaught Error: Returned error: VM Exception while processing transaction: revert
at evalmachine.<anonymous>:1:14
at evalmachine.<anonymous>:2:49
at sigintHandlersWrap (node:vm:271:12)
at Script.runInContext (node:vm:139:14)
at runScript (C:\MyPath\node_modules\truffle\build\webpack:\packages\core\lib\console.js:270:1)
at Console.interpret (C:\MyPath\node_modules\truffle\build\webpack:\packages\core\lib\console.js:285:1)
at bound (node:domain:416:15)
at REPLServer.runBound [as eval] (node:domain:427:12)
at REPLServer.onLine (node:repl:846:10)
at REPLServer.emit (node:events:365:28)
at REPLServer.emit (node:domain:470:12)
at REPLServer.Interface._onLine (node:readline:452:10)
at REPLServer.Interface._line (node:readline:797:8)
at REPLServer.Interface._ttyWrite (node:readline:1142:14) {
data: {
'0xb869b9f32a65d351364873f689271945bed430f22f83dc11a83233734bc0d12e': { error: 'revert', program_counter: 5665, return: '0x' },
stack: 'RuntimeError: VM Exception while processing transaction: revert\n' +
' at Function.RuntimeError.fromResults (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\lib\\utils\\runtimeerror.js:94:13)\n' +
' at BlockchainDouble.processBlock (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\lib\\blockchain_double.js:627:24)\n' +
' at runMicrotasks (<anonymous>)\n' +
' at processTicksAndRejections (internal/process/task_queues.js:93:5)',
name: 'RuntimeError'
},
hijackedStack: 'Error: Returned error: VM Exception while processing transaction: revert\n' +
' at Object.ErrorResponse (C:\\MyPath\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-core-helpers\\lib\\errors.js:28:1)\n' +
' at C:\\MyPath\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3\\node_modules\\web3-core-requestmanager\\lib\\index.js:303:1\n' +
' at C:\\MyPath\\node_modules\\truffle\\build\\webpack:\\packages\\provider\\wrapper.js:107:1\n' +
' at XMLHttpRequest.request.onreadystatechange (C:\\MyPath\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3\\node_modules\\web3-providers-http\\lib\\index.js:98:1)\n' +
' at XMLHttpRequestEventTarget.dispatchEvent (C:\\MyPath\\node_modules\\truffle\\build\\webpack:\\node_modules\\xhr2-cookies\\dist\\xml-http-request-event-target.js:34:1)\n' +
' at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._setReadyState (C:\\MyPath\\node_modules\\truffle\\build\\webpack:\\node_modules\\xhr2-cookies\\dist\\xml-http-request.js:208:1)\n' +
' at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._onHttpResponseEnd (C:\\MyPath\\node_modules\\truffle\\build\\webpack:\\node_modules\\xhr2-cookies\\dist\\xml-http-request.js:318:1)\n' +
' at IncomingMessage.<anonymous> (C:\\MyPath\\node_modules\\truffle\\build\\webpack:\\node_modules\\xhr2-cookies\\dist\\xml-http-request.js:289:47)\n' +
' at IncomingMessage.emit (node:events:377:35)\n' +
' at IncomingMessage.emit (node:domain:532:15)\n' +
' at endReadableNT (node:internal/streams/readable:1312:12)\n' +
' at processTicksAndRejections (node:internal/process/task_queues:83:21)'
}
I also tried with a very simple test using npm test
, mocha
, and '@openzeppelin/test-environment
:
const { contract } = require('@openzeppelin/test-environment');
const FooUpgradeable = contract.fromArtifact('FooUpgradeable');
it('should do nothing', async () => {
foo = await FooUpgradeable.new();
await foo.initialize();
});
I get the following output with the ERC777PresetFixedSupplyUpgradeable
contract:
Error: Returned error: VM Exception while processing transaction: revert
at Context.<anonymous> (test\FooUpgradeable.test.js:6:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
But with the ERC20PresetFixedSupplyUpgradeable
contract, it works:
✔ should do nothing (1225ms)
1 passing (3s)
At first, I thought it may be due to Truffle or Ganache, but the test is using the OpenZeppelin test environment.