| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import {
- instructionAccountNode,
- instructionNode,
- pdaNode,
- programLinkNode,
- programNode,
- rootNode,
- } from '@kinobi-so/nodes';
- import { visit } from '@kinobi-so/visitors-core';
- import { test } from 'vitest';
- import { getRenderMapVisitor } from '../../src';
- import { renderMapContains, renderMapContainsImports } from '../_setup';
- test('it imports constants from the linked program', async () => {
- // Given the following node.
- const node = rootNode(
- programNode({
- instructions: [
- instructionNode({
- accounts: [
- instructionAccountNode({
- defaultValue: programLinkNode('someOtherProgram'),
- isSigner: false,
- isWritable: false,
- name: 'otherProgram',
- }),
- ],
- name: 'myInstruction',
- }),
- ],
- name: 'myProgram',
- pdas: [pdaNode({ name: 'counter', seeds: [] })],
- publicKey: '1111',
- }),
- [programNode({ name: 'someOtherProgram', publicKey: '2222' })],
- );
- // When we render it.
- const renderMap = visit(node, getRenderMapVisitor());
- // Then we expect the following to be exported.
- await renderMapContains(renderMap, 'instructions/myInstruction.ts', ['SOME_OTHER_PROGRAM_PROGRAM_ADDRESS']);
- // And we expect the following imports.
- await renderMapContainsImports(renderMap, 'instructions/myInstruction.ts', {
- '../programs': ['SOME_OTHER_PROGRAM_PROGRAM_ADDRESS'],
- });
- });
- test('it can override the import of a linked account', async () => {
- // Given the following node.
- const node = rootNode(
- programNode({
- instructions: [
- instructionNode({
- accounts: [
- instructionAccountNode({
- defaultValue: programLinkNode('someOtherProgram'),
- isSigner: false,
- isWritable: false,
- name: 'otherProgram',
- }),
- ],
- name: 'myInstruction',
- }),
- ],
- name: 'myProgram',
- pdas: [pdaNode({ name: 'counter', seeds: [] })],
- publicKey: '1111',
- }),
- [programNode({ name: 'someOtherProgram', publicKey: '2222' })],
- );
- // When we render it using a custom import.
- const renderMap = visit(
- node,
- getRenderMapVisitor({
- linkOverrides: {
- programs: { someOtherProgram: 'hooked' },
- },
- }),
- );
- // Then we expect the following to be exported.
- await renderMapContains(renderMap, 'instructions/myInstruction.ts', ['SOME_OTHER_PROGRAM_PROGRAM_ADDRESS']);
- // And we expect the imports to be overridden.
- await renderMapContainsImports(renderMap, 'instructions/myInstruction.ts', {
- '../../hooked': ['SOME_OTHER_PROGRAM_PROGRAM_ADDRESS'],
- });
- });
|