I have the following function that I would like to test.

    function createPlanet(bytes memory _data) public returns (address) {
        emit ProxyCreated(planetImplementation);
        emit TestBytes(_data);
        address proxy = deployMinimal(planetImplementation, _data);
        return proxy;

The function works correctly when I call it from a different contract, here is the funciton call and the initialize function that it is calling:

            address _address = pm.createPlanet(

    function initialize(
        address _treasury,
        address _solar,
        address _fhr,
        address _sats,
        uint256 _yield,
        uint256 _tokenId
    ) public {
        tokenId = _tokenId;
        yield = _yield;
        minHold = 14 days;

        solar = ISolar(_solar);
        fhr = IFHR(_fhr);
        sats = ISat(_sats);
        ts = ITreasury(_treasury);

This all works as intended, I am struggling to replicate this in my tests with web3. The proxy contract is deployed with the correct address but none of the parameters in the initialize function are ever set.

Here is my test:

           const treasury = await treasuryAddress();
            const solar = await solarAddress();
            const sat = await satAddress();
            const fhr = await fhrAddress();

            const signature = web3.eth.abi.encodeFunctionCall(
                    name: 'initialize',
                    type: 'function',
                    inputs: [
                            type: 'address',
                            name: '_treasury'
                            type: 'address',
                            name: '_solar'
                            type: 'address',
                            name: '_fhr'
                            type: 'address',
                            name: '_sats'
                            type: 'uint256',
                            name: '_yield'
                            type: 'uint256',
                            name: '_tokenId'
                [treasury, solar, sat, fhr, 100, 1]
            const receipt = await createPlanet(signature, Owner);

            const proxyAddress = receipt.logs[0].args.proxy;

            const proxyYield = await getYield(proxyAddress, Owner);

            assert.equal(proxyYield.toString(), 100);

The contract works and I can get yield when it is deployed from within another contract so I am assuming it is because of abi.encodeFunctionCall maybe not beinging correctly formatted or something along those line?


CreatePlanet Function:

import { PlanetManagerC } from '../_utils/artifacts';
export async function createPlanet(signedCall, from) {
    const PlanetManager = await PlanetManagerC.deployed();
    return await PlanetManager.createPlanet(signedCall, { from });

GetYield Function:

import { PlanetC } from '../_utils/artifacts';
export async function getYield(planet, from) {
    const Planet = await PlanetC.at(planet);
    return await Planet.yield.call({ from });
  • What exactly is the meaning of { from }? Oct 16, 2020 at 20:53
  • It is es6 short hand for writing {from: from} from is what address is making the call. Oct 16, 2020 at 22:03
  • @JamesDawson What does signature look like? I see that you obtain the proxy address from the receipt but I see no event with the proxy address. There's an event but it contains the implementation and not the proxy address. Am I understanding it correctly or is it a copy&paste error in the question?
    – Ismael
    Oct 17, 2020 at 6:20
  • Yeah I know that, I now see that I missed the fact that you are passing it as a function parameter (I'd use a different name, BTW, as this technically a keyword). Oct 17, 2020 at 7:13


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.