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 7 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
18 changes: 16 additions & 2 deletions contracts/test/TestContractManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ contract ContractManager is IContractManagerTester {

event ContractUpgraded(string contractsName, address contractsAddress);

error ContractNotFound(
string contractName
);

constructor() {
owner = msg.sender;
}
Expand All @@ -64,7 +68,17 @@ 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))];
if (contractAddress == address(0)) {
revert ContractNotFound(name);
}
}
}
21 changes: 18 additions & 3 deletions migrations/upgradeMainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,27 @@ class ImaMainnetUpgrader extends Upgrader {
contractManagerInterface,
ethers.provider
)
if (!process.env.ABI) {
console.log(chalk.red("Set path to file with ABI and addresses to ABI environment variables"));
process.exit(1);
}
const abi = JSON.parse(await fs.readFile(process.env.ABI, "utf-8"));
for (const contractName of contracts) {
try {
const contractAddress = await contractManager.getContract(contractName);
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 contractAddress = abi[`${getContractKeyInAbiFile(contractName)}_address`] as string;
this.transactions.push(Transaction.from(
{
to: await contractManager.getAddress(),
data: contractManager.interface.encodeFunctionData(
"setContractsAddress",
[contractAddress]
[
contractName,
contractAddress
]
)
}
))
Expand Down Expand Up @@ -151,10 +159,17 @@ async function updateAbi() {
}

async function main() {
let contractNamesToUpgrade = [
"MessageProxyForMainnet",
"CommunityPool"
]
if (process.env.UPGRADE_ALL) {
contractNamesToUpgrade = contracts;
}
const upgrader = new ImaMainnetUpgrader(
"2.1.0",
await getImaMainnetInstance(),
contracts
contractNamesToUpgrade
);
await upgrader.upgrade();
await updateAbi();
Expand Down
2 changes: 1 addition & 1 deletion scripts/test_upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ cd "$GITHUB_WORKSPACE"
rm -r --interactive=never "$DEPLOYED_DIR"

MESSAGE_PROXY_FOR_MAINNET=$(cat data/proxyMainnet.json | jq -r .message_proxy_mainnet_address)
TEST_UPGRADE=true \
UPGRADE_ALL=true \
ABI="data/proxyMainnet.json" \
TARGET="$MESSAGE_PROXY_FOR_MAINNET" \
ALLOW_NOT_ATOMIC_UPGRADE="OK" \
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