Skip to content

Commit

Permalink
fix: handling empty accounts for anchor remaining accounts (#80)
Browse files Browse the repository at this point in the history
* test: showing issue for empty account case

* chore: correctly handling empty accounts case

* deps: upgrade beets and web3.js

* deps: upgrade beets to latest patches in hopes of fixing web3.js issue
  • Loading branch information
thlorenz authored Sep 1, 2022
1 parent 7ed3e11 commit c96d265
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
"registry": "https://registry.npmjs.org"
},
"dependencies": {
"@metaplex-foundation/beet": "^0.6.0",
"@metaplex-foundation/beet-solana": "^0.3.0",
"@metaplex-foundation/beet": "^0.6.1",
"@metaplex-foundation/beet-solana": "^0.3.1",
"@metaplex-foundation/rustbin": "^0.3.0",
"@solana/web3.js": "^1.36.0",
"@solana/web3.js": "^1.56.2",
"camelcase": "^6.2.1",
"debug": "^4.3.3",
"js-sha256": "^0.9.0",
Expand Down
7 changes: 4 additions & 3 deletions src/render-instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,16 @@ ${typeMapperImports.join('\n')}`.trim()
return true
})

const anchorRemainingAccounts = this.renderAnchorRemainingAccounts
? `
const anchorRemainingAccounts =
this.renderAnchorRemainingAccounts && processedKeys.length > 0
? `
if (accounts.anchorRemainingAccounts != null) {
for (const acc of accounts.anchorRemainingAccounts) {
keys.push(acc)
}
}
`
: ''
: ''

const requiredKeys = requireds
.map(({ name, isMut, isSigner, knownPubkey }) => {
Expand Down
37 changes: 37 additions & 0 deletions test/render-instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,40 @@ test('ix: one arg rendering remaining accounts', async (t) => {
anchorRemainingAccounts: true,
})
})

test('ix: empty args rendering remaining accounts', async (t) => {
const ix = {
name: 'empyArgs',
accounts: [
{
name: 'authority',
isMut: false,
isSigner: true,
},
],
args: [],
}
await checkRenderedIx(t, ix, [BEET_PACKAGE, SOLANA_WEB3_PACKAGE], {
logCode: false,
rxs: [
/programId = new web3\.PublicKey/,
/anchorRemainingAccounts\?\: web3\.AccountMeta\[\]/,
],
anchorRemainingAccounts: true,
})
})

test('ix: empty args and empty accounts', async (t) => {
const ix = {
name: 'empyArgs',
accounts: [],
args: [],
}
await checkRenderedIx(t, ix, [BEET_PACKAGE, SOLANA_WEB3_PACKAGE], {
logCode: false,
rxs: [/programId = new web3\.PublicKey/],
nonrxs: [/anchorRemainingAccounts\?\: web3\.AccountMeta\[\]/],
anchorRemainingAccounts: true,
})
t.end()
})

0 comments on commit c96d265

Please sign in to comment.