Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
refactor(experimental): allow the nonce authority account to be writa…
Browse files Browse the repository at this point in the history
…ble (#1777)

- this is required because the nonce authority can be writable, eg as
the transaction fee payer
  • Loading branch information
mcintyre94 authored Oct 25, 2023
1 parent 68e85dc commit 589c379
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
25 changes: 24 additions & 1 deletion packages/transactions/src/__tests__/durable-nonce-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'test-matchers/toBeFrozenObject';

import { Base58EncodedAddress } from '@solana/addresses';
import { AccountRole, ReadonlySignerAccount, WritableAccount } from '@solana/instructions';
import { AccountRole, IInstruction, ReadonlySignerAccount, WritableAccount } from '@solana/instructions';

import { Blockhash, ITransactionWithBlockhashLifetime } from '../blockhash';
import {
Expand Down Expand Up @@ -129,6 +129,29 @@ describe('assertIsDurableNonceTransaction()', () => {
assertIsDurableNonceTransaction({ ...durableNonceTx });
}).not.toThrow();
});
it('does not throw when the nonce authority is a writable signer', () => {
const advanceDurableNonceInstruction = createMockAdvanceNonceAccountInstruction(NONCE_CONSTRAINT);
const { accounts } = advanceDurableNonceInstruction;
const updatedInstruction: IInstruction = {
...advanceDurableNonceInstruction,
accounts: [
accounts[0],
accounts[1],
{
...accounts[2],
role: AccountRole.WRITABLE_SIGNER,
},
],
};
const transaction = {
instructions: [updatedInstruction],
lifetimeConstraint: { nonce: NONCE_CONSTRAINT.nonce } as IDurableNonceTransaction['lifetimeConstraint'],
version: 0,
} as const;
expect(() => {
assertIsDurableNonceTransaction({ ...transaction });
}).not.toThrow();
});
});

describe('setTransactionLifetimeUsingDurableNonce', () => {
Expand Down
10 changes: 8 additions & 2 deletions packages/transactions/src/durable-nonce.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Base58EncodedAddress } from '@solana/addresses';
import { AccountRole, IInstruction, IInstructionWithAccounts, IInstructionWithData } from '@solana/instructions';
import {
AccountRole,
IInstruction,
IInstructionWithAccounts,
IInstructionWithData,
isSignerRole,
} from '@solana/instructions';
import { ReadonlyAccount, ReadonlySignerAccount, WritableAccount } from '@solana/instructions/dist/types/accounts';

import { ITransactionWithSignatures } from './signatures';
Expand Down Expand Up @@ -101,7 +107,7 @@ export function isAdvanceNonceAccountInstruction(
instruction.accounts[1].role === AccountRole.READONLY &&
// Third account is nonce authority account
instruction.accounts[2].address != null &&
instruction.accounts[2].role === AccountRole.READONLY_SIGNER
isSignerRole(instruction.accounts[2].role)
);
}

Expand Down

0 comments on commit 589c379

Please sign in to comment.