Skip to content

Commit c8321b0

Browse files
author
Bengt Lofgren
committed
all tests pass
1 parent 043cfcc commit c8321b0

File tree

15 files changed

+714
-343
lines changed

15 files changed

+714
-343
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ pub fn prepare_order_response_cctp_shim(
227227
let finalized_vaa_message = data.finalized_vaa_message;
228228
// Load accounts
229229
let fast_market_order_zero_copy =
230-
FastMarketOrderState::try_deserialize(&mut &fast_market_order.data.borrow()[..])?;
230+
FastMarketOrderState::try_deserialize(&mut &fast_market_order.data.borrow()[..])
231+
.map(Box::new)?;
231232
// Create pdas for addresses that need to be created
232233
// Check the prepared order response account is valid
233234
// TODO: Pass the digest so it isn't recomputed
@@ -240,7 +241,7 @@ pub fn prepare_order_response_cctp_shim(
240241
let finalised_vaa_emitter_address = fast_market_order_zero_copy.vaa_emitter_address;
241242
let finalised_vaa_nonce = fast_market_order_zero_copy.vaa_nonce;
242243
let finalised_vaa_consistency_level = fast_market_order_zero_copy.vaa_consistency_level;
243-
&finalized_vaa_message.digest(
244+
finalized_vaa_message.digest(
244245
finalised_vaa_sequence,
245246
finalised_vaa_timestamp,
246247
finalised_vaa_emitter_chain,
@@ -277,7 +278,6 @@ pub fn prepare_order_response_cctp_shim(
277278
let slow_order_response = liquidity_layer_message
278279
.slow_order_response()
279280
.ok_or_else(|| MatchingEngineError::InvalidDepositPayloadId)?;
280-
281281
let prepared_order_response_seeds = [
282282
PreparedOrderResponse::SEED_PREFIX,
283283
&fast_market_order_digest,
@@ -385,7 +385,7 @@ pub fn prepare_order_response_cctp_shim(
385385
&wormhole_svm_shim::verify_vaa::VerifyVaaShimInstruction::<false>::VERIFY_HASH_SELECTOR,
386386
);
387387
data.push(guardian_set_bump);
388-
data.extend_from_slice(finalized_vaa_message_digest);
388+
data.extend_from_slice(&finalized_vaa_message_digest);
389389
data
390390
};
391391

solana/programs/matching-engine/tests/initialize_integration_tests.rs

Lines changed: 66 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use matching_engine::{CCTP_MINT_RECIPIENT, ID as PROGRAM_ID};
66
use shimless::execute_order::execute_order_shimless_test;
77
use solana_program_test::tokio;
88
use solana_sdk::pubkey::Pubkey;
9+
use testing_engine::config::CreateCctpRouterEndpointsInstructionConfig;
10+
use utils::constants;
911
mod shimful;
1012
mod shimless;
1113
mod testing_engine;
@@ -22,7 +24,7 @@ use shimful::shims::{
2224
use shimful::shims_execute_order::execute_order_fallback_test;
2325
use shimless::initialize::{initialize_program, AuctionParametersConfig};
2426
use shimless::make_offer::{improve_offer, place_initial_offer_shimless};
25-
use solana_sdk::transaction::VersionedTransaction;
27+
use solana_sdk::transaction::{TransactionError, VersionedTransaction};
2628
use utils::auction::AuctionAccounts;
2729
use utils::router::{add_local_router_endpoint_ix, create_all_router_endpoints_test};
2830
use utils::setup::{setup_environment, ShimMode, TestingContext, TransferDirection};
@@ -41,13 +43,13 @@ pub async fn test_initialize_program() {
4143

4244
let initialize_config = InitializeInstructionConfig::default();
4345

44-
let testing_engine = TestingEngine::new(
45-
testing_context,
46-
vec![InstructionTrigger::InitializeProgram(initialize_config)],
47-
)
48-
.await;
46+
let testing_engine = TestingEngine::new(testing_context).await;
4947

50-
testing_engine.execute().await;
48+
testing_engine
49+
.execute(vec![InstructionTrigger::InitializeProgram(
50+
initialize_config,
51+
)])
52+
.await;
5153
}
5254

5355
/// Test that a CCTP token router endpoint is created for the arbitrum and ethereum chains
@@ -62,16 +64,13 @@ pub async fn test_cctp_token_router_endpoint_creation() {
6264

6365
let initialize_config = InitializeInstructionConfig::default();
6466

65-
let testing_engine = TestingEngine::new(
66-
testing_context,
67-
vec![
68-
InstructionTrigger::InitializeProgram(initialize_config),
69-
InstructionTrigger::CreateCctpRouterEndpoints,
70-
],
71-
)
72-
.await;
67+
let testing_engine = TestingEngine::new(testing_context).await;
7368

74-
testing_engine.execute().await;
69+
testing_engine
70+
.execute(vec![InstructionTrigger::InitializeProgram(
71+
initialize_config,
72+
)])
73+
.await;
7574
}
7675

7776
#[tokio::test]
@@ -112,19 +111,19 @@ pub async fn test_setup_vaas() {
112111

113112
testing_context.verify_vaas().await;
114113

115-
let testing_engine = TestingEngine::new(
116-
testing_context,
117-
vec![
114+
let testing_engine = TestingEngine::new(testing_context).await;
115+
testing_engine
116+
.execute(vec![
118117
InstructionTrigger::InitializeProgram(InitializeInstructionConfig::default()),
119-
InstructionTrigger::CreateCctpRouterEndpoints,
118+
InstructionTrigger::CreateCctpRouterEndpoints(
119+
CreateCctpRouterEndpointsInstructionConfig::default(),
120+
),
120121
InstructionTrigger::PlaceInitialOfferShimless(
121122
PlaceInitialOfferInstructionConfig::default(),
122123
),
123124
InstructionTrigger::ImproveOfferShimless(ImproveOfferInstructionConfig::default()),
124-
],
125-
)
126-
.await;
127-
testing_engine.execute().await;
125+
])
126+
.await;
128127
}
129128

130129
#[tokio::test]
@@ -380,7 +379,7 @@ pub async fn test_place_initial_offer_fallback() {
380379
None,
381380
)
382381
.await;
383-
let _initial_offer_fixture = place_initial_offer_fallback_test(
382+
let initial_offer_fixture = place_initial_offer_fallback_test(
384383
&mut testing_context,
385384
&auction_accounts,
386385
true, // Expected to pass
@@ -390,13 +389,17 @@ pub async fn test_place_initial_offer_fallback() {
390389

391390
// Attempt to improve the offer using the non-fallback method with another solver making the improved offer
392391
println!("Improving offer");
392+
let auction_state = initial_offer_fixture
393+
.expect("Failed to get initial offer fixture")
394+
.auction_state;
393395
let second_solver = testing_context.testing_actors.solvers[1].clone();
394396
improve_offer(
395397
&mut testing_context,
396398
PROGRAM_ID,
397399
second_solver,
398400
auction_config_address,
399401
500_000,
402+
&auction_state,
400403
None,
401404
)
402405
.await;
@@ -440,14 +443,19 @@ pub async fn test_place_initial_offer_shim_blocks_non_shim() {
440443
// Now test without the fallback program
441444
let mut auction_accounts = initial_offer_fallback_fixture.auction_accounts;
442445
auction_accounts.fast_vaa = Some(first_test_ft.get_vaa_pubkey());
446+
447+
let offer_price = 1__000_000;
448+
let transaction_error = TransactionError::AccountInUse;
443449
place_initial_offer_shimless(
444450
&mut testing_context,
445451
&auction_accounts,
446-
first_test_ft,
452+
&first_test_ft,
453+
offer_price,
447454
PROGRAM_ID,
448455
Some(&ExpectedError {
449456
instruction_index: 0,
450-
error: MatchingEngineError::AccountAlreadyInitialized,
457+
error_code: 0, // This is the error code for account in use
458+
error_string: transaction_error.to_string(),
451459
}), // Expected to fail
452460
)
453461
.await;
@@ -480,10 +488,12 @@ pub async fn test_place_initial_offer_non_shim_blocks_shim() {
480488
)
481489
.await;
482490
// Place initial offer using the shimless instruction
491+
let offer_price = 1__000_000;
483492
place_initial_offer_shimless(
484493
&mut testing_context,
485494
&auction_accounts,
486-
first_test_ft,
495+
&first_test_ft,
496+
offer_price,
487497
PROGRAM_ID,
488498
None, // Expected to pass
489499
)
@@ -585,17 +595,23 @@ pub async fn test_execute_order_shimless() {
585595
Some(first_test_fast_transfer_pubkey),
586596
)
587597
.await;
588-
place_initial_offer_shimless(
598+
let offer_price = 1__000_000;
599+
let auction_state = place_initial_offer_shimless(
589600
&mut testing_context,
590601
&auction_accounts,
591-
first_test_fast_transfer,
602+
&first_test_fast_transfer,
603+
offer_price,
592604
PROGRAM_ID,
593605
None, // Expected to pass
594606
)
595607
.await;
596-
597-
let execute_order_fixture =
598-
execute_order_shimless_test(&mut testing_context, &auction_accounts, true).await;
608+
let execute_order_fixture = execute_order_shimless_test(
609+
&mut testing_context,
610+
&auction_accounts,
611+
&auction_state,
612+
None,
613+
)
614+
.await;
599615
assert!(execute_order_fixture.is_some());
600616
}
601617
pub async fn test_execute_order_fallback_blocks_shimless() {
@@ -642,9 +658,19 @@ pub async fn test_execute_order_fallback_blocks_shimless() {
642658
)
643659
.await
644660
.expect("Failed to execute order");
645-
646-
let shimless_execute_order_fixture =
647-
execute_order_shimless_test(&mut testing_context, &auction_accounts, false).await;
661+
let auction_state = initial_offer_fallback_fixture.auction_state;
662+
let expected_error = Some(ExpectedError {
663+
instruction_index: 0,
664+
error_code: MatchingEngineError::AccountAlreadyInitialized.into(),
665+
error_string: MatchingEngineError::AccountAlreadyInitialized.to_string(),
666+
});
667+
let shimless_execute_order_fixture = execute_order_shimless_test(
668+
&mut testing_context,
669+
&auction_accounts,
670+
&auction_state,
671+
expected_error,
672+
)
673+
.await;
648674
assert!(shimless_execute_order_fixture.is_none());
649675
}
650676

@@ -713,7 +739,6 @@ pub async fn test_prepare_order_shim_fallback() {
713739
)
714740
.await
715741
.expect("Failed to execute order");
716-
717742
shimful::shims_prepare_order_response::prepare_order_response_test(
718743
&testing_context.test_context,
719744
&payer_signer,
@@ -769,11 +794,13 @@ pub async fn test_settle_auction_complete() {
769794
// Try making initial offer using the shim instruction
770795
let usdc_mint_address = testing_context.get_usdc_mint_address();
771796
let auction_config_address = initialize_fixture.get_auction_config_address();
797+
let router_config = CreateCctpRouterEndpointsInstructionConfig::default();
772798
let router_endpoints = create_all_router_endpoints_test(
773799
&testing_context,
774800
testing_context.testing_actors.owner.pubkey(),
775801
initialize_fixture.get_custodian_address(),
776802
testing_context.testing_actors.owner.keypair(),
803+
router_config.chains,
777804
)
778805
.await;
779806

@@ -833,8 +860,8 @@ pub async fn test_settle_auction_complete() {
833860
&execute_order_fixture,
834861
&initial_offer_fixture,
835862
&initialize_fixture,
836-
&router_endpoints.ethereum.endpoint_address,
837-
&router_endpoints.arbitrum.endpoint_address,
863+
&auction_accounts.to_router_endpoint,
864+
&auction_accounts.from_router_endpoint,
838865
&usdc_mint_address,
839866
&CCTP_MINT_RECIPIENT,
840867
&initialize_fixture.get_custodian_address(),

solana/programs/matching-engine/tests/shimful/shims.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::utils::auction::AuctionState;
2+
13
use super::super::utils;
24
use super::super::utils::setup::TestingContext;
35
use super::super::utils::{constants::*, setup::Solver};
@@ -413,7 +415,7 @@ fn generate_expected_guardian_signatures_info(
413415

414416
// TODO: Separate this into a different file
415417
pub struct PlaceInitialOfferShimFixture {
416-
pub auction_state: Rc<RefCell<utils::auction::ActiveAuctionState>>,
418+
pub auction_state: AuctionState,
417419
pub guardian_set_pubkey: Pubkey,
418420
pub guardian_signatures_pubkey: Pubkey,
419421
pub fast_market_order_address: Pubkey,
@@ -577,10 +579,9 @@ pub async fn place_initial_offer_fallback(
577579
offer_price,
578580
},
579581
};
580-
testing_context.testing_state.auction_state =
581-
utils::auction::AuctionState::Active(new_active_auction_state.clone());
582+
let new_auction_state = utils::auction::AuctionState::Active(new_active_auction_state);
582583
Some(PlaceInitialOfferShimFixture {
583-
auction_state: Rc::new(RefCell::new(new_active_auction_state)),
584+
auction_state: new_auction_state,
584585
guardian_set_pubkey,
585586
guardian_signatures_pubkey: guardian_signatures_pubkey.clone().to_owned(),
586587
fast_market_order_address: fast_market_order_account,
@@ -663,7 +664,7 @@ pub async fn close_fast_market_order_fallback(
663664

664665
pub fn create_fast_market_order_state_from_vaa_data(
665666
vaa_data: &utils::vaa::PostedVaaData,
666-
refund_recipient: Pubkey,
667+
close_account_refund_recipient: Pubkey,
667668
) -> (FastMarketOrderState, utils::vaa::PostedVaaData) {
668669
let vaa_data = utils::vaa::PostedVaaData {
669670
consistency_level: vaa_data.consistency_level,
@@ -711,7 +712,7 @@ pub fn create_fast_market_order_state_from_vaa_data(
711712
order.max_fee,
712713
order.init_auction_fee,
713714
redeemer_message_fixed_length,
714-
refund_recipient.to_bytes(),
715+
close_account_refund_recipient.to_bytes(),
715716
vaa_data.sequence,
716717
vaa_data.vaa_time,
717718
vaa_data.nonce,

solana/programs/matching-engine/tests/shimful/shims_execute_order.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ impl ExecuteOrderFallbackAccounts {
6161
fast_market_order_address: place_initial_offer_fixture.fast_market_order_address,
6262
active_auction: place_initial_offer_fixture
6363
.auction_state
64-
.borrow()
64+
.get_active_auction()
65+
.unwrap()
6566
.auction_address,
6667
active_auction_custody_token: place_initial_offer_fixture
6768
.auction_state
68-
.borrow()
69+
.get_active_auction()
70+
.unwrap()
6971
.auction_custody_token_address,
7072
active_auction_config: auction_accounts.auction_config,
7173
active_auction_best_offer_token: auction_accounts.offer_token,

solana/programs/matching-engine/tests/shimful/shims_prepare_order_response.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ pub async fn prepare_order_response_test(
307307
execute_order_fixture: &ExecuteOrderFallbackFixture,
308308
initial_offer_fixture: &PlaceInitialOfferShimFixture,
309309
initialize_fixture: &InitializeFixture,
310-
eth_endpoint_address: &Pubkey,
311-
arb_endpoint_address: &Pubkey,
310+
to_endpoint_address: &Pubkey,
311+
from_endpoint_address: &Pubkey,
312312
usdc_mint_address: &Pubkey,
313313
cctp_mint_recipient: &Pubkey,
314314
custodian_address: &Pubkey,
@@ -368,8 +368,8 @@ pub async fn prepare_order_response_test(
368368
&execute_order_fixture,
369369
&initial_offer_fixture,
370370
&initialize_fixture,
371-
&eth_endpoint_address,
372-
&arb_endpoint_address,
371+
&from_endpoint_address,
372+
&to_endpoint_address,
373373
&usdc_mint_address,
374374
&cctp_message_decoded,
375375
&guardian_set_pubkey,

0 commit comments

Comments
 (0)