Skip to content

Commit 8b64088

Browse files
author
Edward
committed
Fix flaky CI: load cross-program .so at runtime instead of compile time
The hand test loads lever.so (a different program) via include_bytes!(), which fails during anchor build's IDL generation step because the .so files don't exist yet at compile time. Using std::fs::read() defers the load to test runtime, after anchor build has created the artifacts.
1 parent 432c3cc commit 8b64088

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

  • basics/cross-program-invocation/anchor/programs/hand/tests

basics/cross-program-invocation/anchor/programs/hand/tests/test_hand.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ fn test_pull_lever_cpi() {
5050

5151
// Load both programs
5252
let hand_bytes = include_bytes!("../../../target/deploy/hand.so");
53-
let lever_bytes = include_bytes!("../../../target/deploy/lever.so");
53+
// Use std::fs::read() instead of include_bytes!() for the lever program because
54+
// include_bytes!() runs at compile time, and during `anchor build` the IDL generation
55+
// step compiles tests before the .so files exist. Since this is a cross-program
56+
// dependency (not our own program), lever.so may not be built yet at compile time.
57+
let lever_bytes = std::fs::read("target/deploy/lever.so").expect("lever.so not found — run `anchor build` first");
5458
svm.add_program(hand_program_id, hand_bytes).unwrap();
5559
svm.add_program(lever_program_id, lever_bytes).unwrap();
5660
let payer = create_wallet(&mut svm, 10_000_000_000).unwrap();

0 commit comments

Comments
 (0)