In the unit tests the owner is only set correctly the first time of deployment:
Why does the initialize function not run again when upgrading?
Environment
Truffle (5.3.1)
ERC1155Upgradeable
OwnableUpgradeable
Initializable
Details
I am new to using Upgradeable and Upgrades, so probably I am missing something important. I am following this OZ Tutorial here.
Code to reproduce
migrationfile
const MTD = artifacts.require("MemeOfTheDay");
module.exports = async function (deployer, network, accounts) {
deployer.deploy(MTD, {from: accounts[0]});
let Meme = await MTD.new();
console.log("Deployed at address: " + Meme.address);
await Meme.methods['initialize()']({from: accounts[0]});
console.log("OWNER IS: " + await Meme.owner());
};
testfile
const { expect } = require('chai');
// Load compiled artifacts
const Meme = artifacts.require('MemeOfTheDay');
// Start test block
contract('MemeOfTheDay', function (accounts) {
beforeEach(async function () {
// Deploy a new contract for each test
this.meme = await Meme.new();
});
// Test case
it('retrieve returns a value previously stored', async function () {
// Mint Tokens
await this.meme.mint("0kDfAd", 10);
await this.meme.mint("3kDk2d", 10);
//Print owner
console.log("OWNER:" + await this.meme.owner());
//Print Balance after minting, should be 2
console.log("Balance: " + await this.meme.balanceOf(accounts[0], 0));
// Test if the returned value is the same one
// Note that we need to use strings to compare the 256 bit integers
expect((await this.meme.getMemesCount()).toString()).to.equal('2');
console.log("Balance should still be one: " + await this.meme.balanceOf(accounts[0], 0));
});