AlmostEfficient / full-stack-solana-dev

Anchor + Rust + React Solana app from scratch. Video walkthrough below.
https://youtu.be/vUHF1X48zM4
Creative Commons Zero v1.0 Universal
27 stars 15 forks source link

SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0 #5

Open gameuser1982 opened 4 months ago

gameuser1982 commented 4 months ago

So if I anchor build and then anchor deploy on the devnet and then use anchor test --skip-build --skip-deploy since I already built and deployed everything before, I find the first time around the two tests pass with zero simulation errors. However second time around, I get an error during the simulation phase even though the 2 tests still pass:

candid@DESKTOP-5D7VSM9:~/counter$ anchor test --skip-build --skip-deploy

Found a 'test' script in the Anchor.toml. Running it as a test suite!

Running test suite: "/home/candid/counter/Anchor.toml"

yarn run v1.22.22
warning package.json: No license field
$ /home/candid/counter/node_modules/.bin/ts-mocha -p ./tsconfig.json -t 1000000 'tests/**/*.ts'

  counter
SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0
    at Connection.sendEncodedTransaction (/home/candid/counter/node_modules/@solana/web3.js/src/connection.ts:5923:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Connection.sendRawTransaction (/home/candid/counter/node_modules/@solana/web3.js/src/connection.ts:5880:20)
    at sendAndConfirmRawTransaction (/home/candid/counter/node_modules/@coral-xyz/anchor/src/provider.ts:370:21)
    at AnchorProvider.sendAndConfirm (/home/candid/counter/node_modules/@coral-xyz/anchor/src/provider.ts:160:14)
    at MethodsBuilder.rpc [as _rpcFn] (/home/candid/counter/node_modules/@coral-xyz/anchor/src/program/namespace/rpc.ts:29:16) {
  logs: [
    'Program 6emLDu2jat6pho23Xcy3L2nnkAGu62YEuqpdvpJytSb7 invoke [1]',
    'Program log: Instruction: Initialize',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Allocate: account Address { address: DZR7F2P3S1zBSKYUHEfp44SzZ53pPaPsnvJxpermkBcN, base: None } already in use',
    'Program 11111111111111111111111111111111 failed: custom program error: 0x0',
    'Program 6emLDu2jat6pho23Xcy3L2nnkAGu62YEuqpdvpJytSb7 consumed 6560 of 200000 compute units',
    'Program 6emLDu2jat6pho23Xcy3L2nnkAGu62YEuqpdvpJytSb7 failed: custom program error: 0x0'
  ],
  programErrorStack: ProgramErrorStack {
    stack: [
      [PublicKey [PublicKey(6emLDu2jat6pho23Xcy3L2nnkAGu62YEuqpdvpJytSb7)]],
      [PublicKey [PublicKey(11111111111111111111111111111111)]]
    ]
  }
}
    ✔ Is initialized! (495ms)
Transaction Signature: 4DVEfi5Gfbg4gvX1Yjr4ecorXE52m8UfsVq7yn1BiuYALmmXFFEEmdXTUEArUTviRubGpCgUh6fvAGmdEMvPWF3G
Count: 6
    ✔ Increment (482ms)

  2 passing (981ms)

Done in 2.64s.

Should I worry about this? It looks like it's happening because I am attempting to initialize an already initialized account. Since a constant seed is being used, the same address is being used on each test. How do I reset this without having to redeploy the contract on devnet? Or is that not possible?

Would it have any negative effect to the enduser that is interacting with the smart contract through the frontend? The frontend I setup does appear to work fine on devnet though I haven't tested in production on mainnet yet.

Hopefully @AlmostEfficient or anyone else can provide some insight.

AlmostEfficient commented 4 months ago

You've two options here:

  1. Use another seed - you'll abandon the old PDA. No biggie.
  2. Skip the init test - there's no reason to re-initialize lol. The PDA already exists. Try to read or write to it.