Skip to content

Commit 11fec4b

Browse files
fix token-metadata decoder; add skip-preflight option (#64)
1 parent 2b5e26b commit 11fec4b

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

test-helpers/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tensor-foundation/test-helpers",
3-
"version": "0.5.0",
3+
"version": "0.6.0",
44
"description": "Utility functions for testing Solana programs with the Solana Web3.js library",
55
"sideEffects": false,
66
"module": "./dist/src/index.mjs",

test-helpers/src/token/extensions/index.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
addDecoderSizePrefix,
33
Decoder,
4+
getAddressDecoder,
45
getArrayDecoder,
56
getStructDecoder,
67
getU32Decoder,
@@ -88,15 +89,18 @@ function deserializeTransferHook(extensionBytes: Uint8Array): TransferHook {
8889
}
8990

9091
function deserializeTokenMetadata(extensionBytes: Uint8Array): TokenMetadata {
91-
const updateAuthority = toAddress(extensionBytes.slice(0, 32));
92-
const mint = toAddress(extensionBytes.slice(32, 64));
93-
const name = getUtf8Decoder().decode(extensionBytes);
94-
const symbol = getUtf8Decoder().decode(extensionBytes);
95-
const uri = getUtf8Decoder().decode(extensionBytes);
96-
const additionalMetadata =
97-
getAdditionalMetadataDecoder().decode(extensionBytes);
98-
99-
return { updateAuthority, mint, name, symbol, uri, additionalMetadata };
92+
return getTokenMetadataDecoder().decode(extensionBytes);
93+
}
94+
95+
function getTokenMetadataDecoder(): Decoder<TokenMetadata> {
96+
return getStructDecoder([
97+
['updateAuthority', getAddressDecoder()],
98+
['mint', getAddressDecoder()],
99+
['name', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
100+
['symbol', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
101+
['uri', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
102+
['additionalMetadata', getAdditionalMetadataDecoder()],
103+
]);
100104
}
101105

102106
function getAdditionalMetadataDecoder(): Decoder<AdditionalMetadata[]> {

test-helpers/src/wns/createNft.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface CreateNftArgs {
4646
group?: Address;
4747
data?: NftData;
4848
paymentMint?: Address;
49+
skipPreflight?: boolean;
4950
}
5051

5152
export interface NftData {
@@ -64,6 +65,7 @@ export interface CreateGroupArgs {
6465
mint?: TransactionSigner;
6566
paymentMint?: Address;
6667
data?: GroupData;
68+
skipPreflight?: boolean;
6769
}
6870

6971
export interface GroupData {
@@ -144,13 +146,14 @@ export async function createGroupWithRoyalties(
144146
await pipe(
145147
await createDefaultTransaction(client, payer),
146148
(tx) => appendTransactionMessageInstructions(instructions, tx),
147-
(tx) => signAndSendTransaction(client, tx)
149+
(tx) =>
150+
signAndSendTransaction(client, tx, { skipPreflight: args.skipPreflight })
148151
);
149152

150153
return { group, mint: mint.address, distribution: distributionAccount };
151154
}
152155

153-
const testNftData: NftData = {
156+
export const testNftData: NftData = {
154157
name: 'Test WNS',
155158
symbol: 'TWNS',
156159
uri: 'https://example.com/wns',
@@ -234,7 +237,8 @@ export async function createNft(args: CreateNftArgs): Promise<{
234237
tx
235238
)
236239
: (tx) => tx,
237-
(tx) => signAndSendTransaction(client, tx)
240+
(tx) =>
241+
signAndSendTransaction(client, tx, { skipPreflight: args.skipPreflight })
238242
);
239243

240244
// Hacky--there's probably a better way to do this.

test-helpers/test/wns.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
deserializeExtension,
1010
ExtensionType,
1111
findExtraAccountMetaAddress,
12+
testNftData,
1213
TOKEN22_PROGRAM_ID,
1314
tokenSetup,
1415
} from '../src/index.js';
@@ -137,4 +138,19 @@ test('create nft with createWnsNftInGroup', async (t) => {
137138

138139
t.assert(extraMetasAccount);
139140
t.assert(extraMetasAccount!.owner === WEN_NEW_STANDARD_PROGRAM_ADDRESS);
141+
142+
const tokenMetadata = deserializeExtension(data, ExtensionType.TokenMetadata);
143+
t.assert(tokenMetadata?.updateAuthority === authority.address);
144+
t.assert(tokenMetadata?.mint === mint);
145+
t.assert(tokenMetadata?.name === testNftData.name);
146+
t.assert(tokenMetadata?.symbol === testNftData.symbol);
147+
t.assert(tokenMetadata?.uri === testNftData.uri);
148+
t.assert(tokenMetadata?.additionalMetadata.length === 2);
149+
t.assert(tokenMetadata?.additionalMetadata[0].key === 'royalty_basis_points');
150+
t.assert(
151+
tokenMetadata?.additionalMetadata[0].value ===
152+
testNftData.royaltyBasisPoints.toString()
153+
);
154+
t.assert(tokenMetadata?.additionalMetadata[1].key === authority.address);
155+
t.assert(tokenMetadata?.additionalMetadata[1].value === '100');
140156
});

0 commit comments

Comments
 (0)