11import { Blob } from '@aztec/blob-lib' ;
22import { Fr } from '@aztec/foundation/curves/bn254' ;
33
4- import { BlobWithIndex } from '../types/index.js' ;
54import type { BlobStore } from './interface.js' ;
65
76export function describeBlobStore ( getBlobStore : ( ) => Promise < BlobStore > ) {
@@ -15,39 +14,36 @@ export function describeBlobStore(getBlobStore: () => Promise<BlobStore>) {
1514 // Create a test blob with random fields
1615 const testFields = [ Fr . random ( ) , Fr . random ( ) , Fr . random ( ) ] ;
1716 const blob = Blob . fromFields ( testFields ) ;
18- const blobWithIndex = new BlobWithIndex ( blob , 0 ) ;
1917 const blobHash = blob . getEthVersionedBlobHash ( ) ;
2018
2119 // Store the blob
22- await blobStore . addBlobs ( [ blobWithIndex ] ) ;
20+ await blobStore . addBlobs ( [ blob ] ) ;
2321
2422 // Retrieve the blob by hash
2523 const retrievedBlobs = await blobStore . getBlobsByHashes ( [ blobHash ] ) ;
2624
2725 // Verify the blob was retrieved and matches
2826 expect ( retrievedBlobs . length ) . toBe ( 1 ) ;
29- expect ( retrievedBlobs [ 0 ] . blob ) . toEqual ( blob ) ;
27+ expect ( retrievedBlobs [ 0 ] ) . toEqual ( blob ) ;
3028 } ) ;
3129
3230 it ( 'should handle multiple blobs stored and retrieved by their hashes' , async ( ) => {
3331 // Create two different blobs
3432 const blob1 = Blob . fromFields ( [ Fr . random ( ) , Fr . random ( ) ] ) ;
3533 const blob2 = Blob . fromFields ( [ Fr . random ( ) , Fr . random ( ) , Fr . random ( ) ] ) ;
36- const blobWithIndex1 = new BlobWithIndex ( blob1 , 0 ) ;
37- const blobWithIndex2 = new BlobWithIndex ( blob2 , 1 ) ;
3834
3935 const blobHash1 = blob1 . getEthVersionedBlobHash ( ) ;
4036 const blobHash2 = blob2 . getEthVersionedBlobHash ( ) ;
4137
4238 // Store both blobs
43- await blobStore . addBlobs ( [ blobWithIndex1 , blobWithIndex2 ] ) ;
39+ await blobStore . addBlobs ( [ blob1 , blob2 ] ) ;
4440
4541 // Retrieve and verify both blobs
4642 const retrievedBlobs = await blobStore . getBlobsByHashes ( [ blobHash1 , blobHash2 ] ) ;
4743
4844 expect ( retrievedBlobs . length ) . toBe ( 2 ) ;
49- expect ( retrievedBlobs [ 0 ] . blob ) . toEqual ( blob1 ) ;
50- expect ( retrievedBlobs [ 1 ] . blob ) . toEqual ( blob2 ) ;
45+ expect ( retrievedBlobs [ 0 ] ) . toEqual ( blob1 ) ;
46+ expect ( retrievedBlobs [ 1 ] ) . toEqual ( blob2 ) ;
5147 } ) ;
5248
5349 it ( 'should return empty array for non-existent blob hash' , async ( ) => {
@@ -59,31 +55,13 @@ export function describeBlobStore(getBlobStore: () => Promise<BlobStore>) {
5955 expect ( retrievedBlobs ) . toEqual ( [ ] ) ;
6056 } ) ;
6157
62- it ( 'should handle storing blobs with different indices' , async ( ) => {
63- // Create blobs with different indices
64- const blob1 = Blob . fromFields ( [ Fr . random ( ) ] ) ;
65- const blob2 = Blob . fromFields ( [ Fr . random ( ) ] ) ;
66- const blobWithIndex1 = new BlobWithIndex ( blob1 , 0 ) ;
67- const blobWithIndex2 = new BlobWithIndex ( blob2 , 1 ) ;
68-
69- await blobStore . addBlobs ( [ blobWithIndex1 , blobWithIndex2 ] ) ;
70-
71- const blobHash1 = blob1 . getEthVersionedBlobHash ( ) ;
72- const blobHash2 = blob2 . getEthVersionedBlobHash ( ) ;
73-
74- const retrievedBlobs = await blobStore . getBlobsByHashes ( [ blobHash1 , blobHash2 ] ) ;
75-
76- expect ( retrievedBlobs [ 0 ] . index ) . toBe ( 0 ) ;
77- expect ( retrievedBlobs [ 1 ] . index ) . toBe ( 1 ) ;
78- } ) ;
79-
8058 it ( 'should handle retrieving subset of stored blobs' , async ( ) => {
8159 // Store multiple blobs
8260 const blob1 = Blob . fromFields ( [ Fr . random ( ) ] ) ;
8361 const blob2 = Blob . fromFields ( [ Fr . random ( ) ] ) ;
8462 const blob3 = Blob . fromFields ( [ Fr . random ( ) ] ) ;
8563
86- await blobStore . addBlobs ( [ new BlobWithIndex ( blob1 , 0 ) , new BlobWithIndex ( blob2 , 1 ) , new BlobWithIndex ( blob3 , 2 ) ] ) ;
64+ await blobStore . addBlobs ( [ blob1 , blob2 , blob3 ] ) ;
8765
8866 // Retrieve only some of them
8967 const blobHash1 = blob1 . getEthVersionedBlobHash ( ) ;
@@ -92,23 +70,22 @@ export function describeBlobStore(getBlobStore: () => Promise<BlobStore>) {
9270 const retrievedBlobs = await blobStore . getBlobsByHashes ( [ blobHash1 , blobHash3 ] ) ;
9371
9472 expect ( retrievedBlobs . length ) . toBe ( 2 ) ;
95- expect ( retrievedBlobs [ 0 ] . blob ) . toEqual ( blob1 ) ;
96- expect ( retrievedBlobs [ 1 ] . blob ) . toEqual ( blob3 ) ;
73+ expect ( retrievedBlobs [ 0 ] ) . toEqual ( blob1 ) ;
74+ expect ( retrievedBlobs [ 1 ] ) . toEqual ( blob3 ) ;
9775 } ) ;
9876
9977 it ( 'should handle duplicate blob hashes in request' , async ( ) => {
10078 const blob = Blob . fromFields ( [ Fr . random ( ) ] ) ;
101- const blobWithIndex = new BlobWithIndex ( blob , 0 ) ;
10279 const blobHash = blob . getEthVersionedBlobHash ( ) ;
10380
104- await blobStore . addBlobs ( [ blobWithIndex ] ) ;
81+ await blobStore . addBlobs ( [ blob ] ) ;
10582
10683 // Request the same blob hash multiple times
10784 const retrievedBlobs = await blobStore . getBlobsByHashes ( [ blobHash , blobHash ] ) ;
10885
10986 // Implementation may return duplicates or deduplicate - both are valid
11087 expect ( retrievedBlobs . length ) . toBeGreaterThanOrEqual ( 1 ) ;
111- expect ( retrievedBlobs [ 0 ] . blob ) . toEqual ( blob ) ;
88+ expect ( retrievedBlobs [ 0 ] ) . toEqual ( blob ) ;
11289 } ) ;
11390
11491 it ( 'should overwrite blob when storing with same hash' , async ( ) => {
@@ -117,21 +94,17 @@ export function describeBlobStore(getBlobStore: () => Promise<BlobStore>) {
11794 const blob1 = Blob . fromFields ( fields ) ;
11895 const blob2 = Blob . fromFields ( fields ) ;
11996
120- // Store with different indices
121- const blobWithIndex1 = new BlobWithIndex ( blob1 , 0 ) ;
122- const blobWithIndex2 = new BlobWithIndex ( blob2 , 5 ) ;
123-
12497 const blobHash = blob1 . getEthVersionedBlobHash ( ) ;
12598
12699 // Store first blob
127- await blobStore . addBlobs ( [ blobWithIndex1 ] ) ;
100+ await blobStore . addBlobs ( [ blob1 ] ) ;
128101
129- // Overwrite with second blob (same hash, different index )
130- await blobStore . addBlobs ( [ blobWithIndex2 ] ) ;
102+ // Overwrite with second blob (same hash)
103+ await blobStore . addBlobs ( [ blob2 ] ) ;
131104
132- // Retrieve and verify it's the second blob (with index 5)
105+ // Retrieve and verify it exists
133106 const retrievedBlobs = await blobStore . getBlobsByHashes ( [ blobHash ] ) ;
134107 expect ( retrievedBlobs . length ) . toBe ( 1 ) ;
135- expect ( retrievedBlobs [ 0 ] . index ) . toBe ( 5 ) ;
108+ expect ( retrievedBlobs [ 0 ] ) . toEqual ( blob1 ) ; // Same content
136109 } ) ;
137110}
0 commit comments