forked from coral-xyz/anchor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lang: add sysvar custom error and failing test case (coral-xyz#1535)
- Loading branch information
1 parent
daa2d4d
commit 94f4994
Showing
5 changed files
with
45 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,39 @@ | ||
const anchor = require("@project-serum/anchor"); | ||
const assert = require("assert"); | ||
|
||
describe("sysvars", () => { | ||
// Configure the client to use the local cluster. | ||
anchor.setProvider(anchor.Provider.local()); | ||
const program = anchor.workspace.Sysvars; | ||
|
||
it("Is initialized!", async () => { | ||
const program = anchor.workspace.Sysvars; | ||
const tx = await program.rpc.sysvars({ | ||
accounts: { | ||
const tx = await program.methods | ||
.sysvars() | ||
.accounts({ | ||
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY, | ||
rent: anchor.web3.SYSVAR_RENT_PUBKEY, | ||
stakeHistory: anchor.web3.SYSVAR_STAKE_HISTORY_PUBKEY, | ||
}, | ||
}); | ||
}) | ||
.rpc(); | ||
console.log("Your transaction signature", tx); | ||
}); | ||
|
||
it("Fails when the wrote pubkeys are provided", async () => { | ||
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"; | ||
assert.strictEqual(err.toString(), errMsg); | ||
assert.strictEqual(err.msg, errMsg); | ||
assert.strictEqual(err.code, 3015); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters