Skip to content

Commit d1c9d6c

Browse files
Fix Anchor CI: sync IDL addresses after keys sync
After 'anchor keys sync' generates new keypairs on CI, the declare_id!() in source gets updated but the IDL files in idls/*.json keep the old addresses. Since declare_program!(name) reads from the IDL, LiteSVM tests then load the .so at the stale IDL address while the program expects the new declare_id!() address, causing DeclaredProgramIdMismatch. This adds a step after keys sync that updates each IDL's address field to match the corresponding program address in Anchor.toml.
1 parent d98856f commit d1c9d6c

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

.github/workflows/anchor.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,24 @@ jobs:
142142
# Sync program IDs (Anchor 1.0.0 requires keypair and declare_id! to match)
143143
anchor keys sync
144144
145+
# Update IDL address fields to match the synced keys.
146+
# declare_program!(name) reads the address from idls/<name>.json, so
147+
# after keys sync changes the program IDs, the IDLs must match too —
148+
# otherwise LiteSVM tests load the .so at the old IDL address while
149+
# the compiled program expects the new declare_id!() address.
150+
if [ -d "idls" ]; then
151+
for idl_file in idls/*.json; do
152+
program_name=$(basename "$idl_file" .json)
153+
# Look up the new address from Anchor.toml [programs.localnet]
154+
new_address=$(grep "^${program_name} " Anchor.toml | head -1 | sed 's/.*= *"\(.*\)"/\1/')
155+
if [ -n "$new_address" ]; then
156+
# Update the "address" field in the IDL JSON
157+
tmp=$(mktemp)
158+
jq --arg addr "$new_address" '.address = $addr' "$idl_file" > "$tmp" && mv "$tmp" "$idl_file"
159+
fi
160+
done
161+
fi
162+
145163
# Run anchor build
146164
if ! anchor build; then
147165
echo "::error::anchor build failed for $project"

0 commit comments

Comments
 (0)