workspace.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { assert } from "chai";
  3. describe("Workspace", () => {
  4. anchor.setProvider(anchor.AnchorProvider.env());
  5. it("Can lazy load workspace programs", () => {
  6. assert.doesNotThrow(() => {
  7. // Program exists, should not throw
  8. anchor.workspace.relationsDerivation;
  9. });
  10. assert.throws(() => {
  11. // IDL path in Anchor.toml doesn't exist but other tests still run
  12. // successfully because workspace programs are getting loaded on-demand
  13. anchor.workspace.nonExistent;
  14. }, /non-existent\.json/);
  15. });
  16. it("Can get workspace programs by their name independent of casing", () => {
  17. const camel = anchor.workspace.relationsDerivation;
  18. const pascal = anchor.workspace.RelationsDerivation;
  19. const kebab = anchor.workspace["relations-derivation"];
  20. const snake = anchor.workspace["relations_derivation"];
  21. const compareProgramNames = (...programs: anchor.Program[]) => {
  22. return programs.every(
  23. (program) => program.rawIdl.metadata.name === "relations_derivation"
  24. );
  25. };
  26. assert(compareProgramNames(camel, pascal, kebab, snake));
  27. });
  28. it("Can use numbers in program names", () => {
  29. assert.doesNotThrow(() => {
  30. anchor.workspace.numbers123;
  31. anchor.workspace.Numbers123;
  32. anchor.workspace["numbers-123"];
  33. anchor.workspace["numbers_123"];
  34. });
  35. });
  36. });