How to interact with a new clone contract (EIP-1167) instance on ethers.js?

Viewed 17

I'm currently testing my Clone contract with Ethers using Hardhat and I'm facing some issues. I'm trying to create a new Cloned instance of my implementation contraction like this:

clonedContract = new ethers.Contract(cloneAddress, abi, player)

The contract successfully clones and I receive an address of the 'clonedContract' if I enter console.log(clonedContract.address).

However, when I try testing some functions on the clone contract, it fails. For example, the following code:

[deployer, player] = await ethers.getSigners()

            wf = wf.connect(player)
            tx = await wf.createClone(player.address, {
                value: ethers.utils.parseUnits("0", "ether"),
            })

            txReceipt = await tx.wait(1)

            cloneAddress = await txReceipt.events[0].args._instance
            clonedContract = new ethers.Contract(cloneAddress, abi, player)
            accountConnectedClone = clonedContract.connect(player)

it("initializes contract correctly", async function () {
                accountConnectedClone = clonedContract.connect(player)
                const creator = await accountConnectedClone.getCreator()
                expect(player.address).to.equal(creator)

Returns the following output:

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

      -0x70997970C51812dc3A010C7d01b50e0d17dc79C8
      +0x0000000000000000000000000000000000000000

I've tried testing this exact same code on Remix and it works perfectly, so I think it has something to do with hardhat/ethers and the way I'm writing the tests/interacting with the contracts.

The creator should ideally be set as per the 'createClone' function in my CloneFactory (see below), however for some reason it isn't working here.

    constructor(address _implementation) {
        implementationContract = _implementation;
    }

    function createClone(address _creator) payable external returns(address instance) {
        instance = Clones.clone(implementationContract);
        (bool success, ) = instance.call{value: msg.value}(abi.encodeWithSignature("initialize(address)", _creator));
        allClones.push(instance);
        emit NewClone(instance);
        return instance;
    }

I've been looking for an answer to this for the past week but there's not much info online. Any help at all would be greatly appreciated.

IMPORTANT: My implementation contract implements a ChainLink VRF Coordinator and I think that has something to do with why this is not working. I say this because if I comment parts of the VRF Code out, I am not able to read the following line of code:

cloneAddress = await txReceipt.events[0].args._instance

I've asked this question in a lot more detail over here: https://ethereum.stackexchange.com/questions/135310/how-to-correctly-test-the-initialisation-of-a-clone-contract-on-hardhat-eip-11/135325#135325

0 Answers
Related