From 78c53cf327090dbfe70c9e73001dfde3bae8ddc5 Mon Sep 17 00:00:00 2001 From: edef Date: Tue, 19 Apr 2022 01:15:25 +0000 Subject: ripple/fossil: add read_write test Change-Id: I88d13d9dd7055b8370706df7b3dd4479a0891399 --- ripple/fossil/src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'ripple/fossil') diff --git a/ripple/fossil/src/lib.rs b/ripple/fossil/src/lib.rs index 37df3bd..d7818cd 100644 --- a/ripple/fossil/src/lib.rs +++ b/ripple/fossil/src/lib.rs @@ -242,3 +242,21 @@ pub fn digest_from_bytes(bytes: &[u8]) -> Digest { buffer.copy_from_slice(bytes); buffer.into() } + +#[test] +/// Write a blob, and read it back. +fn read_write() { + let data = { + let mut h = blake3::Hasher::new(); + h.update(b"test vector"); + + let mut buf = Vec::new(); + h.finalize_xof().take(2468).read_to_end(&mut buf).unwrap(); + buf + }; + + // TODO(edef): use a temporary file + let store = Store::open("fossil.db").unwrap(); + let ident = store.write_blob(&data); + assert_eq!(data, store.read_blob(ident)); +} -- cgit 1.4.1