idl_doc.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import * as anchor from "@project-serum/anchor";
  2. import { Program, Wallet } from "@project-serum/anchor";
  3. import { IdlDoc } from "../../target/types/idl_doc";
  4. const { expect } = require("chai");
  5. const idl_doc_idl = require("../../target/idl/idl_doc.json");
  6. describe("idl_doc", () => {
  7. // Configure the client to use the local cluster.
  8. const provider = anchor.AnchorProvider.env();
  9. const wallet = provider.wallet as Wallet;
  10. anchor.setProvider(provider);
  11. const program = anchor.workspace.IdlDoc as Program<IdlDoc>;
  12. describe("IDL doc strings", () => {
  13. const instruction = program.idl.instructions.find(
  14. (i) => i.name === "testIdlDocParse"
  15. );
  16. it("includes instruction doc comment", async () => {
  17. expect(instruction.docs).to.have.same.members([
  18. "This instruction doc should appear in the IDL",
  19. ]);
  20. });
  21. it("includes account doc comment", async () => {
  22. const act = instruction.accounts.find((i) => i.name === "act");
  23. expect(act.docs).to.have.same.members([
  24. "This account doc comment should appear in the IDL",
  25. "This is a multi-line comment",
  26. ]);
  27. });
  28. const dataWithDoc = program.idl.accounts.find(
  29. // @ts-expect-error
  30. (i) => i.name === "DataWithDoc"
  31. );
  32. it("includes accounts doc comment", async () => {
  33. expect(dataWithDoc.docs).to.have.same.members([
  34. "Custom account doc comment should appear in the IDL",
  35. ]);
  36. });
  37. it("includes account attribute doc comment", async () => {
  38. const dataField = dataWithDoc.type.fields.find((i) => i.name === "data");
  39. expect(dataField.docs).to.have.same.members([
  40. "Account attribute doc comment should appear in the IDL",
  41. ]);
  42. });
  43. });
  44. });