@@ -51,6 +51,8 @@ pub struct InstructionResult {
5151 pub program_result : ProgramResult ,
5252 /// The raw result of the program's execution.
5353 pub raw_result : Result < ( ) , InstructionError > ,
54+ /// The return data produced by the instruction, if any.
55+ pub return_data : Vec < u8 > ,
5456 /// The resulting accounts after executing the instruction.
5557 ///
5658 /// This includes all accounts provided to the processor, in the order
@@ -66,6 +68,7 @@ impl Default for InstructionResult {
6668 execution_time : 0 ,
6769 program_result : ProgramResult :: Success ,
6870 raw_result : Ok ( ( ) ) ,
71+ return_data : vec ! [ ] ,
6972 resulting_accounts : vec ! [ ] ,
7073 }
7174 }
@@ -111,6 +114,15 @@ impl InstructionResult {
111114 actual_result, check_result,
112115 ) ;
113116 }
117+ CheckType :: ReturnData ( return_data) => {
118+ let check_return_data = return_data;
119+ let actual_return_data = & self . return_data ;
120+ assert_eq ! (
121+ actual_return_data, check_return_data,
122+ "CHECK: return_data: got {:?}, expected {:?}" ,
123+ actual_return_data, check_return_data,
124+ ) ;
125+ }
114126 CheckType :: ResultingAccount ( account) => {
115127 let pubkey = account. pubkey ;
116128 let resulting_account = self
@@ -199,6 +211,7 @@ impl InstructionResult {
199211 b. resulting_accounts. len( ) ,
200212 "resulting accounts length mismatch"
201213 ) ;
214+ assert_eq ! ( self . return_data, b. return_data, "return data mismatch" ) ;
202215 for ( a, b) in self
203216 . resulting_accounts
204217 . iter ( )
@@ -217,6 +230,8 @@ enum CheckType<'a> {
217230 ExecutionTime ( u64 ) ,
218231 /// Check the result code of the program's execution.
219232 ProgramResult ( ProgramResult ) ,
233+ /// Check the return data produced by executing the instruction.
234+ ReturnData ( Vec < u8 > ) ,
220235 /// Check a resulting account after executing the instruction.
221236 ResultingAccount ( AccountCheck < ' a > ) ,
222237}
@@ -255,6 +270,11 @@ impl<'a> Check<'a> {
255270 Check :: new ( CheckType :: ProgramResult ( ProgramResult :: UnknownError ( error) ) )
256271 }
257272
273+ /// Check the return data produced by executing the instruction.
274+ pub fn return_data ( return_data : Vec < u8 > ) -> Self {
275+ Check :: new ( CheckType :: ReturnData ( return_data) )
276+ }
277+
258278 /// Check a resulting account after executing the instruction.
259279 pub fn account ( pubkey : & Pubkey ) -> AccountCheckBuilder {
260280 AccountCheckBuilder :: new ( pubkey)
0 commit comments