diff --git a/packages/transactions/src/__typetests__/transactions-typetests.ts b/packages/transactions/src/__typetests__/transactions-typetests.ts deleted file mode 100644 index e4c043e152c..00000000000 --- a/packages/transactions/src/__typetests__/transactions-typetests.ts +++ /dev/null @@ -1,463 +0,0 @@ -import { Base58EncodedAddress } from '@solana/addresses'; - -import { - appendTransactionInstruction, - Blockhash, - IDurableNonceTransaction, - ITransactionWithBlockhashLifetime, - ITransactionWithSignatures, - Nonce, - prependTransactionInstruction, - setTransactionLifetimeUsingBlockhash, - setTransactionLifetimeUsingDurableNonce, - signTransaction, -} from '..'; -import { createTransaction } from '../create-transaction'; -import { ITransactionWithFeePayer, setTransactionFeePayer } from '../fee-payer'; -import { CompiledMessage, compileMessage } from '../message'; -import { Transaction } from '../types'; -import { getUnsignedTransaction } from '../unsigned-transaction'; - -const mockFeePayer = null as unknown as Base58EncodedAddress<'feePayer'>; -const mockBlockhash = null as unknown as Blockhash; -const mockBlockhashLifetime = { - blockhash: mockBlockhash, - lastValidBlockHeight: 0n, -}; -const mockSigner = {} as CryptoKeyPair; -const mockNonceConfig = { - nonce: null as unknown as Nonce<'nonce'>, - nonceAccountAddress: null as unknown as Base58EncodedAddress<'nonce'>, - nonceAuthorityAddress: null as unknown as Base58EncodedAddress<'nonceAuthority'>, -}; -const mockInstruction = { - accounts: [], - data: Uint8Array.of(0), - programAddress: null as unknown as Base58EncodedAddress<'program'>, -} as Transaction['instructions'][number]; - -async () => { - // createTransaction - createTransaction({ version: 'legacy' }) satisfies Extract; - // @ts-expect-error version should match - createTransaction({ version: 0 }) satisfies Extract; - createTransaction({ version: 0 }) satisfies Extract; - // @ts-expect-error version should match - createTransaction({ version: 'legacy' }) satisfies Extract; - - // setTransactionLifetimeUsingBlockhash - setTransactionLifetimeUsingBlockhash( - mockBlockhashLifetime, - null as unknown as Extract - ) satisfies Extract & ITransactionWithBlockhashLifetime; - setTransactionLifetimeUsingBlockhash( - mockBlockhashLifetime, - null as unknown as Extract - // @ts-expect-error Version should match - ) satisfies Extract & ITransactionWithBlockhashLifetime; - setTransactionLifetimeUsingBlockhash( - mockBlockhashLifetime, - null as unknown as Extract & ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures; - setTransactionLifetimeUsingBlockhash( - mockBlockhashLifetime, - null as unknown as Extract - ) satisfies Extract & ITransactionWithBlockhashLifetime; - setTransactionLifetimeUsingBlockhash( - mockBlockhashLifetime, - null as unknown as Extract - // @ts-expect-error Version should match - ) satisfies Extract & ITransactionWithBlockhashLifetime; - setTransactionLifetimeUsingBlockhash( - mockBlockhashLifetime, - null as unknown as Extract & ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & ITransactionWithBlockhashLifetime & ITransactionWithSignatures; - - // setTransactionLifetimeUsingDurableNonce - setTransactionLifetimeUsingDurableNonce( - mockNonceConfig, - null as unknown as Extract - ) satisfies Extract & IDurableNonceTransaction; - setTransactionLifetimeUsingDurableNonce( - mockNonceConfig, - null as unknown as Extract - // @ts-expect-error Version should match - ) satisfies Extract & IDurableNonceTransaction; - setTransactionLifetimeUsingDurableNonce( - mockNonceConfig, - null as unknown as Extract & ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & IDurableNonceTransaction & ITransactionWithSignatures; - setTransactionLifetimeUsingDurableNonce( - mockNonceConfig, - null as unknown as Extract - ) satisfies Extract & IDurableNonceTransaction; - setTransactionLifetimeUsingDurableNonce( - mockNonceConfig, - null as unknown as Extract - // @ts-expect-error Version should match - ) satisfies Extract & IDurableNonceTransaction; - setTransactionLifetimeUsingDurableNonce( - mockNonceConfig, - null as unknown as Extract & ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & IDurableNonceTransaction & ITransactionWithSignatures; - - // setTransactionFeePayer - - // (base) - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract - ) satisfies Extract & ITransactionWithFeePayer<'feePayer'>; - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract & ITransactionWithFeePayer<'NOTfeePayer'> - ) satisfies Extract & ITransactionWithFeePayer<'feePayer'>; - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract - // @ts-expect-error Version should match - ) satisfies Extract & ITransactionWithFeePayer<'feePayer'>; - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract & ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithSignatures; - setTransactionFeePayer(mockFeePayer, null as unknown as Extract) satisfies Extract< - Transaction, - { version: 0 } - > & - ITransactionWithFeePayer<'feePayer'>; - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract & ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithSignatures; - - // (blockhash) - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract & ITransactionWithBlockhashLifetime - ) satisfies Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime; - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract & - ITransactionWithFeePayer<'NOTfeePayer'> & - ITransactionWithBlockhashLifetime - ) satisfies Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime; - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract & ITransactionWithBlockhashLifetime - // @ts-expect-error Version should match - ) satisfies Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime; - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures; - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract & ITransactionWithBlockhashLifetime - ) satisfies Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime; - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures; - - // (durable nonce) - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract & IDurableNonceTransaction - ) satisfies Extract & - ITransactionWithFeePayer<'feePayer'> & - IDurableNonceTransaction; - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract & - ITransactionWithFeePayer<'NOTfeePayer'> & - IDurableNonceTransaction - ) satisfies Extract & - ITransactionWithFeePayer<'feePayer'> & - IDurableNonceTransaction; - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract & IDurableNonceTransaction - // @ts-expect-error Version should match - ) satisfies Extract & ITransactionWithFeePayer<'feePayer'> & IDurableNonceTransaction; - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract & - IDurableNonceTransaction & - ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & - ITransactionWithFeePayer<'feePayer'> & - IDurableNonceTransaction & - ITransactionWithSignatures; - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract & IDurableNonceTransaction - ) satisfies Extract & ITransactionWithFeePayer<'feePayer'> & IDurableNonceTransaction; - setTransactionFeePayer( - mockFeePayer, - null as unknown as Extract & IDurableNonceTransaction & ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & - ITransactionWithFeePayer<'feePayer'> & - IDurableNonceTransaction & - ITransactionWithSignatures; - - // signTransaction - // (checks) - signTransaction( - mockSigner, - // @ts-expect-error Type error on missing fee payer and lifetime - null as unknown as Extract - ); - signTransaction( - mockSigner, - // @ts-expect-error Type error on missing lifetime - null as unknown as Extract & ITransactionWithFeePayer<'feePayer'> - ); - signTransaction( - mockSigner, - // @ts-expect-error Type error on missing fee payer (blockhash) - null as unknown as Extract & ITransactionWithBlockhashLifetime - ); - signTransaction( - mockSigner, - // @ts-expect-error Type error on missing fee payer (durable nonce) - null as unknown as Extract & IDurableNonceTransaction - ); - - // (blockhash) - signTransaction( - mockSigner, - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime - ) satisfies Promise< - Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures - >; - signTransaction( - mockSigner, - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime - // @ts-expect-error Version should match - ) satisfies Promise< - Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures - >; - signTransaction( - mockSigner, - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime - ) satisfies Promise< - Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures - >; - signTransaction( - mockSigner, - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures - ) satisfies Promise< - Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures - >; - signTransaction( - mockSigner, - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures - // @ts-expect-error Version should match - ) satisfies Promise< - Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures - >; - signTransaction( - mockSigner, - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures - ) satisfies Promise< - Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures - >; - - // compileMessage - compileMessage( - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime - ) satisfies Extract; - compileMessage( - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime - ) satisfies Extract; - - // getUnsignedTransaction - getUnsignedTransaction( - null as unknown as Extract & ITransactionWithSignatures - ) satisfies Extract; - getUnsignedTransaction( - null as unknown as Extract & ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & ITransactionWithSignatures; - getUnsignedTransaction( - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithSignatures - ) satisfies Extract & ITransactionWithFeePayer<'feePayer'>; - getUnsignedTransaction( - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithSignatures; - getUnsignedTransaction( - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures - ) satisfies Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime; - getUnsignedTransaction( - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithBlockhashLifetime & - ITransactionWithSignatures; - - // appendTransactionInstruction - appendTransactionInstruction( - mockInstruction, - null as unknown as Extract - ) satisfies Extract & { - instructions: Transaction['instructions']; - }; - appendTransactionInstruction( - mockInstruction, - null as unknown as Extract & ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & { - instructions: Transaction['instructions']; - } & ITransactionWithSignatures; - appendTransactionInstruction( - mockInstruction, - null as unknown as Extract & ITransactionWithFeePayer<'feePayer'> - ) satisfies Extract & { - instructions: Transaction['instructions']; - } & ITransactionWithFeePayer<'feePayer'>; - appendTransactionInstruction( - mockInstruction, - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithSignatures - ) satisfies Extract & { - instructions: Transaction['instructions']; - } & ITransactionWithFeePayer<'feePayer'>; - appendTransactionInstruction( - mockInstruction, - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & { - instructions: Transaction['instructions']; - } & ITransactionWithFeePayer<'feePayer'> & - ITransactionWithSignatures; - - // prependTransactionInstruction - prependTransactionInstruction( - mockInstruction, - null as unknown as Extract - ) satisfies Extract & { - instructions: Transaction['instructions']; - }; - prependTransactionInstruction( - mockInstruction, - null as unknown as Extract & ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & { - instructions: Transaction['instructions']; - } & ITransactionWithSignatures; - prependTransactionInstruction( - mockInstruction, - null as unknown as Extract & ITransactionWithFeePayer<'feePayer'> - ) satisfies Extract & { - instructions: Transaction['instructions']; - } & ITransactionWithFeePayer<'feePayer'>; - prependTransactionInstruction( - mockInstruction, - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithSignatures - ) satisfies Extract & { - instructions: Transaction['instructions']; - } & ITransactionWithFeePayer<'feePayer'>; - prependTransactionInstruction( - mockInstruction, - null as unknown as Extract & - ITransactionWithFeePayer<'feePayer'> & - ITransactionWithSignatures - // @ts-expect-error Should not have signatures - ) satisfies Extract & { - instructions: Transaction['instructions']; - } & ITransactionWithFeePayer<'feePayer'> & - ITransactionWithSignatures; -}; diff --git a/packages/transactions/src/durable-nonce.ts b/packages/transactions/src/durable-nonce.ts index a30a9057856..d3dc6f2fabd 100644 --- a/packages/transactions/src/durable-nonce.ts +++ b/packages/transactions/src/durable-nonce.ts @@ -2,7 +2,6 @@ import { Base58EncodedAddress } from '@solana/addresses'; import { AccountRole, IInstruction, IInstructionWithAccounts, IInstructionWithData } from '@solana/instructions'; import { ReadonlyAccount, ReadonlySignerAccount, WritableAccount } from '@solana/instructions/dist/types/accounts'; -import { ITransactionWithSignatures } from './signatures'; import { BaseTransaction } from './types'; import { getUnsignedTransaction } from './unsigned-transaction'; @@ -131,8 +130,7 @@ export function setTransactionLifetimeUsingDurableNonce< nonceAuthorityAddress, }: DurableNonceConfig, transaction: TTransaction | (TTransaction & IDurableNonceTransaction) -): Omit & - IDurableNonceTransaction { +): TTransaction & IDurableNonceTransaction { const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction); if ( isAlreadyDurableNonceTransaction && diff --git a/packages/transactions/src/fee-payer.ts b/packages/transactions/src/fee-payer.ts index c2e329129be..9950828b152 100644 --- a/packages/transactions/src/fee-payer.ts +++ b/packages/transactions/src/fee-payer.ts @@ -12,21 +12,21 @@ export function setTransactionFeePayer, transaction: | (TTransaction & ITransactionWithSignatures) - | (TTransaction & ITransactionWithFeePayer & ITransactionWithSignatures) + | (TTransaction & ITransactionWithFeePayer & ITransactionWithSignatures) ): Omit & ITransactionWithFeePayer; export function setTransactionFeePayer( feePayer: Base58EncodedAddress, - transaction: TTransaction | (TTransaction & ITransactionWithFeePayer) + transaction: TTransaction | (TTransaction & ITransactionWithFeePayer) ): TTransaction & ITransactionWithFeePayer; export function setTransactionFeePayer( feePayer: Base58EncodedAddress, transaction: | TTransaction - | (TTransaction & ITransactionWithFeePayer) + | (TTransaction & ITransactionWithFeePayer) | (TTransaction & ITransactionWithSignatures) - | (TTransaction & ITransactionWithFeePayer & ITransactionWithSignatures) + | (TTransaction & ITransactionWithFeePayer & ITransactionWithSignatures) ) { if ('feePayer' in transaction && feePayer === transaction.feePayer) { return transaction;