InstructionNode.test.ts 718 B

123456789101112131415161718192021
  1. import { instructionArgumentNode, instructionNode, numberTypeNode } from '@codama/nodes';
  2. import { expect, test } from 'vitest';
  3. import { getNodeCodec } from '../../src';
  4. import { hex } from '../_setup';
  5. test('it delegates to the instruction arguments as a struct', () => {
  6. const codec = getNodeCodec([
  7. instructionNode({
  8. arguments: [
  9. instructionArgumentNode({
  10. name: 'foo',
  11. type: numberTypeNode('u32'),
  12. }),
  13. ],
  14. name: 'myInstruction',
  15. }),
  16. ]);
  17. expect(codec.encode({ foo: 42 })).toStrictEqual(hex('2a000000'));
  18. expect(codec.decode(hex('2a000000'))).toStrictEqual({ foo: 42 });
  19. });