diff --git a/client/src/client.rs b/client/src/client.rs index f0d2d11181e..44a35d686dc 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -138,10 +138,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) @@ -1665,14 +1662,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()); } diff --git a/client/tests/integration/permissions.rs b/client/tests/integration/permissions.rs index 8870d6694e1..28b963730b2 100644 --- a/client/tests/integration/permissions.rs +++ b/client/tests/integration/permissions.rs @@ -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()); } diff --git a/client/tests/integration/triggers/by_call_trigger.rs b/client/tests/integration/triggers/by_call_trigger.rs index 90c62dc2e22..4770de13945 100644 --- a/client/tests/integration/triggers/by_call_trigger.rs +++ b/client/tests/integration/triggers/by_call_trigger.rs @@ -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()); } diff --git a/core/src/queue.rs b/core/src/queue.rs index bb5f38cea3f..b9b36f793e7 100644 --- a/core/src/queue.rs +++ b/core/src/queue.rs @@ -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 { diff --git a/core/src/wsv.rs b/core/src/wsv.rs index cc617a671a9..eaac7559502 100644 --- a/core/src/wsv.rs +++ b/core/src/wsv.rs @@ -1393,9 +1393,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(); diff --git a/data_model/src/block.rs b/data_model/src/block.rs index 8fb6a040b54..0eb2cb5079c 100644 --- a/data_model/src/block.rs +++ b/data_model/src/block.rs @@ -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; diff --git a/data_model/src/lib.rs b/data_model/src/lib.rs index a4ca860bc49..8bb1f0d1a98 100644 --- a/data_model/src/lib.rs +++ b/data_model/src/lib.rs @@ -1774,11 +1774,10 @@ pub fn current_time() -> core::time::Duration { declare_versioned_with_scale!(BatchedResponse 1..2, Debug, Clone, iroha_macro::FromVariant, IntoSchema); -impl From> for (T, crate::query::cursor::ForwardCursor) { - fn from(source: BatchedResponseV1) -> Self { - let BatchedResponseV1 { batch, cursor } = source; - - (batch, cursor) +impl From> for (T, crate::query::cursor::ForwardCursor) { + fn from(source: BatchedResponse) -> Self { + let BatchedResponse::V1(batch) = source; + (batch.batch, batch.cursor) } } diff --git a/data_model/src/transaction.rs b/data_model/src/transaction.rs index d081dba6b8f..a7742873c7a 100644 --- a/data_model/src/transaction.rs +++ b/data_model/src/transaction.rs @@ -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 { let SignedTransaction::V1(tx) = self; diff --git a/smart_contract/src/lib.rs b/smart_contract/src/lib.rs index 932692066ad..7893364a6ea 100644 --- a/smart_contract/src/lib.rs +++ b/smart_contract/src/lib.rs @@ -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, @@ -286,10 +284,7 @@ impl> QueryOutputCursorIterator { 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::::try_from(value)?; Ok(Self { iter: vec.into_iter(),