idl.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { Program } from "@coral-xyz/anchor";
  3. import { assert } from "chai";
  4. import { Idl } from "../target/types/idl";
  5. describe("IDL", () => {
  6. anchor.setProvider(anchor.AnchorProvider.env());
  7. const program = anchor.workspace.idl as Program<Idl>;
  8. it("Includes constants that use `#[constant]` macro", () => {
  9. const checkDefined = (
  10. cb: (constant: typeof program["idl"]["constants"][number]) => boolean
  11. ) => {
  12. program.idl.constants.find((c) => cb(c));
  13. };
  14. checkDefined((c) => c.name === "U8" && c.type === "u8" && c.value === "6");
  15. checkDefined(
  16. (c) => c.name === "I128" && c.type === "i128" && c.value === "1000000"
  17. );
  18. checkDefined(
  19. (c) => c.name === "BYTE_STR" && c.type === "u8" && c.value === "116"
  20. );
  21. checkDefined(
  22. (c) =>
  23. c.name === "BYTES_STR" &&
  24. c.type === "bytes" &&
  25. c.value === "[116, 101, 115, 116]"
  26. );
  27. });
  28. it("Does not include constants that does not use `#[constant]` macro ", () => {
  29. // @ts-expect-error
  30. assert.isUndefined(program.idl.constants.find((c) => c.name === "NO_IDL"));
  31. });
  32. });