@@ -1735,14 +1735,14 @@ mod tests {
17351735 use crate :: {
17361736 compression:: CompressedBincode ,
17371737 db:: {
1738- CommitKey , CommitReceipts , LegacyAddressWrapper , PendingCommit , PersistentDB ,
1739- PersistentDBOptions , StaticStringWrapper , StringWrapper ,
1738+ BlockHeaderData , CommitKey , CommitReceipts , LegacyAddressWrapper , PendingCommit ,
1739+ PersistentDB , PersistentDBOptions , StaticStringWrapper , StringWrapper ,
17401740 } ,
17411741 legacy:: { LegacyAccountAttributes , LegacyAddress } ,
17421742 receipt:: TxReceipt ,
17431743 } ;
17441744 use alloy_primitives:: { B256 , U256 , address, b256} ;
1745- use revm:: { primitives:: HashMap , state:: AccountInfo } ;
1745+ use revm:: { Database , primitives:: HashMap , state:: AccountInfo } ;
17461746
17471747 use heed:: { BytesDecode , BytesEncode } ;
17481748
@@ -1823,14 +1823,43 @@ mod tests {
18231823 }
18241824
18251825 #[ test]
1826- fn test_read_receipts ( ) {
1827- let path = tempfile:: Builder :: new ( )
1828- . prefix ( "evm.mdb" )
1829- . tempdir ( )
1830- . unwrap ( ) ;
1826+ fn test_block_hash ( ) {
1827+ let mut db = create_temp_database ( ) ;
18311828
1832- let db = PersistentDB :: new ( PersistentDBOptions :: new ( path. path ( ) . to_path_buf ( ) ) )
1833- . expect ( "database" ) ;
1829+ let hash = db. block_hash ( 1 ) . unwrap ( ) ;
1830+ assert_eq ! ( hash, B256 :: ZERO ) ;
1831+
1832+ {
1833+ let mut wtxn = db. env . write_txn ( ) . unwrap ( ) ;
1834+ let inner = db. inner . borrow_mut ( ) ;
1835+
1836+ inner
1837+ . blocks
1838+ . put (
1839+ & mut wtxn,
1840+ & 1 ,
1841+ & CompressedBincode ( & BlockHeaderData {
1842+ hash : b256 ! (
1843+ "0000000000000000000000000000000000000000000000000000000000000001"
1844+ ) ,
1845+ ..Default :: default ( )
1846+ } ) ,
1847+ )
1848+ . unwrap ( ) ;
1849+
1850+ wtxn. commit ( ) . unwrap ( ) ;
1851+ }
1852+
1853+ let hash = db. block_hash ( 1 ) . unwrap ( ) ;
1854+ assert_eq ! (
1855+ hash,
1856+ b256!( "0000000000000000000000000000000000000000000000000000000000000001" )
1857+ ) ;
1858+ }
1859+
1860+ #[ test]
1861+ fn test_read_receipts ( ) {
1862+ let db = create_temp_database ( ) ;
18341863
18351864 let target_block = 100 ;
18361865 let mut total_receipts = 0 ;
@@ -1907,4 +1936,16 @@ mod tests {
19071936 assert_eq ! ( read_block_number, target_block) ;
19081937 assert_eq ! ( read_receipts, total_receipts) ;
19091938 }
1939+
1940+ fn create_temp_database ( ) -> PersistentDB {
1941+ let path = tempfile:: Builder :: new ( )
1942+ . prefix ( "evm.mdb" )
1943+ . tempdir ( )
1944+ . unwrap ( ) ;
1945+
1946+ let db = PersistentDB :: new ( PersistentDBOptions :: new ( path. path ( ) . to_path_buf ( ) ) )
1947+ . expect ( "database" ) ;
1948+
1949+ db
1950+ }
19101951}
0 commit comments