|
@@ -8,24 +8,29 @@ describe("IDL", () => {
|
|
|
anchor.setProvider(anchor.AnchorProvider.env());
|
|
|
const program = anchor.workspace.idl as Program<Idl>;
|
|
|
|
|
|
- it("Should include `FOO_CONST`", () => {
|
|
|
- assert.isDefined(
|
|
|
- program.idl.constants.find(
|
|
|
- (c) =>
|
|
|
- c.name === "FOO_CONST" && c.type === "u128" && c.value === "1000000"
|
|
|
- )
|
|
|
- );
|
|
|
- });
|
|
|
+ it("Includes constants that use `#[constant]` macro", () => {
|
|
|
+ const checkDefined = (
|
|
|
+ cb: (constant: typeof program["idl"]["constants"][number]) => boolean
|
|
|
+ ) => {
|
|
|
+ program.idl.constants.find((c) => cb(c));
|
|
|
+ };
|
|
|
|
|
|
- it("Should include `BAR_CONST`", () => {
|
|
|
- assert.isDefined(
|
|
|
- program.idl.constants.find(
|
|
|
- (c) => c.name === "BAR_CONST" && c.type === "u8" && c.value === "6"
|
|
|
- )
|
|
|
+ checkDefined((c) => c.name === "U8" && c.type === "u8" && c.value === "6");
|
|
|
+ checkDefined(
|
|
|
+ (c) => c.name === "I128" && c.type === "i128" && c.value === "1000000"
|
|
|
+ );
|
|
|
+ checkDefined(
|
|
|
+ (c) => c.name === "BYTE_STR" && c.type === "u8" && c.value === "116"
|
|
|
+ );
|
|
|
+ checkDefined(
|
|
|
+ (c) =>
|
|
|
+ c.name === "BYTES_STR" &&
|
|
|
+ c.type === "bytes" &&
|
|
|
+ c.value === "[116, 101, 115, 116]"
|
|
|
);
|
|
|
});
|
|
|
|
|
|
- it("Should not include `NO_IDL` const", () => {
|
|
|
+ it("Does not include constants that does not use `#[constant]` macro ", () => {
|
|
|
// @ts-expect-error
|
|
|
assert.isUndefined(program.idl.constants.find((c) => c.name === "NO_IDL"));
|
|
|
});
|