How to Initialize contract using test-environment

I use @openzeppelin/test-environment
I test MyContract

 contract MyContract is
     Initializable,
     ERC20PresetMinterPauserUpgradeable,
     OwnableUpgradeable
{
    function initialize(string memory name, string memory symbol)
        public
        override
        initializer
    {
        ERC20PresetMinterPauserUpgradeable.initialize(name, symbol);
        _mint(msg.sender, 500000000 ether);
    }
}

I want to test symbol and name but when I test it, it always fails with an error that the name is undefined

  beforeEach(async function () {
    this.contract = await MyContract.new({
      name,
      symbol,
      from: owner,
    });
  });

  it("Symbol of the Token = symbol", async function () {
    expect((await this.contract.symbol()).to.equal(symbol));
  });

What is wrong with it?

2 Likes

And what’s the value of name?

1 Like

This is just a string, “any string”

1 Like

The question is if this is correct to init test contract like that

1 Like

Hi @dmdv,

You should use deployProxy and you can provide the parameters to pass to your initialize function. See: https://docs.openzeppelin.com/upgrades-plugins/1.x/truffle-upgrades#test-usage

1 Like

@abcoathup I've posted a new topic with a new implementation, this is definitely a bug

https://forum.openzeppelin.com/t/erc20presetminterpauserupgradeable-bug-symbol-is-not-initialized/5237

1 Like