Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add important setters functions of TransactionBuilder in CallBuilder #726

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -289,6 +289,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 @@ -344,6 +350,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 @@ -596,6 +608,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 @@ -619,6 +641,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
Loading