Skip to content

Commit 1eca2da

Browse files
author
Bengt Lofgren
committed
address shimful directory comments. Added ability to create transaction with compute unit price and compute unit limit
1 parent 4604c3e commit 1eca2da

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Shimful Tests
22

3-
This directory contains tests that use the fallback program.
3+
This directory contains tests that use the fallback entrypoint of the matching engine program.
44

55
## Files
66

77
- `fast_market_order_shim.rs` - A function that creates a fast market order account and one that closes it
88
- `shims_make_offer.rs` - A function that places an initial offer and one that improves an offer
99
- `shims_execute_order.rs` - A function that executes an order
1010
- `shims_prepare_order_response.rs` - A function that prepares an order response
11-
- `shims_settle_auction.rs` - A function that settles an auction

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,17 @@ pub async fn initialise_fast_market_order_fallback(
5454
fast_market_order,
5555
guardian_signature_info,
5656
);
57-
let recent_blockhash = testing_context
58-
.get_new_latest_blockhash(test_context)
59-
.await
60-
.unwrap();
61-
let transaction = solana_sdk::transaction::Transaction::new_signed_with_payer(
62-
&[initialise_fast_market_order_ix],
63-
Some(&payer_signer.pubkey()),
64-
&[payer_signer],
65-
recent_blockhash,
66-
);
67-
let versioned_transaction = VersionedTransaction::from(transaction);
57+
let transaction = testing_context
58+
.create_transaction(
59+
&[initialise_fast_market_order_ix],
60+
Some(&payer_signer.pubkey()),
61+
&[payer_signer],
62+
1000000000,
63+
1000000000,
64+
)
65+
.await;
6866
testing_context
69-
.execute_and_verify_transaction(test_context, versioned_transaction, expected_error)
67+
.execute_and_verify_transaction(test_context, transaction, expected_error)
7068
.await;
7169
}
7270

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use anyhow::Result as AnyhowResult;
3838
use matching_engine::{CCTP_MINT_RECIPIENT, ID as PROGRAM_ID};
3939
use solana_program_test::{BanksClientError, ProgramTest, ProgramTestContext};
4040
use solana_sdk::clock::Clock;
41+
use solana_sdk::compute_budget::ComputeBudgetInstruction;
4142
use solana_sdk::instruction::InstructionError;
4243
use solana_sdk::transaction::{TransactionError, VersionedTransaction};
4344
use solana_sdk::{
@@ -377,6 +378,27 @@ impl TestingContext {
377378
Ok(())
378379
}
379380

381+
pub async fn create_transaction(
382+
&self,
383+
instructions: &[Instruction],
384+
payer: Option<&Pubkey>,
385+
signers: &[&Keypair],
386+
compute_unit_price: u64,
387+
compute_unit_limit: u64,
388+
) -> VersionedTransaction {
389+
let last_blockhash = self.get_new_latest_blockhash(test_context).await;
390+
let compute_budget_price =
391+
ComputeBudgetInstruction::set_compute_unit_price(compute_unit_price);
392+
let compute_budget_limit =
393+
ComputeBudgetInstruction::set_compute_unit_limit(compute_unit_limit);
394+
let instructions = [
395+
&compute_budget_price,
396+
&compute_budget_limit,
397+
instructions.to_vec(),
398+
];
399+
Transaction::new_signed_with_payer(instructions, payer, signers, last_blockhash)
400+
}
401+
380402
// TODO: Edit to handle multiple instructions in a single transaction
381403
pub async fn execute_and_verify_transaction(
382404
&self,

solana/modules/matching-engine-testing/tests/utils/account_fixtures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl FixtureAccounts {
5151
core_guardian_set: add_account_from_file(program_test, "tests/fixtures/accounts/core_bridge/guardian_set_0.json").address,
5252
message_transmitter_config: add_account_from_file(program_test, "tests/fixtures/accounts/message_transmitter/message_transmitter_config.json").address,
5353
// matching_engine_custodian: add_account_from_file(program_test, "tests/fixtures/accounts/testnet/matching_engine_custodian.json").address,
54-
matching_engine_custodian: pubkey!("5BsCKkzuZXLygduw6RorCqEB61AdzNkxp5VzQrFGzYWr"),
54+
matching_engine_custodian: Pubkey::from_str("5BsCKkzuZXLygduw6RorCqEB61AdzNkxp5VzQrFGzYWr").unwrap(),
5555
token_router_custodian: add_account_from_file(program_test, "tests/fixtures/accounts/testnet/token_router_custodian.json").address,
5656
token_router_program: add_account_from_file(program_test, "tests/fixtures/accounts/testnet/token_router_program_data_hacked.json").address,
5757
arbitrum_remote_token_messenger: add_account_from_file(program_test, "tests/fixtures/accounts/token_messenger_minter/arbitrum_remote_token_messenger.json").address,

0 commit comments

Comments
 (0)