Repository navigation
feat(id): currency status transitions (freeze/sunset) in the registry and gateway service (#13342) #13547
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(id): currency status transitions (freeze/sunset) in the registry and gateway service (#13342) #13547
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,3 +240,105 @@ fn migration_creates_the_four_tables_with_the_named_constraints() { | |
| // Design section 6: the allocator entry point exists. | ||
| assert!(sql.contains("create function allocate_ledger")); | ||
| } | ||
|
|
||
| // Status transitions (issue #13342). The oracle is the issue's | ||
| // Acceptance list: "Registry tests: transition happy paths, | ||
| // non-issuer refusal, repeat-transition behavior as documented." | ||
|
|
||
| #[test] | ||
| fn issuer_can_freeze_then_sunset_and_sunset_is_terminal() { | ||
|
Comment on lines
+248
to
+249
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new lifecycle is a specified state machine with terminal-state, authorization, and idempotence invariants, but its coverage consists solely of hand-written examples. AGENTS.md reference: AGENTS.md:L37-L39 Useful? React with 👍 / 👎. |
||
| let mut registry = Registry::new(InMemoryStore::new()); | ||
| registry | ||
| .register_currency(register_input("abc", "alice", "ABC")) | ||
| .unwrap(); | ||
| // Sunset is reachable from frozen: freeze first. | ||
| let frozen = registry.freeze_currency("abc", "alice").unwrap(); | ||
| assert_eq!(frozen.status, CurrencyStatus::Frozen); | ||
| assert_eq!( | ||
| registry.resolve("abc").unwrap().status, | ||
| CurrencyStatus::Frozen, | ||
| "the store carries the new status" | ||
| ); | ||
| let sunset = registry.sunset_currency("abc", "alice").unwrap(); | ||
| assert_eq!(sunset.status, CurrencyStatus::Sunset); | ||
| // Sunset is terminal: freezing a sunset currency is a typed | ||
| // refusal naming the from/to statuses. | ||
| let err = registry.freeze_currency("abc", "alice").unwrap_err(); | ||
| assert_eq!( | ||
| err, | ||
| RegistryError::InvalidTransition { | ||
| currency_id: "abc".to_owned(), | ||
| from: CurrencyStatus::Sunset, | ||
| to: CurrencyStatus::Frozen, | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn issuer_can_sunset_directly_from_active() { | ||
| let mut registry = Registry::new(InMemoryStore::new()); | ||
| registry | ||
| .register_currency(register_input("abc", "alice", "ABC")) | ||
| .unwrap(); | ||
| let sunset = registry.sunset_currency("abc", "alice").unwrap(); | ||
| assert_eq!(sunset.status, CurrencyStatus::Sunset); | ||
| assert_eq!( | ||
| registry.resolve("abc").unwrap().status, | ||
| CurrencyStatus::Sunset | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn only_the_issuer_can_transition_status() { | ||
| let mut registry = Registry::new(InMemoryStore::new()); | ||
| registry | ||
| .register_currency(register_input("abc", "alice", "ABC")) | ||
| .unwrap(); | ||
| for attempt in [ | ||
| registry.freeze_currency("abc", "mallory"), | ||
| registry.sunset_currency("abc", "mallory"), | ||
| ] { | ||
| assert_eq!( | ||
| attempt.unwrap_err(), | ||
| RegistryError::NotIssuer { | ||
| currency_id: "abc".to_owned(), | ||
| account_id: "mallory".to_owned(), | ||
| } | ||
| ); | ||
| } | ||
| // The refusals moved nothing. | ||
| assert_eq!( | ||
| registry.resolve("abc").unwrap().status, | ||
| CurrencyStatus::Active | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn repeat_transitions_are_idempotent_successes() { | ||
| let mut registry = Registry::new(InMemoryStore::new()); | ||
| registry | ||
| .register_currency(register_input("abc", "alice", "ABC")) | ||
| .unwrap(); | ||
| // Freeze on frozen answers with the record as it stands. | ||
| let first = registry.freeze_currency("abc", "alice").unwrap(); | ||
| let repeat = registry.freeze_currency("abc", "alice").unwrap(); | ||
| assert_eq!(repeat, first); | ||
| // Sunset on sunset likewise. | ||
| let first = registry.sunset_currency("abc", "alice").unwrap(); | ||
| let repeat = registry.sunset_currency("abc", "alice").unwrap(); | ||
| assert_eq!(repeat, first); | ||
| assert_eq!(repeat.status, CurrencyStatus::Sunset); | ||
| } | ||
|
|
||
| #[test] | ||
| fn transitions_on_an_unknown_currency_are_refused() { | ||
| let mut registry = Registry::new(InMemoryStore::new()); | ||
| assert_eq!( | ||
| registry.freeze_currency("nope", "alice").unwrap_err(), | ||
| RegistryError::UnknownCurrency("nope".to_owned()) | ||
| ); | ||
| assert_eq!( | ||
| registry.sunset_currency("nope", "alice").unwrap_err(), | ||
| RegistryError::UnknownCurrency("nope".to_owned()) | ||
| ); | ||
| } | ||
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.
This adds public lifecycle APIs and decides terminal-sunset, repeat-idempotence, and restart-replay semantics, but records those decisions only in Rust comments. The earlier control-plane design defines the status flags and signed writes, not these transition/recovery choices; a repository-wide documentation search found no corresponding dated record. Add the dated design document required by
pkgs/id/AGENTS.md, explaining the transition table and retry/replay rationale, so this behavioral/API change has the required architecture history.AGENTS.md reference: pkgs/id/AGENTS.md:L159-L168
Useful? React with 👍 / 👎.