Add upgrade e2e test and fix PackageUpgradedEvent parsing#456
Add upgrade e2e test and fix PackageUpgradedEvent parsing#456
Conversation
2dc5423 to
0403601
Compare
| /// 2. Validators confirm deposits post-upgrade — leader routes calls correctly | ||
| /// 3. Package ID routing — OnchainState.package_id() returns the new package | ||
| #[tokio::test] | ||
| #[ignore = "requires localnet (run with --ignored)"] |
There was a problem hiding this comment.
what is missing from being able to run this in CI?
| async fn wait_for_deposit_confirmation( | ||
| sui_client: &mut sui_rpc::Client, | ||
| request_id: Address, | ||
| timeout: Duration, | ||
| ) -> Result<()> { |
There was a problem hiding this comment.
These functions should already exist elsewhere in the e2e-tests, maybe they just need to be factored out into a common place to that they can be reused?
| #[cfg(test)] | ||
| mod tests { |
There was a problem hiding this comment.
This file is probably better placed in crates/e2e-tests/tests/upgrade_tests.rs then you shouldn't even need the cfg(test) dance.
| let patched = config_src.replace( | ||
| "const PACKAGE_VERSION: u64 = 1;", | ||
| "const PACKAGE_VERSION: u64 = 2;", | ||
| ); |
| //! | ||
| //! Exercises real cascading effects of upgrading the hashi package: | ||
| //! - Rust watcher picks up the new package version via PackageUpgradedEvent | ||
| //! - Validators auto-confirm deposits against the upgraded package |
There was a problem hiding this comment.
I'm actually semi-surprised that our system is already smart enough to do this as a part of our txn construction.
| /// Prepare an upgrade package by copying the deployed source and patching it. | ||
| /// | ||
| /// 1. Copies `<test_dir>/packages/hashi` to `<test_dir>/packages/hashi-upgrade` | ||
| /// 2. Bumps `PACKAGE_VERSION` from 1 to 2 in `config.move` | ||
| /// 3. Sets `published-at` in `Move.toml` to the original package ID | ||
| /// | ||
| /// Returns the path to the patched package directory. |
There was a problem hiding this comment.
Wonder if it would make sense to factor some, not all, of this logic into a reusable functions that we can then leverage in the cli to do upgrades in the future (create, vote, execute proposals). Specifically to do some explicit pre-flight checks (check that VERSION is exactly what we expect it to be +1 of the latest published version, etc.
Thoughts?
Adds an end-to-end test that exercises the full governance-gated upgrade lifecycle and verifies cascading effects across the stack. The test found a real bug: PackageUpgradedEvent was missing from HashiEvent::try_parse(), so validators never learned about package upgrades via the event stream. Fixed by adding the missing match arm. Test flow: - Deposit before upgrade, verify balance survives (state continuity) - Upgrade via propose/vote/execute+publish+finalize - Verify all node watchers pick up the new package version - Deposit after upgrade through full validator confirmation path - Call v2-only canary module (new code reachable) - Disable v1, verify entry points rejected
0403601 to
42de78f
Compare
Summary
PackageUpgradedEventwas missing fromHashiEvent::try_parse(), so validators never learned about package upgrades via the event stream — only on full rescrapeBug fix
PackageUpgradedEventhad a struct definition,MoveTypeimpl, and was handled in the watcher's event loop (watcher.rs:228), but was never added to thetry_parse()match arms inmove_types/mod.rs. The event was silently dropped at the catch-all_ => return Ok(None). After an upgrade, validators would not update their package version map until a subscription reconnect triggered a full rescrape.Test details
The test programmatically patches the deployed package at test time (bumps
PACKAGE_VERSION, injects a canary module), then verifies:PackageUpgradedEventOnchainState.package_id()returns the new package on all nodesEVersionDisabledFiles changed
crates/hashi-types/src/move_types/mod.rs— addPackageUpgradedEventtotry_parse()crates/e2e-tests/src/upgrade_flow.rs— upgrade helpers (prepare, build, propose/vote/execute, disable)crates/e2e-tests/src/upgrade_tests.rs— the e2e testcrates/e2e-tests/src/lib.rs— module declarations +dir()accessorTest plan
cargo test -p e2e-tests -- test_upgrade_v1_to_v2 --ignored— passes in ~44scargo check -p hashi— compiles clean