instructionsPage.test.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { instructionArgumentNode, instructionNode, programNode, stringTypeNode } from '@kinobi-so/nodes';
  2. import { visit } from '@kinobi-so/visitors-core';
  3. import test from 'ava';
  4. import { getRenderMapVisitor } from '../src/index.js';
  5. import { codeContains } from './_setup.js';
  6. test('it renders a public instruction data struct', t => {
  7. // Given the following program with 1 instruction.
  8. const node = programNode({
  9. instructions: [instructionNode({ name: 'mintTokens' })],
  10. name: 'splToken',
  11. publicKey: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
  12. });
  13. // When we render it.
  14. const renderMap = visit(node, getRenderMapVisitor());
  15. // Then we expect the following pub struct.
  16. codeContains(t, renderMap.get('instructions/mint_tokens.rs'), [
  17. `pub struct MintTokensInstructionData`,
  18. `pub fn new(`,
  19. ]);
  20. });
  21. test('it renders an instruction with a remainder str', t => {
  22. // Given the following program with 1 instruction.
  23. const node = programNode({
  24. instructions: [
  25. instructionNode({
  26. arguments: [
  27. instructionArgumentNode({
  28. name: 'memo',
  29. type: stringTypeNode('utf8'),
  30. }),
  31. ],
  32. name: 'addMemo',
  33. }),
  34. ],
  35. name: 'splToken',
  36. publicKey: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
  37. });
  38. // When we render it.
  39. const renderMap = visit(node, getRenderMapVisitor());
  40. // Then we expect the following pub struct.
  41. codeContains(t, renderMap.get('instructions/add_memo.rs'), [
  42. `use kaigan::types::RemainderStr`,
  43. `pub memo: RemainderStr`,
  44. ]);
  45. });