-
Notifications
You must be signed in to change notification settings - Fork 853
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(experimental): add getIdentity API method
- Loading branch information
1 parent
f55f3e7
commit e3d9540
Showing
4 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
packages/rpc-core/src/rpc-methods/__tests__/get-identity-test.ts
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,30 @@ | ||
import { base58 } from '@metaplex-foundation/umi-serializers'; | ||
import { createHttpTransport, createJsonRpc } from '@solana/rpc-transport'; | ||
import type { Rpc } from '@solana/rpc-transport/dist/types/json-rpc-types'; | ||
import fetchMock from 'jest-fetch-mock-fork'; | ||
|
||
import validatorIdentityBytes from '../../../../../test-ledger/validator-keypair.json'; | ||
import { createSolanaRpcApi, SolanaRpcMethods } from '../index'; | ||
|
||
describe('getIdentity', () => { | ||
let rpc: Rpc<SolanaRpcMethods>; | ||
beforeEach(() => { | ||
fetchMock.resetMocks(); | ||
fetchMock.dontMock(); | ||
rpc = createJsonRpc<SolanaRpcMethods>({ | ||
api: createSolanaRpcApi(), | ||
transport: createHttpTransport({ url: 'http://127.0.0.1:8899' }), | ||
}); | ||
}); | ||
|
||
it('returns the identity of the currently running local validator', async () => { | ||
expect.assertions(1); | ||
const secretKey = new Uint8Array(validatorIdentityBytes); | ||
const publicKey = secretKey.slice(32, 64); | ||
const expectedAddress = base58.deserialize(publicKey)[0]; | ||
const identityPromise = rpc.getIdentity().send(); | ||
await expect(identityPromise).resolves.toMatchObject({ | ||
identity: expectedAddress, | ||
}); | ||
}); | ||
}); |
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,15 @@ | ||
import { Base58EncodedAddress } from '@solana/addresses'; | ||
|
||
type GetIdentityApiResponse = Readonly<{ | ||
identity: Base58EncodedAddress; | ||
}>; | ||
|
||
export interface GetIdentityApi { | ||
/** | ||
* Returns the identity pubkey for the current node | ||
*/ | ||
getIdentity( | ||
// FIXME: https://github.com/solana-labs/solana-web3.js/issues/1389 | ||
NO_CONFIG?: Record<string, never> | ||
): GetIdentityApiResponse; | ||
} |
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
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