Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix bug in TimeEvent witness blocks parsing logic #486

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions event/src/unvalidated/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ mod tests {
use crate::unvalidated::signed::JwkSigner;
use crate::unvalidated::tests::{
DATA_EVENT_PAYLOAD, SIGNED_INIT_EVENT, SIGNED_INIT_EVENT_CAR, SIGNED_INIT_EVENT_CID,
SIGNED_INIT_EVENT_PAYLOAD, TIME_EVENT_CAR,
SIGNED_INIT_EVENT_PAYLOAD, TIME_EVENT_CAR_SINGLE_EVENT_BATCH,
};
use crate::DidDocument;

Expand Down Expand Up @@ -508,7 +508,7 @@ mod tests {
assert_eq!(SIGNED_INIT_EVENT_CAR, event_car_str);
}
#[test(tokio::test)]
async fn build_time_event() {
async fn build_time_event_single_event_batch() {
let id = Cid::from_str(SIGNED_INIT_EVENT_CID).unwrap();
let prev =
Cid::from_str("bagcqcerae5oqoglzjjgz53enwsttl7mqglp5eoh2llzbbvfktmzxleeiffbq").unwrap();
Expand All @@ -532,6 +532,6 @@ mod tests {
multibase::Base::Base64Url,
event.encode_car().await.unwrap(),
);
assert_eq!(TIME_EVENT_CAR, event_car_str);
assert_eq!(TIME_EVENT_CAR_SINGLE_EVENT_BATCH, event_car_str);
}
}
24 changes: 15 additions & 9 deletions event/src/unvalidated/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ where
let block_bytes = car_blocks
.get(&proof.root())
.ok_or_else(|| anyhow!("Time Event CAR data missing block for root",))?;
let mut block: Ipld = serde_ipld_dagcbor::from_slice(block_bytes)?;
blocks_in_path.push(block.clone());
blocks_in_path.push(serde_ipld_dagcbor::from_slice(block_bytes)?);
let parts: Vec<_> = event.path().split('/').collect();
// Add blocks for all parts but the last as it is the prev.
for index in parts.iter().take(parts.len() - 1) {
let cid = block
let cid = blocks_in_path
.last()
.unwrap()
dav1do marked this conversation as resolved.
Show resolved Hide resolved
.get(*index)?
.ok_or_else(|| anyhow!("Time Event path indexes missing data"))?;
let cid = match cid {
Expand All @@ -65,8 +66,7 @@ where
let block_bytes = car_blocks
.get(cid)
.ok_or_else(|| anyhow!("Time Event CAR data missing block for path index"))?;
blocks_in_path.push(block);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the bug. We pushed the block before we updated it, meaning we pushed the first block twice and dropped the last block

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😨

block = serde_ipld_dagcbor::from_slice(block_bytes)?;
blocks_in_path.push(serde_ipld_dagcbor::from_slice(block_bytes)?);
}

Ok(blocks_in_path)
Expand Down Expand Up @@ -407,12 +407,14 @@ mod tests {
use ipld_core::ipld::Ipld;
use test_log::test;

use crate::unvalidated::tests::{SIGNED_INIT_EVENT_CID, UNSIGNED_INIT_NO_SEP_CAR};
use crate::unvalidated::tests::{
SIGNED_INIT_EVENT_CID, TIME_EVENT_CAR_MULTI_EVENT_BATCH, UNSIGNED_INIT_NO_SEP_CAR,
};
use crate::unvalidated::{
payload,
tests::{
CACAO_SIGNED_DATA_EVENT_CAR, DATA_EVENT_CAR_UNSIGNED_INIT, SIGNED_DATA_EVENT_CAR,
SIGNED_INIT_EVENT_CAR, TIME_EVENT_CAR, UNSIGNED_INIT_EVENT_CAR,
SIGNED_INIT_EVENT_CAR, TIME_EVENT_CAR_SINGLE_EVENT_BATCH, UNSIGNED_INIT_EVENT_CAR,
},
Builder, Event,
};
Expand Down Expand Up @@ -448,8 +450,12 @@ mod tests {
round_trip(DATA_EVENT_CAR_UNSIGNED_INIT).await;
}
#[test(tokio::test)]
async fn round_trip_time_event() {
round_trip(TIME_EVENT_CAR).await;
async fn round_trip_time_event_single_event_batch() {
round_trip(TIME_EVENT_CAR_SINGLE_EVENT_BATCH).await;
}
#[test(tokio::test)]
async fn round_trip_time_event_multi_event_batch() {
round_trip(TIME_EVENT_CAR_MULTI_EVENT_BATCH).await;
}
#[test(tokio::test)]
async fn round_trip_init_payload_with_no_sep() {
Expand Down
4 changes: 3 additions & 1 deletion event/src/unvalidated/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ mod tests {
// Data event signed with a CACAO
pub const CACAO_SIGNED_DATA_EVENT_CAR:&str="mO6Jlcm9vdHOB2CpYJgABhQESIN12WhnV8Y3aMRxZYqUSpaO4mSQnbGxEpeC8jMsldwv6Z3ZlcnNpb24BigQBcRIgtP3Gc62zs2I/pu98uctnwBAYUUrgyLjnPaxYwOnBytajYWihYXRnZWlwNDM2MWFwqWNhdWR4OGRpZDprZXk6ejZNa3I0YTNaM0ZGYUpGOFlxV25XblZIcWQ1ZURqWk45YkRTVDZ3VlpDMWhKODFQY2V4cHgYMjAyNC0wNi0xOVQyMDowNDo0Mi40NjRaY2lhdHgYMjAyNC0wNi0xMlQyMDowNDo0Mi40NjRaY2lzc3g7ZGlkOnBraDplaXAxNTU6MToweDM3OTRkNGYwNzdjMDhkOTI1ZmY4ZmY4MjAwMDZiNzM1MzI5OWIyMDBlbm9uY2Vqd1BpQ09jcGtsbGZkb21haW5kdGVzdGd2ZXJzaW9uYTFpcmVzb3VyY2VzgWtjZXJhbWljOi8vKmlzdGF0ZW1lbnR4PEdpdmUgdGhpcyBhcHBsaWNhdGlvbiBhY2Nlc3MgdG8gc29tZSBvZiB5b3VyIGRhdGEgb24gQ2VyYW1pY2FzomFzeIQweGIyNjY5OTkyNjM0NDZkZGI5YmY1ODg4MjVlOWFjMDhiNTQ1ZTY1NWY2MDc3ZThkODU3O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