Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
telezhnaya committed Sep 22, 2023
1 parent 6ce9094 commit 4dca195
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion chain/client/src/tests/query_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ fn test_execution_outcome_for_chunk() {
.await
.unwrap()
.unwrap()
.unwrap()
.into_outcome()
.unwrap()
.transaction_outcome
.block_hash;

Expand Down
2 changes: 2 additions & 0 deletions chain/client/src/view_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ impl ViewClientActor {
for block_hash in block_hashes {
headers.push(self.chain.get_block_header(&block_hash)?);
}
// We can't sort and check only the last block;
// previous blocks may be not in the canonical chain
match self.chain.check_blocks_final_and_canonical(&headers) {
Ok(_) => TxExecutionStatus::Final,
Err(_) => TxExecutionStatus::Executed,
Expand Down
3 changes: 2 additions & 1 deletion chain/jsonrpc-primitives/src/types/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ pub enum RpcTransactionError {
pub struct RpcTransactionResponse {
#[serde(flatten)]
pub final_execution_outcome: near_primitives::views::FinalExecutionOutcomeViewEnum,
pub status: near_primitives::views::TxExecutionStatus,
// todo we have status in FinalExecutionOutcomeViewEnum :( we need to think about this naming
pub overall_status: near_primitives::views::TxExecutionStatus,
}

#[derive(serde::Serialize, serde::Deserialize, Debug)]
Expand Down
10 changes: 5 additions & 5 deletions chain/jsonrpc/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use near_jsonrpc_primitives::message::{from_slice, Message};
use near_jsonrpc_primitives::types::changes::{
RpcStateChangesInBlockByTypeRequest, RpcStateChangesInBlockByTypeResponse,
};
use near_jsonrpc_primitives::types::transactions::RpcTransactionResponse;
use near_jsonrpc_primitives::types::validator::RpcValidatorsOrderedRequest;
use near_primitives::hash::CryptoHash;
use near_primitives::types::{AccountId, BlockId, BlockReference, MaybeBlockId, ShardId};
use near_primitives::views::validator_stake_view::ValidatorStakeView;
use near_primitives::views::{
BlockView, ChunkView, EpochValidatorInfo, FinalExecutionOutcomeView, GasPriceView,
StatusResponse,
BlockView, ChunkView, EpochValidatorInfo, GasPriceView, StatusResponse,
};
use std::time::Duration;

Expand Down Expand Up @@ -177,7 +177,7 @@ macro_rules! jsonrpc_client {

jsonrpc_client!(pub struct JsonRpcClient {
pub fn broadcast_tx_async(&self, tx: String) -> RpcRequest<String>;
pub fn broadcast_tx_commit(&self, tx: String) -> RpcRequest<FinalExecutionOutcomeView>;
pub fn broadcast_tx_commit(&self, tx: String) -> RpcRequest<RpcTransactionResponse>;
pub fn status(&self) -> RpcRequest<StatusResponse>;
#[allow(non_snake_case)]
pub fn EXPERIMENTAL_check_tx(&self, tx: String) -> RpcRequest<serde_json::Value>;
Expand All @@ -186,9 +186,9 @@ jsonrpc_client!(pub struct JsonRpcClient {
#[allow(non_snake_case)]
pub fn EXPERIMENTAL_broadcast_tx_sync(&self, tx: String) -> RpcRequest<serde_json::Value>;
#[allow(non_snake_case)]
pub fn EXPERIMENTAL_tx_status(&self, tx: String) -> RpcRequest<serde_json::Value>;
pub fn EXPERIMENTAL_tx_status(&self, tx: String) -> RpcRequest<RpcTransactionResponse>;
pub fn health(&self) -> RpcRequest<()>;
pub fn tx(&self, hash: String, account_id: AccountId) -> RpcRequest<FinalExecutionOutcomeView>;
pub fn tx(&self, hash: String, account_id: AccountId) -> RpcRequest<RpcTransactionResponse>;
pub fn chunk(&self, id: ChunkId) -> RpcRequest<ChunkView>;
pub fn validators(&self, block_id: MaybeBlockId) -> RpcRequest<EpochValidatorInfo>;
pub fn gas_price(&self, block_id: MaybeBlockId) -> RpcRequest<GasPriceView>;
Expand Down
9 changes: 7 additions & 2 deletions chain/jsonrpc/jsonrpc-tests/tests/rpc_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ fn test_send_tx_async() {
.tx(tx_hash.to_string(), signer_account_id)
.map_err(|err| println!("Error: {:?}", err))
.map_ok(|result| {
if let FinalExecutionStatus::SuccessValue(_) = result.status {
if let FinalExecutionStatus::SuccessValue(_) =
result.final_execution_outcome.into_outcome().status
{
System::current().stop();
}
})
Expand Down Expand Up @@ -93,7 +95,10 @@ fn test_send_tx_commit() {
);
let bytes = tx.try_to_vec().unwrap();
let result = client.broadcast_tx_commit(to_base64(&bytes)).await.unwrap();
assert_eq!(result.status, FinalExecutionStatus::SuccessValue(Vec::new()));
assert_eq!(
result.final_execution_outcome.into_outcome().status,
FinalExecutionStatus::SuccessValue(Vec::new())
);
});
}

Expand Down
2 changes: 1 addition & 1 deletion chain/jsonrpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ impl JsonRpcHandler {
if let Some(outcome) = result.execution_outcome {
break Ok(RpcTransactionResponse {
final_execution_outcome: outcome,
status: result.status,
overall_status: result.status,
})
}
// else: No such transaction recorded on chain yet
Expand Down
13 changes: 12 additions & 1 deletion core/primitives/src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ pub struct TxStatusView {
pub status: TxExecutionStatus,
}

#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
#[derive(BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize, Clone, Debug)]
pub enum TxExecutionStatus {
/// Transaction is waiting to be included into the block
None,
Expand Down Expand Up @@ -1689,6 +1689,17 @@ impl FinalExecutionOutcomeViewEnum {
}
}

impl TxStatusView {
pub fn into_outcome(self) -> Option<FinalExecutionOutcomeView> {
self.execution_outcome.map(|outcome| match outcome {
FinalExecutionOutcomeViewEnum::FinalExecutionOutcome(outcome) => outcome,
FinalExecutionOutcomeViewEnum::FinalExecutionOutcomeWithReceipt(outcome) => {
outcome.final_outcome
}
})
}
}

/// Execution outcome of the transaction and all of subsequent the receipts.
/// Could be not finalised yet
#[derive(
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/tests/nearcore/rpc_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn test_get_execution_outcome(is_tx_successful: bool) {
spawn_interruptible(client.broadcast_tx_commit(to_base64(&bytes)).then(
move |res| {
let final_transaction_outcome = match res {
Ok(outcome) => outcome,
Ok(outcome) => outcome.final_execution_outcome.into_outcome(),
Err(_) => return future::ready(()),
};
spawn_interruptible(sleep(Duration::from_secs(1)).then(move |_| {
Expand Down
7 changes: 5 additions & 2 deletions integration-tests/src/user/rpc_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl User for RpcUser {
thread::sleep(Duration::from_millis(50));
}
match result {
Ok(outcome) => Ok(outcome),
Ok(outcome) => Ok(outcome.final_execution_outcome.into_outcome()),
Err(err) => Err(serde_json::from_value::<ServerError>(err.data.unwrap()).unwrap()),
}
}
Expand Down Expand Up @@ -186,7 +186,10 @@ impl User for RpcUser {
fn get_transaction_final_result(&self, hash: &CryptoHash) -> FinalExecutionOutcomeView {
let account_id = self.account_id.clone();
let hash = hash.to_string();
self.actix(move |client| client.tx(hash, account_id)).unwrap()
self.actix(move |client| client.tx(hash, account_id))
.unwrap()
.final_execution_outcome
.into_outcome()
}

fn get_state_root(&self) -> CryptoHash {
Expand Down

0 comments on commit 4dca195

Please sign in to comment.