transaction-status: Add return data to meta (#23688)

* transaction-status: Add return data to meta

* Add return data to simulation results

* Use pretty-hex for printing return data

* Update arg name, make TransactionRecord struct

* Rename TransactionRecord -> ExecutionRecord
This commit is contained in:
Jon Cinque
2022-03-22 23:17:05 +01:00
committed by GitHub
parent 359e2de090
commit 7af48465fa
34 changed files with 439 additions and 45 deletions

View File

@ -8,6 +8,7 @@ repository = "https://github.com/solana-labs/solana"
version = "1.11.0"
[dependencies]
assert_matches = "1.5.0"
async-trait = "0.1.52"
base64 = "0.13.0"
bincode = "1.3.3"

View File

@ -1,14 +1,19 @@
use {
assert_matches::assert_matches,
solana_banks_client::BanksClientError,
solana_program_test::{processor, ProgramTest},
solana_sdk::{
account_info::{next_account_info, AccountInfo},
commitment_config::CommitmentLevel,
entrypoint::ProgramResult,
instruction::{AccountMeta, Instruction},
msg,
program::{get_return_data, invoke, set_return_data},
program_error::ProgramError,
pubkey::Pubkey,
signature::Signer,
transaction::Transaction,
transaction_context::TransactionReturnData,
},
std::str::from_utf8,
};
@ -85,3 +90,55 @@ async fn return_data() {
.await
.unwrap();
}
// Process instruction to echo input back to another program
#[allow(clippy::unnecessary_wraps)]
fn error_set_return_data_process_instruction(
_program_id: &Pubkey,
_accounts: &[AccountInfo],
input: &[u8],
) -> ProgramResult {
set_return_data(input);
Err(ProgramError::InvalidInstructionData)
}
#[tokio::test]
async fn simulation_return_data() {
let error_set_return_data_program_id = Pubkey::new_unique();
let program_test = ProgramTest::new(
"error_set_return_data",
error_set_return_data_program_id,
processor!(error_set_return_data_process_instruction),
);
let mut context = program_test.start_with_context().await;
let expected_data = vec![240, 159, 166, 150];
let instructions = vec![Instruction {
program_id: error_set_return_data_program_id,
accounts: vec![],
data: expected_data.clone(),
}];
let transaction = Transaction::new_signed_with_payer(
&instructions,
Some(&context.payer.pubkey()),
&[&context.payer],
context.last_blockhash,
);
let error = context
.banks_client
.process_transaction_with_preflight_and_commitment(transaction, CommitmentLevel::Confirmed)
.await
.unwrap_err();
assert_matches!(
error,
BanksClientError::SimulationError {
return_data: Some(TransactionReturnData {
program_id,
data,
}),
..
} if program_id == error_set_return_data_program_id && data == expected_data
);
}