feat: demonstrate state-preserving V2 upgrade

This commit is contained in:
golem
2026-08-21 15:31:40 -06:00
parent ca6a99b913
commit 94f2ad6e09
16 changed files with 1082 additions and 36 deletions
+19 -2
View File
@@ -12,11 +12,14 @@ contract CheckState is DemoScript {
error UnknownStage(string stage);
function run() external view {
_run(_manifestPath(ACTIVE_MANIFEST_PATH), vm.envOr("DEMO_EXPECTED_STAGE", string("v1")));
}
function _run(string memory manifestPath, string memory stage) internal view {
_requireSupportedChain(block.chainid);
_printEducationalWarning();
string memory stage = vm.envOr("DEMO_EXPECTED_STAGE", string("v1"));
bool deployedStage = keccak256(bytes(stage)) == keccak256("deployed");
Manifest memory manifest = _readManifest(_manifestPath(ACTIVE_MANIFEST_PATH), !deployedStage);
Manifest memory manifest = _readManifest(manifestPath, !deployedStage);
BankV1 bank = BankV1(manifest.proxy);
MockUSDC token = MockUSDC(manifest.token);
@@ -53,6 +56,20 @@ contract CheckState is DemoScript {
} else if (stageHash == keccak256("v1")) {
_assertV1State(manifest);
_assertUint("surplus", 0, surplus);
} else if (stageHash == keccak256("upgraded")) {
_assertUint("Alice internal balance", 900e6, bank.balanceOf(manifest.actors[1].address_));
_assertUint("Bob internal balance", 500e6, bank.balanceOf(manifest.actors[2].address_));
_assertUint("liabilities", 1_400e6, liabilities);
_assertUint("reserves", 1_400e6, reserves);
_assertUint("surplus", 0, surplus);
_assertUint("version", 2, bank.contractVersion());
} else if (stageHash == keccak256("v2")) {
_assertUint("Alice internal balance", 650e6, bank.balanceOf(manifest.actors[1].address_));
_assertUint("Bob internal balance", 750e6, bank.balanceOf(manifest.actors[2].address_));
_assertUint("liabilities", 1_400e6, liabilities);
_assertUint("reserves", 1_400e6, reserves);
_assertUint("surplus", 0, surplus);
_assertUint("version", 2, bank.contractVersion());
} else if (stageHash != keccak256("invariants")) {
revert UnknownStage(stage);
}