Skip to content

Commit 6d6e91b

Browse files
author
Bengt Lofgren
committed
removed Rc<RefCell<>>
1 parent e0a036f commit 6d6e91b

22 files changed

+404
-309
lines changed

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

Lines changed: 99 additions & 58 deletions
Large diffs are not rendered by default.

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use matching_engine::fallback::initialise_fast_market_order::{
1515
};
1616

1717
use matching_engine::state::{FastMarketOrder as FastMarketOrderState, FastMarketOrderParams};
18+
use solana_program_test::ProgramTestContext;
1819
use solana_sdk::transaction::VersionedTransaction;
1920
use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer, transaction::Transaction};
2021
use std::rc::Rc;
@@ -39,6 +40,7 @@ use wormhole_io::TypePrefixedPayload;
3940
/// * The expected error, if any, is reached when executing the instruction
4041
pub async fn initialise_fast_market_order_fallback(
4142
testing_context: &TestingContext,
43+
test_context: &mut ProgramTestContext,
4244
payer_signer: &Rc<Keypair>,
4345
fast_market_order: FastMarketOrderState,
4446
guardian_set_pubkey: Pubkey,
@@ -55,7 +57,10 @@ pub async fn initialise_fast_market_order_fallback(
5557
guardian_signatures_pubkey,
5658
guardian_set_bump,
5759
);
58-
let recent_blockhash = testing_context.test_context.borrow().last_blockhash;
60+
let recent_blockhash = testing_context
61+
.get_new_latest_blockhash(test_context)
62+
.await
63+
.unwrap();
5964
let transaction = solana_sdk::transaction::Transaction::new_signed_with_payer(
6065
&[initialise_fast_market_order_ix],
6166
Some(&payer_signer.pubkey()),
@@ -64,7 +69,7 @@ pub async fn initialise_fast_market_order_fallback(
6469
);
6570
let versioned_transaction = VersionedTransaction::from(transaction);
6671
testing_context
67-
.execute_and_verify_transaction(versioned_transaction, expected_error)
72+
.execute_and_verify_transaction(test_context, versioned_transaction, expected_error)
6873
.await;
6974
}
7075

@@ -135,13 +140,14 @@ fn initialise_fast_market_order_fallback_instruction(
135140
/// * The expected error, if any, is reached when executing the instruction
136141
pub async fn close_fast_market_order_fallback(
137142
testing_context: &TestingContext,
143+
test_context: &mut ProgramTestContext,
138144
refund_recipient_keypair: &Rc<Keypair>,
139145
fast_market_order_address: &Pubkey,
140146
expected_error: Option<&ExpectedError>,
141147
) {
142148
let program_id = &testing_context.get_matching_engine_program_id();
143149
let recent_blockhash = testing_context
144-
.get_new_latest_blockhash()
150+
.get_new_latest_blockhash(test_context)
145151
.await
146152
.expect("Failed to get new blockhash");
147153
let close_fast_market_order_ix = CloseFastMarketOrderFallback {
@@ -160,7 +166,7 @@ pub async fn close_fast_market_order_fallback(
160166
recent_blockhash,
161167
);
162168
testing_context
163-
.execute_and_verify_transaction(transaction, expected_error)
169+
.execute_and_verify_transaction(test_context, transaction, expected_error)
164170
.await;
165171
}
166172

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::utils::{constants::*, setup::TestingContext};
22

3+
use solana_program_test::ProgramTestContext;
34
use solana_sdk::{
45
compute_budget::ComputeBudgetInstruction,
56
hash::Hash,
@@ -51,11 +52,12 @@ impl BumpCosts {
5152
/// * `emitter_signer` - The emitter signer keypair
5253
pub async fn set_up_post_message_transaction_test(
5354
testing_context: &TestingContext,
55+
test_context: &mut ProgramTestContext,
5456
payer_signer: &Rc<Keypair>,
5557
emitter_signer: &Rc<Keypair>,
5658
) {
5759
let recent_blockhash = testing_context
58-
.get_new_latest_blockhash()
60+
.get_new_latest_blockhash(test_context)
5961
.await
6062
.expect("Could not get last blockhash");
6163
let (transaction, _bump_costs) = set_up_post_message_transaction(
@@ -65,14 +67,11 @@ pub async fn set_up_post_message_transaction_test(
6567
recent_blockhash,
6668
);
6769
let details = {
68-
let test_ctx = &testing_context.test_context;
69-
let mut ctx = test_ctx.borrow_mut();
70-
let out = ctx
70+
let out = test_context
7171
.banks_client
7272
.simulate_transaction(transaction)
7373
.await
7474
.unwrap();
75-
drop(ctx);
7675
assert!(out.result.clone().unwrap().is_ok(), "{:?}", out.result);
7776
out.simulation_details.unwrap()
7877
};

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use common::wormhole_cctp_solana::cctp::{
88
MESSAGE_TRANSMITTER_PROGRAM_ID, TOKEN_MESSENGER_MINTER_PROGRAM_ID,
99
};
1010
use matching_engine::fallback::execute_order::{ExecuteOrderCctpShim, ExecuteOrderShimAccounts};
11+
use solana_program_test::ProgramTestContext;
1112
use solana_sdk::{
1213
pubkey::Pubkey, signature::Keypair, signer::Signer, sysvar::SysvarId, transaction::Transaction,
1314
};
@@ -91,14 +92,14 @@ pub struct ExecuteOrderFallbackFixtureAccounts {
9192

9293
pub async fn execute_order_fallback(
9394
testing_context: &TestingContext,
95+
test_context: &mut ProgramTestContext,
9496
payer_signer: &Rc<Keypair>,
9597
program_id: &Pubkey,
9698
solver: Solver,
9799
execute_order_fallback_accounts: &ExecuteOrderFallbackAccounts,
98100
expected_error: Option<&ExpectedError>,
99101
) -> Option<ExecuteOrderFallbackFixture> {
100102
// Get target chain and use as remote address
101-
let test_ctx = &testing_context.test_context;
102103
let cctp_message = Pubkey::find_program_address(
103104
&[
104105
common::CCTP_MESSAGE_SEED_PREFIX,
@@ -181,16 +182,19 @@ pub async fn execute_order_fallback(
181182
.instruction();
182183

183184
// Considering fast forwarding blocks here for deadline to be reached
184-
let recent_blockhash = test_ctx.borrow().last_blockhash;
185-
utils::setup::fast_forward_slots(testing_context, 3).await;
185+
let recent_blockhash = testing_context
186+
.get_new_latest_blockhash(test_context)
187+
.await
188+
.unwrap();
189+
utils::setup::fast_forward_slots(test_context, 3).await;
186190
let transaction = Transaction::new_signed_with_payer(
187191
&[execute_order_ix],
188192
Some(&payer_signer.pubkey()),
189193
&[&payer_signer],
190194
recent_blockhash,
191195
);
192196
testing_context
193-
.execute_and_verify_transaction(transaction, expected_error)
197+
.execute_and_verify_transaction(test_context, transaction, expected_error)
194198
.await;
195199
if expected_error.is_none() {
196200
Some(ExecuteOrderFallbackFixture {
@@ -212,6 +216,7 @@ pub async fn execute_order_fallback(
212216

213217
pub async fn execute_order_fallback_test(
214218
testing_context: &TestingContext,
219+
test_context: &mut ProgramTestContext,
215220
auction_accounts: &utils::auction::AuctionAccounts,
216221
fast_market_order_address: &Pubkey,
217222
active_auction_state: &ActiveAuctionState,
@@ -231,6 +236,7 @@ pub async fn execute_order_fallback_test(
231236
);
232237
execute_order_fallback(
233238
testing_context,
239+
test_context,
234240
&testing_context.testing_actors.owner.keypair(),
235241
&testing_context.get_matching_engine_program_id(),
236242
solver,

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use matching_engine::fallback::place_initial_offer::{
1010
PlaceInitialOfferCctpShimData as PlaceInitialOfferCctpShimFallbackData,
1111
};
1212
use matching_engine::state::Auction;
13+
use solana_program_test::ProgramTestContext;
1314

1415
use super::fast_market_order_shim::create_fast_market_order_state_from_vaa_data;
1516
use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer, transaction::Transaction};
@@ -39,6 +40,7 @@ use std::rc::Rc;
3940
#[allow(clippy::too_many_arguments)]
4041
pub async fn place_initial_offer_fallback(
4142
testing_context: &TestingContext,
43+
test_context: &mut ProgramTestContext,
4244
payer_signer: &Rc<Keypair>,
4345
vaa_data: &utils::vaa::PostedVaaData,
4446
solver: Solver,
@@ -48,7 +50,6 @@ pub async fn place_initial_offer_fallback(
4850
expected_error: Option<&ExpectedError>,
4951
) -> Option<InitialOfferPlacedState> {
5052
let program_id = testing_context.get_matching_engine_program_id();
51-
let test_ctx = &testing_context.test_context;
5253
let fast_market_order = create_fast_market_order_state_from_vaa_data(vaa_data, solver.pubkey());
5354

5455
let auction_address = Pubkey::find_program_address(
@@ -77,10 +78,10 @@ pub async fn place_initial_offer_fallback(
7778
.0;
7879

7980
solver
80-
.approve_usdc(test_ctx, &transfer_authority, 420_000__000_000)
81+
.approve_usdc(test_context, &transfer_authority, 420_000__000_000)
8182
.await;
8283

83-
let solver_usdc_balance_before = solver.get_balance(test_ctx).await;
84+
let solver_usdc_balance_before = solver.get_balance(test_context).await;
8485

8586
let place_initial_offer_ix_data = PlaceInitialOfferCctpShimFallbackData::new(offer_price);
8687

@@ -106,7 +107,10 @@ pub async fn place_initial_offer_fallback(
106107
}
107108
.instruction();
108109

109-
let recent_blockhash = test_ctx.borrow().last_blockhash;
110+
let recent_blockhash = testing_context
111+
.get_new_latest_blockhash(test_context)
112+
.await
113+
.unwrap();
110114

111115
let transaction = Transaction::new_signed_with_payer(
112116
&[place_initial_offer_ix],
@@ -116,10 +120,10 @@ pub async fn place_initial_offer_fallback(
116120
);
117121

118122
testing_context
119-
.execute_and_verify_transaction(transaction, expected_error)
123+
.execute_and_verify_transaction(test_context, transaction, expected_error)
120124
.await;
121125
if expected_error.is_none() {
122-
let solver_usdc_balance_after = solver.get_balance(test_ctx).await;
126+
let solver_usdc_balance_after = solver.get_balance(test_context).await;
123127
assert!(
124128
solver_usdc_balance_after < solver_usdc_balance_before,
125129
"Solver USDC balance should have decreased"

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use matching_engine::fallback::prepare_order_response::{
1616
};
1717
use matching_engine::state::{FastMarketOrder as FastMarketOrderState, PreparedOrderResponse};
1818
use matching_engine::CCTP_MINT_RECIPIENT;
19+
use solana_program_test::ProgramTestContext;
1920
use solana_sdk::signature::Keypair;
2021
use solana_sdk::signer::Signer;
2122
use solana_sdk::transaction::Transaction;
@@ -171,13 +172,13 @@ impl PrepareOrderResponseShimDataFixture {
171172

172173
pub async fn prepare_order_response_cctp_shim(
173174
testing_context: &TestingContext,
175+
test_context: &mut ProgramTestContext,
174176
payer_signer: &Rc<Keypair>,
175177
accounts: PrepareOrderResponseShimAccountsFixture,
176178
data: PrepareOrderResponseShimDataFixture,
177179
matching_engine_program_id: &Pubkey,
178180
expected_error: Option<&ExpectedError>,
179181
) -> Option<PrepareOrderResponseShimFixture> {
180-
let test_ctx = &testing_context.test_context;
181182
let fast_market_order_digest = data.fast_market_order.digest();
182183
let prepared_order_response_seeds = [
183184
PreparedOrderResponse::SEED_PREFIX,
@@ -247,9 +248,8 @@ pub async fn prepare_order_response_cctp_shim(
247248
}
248249
.instruction();
249250

250-
let recent_blockhash = test_ctx
251-
.borrow_mut()
252-
.get_new_latest_blockhash()
251+
let recent_blockhash = testing_context
252+
.get_new_latest_blockhash(test_context)
253253
.await
254254
.expect("Failed to get new latest blockhash");
255255
let transaction = Transaction::new_signed_with_payer(
@@ -259,7 +259,7 @@ pub async fn prepare_order_response_cctp_shim(
259259
recent_blockhash,
260260
);
261261
testing_context
262-
.execute_and_verify_transaction(transaction, expected_error)
262+
.execute_and_verify_transaction(test_context, transaction, expected_error)
263263
.await;
264264
if expected_error.is_none() {
265265
Some(PrepareOrderResponseShimFixture {
@@ -274,6 +274,7 @@ pub async fn prepare_order_response_cctp_shim(
274274
#[allow(clippy::too_many_arguments)]
275275
pub async fn prepare_order_response_test(
276276
testing_context: &TestingContext,
277+
test_context: &mut ProgramTestContext,
277278
payer_signer: &Rc<Keypair>,
278279
deposit_vaa_data: &utils::vaa::PostedVaaData,
279280
testing_engine_state: &TestingEngineState,
@@ -282,7 +283,6 @@ pub async fn prepare_order_response_test(
282283
deposit: &Deposit,
283284
expected_error: Option<&ExpectedError>,
284285
) -> Option<PrepareOrderResponseShimFixture> {
285-
let test_ctx = &testing_context.test_context;
286286
let core_bridge_program_id = &testing_context.get_wormhole_program_id();
287287
let matching_engine_program_id = &testing_context.get_matching_engine_program_id();
288288
let usdc_mint_address = &testing_context.get_usdc_mint_address();
@@ -296,6 +296,7 @@ pub async fn prepare_order_response_test(
296296
let (guardian_set_pubkey, guardian_signatures_pubkey, guardian_set_bump) =
297297
super::verify_shim::create_guardian_signatures(
298298
testing_context,
299+
test_context,
299300
payer_signer,
300301
deposit_vaa_data,
301302
core_bridge_program_id,
@@ -307,7 +308,7 @@ pub async fn prepare_order_response_test(
307308
let source_remote_token_messenger = match testing_context.testing_state.transfer_direction {
308309
TransferDirection::FromEthereumToArbitrum => {
309310
utils::router::get_remote_token_messenger(
310-
testing_context,
311+
test_context,
311312
fixture_accounts.ethereum_remote_token_messenger,
312313
)
313314
.await
@@ -326,7 +327,7 @@ pub async fn prepare_order_response_test(
326327
.expect("Custodian address not found");
327328
// TODO: Make checks to see if fast market order sender matches cctp message sender ...
328329
let cctp_token_burn_message = utils::cctp_message::craft_cctp_token_burn_message(
329-
test_ctx,
330+
test_context,
330331
source_remote_token_messenger.domain,
331332
cctp_nonce,
332333
deposit.amount,
@@ -371,6 +372,7 @@ pub async fn prepare_order_response_test(
371372
);
372373
super::shims_prepare_order_response::prepare_order_response_cctp_shim(
373374
testing_context,
375+
test_context,
374376
payer_signer,
375377
prepare_order_response_cctp_shim_accounts,
376378
prepare_order_response_cctp_shim_data,

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::utils::{self, setup::TestingContext};
33
use anchor_lang::prelude::*;
44
use anyhow::Result as AnyhowResult;
55

6+
use solana_program_test::ProgramTestContext;
67
use solana_sdk::{
78
compute_budget::ComputeBudgetInstruction,
89
hash::Hash,
@@ -33,6 +34,7 @@ use wormhole_svm_shim::verify_vaa;
3334
/// * `(guardian_set_pubkey, guardian_signatures_pubkey, guardian_set_bump)` - The guardian set pubkey, the guardian signatures pubkey and the guardian set bump
3435
pub async fn create_guardian_signatures(
3536
testing_context: &TestingContext,
37+
test_context: &mut ProgramTestContext,
3638
payer_signer: &Rc<Keypair>,
3739
vaa_data: &utils::vaa::PostedVaaData,
3840
wormhole_program_id: &Pubkey,
@@ -49,6 +51,7 @@ pub async fn create_guardian_signatures(
4951
let guardian_set_signatures = vaa_data.sign_with_guardian_key(&guardian_secret_key, 0);
5052
let guardian_signatures_pubkey = add_guardian_signatures_account(
5153
testing_context,
54+
test_context,
5255
payer_signer,
5356
guardian_signature_signer,
5457
vec![guardian_set_signatures],
@@ -79,12 +82,15 @@ pub async fn create_guardian_signatures(
7982
/// * `guardian_signatures_pubkey` - The guardian signatures pubkey
8083
async fn add_guardian_signatures_account(
8184
testing_context: &TestingContext,
85+
test_context: &mut ProgramTestContext,
8286
payer_signer: &Rc<Keypair>,
8387
signatures_signer: &Rc<Keypair>,
8488
guardian_signatures: Vec<[u8; GUARDIAN_SIGNATURE_LENGTH]>,
8589
guardian_set_index: u32,
8690
) -> AnyhowResult<Pubkey> {
87-
let new_blockhash = testing_context.get_new_latest_blockhash().await?;
91+
let new_blockhash = testing_context
92+
.get_new_latest_blockhash(test_context)
93+
.await?;
8894
let transaction = post_signatures_transaction(
8995
payer_signer,
9096
signatures_signer,
@@ -93,7 +99,9 @@ async fn add_guardian_signatures_account(
9399
&guardian_signatures,
94100
new_blockhash,
95101
);
96-
testing_context.process_transaction(transaction).await?;
102+
testing_context
103+
.process_transaction(test_context, transaction)
104+
.await?;
97105

98106
Ok(signatures_signer.pubkey())
99107
}

0 commit comments

Comments
 (0)