Files
khadhroony-solana-project/crates/ksp-store-postgres-lib/unit_tests/migration.rs
2026-08-29 19:53:00 +02:00

51 lines
2.3 KiB
Rust

// file: crates/ksp-store-postgres-lib/unit_tests/migration.rs
// version: 1
fn applied(version: i64, name: &str, checksum: &str) -> super::AppliedMigration {
return super::AppliedMigration { checksum: checksum.to_owned(), name: name.to_owned(), version };
}
#[test]
fn bootstrap_migration_is_static_metadata_only_and_checksum_is_stable_sha256() {
assert_eq!(super::BOOTSTRAP_MIGRATION_VERSION, 0);
assert_eq!(super::BOOTSTRAP_MIGRATION_NAME, "bootstrap");
assert!(super::BOOTSTRAP_MIGRATION_SQL.contains("CREATE TABLE ksp_store_schema_migrations"));
for forbidden in ["RawTransaction", "RawAccountState", "raw_transaction", "raw_account", "CORE", "DECODE", "SPECIALIZED"] {
assert!(!super::BOOTSTRAP_MIGRATION_SQL.contains(forbidden), "business schema leaked into bootstrap SQL: {forbidden}");
}
let checksum = super::bootstrap_checksum();
assert_eq!(checksum.len(), 64);
assert_eq!(checksum, "d29068b8c13b9dc0cc9ef6aaadd0fa12d41e0fe4c56541a1118c4bfc846a1450");
return;
}
#[test]
fn matching_sentinel_history_is_accepted() {
let checksum = super::bootstrap_checksum();
let history = [applied(0, "bootstrap", checksum.as_str())];
assert!(super::validate_history(&history, checksum.as_str()).is_ok());
return;
}
#[test]
fn divergent_or_missing_sentinel_is_terminal_mismatch() {
let checksum = super::bootstrap_checksum();
let wrong_name = [applied(0, "changed", checksum.as_str())];
let wrong_checksum = [applied(0, "bootstrap", "00")];
let missing: [super::AppliedMigration; 0] = [];
for history in [&wrong_name[..], &wrong_checksum[..], &missing[..]] {
let result = super::validate_history(history, checksum.as_str());
assert_eq!(result.err().map(|value| return value.kind()), std::option::Option::Some(crate::PostgresBackendErrorKind::MigrationMismatch));
}
return;
}
#[test]
fn newer_history_is_rejected_without_down_migration() {
let checksum = super::bootstrap_checksum();
let history = [applied(0, "bootstrap", checksum.as_str()), applied(1, "future", "future-checksum")];
let result = super::validate_history(&history, checksum.as_str());
assert_eq!(result.err().map(|value| return value.kind()), std::option::Option::Some(crate::PostgresBackendErrorKind::SchemaNewer));
return;
}