Skip to content

Commit

Permalink
Use remainder str type (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
febo authored and lorisleiva committed Apr 19, 2024
1 parent 3f9e025 commit 7088cc4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-apples-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@metaplex-foundation/kinobi": patch
---

Use remainder str type in Rust client
4 changes: 2 additions & 2 deletions src/renderers/rust/getTypeManifestVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ export function getTypeManifestVisitor() {
visitStringType() {
if (!parentSize) {
return {
type: `&str`,
imports: new RustImportMap(),
type: `RemainderStr`,
imports: new RustImportMap().add(`kaigan::types::RemainderStr`),
nestedStructs: [],
};
}
Expand Down
30 changes: 29 additions & 1 deletion test/renderers/rust/instructionsPage.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import { instructionNode, programNode, visit } from '../../../src';
import { instructionArgumentNode, instructionNode, programNode, remainderSizeNode, stringTypeNode, visit } from '../../../src';

Check failure on line 2 in test/renderers/rust/instructionsPage.test.ts

View workflow job for this annotation

GitHub Actions / Test (16.x)

Module '"../../../src"' has no exported member 'remainderSizeNode'.

Check failure on line 2 in test/renderers/rust/instructionsPage.test.ts

View workflow job for this annotation

GitHub Actions / Test (18.x)

Module '"../../../src"' has no exported member 'remainderSizeNode'.
import { getRenderMapVisitor } from '../../../src/renderers/rust/getRenderMapVisitor';
import { codeContains } from './_setup';

Expand All @@ -20,3 +20,31 @@ test('it renders a public instruction data struct', (t) => {
`pub fn new(`,
]);
});

test('it renders an instruction with a remainder str', (t) => {
// Given the following program with 1 instruction.
const node = programNode({
name: 'splToken',
publicKey: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
instructions: [
instructionNode({
name: 'addMemo',
arguments: [
instructionArgumentNode({
name: 'memo',
type: stringTypeNode({ size: remainderSizeNode() }),

Check failure on line 35 in test/renderers/rust/instructionsPage.test.ts

View workflow job for this annotation

GitHub Actions / Test (16.x)

Argument of type '{ size: any; }' is not assignable to parameter of type 'StringEncoding'.

Check failure on line 35 in test/renderers/rust/instructionsPage.test.ts

View workflow job for this annotation

GitHub Actions / Test (18.x)

Argument of type '{ size: any; }' is not assignable to parameter of type 'StringEncoding'.
}),
],
}),
],
});

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

// Then we expect the following pub struct.
codeContains(t, renderMap.get('instructions/add_memo.rs'), [
`use kaigan::types::RemainderStr`,
`pub memo: RemainderStr`,
]);
});

0 comments on commit 7088cc4

Please sign in to comment.