-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2127 test rollback strategies for smart contracts (#2154)
* downgrade demonstrated via test * test downgrade to invalid address reverts * turned require statements into reverts in scripts
- Loading branch information
1 parent
7e16992
commit 5262929
Showing
4 changed files
with
157 additions
and
15 deletions.
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import { Script } from "forge-std/Script.sol"; | ||
|
||
import { LightClientV2 as LCV2 } from "../LightClientV2.sol"; | ||
|
||
contract DowngradeLightClientScript is Script { | ||
/// @notice runs the downgrade | ||
/// @param mostRecentlyDeployedProxy address of deployed proxy | ||
/// @param lightClientImplAddr address of old light client implementation that we're downgrading | ||
/// to | ||
/// @return address of the proxy | ||
function run(address mostRecentlyDeployedProxy, address admin, address lightClientImplAddr) | ||
external | ||
returns (address) | ||
{ | ||
vm.startBroadcast(admin); | ||
address proxy = downgradeLightClient(mostRecentlyDeployedProxy, lightClientImplAddr); | ||
vm.stopBroadcast(); | ||
return proxy; | ||
} | ||
|
||
/// @notice downgrades the light client contract by calling the upgrade function in the | ||
/// implementation contract via the proxy | ||
/// @param proxyAddress address of proxy | ||
/// @param oldLightClient address of old implementation | ||
/// @return address of the proxy | ||
function downgradeLightClient(address proxyAddress, address oldLightClient) | ||
public | ||
returns (address) | ||
{ | ||
LCV2 proxy = LCV2(proxyAddress); //make the function call on the previous implementation | ||
|
||
// "upgrade" the proxy address so that it now points to the old implementation | ||
proxy.upgradeToAndCall(oldLightClient, ""); | ||
return address(proxy); | ||
} | ||
} |