Skip to content

Commit

Permalink
fix: fix conversion of transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
guy-starkware committed Sep 19, 2024
1 parent 2b187fb commit dfa7bfc
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion crates/papyrus_protobuf/src/converters/consensus_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,32 @@ fn convert_proposal_init_to_vec_u8_and_back() {
fn convert_transaction_batch_to_vec_u8_and_back() {
let mut rng = get_rng();

let transaction_batch = TransactionBatch::get_test_instance(&mut rng);
let mut transaction_batch = TransactionBatch::get_test_instance(&mut rng);

// Below is a hack: The problem is that when we deserialize a Transaction, if it has an
// AllResources variant, it will turn into a L1Gas variant if all the gas prices are zero.
// So I will intentionally make them non-zero, but the real solution is to make the randomly
// generated structs contain random values instead of zero.
// TODO(guyn): add random values to the structs generated by get_test_instance
let transaction = &mut transaction_batch.transactions[0];
match transaction {
Transaction::Declare(DeclareTransaction::V3(DeclareTransactionV3 {
resource_bounds,
..
}))
| Transaction::Invoke(InvokeTransaction::V3(InvokeTransactionV3 {
resource_bounds, ..
}))
| Transaction::DeployAccount(DeployAccountTransaction::V3(DeployAccountTransactionV3 {
resource_bounds,
..
})) => {
if let ValidResourceBounds::AllResources(ref mut bounds) = resource_bounds {
bounds.l2_gas.max_amount = 1;
}
}
_ => {}
}
let bytes_data: Vec<u8> = transaction_batch.clone().into();
let res_data = TransactionBatch::try_from(bytes_data).unwrap();
assert_eq!(transaction_batch, res_data);
Expand Down

0 comments on commit dfa7bfc

Please sign in to comment.