1

I'm writing some unit tests and want to test that a user cannot update data on a PDA created by another user. How can I get "another user?" I'm creating the first user:

const provider = anchor.AnchorProvider.env()
anchor.setProvider(provider)

Then

await program.methods
        .createPda('data')
        .accounts({
          user: provider.wallet.publicKey,
        })
        .rpc()

Then I want to call updatePda with another wallet like so:

await program.methods
        .updatePda('NEW DATA')
        .accounts({
          user: another_provider.another_wallet.publicKey,
        })
        .rpc()

Is this doable in anchor? Do I need a new wallet on the same provider, or do I need an entirely new provider?

1 Answer 1

2

Another user in your case is any Keypair

You can generate another Keypair using:

const user1 = anchor.web3.Keypair.generate();
const user2 = anchor.web3.Keypair.generate();

Then you can call updatePda with user1.publicKey

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.