Home > Net >  Owner of smart contract on hardhat development network is being returned 0x00000
Owner of smart contract on hardhat development network is being returned 0x00000

Time:11-18

I was trying to deploy my smart contract through unit testing using hardhat. The owner upon deployment is being returned as 0x0000.. although when writing my js script i assign a certain address from the hardhat network as the owner.

const  hre = require('hardhat')
const { expect, assert } = require('chai')

describe('ProperSubsetFund', async function () {
  // Initialize Contract Var
  let deployERC20, deployer, user1, user2, trader1, trader2
  let signers

  beforeEach(async function () {
    // Getting all the signers
    signers = await hre.ethers.getSigners()
    // console.log(signers.map(item => item.address));

    // Assign addresses to roles for later use
    deployer = signers[0].address
    user1 = signers[1].address
    user2 = signers[2].address
    trader1 = signers[3].address
    trader2 = signers[4].address

    // Read Contract ERC20
    const contractERC20 = await hre.ethers.getContractFactory('ProperSubsetERC20')
    // Read Contract Launchpad
    const contractLaunchpad = await hre.ethers.getContractFactory('ProperSubsetFactory')
    // Read Contract Funds
    const contractFunds = await hre.ethers.getContractFactory('ProperSubsetFund')

    // Deploy the three contracts
    deployERC20 = await contractERC20.connect(signers[0]).deploy(true)
    
  });

  describe('Deployment and Ownership', function () {
    it('Check if the owner is the deployer', async function () {

        expect(await deployERC20.owner()).to.equal(deployer)
    });
  });
})

These are the results

 ProperSubsetFund
       Deployment and Ownership
         Deployment
           Should set the right owner:

      AssertionError: expected '0x00000000000000000000000000000000000…' to equal '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb…'
        expected - actual

      -0x0000000000000000000000000000000000000000
       0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
      
      at Context.<anonymous> (test/ProperSubsetFund.test.js:71:49)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)

CodePudding user response:

Hardhat is not returning address(0), your contract owner() is returning address(0). If you read the terminal it says

 AssertionError: expected '0x00000000000000000000000000000000000…' to equal '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb…'

since you set this:

    expect(await deployERC20.owner()).to.equal(deployer)

your deployer address by hardhat is '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb…'. But deployERC20.owner() is '0x00000000000000000000000000000000000…'

  • Related