diff --git a/crates/net/eth-wire-types/src/header.rs b/crates/net/eth-wire-types/src/header.rs index 402212fda8c..986fbb006df 100644 --- a/crates/net/eth-wire-types/src/header.rs +++ b/crates/net/eth-wire-types/src/header.rs @@ -88,7 +88,7 @@ impl From for bool { mod tests { use super::*; use alloy_consensus::{Header, EMPTY_OMMER_ROOT_HASH, EMPTY_ROOT_HASH}; - use alloy_primitives::{address, b256, bloom, bytes, hex, Address, Bytes, B256, U256}; + use alloy_primitives::{address, b256, bloom, bytes, hex, Bytes, B256, U256}; use alloy_rlp::{Decodable, Encodable}; use std::str::FromStr; @@ -121,8 +121,7 @@ mod tests { #[test] fn test_eip1559_block_header_hash() { let expected_hash = - B256::from_str("6a251c7c3c5dca7b42407a3752ff48f3bbca1fab7f9868371d9918daf1988d1f") - .unwrap(); + b256!("0x6a251c7c3c5dca7b42407a3752ff48f3bbca1fab7f9868371d9918daf1988d1f"); let header = Header { parent_hash: b256!("0xe0a94a7a3c9617401586b1a27025d2d9671332d22d540e0af72b069170380f2a"), ommers_hash: EMPTY_OMMER_ROOT_HASH, @@ -181,8 +180,7 @@ mod tests { // make sure the hash matches let expected_hash = - B256::from_str("8c2f2af15b7b563b6ab1e09bed0e9caade7ed730aec98b70a993597a797579a9") - .unwrap(); + b256!("0x8c2f2af15b7b563b6ab1e09bed0e9caade7ed730aec98b70a993597a797579a9"); assert_eq!(header.hash_slow(), expected_hash); } @@ -197,7 +195,7 @@ mod tests { "18db39e19931515b30b16b3a92c292398039e31d6c267111529c3f2ba0a26c17", ) .unwrap(), - beneficiary: Address::from_str("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba").unwrap(), + beneficiary: address!("0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"), state_root: B256::from_str( "95efce3d6972874ca8b531b233b7a1d1ff0a56f08b20c8f1b89bef1b001194a5", ) @@ -217,18 +215,16 @@ mod tests { extra_data: Bytes::from_str("42").unwrap(), mix_hash: EMPTY_ROOT_HASH, base_fee_per_gas: Some(0x09), - withdrawals_root: Some( - B256::from_str("27f166f1d7c789251299535cb176ba34116e44894476a7886fe5d73d9be5c973") - .unwrap(), - ), + withdrawals_root: Some(b256!( + "0x27f166f1d7c789251299535cb176ba34116e44894476a7886fe5d73d9be5c973" + )), ..Default::default() }; let header =
::decode(&mut data.as_slice()).unwrap(); assert_eq!(header, expected); let expected_hash = - B256::from_str("85fdec94c534fa0a1534720f167b899d1fc268925c71c0cbf5aaa213483f5a69") - .unwrap(); + b256!("0x85fdec94c534fa0a1534720f167b899d1fc268925c71c0cbf5aaa213483f5a69"); assert_eq!(header.hash_slow(), expected_hash); } @@ -244,7 +240,7 @@ mod tests { ) .unwrap(), ommers_hash: EMPTY_OMMER_ROOT_HASH, - beneficiary: Address::from_str("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba").unwrap(), + beneficiary: address!("0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"), state_root: B256::from_str( "3c837fc158e3e93eafcaf2e658a02f5d8f99abc9f1c4c66cdea96c0ca26406ae", ) diff --git a/crates/net/eth-wire-types/src/status.rs b/crates/net/eth-wire-types/src/status.rs index 8f90058639c..db363695c32 100644 --- a/crates/net/eth-wire-types/src/status.rs +++ b/crates/net/eth-wire-types/src/status.rs @@ -461,7 +461,7 @@ mod tests { use alloy_consensus::constants::MAINNET_GENESIS_HASH; use alloy_genesis::Genesis; use alloy_hardforks::{EthereumHardfork, ForkHash, ForkId, Head}; - use alloy_primitives::{hex, B256, U256}; + use alloy_primitives::{b256, hex, B256, U256}; use alloy_rlp::{Decodable, Encodable}; use rand::Rng; use reth_chainspec::{Chain, ChainSpec, ForkCondition, NamedChain}; @@ -516,10 +516,7 @@ mod tests { .chain(Chain::mainnet()) .genesis(MAINNET_GENESIS_HASH) .forkid(ForkId { hash: ForkHash([0xb7, 0x15, 0x07, 0x7d]), next: 0 }) - .blockhash( - B256::from_str("feb27336ca7923f8fab3bd617fcb6e75841538f71c1bcfc267d7838489d9e13d") - .unwrap(), - ) + .blockhash(b256!("0xfeb27336ca7923f8fab3bd617fcb6e75841538f71c1bcfc267d7838489d9e13d")) .earliest_block(Some(1)) .latest_block(Some(2)) .total_difficulty(None) @@ -538,10 +535,7 @@ mod tests { .chain(Chain::sepolia()) .genesis(MAINNET_GENESIS_HASH) .forkid(ForkId { hash: ForkHash([0xaa, 0xbb, 0xcc, 0xdd]), next: 0 }) - .blockhash( - B256::from_str("feb27336ca7923f8fab3bd617fcb6e75841538f71c1bcfc267d7838489d9e13d") - .unwrap(), - ) + .blockhash(b256!("0xfeb27336ca7923f8fab3bd617fcb6e75841538f71c1bcfc267d7838489d9e13d")) .total_difficulty(Some(U256::from(42u64))) .earliest_block(None) .latest_block(None) @@ -578,10 +572,7 @@ mod tests { .chain(Chain::from_named(NamedChain::Mainnet)) .genesis(MAINNET_GENESIS_HASH) .forkid(ForkId { hash: ForkHash([0xb7, 0x15, 0x07, 0x7d]), next: 0 }) - .blockhash( - B256::from_str("feb27336ca7923f8fab3bd617fcb6e75841538f71c1bcfc267d7838489d9e13d") - .unwrap(), - ) + .blockhash(b256!("0xfeb27336ca7923f8fab3bd617fcb6e75841538f71c1bcfc267d7838489d9e13d")) .earliest_block(Some(15_537_394)) .latest_block(Some(18_000_000)) .build() @@ -617,10 +608,7 @@ mod tests { .forkid(ForkId { hash: ForkHash([0xb7, 0x15, 0x07, 0x7d]), next: 0 }) .earliest_block(Some(15_537_394)) .latest_block(Some(18_000_000)) - .blockhash( - B256::from_str("feb27336ca7923f8fab3bd617fcb6e75841538f71c1bcfc267d7838489d9e13d") - .unwrap(), - ) + .blockhash(b256!("0xfeb27336ca7923f8fab3bd617fcb6e75841538f71c1bcfc267d7838489d9e13d")) .build() .into_message(); diff --git a/crates/optimism/cli/src/receipt_file_codec.rs b/crates/optimism/cli/src/receipt_file_codec.rs index 8cd50037c57..e12af039eac 100644 --- a/crates/optimism/cli/src/receipt_file_codec.rs +++ b/crates/optimism/cli/src/receipt_file_codec.rs @@ -149,7 +149,7 @@ pub(crate) mod test { "00000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000400000000000100000000000000200000000002000000000000001000000000000000000004000000000000000000000000000040000400000100400000000000000100000000000000000000000000000020000000000000000000000000000000000000000000000001000000000000000000000100000000000000000000000000000000000000000000000000000000000000088000000080000000000010000000000000000000000000000800008000120000000000000000000000000000000002000" )), logs: receipt.receipt.into_logs(), - tx_hash: b256!("0x5e77a04531c7c107af1882d76cbff9486d0a9aa53701c30888509d4f5f2b003a"), contract_address: address!("0x0000000000000000000000000000000000000000"), gas_used: 202813, + tx_hash: b256!("0x5e77a04531c7c107af1882d76cbff9486d0a9aa53701c30888509d4f5f2b003a"), contract_address: Address::ZERO, gas_used: 202813, block_hash: b256!("0xbee7192e575af30420cae0c7776304ac196077ee72b048970549e4f08e875453"), block_number: receipt.number, transaction_index: 0, diff --git a/crates/primitives-traits/src/transaction/signature.rs b/crates/primitives-traits/src/transaction/signature.rs index 2e994f1e5f4..481096b7936 100644 --- a/crates/primitives-traits/src/transaction/signature.rs +++ b/crates/primitives-traits/src/transaction/signature.rs @@ -6,7 +6,7 @@ pub use alloy_primitives::Signature; #[cfg(test)] mod tests { use crate::crypto::secp256k1::recover_signer; - use alloy_primitives::{address, Signature, B256, U256}; + use alloy_primitives::{address, b256, Signature, U256}; use std::str::FromStr; #[test] @@ -22,9 +22,7 @@ mod tests { .unwrap(), false, ); - let hash = - B256::from_str("daf5a779ae972f972197303d7b574746c7ef83eadac0f2791ad23db92e4c8e53") - .unwrap(); + let hash = b256!("0xdaf5a779ae972f972197303d7b574746c7ef83eadac0f2791ad23db92e4c8e53"); let signer = recover_signer(&signature, hash).unwrap(); let expected = address!("0x9d8a62f656a8d1615c1294fd71e9cfb3e4855a4f"); assert_eq!(expected, signer); diff --git a/crates/storage/db-api/src/models/accounts.rs b/crates/storage/db-api/src/models/accounts.rs index ad6e37e0ecb..e363aff2f70 100644 --- a/crates/storage/db-api/src/models/accounts.rs +++ b/crates/storage/db-api/src/models/accounts.rs @@ -107,13 +107,13 @@ impl_fixed_arbitrary!((BlockNumberAddress, 28), (AddressStorageKey, 52)); #[cfg(test)] mod tests { use super::*; + use alloy_primitives::address; use rand::{rng, Rng}; - use std::str::FromStr; #[test] fn test_block_number_address() { let num = 1u64; - let hash = Address::from_str("ba5e000000000000000000000000000000000000").unwrap(); + let hash = address!("0xba5e000000000000000000000000000000000000"); let key = BlockNumberAddress((num, hash)); let mut bytes = [0u8; 28]; @@ -138,7 +138,7 @@ mod tests { #[test] fn test_address_storage_key() { let storage_key = StorageKey::random(); - let address = Address::from_str("ba5e000000000000000000000000000000000000").unwrap(); + let address = address!("0xba5e000000000000000000000000000000000000"); let key = AddressStorageKey((address, storage_key)); let mut bytes = [0u8; 52]; diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index 2087bd0219d..6b69336e00f 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -3774,7 +3774,7 @@ mod tests { let mut f = MockTransactionFactory::default(); let mut pool = TxPool::new(MockOrdering::default(), Default::default()); - let sender = address!("1234567890123456789012345678901234567890"); + let sender = address!("0x1234567890123456789012345678901234567890"); let tx0 = f.validated_arc( MockTransaction::legacy().with_sender(sender).with_nonce(0).with_gas_price(10), ); diff --git a/crates/trie/db/tests/trie.rs b/crates/trie/db/tests/trie.rs index 4b56911b518..6f2588f39e9 100644 --- a/crates/trie/db/tests/trie.rs +++ b/crates/trie/db/tests/trie.rs @@ -1,7 +1,9 @@ #![allow(missing_docs)] use alloy_consensus::EMPTY_ROOT_HASH; -use alloy_primitives::{hex_literal::hex, keccak256, map::HashMap, Address, B256, U256}; +use alloy_primitives::{ + address, b256, hex_literal::hex, keccak256, map::HashMap, Address, B256, U256, +}; use alloy_rlp::Encodable; use proptest::{prelude::ProptestConfig, proptest}; use proptest_arbitrary_interop::arb; @@ -295,7 +297,7 @@ fn storage_root_regression() { let factory = create_test_provider_factory(); let tx = factory.provider_rw().unwrap(); // Some address whose hash starts with 0xB041 - let address3 = Address::from_str("16b07afd1c635f77172e842a000ead9a2a222459").unwrap(); + let address3 = address!("0x16b07afd1c635f77172e842a000ead9a2a222459"); let key3 = keccak256(address3); assert_eq!(key3[0], 0xB0); assert_eq!(key3[1], 0x41); @@ -346,14 +348,13 @@ fn account_and_storage_trie() { let mut hash_builder = HashBuilder::default(); // Insert first account - let key1 = - B256::from_str("b000000000000000000000000000000000000000000000000000000000000000").unwrap(); + let key1 = b256!("0xb000000000000000000000000000000000000000000000000000000000000000"); let account1 = Account { nonce: 0, balance: U256::from(3).mul(ether), bytecode_hash: None }; hashed_account_cursor.upsert(key1, &account1).unwrap(); hash_builder.add_leaf(Nibbles::unpack(key1), &encode_account(account1, None)); // Some address whose hash starts with 0xB040 - let address2 = Address::from_str("7db3e81b72d2695e19764583f6d219dbee0f35ca").unwrap(); + let address2 = address!("0x7db3e81b72d2695e19764583f6d219dbee0f35ca"); let key2 = keccak256(address2); assert_eq!(key2[0], 0xB0); assert_eq!(key2[1], 0x40); @@ -362,12 +363,11 @@ fn account_and_storage_trie() { hash_builder.add_leaf(Nibbles::unpack(key2), &encode_account(account2, None)); // Some address whose hash starts with 0xB041 - let address3 = Address::from_str("16b07afd1c635f77172e842a000ead9a2a222459").unwrap(); + let address3 = address!("0x16b07afd1c635f77172e842a000ead9a2a222459"); let key3 = keccak256(address3); assert_eq!(key3[0], 0xB0); assert_eq!(key3[1], 0x41); - let code_hash = - B256::from_str("5be74cad16203c4905c068b012a2e9fb6d19d036c410f16fd177f337541440dd").unwrap(); + let code_hash = b256!("0x5be74cad16203c4905c068b012a2e9fb6d19d036c410f16fd177f337541440dd"); let account3 = Account { nonce: 0, balance: U256::from(2).mul(ether), bytecode_hash: Some(code_hash) }; hashed_account_cursor.upsert(key3, &account3).unwrap(); @@ -386,27 +386,23 @@ fn account_and_storage_trie() { hash_builder .add_leaf(Nibbles::unpack(key3), &encode_account(account3, Some(account3_storage_root))); - let key4a = - B256::from_str("B1A0000000000000000000000000000000000000000000000000000000000000").unwrap(); + let key4a = b256!("0xB1A0000000000000000000000000000000000000000000000000000000000000"); let account4a = Account { nonce: 0, balance: U256::from(4).mul(ether), ..Default::default() }; hashed_account_cursor.upsert(key4a, &account4a).unwrap(); hash_builder.add_leaf(Nibbles::unpack(key4a), &encode_account(account4a, None)); - let key5 = - B256::from_str("B310000000000000000000000000000000000000000000000000000000000000").unwrap(); + let key5 = b256!("0xB310000000000000000000000000000000000000000000000000000000000000"); let account5 = Account { nonce: 0, balance: U256::from(8).mul(ether), ..Default::default() }; hashed_account_cursor.upsert(key5, &account5).unwrap(); hash_builder.add_leaf(Nibbles::unpack(key5), &encode_account(account5, None)); - let key6 = - B256::from_str("B340000000000000000000000000000000000000000000000000000000000000").unwrap(); + let key6 = b256!("0xB340000000000000000000000000000000000000000000000000000000000000"); let account6 = Account { nonce: 0, balance: U256::from(1).mul(ether), ..Default::default() }; hashed_account_cursor.upsert(key6, &account6).unwrap(); hash_builder.add_leaf(Nibbles::unpack(key6), &encode_account(account6, None)); // Populate account & storage trie DB tables - let expected_root = - B256::from_str("72861041bc90cd2f93777956f058a545412b56de79af5eb6b8075fe2eabbe015").unwrap(); + let expected_root = b256!("0x72861041bc90cd2f93777956f058a545412b56de79af5eb6b8075fe2eabbe015"); let computed_expected_root: B256 = triehash::trie_root::([ (key1, encode_account(account1, None)), (key2, encode_account(account2, None)), @@ -448,7 +444,7 @@ fn account_and_storage_trie() { // Add an account // Some address whose hash starts with 0xB1 - let address4b = Address::from_str("4f61f2d5ebd991b85aa1677db97307caf5215c91").unwrap(); + let address4b = address!("0x4f61f2d5ebd991b85aa1677db97307caf5215c91"); let key4b = keccak256(address4b); assert_eq!(key4b.0[0], key4a.0[0]); let account4b = Account { nonce: 0, balance: U256::from(5).mul(ether), bytecode_hash: None }; @@ -458,7 +454,7 @@ fn account_and_storage_trie() { prefix_set.insert(Nibbles::unpack(key4b)); let expected_state_root = - B256::from_str("8e263cd4eefb0c3cbbb14e5541a66a755cad25bcfab1e10dd9d706263e811b28").unwrap(); + b256!("0x8e263cd4eefb0c3cbbb14e5541a66a755cad25bcfab1e10dd9d706263e811b28"); let (root, trie_updates) = StateRoot::from_tx(tx.tx_ref()) .with_prefix_sets(TriePrefixSets { diff --git a/crates/trie/sparse-parallel/src/trie.rs b/crates/trie/sparse-parallel/src/trie.rs index e0518ad4d2c..56f515d1649 100644 --- a/crates/trie/sparse-parallel/src/trie.rs +++ b/crates/trie/sparse-parallel/src/trie.rs @@ -6272,7 +6272,7 @@ mod tests { // Assert the root hash matches the expected value let expected_root = - b256!("29b07de8376e9ce7b3a69e9b102199869514d3f42590b5abc6f7d48ec9b8665c"); + b256!("0x29b07de8376e9ce7b3a69e9b102199869514d3f42590b5abc6f7d48ec9b8665c"); assert_eq!(trie.root(), expected_root); }