Skip to content

Commit ac889d6

Browse files
author
Bengt Lofgren
committed
tests and lint pass
1 parent f74c895 commit ac889d6

File tree

28 files changed

+1309
-440
lines changed

28 files changed

+1309
-440
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"pubkey": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
3+
"account": {
4+
"lamports": 14801671630,
5+
"data": [
6+
"AQAAAAXqnPFs5BGY8aSZN8iMNwqU1K//ibW6y470XmMku3j3wYJlUqF9CAAGAQEAAAAF6pzxbOQRmPGkmTfIjDcKlNSv/4m1usuO9F5jJLt49w==",
7+
"base64"
8+
],
9+
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
10+
"executable": false,
11+
"rentEpoch": 18446744073709551615,
12+
"space": 82
13+
}
14+
}

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

Lines changed: 135 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
use crate::testing_engine::config::ExpectedError;
2-
use crate::testing_engine::setup::{Solver, TestingContext, TransferDirection};
3-
use crate::utils::auction::ActiveAuctionState;
1+
use crate::testing_engine::config::{
2+
ExecuteOrderInstructionConfig, ExpectedError, InstructionConfig,
3+
};
4+
use crate::testing_engine::setup::{TestingContext, TransferDirection};
5+
use crate::testing_engine::state::TestingEngineState;
6+
use crate::utils::token_account::SplTokenEnum;
47

58
use super::super::utils;
69
use anchor_spl::token::spl_token;
@@ -9,10 +12,7 @@ use common::wormhole_cctp_solana::cctp::{
912
};
1013
use matching_engine::fallback::execute_order::{ExecuteOrderCctpShim, ExecuteOrderShimAccounts};
1114
use solana_program_test::ProgramTestContext;
12-
use solana_sdk::{
13-
pubkey::Pubkey, signature::Keypair, signer::Signer, sysvar::SysvarId, transaction::Transaction,
14-
};
15-
use std::rc::Rc;
15+
use solana_sdk::{pubkey::Pubkey, signer::Signer, sysvar::SysvarId, transaction::Transaction};
1616
use utils::constants::*;
1717
use wormhole_svm_definitions::solana::CORE_BRIDGE_PROGRAM_ID;
1818
use wormhole_svm_definitions::{
@@ -40,13 +40,17 @@ pub struct ExecuteOrderFallbackAccounts {
4040

4141
impl ExecuteOrderFallbackAccounts {
4242
pub fn new(
43-
auction_accounts: &utils::auction::AuctionAccounts,
44-
fast_market_order_address: &Pubkey,
45-
active_auction_state: &ActiveAuctionState,
46-
signer: &Pubkey,
43+
current_state: &TestingEngineState,
44+
payer_signer: &Pubkey,
4745
fixture_accounts: &utils::account_fixtures::FixtureAccounts,
48-
transfer_direction: TransferDirection,
4946
) -> Self {
47+
let transfer_direction = current_state.base().transfer_direction;
48+
let auction_accounts = current_state.auction_accounts().unwrap();
49+
let active_auction_state = current_state.auction_state().get_active_auction().unwrap();
50+
let fast_market_order_address = current_state
51+
.fast_market_order()
52+
.unwrap()
53+
.fast_market_order_address;
5054
let remote_token_messenger = match transfer_direction {
5155
TransferDirection::FromEthereumToArbitrum => {
5256
fixture_accounts.arbitrum_remote_token_messenger
@@ -58,15 +62,15 @@ impl ExecuteOrderFallbackAccounts {
5862
};
5963

6064
Self {
61-
signer: *signer,
65+
signer: *payer_signer,
6266
custodian: auction_accounts.custodian,
63-
fast_market_order_address: *fast_market_order_address,
67+
fast_market_order_address,
6468
active_auction: active_auction_state.auction_address,
6569
active_auction_custody_token: active_auction_state.auction_custody_token_address,
6670
active_auction_config: auction_accounts.auction_config,
6771
active_auction_best_offer_token: auction_accounts.offer_token,
6872
initial_offer_token: auction_accounts.offer_token,
69-
initial_participant: *signer,
73+
initial_participant: *payer_signer,
7074
to_router_endpoint: auction_accounts.to_router_endpoint,
7175
remote_token_messenger,
7276
token_messenger: fixture_accounts.token_messenger,
@@ -87,18 +91,70 @@ pub struct ExecuteOrderFallbackFixtureAccounts {
8791
pub remote_token_messenger: Pubkey,
8892
pub token_messenger_minter_sender_authority: Pubkey,
8993
pub token_messenger_minter_event_authority: Pubkey,
94+
pub messenger_transmitter_config: Pubkey,
95+
pub token_minter: Pubkey,
96+
pub executor_token: Pubkey,
9097
}
9198

9299
pub async fn execute_order_fallback(
93100
testing_context: &TestingContext,
94101
test_context: &mut ProgramTestContext,
95-
payer_signer: &Rc<Keypair>,
96-
program_id: &Pubkey,
97-
solver: Solver,
102+
config: &ExecuteOrderInstructionConfig,
98103
execute_order_fallback_accounts: &ExecuteOrderFallbackAccounts,
99104
expected_error: Option<&ExpectedError>,
100105
) -> Option<ExecuteOrderFallbackFixture> {
101-
// Get target chain and use as remote address
106+
let program_id = &testing_context.get_matching_engine_program_id();
107+
let payer_signer = config
108+
.payer_signer
109+
.clone()
110+
.unwrap_or_else(|| testing_context.testing_actors.owner.keypair());
111+
112+
let execute_order_fallback_fixture = create_execute_order_fallback_fixture(
113+
testing_context,
114+
config,
115+
execute_order_fallback_accounts,
116+
);
117+
let clock_id = solana_program::clock::Clock::id();
118+
let execute_order_ix_accounts = create_execute_order_shim_accounts(
119+
execute_order_fallback_accounts,
120+
&execute_order_fallback_fixture,
121+
&clock_id,
122+
);
123+
124+
let execute_order_ix = ExecuteOrderCctpShim {
125+
program_id,
126+
accounts: execute_order_ix_accounts,
127+
}
128+
.instruction();
129+
130+
// Considering fast forwarding blocks here for deadline to be reached
131+
let recent_blockhash = testing_context
132+
.get_new_latest_blockhash(test_context)
133+
.await
134+
.unwrap();
135+
crate::testing_engine::engine::fast_forward_slots(test_context, 3).await;
136+
let transaction = Transaction::new_signed_with_payer(
137+
&[execute_order_ix],
138+
Some(&payer_signer.pubkey()),
139+
&[&payer_signer],
140+
recent_blockhash,
141+
);
142+
testing_context
143+
.execute_and_verify_transaction(test_context, transaction, expected_error)
144+
.await;
145+
if expected_error.is_none() {
146+
Some(execute_order_fallback_fixture)
147+
} else {
148+
None
149+
}
150+
}
151+
152+
pub fn create_execute_order_fallback_fixture(
153+
testing_context: &TestingContext,
154+
config: &ExecuteOrderInstructionConfig,
155+
execute_order_fallback_accounts: &ExecuteOrderFallbackAccounts,
156+
) -> ExecuteOrderFallbackFixture {
157+
let program_id = &testing_context.get_matching_engine_program_id();
102158
let cctp_message = Pubkey::find_program_address(
103159
&[
104160
common::CCTP_MESSAGE_SEED_PREFIX,
@@ -134,35 +190,70 @@ pub async fn execute_order_fallback(
134190
&POST_MESSAGE_SHIM_PROGRAM_ID,
135191
)
136192
.0;
137-
let executor_token = solver.actor.token_account_address().unwrap();
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();
198+
ExecuteOrderFallbackFixture {
199+
cctp_message,
200+
post_message_sequence,
201+
post_message_message,
202+
accounts: ExecuteOrderFallbackFixtureAccounts {
203+
local_token,
204+
token_messenger,
205+
remote_token_messenger,
206+
token_messenger_minter_sender_authority,
207+
token_messenger_minter_event_authority: *token_messenger_minter_event_authority,
208+
messenger_transmitter_config,
209+
token_minter,
210+
executor_token,
211+
},
212+
}
213+
}
138214

139-
let execute_order_ix_accounts = ExecuteOrderShimAccounts {
140-
signer: &payer_signer.pubkey(), // 0
141-
cctp_message: &cctp_message, // 1
215+
pub fn create_execute_order_shim_accounts<'ix>(
216+
execute_order_fallback_accounts: &'ix ExecuteOrderFallbackAccounts,
217+
execute_order_fallback_fixture: &'ix ExecuteOrderFallbackFixture,
218+
clock_id: &'ix Pubkey,
219+
) -> ExecuteOrderShimAccounts<'ix> {
220+
ExecuteOrderShimAccounts {
221+
signer: &execute_order_fallback_accounts.signer, // 0
222+
cctp_message: &execute_order_fallback_fixture.cctp_message, // 1
142223
custodian: &execute_order_fallback_accounts.custodian, // 2
143224
fast_market_order: &execute_order_fallback_accounts.fast_market_order_address, // 3
144225
active_auction: &execute_order_fallback_accounts.active_auction, // 4
145226
active_auction_custody_token: &execute_order_fallback_accounts.active_auction_custody_token, // 5
146227
active_auction_config: &execute_order_fallback_accounts.active_auction_config, // 6
147228
active_auction_best_offer_token: &execute_order_fallback_accounts
148229
.active_auction_best_offer_token, // 7
149-
executor_token: &executor_token, // 8
230+
executor_token: &execute_order_fallback_fixture.accounts.executor_token, // 8
150231
initial_offer_token: &execute_order_fallback_accounts.initial_offer_token, // 9
151232
initial_participant: &execute_order_fallback_accounts.initial_participant, // 10
152233
to_router_endpoint: &execute_order_fallback_accounts.to_router_endpoint, // 11
153234
post_message_shim_program: &POST_MESSAGE_SHIM_PROGRAM_ID, // 12
154-
post_message_sequence: &post_message_sequence, // 13
155-
post_message_message: &post_message_message, // 14
235+
post_message_sequence: &execute_order_fallback_fixture.post_message_sequence, // 13
236+
post_message_message: &execute_order_fallback_fixture.post_message_message, // 14
156237
cctp_deposit_for_burn_mint: &USDC_MINT, // 15
157238
cctp_deposit_for_burn_token_messenger_minter_sender_authority:
158-
&token_messenger_minter_sender_authority, // 16
159-
cctp_deposit_for_burn_message_transmitter_config: &messenger_transmitter_config, // 17
160-
cctp_deposit_for_burn_token_messenger: &token_messenger, // 18
161-
cctp_deposit_for_burn_remote_token_messenger: &remote_token_messenger, // 19
162-
cctp_deposit_for_burn_token_minter: &token_minter, // 20
163-
cctp_deposit_for_burn_local_token: &local_token, // 21
239+
&execute_order_fallback_fixture
240+
.accounts
241+
.token_messenger_minter_sender_authority, // 16
242+
cctp_deposit_for_burn_message_transmitter_config: &execute_order_fallback_fixture
243+
.accounts
244+
.messenger_transmitter_config, // 17
245+
cctp_deposit_for_burn_token_messenger: &execute_order_fallback_fixture
246+
.accounts
247+
.token_messenger, // 18
248+
cctp_deposit_for_burn_remote_token_messenger: &execute_order_fallback_fixture
249+
.accounts
250+
.remote_token_messenger, // 19
251+
cctp_deposit_for_burn_token_minter: &execute_order_fallback_fixture.accounts.token_minter, // 20
252+
cctp_deposit_for_burn_local_token: &execute_order_fallback_fixture.accounts.local_token, // 21
164253
cctp_deposit_for_burn_token_messenger_minter_event_authority:
165-
token_messenger_minter_event_authority, // 22
254+
&execute_order_fallback_fixture
255+
.accounts
256+
.token_messenger_minter_event_authority, // 22
166257
cctp_deposit_for_burn_token_messenger_minter_program: &TOKEN_MESSENGER_MINTER_PROGRAM_ID, // 23
167258
cctp_deposit_for_burn_message_transmitter_program: &MESSAGE_TRANSMITTER_PROGRAM_ID, // 24
168259
core_bridge_program: &CORE_BRIDGE_PROGRAM_ID, // 25
@@ -171,74 +262,30 @@ pub async fn execute_order_fallback(
171262
post_message_shim_event_authority: &POST_MESSAGE_SHIM_EVENT_AUTHORITY, // 28
172263
system_program: &solana_program::system_program::ID, // 29
173264
token_program: &spl_token::ID, // 30
174-
clock: &solana_program::clock::Clock::id(), // 31
175-
};
176-
177-
let execute_order_ix = ExecuteOrderCctpShim {
178-
program_id,
179-
accounts: execute_order_ix_accounts,
180-
}
181-
.instruction();
182-
183-
// Considering fast forwarding blocks here for deadline to be reached
184-
let recent_blockhash = testing_context
185-
.get_new_latest_blockhash(test_context)
186-
.await
187-
.unwrap();
188-
crate::testing_engine::engine::fast_forward_slots(test_context, 3).await;
189-
let transaction = Transaction::new_signed_with_payer(
190-
&[execute_order_ix],
191-
Some(&payer_signer.pubkey()),
192-
&[&payer_signer],
193-
recent_blockhash,
194-
);
195-
testing_context
196-
.execute_and_verify_transaction(test_context, transaction, expected_error)
197-
.await;
198-
if expected_error.is_none() {
199-
Some(ExecuteOrderFallbackFixture {
200-
cctp_message,
201-
post_message_sequence,
202-
post_message_message,
203-
accounts: ExecuteOrderFallbackFixtureAccounts {
204-
local_token,
205-
token_messenger,
206-
remote_token_messenger,
207-
token_messenger_minter_sender_authority,
208-
token_messenger_minter_event_authority: *token_messenger_minter_event_authority,
209-
},
210-
})
211-
} else {
212-
None
265+
clock: clock_id, // 31
213266
}
214267
}
215268

216269
pub async fn execute_order_fallback_test(
217270
testing_context: &TestingContext,
218271
test_context: &mut ProgramTestContext,
219-
auction_accounts: &utils::auction::AuctionAccounts,
220-
fast_market_order_address: &Pubkey,
221-
active_auction_state: &ActiveAuctionState,
222-
solver: Solver,
223-
expected_error: Option<&ExpectedError>,
272+
current_state: &TestingEngineState,
273+
config: &ExecuteOrderInstructionConfig,
224274
) -> Option<ExecuteOrderFallbackFixture> {
275+
let expected_error = config.expected_error();
225276
let fixture_accounts = testing_context
226277
.get_fixture_accounts()
227278
.expect("Pre-made fixture accounts not found");
228-
let execute_order_fallback_accounts = ExecuteOrderFallbackAccounts::new(
229-
auction_accounts,
230-
fast_market_order_address,
231-
active_auction_state,
232-
&testing_context.testing_actors.owner.pubkey(),
233-
&fixture_accounts,
234-
testing_context.transfer_direction,
235-
);
279+
let payer_signer = config
280+
.payer_signer
281+
.clone()
282+
.unwrap_or_else(|| testing_context.testing_actors.owner.keypair());
283+
let execute_order_fallback_accounts =
284+
ExecuteOrderFallbackAccounts::new(current_state, &payer_signer.pubkey(), &fixture_accounts);
236285
execute_order_fallback(
237286
testing_context,
238287
test_context,
239-
&testing_context.testing_actors.owner.keypair(),
240-
&testing_context.get_matching_engine_program_id(),
241-
solver,
288+
config,
242289
&execute_order_fallback_accounts,
243290
expected_error,
244291
)

0 commit comments

Comments
 (0)