I am attempting to test an upgradable contract using the TestHelper()
function and am unable to figure out how to pass the proxy admin address into the proxy creation as a constructor parameter. Is this possible using TestHelper()
?
The use case for this is to create upgradable contracts on behalf of someone and allow them to be the owner immediately after deployment. I do not want to create a proxy using createProxy()
in order to only get the admin proxy address and then follow that up with the desired createProxy()
.
If this is not possible, what is the expected method of achieving this goal?
The code looks like:
function initialize(address _proxyAdmin) public initializer {
// Call the proxy admin address to change the owner to the newly deployed proxy contract
}
1 Like
Hello, Shane! Great to see you around here!
I am attempting to test an upgradable contract using the TestHelper()
function and am unable to figure out how to pass the proxy admin address into the proxy creation as a constructor parameter. Is this possible using TestHelper()
?
You can send the proxy admin address to the TestHelper
's createProxy
method. The declaration of it looks like this:
public async createProxy(contract: Contract, contractParams: ContractInterface = {}): Promise<Contract> {
...
}
Where contractParams
follows ContractInterface
interface structure, which looks like this:
export interface ContractInterface {
packageName: string;
contractName: string;
initMethod?: string;
initArgs?: string[];
redeployIfChanged?: boolean;
admin?: string;
}
That being said, you should be able to set the proxy admin doing something like:
const project = await TestHelper();
const proxy = await this.project.createProxy(MyContract, { contractName: 'MyContract', packageName: 'MyPackage', admin: '0x12345...' });
Where 0x12345...
will be the admin of the proxy.
If you then try to do something like this:
await proxy.methods.myContractFn().call({ from: '0x12345...' });
It should revert, as you are calling a function from the implementation contract directly from the proxy admin.
2 Likes