sysvars.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. const anchor = require("@project-serum/anchor");
  2. const assert = require("assert");
  3. describe("sysvars", () => {
  4. // Configure the client to use the local cluster.
  5. anchor.setProvider(anchor.Provider.local());
  6. const program = anchor.workspace.Sysvars;
  7. it("Is initialized!", async () => {
  8. const tx = await program.methods
  9. .sysvars()
  10. .accounts({
  11. clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
  12. rent: anchor.web3.SYSVAR_RENT_PUBKEY,
  13. stakeHistory: anchor.web3.SYSVAR_STAKE_HISTORY_PUBKEY,
  14. })
  15. .rpc();
  16. console.log("Your transaction signature", tx);
  17. });
  18. it("Fails when the wrong pubkeys are provided", async () => {
  19. try {
  20. await program.methods
  21. .sysvars()
  22. .accounts({
  23. clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
  24. rent: anchor.web3.SYSVAR_RENT_PUBKEY,
  25. stakeHistory: anchor.web3.SYSVAR_REWARDS_PUBKEY,
  26. })
  27. .rpc();
  28. assert.ok(false);
  29. } catch (err) {
  30. const errMsg = "The given public key does not match the required sysvar";
  31. assert.strictEqual(err.error.errorMessage, errMsg);
  32. assert.strictEqual(err.error.errorCode.number, 3015);
  33. }
  34. });
  35. });