Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
protect against json stringify
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Dec 6, 2024
1 parent c082afa commit fe71082
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4557,19 +4557,23 @@ export class Connection {
context,
value: {blockhash},
} = await this.getLatestBlockhashAndContext(commitment);
const feeCalculator = {
get lamportsPerSignature(): number {
throw new Error(
'The capability to fetch `lamportsPerSignature` using the `getRecentBlockhash` API is ' +
'no longer offered by the network. Use the `getFeeForMessage` API to obtain the fee ' +
'for a given message.',
);
},
toJSON() {
return {};
},
};
return {
context,
value: {
blockhash,
feeCalculator: {
get lamportsPerSignature(): number {
throw new Error(
'The capability to fetch `lamportsPerSignature` using the `getRecentBlockhash` API is ' +
'no longer offered by the network. Use the `getFeeForMessage` API to obtain the fee ' +
'for a given message.',
);
},
},
feeCalculator,
},
};
}
Expand Down
13 changes: 13 additions & 0 deletions test/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4625,6 +4625,19 @@ describe('Connection', function () {
}
});

it('get recent blockhash can stringify', async () => {
const commitments: Commitment[] = ['processed', 'confirmed', 'finalized'];
for (const commitment of commitments) {
const response = await helpers.recentBlockhash({
connection,
commitment,
});
expect(JSON.stringify(response)).to.match(
/{"blockhash":"\w+","feeCalculator":{}}/,
);
}
});

it('get recent blockhash LPS field throws', async () => {
const commitments: Commitment[] = ['processed', 'confirmed', 'finalized'];
for (const commitment of commitments) {
Expand Down

0 comments on commit fe71082

Please sign in to comment.