| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import {
- instructionAccountNode,
- instructionNode,
- pdaLinkNode,
- pdaNode,
- pdaValueNode,
- programNode,
- } 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 functions from the linked pda', async () => {
- // Given the following node.
- const node = programNode({
- instructions: [
- instructionNode({
- accounts: [
- instructionAccountNode({
- defaultValue: pdaValueNode(pdaLinkNode('counter')),
- isSigner: true,
- isWritable: true,
- name: 'counter',
- }),
- ],
- name: 'createCounter',
- }),
- ],
- name: 'myProgram',
- pdas: [pdaNode({ name: 'counter', seeds: [] })],
- publicKey: '1111',
- });
- // When we render it.
- const renderMap = visit(node, getRenderMapVisitor());
- // Then we expect the following to be exported.
- await renderMapContains(renderMap, 'instructions/createCounter.ts', ['await findCounterPda()']);
- // And we expect the following imports.
- await renderMapContainsImports(renderMap, 'instructions/createCounter.ts', {
- '../pdas': ['findCounterPda'],
- });
- });
- test('it can override the import of a linked account', async () => {
- // Given the following node.
- const node = programNode({
- instructions: [
- instructionNode({
- accounts: [
- instructionAccountNode({
- defaultValue: pdaValueNode(pdaLinkNode('counter')),
- isSigner: true,
- isWritable: true,
- name: 'counter',
- }),
- ],
- name: 'createCounter',
- }),
- ],
- name: 'myProgram',
- pdas: [pdaNode({ name: 'counter', seeds: [] })],
- publicKey: '1111',
- });
- // When we render it using a custom import.
- const renderMap = visit(
- node,
- getRenderMapVisitor({
- linkOverrides: {
- pdas: { counter: 'hooked' },
- },
- }),
- );
- // Then we expect the following to be exported.
- await renderMapContains(renderMap, 'instructions/createCounter.ts', ['await findCounterPda()']);
- // And we expect the imports to be overridden.
- await renderMapContainsImports(renderMap, 'instructions/createCounter.ts', {
- '../../hooked': ['findCounterPda'],
- });
- });
|