DEV Community

Cover image for Anchor Test failing on 0 !== 1 despite increment method being called in Solana Playground- Hala Kabir
Hala Kabir
Hala Kabir

Posted on

Anchor Test failing on 0 !== 1 despite increment method being called in Solana Playground- Hala Kabir

@niranjannlc @walletguy @ajdroi & @matthewrevell pleasee help an young develpoer..

Hi everyone, I am running into a persistent issue on Solana Playground where my Anchor integration test is failing with an AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: 0 !== 1.

My smart contract includes a functional increment instruction, and my anchor.test.ts file correctly initializes the account and immediately calls the increment instruction right after. The code looks like this:

describe("counter", () => {
  it("Increments", async () => {
    const provider = anchor.AnchorProvider.env();
    anchor.setProvider(provider);
    const program = anchor.workspace.Counter;
    const keypair = anchor.web3.Keypair.generate();

    await program.methods.initialize().accounts({ counter: keypair.publicKey, authority: provider.wallet.publicKey }).signers([keypair]).rpc();
    await program.methods.increment().accounts({ counter: keypair.publicKey, authority: provider.wallet.publicKey }).rpc();

    const state = await program.account.counter.fetch(keypair.publicKey);
    assert.strictEqual(state.count.toNumber(), 1);
  });
});
Enter fullscreen mode Exit fullscreen mode

What I've tried:

  1. Re-building and re-deploying the contract successfully on Testnet.
  2. Hard-refreshing the playground browser environment.
  3. Running test directly via the playground terminal console.

Despite the successful deployment and complete test script execution, the fetched state counter remains 0. Is there a known state-caching or deployment-sync quirk within Solana Playground that prevents the transaction from reflecting on the account state during test runner execution? Any help would be greatly appreciated!

Top comments (0)