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 input field to CallRequest #1069

Merged
merged 5 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
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
33 changes: 32 additions & 1 deletion core/lib/types/src/transaction_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pub struct CallRequest {
/// Data (None for empty data)
#[serde(default, skip_serializing_if = "Option::is_none")]
pub data: Option<Bytes>,
/// Input (None for empty)
#[serde(default, skip_serializing_if = "Option::is_none")]
pub input: Option<Bytes>,
/// Nonce
#[serde(default, skip_serializing_if = "Option::is_none")]
pub nonce: Option<U256>,
Expand Down Expand Up @@ -123,6 +126,11 @@ impl CallRequestBuilder {
self
}

pub fn input(mut self, input: Bytes) -> Self {
self.call_request.input = Some(input);
self
}

/// Set transaction type, Some(1) for AccessList transaction, None for Legacy
pub fn transaction_type(mut self, transaction_type: U64) -> Self {
self.call_request.transaction_type = Some(transaction_type);
Expand Down Expand Up @@ -869,7 +877,7 @@ impl From<CallRequest> for TransactionRequest {
value: call_request.value.unwrap_or_default(),
gas_price: call_request.gas_price.unwrap_or_default(),
gas: call_request.gas.unwrap_or_default(),
input: call_request.data.unwrap_or_default(),
input: call_request.input.or(call_request.data).unwrap_or_default(),
transaction_type: call_request.transaction_type,
access_list: call_request.access_list,
eip712_meta: call_request.eip712_meta,
Expand Down Expand Up @@ -1457,6 +1465,7 @@ mod tests {
max_priority_fee_per_gas: Some(U256::from(12u32)),
value: Some(U256::from(12u32)),
data: Some(Bytes(factory_dep)),
input: None,
nonce: None,
transaction_type: Some(U64::from(EIP_712_TX_TYPE)),
access_list: None,
Expand All @@ -1483,6 +1492,7 @@ mod tests {
max_priority_fee_per_gas: Some(U256::from(12u32)),
value: Some(U256::from(12u32)),
data: Some(Bytes(vec![1, 2, 3])),
input: None,
nonce: Some(U256::from(123u32)),
transaction_type: Some(U64::from(EIP_712_TX_TYPE)),
access_list: None,
Expand All @@ -1499,4 +1509,25 @@ mod tests {
L2Tx::from_request(call_request_without_nonce.into(), MAX_ENCODED_TX_SIZE).unwrap();
assert_eq!(l2_tx.nonce(), Nonce(0u32));
}

#[test]
fn test_correct_data_field() {
let mut call_request = CallRequest {
input: Some(Bytes(vec![1, 2, 3])),
data: Some(Bytes(vec![3, 2, 1])),
..Default::default()
};

let tx_request = TransactionRequest::from(call_request.clone());
assert_eq!(tx_request.input, call_request.input.unwrap());

call_request.input = None;
let tx_request = TransactionRequest::from(call_request.clone());
assert_eq!(tx_request.input, call_request.data.unwrap());

call_request.input = Some(Bytes(vec![1, 2, 3]));
call_request.data = None;
let tx_request = TransactionRequest::from(call_request.clone());
assert_eq!(tx_request.input, call_request.input.unwrap());
}
}
9 changes: 8 additions & 1 deletion core/lib/zksync_core/src/api_server/web3/tests/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,14 @@ impl TraceCallTest {
assert_eq!(call_result.from, Address::zero());
assert_eq!(call_result.gas, call_request.gas.unwrap());
assert_eq!(call_result.value, call_request.value.unwrap());
assert_eq!(call_result.input, *call_request.data.as_ref().unwrap());
assert_eq!(
call_result.input,
call_request
.clone()
.input
.or(call_request.clone().data)
.unwrap()
);
assert_eq!(call_result.output.0, b"output");
}
}
Expand Down
Loading