I am trying to run some tests in my Solana Anchor project but I get an error saying that the declared program id does not match the actual program id.
Error: AnchorError occurred. Error Code: DeclaredProgramIdMismatch. Error Number: 4100. Error Message: The declared program id does not match the actual program id.
Here's the steps I take:
- Build my program (
anchor build
) - Deploy using local testnet (
solana-test-validator -r
) - Copy paste the program id that comes out after deployment
- Stop the local testnet
- Run the tests (
anchor test
)
My rust program declared id is:
declare_id!("hqgrvUepLLhFbXCb8woduWM62ps5rqap3TmPHbpuK11");
But if i try to paste the client's program id I get this:
ProgramId: PublicKey {
_bn: <BN: da075cb2ff5ec6817613de530b692a8735477769da47430cbd8154335c4a8327>
}
My question is, how do I further debug this? I've looked for the error inside node_modules to see what is compared that throws such error but I could not find much.
Thank you in advance, Happy coding.
EDIT_1:
Test client:
import * as anchor from "@project-serum/anchor";
import { Program } from "@project-serum/anchor";
import { BoyncAnchorProgram } from "../target/types/boync_anchor_program";
import { PublicKey } from '@solana/web3.js';
import { expect } from "chai";
describe("boync-anchor-program", () => {
// Configure the client to use the local cluster.
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
const program = anchor.workspace.BoyncAnchorProgram as Program<BoyncAnchorProgram>;
it("Creating user Bob", async () => {
// Add your test here.
const [bobUserPDA, _] = await PublicKey
.findProgramAddress(
[
anchor.utils.bytes.utf8.encode('user'),
provider.wallet.publicKey.toBuffer(),
],
program.programId
);
const tx = await program.methods
.initialize('Bob')
.accounts({
user: provider.wallet.publicKey,
userData: bobUserPDA,
})
.rpc();
^^^ ERROR at this transaction invocation.
console.log("[Success] Your transaction signature", tx);
const bobData = await program.account.boyncUserData.fetch(bobUserPDA);
expect(bobData.name).to.be.eql('Bob');
});
});