Unit Tests for using OwnableUpgradeable.sol gives an error when running a function to a value

I'm playing with the OwnableUpgradeable.sol contract with my own smart contract. When running a unit test for my contract, I've got below output and error:


  Box
owner: 0xd4d499a1e956893A52B437f4546387b0C5824b11
addr1: 0x7E6e8af1689162B7e47f11EA5E2e10acc0dEb5e1
addr2: 0x53FDF098Df0b055DD838f84cD98CB579036A2a3D
Contract deployed to address: 0x17Ac25D59014E3aEFC0bC8a42b2F2Fea681aa38F
Owner Address: 0xd4d499a1e956893A52B437f4546387b0C5824b11
Setting new value: 10
Contract Address: 0x17Ac25D59014E3aEFC0bC8a42b2F2Fea681aa38F
    1) should allow owner to get a value


  0 passing (309ms)
  1 failing

  1) Box
       should allow owner to get a value:
     Error: could not decode result data (value="0x", info={ "method": "retrieve", "signature": "retrieve()" }, code=BAD_DATA, version=6.11.1)
      at makeError (node_modules/ethers/src.ts/utils/errors.ts:694:21)
      at assert (node_modules/ethers/src.ts/utils/errors.ts:715:25)
      at Interface.decodeFunctionResult (node_modules/ethers/src.ts/abi/interface.ts:916:15)
      at staticCallResult (node_modules/ethers/src.ts/contract/contract.ts:346:35)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at staticCall (node_modules/ethers/src.ts/contract/contract.ts:303:24)
      at Proxy.retrieve (node_modules/ethers/src.ts/contract/contract.ts:351:41)
      at Context.<anonymous> (test/Box.test.js:265:19)

With the log info in my unit tests, I can tell the new value has been set successfully.

:1234: Code to reproduce

My Smart Contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contract Box is OwnableUpgradeable {
    uint256 private _value;

    function initialize(address initialOwner) public initializer {
        __Ownable_init(initialOwner);
    }

    function store(uint256 value) public {
        _value = value;
    }

    function retrieve() external view onlyOwner returns(uint256) {
        return _value;
    }
}

My unit test file:

const { expect } = require("chai");
const { ethers } = require("hardhat");
const url = "http://127.0.0.1:8545";

// Start test block
describe("Box", function () {
  let Box;
  let ownerBox;
  let owner;
  let addr1;
  let addr2;

  beforeEach(async function () {
    [owner, addr1, addr2] = await ethers.getSigners();
    console.log("owner:", owner.address);
    console.log("addr1:", addr1.address);
    console.log("addr2:", addr2.address);

    Box = await ethers.getContractFactory("Box");
    ownerBox = await upgrades.deployProxy(Box, [owner.address], { initializer: "initialize" });
    console.log("Contract deployed to address:", ownerBox.target);
  });

  it("should allow owner to get a value", async function () {
    const newValue = 10;
    console.log("Owner Address:", owner.address);

    console.log("Setting new value:", newValue);
    await ownerBox.store(newValue);
    console.log("Contract Address:", ownerBox.target);
   
    const value = await ownerBox.retrieve();
    console.log("Retrieved Value:", value);
    expect(value).to.equal(newValue);
  });

});

:computer: Environment

The network I'm using is a Hyperleger Besu personal development network running in my local machine. and I'm using Hardhat as the development framework.

Finally, solved it by myself by adding one new line of code in the unit test file.

before(async function () {
    [owner, addr1, addr2] = await ethers.getSigners();
    console.log("owner:", owner.address);
    console.log("addr1:", addr1.address);
    console.log("addr2:", addr2.address);

    Box = await ethers.getContractFactory("Box");
    ownerBox = await upgrades.deployProxy(Box, [owner.address], {
      initializer: "initialize",
    });
    
    //this is the right function used in ethers 6.x.x
    await ownerBox.waitForDeployment();
    console.log("Contract deployed to address:", ownerBox.target);
  });