diff --git a/crates/interfaces/src/test_utils/generators.rs b/crates/interfaces/src/test_utils/generators.rs index ebb2a18e7a..53733e21d7 100644 --- a/crates/interfaces/src/test_utils/generators.rs +++ b/crates/interfaces/src/test_utils/generators.rs @@ -72,6 +72,11 @@ pub fn random_signed_tx() -> TransactionSigned { let secp = Secp256k1::new(); let key_pair = KeyPair::new(&secp, &mut rand::thread_rng()); let tx = random_tx(); + sign_tx_with_key_pair(key_pair, tx) +} + +/// Signs the [Transaction] with the given key pair. +pub fn sign_tx_with_key_pair(key_pair: KeyPair, tx: Transaction) -> TransactionSigned { let signature = sign_message(H256::from_slice(&key_pair.secret_bytes()[..]), tx.signature_hash()).unwrap(); TransactionSigned::from_transaction_and_signature(tx, signature) diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index 6e60722cba..4a682f8c71 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -224,6 +224,33 @@ impl Transaction { } } } + + /// This sets the transaction's nonce. + pub fn set_nonce(&mut self, nonce: u64) { + match self { + Transaction::Legacy(tx) => tx.nonce = nonce, + Transaction::Eip2930(tx) => tx.nonce = nonce, + Transaction::Eip1559(tx) => tx.nonce = nonce, + } + } + + /// This sets the transaction's value. + pub fn set_value(&mut self, value: u128) { + match self { + Transaction::Legacy(tx) => tx.value = value, + Transaction::Eip2930(tx) => tx.value = value, + Transaction::Eip1559(tx) => tx.value = value, + } + } + + /// This sets the transaction's input field. + pub fn set_input(&mut self, input: Bytes) { + match self { + Transaction::Legacy(tx) => tx.input = input, + Transaction::Eip2930(tx) => tx.input = input, + Transaction::Eip1559(tx) => tx.input = input, + } + } } impl Compact for Transaction {