Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

project-8-token-lottery: Error InvalidSecpSignature when run anchor test #1

Open
tiulinh opened this issue Aug 9, 2024 · 0 comments

Comments

@tiulinh
Copy link

tiulinh commented Aug 9, 2024

Hello admin.
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!
image

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);
   

  });


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant