Skip to main content
added 237 characters in body
Source Link
Concise Labs
  • 1.4k
  • 3
  • 13

The usual way of using testing using a different user is, first you would create the keypair of the user.

const newUser = anchor.web3.Keypair.generate();

Then you would have to fund this user account so that they can pay the gas fees and sign the transaction. This would go inside a test, something like

it("initialize program state", async () => {
    await provider.connection.confirmTransaction(
        await provider.connection.requestAirdrop(
            newUser.publicKey,
            10000000000
        ),
        "confirmed"
    );
);

Then, all you would need to do is add newUser in the signer'ssigners array while making the rpc call.

Sometimes testing with multiple users becomes necessary when, for example you have a program which allows only certain whitelisted addresses to sign certain transactions. Then you would need to test those cases using multiple users.

The usual way of using testing using a different user is, first you would create the keypair of the user.

const newUser = anchor.web3.Keypair.generate();

Then you would have to fund this user account so that they can pay the gas fees and sign the transaction. This would go inside a test, something like

it("initialize program state", async () => {
    await provider.connection.confirmTransaction(
        await provider.connection.requestAirdrop(
            newUser.publicKey,
            10000000000
        ),
        "confirmed"
    );
);

Then, all you would need to do is add newUser in the signer's array while making the rpc call.

The usual way of using testing using a different user is, first you would create the keypair of the user.

const newUser = anchor.web3.Keypair.generate();

Then you would have to fund this user account so that they can pay the gas fees and sign the transaction. This would go inside a test, something like

it("initialize program state", async () => {
    await provider.connection.confirmTransaction(
        await provider.connection.requestAirdrop(
            newUser.publicKey,
            10000000000
        ),
        "confirmed"
    );
);

Then, all you would need to do is add newUser in the signers array while making the rpc call.

Sometimes testing with multiple users becomes necessary when, for example you have a program which allows only certain whitelisted addresses to sign certain transactions. Then you would need to test those cases using multiple users.

Source Link
Concise Labs
  • 1.4k
  • 3
  • 13

The usual way of using testing using a different user is, first you would create the keypair of the user.

const newUser = anchor.web3.Keypair.generate();

Then you would have to fund this user account so that they can pay the gas fees and sign the transaction. This would go inside a test, something like

it("initialize program state", async () => {
    await provider.connection.confirmTransaction(
        await provider.connection.requestAirdrop(
            newUser.publicKey,
            10000000000
        ),
        "confirmed"
    );
);

Then, all you would need to do is add newUser in the signer's array while making the rpc call.