Skip to content

Commit 940c716

Browse files
Bengt Lofgrena5-pickle
authored andcommitted
[working] instruction added to check that create fast market order and place initial offer can be done in the same tx
1 parent e0f97f9 commit 940c716

File tree

6 files changed

+71
-33
lines changed

6 files changed

+71
-33
lines changed

solana/modules/matching-engine-testing/tests/shimful/shims_make_offer.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ pub async fn place_initial_offer_shimful(
7676
1000000000,
7777
)
7878
.await;
79-
8079
testing_context
8180
.execute_and_verify_transaction(test_context, transaction, expected_error)
8281
.await;
@@ -244,10 +243,13 @@ impl PlaceInitialOfferShimfulAccounts {
244243
.payer_signer
245244
.clone()
246245
.unwrap_or_else(|| testing_context.testing_actors.payer_signer.clone());
247-
let close_account_refund_recipient = current_state
248-
.fast_market_order()
249-
.unwrap()
250-
.close_account_refund_recipient;
246+
let close_account_refund_recipient =
247+
config.close_account_refund_recipient.unwrap_or_else(|| {
248+
current_state
249+
.fast_market_order()
250+
.unwrap()
251+
.close_account_refund_recipient
252+
});
251253
let fast_market_order = match &config.fast_market_order_address {
252254
Some(fast_market_order_address) => *fast_market_order_address,
253255
None => {

solana/modules/matching-engine-testing/tests/shimless/initialize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ pub async fn initialize_program(
181181
test_context,
182182
&[instruction],
183183
Some(&payer_signer.pubkey()),
184-
&[&payer_signer],
184+
&[&payer_signer, &testing_context.testing_actors.owner.keypair()],
185185
1000000000,
186186
1000000000,
187187
)
@@ -200,7 +200,7 @@ pub async fn initialize_program(
200200
test_context,
201201
&[instruction],
202202
Some(&payer_signer.pubkey()),
203-
&[&payer_signer,],
203+
&[&payer_signer, &testing_context.testing_actors.owner.keypair()],
204204
1000000000,
205205
1000000000,
206206
)

solana/modules/matching-engine-testing/tests/test_scenarios/initialize_and_misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub async fn test_local_token_router_endpoint_creation() {
131131
&config,
132132
)
133133
.await;
134-
let custodian = initialize_state.auction_accounts().unwrap().custodian;
134+
let custodian = initialize_state.initialized().unwrap().custodian_address;
135135
let owner = &testing_engine.testing_context.testing_actors.owner;
136136
let _local_token_router_endpoint = add_local_router_endpoint_ix(
137137
&testing_engine.testing_context,

solana/modules/matching-engine-testing/tests/test_scenarios/make_offer.rs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,8 @@ pub async fn test_place_initial_offer_shim_and_improve_offer_shimless() {
186186
/// Test that place initial offer and create fast market order can be done in one transaction
187187
#[tokio::test]
188188
pub async fn test_place_initial_offer_and_create_fast_market_order_in_one_transaction() {
189-
let config = Box::new(CombinedInstructionConfig::create_fast_market_order_and_place_initial_offer());
190-
let vaa_args =
191-
vec![VaaArgs {
192-
post_vaa: false,
189+
let vaa_args = vec![VaaArgs {
190+
post_vaa: false,
193191
..VaaArgs::default()
194192
}];
195193
let (testing_context, mut test_context) = setup_environment(
@@ -205,9 +203,23 @@ pub async fn test_place_initial_offer_and_create_fast_market_order_in_one_transa
205203
CreateCctpRouterEndpointsInstructionConfig::default(),
206204
),
207205
];
208-
let initial_state = testing_engine.execute(&mut test_context, initialize_instruction_triggers, None).await;
209-
let instruction_triggers = vec![CombinationTrigger::CreateFastMarketOrderAndPlaceInitialOffer(config)];
210-
testing_engine.execute(&mut test_context, instruction_triggers, Some(initial_state)).await;
206+
let initial_state = testing_engine
207+
.execute(&mut test_context, initialize_instruction_triggers, None)
208+
.await;
209+
let config = Box::new(
210+
CombinedInstructionConfig::create_fast_market_order_and_place_initial_offer(
211+
&testing_engine.testing_context.testing_actors,
212+
&initial_state,
213+
&testing_engine
214+
.testing_context
215+
.get_matching_engine_program_id(),
216+
),
217+
);
218+
let instruction_triggers =
219+
vec![CombinationTrigger::CreateFastMarketOrderAndPlaceInitialOffer(config)];
220+
testing_engine
221+
.execute(&mut test_context, instruction_triggers, Some(initial_state))
222+
.await;
211223
}
212224
/*
213225
Sad path tests section
@@ -267,7 +279,7 @@ pub async fn test_place_initial_offer_shimless_blocks_shim() {
267279
InstructionTrigger::PlaceInitialOfferShim(PlaceInitialOfferInstructionConfig {
268280
actor: TestingActorEnum::Solver(1),
269281
expected_error: Some(ExpectedError {
270-
instruction_index: 0,
282+
instruction_index: 2,
271283
error_code: 0,
272284
error_string: TransactionError::AccountInUse.to_string(),
273285
}),
@@ -326,7 +338,7 @@ pub async fn test_place_initial_offer_shim_blocks_shimless() {
326338
#[tokio::test]
327339
pub async fn test_place_initial_offer_shim_fails_usdt_token_account() {
328340
let expected_error = ExpectedError {
329-
instruction_index: 0,
341+
instruction_index: 2,
330342
error_code: 3, // Token spl transfer error code when mint does not match
331343
error_string: "Invalid argument".to_string(),
332344
};
@@ -346,7 +358,7 @@ pub async fn test_place_initial_shim_offer_fails_usdt_mint_address() {
346358
..PlaceInitialOfferCustomAccounts::default()
347359
};
348360
let expected_error = ExpectedError {
349-
instruction_index: 0,
361+
instruction_index: 2,
350362
error_code: u32::from(MatchingEngineError::InvalidMint), // Token spl transfer error code when mint does not match
351363
error_string: "Invalid mint".to_string(),
352364
};
@@ -390,7 +402,7 @@ pub async fn test_place_initial_offer_fails_if_fast_market_order_not_created() {
390402
InstructionTrigger::PlaceInitialOfferShim(PlaceInitialOfferInstructionConfig {
391403
fast_market_order_address: OverwriteCurrentState::Some(fake_fast_market_order_address),
392404
expected_error: Some(ExpectedError {
393-
instruction_index: 0,
405+
instruction_index: 2,
394406
error_code: u32::from(ErrorCode::ConstraintOwner),
395407
error_string: "Fast market order account owner is invalid".to_string(),
396408
}),
@@ -421,7 +433,7 @@ pub async fn test_place_initial_offer_shim_fails_when_offer_greater_than_max_fee
421433
.create_vaa_args_and_initial_offer_config();
422434

423435
let expected_error = ExpectedError {
424-
instruction_index: 0,
436+
instruction_index: 2,
425437
error_code: u32::from(MatchingEngineError::OfferPriceTooHigh),
426438
error_string: "Offer price is greater than max fee".to_string(),
427439
};
@@ -451,7 +463,7 @@ pub async fn test_place_initial_offer_shim_fails_when_amount_in_is_u64_max() {
451463
.create_vaa_args_and_initial_offer_config();
452464

453465
let expected_error = ExpectedError {
454-
instruction_index: 0,
466+
instruction_index: 2,
455467
error_code: u32::from(MatchingEngineError::U64Overflow),
456468
error_string: "U64Overflow".to_string(),
457469
};
@@ -481,7 +493,7 @@ pub async fn test_place_initial_offer_shim_fails_when_max_fee_and_amount_in_sum_
481493
.create_vaa_args_and_initial_offer_config();
482494

483495
let expected_error = ExpectedError {
484-
instruction_index: 0,
496+
instruction_index: 2,
485497
error_code: u32::from(MatchingEngineError::U64Overflow),
486498
error_string: "U64Overflow".to_string(),
487499
};
@@ -528,7 +540,7 @@ pub async fn test_place_initial_offer_shim_fails_when_vaa_is_expired() {
528540

529541
let place_initial_offer_config = PlaceInitialOfferInstructionConfig {
530542
expected_error: Some(ExpectedError {
531-
instruction_index: 0,
543+
instruction_index: 2,
532544
error_code: u32::from(MatchingEngineError::FastMarketOrderExpired),
533545
error_string: "Fast market order has expired".to_string(),
534546
}),
@@ -588,7 +600,7 @@ pub async fn test_place_initial_offer_shim_fails_custodian_is_paused() {
588600

589601
let place_initial_offer_config = PlaceInitialOfferInstructionConfig {
590602
expected_error: Some(ExpectedError {
591-
instruction_index: 0,
603+
instruction_index: 2,
592604
error_code: u32::from(MatchingEngineError::Paused),
593605
error_string: "Fast market order account owner is invalid".to_string(),
594606
}),
@@ -614,7 +626,7 @@ pub async fn test_place_initial_offer_shim_fails_back_to_back() {
614626
.await;
615627

616628
let expected_error = ExpectedError {
617-
instruction_index: 0,
629+
instruction_index: 2,
618630
error_code: 0,
619631
error_string: "Already in use".to_string(),
620632
};

solana/modules/matching-engine-testing/tests/testing_engine/config.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::{
2121
};
2222

2323
use crate::{
24+
shimful::fast_market_order_shim::create_fast_market_order_state_from_vaa_data,
2425
shimless::initialize::AuctionParametersConfig,
2526
utils::{
2627
auction::{ActiveAuctionState, AuctionAccounts},
@@ -29,6 +30,7 @@ use crate::{
2930
},
3031
};
3132
use anchor_lang::prelude::*;
33+
use matching_engine::state::FastMarketOrder as FastMarketOrderState;
3234
use solana_program_test::ProgramTestContext;
3335
use solana_sdk::signature::Keypair;
3436

@@ -292,6 +294,7 @@ pub struct PlaceInitialOfferInstructionConfig {
292294
pub test_vaa_pair_index: usize,
293295
pub offer_price: u64,
294296
pub payer_signer: Option<Rc<Keypair>>,
297+
pub close_account_refund_recipient: Option<Pubkey>,
295298
pub fast_market_order_address: OverwriteCurrentState<Pubkey>,
296299
pub custom_accounts: OverwriteCurrentState<PlaceInitialOfferCustomAccounts>,
297300
pub spl_token_enum: SplTokenEnum,
@@ -350,6 +353,7 @@ impl Default for PlaceInitialOfferInstructionConfig {
350353
test_vaa_pair_index: 0,
351354
offer_price: 1__000_000,
352355
payer_signer: None,
356+
close_account_refund_recipient: None,
353357
fast_market_order_address: None,
354358
custom_accounts: None,
355359
spl_token_enum: SplTokenEnum::Usdc,
@@ -643,12 +647,36 @@ impl Default for CombinedInstructionConfig {
643647
}
644648

645649
impl CombinedInstructionConfig {
646-
pub fn create_fast_market_order_and_place_initial_offer(
650+
pub fn create_fast_market_order_and_place_initial_offer(
651+
testing_actors: &TestingActors,
652+
current_state: &TestingEngineState,
653+
program_id: &Pubkey,
647654
) -> Self {
655+
let test_vaa_pair = current_state.get_test_vaa_pair(0);
656+
let fast_transfer_vaa = test_vaa_pair.fast_transfer_vaa.clone();
657+
let fast_market_order = create_fast_market_order_state_from_vaa_data(
658+
&fast_transfer_vaa.vaa_data,
659+
testing_actors.solvers[0].pubkey(),
660+
);
661+
let (fast_market_order_address, _fast_market_order_bump) = Pubkey::find_program_address(
662+
&[
663+
FastMarketOrderState::SEED_PREFIX,
664+
&fast_market_order.digest(),
665+
&fast_market_order.close_account_refund_recipient.as_ref(),
666+
],
667+
program_id,
668+
);
669+
648670
Self {
649-
create_fast_market_order_config: Some(InitializeFastMarketOrderShimInstructionConfig::default()),
650-
place_initial_offer_config: Some(PlaceInitialOfferInstructionConfig::default()),
671+
create_fast_market_order_config: Some(
672+
InitializeFastMarketOrderShimInstructionConfig::default(),
673+
),
674+
place_initial_offer_config: Some(PlaceInitialOfferInstructionConfig {
675+
close_account_refund_recipient: Some(testing_actors.solvers[0].actor.pubkey()),
676+
fast_market_order_address: Some(fast_market_order_address),
677+
..PlaceInitialOfferInstructionConfig::default()
678+
}),
651679
..Default::default()
652680
}
653681
}
654-
}
682+
}

solana/modules/matching-engine-testing/tests/testing_engine/engine.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,6 @@ impl TestingEngine {
944944
.payer_signer
945945
.clone()
946946
.unwrap_or_else(|| self.testing_context.testing_actors.payer_signer.clone());
947-
println!("Got here 0");
948947
let guardian_signature_info = create_guardian_signatures(
949948
&self.testing_context,
950949
test_context,
@@ -981,7 +980,6 @@ impl TestingEngine {
981980
.payer_signer
982981
.clone()
983982
.unwrap_or_else(|| self.testing_context.testing_actors.payer_signer.clone());
984-
println!("Got here 1");
985983
let transaction = self
986984
.testing_context
987985
.create_transaction(
@@ -998,7 +996,6 @@ impl TestingEngine {
998996
1000000000,
999997
)
1000998
.await;
1001-
println!("Got here 2");
1002999
let actor_usdc_balance_before = place_initial_offer_config
10031000
.actor
10041001
.get_actor(&self.testing_context.testing_actors)
@@ -1012,7 +1009,6 @@ impl TestingEngine {
10121009
self.testing_context
10131010
.execute_and_verify_transaction(test_context, transaction, None)
10141011
.await;
1015-
println!("Got here 3");
10161012
let fast_market_order_created_state = TestingEngineState::FastMarketOrderAccountCreated {
10171013
base: current_state.base().clone(),
10181014
initialized: current_state.initialized().unwrap().clone(),

0 commit comments

Comments
 (0)