@@ -14,7 +14,9 @@ use crate::testing_engine::config::{
14
14
InitializeInstructionConfig , PlaceInitialOfferInstructionConfig ,
15
15
} ;
16
16
use crate :: utils;
17
+ use crate :: utils:: auction:: { ActiveAuctionState , AuctionAccounts } ;
17
18
19
+ use anchor_lang:: error:: ErrorCode ;
18
20
use solana_program_test:: tokio;
19
21
use testing_engine:: config:: * ;
20
22
use testing_engine:: engine:: { InstructionTrigger , TestingEngine } ;
@@ -150,6 +152,179 @@ pub async fn test_settle_auction_balance_changes() {
150
152
helpers:: compare_balance_changes ( & balance_changes_shim, & balance_changes_shimless) ;
151
153
}
152
154
155
+ /// Test settle auction prepare order before active auction
156
+ #[ tokio:: test]
157
+ pub async fn test_settle_auction_prepare_order_before_active_auction ( ) {
158
+ let transfer_direction = TransferDirection :: FromEthereumToArbitrum ;
159
+ let ( testing_context, mut test_context) = setup_environment (
160
+ ShimMode :: VerifyAndPostSignature ,
161
+ transfer_direction,
162
+ Some ( vec ! [ VaaArgs :: default ( ) ] ) ,
163
+ )
164
+ . await ;
165
+ let testing_engine = TestingEngine :: new ( testing_context) . await ;
166
+
167
+ let instruction_triggers = vec ! [
168
+ InstructionTrigger :: InitializeProgram ( InitializeInstructionConfig :: default ( ) ) ,
169
+ InstructionTrigger :: CreateCctpRouterEndpoints (
170
+ CreateCctpRouterEndpointsInstructionConfig :: default ( ) ,
171
+ ) ,
172
+ ] ;
173
+ let create_cctp_router_endpoints_state = testing_engine
174
+ . execute ( & mut test_context, instruction_triggers, None )
175
+ . await ;
176
+
177
+ // This is just needed to get the router endpoint accounts when prepare order happens before place initial offer, it is not used for anything else
178
+ let fake_auction_accounts = AuctionAccounts :: fake_auction_accounts (
179
+ & create_cctp_router_endpoints_state,
180
+ & testing_engine. testing_context ,
181
+ ) ;
182
+ let instruction_triggers = vec ! [
183
+ InstructionTrigger :: InitializeFastMarketOrderShim (
184
+ InitializeFastMarketOrderShimInstructionConfig :: default ( ) ,
185
+ ) ,
186
+ InstructionTrigger :: PrepareOrderShim ( PrepareOrderResponseInstructionConfig {
187
+ overwrite_auction_accounts: Some ( fake_auction_accounts) ,
188
+ ..Default :: default ( )
189
+ } ) ,
190
+ ] ;
191
+ let prepared_order_state = testing_engine
192
+ . execute (
193
+ & mut test_context,
194
+ instruction_triggers,
195
+ Some ( create_cctp_router_endpoints_state) ,
196
+ )
197
+ . await ;
198
+
199
+ let instruction_triggers = vec ! [
200
+ InstructionTrigger :: PlaceInitialOfferShim ( PlaceInitialOfferInstructionConfig :: default ( ) ) ,
201
+ InstructionTrigger :: ExecuteOrderShim ( ExecuteOrderInstructionConfig :: default ( ) ) ,
202
+ InstructionTrigger :: SettleAuction ( SettleAuctionInstructionConfig :: default ( ) ) ,
203
+ ] ;
204
+ testing_engine
205
+ . execute (
206
+ & mut test_context,
207
+ instruction_triggers,
208
+ Some ( prepared_order_state) ,
209
+ )
210
+ . await ;
211
+ }
212
+
213
+ /// Test settle auction with base_fee_token != best offer actor
214
+ #[ tokio:: test]
215
+ pub async fn test_settle_auction_base_fee_token_not_best_offer_actor ( ) {
216
+ let transfer_direction = TransferDirection :: FromEthereumToArbitrum ;
217
+ let ( place_initial_offer_state, mut test_context, testing_engine) =
218
+ Box :: pin ( place_initial_offer_shim (
219
+ PlaceInitialOfferInstructionConfig :: default ( ) ,
220
+ None ,
221
+ transfer_direction,
222
+ ) )
223
+ . await ;
224
+
225
+ let instruction_triggers = vec ! [
226
+ InstructionTrigger :: ExecuteOrderShim ( ExecuteOrderInstructionConfig :: default ( ) ) ,
227
+ InstructionTrigger :: PrepareOrderShim ( PrepareOrderResponseInstructionConfig {
228
+ actor_enum: TestingActorEnum :: Solver ( 2 ) ,
229
+ ..Default :: default ( )
230
+ } ) ,
231
+ InstructionTrigger :: SettleAuction ( SettleAuctionInstructionConfig :: default ( ) ) ,
232
+ ] ;
233
+ testing_engine
234
+ . execute (
235
+ & mut test_context,
236
+ instruction_triggers,
237
+ Some ( place_initial_offer_state) ,
238
+ )
239
+ . await ;
240
+ }
241
+
242
+ /*
243
+ Sad path tests section
244
+
245
+ *****************
246
+ ****** ******
247
+ **** ****
248
+ **** ***
249
+ *** ***
250
+ ** *** *** **
251
+ ** ******* ******* ***
252
+ ** ******* ******* **
253
+ ** ******* ******* **
254
+ ** *** *** **
255
+ ** **
256
+ ** **
257
+ ** **
258
+ ** **
259
+ ** ************ **
260
+ ** ****** ****** **
261
+ *** ***** ***** ***
262
+ ** *** *** **
263
+ *** ** ** ***
264
+ **** ****
265
+ **** ****
266
+ ****** ******
267
+ *****************
268
+ */
269
+
270
+ /// Test cannot settle non-existent auction
271
+ #[ tokio:: test]
272
+ pub async fn test_settle_auction_non_existent ( ) {
273
+ let transfer_direction = TransferDirection :: FromEthereumToArbitrum ;
274
+ let ( testing_context, mut test_context) = setup_environment (
275
+ ShimMode :: VerifyAndPostSignature ,
276
+ transfer_direction,
277
+ Some ( vec ! [ VaaArgs :: default ( ) ] ) ,
278
+ )
279
+ . await ;
280
+ let testing_engine = TestingEngine :: new ( testing_context) . await ;
281
+
282
+ let instruction_triggers = vec ! [
283
+ InstructionTrigger :: InitializeProgram ( InitializeInstructionConfig :: default ( ) ) ,
284
+ InstructionTrigger :: CreateCctpRouterEndpoints (
285
+ CreateCctpRouterEndpointsInstructionConfig :: default ( ) ,
286
+ ) ,
287
+ ] ;
288
+ let create_cctp_router_endpoints_state = testing_engine
289
+ . execute ( & mut test_context, instruction_triggers, None )
290
+ . await ;
291
+
292
+ let fake_auction_accounts = AuctionAccounts :: fake_auction_accounts (
293
+ & create_cctp_router_endpoints_state,
294
+ & testing_engine. testing_context ,
295
+ ) ;
296
+ let fake_active_auction_state =
297
+ ActiveAuctionState :: fake_active_auction_state ( & fake_auction_accounts) ;
298
+ let instruction_triggers = vec ! [
299
+ InstructionTrigger :: InitializeFastMarketOrderShim (
300
+ InitializeFastMarketOrderShimInstructionConfig :: default ( ) ,
301
+ ) ,
302
+ InstructionTrigger :: PrepareOrderShim ( PrepareOrderResponseInstructionConfig {
303
+ overwrite_auction_accounts: Some ( fake_auction_accounts) ,
304
+ ..Default :: default ( )
305
+ } ) ,
306
+ InstructionTrigger :: SettleAuction ( SettleAuctionInstructionConfig {
307
+ overwrite_active_auction_state: Some ( fake_active_auction_state) ,
308
+ expected_error: Some ( ExpectedError {
309
+ instruction_index: 0 ,
310
+ error_code: u32 :: from( ErrorCode :: AccountNotInitialized ) ,
311
+ error_string: "AccountNotInitialized" . to_string( ) ,
312
+ } ) ,
313
+ ..SettleAuctionInstructionConfig :: default ( )
314
+ } ) ,
315
+ ] ;
316
+ testing_engine
317
+ . execute (
318
+ & mut test_context,
319
+ instruction_triggers,
320
+ Some ( create_cctp_router_endpoints_state) ,
321
+ )
322
+ . await ;
323
+ }
324
+
325
+ /*
326
+ Helper code
327
+ */
153
328
mod helpers {
154
329
use super :: * ;
155
330
0 commit comments