Skip to content

Commit

Permalink
feat: duplicate funtions of in crates/contract/src/call.rs (alloy-rs#534
Browse files Browse the repository at this point in the history
  • Loading branch information
therainisme authored and ben186 committed Jul 27, 2024
1 parent 06df155 commit c89d03e
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion crates/contract/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -357,6 +357,12 @@ impl<T: Transport + Clone, P: Provider<T, N>, 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);
Expand Down Expand Up @@ -426,6 +432,12 @@ impl<T: Transport + Clone, P: Provider<T, N>, 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);
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down

0 comments on commit c89d03e

Please sign in to comment.