From c89d03ec59968bc9981372f83bb4536006ffbb06 Mon Sep 17 00:00:00 2001 From: therainisme Date: Sun, 12 May 2024 19:47:05 +0800 Subject: [PATCH] feat: duplicate funtions of in crates/contract/src/call.rs (#534) (#726) --- crates/contract/src/call.rs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/crates/contract/src/call.rs b/crates/contract/src/call.rs index 1f01c1660c6..2105985a7da 100644 --- a/crates/contract/src/call.rs +++ b/crates/contract/src/call.rs @@ -2,7 +2,7 @@ use crate::{CallDecoder, Error, EthCall, Result}; use alloy_dyn_abi::{DynSolValue, JsonAbiExt}; use alloy_json_abi::Function; use alloy_network::{Ethereum, Network, ReceiptResponse, TransactionBuilder}; -use alloy_primitives::{Address, Bytes, TxKind, U256}; +use alloy_primitives::{Address, Bytes, ChainId, TxKind, U256}; use alloy_provider::{PendingTransactionBuilder, Provider}; use alloy_rpc_types::{state::StateOverride, AccessList, BlobTransactionSidecar, BlockId}; use alloy_sol_types::SolCall; @@ -357,6 +357,12 @@ impl, D: CallDecoder, N: Network> CallBu } } + /// Sets the `chain_id` field in the transaction to the provided value + pub fn chain_id(mut self, chain_id: ChainId) -> Self { + self.request.set_chain_id(chain_id); + self + } + /// Sets the `from` field in the transaction to the provided value. pub fn from(mut self, from: Address) -> Self { self.request.set_from(from); @@ -426,6 +432,12 @@ impl, D: CallDecoder, N: Network> CallBu self } + /// Sets the `max_fee_per_blob_gas` in the transaction to the provided value + pub fn max_fee_per_blob_gas(mut self, max_fee_per_blob_gas: u128) -> Self { + self.request.set_max_fee_per_blob_gas(max_fee_per_blob_gas); + self + } + /// Sets the `access_list` in the transaction to the provided value pub fn access_list(mut self, access_list: AccessList) -> Self { self.request.set_access_list(access_list); @@ -683,6 +695,16 @@ mod tests { call_builder } + #[test] + fn change_chain_id() { + let call_builder = build_call_builder().chain_id(1337); + assert_eq!( + call_builder.request.chain_id.expect("chain_id should be set"), + 1337, + "chain_id of request should be '1337'" + ); + } + #[test] fn change_max_fee_per_gas() { let call_builder = build_call_builder().max_fee_per_gas(42); @@ -706,6 +728,16 @@ mod tests { ); } + #[test] + fn change_max_fee_per_blob_gas() { + let call_builder = build_call_builder().max_fee_per_blob_gas(50); + assert_eq!( + call_builder.request.max_fee_per_blob_gas.expect("max_fee_per_blob_gas should be set"), + 50, + "max_fee_per_blob_gas of request should be '50'" + ); + } + #[test] fn change_access_list() { let access_list = AccessList::from(vec![AccessListItem {