1
1
use std:: rc:: Rc ;
2
2
3
- use crate :: testing_engine:: config:: { ExecuteOrderInstructionConfig , ExpectedError } ;
3
+ use crate :: testing_engine:: config:: { ExecuteOrderInstructionConfig , InstructionConfig } ;
4
4
use crate :: testing_engine:: setup:: { TestingContext , TransferDirection } ;
5
- use crate :: utils :: account_fixtures :: FixtureAccounts ;
5
+ use crate :: testing_engine :: state :: { OrderExecutedState , TestingEngineState } ;
6
6
use crate :: utils:: auction:: { AuctionAccounts , AuctionState } ;
7
7
use anchor_lang:: prelude:: * ;
8
8
use anchor_lang:: { InstructionData , ToAccountMetas } ;
@@ -22,18 +22,123 @@ use solana_sdk::sysvar::SysvarId;
22
22
use solana_sdk:: transaction:: Transaction ;
23
23
use wormhole_svm_definitions:: EVENT_AUTHORITY_SEED ;
24
24
25
- pub struct ExecuteOrderShimlessFixture {
26
- pub cctp_message : Pubkey ,
25
+ /// Execute order shimless
26
+ ///
27
+ /// Helper function to execute an order using the shimless method
28
+ ///
29
+ /// # Arguments
30
+ ///
31
+ /// * `testing_context`: The testing context of the testing engine
32
+ /// * `test_context`: A mutable reference to the test context
33
+ /// * `current_state`: The current state of the testing engine
34
+ /// * `config`: The execute order instruction config
35
+ /// * `auction_accounts`: The auction accounts
36
+ ///
37
+ /// # Returns
38
+ ///
39
+ /// The new state of the testing engine
40
+ pub async fn execute_order_shimless (
41
+ testing_context : & TestingContext ,
42
+ test_context : & mut ProgramTestContext ,
43
+ current_state : & TestingEngineState ,
44
+ config : & ExecuteOrderInstructionConfig ,
45
+ auction_accounts : & AuctionAccounts ,
46
+ ) -> TestingEngineState {
47
+ let payer_signer = config
48
+ . payer_signer
49
+ . clone ( )
50
+ . unwrap_or_else ( || testing_context. testing_actors . payer_signer . clone ( ) ) ;
51
+ let auction_state = current_state. auction_state ( ) ;
52
+ let slots_to_fast_forward = config. fast_forward_slots ;
53
+ if slots_to_fast_forward > 0 {
54
+ crate :: testing_engine:: engine:: fast_forward_slots ( test_context, slots_to_fast_forward)
55
+ . await ;
56
+ }
57
+ let execute_order_accounts: ExecuteOrderShimlessAccounts =
58
+ create_execute_order_shimless_accounts (
59
+ testing_context,
60
+ auction_accounts,
61
+ & payer_signer,
62
+ auction_state,
63
+ config,
64
+ ) ;
65
+ let execute_order_instruction_data = ExecuteOrderShimlessInstruction { } . data ( ) ;
66
+ let execute_order_ix = Instruction {
67
+ program_id : testing_context. get_matching_engine_program_id ( ) ,
68
+ accounts : execute_order_accounts. to_account_metas ( None ) ,
69
+ data : execute_order_instruction_data,
70
+ } ;
71
+ let tx = Transaction :: new_signed_with_payer (
72
+ & [ execute_order_ix] ,
73
+ Some ( & payer_signer. pubkey ( ) ) ,
74
+ & [ & payer_signer] ,
75
+ testing_context
76
+ . get_new_latest_blockhash ( test_context)
77
+ . await
78
+ . unwrap ( ) ,
79
+ ) ;
80
+ let expected_error = config. expected_error ( ) ;
81
+ testing_context
82
+ . execute_and_verify_transaction ( test_context, tx, expected_error)
83
+ . await ;
84
+ if config. expected_error . is_none ( ) {
85
+ let order_executed_state = OrderExecutedState {
86
+ cctp_message : execute_order_accounts. cctp_message ,
87
+ post_message_sequence : None ,
88
+ post_message_message : None ,
89
+ actor_enum : config. actor_enum ,
90
+ } ;
91
+ TestingEngineState :: OrderExecuted {
92
+ base : current_state. base ( ) . clone ( ) ,
93
+ initialized : current_state. initialized ( ) . unwrap ( ) . clone ( ) ,
94
+ router_endpoints : current_state. router_endpoints ( ) . unwrap ( ) . clone ( ) ,
95
+ fast_market_order : current_state. fast_market_order ( ) . cloned ( ) ,
96
+ auction_state : current_state. auction_state ( ) . clone ( ) ,
97
+ order_executed : order_executed_state,
98
+ auction_accounts : auction_accounts. clone ( ) ,
99
+ order_prepared : current_state. order_prepared ( ) . cloned ( ) ,
100
+ }
101
+ } else {
102
+ current_state. clone ( )
103
+ }
27
104
}
28
105
29
- pub fn create_execute_order_shimless_accounts (
106
+ /// Create execute order shimless accounts
107
+ ///
108
+ /// Helper function to create the accounts needed for the execute order instruction
109
+ ///
110
+ /// # Arguments
111
+ ///
112
+ /// * `testing_context`: The testing context
113
+ /// * `auction_accounts`: The auction accounts
114
+ /// * `payer_signer`: The payer signer
115
+ /// * `auction_state`: The auction state
116
+ /// * `config`: The execute order instruction config
117
+ ///
118
+ /// # Returns
119
+ ///
120
+ /// The execute order shimless accounts
121
+ fn create_execute_order_shimless_accounts (
30
122
testing_context : & TestingContext ,
31
- fixture_accounts : & FixtureAccounts ,
32
123
auction_accounts : & AuctionAccounts ,
33
124
payer_signer : & Rc < Keypair > ,
34
125
auction_state : & AuctionState ,
35
- executor_token : Pubkey ,
126
+ config : & ExecuteOrderInstructionConfig ,
36
127
) -> ExecuteOrderShimlessAccounts {
128
+ let fixture_accounts = testing_context
129
+ . get_fixture_accounts ( )
130
+ . expect ( "Fixture accounts not found" ) ;
131
+ let executor_token = config
132
+ . actor_enum
133
+ . get_actor ( & testing_context. testing_actors )
134
+ . token_account_address ( & config. token_enum )
135
+ . unwrap_or_else ( || {
136
+ auction_state
137
+ . get_active_auction ( )
138
+ . unwrap ( )
139
+ . best_offer
140
+ . offer_token
141
+ } ) ;
37
142
let active_auction_state = auction_state. get_active_auction ( ) . unwrap ( ) ;
38
143
let active_auction_address = active_auction_state. auction_address ;
39
144
let active_auction_custody_token = active_auction_state. auction_custody_token_address ;
@@ -152,70 +257,3 @@ pub fn create_execute_order_shimless_accounts(
152
257
sysvars,
153
258
}
154
259
}
155
-
156
- pub async fn execute_order_shimless_test (
157
- testing_context : & TestingContext ,
158
- test_context : & mut ProgramTestContext ,
159
- config : & ExecuteOrderInstructionConfig ,
160
- auction_accounts : & AuctionAccounts ,
161
- auction_state : & AuctionState ,
162
- expected_error : Option < & ExpectedError > ,
163
- ) -> Option < ExecuteOrderShimlessFixture > {
164
- let payer_signer = config
165
- . payer_signer
166
- . clone ( )
167
- . unwrap_or_else ( || testing_context. testing_actors . payer_signer . clone ( ) ) ;
168
- let slots_to_fast_forward = config. fast_forward_slots ;
169
- if slots_to_fast_forward > 0 {
170
- crate :: testing_engine:: engine:: fast_forward_slots ( test_context, slots_to_fast_forward)
171
- . await ;
172
- }
173
- let executor_token = config
174
- . actor_enum
175
- . get_actor ( & testing_context. testing_actors )
176
- . token_account_address ( & config. token_enum )
177
- . unwrap_or_else ( || {
178
- auction_state
179
- . get_active_auction ( )
180
- . unwrap ( )
181
- . best_offer
182
- . offer_token
183
- } ) ;
184
- let fixture_accounts = testing_context
185
- . get_fixture_accounts ( )
186
- . expect ( "Fixture accounts not found" ) ;
187
- let execute_order_accounts: ExecuteOrderShimlessAccounts =
188
- create_execute_order_shimless_accounts (
189
- testing_context,
190
- & fixture_accounts,
191
- auction_accounts,
192
- & payer_signer,
193
- auction_state,
194
- executor_token,
195
- ) ;
196
- let execute_order_instruction_data = ExecuteOrderShimlessInstruction { } . data ( ) ;
197
- let execute_order_ix = Instruction {
198
- program_id : testing_context. get_matching_engine_program_id ( ) ,
199
- accounts : execute_order_accounts. to_account_metas ( None ) ,
200
- data : execute_order_instruction_data,
201
- } ;
202
- let tx = Transaction :: new_signed_with_payer (
203
- & [ execute_order_ix] ,
204
- Some ( & payer_signer. pubkey ( ) ) ,
205
- & [ & payer_signer] ,
206
- testing_context
207
- . get_new_latest_blockhash ( test_context)
208
- . await
209
- . unwrap ( ) ,
210
- ) ;
211
- testing_context
212
- . execute_and_verify_transaction ( test_context, tx, expected_error)
213
- . await ;
214
- if expected_error. is_none ( ) {
215
- Some ( ExecuteOrderShimlessFixture {
216
- cctp_message : execute_order_accounts. cctp_message ,
217
- } )
218
- } else {
219
- None
220
- }
221
- }
0 commit comments