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 c31cf11
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions 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 @@ -547,7 +549,9 @@ order by open_message.created_at desc, open_message.rowid desc
mod tests {
use mithril_common::{entities::Beacon, sqlite::SourceAlias};

use crate::{dependency_injection::DependenciesBuilder, Configuration};
use crate::{
database::provider::signed_entity, dependency_injection::DependenciesBuilder, Configuration,
};

use super::*;

Expand Down Expand Up @@ -697,6 +701,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 c31cf11

Please sign in to comment.