discriminator.test.ts 1004 B

1234567891011121314151617181920212223242526
  1. import { bytesValueNode } from '@kinobi-so/nodes';
  2. import { expect, test } from 'vitest';
  3. import { getAnchorAccountDiscriminator, getAnchorInstructionDiscriminator } from '../src';
  4. test('it can compute the discriminator of an Anchor account', () => {
  5. // Given an account named "StakeEntry" on the IDL.
  6. const idlName = 'StakeEntry';
  7. // When we compute its Anchor discriminator.
  8. const discriminator = getAnchorAccountDiscriminator(idlName);
  9. // Then we get the expected value.
  10. expect(discriminator).toEqual(bytesValueNode('base16', 'bb7f09239b445628'));
  11. });
  12. test('it can compute the discriminator of an Anchor instruction', () => {
  13. // Given an instruction named "addConfigLines" on the IDL.
  14. const idlName = 'addConfigLines';
  15. // When we compute its Anchor discriminator.
  16. const discriminator = getAnchorInstructionDiscriminator(idlName);
  17. // Then we get the expected value.
  18. expect(discriminator).toEqual(bytesValueNode('base16', 'df32e0e39708736a'));
  19. });