From 23420ecebc6881b5379bf83883d774bd3080e83e Mon Sep 17 00:00:00 2001 From: Callum McIntyre Date: Thu, 11 Jan 2024 10:46:34 +0000 Subject: [PATCH] Fix return type of getTokenAccountsByDelegate/Owner (#2027) --- .../__typetests__/rpc-methods-test.ts | 36 +++++++++++++++++++ .../rpc-methods/getTokenAccountsByDelegate.ts | 4 +-- .../rpc-methods/getTokenAccountsByOwner.ts | 4 +-- 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 packages/rpc-core/src/rpc-methods/__typetests__/rpc-methods-test.ts diff --git a/packages/rpc-core/src/rpc-methods/__typetests__/rpc-methods-test.ts b/packages/rpc-core/src/rpc-methods/__typetests__/rpc-methods-test.ts new file mode 100644 index 00000000000..d38874b4368 --- /dev/null +++ b/packages/rpc-core/src/rpc-methods/__typetests__/rpc-methods-test.ts @@ -0,0 +1,36 @@ +import { Address } from '@solana/addresses'; +import { Rpc } from '@solana/rpc-transport'; + +import { SolanaRpcMethods } from '..'; + +const rpc = {} as unknown as Rpc; + +// getTokenAccountsByDelegate +async () => { + const tokenAccountsByDelegate = await rpc + .getTokenAccountsByDelegate( + 'delegate' as Address, + { programId: 'program' as Address }, + { encoding: 'jsonParsed' }, + ) + .send(); + + const firstAccount = tokenAccountsByDelegate.value[0]; + firstAccount.pubkey satisfies Address; + firstAccount.account.data.program satisfies Address; + firstAccount.account.data.parsed.type satisfies 'account'; + firstAccount.account.data.parsed.info.mint satisfies Address; +}; + +// getTokenAccountsByOwner +async () => { + const tokenAccountsByOwner = await rpc + .getTokenAccountsByOwner('owner' as Address, { programId: 'program' as Address }, { encoding: 'jsonParsed' }) + .send(); + + const firstAccount = tokenAccountsByOwner.value[0]; + firstAccount.pubkey satisfies Address; + firstAccount.account.data.program satisfies Address; + firstAccount.account.data.parsed.type satisfies 'account'; + firstAccount.account.data.parsed.info.mint satisfies Address; +}; diff --git a/packages/rpc-core/src/rpc-methods/getTokenAccountsByDelegate.ts b/packages/rpc-core/src/rpc-methods/getTokenAccountsByDelegate.ts index ba2d86596b8..5e99e72f1d3 100644 --- a/packages/rpc-core/src/rpc-methods/getTokenAccountsByDelegate.ts +++ b/packages/rpc-core/src/rpc-methods/getTokenAccountsByDelegate.ts @@ -19,11 +19,11 @@ import { type TokenAccountInfoWithJsonData = Readonly<{ data: Readonly<{ /** Name of the program that owns this account. */ - program: { + program: Address; + parsed: { info: TokenAccount; type: 'account'; }; - parsed: unknown; space: U64UnsafeBeyond2Pow53Minus1; }>; }>; diff --git a/packages/rpc-core/src/rpc-methods/getTokenAccountsByOwner.ts b/packages/rpc-core/src/rpc-methods/getTokenAccountsByOwner.ts index e2938b706c2..62ec4b5e406 100644 --- a/packages/rpc-core/src/rpc-methods/getTokenAccountsByOwner.ts +++ b/packages/rpc-core/src/rpc-methods/getTokenAccountsByOwner.ts @@ -19,11 +19,11 @@ import { type TokenAccountInfoWithJsonData = Readonly<{ data: Readonly<{ /** Name of the program that owns this account. */ - program: { + program: Address; + parsed: { info: TokenAccount; type: 'account'; }; - parsed: unknown; space: U64UnsafeBeyond2Pow53Minus1; }>; }>;