2022-12-16 05:21:50 -08:00
|
|
|
const anchor = require("@coral-xyz/anchor");
|
2022-03-24 08:44:33 -07:00
|
|
|
const { assert } = require("chai");
|
2021-01-11 09:22:25 -08:00
|
|
|
|
2021-12-15 15:11:41 -08:00
|
|
|
describe("sysvars", () => {
|
2021-01-11 09:22:25 -08:00
|
|
|
// Configure the client to use the local cluster.
|
2022-04-11 12:48:58 -07:00
|
|
|
anchor.setProvider(anchor.AnchorProvider.local());
|
2022-03-01 08:33:18 -08:00
|
|
|
const program = anchor.workspace.Sysvars;
|
2021-01-11 09:22:25 -08:00
|
|
|
|
2021-12-15 15:11:41 -08:00
|
|
|
it("Is initialized!", async () => {
|
2022-03-01 08:33:18 -08:00
|
|
|
const tx = await program.methods
|
|
|
|
.sysvars()
|
|
|
|
.accounts({
|
2021-01-11 09:22:25 -08:00
|
|
|
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
|
|
|
|
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
|
|
stakeHistory: anchor.web3.SYSVAR_STAKE_HISTORY_PUBKEY,
|
2022-03-01 08:33:18 -08:00
|
|
|
})
|
|
|
|
.rpc();
|
2021-01-11 09:22:25 -08:00
|
|
|
console.log("Your transaction signature", tx);
|
|
|
|
});
|
2022-03-01 08:33:18 -08:00
|
|
|
|
2022-03-20 17:29:12 -07:00
|
|
|
it("Fails when the wrong pubkeys are provided", async () => {
|
2022-03-01 08:33:18 -08:00
|
|
|
try {
|
|
|
|
await program.methods
|
|
|
|
.sysvars()
|
|
|
|
.accounts({
|
|
|
|
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
|
|
|
|
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
|
|
stakeHistory: anchor.web3.SYSVAR_REWARDS_PUBKEY,
|
|
|
|
})
|
|
|
|
.rpc();
|
|
|
|
assert.ok(false);
|
|
|
|
} catch (err) {
|
|
|
|
const errMsg = "The given public key does not match the required sysvar";
|
2022-03-20 17:29:12 -07:00
|
|
|
assert.strictEqual(err.error.errorMessage, errMsg);
|
|
|
|
assert.strictEqual(err.error.errorCode.number, 3015);
|
2022-03-01 08:33:18 -08:00
|
|
|
}
|
|
|
|
});
|
2021-01-11 09:22:25 -08:00
|
|
|
});
|