Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions clients/js-legacy/tests/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,42 @@ test('update metadata', async (t) => {
);
});

test('update metadata with non-ascii name', async (t) => {
const authorizedWithdrawer = new Keypair();

const context = await startWithContext(authorizedWithdrawer.publicKey);
const svm = context.svm;
const payer = context.payer;
const connection = new LiteConnection(svm, payer);

const voteAccountAddress = new PublicKey(voteAccount.pubkey);
const poolAddress = await findPoolAddress(SinglePoolProgram.programId, voteAccountAddress);
const poolMintAddress = await findPoolMintAddress(SinglePoolProgram.programId, poolAddress);
const poolMetadataAddress = findMplMetadataAddress(poolMintAddress);

let transaction = await SinglePoolProgram.initialize(
connection,
voteAccountAddress,
payer.publicKey,
);
await processTransaction(context, transaction);

const newName = 'Café Staking ☀';
const newSymbol = 'stkÉ';
transaction = await SinglePoolProgram.updateTokenMetadata(
voteAccountAddress,
authorizedWithdrawer.publicKey,
newName,
newSymbol,
);
await processTransaction(context, transaction, [authorizedWithdrawer]);

const metadataAccount = svm.getAccount(poolMetadataAddress);
const metadata = new TextDecoder().decode(metadataAccount.data);
t.true(metadata.indexOf(newName) > -1, 'metadata name has been updated');
t.true(metadata.indexOf(newSymbol) > -1, 'metadata symbol has been updated');
});

test('get vote account address', async (t) => {
const context = await startWithContext();
const svm = context.svm;
Expand Down
15 changes: 9 additions & 6 deletions clients/js/src/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,17 @@ export async function updateTokenMetadataInstruction(
const mplMetadata = await findMplMetadataAddress(mint);

const text = new TextEncoder();
const nameBytes = text.encode(tokenName);
const symbolBytes = text.encode(tokenSymbol);
const uriBytes = text.encode(tokenUri);
const data = new Uint8Array([
SinglePoolInstructionType.UpdateTokenMetadata,
...getU32Encoder().encode(tokenName.length),
...text.encode(tokenName),
...getU32Encoder().encode(tokenSymbol.length),
...text.encode(tokenSymbol),
...getU32Encoder().encode(tokenUri.length),
...text.encode(tokenUri),
...getU32Encoder().encode(nameBytes.length),
...nameBytes,
...getU32Encoder().encode(symbolBytes.length),
...symbolBytes,
...getU32Encoder().encode(uriBytes.length),
...uriBytes,
]);

return {
Expand Down
Loading