Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix for initialize #1732

Merged
merged 9 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions contracts/test/TestContractManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ contract ContractManager is IContractManagerTester {
/**
* @dev Returns the contract address for a given contractName.
*/
function getContract(string memory contractName) external view override returns (address) {
return contracts[keccak256(abi.encodePacked(contractName))];
function getContract(
string memory name
)
public
view
override
returns (address contractAddress)
{
contractAddress = contracts[keccak256(abi.encodePacked(name))];
require(contractAddress != address(0), "Contract has not been found");
}
}
9 changes: 6 additions & 3 deletions migrations/upgradeMainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,20 @@ class ImaMainnetUpgrader extends Upgrader {
console.log(`Address of ${contractName} is set to ${contractAddress}`);
} catch {
// getContract failed because the contract is not set
const contractAddress = await this.instance.getContract(contractName);
const contract = await this.instance.getContract(contractName);
this.transactions.push(Transaction.from(
{
to: await contractManager.getAddress(),
data: contractManager.interface.encodeFunctionData(
"setContractsAddress",
[contractAddress]
[
contractName,
await contract.getAddress()
]
)
}
))
console.log(`Set ${contractName} address to ${contractAddress}`);
console.log(`Set ${contractName} address to ${await contract.getAddress()}`);
}
}
};
Expand Down
7 changes: 4 additions & 3 deletions test/utils/deploy/mainnet/messageProxyForMainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ export async function deployMessageProxyForMainnet(
contractManager: ContractManager
) {
const factory = await ethers.getContractFactory(name);
if (await contractManager.getContract(name) !== "0x0000000000000000000000000000000000000000") {
return factory.attach(await contractManager.getContract(name)) as MessageProxyForMainnet;
} else {
try {
await contractManager.getContract(name);
} catch {
const instance = await upgrades.deployProxy(factory, [await contractManager.getAddress()]) as unknown as MessageProxyForMainnet;
await contractManager.setContractsAddress(name, instance);
return instance;
}
return factory.attach(await contractManager.getContract(name)) as MessageProxyForMainnet;
}
7 changes: 4 additions & 3 deletions test/utils/deploy/test/messageProxyForMainnetTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ export async function deployMessageProxyForMainnetTester(
contractManager: ContractManager
) {
const factory = await ethers.getContractFactory(name);
if (await contractManager.getContract(name) !== "0x0000000000000000000000000000000000000000") {
return factory.attach(await contractManager.getContract(name)) as MessageProxyForMainnetTester;
} else {
try {
await contractManager.getContract(name);
} catch {
const instance = await upgrades.deployProxy(
factory,
[await contractManager.getAddress()]
) as unknown as MessageProxyForMainnetTester;
await contractManager.setContractsAddress(name, instance);
return instance;
}
return factory.attach(await contractManager.getContract(name)) as MessageProxyForMainnetTester;
}
26 changes: 19 additions & 7 deletions test/utils/skale-manager-utils/contractManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,43 @@ export async function deployContractManager(contractManagerAddress: string) {
if (contractManagerAddress === "0x0000000000000000000000000000000000000000") {
instance = await contractManagerFactory.deploy() as ContractManager;
} else {
instance = await contractManagerFactory.attach(contractManagerAddress) as ContractManager;
instance = contractManagerFactory.attach(contractManagerAddress) as ContractManager;
}
if (await instance.getContract("KeyStorage") === "0x0000000000000000000000000000000000000000") {
try {
await instance.getContract("KeyStorage");
} catch {
const keyStorageInstance = await (await ethers.getContractFactory("KeyStorageMock")).deploy() as KeyStorageMock;
await instance.setContractsAddress("KeyStorage", keyStorageInstance);
}
if (await instance.getContract(nameNodes) === "0x0000000000000000000000000000000000000000") {
try {
await instance.getContract(nameNodes);
} catch {
const nodesInstance = await (await ethers.getContractFactory(nameNodes)).deploy() as Nodes;
await instance.setContractsAddress(nameNodes, nodesInstance);
}
if (await instance.getContract(nameSchains) === "0x0000000000000000000000000000000000000000") {
try {
await instance.getContract(nameSchains);
} catch {
const schainsInstance = await (await ethers.getContractFactory(nameSchains)).deploy() as Schains;
await schainsInstance.addContractManager(instance);
await instance.setContractsAddress(nameSchains, schainsInstance);
}
if (await instance.getContract(nameSchainsInternal) === "0x0000000000000000000000000000000000000000") {
try {
await instance.getContract(nameSchainsInternal);
} catch {
const schainsInternalInstance = await (await ethers.getContractFactory(nameSchainsInternal)).deploy() as SchainsInternal;
await schainsInternalInstance.addContractManager(instance);
await instance.setContractsAddress(nameSchainsInternal, schainsInternalInstance);
}
if (await instance.getContract(nameSkaleVerifier) === "0x0000000000000000000000000000000000000000") {
try {
await instance.getContract(nameSkaleVerifier);
} catch {
const skaleVerifierInstance = await (await ethers.getContractFactory(nameSkaleVerifier)).deploy() as SkaleVerifierMock;
await instance.setContractsAddress("SkaleVerifier", skaleVerifierInstance);
}
if (await instance.getContract(nameWallets) === "0x0000000000000000000000000000000000000000") {
try {
await instance.getContract(nameWallets);
} catch {
const walletsInstance = await (await ethers.getContractFactory(nameWallets)).deploy() as Wallets;
await walletsInstance.addContractManager(instance);
await instance.setContractsAddress(nameWallets, walletsInstance);
Expand Down
Loading