-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from avianlabs/keep-order-in-account-keys
keep order in account keys
- Loading branch information
Showing
4 changed files
with
126 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 45 additions & 2 deletions
47
solana-kotlin/src/commonTest/kotlin/net/avianlabs/solana/domain/core/AccountKeysListTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,65 @@ | ||
package net.avianlabs.solana.domain.core | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
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) | ||
val accountMeta1 = AccountMeta( | ||
publicKey = PublicKey.fromBase58("4rZoSK72jVaAW1ayZLrefdMPAAStRVhCfH1PSundaoNt"), | ||
isSigner = false, | ||
isWritable = true, | ||
) | ||
|
||
accountKeysList.add(accountMeta1) | ||
|
||
val accountMeta2 = AccountMeta(PublicKey.fromBase58("4rZoSK72jVaAW1ayZLrefdMPAAStRVhCfH1PSundaoNt"), true, false) | ||
val accountMeta2 = AccountMeta( | ||
publicKey = PublicKey.fromBase58("4rZoSK72jVaAW1ayZLrefdMPAAStRVhCfH1PSundaoNt"), | ||
isSigner = true, | ||
isWritable = false, | ||
) | ||
|
||
accountKeysList.add(accountMeta2) | ||
|
||
assertTrue(accountKeysList.list.size == 1) | ||
assertTrue(accountKeysList.list[0].isSigner) | ||
assertTrue(accountKeysList.list[0].isWritable) | ||
} | ||
|
||
@Test | ||
fun account_order() { | ||
val accountKeysList = AccountKeysList() | ||
|
||
val meta = listOf( | ||
AccountMeta( | ||
publicKey = PublicKey.fromBase58("EtDXsqZ9Cgod7Z6j8cqu8fNMF7fu9txu2puHnxVY1wBk"), | ||
isSigner = true, | ||
isWritable = true, | ||
), | ||
AccountMeta( | ||
publicKey = PublicKey.fromBase58("9JGhZqi4MbnVz424uJ6vqk9a1u359xg3nJekdjzzL4d5"), | ||
isSigner = false, | ||
isWritable = true, | ||
), | ||
AccountMeta( | ||
publicKey = PublicKey.fromBase58("G8iheDY9bGix5qCXEitCExLcgZzZrEemngk9cbTR3CQs"), | ||
isSigner = false, | ||
isWritable = false, | ||
), | ||
) | ||
|
||
accountKeysList.addAll(meta.shuffled()) | ||
|
||
assertEquals( | ||
listOf( | ||
PublicKey.fromBase58("EtDXsqZ9Cgod7Z6j8cqu8fNMF7fu9txu2puHnxVY1wBk"), | ||
PublicKey.fromBase58("9JGhZqi4MbnVz424uJ6vqk9a1u359xg3nJekdjzzL4d5"), | ||
PublicKey.fromBase58("G8iheDY9bGix5qCXEitCExLcgZzZrEemngk9cbTR3CQs"), | ||
), | ||
accountKeysList.list.map { it.publicKey } | ||
) | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
solana-kotlin/src/commonTest/kotlin/net/avianlabs/solana/domain/core/MessageTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package net.avianlabs.solana.domain.core | ||
|
||
import net.avianlabs.solana.domain.program.ComputeBudgetProgram | ||
import net.avianlabs.solana.domain.program.TokenProgram | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class MessageTest { | ||
|
||
@Test | ||
fun account_keys_order() { | ||
val transaction = Transaction() | ||
.addInstruction( | ||
TokenProgram.transferChecked( | ||
source = PublicKey.fromBase58("9JGhZqi4MbnVz424uJ6vqk9a1u359xg3nJekdjzzL4d5"), | ||
mint = PublicKey.fromBase58("G8iheDY9bGix5qCXEitCExLcgZzZrEemngk9cbTR3CQs"), | ||
destination = PublicKey.fromBase58("3RfWpJnpr4DHxMDWfhqZRQ4acnQwM1HQXSvmgzzpz2K2"), | ||
owner = PublicKey.fromBase58("EtDXsqZ9Cgod7Z6j8cqu8fNMF7fu9txu2puHnxVY1wBk"), | ||
amount = 1u, | ||
decimals = 1u, | ||
) | ||
) | ||
.addInstruction( | ||
ComputeBudgetProgram.setComputeUnitPrice( | ||
microLamports = 1u, | ||
) | ||
) | ||
|
||
transaction.message.accountKeys.map { println(it) } | ||
|
||
assertEquals( | ||
transaction.message.accountKeys, | ||
listOf( | ||
AccountMeta( | ||
publicKey = PublicKey.fromBase58("EtDXsqZ9Cgod7Z6j8cqu8fNMF7fu9txu2puHnxVY1wBk"), | ||
isSigner = true, | ||
isWritable = false | ||
), | ||
AccountMeta( | ||
publicKey = PublicKey.fromBase58("9JGhZqi4MbnVz424uJ6vqk9a1u359xg3nJekdjzzL4d5"), | ||
isSigner = false, | ||
isWritable = true | ||
), | ||
AccountMeta( | ||
publicKey = PublicKey.fromBase58("3RfWpJnpr4DHxMDWfhqZRQ4acnQwM1HQXSvmgzzpz2K2"), | ||
isSigner = false, | ||
isWritable = true | ||
), | ||
AccountMeta( | ||
publicKey = PublicKey.fromBase58("G8iheDY9bGix5qCXEitCExLcgZzZrEemngk9cbTR3CQs"), | ||
isSigner = false, | ||
isWritable = false | ||
), | ||
AccountMeta( | ||
publicKey = PublicKey.fromBase58("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"), | ||
isSigner = false, | ||
isWritable = false | ||
), | ||
AccountMeta( | ||
publicKey = PublicKey.fromBase58("ComputeBudget111111111111111111111111111111"), | ||
isSigner = false, | ||
isWritable = false | ||
), | ||
), | ||
) | ||
} | ||
} |