diff --git a/solana-kotlin/src/commonMain/kotlin/net/avianlabs/solana/domain/core/AccountKeysList.kt b/solana-kotlin/src/commonMain/kotlin/net/avianlabs/solana/domain/core/AccountKeysList.kt index 3a7312a..8b58bd7 100644 --- a/solana-kotlin/src/commonMain/kotlin/net/avianlabs/solana/domain/core/AccountKeysList.kt +++ b/solana-kotlin/src/commonMain/kotlin/net/avianlabs/solana/domain/core/AccountKeysList.kt @@ -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 } diff --git a/solana-kotlin/src/commonTest/kotlin/net/avianlabs/solana/domain/core/AccountKeysListTest.kt b/solana-kotlin/src/commonTest/kotlin/net/avianlabs/solana/domain/core/AccountKeysListTest.kt new file mode 100644 index 0000000..0ba8d68 --- /dev/null +++ b/solana-kotlin/src/commonTest/kotlin/net/avianlabs/solana/domain/core/AccountKeysListTest.kt @@ -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) + } +}