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

Add upgradeToWithSigAndCall function to the UUPSSignableUpgradeable #7

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions contracts/utils/UUPSSignableUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,21 @@ abstract contract UUPSSignableUpgradeable is UUPSUpgradeable {
_authorizeUpgrade(newImplementation_, signatures_);
_upgradeToAndCallUUPS(newImplementation_, new bytes(0), false);
}

/**
* @notice Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade} with the provided `newImplementation` and `signatures`.
*
* Emits an {Upgraded} event.
*/
function upgradeToWithSigAndCall(
address newImplementation_,
bytes[] calldata signatures_,
bytes calldata data_
) external virtual onlyProxy {
_authorizeUpgrade(newImplementation_, signatures_);
_upgradeToAndCallUUPS(newImplementation_, data_, false);
}
}
8 changes: 8 additions & 0 deletions test/bridge/Upgradeable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ describe("Upgradeable", () => {
await expect(newBridge.upgradeToWithSig(await newBridge.getAddress(), [])).to.be.rejectedWith(
"Function must be called through delegatecall",
);

await expect(newBridge.upgradeToWithSigAndCall(await newBridge.getAddress(), [], "0x")).to.be.rejectedWith(
"Function must be called through delegatecall",
);
});

it("should upgrade implementation", async () => {
Expand Down Expand Up @@ -85,6 +89,10 @@ describe("Upgradeable", () => {
await expect(proxyBridge.connect(SECOND).upgradeToWithSig(await newBridge.getAddress(), [])).to.be.rejectedWith(
"Ownable: caller is not the owner",
);

await expect(
proxyBridge.connect(SECOND).upgradeToWithSigAndCall(await newBridge.getAddress(), [], "0x"),
).to.be.rejectedWith("Ownable: caller is not the owner");
});

it("should receive ether through proxy", async () => {
Expand Down
Loading