Skip to content

Commit

Permalink
Rename newCompileTransactionMessage to compileTransactionMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
mcintyre94 committed Apr 19, 2024
1 parent 2d6ed1c commit b09da71
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getCompiledAddressTableLookups } from '../address-table-lookups';
import { getCompiledMessageHeader } from '../header';
import { getCompiledInstructions } from '../instructions';
import { getCompiledLifetimeToken } from '../lifetime-token';
import { newCompileTransactionMessage } from '../message';
import { compileTransactionMessage } from '../message';
import { getCompiledStaticAccounts } from '../static-accounts';

jest.mock('../address-table-lookups');
Expand Down Expand Up @@ -39,16 +39,16 @@ describe('compileTransactionMessage', () => {
legacyBaseTx = { ...baseTx, version: 'legacy' };
});
it('does not set `addressTableLookups`', () => {
const message = newCompileTransactionMessage(legacyBaseTx);
const message = compileTransactionMessage(legacyBaseTx);
expect(message).not.toHaveProperty('addressTableLookups');
});
it('does not call `getCompiledAddressTableLookups`', () => {
newCompileTransactionMessage(legacyBaseTx);
compileTransactionMessage(legacyBaseTx);
expect(getCompiledAddressTableLookups).not.toHaveBeenCalled();
});
});
it('sets `addressTableLookups` to the return value of `getCompiledAddressTableLookups`', () => {
const message = newCompileTransactionMessage(baseTx);
const message = compileTransactionMessage(baseTx);
expect(getCompiledAddressTableLookups).toHaveBeenCalled();
expect(message.addressTableLookups).toBe(expectedAddressTableLookups);
});
Expand All @@ -63,7 +63,7 @@ describe('compileTransactionMessage', () => {
jest.mocked(getCompiledMessageHeader).mockReturnValue(expectedCompiledMessageHeader);
});
it('sets `header` to the return value of `getCompiledMessageHeader`', () => {
const message = newCompileTransactionMessage(baseTx);
const message = compileTransactionMessage(baseTx);
expect(getCompiledMessageHeader).toHaveBeenCalled();
expect(message.header).toBe(expectedCompiledMessageHeader);
});
Expand All @@ -74,7 +74,7 @@ describe('compileTransactionMessage', () => {
jest.mocked(getCompiledInstructions).mockReturnValue(expectedInstructions);
});
it('sets `instructions` to the return value of `getCompiledInstructions`', () => {
const message = newCompileTransactionMessage(baseTx);
const message = compileTransactionMessage(baseTx);
console.log({ message });
expect(getCompiledInstructions).toHaveBeenCalledWith(
baseTx.instructions,
Expand All @@ -88,7 +88,7 @@ describe('compileTransactionMessage', () => {
jest.mocked(getCompiledLifetimeToken).mockReturnValue('abc');
});
it('sets `lifetimeToken` to the return value of `getCompiledLifetimeToken`', () => {
const message = newCompileTransactionMessage(baseTx);
const message = compileTransactionMessage(baseTx);
expect(getCompiledLifetimeToken).toHaveBeenCalledWith('SOME_CONSTRAINT');
expect(message.lifetimeToken).toBe('abc');
});
Expand All @@ -99,14 +99,14 @@ describe('compileTransactionMessage', () => {
jest.mocked(getCompiledStaticAccounts).mockReturnValue(expectedStaticAccounts);
});
it('sets `staticAccounts` to the return value of `getCompiledStaticAccounts`', () => {
const message = newCompileTransactionMessage(baseTx);
const message = compileTransactionMessage(baseTx);
expect(getCompiledStaticAccounts).toHaveBeenCalled();
expect(message.staticAccounts).toBe(expectedStaticAccounts);
});
});
describe('versions', () => {
it('compiles the version', () => {
const message = newCompileTransactionMessage(baseTx);
const message = compileTransactionMessage(baseTx);
expect(message).toHaveProperty('version', 0);
});
});
Expand Down
6 changes: 3 additions & 3 deletions packages/transaction-messages/src/compile/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ type VersionedCompiledTransactionMessage = BaseCompiledTransactionMessage &
version: number;
}>;

export function newCompileTransactionMessage(
export function compileTransactionMessage(
transaction: CompilableTransactionMessage & Readonly<{ version: 'legacy' }>,
): LegacyCompiledTransactionMessage;
export function newCompileTransactionMessage(
export function compileTransactionMessage(
transaction: CompilableTransactionMessage,
): VersionedCompiledTransactionMessage;
export function newCompileTransactionMessage(transaction: CompilableTransactionMessage): CompiledTransactionMessage {
export function compileTransactionMessage(transaction: CompilableTransactionMessage): CompiledTransactionMessage {
const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { Address } from '@solana/addresses';
import { Blockhash } from '@solana/rpc-types';
import {
CompiledTransactionMessage,
compileTransactionMessage,
getCompiledTransactionMessageEncoder,
newCompileTransactionMessage,
NewNonce,
} from '@solana/transaction-messages';

import { compileTransaction } from '../compile-transaction';

jest.mock('@solana/transaction-messages', () => ({
...jest.requireActual('@solana/transaction-messages'),
compileTransactionMessage: jest.fn(),
getCompiledTransactionMessageEncoder: jest.fn(),
newCompileTransactionMessage: jest.fn(),
}));

type TransactionMessage = Parameters<typeof compileTransaction>[0];
Expand All @@ -35,7 +35,7 @@ describe('compileTransactionMessage', () => {
} as CompiledTransactionMessage;
const mockCompiledMessageBytes = new Uint8Array(Array(100)).fill(1);
beforeEach(() => {
(newCompileTransactionMessage as jest.Mock).mockReturnValue(mockCompiledMessage);
(compileTransactionMessage as jest.Mock).mockReturnValue(mockCompiledMessage);
(getCompiledTransactionMessageEncoder as jest.Mock).mockReturnValue({
encode: jest.fn().mockReturnValue(mockCompiledMessageBytes),
});
Expand Down
4 changes: 2 additions & 2 deletions packages/transactions/src/compile-transaction.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ReadonlyUint8Array } from '@solana/codecs-core';
import {
CompilableTransactionMessage,
compileTransactionMessage,
getCompiledTransactionMessageEncoder,
IDurableNonceTransactionMessage,
isTransactionMessageWithBlockhashLifetime,
ITransactionMessageWithBlockhashLifetime,
newCompileTransactionMessage,
} from '@solana/transaction-messages';

import {
Expand All @@ -30,7 +30,7 @@ export function compileTransaction(
export function compileTransaction(
transactionMessage: CompilableTransactionMessage,
): Readonly<Transaction & TransactionWithLifetime> {
const compiledMessage = newCompileTransactionMessage(transactionMessage);
const compiledMessage = compileTransactionMessage(transactionMessage);
const messageBytes = getCompiledTransactionMessageEncoder().encode(
compiledMessage,
) as ReadonlyUint8Array as TransactionMessageBytes;
Expand Down

0 comments on commit b09da71

Please sign in to comment.