Skip to content

Commit

Permalink
feat(primitives) : test for TxDeposit and related methods (#5317)
Browse files Browse the repository at this point in the history
  • Loading branch information
DoTheBestToGetTheBest authored Nov 5, 2023
1 parent 45628e7 commit 1aca4b0
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions crates/primitives/src/transaction/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,80 @@ mod tests {
tx_b.encode_enveloped(&mut buf_b);
assert_eq!(&buf_b[..], &bytes[..]);
}
#[test]
fn test_tx_deposit_size() {
let tx_deposit = TxDeposit {
source_hash: B256::default(),
from: Address::default(),
to: TransactionKind::default(),
mint: Some(100),
value: TxValue::default(),
gas_limit: 50000,
is_system_transaction: false,
input: Bytes::default(),
};

assert_eq!(tx_deposit.size(), mem::size_of_val(&tx_deposit));
}

#[test]
fn test_encode_decode_inner() {
let original = TxDeposit {
source_hash: B256::default(),
from: Address::default(),
to: TransactionKind::default(),
mint: Some(100),
value: TxValue::default(),
gas_limit: 50000,
is_system_transaction: true,
input: Bytes::default(),
};

let mut buffer = BytesMut::new();
original.encode(&mut buffer, false);
let decoded = TxDeposit::decode_inner(&mut &buffer[..]).expect("Failed to decode");

assert_eq!(original, decoded);
}

#[test]
fn test_encode_with_and_without_header() {
let tx_deposit = TxDeposit {
source_hash: B256::default(),
from: Address::default(),
to: TransactionKind::default(),
mint: Some(100),
value: TxValue::default(),
gas_limit: 50000,
is_system_transaction: true,
input: Bytes::default(),
};

let mut buffer_with_header = BytesMut::new();
tx_deposit.encode(&mut buffer_with_header, true);

let mut buffer_without_header = BytesMut::new();
tx_deposit.encode(&mut buffer_without_header, false);

assert!(buffer_with_header.len() > buffer_without_header.len());
}

#[test]
fn test_payload_length() {
let tx_deposit = TxDeposit {
source_hash: B256::default(),
from: Address::default(),
to: TransactionKind::default(),
mint: Some(100),
value: TxValue::default(),
gas_limit: 50000,
is_system_transaction: true,
input: Bytes::default(),
};

let total_len = tx_deposit.payload_len();
let len_without_header = tx_deposit.payload_len_without_header();

assert!(total_len > len_without_header);
}
}

0 comments on commit 1aca4b0

Please sign in to comment.