From 39fde7c098d7446ac0d1765f0801b399590e1222 Mon Sep 17 00:00:00 2001 From: Andrey Pfau Date: Wed, 25 Jan 2023 03:53:03 +0300 Subject: [PATCH] fix tests --- .../commonMain/kotlin/org/ton/block/CommonMsgInfo.kt | 6 +++--- .../src/commonMain/kotlin/org/ton/block/Maybe.kt | 4 ++-- .../src/commonMain/kotlin/org/ton/block/Message.kt | 11 +---------- .../org/ton/contract/wallet/v3/AbstractContractV3.kt | 2 +- .../org/ton/contract/wallet/v4/AbstractContractV4.kt | 2 +- .../org/ton/contract/wallet/v1/WalletV1R3Test.kt | 11 +---------- ton-kotlin-liteclient/jvm/test/LiteClientTest2.kt | 2 ++ .../commonMain/kotlin/org/ton/tlb/TlbCombinator.kt | 10 ++++++---- 8 files changed, 17 insertions(+), 31 deletions(-) diff --git a/ton-kotlin-block/src/commonMain/kotlin/org/ton/block/CommonMsgInfo.kt b/ton-kotlin-block/src/commonMain/kotlin/org/ton/block/CommonMsgInfo.kt index 86bb09ed..6fc4a932 100644 --- a/ton-kotlin-block/src/commonMain/kotlin/org/ton/block/CommonMsgInfo.kt +++ b/ton-kotlin-block/src/commonMain/kotlin/org/ton/block/CommonMsgInfo.kt @@ -11,10 +11,10 @@ import kotlin.jvm.JvmStatic @JsonClassDiscriminator("@type") @Serializable -sealed interface CommonMsgInfo : TlbObject { - companion object : TlbCodec by CommonMsgInfoTlbCombinator { +public sealed interface CommonMsgInfo : TlbObject { + public companion object : TlbCodec by CommonMsgInfoTlbCombinator { @JvmStatic - fun tlbCodec(): TlbCombinator = CommonMsgInfoTlbCombinator + public fun tlbCodec(): TlbCombinator = CommonMsgInfoTlbCombinator } } diff --git a/ton-kotlin-block/src/commonMain/kotlin/org/ton/block/Maybe.kt b/ton-kotlin-block/src/commonMain/kotlin/org/ton/block/Maybe.kt index 430dd087..220243ab 100644 --- a/ton-kotlin-block/src/commonMain/kotlin/org/ton/block/Maybe.kt +++ b/ton-kotlin-block/src/commonMain/kotlin/org/ton/block/Maybe.kt @@ -52,11 +52,11 @@ public data class Just( ) : Maybe { override fun print(printer: TlbPrettyPrinter): TlbPrettyPrinter = printer { type("just") { - field("value", value as Any) + field("value", value) } } - override fun toString(): String = "(just\nvalue:$value)" + override fun toString(): String = print().toString() } private class MaybeTlbCombinator( diff --git a/ton-kotlin-block/src/commonMain/kotlin/org/ton/block/Message.kt b/ton-kotlin-block/src/commonMain/kotlin/org/ton/block/Message.kt index e199f270..c9afcddc 100644 --- a/ton-kotlin-block/src/commonMain/kotlin/org/ton/block/Message.kt +++ b/ton-kotlin-block/src/commonMain/kotlin/org/ton/block/Message.kt @@ -52,16 +52,7 @@ public data class Message( ): TlbConstructor> = MessageTlbConstructor(x) } - override fun toString(): String = buildString { - append("(message\n") - append("info:") - append(info) - append(" init:") - append(init) - append(" body:") - append(body.toString()) - append(")") - } + override fun toString(): String = print().toString() } operator fun Message.Companion.invoke(x: TlbCodec) = tlbCodec(x) diff --git a/ton-kotlin-contract/src/commonMain/kotlin/org/ton/contract/wallet/v3/AbstractContractV3.kt b/ton-kotlin-contract/src/commonMain/kotlin/org/ton/contract/wallet/v3/AbstractContractV3.kt index 4ec51ad1..f1d127f9 100644 --- a/ton-kotlin-contract/src/commonMain/kotlin/org/ton/contract/wallet/v3/AbstractContractV3.kt +++ b/ton-kotlin-contract/src/commonMain/kotlin/org/ton/contract/wallet/v3/AbstractContractV3.kt @@ -20,7 +20,7 @@ abstract class AbstractContractV3( override fun createDataInit(): Cell = CellBuilder.createCell { storeUInt(0, 32) // seqno storeUInt(subwalletId, 32) - storeBits(privateKey.publicKey().key.toBitString()) + storeBits(privateKey.publicKey().key) } override fun createSigningMessage(seqno: Int, builder: CellBuilder.() -> Unit): Cell = CellBuilder.createCell { diff --git a/ton-kotlin-contract/src/commonMain/kotlin/org/ton/contract/wallet/v4/AbstractContractV4.kt b/ton-kotlin-contract/src/commonMain/kotlin/org/ton/contract/wallet/v4/AbstractContractV4.kt index 7990d5fc..8b308135 100644 --- a/ton-kotlin-contract/src/commonMain/kotlin/org/ton/contract/wallet/v4/AbstractContractV4.kt +++ b/ton-kotlin-contract/src/commonMain/kotlin/org/ton/contract/wallet/v4/AbstractContractV4.kt @@ -21,7 +21,7 @@ abstract class AbstractContractV4( override fun createDataInit(): Cell = CellBuilder.createCell { storeUInt(0, 32) // seqno storeUInt(subwalletId, 32) - storeBits(privateKey.publicKey().key.toBitString()) + storeBits(privateKey.publicKey().key) storeUInt(0, 1) // plugins dict empty } diff --git a/ton-kotlin-contract/src/commonTest/kotlin/org/ton/contract/wallet/v1/WalletV1R3Test.kt b/ton-kotlin-contract/src/commonTest/kotlin/org/ton/contract/wallet/v1/WalletV1R3Test.kt index adf191c0..d38bd7dd 100644 --- a/ton-kotlin-contract/src/commonTest/kotlin/org/ton/contract/wallet/v1/WalletV1R3Test.kt +++ b/ton-kotlin-contract/src/commonTest/kotlin/org/ton/contract/wallet/v1/WalletV1R3Test.kt @@ -9,7 +9,6 @@ import org.ton.boc.BagOfCells import org.ton.cell.Cell import org.ton.cell.CellBuilder import org.ton.contract.wallet.liteClient -import org.ton.crypto.encodeHex import org.ton.crypto.hex import org.ton.tlb.constructor.AnyTlbConstructor import org.ton.tlb.storeTlb @@ -88,7 +87,7 @@ class WalletV1R3Test { Cell("FF0020DD2082014C97BA218201339CBAB19C71B0ED44D0D31FD70BFFE304E0A4F260810200D71820D70B1FED44D0D31FD3FFD15112BAF2A122F901541044F910F2A2F80001D31F3120D74A96D307D402FB00DED1A4C8CB1FCBFFC9ED54"), Cell("000000003B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29") ) - assertEquals(actual, expected) + assertEquals(expected, actual) } @Test @@ -107,14 +106,6 @@ class WalletV1R3Test { val expectedBoc = BagOfCells(hex("b5ee9c720101030100f10002cf880083a2c647078b8a66f9765a64401ce06b507a077e2e426e1c0eb9d0dfc45bc7ac11985b73c78dd0fef1ad628feeba22ce006ddd70361e50f671607a41713ad2373bd9c24dac2cb48bf838599e15897e063f5d528e5bdc150d40e28e78aff0c798c08000000010010200baff0020dd2082014c97ba218201339cbab19c71b0ed44d0d31fd70bffe304e0a4f260810200d71820d70b1fed44d0d31fd3ffd15112baf2a122f901541044f910f2a2f80001d31f3120d74a96d307d402fb00ded1a4c8cb1fcbffc9ed540048000000003b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29")) assertEquals(expectedBoc, actualBoc) - - - println("---") - println(actualBoc) - - println("---") - println(actualBoc.toByteArray().encodeHex()) - // assertEquals(expected, hex(actual).uppercase()) } diff --git a/ton-kotlin-liteclient/jvm/test/LiteClientTest2.kt b/ton-kotlin-liteclient/jvm/test/LiteClientTest2.kt index 1a24c524..2eb3933a 100644 --- a/ton-kotlin-liteclient/jvm/test/LiteClientTest2.kt +++ b/ton-kotlin-liteclient/jvm/test/LiteClientTest2.kt @@ -10,6 +10,7 @@ import org.ton.crypto.base64 import org.ton.lite.client.LiteClient import kotlin.test.assertNotNull import kotlin.test.assertTrue +import kotlin.time.ExperimentalTime class LiteClientTest2 { private fun getClient() = LiteClient( @@ -25,6 +26,7 @@ class LiteClientTest2 { coroutineContext = Dispatchers.Default ) + @ExperimentalTime @Test fun getAccount() { val liteClient = getClient() diff --git a/ton-kotlin-tlb/src/commonMain/kotlin/org/ton/tlb/TlbCombinator.kt b/ton-kotlin-tlb/src/commonMain/kotlin/org/ton/tlb/TlbCombinator.kt index 2507f29a..e7eb63dc 100644 --- a/ton-kotlin-tlb/src/commonMain/kotlin/org/ton/tlb/TlbCombinator.kt +++ b/ton-kotlin-tlb/src/commonMain/kotlin/org/ton/tlb/TlbCombinator.kt @@ -52,11 +52,13 @@ public abstract class TlbCombinator( } override fun storeTlb(cellBuilder: CellBuilder, value: T) { - val constructor = findTlbStorerOrNull(value) ?: throw UnknownTlbConstructorException() - if (constructor is TlbConstructor<*>) { - cellBuilder.storeBits(constructor.id) + val storer = findTlbStorerOrNull(value) ?: throw UnknownTlbConstructorException() + if (storer is TlbConstructorProvider<*>) { + cellBuilder.storeBits(storer.tlbConstructor().id) + } else if (storer is TlbConstructor<*>) { + cellBuilder.storeBits(storer.id) } - return constructor.storeTlb(cellBuilder, value) + return storer.storeTlb(cellBuilder, value) } protected open fun findTlbLoaderOrNull(cellSlice: CellSlice): TlbLoader? {