Add test_post_update_with_wormhole using core-bridge VAA flow#3649
Add test_post_update_with_wormhole using core-bridge VAA flow#3649guibescos wants to merge 3 commits into
Conversation
Add integration test that verifies post_update works with VAAs created through the actual wormhole core-bridge contract (init -> write -> verify), rather than manually building pre-verified account data. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
guibescos
left a comment
There was a problem hiding this comment.
the test is failing
The core-bridge's default Cargo features include cpi -> no-entrypoint, so the .so built by cargo-build-sbf has no entrypoint. Use the native Anchor entry function via processor!() macro with an unsafe transmute to bridge the Anchor lifetime constraint with ProgramTest's signature. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| fn wormhole_process_instruction() -> solana_program::entrypoint::ProcessInstruction { | ||
| unsafe { std::mem::transmute(wormhole_core_bridge_solana::entry as usize) } | ||
| } |
There was a problem hiding this comment.
🔴 Unsafe transmute used where a safe wrapper function would suffice
The unsafe { std::mem::transmute(wormhole_core_bridge_solana::entry as usize) } at line 39 violates the REVIEW.md rule "No unsafe code unless absolutely necessary" and doc/rust-code-guidelines.md which states "Avoid writing unsafe code" and recommends unsafe_code = "deny" in clippy config.
The transmute converts the Anchor entry function (which ties the slice and AccountInfo lifetimes: &'info [AccountInfo<'info>]) to a ProcessInstruction pointer (which has independent lifetimes). A safe wrapper function can achieve this without unsafe because Rust's lifetime subtyping allows independent lifetimes to be unified when calling a function that requires matching lifetimes:
Safe alternative
fn wormhole_process_instruction(
program_id: &solana_program::pubkey::Pubkey,
accounts: &[solana_program::account_info::AccountInfo],
instruction_data: &[u8],
) -> solana_program::entrypoint::ProgramResult {
wormhole_core_bridge_solana::entry(program_id, accounts, instruction_data)
}Beyond the rule violation, the transmute through usize is fragile: it relies on an assumption about ProgramTest's internal implementation providing matching lifetimes, which could change in future versions of the dependency.
| fn wormhole_process_instruction() -> solana_program::entrypoint::ProcessInstruction { | |
| unsafe { std::mem::transmute(wormhole_core_bridge_solana::entry as usize) } | |
| } | |
| fn wormhole_process_instruction( | |
| program_id: &solana_program::pubkey::Pubkey, | |
| accounts: &[solana_program::account_info::AccountInfo], | |
| instruction_data: &[u8], | |
| ) -> solana_program::entrypoint::ProgramResult { | |
| wormhole_core_bridge_solana::entry(program_id, accounts, instruction_data) | |
| } |
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary