Skip to content

Commit 4a20154

Browse files
author
Bengt Lofgren
committed
more docs
1 parent ffc050a commit 4a20154

File tree

13 files changed

+489
-177
lines changed

13 files changed

+489
-177
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![allow(clippy::expect_used)]
2-
#![allow(dead_code)]
32
#![allow(clippy::panic)]
43

54
use anchor_lang::AccountDeserialize;
@@ -108,8 +107,12 @@ pub async fn test_setup_vaas() {
108107
post_vaa: true,
109108
..VaaArgs::default()
110109
};
111-
let (testing_context, mut test_context) =
112-
setup_environment(ShimMode::PostVaa, transfer_direction, Some(vaa_args)).await;
110+
let (testing_context, mut test_context) = setup_environment(
111+
ShimMode::VerifySignature,
112+
transfer_direction,
113+
Some(vaa_args),
114+
)
115+
.await;
113116

114117
testing_context.verify_vaas(&mut test_context).await;
115118

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ pub async fn execute_order_fallback_test(
232232
active_auction_state,
233233
&testing_context.testing_actors.owner.pubkey(),
234234
&fixture_accounts,
235-
testing_context.testing_state.transfer_direction,
235+
testing_context.initial_testing_state.transfer_direction,
236236
);
237237
execute_order_fallback(
238238
testing_context,

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct PrepareOrderResponseShimAccountsFixture {
5353
}
5454

5555
impl PrepareOrderResponseShimAccountsFixture {
56-
#[allow(clippy::too_many_arguments)]
56+
#[allow(clippy::too_many_arguments)] // TODO: fix this (10/7)
5757
pub fn new(
5858
signer: &Pubkey,
5959
fixture_accounts: &FixtureAccounts,
@@ -304,16 +304,17 @@ pub async fn prepare_order_response_test(
304304
.await
305305
.unwrap();
306306

307-
let source_remote_token_messenger = match testing_context.testing_state.transfer_direction {
308-
TransferDirection::FromEthereumToArbitrum => {
309-
utils::router::get_remote_token_messenger(
310-
test_context,
311-
fixture_accounts.ethereum_remote_token_messenger,
312-
)
313-
.await
314-
}
315-
_ => panic!("Unsupported transfer direction"),
316-
};
307+
let source_remote_token_messenger =
308+
match testing_context.initial_testing_state.transfer_direction {
309+
TransferDirection::FromEthereumToArbitrum => {
310+
utils::router::get_remote_token_messenger(
311+
test_context,
312+
fixture_accounts.ethereum_remote_token_messenger,
313+
)
314+
.await
315+
}
316+
_ => panic!("Unsupported transfer direction"),
317+
};
317318
let cctp_nonce = deposit.cctp_nonce;
318319

319320
let message_transmitter_config_pubkey = fixture_accounts.message_transmitter_config;
@@ -366,7 +367,7 @@ pub async fn prepare_order_response_test(
366367
usdc_mint_address,
367368
&cctp_message_decoded,
368369
&guardian_signature_info,
369-
&testing_context.testing_state.transfer_direction,
370+
&testing_context.initial_testing_state.transfer_direction,
370371
);
371372
super::shims_prepare_order_response::prepare_order_response_cctp_shim(
372373
testing_context,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub fn create_execute_order_shimless_accounts(
106106
Pubkey::find_program_address(&[b"message_transmitter"], &MESSAGE_TRANSMITTER_PROGRAM_ID).0;
107107
let token_messenger =
108108
Pubkey::find_program_address(&[b"token_messenger"], &TOKEN_MESSENGER_MINTER_PROGRAM_ID).0;
109-
let remote_token_messenger = match testing_context.testing_state.transfer_direction {
109+
let remote_token_messenger = match testing_context.initial_testing_state.transfer_direction {
110110
TransferDirection::FromEthereumToArbitrum => {
111111
fixture_accounts.arbitrum_remote_token_messenger
112112
}

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,17 @@ pub async fn prepare_order_response(
5050
.clone()
5151
.expect("Fixture accounts not found");
5252

53-
let source_remote_token_messenger = match testing_context.testing_state.transfer_direction {
54-
TransferDirection::FromEthereumToArbitrum => {
55-
utils::router::get_remote_token_messenger(
56-
test_context,
57-
fixture_accounts.ethereum_remote_token_messenger,
58-
)
59-
.await
60-
}
61-
_ => panic!("Unsupported transfer direction"),
62-
};
53+
let source_remote_token_messenger =
54+
match testing_context.initial_testing_state.transfer_direction {
55+
TransferDirection::FromEthereumToArbitrum => {
56+
utils::router::get_remote_token_messenger(
57+
test_context,
58+
fixture_accounts.ethereum_remote_token_messenger,
59+
)
60+
.await
61+
}
62+
_ => panic!("Unsupported transfer direction"),
63+
};
6364

6465
let message_transmitter_config_pubkey = fixture_accounts.message_transmitter_config;
6566
let custodian_address = testing_engine_state
@@ -144,7 +145,8 @@ pub async fn prepare_order_response(
144145
};
145146
let cctp_message_transmitter_event_authority =
146147
Pubkey::find_program_address(&[EVENT_AUTHORITY_SEED], &MESSAGE_TRANSMITTER_PROGRAM_ID).0;
147-
let cctp_remote_token_messenger = match testing_context.testing_state.transfer_direction {
148+
let cctp_remote_token_messenger = match testing_context.initial_testing_state.transfer_direction
149+
{
148150
TransferDirection::FromEthereumToArbitrum => {
149151
fixture_accounts.ethereum_remote_token_messenger
150152
}

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,33 @@ use crate::{shimless::initialize::AuctionParametersConfig, utils::Chain};
44
use anchor_lang::prelude::*;
55
use solana_sdk::signature::Keypair;
66

7+
pub trait InstructionConfig: Default {
8+
fn expected_error(&self) -> Option<&ExpectedError>;
9+
}
10+
11+
/// A type alias for an optional value that overwrites the current state
712
pub type OverwriteCurrentState<T> = Option<T>;
813

14+
/// A struct representing an expected error
15+
///
16+
/// # Fields
17+
///
18+
/// * `instruction_index` - The index of the instruction that is expected to error
19+
/// * `error_code` - The error code that is expected to be returned
20+
/// * `error_string` - The error string that is expected to be returned
921
#[derive(Clone)]
1022
pub struct ExpectedError {
1123
pub instruction_index: u8,
1224
pub error_code: u32,
1325
pub error_string: String,
1426
}
1527

28+
/// A struct representing an expected log
29+
///
30+
/// # Fields
31+
///
32+
/// * `log_message` - The log message that is expected to be returned
33+
/// * `count` - The number of times the log message is expected to appear
1634
#[derive(Clone)]
1735
pub struct ExpectedLog {
1836
pub log_message: String,
@@ -25,6 +43,11 @@ pub struct InitializeInstructionConfig {
2543
pub expected_error: Option<ExpectedError>,
2644
}
2745

46+
impl InstructionConfig for InitializeInstructionConfig {
47+
fn expected_error(&self) -> Option<&ExpectedError> {
48+
self.expected_error.as_ref()
49+
}
50+
}
2851
pub struct CreateCctpRouterEndpointsInstructionConfig {
2952
pub chains: HashSet<Chain>,
3053
pub payer_signer: Option<Rc<Keypair>>,
@@ -42,6 +65,13 @@ impl Default for CreateCctpRouterEndpointsInstructionConfig {
4265
}
4366
}
4467
}
68+
69+
impl InstructionConfig for CreateCctpRouterEndpointsInstructionConfig {
70+
fn expected_error(&self) -> Option<&ExpectedError> {
71+
self.expected_error.as_ref()
72+
}
73+
}
74+
4575
#[derive(Clone, Default)]
4676
pub struct InitializeFastMarketOrderShimInstructionConfig {
4777
pub fast_market_order_id: u32,
@@ -50,6 +80,12 @@ pub struct InitializeFastMarketOrderShimInstructionConfig {
5080
pub expected_error: Option<ExpectedError>,
5181
}
5282

83+
impl InstructionConfig for InitializeFastMarketOrderShimInstructionConfig {
84+
fn expected_error(&self) -> Option<&ExpectedError> {
85+
self.expected_error.as_ref()
86+
}
87+
}
88+
5389
#[derive(Clone, Default)]
5490
pub struct PrepareOrderInstructionConfig {
5591
pub fast_market_order_address: OverwriteCurrentState<Pubkey>,
@@ -59,6 +95,12 @@ pub struct PrepareOrderInstructionConfig {
5995
pub expected_log_messages: Option<Vec<ExpectedLog>>,
6096
}
6197

98+
impl InstructionConfig for PrepareOrderInstructionConfig {
99+
fn expected_error(&self) -> Option<&ExpectedError> {
100+
self.expected_error.as_ref()
101+
}
102+
}
103+
62104
#[derive(Clone, Default)]
63105
pub struct ExecuteOrderInstructionConfig {
64106
pub fast_market_order_address: OverwriteCurrentState<Pubkey>,
@@ -67,19 +109,37 @@ pub struct ExecuteOrderInstructionConfig {
67109
pub expected_error: Option<ExpectedError>,
68110
}
69111

112+
impl InstructionConfig for ExecuteOrderInstructionConfig {
113+
fn expected_error(&self) -> Option<&ExpectedError> {
114+
self.expected_error.as_ref()
115+
}
116+
}
117+
70118
#[derive(Clone, Default)]
71119
pub struct SettleAuctionInstructionConfig {
72120
pub payer_signer: Option<Rc<Keypair>>,
73121
pub expected_error: Option<ExpectedError>,
74122
}
75123

124+
impl InstructionConfig for SettleAuctionInstructionConfig {
125+
fn expected_error(&self) -> Option<&ExpectedError> {
126+
self.expected_error.as_ref()
127+
}
128+
}
129+
76130
#[derive(Clone, Default)]
77131
pub struct CloseFastMarketOrderShimInstructionConfig {
78132
pub close_account_refund_recipient_keypair: Option<Rc<Keypair>>, // If none, will use the solver 0 keypair
79133
pub fast_market_order_address: OverwriteCurrentState<Pubkey>, // If none, will use the fast market order address from the current state
80134
pub expected_error: Option<ExpectedError>,
81135
}
82136

137+
impl InstructionConfig for CloseFastMarketOrderShimInstructionConfig {
138+
fn expected_error(&self) -> Option<&ExpectedError> {
139+
self.expected_error.as_ref()
140+
}
141+
}
142+
83143
pub struct PlaceInitialOfferInstructionConfig {
84144
pub solver_index: usize,
85145
pub offer_price: u64,
@@ -100,6 +160,12 @@ impl Default for PlaceInitialOfferInstructionConfig {
100160
}
101161
}
102162

163+
impl InstructionConfig for PlaceInitialOfferInstructionConfig {
164+
fn expected_error(&self) -> Option<&ExpectedError> {
165+
self.expected_error.as_ref()
166+
}
167+
}
168+
103169
pub struct ImproveOfferInstructionConfig {
104170
pub solver_index: usize,
105171
pub offer_price: u64,
@@ -117,3 +183,9 @@ impl Default for ImproveOfferInstructionConfig {
117183
}
118184
}
119185
}
186+
187+
impl InstructionConfig for ImproveOfferInstructionConfig {
188+
fn expected_error(&self) -> Option<&ExpectedError> {
189+
self.expected_error.as_ref()
190+
}
191+
}

0 commit comments

Comments
 (0)