-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(experimental): Introduce a
createDefaultRpc()
method to th…
…e library ## Summary You can use this to create a transport with default config. Supply only a URL. ## Test Plan ``` pnpm test:unit:browser pnpm test:unit:node ```
- Loading branch information
1 parent
c79035a
commit baaff63
Showing
6 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,9 @@ | |
"test:treeshakability:browser": "agadoo dist/index.browser.js", | ||
"test:treeshakability:native": "agadoo dist/index.node.js", | ||
"test:treeshakability:node": "agadoo dist/index.native.js", | ||
"test:typecheck": "tsc --noEmit" | ||
"test:typecheck": "tsc --noEmit", | ||
"test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent", | ||
"test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --rootDir . --silent" | ||
}, | ||
"author": "Solana Labs Maintainers <[email protected]>", | ||
"license": "MIT", | ||
|
@@ -60,10 +62,12 @@ | |
"maintained node versions" | ||
], | ||
"dependencies": { | ||
"@solana/keys": "workspace:*" | ||
"@solana/keys": "workspace:*", | ||
"@solana/rpc-transport": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@solana/eslint-config-solana": "^0.0.4", | ||
"@solana/rpc-core": "workspace:*", | ||
"@swc/core": "^1.3.18", | ||
"@swc/jest": "^0.2.23", | ||
"@types/jest": "^29.5.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { createDefaultRpc } from '../rpc'; | ||
import { SolanaJsonRpcIntegerOverflowError } from '../rpc-integer-overflow-error'; | ||
|
||
import { SolanaJsonRpcApi } from '@solana/rpc-core'; | ||
import { Transport } from '@solana/rpc-transport/dist/types/json-rpc-transport/json-rpc-transport-types'; | ||
|
||
describe('RPC', () => { | ||
let transport: Transport<SolanaJsonRpcApi>; | ||
beforeEach(() => { | ||
transport = createDefaultRpc('fake://url'); | ||
}); | ||
describe('with respect to integer overflows', () => { | ||
it('does not throw when called with a value up to `Number.MAX_SAFE_INTEGER`', () => { | ||
expect(() => { | ||
transport.getBlocks(BigInt(Number.MAX_SAFE_INTEGER)); | ||
}).not.toThrow(); | ||
}); | ||
it('does not throw when called with a value up to `-Number.MAX_SAFE_INTEGER`', () => { | ||
expect(() => { | ||
transport.getBlocks(BigInt(-Number.MAX_SAFE_INTEGER)); | ||
}).not.toThrow(); | ||
}); | ||
it('throws when called with a value greater than `Number.MAX_SAFE_INTEGER`', () => { | ||
expect(() => { | ||
transport.getBlocks(BigInt(Number.MAX_SAFE_INTEGER) + 1n); | ||
}).toThrow(SolanaJsonRpcIntegerOverflowError); | ||
}); | ||
it('throws when called with a value less than `-Number.MAX_SAFE_INTEGER`', () => { | ||
expect(() => { | ||
transport.getBlocks(BigInt(-Number.MAX_SAFE_INTEGER) - 1n); | ||
}).toThrow(SolanaJsonRpcIntegerOverflowError); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from '@solana/keys'; | ||
export * from './rpc'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { SolanaJsonRpcIntegerOverflowError } from './rpc-integer-overflow-error'; | ||
|
||
import { createJsonRpcTransport } from '@solana/rpc-transport'; | ||
|
||
export const DEFAULT_RPC_CONFIG: Partial<Parameters<typeof createJsonRpcTransport>[0]> = { | ||
onIntegerOverflow(...args) { | ||
throw new SolanaJsonRpcIntegerOverflowError(...args); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { DEFAULT_RPC_CONFIG } from './rpc-default-config'; | ||
|
||
import { SolanaJsonRpcApi } from '@solana/rpc-core'; | ||
import { createJsonRpcTransport } from '@solana/rpc-transport'; | ||
import { Transport } from '@solana/rpc-transport/dist/types/json-rpc-transport/json-rpc-transport-types'; | ||
|
||
export function createDefaultRpc(url: string): Transport<SolanaJsonRpcApi> { | ||
return createJsonRpcTransport({ | ||
...DEFAULT_RPC_CONFIG, | ||
url, | ||
}) as Transport<SolanaJsonRpcApi>; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.