Skip to content

Commit

Permalink
[fix] #3826: Fix benchmarks build
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Oct 31, 2023
1 parent a04448e commit dee548b
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 30 deletions.
10 changes: 3 additions & 7 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ where
}
}

let response =
_handle_query_response_base(resp).map(|BatchedResponse::V1(response)| response)?;

let (batch, cursor) = response.into();
let (batch, cursor) = _handle_query_response_base(resp)?.into();

let value = R::try_from(batch)
.map_err(Into::into)
Expand Down Expand Up @@ -1772,14 +1769,13 @@ mod tests {
let mut tx2 = build_transaction();
assert_ne!(tx1.payload().hash(), tx2.payload().hash());

let SignedTransaction::V1(tx2_ref) = &mut tx2;
tx2_ref.payload.creation_time_ms = tx1
tx2.payload_mut().creation_time_ms = tx1
.payload()
.creation_time()
.as_millis()
.try_into()
.expect("Valid");
tx2_ref.payload.nonce = tx1.payload().nonce;
tx2.payload_mut().nonce = tx1.payload().nonce;
assert_eq!(tx1.payload().hash(), tx2.payload().hash());
}

Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ fn genesis_transactions_are_validated() {
AccountId::from_str("alice@wonderland").unwrap(),
);

let SignedTransaction::V1(tx_ref) = &mut genesis.transactions.last_mut().unwrap().0;
match &mut tx_ref.payload.instructions {
let tx_ref = &mut genesis.transactions.last_mut().unwrap().0;
match &mut tx_ref.payload_mut().instructions {
Executable::Instructions(instructions) => {
instructions.push(grant_invalid_token.into());
}
Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/triggers/by_call_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ fn trigger_in_genesis_using_base64() -> Result<()> {

// Registering trigger in genesis
let mut genesis = GenesisNetwork::test(true).expect("Expected genesis");
let SignedTransaction::V1(tx_ref) = &mut genesis.transactions[0].0;
match &mut tx_ref.payload.instructions {
let tx_ref = &mut genesis.transactions[0].0;
match &mut tx_ref.payload_mut().instructions {
Executable::Instructions(instructions) => {
instructions.push(RegisterExpr::new(trigger).into());
}
Expand Down
3 changes: 1 addition & 2 deletions core/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,7 @@ mod tests {
let mut tx = accepted_tx("alice@wonderland", alice_key);
assert!(queue.push(tx.clone(), &wsv).is_ok());
// tamper timestamp
let SignedTransaction::V1(tx_ref) = &mut tx.0;
tx_ref.payload.creation_time_ms += 2 * future_threshold_ms;
tx.0.payload_mut().creation_time_ms += 2 * future_threshold_ms;
assert!(matches!(
queue.push(tx, &wsv),
Err(Failure {
Expand Down
5 changes: 2 additions & 3 deletions core/src/wsv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,9 +1364,8 @@ mod tests {
for i in 1..=BLOCK_CNT {
let mut block = block.clone();

let SignedBlock::V1(v1_block) = &mut block.0;
v1_block.payload.header.height = i as u64;
v1_block.payload.header.previous_block_hash = block_hashes.last().copied();
block.0.payload_mut().header.height = i as u64;
block.0.payload_mut().header.previous_block_hash = block_hashes.last().copied();

block_hashes.push(block.hash());
wsv.apply(&block).unwrap();
Expand Down
1 change: 0 additions & 1 deletion data_model/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ impl SignedBlock {
}

/// Used to inject faulty payload for testing
#[cfg(debug_assertions)]
#[cfg(feature = "transparent_api")]
pub fn payload_mut(&mut self) -> &mut BlockPayload {
let SignedBlock::V1(block) = self;
Expand Down
9 changes: 4 additions & 5 deletions data_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1774,11 +1774,10 @@ pub fn current_time() -> core::time::Duration {

declare_versioned_with_scale!(BatchedResponse<T> 1..2, Debug, Clone, iroha_macro::FromVariant, IntoSchema);

impl<T> From<BatchedResponseV1<T>> for (T, crate::query::cursor::ForwardCursor) {
fn from(source: BatchedResponseV1<T>) -> Self {
let BatchedResponseV1 { batch, cursor } = source;

(batch, cursor)
impl<T> From<BatchedResponse<T>> for (T, crate::query::cursor::ForwardCursor) {
fn from(source: BatchedResponse<T>) -> Self {
let BatchedResponse::V1(batch) = source;
(batch.batch, batch.cursor)
}
}

Expand Down
15 changes: 15 additions & 0 deletions data_model/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,21 @@ impl SignedTransaction {
&tx.payload
}

/// Used to inject faulty payload for testing
#[cfg(feature = "transparent_api")]
pub fn payload_mut(&mut self) -> &mut TransactionPayload {
let SignedTransaction::V1(tx) = self;
&mut tx.payload
}

/// Used to inject faulty payload for testing
#[cfg(debug_assertions)]
#[cfg(not(feature = "transparent_api"))]
pub fn payload_mut(&mut self) -> &mut TransactionPayload {
let SignedTransaction::V1(tx) = self;
&mut tx.payload
}

/// Return transaction signatures
pub fn signatures(&self) -> &SignaturesOf<TransactionPayload> {
let SignedTransaction::V1(tx) = self;
Expand Down
11 changes: 3 additions & 8 deletions smart_contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,8 @@ where
host_execute_query,
))
};
let BatchedResponse::V1(response) = res? else {
panic!("Unsupported response version")
};
let (value, cursor) = response.into();

let (value, cursor) = res?.into();
let typed_value = Self::Output::try_from(value).expect("Query output has incorrect type");
Ok(QueryOutputCursor {
batch: typed_value,
Expand Down Expand Up @@ -286,10 +284,7 @@ impl<T: TryFrom<Value>> QueryOutputCursorIterator<T> {
host_execute_query,
))
};
let BatchedResponse::V1(response) = res? else {
panic!("Unsupported response version")
};
let (value, cursor) = response.into();
let (value, cursor) = res?.into();
let vec = Vec::<T>::try_from(value)?;
Ok(Self {
iter: vec.into_iter(),
Expand Down

0 comments on commit dee548b

Please sign in to comment.