Skip to content

Commit 1f10648

Browse files
committed
nft-minter pinocchio: read NFT token amount as u64 BigInt in tests
Use Buffer.readBigUInt64LE so the full u64 range is represented exactly, avoiding the silent precision loss of Number arithmetic above 2^53. Addresses review feedback on PR #611.
1 parent 3aa5a29 commit 1f10648

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

  • tokens/nft-minter/pinocchio/tests

tokens/nft-minter/pinocchio/tests/test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ function getAssociatedTokenAddress(mint: PublicKey, owner: PublicKey): PublicKey
4747
)[0];
4848
}
4949

50-
// Read the `amount` field (u64 at offset 64) of an SPL token account.
51-
function readTokenAmount(data: Uint8Array): number {
52-
const buffer = Buffer.from(data);
53-
return buffer.readUInt32LE(64) + buffer.readUInt32LE(68) * 4294967296; // 2^32
50+
// Read the `amount` field (u64 at offset 64) of an SPL token account. Returns a
51+
// BigInt so the full u64 range is represented exactly (a plain Number would lose
52+
// precision above 2^53).
53+
function readTokenAmount(data: Uint8Array): bigint {
54+
return Buffer.from(data).readBigUInt64LE(64);
5455
}
5556

5657
describe("NFT Minter (Pinocchio)", async () => {
@@ -142,7 +143,7 @@ describe("NFT Minter (Pinocchio)", async () => {
142143
// The NFT (a single token) landed in the payer's associated token account.
143144
const ataAccount = await client.getAccount(ata);
144145
if (ataAccount === null) throw new Error("Associated token account not found");
145-
assert.equal(readTokenAmount(ataAccount.data), 1);
146+
assert.equal(readTokenAmount(ataAccount.data), 1n);
146147

147148
// The master edition account exists and is owned by the Token Metadata
148149
// program — proof the CreateMasterEditionV3 CPI succeeded.

0 commit comments

Comments
 (0)