codama-idl / codama

Generate clients, CLIs, documentation and more from your Solana programs
MIT License
73 stars 16 forks source link

fix: render PDA helper with programAddress = node.programId if defined #52

Closed lithdew closed 4 months ago

lithdew commented 4 months ago

PDA helpers should generate PDA's with a default programAddress set to the provided PDA nodes' programId if programId is defined. If not defined, the default programAddress should be the encapsulating program node programId.

With this PR, the following test passes. All tests are passing locally. A changeset has been included.

test('it renders a PDA helper function with a default program address', async () => {
    // Given the following PDA node with a default program address.
    const node = programNode({
        name: 'myProgram',
        pdas: [
            pdaNode({
                name: 'foo',
                programId: 'myProgramId',
                seeds: [constantPdaSeedNodeFromString('utf8', 'myPrefix')],
            }),
        ],
        publicKey: '1111',
    });

    // When we render it.
    const renderMap = visit(node, getRenderMapVisitor());

    // Then we expect the following PDA function using the programId as the default program address.
    await renderMapContains(renderMap, 'pdas/foo.ts', [
        'export async function findFooPda',
        "const { programAddress = 'myProgramId' as Address<'myProgramId'> } = config;",
    ]);
});
changeset-bot[bot] commented 4 months ago

🦋 Changeset detected

Latest commit: 4bb13bf6c3aeebeb0726c421083c522153f40e3a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages | Name | Type | | ----------------------- | ----- | | @kinobi-so/renderers-js | Patch | | @kinobi-so/renderers | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR