Skip to main content
2 of 2
edited body
Will
  • 113
  • 4

How to generate new wallets in anchor typescript tests

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?

Will
  • 113
  • 4