-
Notifications
You must be signed in to change notification settings - Fork 194
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
feat: add proper upgrade to version 3 in Lido #882
Open
folkyatina
wants to merge
1
commit into
feat/vaults
Choose a base branch
from
fix/lido-upgrade-version
base: feat/vaults
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+116
−144
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { expect } from "chai"; | ||
import { MaxUint256, ZeroAddress } from "ethers"; | ||
import { ethers } from "hardhat"; | ||
|
||
import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers"; | ||
import { time } from "@nomicfoundation/hardhat-network-helpers"; | ||
|
||
import { Lido__HarnessForFinalizeUpgradeV3, LidoLocator } from "typechain-types"; | ||
|
||
import { certainAddress, INITIAL_STETH_HOLDER, proxify } from "lib"; | ||
|
||
import { deployLidoLocator } from "test/deploy"; | ||
import { Snapshot } from "test/suite"; | ||
|
||
describe("Lido.sol:finalizeUpgrade_v3", () => { | ||
let deployer: HardhatEthersSigner; | ||
|
||
let impl: Lido__HarnessForFinalizeUpgradeV3; | ||
let lido: Lido__HarnessForFinalizeUpgradeV3; | ||
let locator: LidoLocator; | ||
|
||
const initialValue = 1n; | ||
const initialVersion = 2n; | ||
const finalizeVersion = 3n; | ||
|
||
let withdrawalQueueAddress: string; | ||
let burnerAddress: string; | ||
const eip712helperAddress = certainAddress("lido:initialize:eip712helper"); | ||
|
||
let originalState: string; | ||
|
||
before(async () => { | ||
[deployer] = await ethers.getSigners(); | ||
impl = await ethers.deployContract("Lido__HarnessForFinalizeUpgradeV3"); | ||
[lido] = await proxify({ impl, admin: deployer }); | ||
|
||
locator = await deployLidoLocator(); | ||
[withdrawalQueueAddress, burnerAddress] = await Promise.all([locator.withdrawalQueue(), locator.burner()]); | ||
}); | ||
|
||
beforeEach(async () => (originalState = await Snapshot.take())); | ||
|
||
afterEach(async () => await Snapshot.restore(originalState)); | ||
|
||
it("Reverts if not initialized", async () => { | ||
await expect(lido.harness_setContractVersion(initialVersion)) | ||
.and.to.emit(lido, "ContractVersionSet") | ||
.withArgs(initialVersion); | ||
|
||
await expect(lido.finalizeUpgrade_v3()).to.be.revertedWith("NOT_INITIALIZED"); | ||
}); | ||
|
||
context("initialized", () => { | ||
before(async () => { | ||
const latestBlock = BigInt(await time.latestBlock()); | ||
|
||
await expect(lido.initialize(locator, eip712helperAddress, { value: initialValue })) | ||
.to.emit(lido, "Submitted") | ||
.withArgs(INITIAL_STETH_HOLDER, initialValue, ZeroAddress) | ||
.and.to.emit(lido, "Transfer") | ||
.withArgs(ZeroAddress, INITIAL_STETH_HOLDER, initialValue) | ||
.and.to.emit(lido, "TransferShares") | ||
.withArgs(ZeroAddress, INITIAL_STETH_HOLDER, initialValue) | ||
.and.to.emit(lido, "ContractVersionSet") | ||
.withArgs(finalizeVersion) | ||
.and.to.emit(lido, "EIP712StETHInitialized") | ||
.withArgs(eip712helperAddress) | ||
.and.to.emit(lido, "Approval") | ||
.withArgs(withdrawalQueueAddress, burnerAddress, MaxUint256) | ||
.and.to.emit(lido, "LidoLocatorSet") | ||
.withArgs(await locator.getAddress()); | ||
|
||
expect(await impl.getInitializationBlock()).to.equal(MaxUint256); | ||
expect(await lido.getInitializationBlock()).to.equal(latestBlock + 1n); | ||
}); | ||
|
||
it("Reverts if initialized from scratch", async () => { | ||
await expect(lido.finalizeUpgrade_v3()).to.be.reverted; | ||
}); | ||
|
||
it("Reverts if contract version does not equal 2", async () => { | ||
const unexpectedVersion = 1n; | ||
|
||
await expect(lido.harness_setContractVersion(unexpectedVersion)) | ||
.and.to.emit(lido, "ContractVersionSet") | ||
.withArgs(unexpectedVersion); | ||
|
||
await expect(lido.finalizeUpgrade_v3()).to.be.reverted; | ||
}); | ||
|
||
it("Sets contract version to 3", async () => { | ||
await expect(lido.harness_setContractVersion(initialVersion)) | ||
.and.to.emit(lido, "ContractVersionSet") | ||
.withArgs(initialVersion); | ||
|
||
await expect(lido.finalizeUpgrade_v3()).and.to.emit(lido, "ContractVersionSet").withArgs(finalizeVersion); | ||
|
||
expect(await lido.getContractVersion()).to.equal(finalizeVersion); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove _initialize_v2 altogether by moving it's logic to v3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can, but should we?