Skip to content

Commit

Permalink
Default optional account strategy to program ID (#108)
Browse files Browse the repository at this point in the history
As the new shank version will assume
  • Loading branch information
lorisleiva authored Jul 6, 2023
1 parent 1b379fe commit 08f8ea0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/render-instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class InstructionRenderer {
typeMapper
)
this.programIdPubkey = `new ${SOLANA_WEB3_EXPORT_NAME}.PublicKey('${this.programId}')`
this.defaultOptionalAccounts = ix.defaultOptionalAccounts ?? false
this.defaultOptionalAccounts = !ix.legacyOptionalAccountsStrategy
}

// -----------------
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export type IdlInstructionArg = {
export type IdlInstruction = {
name: string
defaultOptionalAccounts?: boolean
legacyOptionalAccountsStrategy?: boolean
accounts: IdlInstructionAccount[] | IdlAccountsCollection[]
args: IdlInstructionArg[]
}
Expand Down
6 changes: 4 additions & 2 deletions test/render-instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ test('ix: two accounts and two args', async (t) => {
test('ix: three accounts, two optional', async (t) => {
const ix = <IdlInstruction>{
name: 'choicy',
legacyOptionalAccountsStrategy: true,
accounts: [
{
name: 'authority',
Expand Down Expand Up @@ -242,6 +243,7 @@ test('ix: three accounts, two optional', async (t) => {
test('ix: five accounts composed of two required, two optional and one required', async (t) => {
const ix = <IdlInstruction>{
name: 'sandwichedOptionalAccounts',
legacyOptionalAccountsStrategy: true,
accounts: [
{
name: 'authority',
Expand Down Expand Up @@ -292,14 +294,13 @@ test('ix: five accounts composed of two required, two optional and one required'
// Ensuring we are not pushing the first 2 accounts.
/keys\.push\(\{\s+pubkey\: accounts\.authority,/,
/keys\.push\(\{\s+pubkey\: accounts\.metadata,/,
]
],
})
})

test('ix: three accounts, two optional, defaultOptionalAccounts', async (t) => {
const ix = <IdlInstruction>{
name: 'choicy',
defaultOptionalAccounts: true,
accounts: [
{
name: 'authority',
Expand Down Expand Up @@ -431,6 +432,7 @@ test('ix: with args one system program account and programId', async (t) => {
test('ix: empty args one system program account + one optional rent account', async (t) => {
const ix = {
name: 'empyArgsWithSystemProgram',
legacyOptionalAccountsStrategy: true,
accounts: [
{
name: 'authority',
Expand Down

0 comments on commit 08f8ea0

Please sign in to comment.