1
- use crate :: testing_engine:: config:: ExpectedError ;
2
- use crate :: testing_engine:: setup:: { Solver , TestingContext , TransferDirection } ;
3
- use crate :: utils:: auction:: ActiveAuctionState ;
1
+ use crate :: testing_engine:: config:: {
2
+ ExecuteOrderInstructionConfig , ExpectedError , InstructionConfig ,
3
+ } ;
4
+ use crate :: testing_engine:: setup:: { TestingContext , TransferDirection } ;
5
+ use crate :: testing_engine:: state:: TestingEngineState ;
6
+ use crate :: utils:: token_account:: SplTokenEnum ;
4
7
5
8
use super :: super :: utils;
6
9
use anchor_spl:: token:: spl_token;
@@ -9,10 +12,7 @@ use common::wormhole_cctp_solana::cctp::{
9
12
} ;
10
13
use matching_engine:: fallback:: execute_order:: { ExecuteOrderCctpShim , ExecuteOrderShimAccounts } ;
11
14
use solana_program_test:: ProgramTestContext ;
12
- use solana_sdk:: {
13
- pubkey:: Pubkey , signature:: Keypair , signer:: Signer , sysvar:: SysvarId , transaction:: Transaction ,
14
- } ;
15
- use std:: rc:: Rc ;
15
+ use solana_sdk:: { pubkey:: Pubkey , signer:: Signer , sysvar:: SysvarId , transaction:: Transaction } ;
16
16
use utils:: constants:: * ;
17
17
use wormhole_svm_definitions:: solana:: CORE_BRIDGE_PROGRAM_ID ;
18
18
use wormhole_svm_definitions:: {
@@ -40,13 +40,17 @@ pub struct ExecuteOrderFallbackAccounts {
40
40
41
41
impl ExecuteOrderFallbackAccounts {
42
42
pub fn new (
43
- auction_accounts : & utils:: auction:: AuctionAccounts ,
44
- fast_market_order_address : & Pubkey ,
45
- active_auction_state : & ActiveAuctionState ,
46
- signer : & Pubkey ,
43
+ current_state : & TestingEngineState ,
44
+ payer_signer : & Pubkey ,
47
45
fixture_accounts : & utils:: account_fixtures:: FixtureAccounts ,
48
- transfer_direction : TransferDirection ,
49
46
) -> Self {
47
+ let transfer_direction = current_state. base ( ) . transfer_direction ;
48
+ let auction_accounts = current_state. auction_accounts ( ) . unwrap ( ) ;
49
+ let active_auction_state = current_state. auction_state ( ) . get_active_auction ( ) . unwrap ( ) ;
50
+ let fast_market_order_address = current_state
51
+ . fast_market_order ( )
52
+ . unwrap ( )
53
+ . fast_market_order_address ;
50
54
let remote_token_messenger = match transfer_direction {
51
55
TransferDirection :: FromEthereumToArbitrum => {
52
56
fixture_accounts. arbitrum_remote_token_messenger
@@ -58,15 +62,15 @@ impl ExecuteOrderFallbackAccounts {
58
62
} ;
59
63
60
64
Self {
61
- signer : * signer ,
65
+ signer : * payer_signer ,
62
66
custodian : auction_accounts. custodian ,
63
- fast_market_order_address : * fast_market_order_address ,
67
+ fast_market_order_address,
64
68
active_auction : active_auction_state. auction_address ,
65
69
active_auction_custody_token : active_auction_state. auction_custody_token_address ,
66
70
active_auction_config : auction_accounts. auction_config ,
67
71
active_auction_best_offer_token : auction_accounts. offer_token ,
68
72
initial_offer_token : auction_accounts. offer_token ,
69
- initial_participant : * signer ,
73
+ initial_participant : * payer_signer ,
70
74
to_router_endpoint : auction_accounts. to_router_endpoint ,
71
75
remote_token_messenger,
72
76
token_messenger : fixture_accounts. token_messenger ,
@@ -87,18 +91,70 @@ pub struct ExecuteOrderFallbackFixtureAccounts {
87
91
pub remote_token_messenger : Pubkey ,
88
92
pub token_messenger_minter_sender_authority : Pubkey ,
89
93
pub token_messenger_minter_event_authority : Pubkey ,
94
+ pub messenger_transmitter_config : Pubkey ,
95
+ pub token_minter : Pubkey ,
96
+ pub executor_token : Pubkey ,
90
97
}
91
98
92
99
pub async fn execute_order_fallback (
93
100
testing_context : & TestingContext ,
94
101
test_context : & mut ProgramTestContext ,
95
- payer_signer : & Rc < Keypair > ,
96
- program_id : & Pubkey ,
97
- solver : Solver ,
102
+ config : & ExecuteOrderInstructionConfig ,
98
103
execute_order_fallback_accounts : & ExecuteOrderFallbackAccounts ,
99
104
expected_error : Option < & ExpectedError > ,
100
105
) -> Option < ExecuteOrderFallbackFixture > {
101
- // Get target chain and use as remote address
106
+ let program_id = & testing_context. get_matching_engine_program_id ( ) ;
107
+ let payer_signer = config
108
+ . payer_signer
109
+ . clone ( )
110
+ . unwrap_or_else ( || testing_context. testing_actors . owner . keypair ( ) ) ;
111
+
112
+ let execute_order_fallback_fixture = create_execute_order_fallback_fixture (
113
+ testing_context,
114
+ config,
115
+ execute_order_fallback_accounts,
116
+ ) ;
117
+ let clock_id = solana_program:: clock:: Clock :: id ( ) ;
118
+ let execute_order_ix_accounts = create_execute_order_shim_accounts (
119
+ execute_order_fallback_accounts,
120
+ & execute_order_fallback_fixture,
121
+ & clock_id,
122
+ ) ;
123
+
124
+ let execute_order_ix = ExecuteOrderCctpShim {
125
+ program_id,
126
+ accounts : execute_order_ix_accounts,
127
+ }
128
+ . instruction ( ) ;
129
+
130
+ // Considering fast forwarding blocks here for deadline to be reached
131
+ let recent_blockhash = testing_context
132
+ . get_new_latest_blockhash ( test_context)
133
+ . await
134
+ . unwrap ( ) ;
135
+ crate :: testing_engine:: engine:: fast_forward_slots ( test_context, 3 ) . await ;
136
+ let transaction = Transaction :: new_signed_with_payer (
137
+ & [ execute_order_ix] ,
138
+ Some ( & payer_signer. pubkey ( ) ) ,
139
+ & [ & payer_signer] ,
140
+ recent_blockhash,
141
+ ) ;
142
+ testing_context
143
+ . execute_and_verify_transaction ( test_context, transaction, expected_error)
144
+ . await ;
145
+ if expected_error. is_none ( ) {
146
+ Some ( execute_order_fallback_fixture)
147
+ } else {
148
+ None
149
+ }
150
+ }
151
+
152
+ pub fn create_execute_order_fallback_fixture (
153
+ testing_context : & TestingContext ,
154
+ config : & ExecuteOrderInstructionConfig ,
155
+ execute_order_fallback_accounts : & ExecuteOrderFallbackAccounts ,
156
+ ) -> ExecuteOrderFallbackFixture {
157
+ let program_id = & testing_context. get_matching_engine_program_id ( ) ;
102
158
let cctp_message = Pubkey :: find_program_address (
103
159
& [
104
160
common:: CCTP_MESSAGE_SEED_PREFIX ,
@@ -134,35 +190,70 @@ pub async fn execute_order_fallback(
134
190
& POST_MESSAGE_SHIM_PROGRAM_ID ,
135
191
)
136
192
. 0 ;
137
- let executor_token = solver. actor . token_account_address ( ) . unwrap ( ) ;
193
+ let solver = testing_context. testing_actors . solvers [ config. solver_index ] . clone ( ) ;
194
+ let executor_token = solver
195
+ . actor
196
+ . token_account_address ( & SplTokenEnum :: Usdc )
197
+ . unwrap ( ) ;
198
+ ExecuteOrderFallbackFixture {
199
+ cctp_message,
200
+ post_message_sequence,
201
+ post_message_message,
202
+ accounts : ExecuteOrderFallbackFixtureAccounts {
203
+ local_token,
204
+ token_messenger,
205
+ remote_token_messenger,
206
+ token_messenger_minter_sender_authority,
207
+ token_messenger_minter_event_authority : * token_messenger_minter_event_authority,
208
+ messenger_transmitter_config,
209
+ token_minter,
210
+ executor_token,
211
+ } ,
212
+ }
213
+ }
138
214
139
- let execute_order_ix_accounts = ExecuteOrderShimAccounts {
140
- signer : & payer_signer. pubkey ( ) , // 0
141
- cctp_message : & cctp_message, // 1
215
+ pub fn create_execute_order_shim_accounts < ' ix > (
216
+ execute_order_fallback_accounts : & ' ix ExecuteOrderFallbackAccounts ,
217
+ execute_order_fallback_fixture : & ' ix ExecuteOrderFallbackFixture ,
218
+ clock_id : & ' ix Pubkey ,
219
+ ) -> ExecuteOrderShimAccounts < ' ix > {
220
+ ExecuteOrderShimAccounts {
221
+ signer : & execute_order_fallback_accounts. signer , // 0
222
+ cctp_message : & execute_order_fallback_fixture. cctp_message , // 1
142
223
custodian : & execute_order_fallback_accounts. custodian , // 2
143
224
fast_market_order : & execute_order_fallback_accounts. fast_market_order_address , // 3
144
225
active_auction : & execute_order_fallback_accounts. active_auction , // 4
145
226
active_auction_custody_token : & execute_order_fallback_accounts. active_auction_custody_token , // 5
146
227
active_auction_config : & execute_order_fallback_accounts. active_auction_config , // 6
147
228
active_auction_best_offer_token : & execute_order_fallback_accounts
148
229
. active_auction_best_offer_token , // 7
149
- executor_token : & executor_token, // 8
230
+ executor_token : & execute_order_fallback_fixture . accounts . executor_token , // 8
150
231
initial_offer_token : & execute_order_fallback_accounts. initial_offer_token , // 9
151
232
initial_participant : & execute_order_fallback_accounts. initial_participant , // 10
152
233
to_router_endpoint : & execute_order_fallback_accounts. to_router_endpoint , // 11
153
234
post_message_shim_program : & POST_MESSAGE_SHIM_PROGRAM_ID , // 12
154
- post_message_sequence : & post_message_sequence, // 13
155
- post_message_message : & post_message_message, // 14
235
+ post_message_sequence : & execute_order_fallback_fixture . post_message_sequence , // 13
236
+ post_message_message : & execute_order_fallback_fixture . post_message_message , // 14
156
237
cctp_deposit_for_burn_mint : & USDC_MINT , // 15
157
238
cctp_deposit_for_burn_token_messenger_minter_sender_authority :
158
- & token_messenger_minter_sender_authority, // 16
159
- cctp_deposit_for_burn_message_transmitter_config : & messenger_transmitter_config, // 17
160
- cctp_deposit_for_burn_token_messenger : & token_messenger, // 18
161
- cctp_deposit_for_burn_remote_token_messenger : & remote_token_messenger, // 19
162
- cctp_deposit_for_burn_token_minter : & token_minter, // 20
163
- cctp_deposit_for_burn_local_token : & local_token, // 21
239
+ & execute_order_fallback_fixture
240
+ . accounts
241
+ . token_messenger_minter_sender_authority , // 16
242
+ cctp_deposit_for_burn_message_transmitter_config : & execute_order_fallback_fixture
243
+ . accounts
244
+ . messenger_transmitter_config , // 17
245
+ cctp_deposit_for_burn_token_messenger : & execute_order_fallback_fixture
246
+ . accounts
247
+ . token_messenger , // 18
248
+ cctp_deposit_for_burn_remote_token_messenger : & execute_order_fallback_fixture
249
+ . accounts
250
+ . remote_token_messenger , // 19
251
+ cctp_deposit_for_burn_token_minter : & execute_order_fallback_fixture. accounts . token_minter , // 20
252
+ cctp_deposit_for_burn_local_token : & execute_order_fallback_fixture. accounts . local_token , // 21
164
253
cctp_deposit_for_burn_token_messenger_minter_event_authority :
165
- token_messenger_minter_event_authority, // 22
254
+ & execute_order_fallback_fixture
255
+ . accounts
256
+ . token_messenger_minter_event_authority , // 22
166
257
cctp_deposit_for_burn_token_messenger_minter_program : & TOKEN_MESSENGER_MINTER_PROGRAM_ID , // 23
167
258
cctp_deposit_for_burn_message_transmitter_program : & MESSAGE_TRANSMITTER_PROGRAM_ID , // 24
168
259
core_bridge_program : & CORE_BRIDGE_PROGRAM_ID , // 25
@@ -171,74 +262,30 @@ pub async fn execute_order_fallback(
171
262
post_message_shim_event_authority : & POST_MESSAGE_SHIM_EVENT_AUTHORITY , // 28
172
263
system_program : & solana_program:: system_program:: ID , // 29
173
264
token_program : & spl_token:: ID , // 30
174
- clock : & solana_program:: clock:: Clock :: id ( ) , // 31
175
- } ;
176
-
177
- let execute_order_ix = ExecuteOrderCctpShim {
178
- program_id,
179
- accounts : execute_order_ix_accounts,
180
- }
181
- . instruction ( ) ;
182
-
183
- // Considering fast forwarding blocks here for deadline to be reached
184
- let recent_blockhash = testing_context
185
- . get_new_latest_blockhash ( test_context)
186
- . await
187
- . unwrap ( ) ;
188
- crate :: testing_engine:: engine:: fast_forward_slots ( test_context, 3 ) . await ;
189
- let transaction = Transaction :: new_signed_with_payer (
190
- & [ execute_order_ix] ,
191
- Some ( & payer_signer. pubkey ( ) ) ,
192
- & [ & payer_signer] ,
193
- recent_blockhash,
194
- ) ;
195
- testing_context
196
- . execute_and_verify_transaction ( test_context, transaction, expected_error)
197
- . await ;
198
- if expected_error. is_none ( ) {
199
- Some ( ExecuteOrderFallbackFixture {
200
- cctp_message,
201
- post_message_sequence,
202
- post_message_message,
203
- accounts : ExecuteOrderFallbackFixtureAccounts {
204
- local_token,
205
- token_messenger,
206
- remote_token_messenger,
207
- token_messenger_minter_sender_authority,
208
- token_messenger_minter_event_authority : * token_messenger_minter_event_authority,
209
- } ,
210
- } )
211
- } else {
212
- None
265
+ clock : clock_id, // 31
213
266
}
214
267
}
215
268
216
269
pub async fn execute_order_fallback_test (
217
270
testing_context : & TestingContext ,
218
271
test_context : & mut ProgramTestContext ,
219
- auction_accounts : & utils:: auction:: AuctionAccounts ,
220
- fast_market_order_address : & Pubkey ,
221
- active_auction_state : & ActiveAuctionState ,
222
- solver : Solver ,
223
- expected_error : Option < & ExpectedError > ,
272
+ current_state : & TestingEngineState ,
273
+ config : & ExecuteOrderInstructionConfig ,
224
274
) -> Option < ExecuteOrderFallbackFixture > {
275
+ let expected_error = config. expected_error ( ) ;
225
276
let fixture_accounts = testing_context
226
277
. get_fixture_accounts ( )
227
278
. expect ( "Pre-made fixture accounts not found" ) ;
228
- let execute_order_fallback_accounts = ExecuteOrderFallbackAccounts :: new (
229
- auction_accounts,
230
- fast_market_order_address,
231
- active_auction_state,
232
- & testing_context. testing_actors . owner . pubkey ( ) ,
233
- & fixture_accounts,
234
- testing_context. transfer_direction ,
235
- ) ;
279
+ let payer_signer = config
280
+ . payer_signer
281
+ . clone ( )
282
+ . unwrap_or_else ( || testing_context. testing_actors . owner . keypair ( ) ) ;
283
+ let execute_order_fallback_accounts =
284
+ ExecuteOrderFallbackAccounts :: new ( current_state, & payer_signer. pubkey ( ) , & fixture_accounts) ;
236
285
execute_order_fallback (
237
286
testing_context,
238
287
test_context,
239
- & testing_context. testing_actors . owner . keypair ( ) ,
240
- & testing_context. get_matching_engine_program_id ( ) ,
241
- solver,
288
+ config,
242
289
& execute_order_fallback_accounts,
243
290
expected_error,
244
291
)
0 commit comments