Skip to content

Commit

Permalink
Merge pull request #2 from avianlabs/account_keys_list_fix
Browse files Browse the repository at this point in the history
fix AccountKeysList flag logic
  • Loading branch information
wiyarmir authored Jan 18, 2024
2 parents 524b314 + 19e479b commit 10fc8a6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ public class AccountKeysList {

public fun add(accountMeta: AccountMeta) {
val key = accountMeta.publicKey.toString()
if (accounts.containsKey(key)) {
if (!accounts[key]!!.isWritable && accountMeta.isWritable) {
accounts[key] = accountMeta
}
val existing = accounts[key]
if (existing != null) {
accounts[key] = existing.copy(
isSigner = accountMeta.isSigner || existing.isSigner,
isWritable = accountMeta.isWritable || existing.isWritable,
)
} else {
accounts[key] = accountMeta
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.avianlabs.solana.domain.core

import kotlin.test.Test
import kotlin.test.assertTrue

class AccountKeysListTest {
@Test
fun add_different_writable_flags_preserves_isSigner() {
val accountKeysList = AccountKeysList()
val accountMeta1 = AccountMeta(PublicKey.fromBase58("4rZoSK72jVaAW1ayZLrefdMPAAStRVhCfH1PSundaoNt"), false, true)

accountKeysList.add(accountMeta1)

val accountMeta2 = AccountMeta(PublicKey.fromBase58("4rZoSK72jVaAW1ayZLrefdMPAAStRVhCfH1PSundaoNt"), true, false)

accountKeysList.add(accountMeta2)

assertTrue(accountKeysList.list.size == 1)
assertTrue(accountKeysList.list[0].isSigner)
assertTrue(accountKeysList.list[0].isWritable)
}
}

0 comments on commit 10fc8a6

Please sign in to comment.