Skip to content

Commit 4979b94

Browse files
authored
fix: convert name to camel case before searching argument nodes for a match (#109)
1 parent 6daf60c commit 4979b94

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

.changeset/small-jars-play.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@kinobi-so/nodes-from-anchor": patch
3+
---
4+
5+
Fix argument node lookup for anchor v01 instruction pda seeds.

packages/nodes-from-anchor/src/v01/InstructionAccountNode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ export function instructionAccountNodeFromAnchorV01(
105105
}
106106
}
107107
case 'arg': {
108-
const argumentNode = instructionArguments.find(({ name }) => name === seed.path);
108+
const argumentName = camelCase(seed.path);
109+
const argumentNode = instructionArguments.find(({ name }) => name === argumentName);
109110
if (!argumentNode) {
110111
throw new KinobiError(KINOBI_ERROR__ANCHOR__ARGUMENT_TYPE_MISSING, { name: seed.path });
111112
}

packages/nodes-from-anchor/test/v01/ProgramNode.test.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
accountNode,
33
accountValueNode,
4+
argumentValueNode,
45
bytesTypeNode,
56
constantPdaSeedNodeFromBytes,
67
errorNode,
@@ -9,6 +10,7 @@ import {
910
instructionAccountNode,
1011
instructionArgumentNode,
1112
instructionNode,
13+
numberTypeNode,
1214
pdaNode,
1315
pdaSeedValueNode,
1416
pdaValueNode,
@@ -36,6 +38,7 @@ test('it creates program nodes', () => {
3638
seeds: [
3739
{ kind: 'const', value: [42, 31, 29] },
3840
{ kind: 'account', path: 'owner' },
41+
{ kind: 'arg', path: 'amount' },
3942
],
4043
},
4144
},
@@ -46,12 +49,17 @@ test('it creates program nodes', () => {
4649
name: 'some_account',
4750
},
4851
],
49-
args: [],
52+
args: [
53+
{
54+
name: 'amount',
55+
type: 'u8',
56+
},
57+
],
5058
discriminator: [246, 28, 6, 87, 251, 45, 50, 42],
51-
name: 'myInstruction',
59+
name: 'my_instruction',
5260
},
5361
],
54-
metadata: { name: 'myProgram', spec: '0.1.0', version: '1.2.3' },
62+
metadata: { name: 'my_program', spec: '0.1.0', version: '1.2.3' },
5563
types: [{ name: 'MyAccount', type: { fields: [{ name: 'delegate', type: 'pubkey' }], kind: 'struct' } }],
5664
});
5765

@@ -94,9 +102,13 @@ test('it creates program nodes', () => {
94102
seeds: [
95103
constantPdaSeedNodeFromBytes('base16', '2a1f1d'),
96104
variablePdaSeedNode('owner', publicKeyTypeNode()),
105+
variablePdaSeedNode('amount', numberTypeNode('u8')),
97106
],
98107
}),
99-
[pdaSeedValueNode('owner', accountValueNode('owner'))],
108+
[
109+
pdaSeedValueNode('owner', accountValueNode('owner')),
110+
pdaSeedValueNode('amount', argumentValueNode('amount')),
111+
],
100112
),
101113
isSigner: false,
102114
isWritable: false,
@@ -120,6 +132,7 @@ test('it creates program nodes', () => {
120132
name: 'discriminator',
121133
type: fixedSizeTypeNode(bytesTypeNode(), 8),
122134
}),
135+
instructionArgumentNode({ name: 'amount', type: numberTypeNode('u8') }),
123136
],
124137
discriminators: [fieldDiscriminatorNode('discriminator')],
125138
name: 'myInstruction',

0 commit comments

Comments
 (0)