Skip to content

Commit

Permalink
add missing compiledMessage field to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcintyre94 committed Mar 25, 2024
1 parent 5b245a7 commit 26ba326
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 3 deletions.
9 changes: 8 additions & 1 deletion packages/signers/src/__tests__/fee-payer-signer-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import '@solana/test-matchers/toBeFrozenObject';

import { Address } from '@solana/addresses';
import { BaseTransaction, ITransactionWithFeePayer, ITransactionWithSignatures } from '@solana/transactions';
import {
BaseTransaction,
CompiledMessage,
ITransactionWithFeePayer,
ITransactionWithSignatures,
} from '@solana/transactions';

import { ITransactionWithFeePayerSigner, setTransactionFeePayerSigner } from '../fee-payer-signer';
import { TransactionSigner } from '../transaction-signer';
Expand Down Expand Up @@ -45,6 +50,7 @@ describe('setTransactionFeePayerSigner', () => {
txWithFeePayerAndSignatures = {
...txWithFeePayerA,
signatures: {},
compiledMessage: {} as unknown as CompiledMessage,
};
});
it('does not clear the signatures when the fee payer is the same as the current one', () => {
Expand Down Expand Up @@ -85,6 +91,7 @@ describe('setTransactionFeePayerSigner', () => {
txWithFeePayerAndSignatures = {
...txWithFeePayerA,
signatures: {},
compiledMessage: {} as unknown as CompiledMessage,
};
});
it('does not clear the signatures when the fee payer is the same as the current one', () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/signers/src/__tests__/keypair-signer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import '@solana/test-matchers/toBeFrozenObject';
import { address, getAddressFromPublicKey } from '@solana/addresses';
import { SOLANA_ERROR__SIGNER__EXPECTED_KEY_PAIR_SIGNER, SolanaError } from '@solana/errors';
import { generateKeyPair, SignatureBytes, signBytes } from '@solana/keys';
import { CompilableTransaction, partiallySignTransaction } from '@solana/transactions';
import { CompilableTransaction, CompiledMessage, partiallySignTransaction } from '@solana/transactions';

import {
assertIsKeyPairSigner,
Expand Down Expand Up @@ -151,10 +151,12 @@ describe('createSignerFromKeyPair', () => {
jest.mocked(partiallySignTransaction).mockResolvedValueOnce({
...mockTransactions[0],
signatures: { [myAddress]: mockSignatures[0] },
compiledMessage: {} as unknown as CompiledMessage,
});
jest.mocked(partiallySignTransaction).mockResolvedValueOnce({
...mockTransactions[1],
signatures: { [myAddress]: mockSignatures[1] },
compiledMessage: {} as unknown as CompiledMessage,
});

// When we sign both transactions using that signer.
Expand Down
6 changes: 6 additions & 0 deletions packages/signers/src/sign-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SignatureBytes } from '@solana/keys';
import {
assertTransactionIsFullySigned,
CompilableTransaction,
compileMessage,
IFullySignedTransaction,
ITransactionWithSignatures,
} from '@solana/transactions';
Expand Down Expand Up @@ -192,13 +193,18 @@ async function signModifyingAndPartialTransactionSigners<
return signatures;
}),
);
let compiledMessage = modifiedTransaction.compiledMessage;
if (!compiledMessage) {
compiledMessage = compileMessage(modifiedTransaction);
}
const signedTransaction: ITransactionWithSignatures & TTransaction = {
...modifiedTransaction,
signatures: Object.freeze(
signatureDictionaries.reduce((signatures, signatureDictionary) => {
return { ...signatures, ...signatureDictionary };
}, modifiedTransaction.signatures ?? {}),
),
compiledMessage,
};

return Object.freeze(signedTransaction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SOLANA_ERROR__TRANSACTION__FEE_PAYER_SIGNATURE_MISSING, SolanaError } f
import { AccountRole, ReadonlySignerAccount, WritableAccount } from '@solana/instructions';
import { Signature, SignatureBytes } from '@solana/keys';
import type { Blockhash } from '@solana/rpc-types';
import { IDurableNonceTransaction, Nonce } from '@solana/transactions';
import { CompiledMessage, IDurableNonceTransaction, Nonce } from '@solana/transactions';

import {
waitForDurableNonceTransactionConfirmation,
Expand Down Expand Up @@ -41,6 +41,7 @@ describe('waitForDurableNonceTransactionConfirmation', () => {
signatures: {
['9'.repeat(44) as Address]: new Uint8Array(new Array(64).fill(0)) as SignatureBytes,
} as const,
compiledMessage: {} as unknown as CompiledMessage,
} as const;
let getNonceInvalidationPromise: jest.Mock<Promise<void>>;
let getRecentSignatureConfirmationPromise: jest.Mock<Promise<void>>;
Expand Down Expand Up @@ -194,6 +195,7 @@ describe('waitForRecentTransactionConfirmation', () => {
signatures: {
['9'.repeat(44) as Address]: new Uint8Array(new Array(64).fill(0)) as SignatureBytes,
} as const,
compiledMessage: {} as unknown as CompiledMessage,
} as const;
let getBlockHeightExceedencePromise: jest.Mock<Promise<void>>;
let getRecentSignatureConfirmationPromise: jest.Mock<Promise<void>>;
Expand Down
2 changes: 2 additions & 0 deletions packages/transactions/src/__tests__/blockhash-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '../blockhash';
import { ITransactionWithSignatures } from '../signatures';
import { BaseTransaction } from '../types';
import { CompiledMessage } from '../message';

jest.mock('@solana/codecs-strings', () => ({
...jest.requireActual('@solana/codecs-strings'),
Expand Down Expand Up @@ -135,6 +136,7 @@ describe('setTransactionLifetimeUsingBlockhash', () => {
txWithBlockhashLifetimeConstraintAndSignatures = {
...txWithBlockhashLifetimeConstraint,
signatures: {},
compiledMessage: {} as unknown as CompiledMessage,
};
});
it('does not clear the signatures when the blockhash lifetime constraint is the same as the current one', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/transactions/src/__tests__/durable-nonce-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../durable-nonce';
import { ITransactionWithSignatures } from '../signatures';
import { BaseTransaction } from '../types';
import { CompiledMessage } from '../message';

function createMockAdvanceNonceAccountInstruction<
TNonceAccountAddress extends string = string,
Expand Down Expand Up @@ -257,6 +258,7 @@ describe('setTransactionLifetimeUsingDurableNonce', () => {
durableNonceTxWithConstraintAAndSignatures = {
...durableNonceTxWithConstraintA,
signatures: {},
compiledMessage: {} as unknown as CompiledMessage,
};
});
it('does not clear the signatures when the durable nonce constraint is the same as the current one', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/transactions/src/__tests__/fee-payer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Address } from '@solana/addresses';
import { ITransactionWithFeePayer, setTransactionFeePayer } from '../fee-payer';
import { ITransactionWithSignatures } from '../signatures';
import { BaseTransaction } from '../types';
import { CompiledMessage } from '../message';

const EXAMPLE_FEE_PAYER_A =
'7mvYAxeCui21xYkAyQSjh6iBVZPpgVyt7PYv9km8V5mE' as Address<'7mvYAxeCui21xYkAyQSjh6iBVZPpgVyt7PYv9km8V5mE'>;
Expand Down Expand Up @@ -45,6 +46,7 @@ describe('setTransactionFeePayer', () => {
txWithFeePayerAndSignatures = {
...txWithFeePayerA,
signatures: {},
compiledMessage: {} as unknown as CompiledMessage,
};
});
it('does not clear the signatures when the fee payer is the same as the current one', () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/transactions/src/__tests__/instructions-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '../instructions';
import { ITransactionWithSignatures } from '../signatures';
import { BaseTransaction } from '../types';
import { CompiledMessage } from '../message';

const PROGRAM_A =
'AALQD2dt1k43Acrkp4SvdhZaN4S115Ff2Bi7rHPti3sL' as Address<'AALQD2dt1k43Acrkp4SvdhZaN4S115Ff2Bi7rHPti3sL'>;
Expand Down Expand Up @@ -50,6 +51,7 @@ describe('Transaction instruction helpers', () => {
txWithSignatures = {
...baseTx,
signatures: {},
compiledMessage: {} as unknown as CompiledMessage,
};
});
it('clears the transaction signatures', () => {
Expand Down Expand Up @@ -81,6 +83,7 @@ describe('Transaction instruction helpers', () => {
txWithSignatures = {
...baseTx,
signatures: {},
compiledMessage: {} as unknown as CompiledMessage,
};
});
it('clears the transaction signatures', () => {
Expand Down Expand Up @@ -108,6 +111,7 @@ describe('Transaction instruction helpers', () => {
txWithSignatures = {
...baseTx,
signatures: {},
compiledMessage: {} as unknown as CompiledMessage,
};
});
it('clears the transaction signatures', () => {
Expand Down Expand Up @@ -139,6 +143,7 @@ describe('Transaction instruction helpers', () => {
txWithSignatures = {
...baseTx,
signatures: {},
compiledMessage: {} as unknown as CompiledMessage,
};
});
it('clears the transaction signatures', () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/transactions/src/__tests__/signatures-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('getSignatureFromTransaction', () => {
signatures: {
['123' as Address]: new Uint8Array(new Array(64).fill(9)) as SignatureBytes,
} as const,
compiledMessage: {} as unknown as CompiledMessage,

Check failure on line 40 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node current

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'

Check failure on line 40 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node lts/*

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'
};
expect(getSignatureFromTransaction(transactionWithoutFeePayerSignature)).toBe(
'BUguQsv2ZuHus54HAFzjdJHzZBkygAjKhEeYwSG19tUfUyvvz3worsdQCdAXDNjakJHioSiyxhFiDJrm8XpSXRA',
Expand All @@ -49,6 +50,7 @@ describe('getSignatureFromTransaction', () => {
// No signature by the fee payer.
['456' as Address]: new Uint8Array(new Array(64).fill(9)) as SignatureBytes,
} as const,
compiledMessage: {} as unknown as CompiledMessage,

Check failure on line 53 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node current

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'

Check failure on line 53 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node lts/*

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'
};
expect(() => {
getSignatureFromTransaction(transactionWithoutFeePayerSignature);
Expand Down Expand Up @@ -401,6 +403,7 @@ describe('assertTransactionIsFullySigned', () => {
instructions: [],
lifetimeConstraint: mockBlockhashConstraint,
signatures: {},
compiledMessage: {} as unknown as CompiledMessage,

Check failure on line 406 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node current

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'

Check failure on line 406 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node lts/*

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'
version: 0,
};

Expand All @@ -422,6 +425,7 @@ describe('assertTransactionIsFullySigned', () => {
],
lifetimeConstraint: mockBlockhashConstraint,
signatures: {},
compiledMessage: {} as unknown as CompiledMessage,

Check failure on line 428 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node current

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'

Check failure on line 428 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node lts/*

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'
version: 0,
};

Expand Down Expand Up @@ -450,6 +454,7 @@ describe('assertTransactionIsFullySigned', () => {
signatures: {
[mockPublicKeyAddressA]: mockSignatureA,
},
compiledMessage: {} as unknown as CompiledMessage,

Check failure on line 457 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node current

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'

Check failure on line 457 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node lts/*

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'
version: 0,
};

Expand Down Expand Up @@ -478,6 +483,7 @@ describe('assertTransactionIsFullySigned', () => {
signatures: {
[mockPublicKeyAddressA]: mockSignatureA,
},
compiledMessage: {} as unknown as CompiledMessage,

Check failure on line 486 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node current

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'

Check failure on line 486 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node lts/*

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'
version: 0,
};

Expand Down Expand Up @@ -516,6 +522,7 @@ describe('assertTransactionIsFullySigned', () => {
[mockPublicKeyAddressA]: mockSignatureA,
[mockPublicKeyAddressB]: mockSignatureB,
},
compiledMessage: {} as unknown as CompiledMessage,

Check failure on line 525 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node current

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'

Check failure on line 525 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node lts/*

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'
version: 0,
};

Expand All @@ -534,6 +541,7 @@ describe('assertTransactionIsFullySigned', () => {
signatures: {
[mockPublicKeyAddressA]: mockSignatureA,
},
compiledMessage: {} as unknown as CompiledMessage,

Check failure on line 544 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node current

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'

Check failure on line 544 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node lts/*

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'
version: 0,
};

Expand All @@ -559,6 +567,7 @@ describe('assertTransactionIsFullySigned', () => {
[mockPublicKeyAddressA]: mockSignatureA,
[mockPublicKeyAddressB]: mockSignatureB,
},
compiledMessage: {} as unknown as CompiledMessage,

Check failure on line 570 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node current

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'

Check failure on line 570 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node lts/*

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'
version: 0,
};

Expand Down Expand Up @@ -594,6 +603,7 @@ describe('assertTransactionIsFullySigned', () => {
[mockPublicKeyAddressB]: mockSignatureB,
[mockPublicKeyAddressC]: mockSignatureC,
},
compiledMessage: {} as unknown as CompiledMessage,

Check failure on line 606 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node current

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'

Check failure on line 606 in packages/transactions/src/__tests__/signatures-test.ts

View workflow job for this annotation

GitHub Actions / Build & Test on Node lts/*

Expected object keys to be in ascending order. 'compiledMessage' should be before 'signatures'
version: 0,
};

Expand All @@ -618,6 +628,7 @@ describe('assertTransactionIsFullySigned', () => {
signatures: {
[mockPublicKeyAddressA]: mockSignatureA,
},
compiledMessage: {} as unknown as CompiledMessage,
version: 0,
};

Expand All @@ -636,6 +647,7 @@ describe('assertTransactionIsFullySigned', () => {
signatures: {
[mockPublicKeyAddressA]: mockSignatureA,
},
compiledMessage: {} as unknown as CompiledMessage,
version: 0,
};

Expand Down

0 comments on commit 26ba326

Please sign in to comment.