docs.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { Program } from "@coral-xyz/anchor";
  3. import { assert } from "chai";
  4. import { Docs } from "../target/types/docs";
  5. describe("Docs", () => {
  6. anchor.setProvider(anchor.AnchorProvider.env());
  7. const program = anchor.workspace.docs as Program<Docs>;
  8. const instruction = program.idl.instructions.find(
  9. (i) => i.name === "testIdlDocParse"
  10. );
  11. it("includes instruction doc comment", () => {
  12. assert.deepEqual(instruction.docs, [
  13. "This instruction doc should appear in the IDL",
  14. ]);
  15. });
  16. it("includes account doc comment", () => {
  17. const act = instruction.accounts.find((i) => i.name === "act");
  18. assert.deepEqual(act.docs, [
  19. "This account doc comment should appear in the IDL",
  20. "This is a multi-line comment",
  21. ]);
  22. });
  23. const dataWithDoc = program.idl.accounts.find(
  24. // @ts-expect-error
  25. (acc) => acc.name === "DataWithDoc"
  26. );
  27. it("includes accounts doc comment", () => {
  28. assert.deepEqual(dataWithDoc.docs, [
  29. "Custom account doc comment should appear in the IDL",
  30. ]);
  31. });
  32. it("includes account attribute doc comment", () => {
  33. const dataField = dataWithDoc.type.fields.find((i) => i.name === "data");
  34. assert.deepEqual(dataField.docs, [
  35. "Account attribute doc comment should appear in the IDL",
  36. ]);
  37. });
  38. });