Skip to content

Commit

Permalink
tests: Test blob insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
netrome committed Feb 4, 2025
1 parent 54d1e6b commit 3f9006e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions crates/fraud_proofs/global_merkle_root/storage/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,13 @@ mod tests {
StorageAsRef,
};
use fuel_core_types::fuel_tx::{
BlobId,
BlobIdExt,
Bytes32,
ContractId,
TransactionBuilder,
TxId,
Witness,
};

use rand::{
Expand Down Expand Up @@ -554,6 +558,50 @@ mod tests {
assert!(coin_doesnt_exist_after_process_input);
}

#[test]
/// When encountering a blob transaction,
/// `process_transaction` should insert the
/// corresponding blob.
fn process_transaction__should_insert_blob() {
let mut rng = StdRng::seed_from_u64(1337);

// Given
let blob = vec![1, 3, 3, 7];
let blob_id = BlobId::compute(&blob);
let body = BlobBody {
id: blob_id,
witness_index: 0,
};
let blob_tx = TransactionBuilder::blob(body)
.add_witness(Witness::from(blob.as_slice()))
.finalize_as_transaction();

let mut storage: InMemoryStorage<Column> = InMemoryStorage::default();
let mut storage_tx = storage.write_transaction();
let mut storage_update_tx =
storage_tx.construct_update_merkleized_tables_transaction();

let block_height = BlockHeight::new(rng.gen());
let tx_idx = rng.gen();

// When
storage_update_tx
.process_transaction(block_height, tx_idx, &blob_tx)
.unwrap();

storage_tx.commit().unwrap();

let read_tx = storage.read_transaction();
let blob_in_storage = read_tx
.storage_as_ref::<Blobs>()
.get(&blob_id)
.unwrap()
.unwrap();

// Then
assert_eq!(blob_in_storage.0.as_slice(), blob.as_slice());
}

fn random_utxo_id(rng: &mut impl rand::RngCore) -> UtxoId {
let mut txid = TxId::default();
rng.fill_bytes(txid.as_mut());
Expand Down

0 comments on commit 3f9006e

Please sign in to comment.