Using setUpRole on AccessControlUpgradeable in a test for a smart contract the admin address is always 0x000..0

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:


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 {

        _setupRole(DEFAULT_ADMIN_ROLE, admin);
        _setupRole(URI_SETTER_ROLE, admin);
        _setupRole(PAUSER_ROLE, admin);
        _setupRole(MINTER_ROLE, admin);
        _setupRole(UPGRADER_ROLE, admin);


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  });

    it('i am the owner of the contract', async function () {
        const own = await this.proxy.DEFAULT_ADMIN_ROLE();


1) Contract: Minter
       i am the owner of the contract:

      AssertionError: expected '0x00000000000000000000000000000000000…' to equal '0x90F8bf6A479f320ead074411a4B0e7944Ea…'
      + expected - actual


Has someone suggestions for me? Is there something wrong in my implementation? Thanks in advance!!

I think in this line of code, the right hand side returns the role data for DEFAULT_ADMIN_ROLE() instead of the role address itself. This can also be seen by the length of own which appears to be 32 when it is supposed to be 20.

1 Like

You have to use hasRole like this:

    it('i am the owner of the contract', async function () {
        const DEFAULT_ADMIN_ROLE = await this.proxy.DEFAULT_ADMIN_ROLE();
        expect(await this.proxy.hasRole(DEFAULT_ADMIN_ROLE, owner));
1 Like