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(
abi.encodeWithSignature(
'initialize(address,address,address,address,uint256,uint256)',
address(TS),
address(solar),
address(fhr),
address(sats),
yield,
_id
)
);
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?
MORE INFO:
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 });
}
{ from }
?{from: from}
from is what address is making the call.