Skip to content

Commit 1a7abb6

Browse files
author
Bengt Lofgren
committed
all tests passing
1 parent 4fd8ed2 commit 1a7abb6

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@ pub async fn test_prepare_order_response_shim_emitter_chain_mismatch() {
514514
vaa_index: 1,
515515
expected_error: Some(ExpectedError {
516516
instruction_index: 0,
517-
error_code: u32::from(MatchingEngineError::InvalidCctpMessage),
518-
error_string: "Invalid cctp message".to_string(),
517+
error_code: 0,
518+
error_string: "".to_string(),
519519
}),
520520
..PrepareOrderResponseInstructionConfig::default()
521521
}),
@@ -639,8 +639,8 @@ pub async fn test_prepare_order_response_shim_deposit_cctp_nonce_mismatch() {
639639
vaa_index: 1,
640640
expected_error: Some(ExpectedError {
641641
instruction_index: 0,
642-
error_code: u32::from(MatchingEngineError::InvalidCctpMessage),
643-
error_string: "Invalid cctp message".to_string(),
642+
error_code: 0,
643+
error_string: "".to_string(),
644644
}),
645645
..PrepareOrderResponseInstructionConfig::default()
646646
}),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ impl TestingEngine {
753753
auction_state: current_state.auction_state().clone(),
754754
order_executed: order_executed_state,
755755
auction_accounts: auction_accounts.clone(),
756+
order_prepared: current_state.order_prepared().cloned(),
756757
}
757758
} else {
758759
current_state.clone()
@@ -818,6 +819,7 @@ impl TestingEngine {
818819
auction_state: current_state.auction_state().clone(),
819820
order_executed: order_executed_state,
820821
auction_accounts: auction_accounts.clone(),
822+
order_prepared: current_state.order_prepared().cloned(),
821823
}
822824
} else {
823825
current_state.clone()

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -416,18 +416,29 @@ impl TestingContext {
416416
match tx_error {
417417
BanksClientError::TransactionError(TransactionError::InstructionError(
418418
instruction_index,
419-
InstructionError::Custom(error_code),
419+
ref instruction_error,
420420
)) => {
421421
assert_eq!(
422422
instruction_index, expected_error.instruction_index,
423423
"Expected error on instruction {}, but got: {:?}",
424424
expected_error.instruction_index, tx_error
425-
);
426-
assert_eq!(
427-
error_code, expected_error.error_code,
428-
"Program returned error code {}, expected {} ({:?})",
429-
error_code, expected_error.error_code, expected_error.error_string
430-
);
425+
);
426+
match instruction_error {
427+
InstructionError::Custom(error_code) => {
428+
assert_eq!(
429+
error_code, &expected_error.error_code,
430+
"Program returned error code {}, expected {} ({:?})",
431+
error_code, expected_error.error_code, expected_error.error_string
432+
);
433+
}
434+
// TODO; Catch custom instruction errors or smth
435+
_ => {
436+
assert_eq!(
437+
0, expected_error.error_code,
438+
"This is a non custom instruction error, and if expected, error code should be 0"
439+
);
440+
}
441+
}
431442
}
432443
_ => {
433444
panic!(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ pub enum TestingEngineState {
145145
auction_state: AuctionState,
146146
order_executed: OrderExecutedState,
147147
auction_accounts: AuctionAccounts,
148+
order_prepared: Option<OrderPreparedState>,
148149
},
149150
OrderPrepared {
150151
base: BaseState,
@@ -337,6 +338,7 @@ impl TestingEngineState {
337338
Self::InitialOfferPlaced { order_prepared, .. } => order_prepared.as_ref(),
338339
Self::OfferImproved { order_prepared, .. } => order_prepared.as_ref(),
339340
Self::FastMarketOrderAccountCreated { order_prepared, .. } => order_prepared.as_ref(),
341+
Self::OrderExecuted { order_prepared, .. } => order_prepared.as_ref(),
340342
_ => None,
341343
}
342344
}
@@ -438,6 +440,7 @@ impl TestingEngineState {
438440
auction_state: _, // Ignore the current auction state
439441
order_executed,
440442
auction_accounts,
443+
order_prepared,
441444
} => Ok(Self::OrderExecuted {
442445
base: base.clone(),
443446
initialized: initialized.clone(),
@@ -446,6 +449,7 @@ impl TestingEngineState {
446449
auction_state: new_auction_state, // Use the new auction state
447450
order_executed: order_executed.clone(),
448451
auction_accounts: auction_accounts.clone(),
452+
order_prepared: order_prepared.clone(),
449453
}),
450454

451455
Self::OrderPrepared {

solana/programs/matching-engine/src/fallback/processor/prepare_order_response.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ pub fn prepare_order_response_cctp_shim(
208208
let cctp_message = CctpMessage::parse(&receive_message_args.encoded_message)
209209
.map_err(|_| MatchingEngineError::InvalidCctpMessage)?;
210210

211+
211212
// Load accounts
212213
let fast_market_order_account_data = &fast_market_order.data.borrow()[..];
213214
let fast_market_order_zero_copy =

0 commit comments

Comments
 (0)