0

I am very grateful for your knowledge to be shared. Through the knowledge you share I learn many new and very interesting things. while practicing project-8-token-lottery. I get an error when running Anchor test. It is the error: "Program log: AnchorError occurred. Error Code: InvalidSecpSignature. Error Number: 6016. Error Message: InvalidSecpSignature". I have tried many ways but have not fixed it. Please give me advice. Thank you so much! enter image description here

my code in Anchor test

it("Is committing and revealing a winner",async()=>{

const queue = new anchor.web3.PublicKey("FfD96yeXs4cxZshoPPSKhSPgVQxLAJUT3gefgh84m1Di"); //devnet
const queueAccount = new sb.Queue(switchboardProgram, queue);
const rngKp = anchor.web3.Keypair.generate();


try {
  await queueAccount.loadData(); 
} catch (err) {
  console.log("Queue account not found");
  process.exit(1);
}
const [randomness, ix] = await sb.Randomness.create(switchboardProgram, rngKp, queue);
console.log("Created randomness account..");
console.log("Randomness account", randomness.pubkey.toBase58());
console.log("rkp account", rngKp.publicKey.toBase58());

const createRandomnessTx = await sb.asV0Tx({
  connection:provider. connection,
  ixs: [ix],
  payer: wallet.publicKey,
  signers: [wallet.payer,rngKp],
  computeUnitPrice: 75_000,
  computeUnitLimitMultiple: 1.3,
});
const blockhashContext = await provider.connection.getLatestBlockhashAndContext();

const createRandomnessSignature = await provider.connection.sendTransaction(createRandomnessTx);
await provider.connection.confirmTransaction({ //sign the transaction
  signature: createRandomnessSignature,
  blockhash: blockhashContext.value.blockhash,
  lastValidBlockHeight: blockhashContext.value.lastValidBlockHeight
});
console.log(
  "Transaction Signature for randomness account creation: ",
  createRandomnessSignature
);

const sbCommitIx = await randomness.commitIx(queue); 

 // commint a winer on chain.
  const commitIx = await program.methods.commitAWinner()
  .accounts(
    {
      randomnessAccountData: randomness.pubkey
    }
  )
  .instruction();
  const commitTx = await sb.asV0Tx({
    connection: switchboardProgram.provider.connection,
    ixs: [sbCommitIx, commitIx],
    payer: wallet.publicKey,
    signers: [wallet.payer],
    computeUnitPrice: 75_000,
    computeUnitLimitMultiple: 1.3,
  });

  const commitSignature = await provider.connection.sendTransaction(commitTx);
  await provider.connection.confirmTransaction({
    signature: commitSignature,
    blockhash: blockhashContext.value.blockhash,
    lastValidBlockHeight: blockhashContext.value.lastValidBlockHeight
  });
  console.log(
    "Transaction Signature for commit: ",
    commitSignature
  );

// choose a winer
const sbRevealIx = await randomness.revealIx();
const revealIx = await program.methods.choseWiner()
  .accounts({
    randomnessAccountData: randomness.pubkey
  })
  .instruction();


const revealTx = await sb.asV0Tx({
  connection: switchboardProgram.provider.connection,
  ixs: [sbRevealIx,revealIx],
  payer: wallet.publicKey,
  signers: [wallet.payer],
  computeUnitPrice: 75_000,
  computeUnitLimitMultiple: 1.3,
});

const revealSignature = await provider.connection.sendTransaction(revealTx);
await provider.connection.confirmTransaction({
  signature: revealSignature,
  blockhash: blockhashContext.value.blockhash,
  lastValidBlockHeight: blockhashContext.value.lastValidBlockHeight
});
// await provider.connection.confirmTransaction(revealSignature,"confirmed");
console.log("Transaction Signature revealTx: ", revealSignature);

});

1
  • You might need to look through the Switchboard documentation or find a direct channel to contact them -- I don't know if they check the Stack Exchange unfortunately
    – Jon C
    Commented Aug 13 at 10:42

1 Answer 1

0

Apparently the signature is wrong.

You can checkout how to make a lottery program here: https://medium.com/@edinaldo-jr/beyond-simple-tutorials-building-a-lottery-game-on-solana-blockchain-with-anchor-and-rust-7c3d5fe3963a

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.