v0.3.8-pre.005
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-store-postgres-lib/unit_tests/raw_account.rs
|
||||
// version: 5
|
||||
// version: 6
|
||||
|
||||
fn network() -> ksp_store_api::RawNetworkId {
|
||||
return match ksp_store_api::RawNetworkId::new("devnet") {
|
||||
@@ -67,6 +67,95 @@ fn observation_row() -> super::RawAccountObservationDbRow {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
return super::RawAccountInspectionDbRow {
|
||||
data_length_bytes: std::option::Option::Some(data_length_bytes),
|
||||
executable: std::option::Option::Some(true),
|
||||
filtered_count_text: "3".to_owned(),
|
||||
lamports_text: std::option::Option::Some(u64::MAX.to_string()),
|
||||
owner: std::option::Option::Some(vec![2; 32]),
|
||||
page_present: true,
|
||||
pubkey: std::option::Option::Some(vec![1; 32]),
|
||||
rent_epoch_text: std::option::Option::Some(u64::MAX.to_string()),
|
||||
slot_text: std::option::Option::Some(u64::MAX.to_string()),
|
||||
state_hash: std::option::Option::Some(vec![3; 32]),
|
||||
total_count_text: "4".to_owned(),
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn v0_3_8_pre_005_inspection_window_rejects_unrepresentable_limit_and_offset_before_io() {
|
||||
let normal_limit = match ksp_store_api::RawPageLimit::new(100) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => panic!("valid account inspection page limit rejected: {error:?}"),
|
||||
};
|
||||
let normal = super::raw_account_inspection_sql_window(ksp_store_api::RawInspectionPageRequest::new(25, normal_limit));
|
||||
assert_eq!(normal, std::result::Result::Ok((100, 25)));
|
||||
let huge_limit = match ksp_store_api::RawPageLimit::new(u64::MAX) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => panic!("API unexpectedly rejected backend-physical account limit fixture: {error:?}"),
|
||||
};
|
||||
let limit_error = super::raw_account_inspection_sql_window(ksp_store_api::RawInspectionPageRequest::new(0, huge_limit));
|
||||
assert_eq!(
|
||||
limit_error.err().map(|value| return (value.kind(), value.phase())),
|
||||
std::option::Option::Some((crate::PostgresBackendErrorKind::PageLimitUnsupported, "raw_account_inspection_limit")),
|
||||
);
|
||||
let offset_error = super::raw_account_inspection_sql_window(ksp_store_api::RawInspectionPageRequest::new(u64::MAX, normal_limit));
|
||||
assert_eq!(
|
||||
offset_error.err().map(|value| return (value.kind(), value.phase())),
|
||||
std::option::Option::Some((crate::PostgresBackendErrorKind::QueryInvalid, "raw_account_inspection_offset")),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn v0_3_8_pre_005_inspection_summary_is_data_free_and_preserves_complete_u64_domain() {
|
||||
let network = network();
|
||||
let decoded = super::decode_raw_account_inspection_summary(&network, inspection_row(4));
|
||||
let summary = match decoded {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => panic!("valid account inspection summary rejected: {error:?}"),
|
||||
};
|
||||
assert_eq!(summary.reference().network().as_str(), "devnet");
|
||||
assert_eq!(summary.reference().pubkey(), &ksp_store_api::Pubkey::new_from_array([1; 32]));
|
||||
assert_eq!(summary.reference().slot(), u64::MAX);
|
||||
assert_eq!(summary.reference().state_hash(), ksp_store_api::RawContentHash::new([3; 32]));
|
||||
assert_eq!(summary.lamports(), u64::MAX);
|
||||
assert_eq!(summary.owner(), &ksp_store_api::Pubkey::new_from_array([2; 32]));
|
||||
assert!(summary.executable());
|
||||
assert_eq!(summary.rent_epoch(), u64::MAX);
|
||||
assert_eq!(summary.data_length_bytes(), 4);
|
||||
return;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn v0_3_8_pre_005_inspection_summary_rejects_hostile_width_decimal_and_data_length() {
|
||||
let network = network();
|
||||
let mut bad_owner = inspection_row(4);
|
||||
bad_owner.owner = std::option::Option::Some(vec![2; 31]);
|
||||
assert_eq!(
|
||||
super::decode_raw_account_inspection_summary(&network, bad_owner).err().map(|value| return value.kind()),
|
||||
std::option::Option::Some(crate::PostgresBackendErrorKind::DataInvalid)
|
||||
);
|
||||
let mut bad_slot = inspection_row(4);
|
||||
bad_slot.slot_text = std::option::Option::Some("18446744073709551616-HOSTILE".to_owned());
|
||||
let error = match super::decode_raw_account_inspection_summary(&network, bad_slot) {
|
||||
std::result::Result::Err(value) => value,
|
||||
std::result::Result::Ok(_) => panic!("hostile account inspection slot unexpectedly decoded"),
|
||||
};
|
||||
assert_eq!(error.kind(), crate::PostgresBackendErrorKind::DataInvalid);
|
||||
assert!(!std::format!("{error:?}").contains("HOSTILE"));
|
||||
let maximum = match i64::try_from(ksp_store_api::MAX_RAW_ACCOUNT_DATA_BYTES) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => panic!("account data bound must fit PostgreSQL BIGINT in test fixture"),
|
||||
};
|
||||
for length in [-1_i64, maximum.saturating_add(1)] {
|
||||
let result = super::decode_raw_account_inspection_summary(&network, inspection_row(length));
|
||||
assert_eq!(result.err().map(|value| return value.kind()), std::option::Option::Some(crate::PostgresBackendErrorKind::DataInvalid));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pre_004_account_state_row_round_trips_complete_u64_domain_and_bytes() {
|
||||
let network = network();
|
||||
|
||||
Reference in New Issue
Block a user