Skip to content

Commit

Permalink
sdk/js-query: solana mock band-aid
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-gray committed Feb 17, 2024
1 parent eee4641 commit 00f504e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 37 deletions.
6 changes: 6 additions & 0 deletions sdk/js-query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.0.10

Fix SolanaAccount mock for bad rentEpoch parsing

Add axios as dependency to avoid errors for mock users

## 0.0.9

Fix SolanaAccount mock for minContextSlot
Expand Down
50 changes: 16 additions & 34 deletions sdk/js-query/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions sdk/js-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/wormhole-query-sdk",
"version": "0.0.9",
"version": "0.0.10",
"description": "Wormhole cross-chain query SDK",
"homepage": "https://wormhole.com",
"main": "./lib/cjs/index.js",
Expand All @@ -24,7 +24,6 @@
"license": "Apache-2.0",
"devDependencies": {
"@types/bs58": "^4.0.4",
"axios": "^1.4.0",
"jest": "^29.5.0",
"prettier": "^2.3.2",
"ts-jest": "^29.1.0",
Expand All @@ -36,6 +35,7 @@
"dependencies": {
"@ethersproject/keccak256": "^5.7.0",
"@types/elliptic": "^6.4.14",
"axios": "^1.6.7",
"bs58": "^4.0.1",
"buffer": "^6.0.3",
"elliptic": "^6.5.4"
Expand Down
12 changes: 11 additions & 1 deletion sdk/js-query/src/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import {
} from "../query";
import { BinaryWriter } from "../query/BinaryWriter";

// (2**64)-1
const SOLANA_MAX_RENT_EPOCH = BigInt("18446744073709551615");

interface SolanaGetMultipleAccountsOpts {
commitment: string;
minContextSlot?: number;
Expand Down Expand Up @@ -440,9 +443,16 @@ export class QueryProxyMock {
const slotNumber = response.data.result.context.slot;
let results: SolanaAccountResult[] = [];
response.data.result.value.forEach((val) => {
const rentEpoch = BigInt(val.rentEpoch);
results.push({
lamports: BigInt(val.lamports),
rentEpoch: BigInt(val.rentEpoch),
rentEpoch:
// this is a band-aid for an axios / JSON.parse effect where numbers > Number.MAX_SAFE_INTEGER are not parsed correctly
// e.g. 18446744073709551615 becomes 18446744073709552000
// https://github.com/axios/axios/issues/4846
rentEpoch > SOLANA_MAX_RENT_EPOCH
? SOLANA_MAX_RENT_EPOCH
: rentEpoch,
executable: Boolean(val.executable),
owner: Uint8Array.from(base58.decode(val.owner.toString())),
data: Uint8Array.from(
Expand Down

0 comments on commit 00f504e

Please sign in to comment.