Skip to content

Commit b914d96

Browse files
committed
Fix open message hydrate error
1 parent a58808b commit b914d96

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

mithril-aggregator/src/database/provider/open_message.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ impl SqLiteEntity for OpenMessage {
9898
let epoch_val = u64::try_from(epoch_setting_id)
9999
.map_err(|e| panic!("Integer field open_message.epoch_setting_id (value={epoch_setting_id}) is incompatible with u64 Epoch representation. Error = {e}"))?;
100100

101-
let beacon_str = row.get::<String, _>(2);
101+
// TODO: We need to check first that the cell can be read as a string first
102+
// (e.g. when beacon json is '{"network": "dev", "epoch": 1, "immutable_file_number": 2}').
103+
// If it fails, we fallback on readign the cell as an integer (e.g. when beacon json is '5').
104+
// Maybe there is a better way of doing this.
105+
let beacon_str = row
106+
.try_get::<String, _>(2)
107+
.unwrap_or_else(|_| (row.get::<i64, _>(2)).to_string());
108+
102109
let signed_entity_type_id = usize::try_from(row.get::<i64, _>(3)).map_err(|e| {
103110
panic!(
104111
"Integer field open_message.signed_entity_type_id cannot be turned into usize: {e}"
@@ -697,6 +704,35 @@ mod tests {
697704
connection
698705
}
699706

707+
#[tokio::test]
708+
async fn repository_get_open_message() {
709+
let connection = get_connection().await;
710+
let repository = OpenMessageRepository::new(connection.clone());
711+
let beacon = Beacon::new("devnet".to_string(), 1, 1);
712+
713+
let signed_entity_type = SignedEntityType::MithrilStakeDistribution(beacon.epoch);
714+
repository
715+
.create_open_message(beacon.epoch, &signed_entity_type, &ProtocolMessage::new())
716+
.await
717+
.unwrap();
718+
let open_message_result = repository
719+
.get_open_message(&signed_entity_type)
720+
.await
721+
.unwrap();
722+
assert!(open_message_result.is_some());
723+
724+
let signed_entity_type = SignedEntityType::CardanoImmutableFilesFull(beacon.clone());
725+
repository
726+
.create_open_message(beacon.epoch, &signed_entity_type, &ProtocolMessage::new())
727+
.await
728+
.unwrap();
729+
let open_message_result = repository
730+
.get_open_message(&signed_entity_type)
731+
.await
732+
.unwrap();
733+
assert!(open_message_result.is_some());
734+
}
735+
700736
#[tokio::test]
701737
async fn repository_create_open_message() {
702738
let connection = get_connection().await;

0 commit comments

Comments
 (0)