Skip to content

Commit

Permalink
Fix failed deserialization of TransactionEvents in HttpKVStore (#…
Browse files Browse the repository at this point in the history
…5308)

* fix(iota-storage): remove byte slice range

* refactor(iota-storage): modify test_multi_fetch to include also events
  • Loading branch information
sergiupopescu199 authored Feb 14, 2025
1 parent 59deb43 commit 16c4b2b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
3 changes: 1 addition & 2 deletions crates/iota-storage/src/http_key_value_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,7 @@ impl TransactionKeyValueStoreTrait for HttpKVStore {
.zip(digests.iter())
.map(map_fetch)
.map(|maybe_bytes| {
maybe_bytes
.and_then(|(bytes, key)| deser::<_, TransactionEvents>(&key, &bytes.slice(1..)))
maybe_bytes.and_then(|(bytes, key)| deser::<_, TransactionEvents>(&key, bytes))
})
.collect::<Vec<_>>())
}
Expand Down
27 changes: 24 additions & 3 deletions crates/iota-storage/tests/key_value_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ mod simtests {
use iota_macros::sim_test;
use iota_simulator::configs::constant_latency_ms;
use iota_storage::http_key_value_store::*;
use iota_types::event::Event;
use rustls::crypto::{CryptoProvider, ring};
use tracing::info;

Expand Down Expand Up @@ -420,6 +421,11 @@ mod simtests {
startup_receiver.changed().await.unwrap();
}

fn random_events() -> TransactionEvents {
let event = Event::random_for_testing();
TransactionEvents { data: vec![event] }
}

#[sim_test(config = "constant_latency_ms(250)")]
async fn test_multi_fetch() {
if CryptoProvider::get_default().is_none() {
Expand All @@ -429,21 +435,30 @@ mod simtests {
let mut data = HashMap::new();

let tx = random_tx();
let tx_digest = *tx.digest();
let random_digest = TransactionDigest::random();
let fx = random_fx();
let ev = random_events();

{
let bytes = bcs::to_bytes(&tx).unwrap();
assert_eq!(tx, bcs::from_bytes::<Transaction>(&bytes).unwrap());

let bytes = bcs::to_bytes(&fx).unwrap();
assert_eq!(fx, bcs::from_bytes::<TransactionEffects>(&bytes).unwrap());

let bytes = bcs::to_bytes(&ev).unwrap();
assert_eq!(ev, bcs::from_bytes::<TransactionEvents>(&bytes).unwrap());
}

data.insert(
format!("{}/tx", encode_digest(tx.digest())),
format!("{}/tx", encode_digest(&tx_digest)),
bcs::to_bytes(&tx).unwrap(),
);
data.insert(
format!("{}/evtx", encode_digest(&tx_digest)),
bcs::to_bytes(&ev).unwrap(),
);
data.insert(
format!("{}/fx", encode_digest(fx.transaction_digest())),
bcs::to_bytes(&fx).unwrap(),
Expand All @@ -461,12 +476,12 @@ mod simtests {
let store = HttpKVStore::new("http://10.10.10.10:8080").unwrap();

// send one request to warm up the client (and open a connection)
store.multi_get(&[*tx.digest()], &[]).await.unwrap();
store.multi_get(&[tx_digest], &[]).await.unwrap();

let start_time = Instant::now();
let result = store
.multi_get(
&[*tx.digest(), *random_tx().digest()],
&[tx_digest, *random_tx().digest()],
&[*fx.transaction_digest()],
)
.await
Expand All @@ -480,5 +495,11 @@ mod simtests {

let result = store.multi_get(&[random_digest], &[]).await.unwrap();
assert_eq!(result, (vec![None], vec![]));

let result = store
.multi_get_events_by_tx_digests(&[tx_digest])
.await
.unwrap();
assert_eq!(result, vec![Some(ev)]);
}
}

0 comments on commit 16c4b2b

Please sign in to comment.