Skip to content

Commit 890aba2

Browse files
author
Bengt Lofgren
committed
all tests passing
1 parent 2992263 commit 890aba2

File tree

14 files changed

+837
-750
lines changed

14 files changed

+837
-750
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
[submodule "solana/lib/wormhole"]
1414
path = solana/lib/wormhole
1515
url = https://github.com/wormholelabs-xyz/wormhole.git
16-
branch = svm-shims-2
16+
branch = f69b3ae366211276fe15554f83a2d76abee0535c

solana/Cargo.lock

Lines changed: 66 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

solana/Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,22 @@ ruint = "1.9.0"
4949
cfg-if = "1.0"
5050
hex-literal = "0.4.1"
5151
bytemuck = "1.13.0"
52-
wormhole-svm-shim = { git = "https://github.com/wormholelabs-xyz/wormhole.git", rev = "f69b3ae3" }
53-
wormhole-svm-definitions = { git = "https://github.com/wormholelabs-xyz/wormhole.git", rev = "f69b3ae3", features = ["borsh"] }
52+
wormhole-svm-shim = { git = "https://github.com/wormholelabs-xyz/wormhole.git", rev = "32cb65dd9ae11547f0e57d106b6974dc8ed5f52d" }
53+
wormhole-svm-definitions = { git = "https://github.com/wormholelabs-xyz/wormhole.git", rev = "32cb65dd9ae11547f0e57d106b6974dc8ed5f52d", features = ["borsh"] }
5454

5555
[patch."https://github.com/wormholelabs-xyz/wormhole.git"]
5656
wormhole-svm-shim = { path = "lib/wormhole/svm/wormhole-core-shims/crates/shim" }
5757
wormhole-svm-definitions = { path = "lib/wormhole/svm/wormhole-core-shims/crates/definitions" }
5858

59-
[profile.release]
60-
overflow-checks = true
61-
lto = "fat"
62-
codegen-units = 1
59+
# [profile.release]
60+
# overflow-checks = true
61+
# lto = "fat"
62+
# codegen-units = 1
6363

64-
[profile.release.build-override]
65-
opt-level = 3
66-
incremental = false
67-
codegen-units = 1
64+
# [profile.release.build-override]
65+
# opt-level = 3
66+
# incremental = false
67+
# codegen-units = 1
6868

6969
[workspace.lints.clippy]
7070
correctness = { priority = -1, level = "warn"}

solana/programs/matching-engine/tests/integration_tests.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::testing_engine::config::{
1414
PlaceInitialOfferInstructionConfig,
1515
};
1616
use crate::testing_engine::engine::{InstructionTrigger, TestingEngine};
17-
use shimful::shims::set_up_post_message_transaction_test;
17+
use shimful::post_message::set_up_post_message_transaction_test;
1818
use shimless::initialize::{initialize_program, AuctionParametersConfig};
1919
use solana_sdk::transaction::TransactionError;
2020
use utils::router::add_local_router_endpoint_ix;
@@ -87,9 +87,8 @@ pub async fn test_local_token_router_endpoint_creation() {
8787
.await;
8888
}
8989

90-
// Test setting up vaas
91-
// Vaa is from arbitrum to ethereum
92-
// - The payload of the vaa should be the .to_vec() of the FastMarketOrder under universal/rs/messages/src/fast_market_order.rs
90+
/// Test setting up vaas
91+
/// Vaa is from arbitrum to ethereum
9392
#[tokio::test]
9493
pub async fn test_setup_vaas() {
9594
let transfer_direction = TransferDirection::FromArbitrumToEthereum;
@@ -227,7 +226,7 @@ pub async fn test_approve_usdc() {
227226

228227
// TODO: Create an issue based on this bug. So this function will transfer the ownership of whatever the guardian signatures signer is set to to the verify shim program. This means that the argument to this function MUST be ephemeral and cannot be used until the close signatures instruction has been executed.
229228
let (_guardian_set_pubkey, _guardian_signatures_pubkey, _guardian_set_bump) =
230-
shimful::shims::create_guardian_signatures(
229+
shimful::verify_shim::create_guardian_signatures(
231230
&testing_context.test_context,
232231
&actors.owner.keypair(),
233232
&vaa_data,
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
use crate::testing_engine::config::ExpectedError;
2+
3+
use super::super::utils;
4+
use super::super::utils::constants::*;
5+
use super::super::utils::setup::TestingContext;
6+
use common::messages::FastMarketOrder;
7+
use matching_engine::fallback::close_fast_market_order::{
8+
CloseFastMarketOrder as CloseFastMarketOrderFallback,
9+
CloseFastMarketOrderAccounts as CloseFastMarketOrderFallbackAccounts,
10+
};
11+
use matching_engine::fallback::initialise_fast_market_order::{
12+
InitialiseFastMarketOrder as InitialiseFastMarketOrderFallback,
13+
InitialiseFastMarketOrderAccounts as InitialiseFastMarketOrderFallbackAccounts,
14+
InitialiseFastMarketOrderData as InitialiseFastMarketOrderFallbackData,
15+
};
16+
17+
use matching_engine::state::FastMarketOrder as FastMarketOrderState;
18+
use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer, transaction::Transaction};
19+
use std::rc::Rc;
20+
use wormhole_io::TypePrefixedPayload;
21+
22+
pub fn initialise_fast_market_order_fallback_instruction(
23+
payer_signer: &Rc<Keypair>,
24+
program_id: &Pubkey,
25+
fast_market_order: FastMarketOrderState,
26+
guardian_set_pubkey: Pubkey,
27+
guardian_signatures_pubkey: Pubkey,
28+
guardian_set_bump: u8,
29+
) -> solana_program::instruction::Instruction {
30+
let fast_market_order_account = Pubkey::find_program_address(
31+
&[
32+
FastMarketOrderState::SEED_PREFIX,
33+
&fast_market_order.digest(),
34+
&fast_market_order.close_account_refund_recipient,
35+
],
36+
program_id,
37+
)
38+
.0;
39+
40+
let create_fast_market_order_accounts = InitialiseFastMarketOrderFallbackAccounts {
41+
signer: &payer_signer.pubkey(),
42+
fast_market_order_account: &fast_market_order_account,
43+
guardian_set: &guardian_set_pubkey,
44+
guardian_set_signatures: &guardian_signatures_pubkey,
45+
verify_vaa_shim_program: &WORMHOLE_VERIFY_VAA_SHIM_PID,
46+
system_program: &solana_program::system_program::ID,
47+
};
48+
49+
InitialiseFastMarketOrderFallback {
50+
program_id: program_id,
51+
accounts: create_fast_market_order_accounts,
52+
data: InitialiseFastMarketOrderFallbackData::new(fast_market_order, guardian_set_bump),
53+
}
54+
.instruction()
55+
}
56+
57+
pub async fn close_fast_market_order_fallback(
58+
testing_context: &TestingContext,
59+
refund_recipient_keypair: &Rc<Keypair>,
60+
program_id: &Pubkey,
61+
fast_market_order_address: &Pubkey,
62+
expected_error: Option<&ExpectedError>,
63+
) {
64+
let test_ctx = &testing_context.test_context;
65+
let recent_blockhash = test_ctx
66+
.borrow_mut()
67+
.get_new_latest_blockhash()
68+
.await
69+
.expect("Failed to get new blockhash");
70+
let close_fast_market_order_ix = CloseFastMarketOrderFallback {
71+
program_id: program_id,
72+
accounts: CloseFastMarketOrderFallbackAccounts {
73+
fast_market_order: fast_market_order_address,
74+
close_account_refund_recipient: &refund_recipient_keypair.pubkey(),
75+
},
76+
}
77+
.instruction();
78+
79+
let transaction = Transaction::new_signed_with_payer(
80+
&[close_fast_market_order_ix],
81+
Some(&refund_recipient_keypair.pubkey()),
82+
&[refund_recipient_keypair],
83+
recent_blockhash,
84+
);
85+
testing_context
86+
.execute_and_verify_transaction(transaction, expected_error)
87+
.await;
88+
}
89+
90+
pub fn create_fast_market_order_state_from_vaa_data(
91+
vaa_data: &utils::vaa::PostedVaaData,
92+
close_account_refund_recipient: Pubkey,
93+
) -> (FastMarketOrderState, utils::vaa::PostedVaaData) {
94+
let vaa_data = utils::vaa::PostedVaaData {
95+
consistency_level: vaa_data.consistency_level,
96+
vaa_time: vaa_data.vaa_time,
97+
sequence: vaa_data.sequence,
98+
emitter_chain: vaa_data.emitter_chain,
99+
emitter_address: vaa_data.emitter_address,
100+
payload: vaa_data.payload.clone(),
101+
nonce: vaa_data.nonce,
102+
vaa_signature_account: vaa_data.vaa_signature_account,
103+
submission_time: 0,
104+
};
105+
let vaa_message = matching_engine::fallback::place_initial_offer::VaaMessageBodyHeader::new(
106+
vaa_data.consistency_level,
107+
vaa_data.vaa_time,
108+
vaa_data.sequence,
109+
vaa_data.emitter_chain,
110+
vaa_data.emitter_address,
111+
);
112+
113+
let order: FastMarketOrder = TypePrefixedPayload::<1>::read_slice(&vaa_data.payload).unwrap();
114+
115+
let redeemer_message_fixed_length = {
116+
let mut fixed_array = [0u8; 512]; // Initialize with zeros (automatic padding)
117+
118+
if !order.redeemer_message.is_empty() {
119+
// Calculate how many bytes to copy (min of message length and array size)
120+
let copy_len = std::cmp::min(order.redeemer_message.len(), 512);
121+
122+
// Copy the bytes from the message to the fixed array
123+
fixed_array[..copy_len].copy_from_slice(&order.redeemer_message[..copy_len]);
124+
}
125+
126+
fixed_array
127+
};
128+
let fast_market_order = FastMarketOrderState::new(
129+
order.amount_in,
130+
order.min_amount_out,
131+
order.deadline,
132+
order.target_chain,
133+
order.redeemer_message.len() as u16,
134+
order.redeemer,
135+
order.sender,
136+
order.refund_address,
137+
order.max_fee,
138+
order.init_auction_fee,
139+
redeemer_message_fixed_length,
140+
close_account_refund_recipient.to_bytes(),
141+
vaa_data.sequence,
142+
vaa_data.vaa_time,
143+
vaa_data.nonce,
144+
vaa_data.emitter_chain,
145+
vaa_data.consistency_level,
146+
vaa_data.emitter_address,
147+
);
148+
149+
assert_eq!(fast_market_order.redeemer, order.redeemer);
150+
assert_eq!(
151+
vaa_message.digest(&fast_market_order).as_ref(),
152+
vaa_data.digest().as_ref()
153+
);
154+
155+
(fast_market_order, vaa_data)
156+
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
pub mod shims;
1+
pub mod fast_market_order_shim;
2+
pub mod post_message;
23
pub mod shims_execute_order;
4+
pub mod shims_make_offer;
35
pub mod shims_prepare_order_response;
6+
pub mod verify_shim;

0 commit comments

Comments
 (0)