Skip to content

Commit 0b4abb8

Browse files
author
Bengt Lofgren
committed
more negative tests added
1 parent 71927e1 commit 0b4abb8

24 files changed

+1799
-100
lines changed

solana/modules/matching-engine-testing/Cargo.toml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,37 @@ tracing-log = "0.2.0"
6161
once_cell = "1.8"
6262
anyhow = "1.0.97"
6363

64-
[lints]
65-
workspace = true
64+
[lints.clippy]
65+
correctness = { priority = -1, level = "warn"}
66+
inconsistent_digit_grouping = "allow"
67+
68+
### See clippy.toml.
69+
unnecessary_lazy_evaluations = "allow"
70+
or_fun_call = "warn"
71+
72+
arithmetic_side_effects = "allow"
73+
as_conversions = "allow"
74+
cast_abs_to_unsigned = "allow"
75+
cast_lossless= "allow"
76+
cast_possible_truncation = "allow"
77+
cast_possible_wrap = "allow"
78+
cast_precision_loss = "deny"
79+
cast_sign_loss = "deny"
80+
eq_op = "deny"
81+
expect_used = "deny"
82+
float_cmp = "deny"
83+
integer_division = "allow"
84+
large_futures = "deny"
85+
large_stack_arrays = "deny"
86+
large_stack_frames = "deny"
87+
lossy_float_literal = "deny"
88+
manual_slice_size_calculation = "deny"
89+
modulo_one = "deny"
90+
out_of_bounds_indexing = "deny"
91+
overflow_check_conditional = "deny"
92+
panic = "allow"
93+
recursive_format_impl = "deny"
94+
todo = "allow"
95+
unchecked_duration_subtraction = "allow"
96+
unreachable = "deny"
6697

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::testing_engine::config::{
33
};
44
use crate::testing_engine::setup::{TestingContext, TransferDirection};
55
use crate::testing_engine::state::TestingEngineState;
6-
use crate::utils::token_account::SplTokenEnum;
76

87
use super::super::utils;
98
use anchor_spl::token::spl_token;
@@ -107,7 +106,7 @@ pub async fn execute_order_fallback(
107106
let payer_signer = config
108107
.payer_signer
109108
.clone()
110-
.unwrap_or_else(|| testing_context.testing_actors.owner.keypair());
109+
.unwrap_or_else(|| testing_context.testing_actors.payer_signer.clone());
111110

112111
let execute_order_fallback_fixture = create_execute_order_fallback_fixture(
113112
testing_context,
@@ -190,11 +189,8 @@ pub fn create_execute_order_fallback_fixture(
190189
&POST_MESSAGE_SHIM_PROGRAM_ID,
191190
)
192191
.0;
193-
let solver = testing_context.testing_actors.solvers[config.solver_index].clone();
194-
let executor_token = solver
195-
.actor
196-
.token_account_address(&SplTokenEnum::Usdc)
197-
.unwrap();
192+
let solver = config.actor_enum.get_actor(&testing_context.testing_actors);
193+
let executor_token = solver.token_account_address(&config.token_enum).unwrap();
198194
ExecuteOrderFallbackFixture {
199195
cctp_message,
200196
post_message_sequence,
@@ -279,7 +275,7 @@ pub async fn execute_order_fallback_test(
279275
let payer_signer = config
280276
.payer_signer
281277
.clone()
282-
.unwrap_or_else(|| testing_context.testing_actors.owner.keypair());
278+
.unwrap_or_else(|| testing_context.testing_actors.payer_signer.clone());
283279
let execute_order_fallback_accounts =
284280
ExecuteOrderFallbackAccounts::new(current_state, &payer_signer.pubkey(), &fixture_accounts);
285281
execute_order_fallback(

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub async fn place_initial_offer_fallback(
4646
let payer_signer = config
4747
.payer_signer
4848
.clone()
49-
.unwrap_or_else(|| testing_context.testing_actors.owner.keypair());
49+
.unwrap_or_else(|| testing_context.testing_actors.payer_signer.clone());
5050
let close_account_refund_recipient = current_state
5151
.fast_market_order()
5252
.unwrap()
@@ -73,6 +73,7 @@ pub async fn place_initial_offer_fallback(
7373
let fast_market_order =
7474
create_fast_market_order_state_from_vaa_data(vaa_data, close_account_refund_recipient);
7575
let offer_price = config.offer_price;
76+
let actor_enum = config.actor;
7677
let offer_actor = config.actor.get_actor(&testing_context.testing_actors);
7778
let offer_token = match &config.custom_accounts {
7879
Some(custom_accounts) => match custom_accounts.offer_token_address {
@@ -186,11 +187,13 @@ pub async fn place_initial_offer_fallback(
186187
auction_custody_token_address,
187188
auction_config_address,
188189
initial_offer: utils::auction::AuctionOffer {
190+
actor: actor_enum,
189191
participant: payer_signer.pubkey(),
190192
offer_token,
191193
offer_price,
192194
},
193195
best_offer: utils::auction::AuctionOffer {
196+
actor: actor_enum,
194197
participant: payer_signer.pubkey(),
195198
offer_token,
196199
offer_price,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ pub async fn prepare_order_response_cctp_shim(
265265
Some(PrepareOrderResponseShimFixture {
266266
prepared_order_response: prepared_order_response_pda,
267267
prepared_custody_token: prepared_custody_token_pda,
268+
base_fee_token: accounts.base_fee_token,
268269
})
269270
} else {
270271
None
@@ -383,4 +384,5 @@ pub async fn prepare_order_response_test(
383384
pub struct PrepareOrderResponseShimFixture {
384385
pub prepared_order_response: Pubkey,
385386
pub prepared_custody_token: Pubkey,
387+
pub base_fee_token: Pubkey,
386388
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use solana_program_test::ProgramTestContext;
22
use solana_sdk::{
33
instruction::Instruction,
44
pubkey::Pubkey,
5-
signature::Signer,
5+
signature::{Keypair, Signer},
66
transaction::{Transaction, VersionedTransaction},
77
};
88

@@ -144,6 +144,7 @@ pub async fn initialize_program(
144144
testing_context: &TestingContext,
145145
test_context: &mut ProgramTestContext,
146146
auction_parameters_config: AuctionParametersConfig,
147+
payer_signer: &Keypair,
147148
expected_error: Option<&ExpectedError>,
148149
expected_log_messages: Option<&Vec<ExpectedLog>>,
149150
) -> Option<InitializeFixture> {
@@ -201,16 +202,15 @@ pub async fn initialize_program(
201202
data: ix_data.data(),
202203
};
203204
// Create and sign transaction
204-
let mut transaction =
205-
Transaction::new_with_payer(&[instruction], Some(&test_context.payer.pubkey()));
205+
let mut transaction = Transaction::new_with_payer(&[instruction], Some(&payer_signer.pubkey()));
206206
let new_blockhash = testing_context
207207
.get_new_latest_blockhash(test_context)
208208
.await
209209
.expect("Could not get new blockhash");
210210
transaction.sign(
211211
&[
212-
&test_context.payer,
213-
&testing_context.testing_actors.owner.keypair(),
212+
&payer_signer,
213+
&testing_context.testing_actors.owner.keypair().as_ref(),
214214
],
215215
new_blockhash,
216216
);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub async fn place_initial_offer_shimless(
5757
let payer_signer = config
5858
.payer_signer
5959
.clone()
60-
.unwrap_or_else(|| testing_context.testing_actors.owner.keypair());
60+
.unwrap_or_else(|| testing_context.testing_actors.payer_signer.clone());
6161
let offer_actor = config.actor.get_actor(&testing_context.testing_actors);
6262
let offer_token = offer_actor
6363
.token_account_address(&config.spl_token_enum)
@@ -253,11 +253,13 @@ pub async fn place_initial_offer_shimless(
253253
auction_custody_token_address,
254254
auction_config_address,
255255
initial_offer: AuctionOffer {
256+
actor: config.actor,
256257
participant: payer_signer.pubkey(),
257258
offer_token,
258259
offer_price: initial_offer_ix.offer_price,
259260
},
260261
best_offer: AuctionOffer {
262+
actor: config.actor,
261263
participant: payer_signer.pubkey(),
262264
offer_token,
263265
offer_price: initial_offer_ix.offer_price,
@@ -397,6 +399,7 @@ pub async fn improve_offer(
397399
auction_config_address: auction_config,
398400
initial_offer: initial_offer.clone(),
399401
best_offer: AuctionOffer {
402+
actor: config.actor,
400403
participant: payer_signer.pubkey(),
401404
offer_token,
402405
offer_price,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
pub mod execute_order;
44
pub mod initialize;
55
pub mod make_offer;
6+
pub mod pause_custodian;
67
pub mod prepare_order_response;
78
pub mod settle_auction;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use std::rc::Rc;
2+
3+
use crate::testing_engine::config::ExpectedError;
4+
5+
use crate::testing_engine::state::TestingEngineState;
6+
7+
use anchor_lang::prelude::*;
8+
use anchor_lang::InstructionData;
9+
use matching_engine::accounts::AdminMut;
10+
11+
use crate::testing_engine::setup::TestingContext;
12+
13+
use matching_engine::accounts::SetPause as SetPauseAccounts;
14+
use matching_engine::instruction::SetPause as SetPauseIx;
15+
use solana_program_test::ProgramTestContext;
16+
use solana_sdk::instruction::Instruction;
17+
use solana_sdk::signature::Keypair;
18+
use solana_sdk::signature::Signer;
19+
use solana_sdk::transaction::Transaction;
20+
21+
/// Pause the custodian
22+
///
23+
/// # Arguments
24+
///
25+
/// * `test_context` - The test context
26+
/// * `current_state` - The current state
27+
/// * `config` - The config
28+
///
29+
/// # Returns
30+
///
31+
/// The new paused state
32+
pub async fn set_pause(
33+
test_context: &mut ProgramTestContext,
34+
testing_context: &TestingContext,
35+
current_state: &TestingEngineState,
36+
owner_or_assistant: &Rc<Keypair>,
37+
expected_error: Option<&ExpectedError>,
38+
is_paused: bool,
39+
) -> TestingEngineState {
40+
let custodian_address = current_state.initialized().unwrap().custodian_address;
41+
let admin_mut = AdminMut {
42+
owner_or_assistant: owner_or_assistant.pubkey(),
43+
custodian: custodian_address,
44+
};
45+
let accounts = SetPauseAccounts { admin: admin_mut };
46+
let instruction_data = SetPauseIx { pause: is_paused }.data();
47+
let instruction = Instruction {
48+
program_id: testing_context.get_matching_engine_program_id(),
49+
accounts: accounts.to_account_metas(None),
50+
data: instruction_data,
51+
};
52+
let transaction = Transaction::new_signed_with_payer(
53+
&[instruction],
54+
Some(&owner_or_assistant.pubkey()),
55+
&[&owner_or_assistant],
56+
test_context.last_blockhash,
57+
);
58+
testing_context
59+
.execute_and_verify_transaction(test_context, transaction, expected_error)
60+
.await;
61+
62+
let new_auction_state = current_state.auction_state().set_pause(is_paused);
63+
64+
let expect_msg = format!(
65+
"Failed to set {} auction state",
66+
if is_paused { "pause" } else { "unpause" }
67+
);
68+
current_state
69+
.set_auction_state(new_auction_state)
70+
.expect(&expect_msg)
71+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use wormhole_svm_definitions::EVENT_AUTHORITY_SEED;
2828
pub struct PrepareOrderResponseFixture {
2929
pub prepared_order_response: Pubkey,
3030
pub prepared_custody_token: Pubkey,
31+
pub base_fee_token: Pubkey,
3132
}
3233

3334
/// Prepare an order response (shimless)
@@ -239,6 +240,7 @@ pub async fn prepare_order_response(
239240
Some(PrepareOrderResponseFixture {
240241
prepared_order_response: prepared_order_response_pda,
241242
prepared_custody_token: prepared_custody_token_pda,
243+
base_fee_token: *base_fee_token_address,
242244
})
243245
} else {
244246
None

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::testing_engine::config::ExpectedError;
22
use crate::testing_engine::setup::TestingContext;
3+
use crate::testing_engine::state::OrderPreparedState;
4+
use crate::testing_engine::state::TestingEngineState;
35
use crate::utils::auction::AuctionState;
46

57
use anchor_lang::prelude::*;
@@ -33,27 +35,34 @@ use wormhole_svm_definitions::EVENT_AUTHORITY_SEED;
3335
/// The new auction state if successful, otherwise the old auction state
3436
pub async fn settle_auction_complete(
3537
testing_context: &TestingContext,
38+
current_state: &TestingEngineState,
3639
test_context: &mut ProgramTestContext,
3740
payer_signer: &Rc<Keypair>,
38-
auction_state: &AuctionState,
39-
prepare_order_response_address: &Pubkey,
40-
prepared_custody_token: &Pubkey,
4141
expected_error: Option<&ExpectedError>,
4242
) -> AuctionState {
43+
let auction_state = current_state.auction_state();
44+
let order_prepared_state = current_state
45+
.order_prepared()
46+
.expect("Order prepared not found");
47+
let OrderPreparedState {
48+
prepared_order_response_address,
49+
prepared_custody_token,
50+
base_fee_token,
51+
actor_enum: _,
52+
} = *order_prepared_state;
53+
4354
let matching_engine_program_id = testing_context.get_matching_engine_program_id();
44-
let usdc_mint_address = &testing_context.get_usdc_mint_address();
4555
let active_auction = auction_state
4656
.get_active_auction()
4757
.expect("Failed to get active auction");
48-
let base_fee_token = *usdc_mint_address;
4958
let event_seeds = EVENT_AUTHORITY_SEED;
5059
let event_authority =
5160
Pubkey::find_program_address(&[event_seeds], &matching_engine_program_id).0;
5261
let settle_auction_accounts = SettleAuctionCompleteCpiAccounts {
5362
beneficiary: payer_signer.pubkey(),
5463
base_fee_token,
55-
prepared_order_response: *prepare_order_response_address,
56-
prepared_custody_token: *prepared_custody_token,
64+
prepared_order_response: prepared_order_response_address,
65+
prepared_custody_token,
5766
auction: active_auction.auction_address,
5867
best_offer_token: active_auction.best_offer.offer_token,
5968
token_program: spl_token::ID,

0 commit comments

Comments
 (0)