Skip to content

Commit

Permalink
Fix open message hydrate error
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraynaud committed Apr 26, 2023
1 parent a58808b commit 74159f6
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion mithril-aggregator/src/database/provider/open_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ impl SqLiteEntity for OpenMessage {
let epoch_val = u64::try_from(epoch_setting_id)
.map_err(|e| panic!("Integer field open_message.epoch_setting_id (value={epoch_setting_id}) is incompatible with u64 Epoch representation. Error = {e}"))?;

let beacon_str = row.get::<String, _>(2);
let beacon_str = row
.try_get::<String, _>(2)
.unwrap_or_else(|_| (row.get::<i64, _>(2)).to_string());
let signed_entity_type_id = usize::try_from(row.get::<i64, _>(3)).map_err(|e| {
panic!(
"Integer field open_message.signed_entity_type_id cannot be turned into usize: {e}"
Expand Down Expand Up @@ -697,6 +699,35 @@ mod tests {
connection
}

#[tokio::test]
async fn repository_get_open_message() {
let connection = get_connection().await;
let repository = OpenMessageRepository::new(connection.clone());
let beacon = Beacon::new("devnet".to_string(), 1, 1);

let signed_entity_type = SignedEntityType::MithrilStakeDistribution(beacon.epoch);
repository
.create_open_message(beacon.epoch, &signed_entity_type, &ProtocolMessage::new())
.await
.unwrap();
let open_message_result = repository
.get_open_message(&signed_entity_type)
.await
.unwrap();
assert!(open_message_result.is_some());

let signed_entity_type = SignedEntityType::CardanoImmutableFilesFull(beacon.clone());
repository
.create_open_message(beacon.epoch, &signed_entity_type, &ProtocolMessage::new())
.await
.unwrap();
let open_message_result = repository
.get_open_message(&signed_entity_type)
.await
.unwrap();
assert!(open_message_result.is_some());
}

#[tokio::test]
async fn repository_create_open_message() {
let connection = get_connection().await;
Expand Down

0 comments on commit 74159f6

Please sign in to comment.