AccountNode.test.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {
  2. accountNode,
  3. bytesTypeNode,
  4. bytesValueNode,
  5. fieldDiscriminatorNode,
  6. numberTypeNode,
  7. structFieldTypeNode,
  8. structTypeNode,
  9. } from '@kinobi-so/nodes';
  10. import { expect, test } from 'vitest';
  11. import { accountNodeFromAnchorV00 } from '../../src';
  12. test('it creates account nodes', () => {
  13. const node = accountNodeFromAnchorV00({
  14. name: 'myAccount',
  15. type: {
  16. fields: [{ name: 'myField', type: 'u64' }],
  17. kind: 'struct',
  18. },
  19. });
  20. expect(node).toEqual(
  21. accountNode({
  22. data: structTypeNode([
  23. structFieldTypeNode({
  24. name: 'myField',
  25. type: numberTypeNode('u64'),
  26. }),
  27. ]),
  28. name: 'myAccount',
  29. }),
  30. );
  31. });
  32. test('it creates account nodes with anchor discriminators', () => {
  33. const node = accountNodeFromAnchorV00(
  34. {
  35. name: 'myAccount',
  36. type: { fields: [], kind: 'struct' },
  37. },
  38. 'anchor',
  39. );
  40. expect(node).toEqual(
  41. accountNode({
  42. data: structTypeNode([
  43. structFieldTypeNode({
  44. defaultValue: bytesValueNode('base16', 'f61c0657fb2d322a'),
  45. defaultValueStrategy: 'omitted',
  46. name: 'discriminator',
  47. type: bytesTypeNode(),
  48. }),
  49. ]),
  50. discriminators: [fieldDiscriminatorNode('discriminator')],
  51. name: 'myAccount',
  52. }),
  53. );
  54. });