Dears, I'm developing an upgredable smart contract. I want to use AccessControlUpgradeable but I'm unable to test the contract. Initializing the contract the DEFAULT_ADMIN_ROLE is 0x0000000000000000000000000000000000000000000000000000000000000000 though I use a specific address.
I'm using truffle and this is my code:
ERC1155.sol
pragma solidity ^0.8.9;
import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155SupplyUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
contract ERC1155 is Initializable, ERC1155Upgradeable, AccessControlUpgradeable, PausableUpgradeable, ERC1155BurnableUpgradeable, ERC1155SupplyUpgradeable, UUPSUpgradeable {
bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");
/// @custom:oz-upgrades-unsafe-allow constructor
//constructor() initializer {}
function initialize(address admin) initializer public {
__ERC1155_init("");
__AccessControl_init();
__Pausable_init();
__ERC1155Burnable_init();
__ERC1155Supply_init();
__UUPSUpgradeable_init();
_setupRole(DEFAULT_ADMIN_ROLE, admin);
_setupRole(URI_SETTER_ROLE, admin);
_setupRole(PAUSER_ROLE, admin);
_setupRole(MINTER_ROLE, admin);
_setupRole(UPGRADER_ROLE, admin);
}
....
}
Factory.test.js
const { expect, assert } = require('chai');
const { deployProxy, upgradeProxy } = require('@openzeppelin/truffle-upgrades');
const Erc = artifacts.require('ERC1155');
contract('Minter', async function ([owner, other]){
beforeEach(async function () {
this.proxy = await deployProxy(Erc, [owner], { kind: 'uups', initializer: 'initialize', from: owner });
console.log(owner);
});
it('i am the owner of the contract', async function () {
const own = await this.proxy.DEFAULT_ADMIN_ROLE();
expect(own).to.equal(owner);
});
});
Results:
1) Contract: Minter
i am the owner of the contract:
AssertionError: expected '0x00000000000000000000000000000000000…' to equal '0x90F8bf6A479f320ead074411a4B0e7944Ea…'
+ expected - actual
-0x0000000000000000000000000000000000000000000000000000000000000000
+0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1
Has someone suggestions for me? Is there something wrong in my implementation? Thanks in advance!!